Giter Site home page Giter Site logo

amerkoleci / vortice.vulkan Goto Github PK

View Code? Open in Web Editor NEW
258.0 258.0 25.0 41.48 MB

Cross platform .NET bindings for Vulkan, VMA, SPIRV-Cross and shaderc

License: MIT License

C# 54.99% C 25.37% Objective-C 0.11% GLSL 0.03% C++ 19.50%
csharp dotnet dotnet-core dotnetcore net6 netstandard netstandard20 vortice vulkan vulkan-api vulkan-sdk

vortice.vulkan's Introduction

Hey! I am Amer Koleci, my github id is `amerkoleci`

I'm a self-taught, passionate software developer from Italy

Amer streak Amer top langs

Amer's github activity graph

  • ๐Ÿ”ญ Iโ€™m currently working as senior software engineer using C#/VB .NET and .NET in general writing WMS software.
  • โค๏ธ I love open source and work on personal projects whether possible, I enjoy contributing to other projects and share opinions with other people.
  • ๐ŸŒŸ I like to write game engine code and explore the different graphics APIs out there (Direct3D12, Vulkan, Metal or OpenGL). Therefore, I have created several projects to abstract the graphics APIs to make it easier to do graphics programming, which is where my main focus is. I love learning and read about new rendering techniques and try to implement them.
  • ๐Ÿ’ฌ If you have any question feel free to contact me and I will gladly reply.
  • ๐Ÿค” If you like to join my open source project feel free to do so by submitting PR or opening issues.
  • โšก Consider SPONSORING me to help me out reach my goals sooner.

If you are curious, I suggest you check out the following repositories:

vortice.vulkan's People

Contributors

abenedik avatar amerkoleci avatar dependabot[bot] avatar manuelxmarquez avatar torss avatar voltstro avatar xen2 avatar xpaw avatar zorbn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vortice.vulkan's Issues

Trying SpirvCrossApi.spvc_compiler_get_combined_image_samplers and get nothing

Unlike spvc_resources_get_resource_list_for_type this function doesn't offer a out variable so I'm supposed to provide it a pointer, of presumably a reasonably sized spvc_combined_image_sampler buffer.

However doing

spvc_combined_image_sampler* samplers = stackalloc spvc_combined_image_sampler[25];
SpirvCrossApi.spvc_compiler_get_combined_image_samplers(compiler, samplers, &samplerCount).CheckResult();

doesn't work, and

spvc_combined_image_sampler[] samplers = new spvc_combined_image_sampler[25];
SpirvCrossApi.spvc_compiler_get_combined_image_samplers(compiler, (spvc_combined_image_sampler*)Unsafe.AsPointer(ref samplers), &samplerCount).CheckResult();

almost works, but the array is short of four uints, or one struct+1 field
image

One thing I noticed is function signatures differ, and the C++ side works with SmallVector.

C

SPVC_PUBLIC_API spvc_result spvc_compiler_get_combined_image_samplers(spvc_compiler compiler,
                                                                      const spvc_combined_image_sampler **samplers,
                                                                      size_t *num_samplers);

C#

public unsafe spvc_result spvc_compiler_get_combined_image_samplers(spvc_compiler compiler,
                                                                    spvc_combined_image_sampler* samplers,
                                                                    nuint* num_samplers)

num_samplers is correctly set to 7

vkCmdSetBlendConstants: wrong argument type

The "blendConstants" argument of the "vkCmdSetBlendConstants" command must be a pointer to float.

current command signature:
void vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, float blendConstants);

valid command signature:
void vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, float* blendConstants);

LibraryLoader was rolled back reintroducing #17.

LibraryLoader was rolled back reintroducing #17. If the old code is needed, fall back to the new code before doing nothing.

Let me know if the old code is needed and I can work on merging the new code in.

VkAccelerationStructureInstanceKHR struct

Hi Amer,
I found an issue with VkAccelerationStructureInstanceKHR struct in Vortice.Vulkan. The size of this struct in C++ API is 64 ( Ej. sizeof(VkAccelerationStructureInstanceKHR) ) however in Vortice C# API is 72 (Unsafe.SizeOf< VkAccelerationStructureInstanceKHR >()), and this doesn't work in my Raytracing sample. I think that you must specify the explicit layout for this struct.

Vortice.Vulkan struct

	[StructLayout(LayoutKind.Sequential)]
	public partial struct VkAccelerationStructureInstanceKHR
	{
		public VkTransformMatrixKHR transform;
		public uint instanceCustomIndex;
		public uint mask;
		public uint instanceShaderBindingTableRecordOffset;
		public VkGeometryInstanceFlagsKHR flags;
		public ulong accelerationStructureReference;
	}

Khronos Group specification vk.xml

 <type category="struct" name="VkAccelerationStructureInstanceKHR">
            <comment>The bitfields in this structure are non-normative since bitfield ordering is implementation-defined in C. The specification defines the normative layout.</comment>
            <member><type>VkTransformMatrixKHR</type>                                    <name>transform</name></member>
            <member><type>uint32_t</type>                                                <name>instanceCustomIndex</name>:24</member>
            <member><type>uint32_t</type>                                                <name>mask</name>:8</member>
            <member><type>uint32_t</type>                                                <name>instanceShaderBindingTableRecordOffset</name>:24</member>
            <member optional="true"><type>VkGeometryInstanceFlagsKHR</type>              <name>flags</name>:8</member>
            <member><type>uint64_t</type>                                                <name>accelerationStructureReference</name></member>
        </type>

Vulkan C++ struct

typedef struct VkAccelerationStructureInstanceKHR {
    VkTransformMatrixKHR          transform;
    uint32_t                      instanceCustomIndex:24;
    uint32_t                      mask:8;
    uint32_t                      instanceShaderBindingTableRecordOffset:24;
    VkGeometryInstanceFlagsKHR    flags:8;
    uint64_t                      accelerationStructureReference;
} VkAccelerationStructureInstanceKHR;

Proposal C# struct

	[StructLayout(LayoutKind.Explicit)]
	public unsafe partial struct VkAccelerationStructureInstanceKHR
	{
		[FieldOffset(0)]
		public VkTransformMatrixKHR transform;
		[FieldOffset(48)]
		public uint instanceCustomIndex;
		[FieldOffset(51)]
		public uint mask;
		[FieldOffset(52)]
		public uint instanceShaderBindingTableRecordOffset;
		[FieldOffset(55)]
		public VkGeometryInstanceFlagBitsKHR flags;
		[FieldOffset(56)]
		public ulong accelerationStructureReference;
	}

I tested proposal struct and work fine :).

Vortice.Vulkan.Vulkan.vkCmdSetViewport is self-recursive loop? (StackOverflowException)

What gives?

Stack overflow.
Repeat 31860 times:
--------------------------------
   at Vortice.Vulkan.Vulkan.vkCmdSetViewport[[Vortice.Vulkan.VkViewport, Vortice.Vulkan, Version=1.5.13.0, Culture=neutral, PublicKeyToken=5431ec61a7e925da]](Vortice.Vulkan.VkCommandBuffer, UInt32, UInt32, Vortice.Vulkan.VkViewport*)

I'll try with 1.5.15 and see if anything is different.

Migration to universal GLFW instead of Win32 only

I created 2 days ago a PR #24. Because of a new change two hours ago, the branch is now in conflict.

Because i did not got any feedback, my question is: Should i keep the PR up to date? A small feedback would be nice.

Is there any other way to contact you, like Discord or something else?

Libdl.dlopen

Seems wrong values for flags Libdl.RTLD_NOW and Libdl.RTLD_LOCAL on my linux system

shaderc_shared.dll is not found

shaderc_shared.dll is not found when compiling shaders. It was working on my development machine but not on a build server. I found that the code in LibraryLoader was not finding the file and falling back to the OS default and was finding it in the Vulkan SDK folder which is in PATH.

I verified this by using this code:

            IntPtr handle;
#if NETSTANDARD2_0
            handle = LoadPlatformLibrary(libraryPath);
#else
            handle = NativeLibrary.Load(libraryPath);
#endif

            if (handle == IntPtr.Zero)
                throw new DllNotFoundException($"Unable to load library '{libraryName}'.");

            var sbPath = new StringBuilder(1024);
            var count = Win32.GetModuleFileNameA(handle, sbPath, sbPath.Capacity);

            Console.WriteLine(sbPath);


            [DllImport(SystemLibrary, SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern int GetModuleFileNameA(IntPtr hModule, StringBuilder lpFileName, int nSize);

vmaMapMemory may be missing

My experience using these bindings was very smooth up until I had to map some memory allocated with VMA. I used Vma.vmaCreateBuffer to allocate a buffer, and I expected to find a function along the lines of Vma.vmaMapMemory that would allow me to map the buffer, like how VMA is used in C++. I couldn't find that function or any alternative. Is this function missing or is there another way to do this? Thanks!

Edit:
I also couldn't find the corresponding vmaUnmapMemory.

VkAccelerationStructureMatrixMotionInstanceNV is a bit-field structure

auto size_cpp = sizeof(VkAccelerationStructureMatrixMotionInstanceNV);
size_cpp == 112

var vortice_s = sizeof(Vortice.Vulkan.VkAccelerationStructureMatrixMotionInstanceNV);
vortice_s == 120

typedef struct VkAccelerationStructureMatrixMotionInstanceNV {
    VkTransformMatrixKHR          transformT0;
    VkTransformMatrixKHR          transformT1;
    uint32_t                      instanceCustomIndex:24;
    uint32_t                      mask:8;
    uint32_t                      instanceShaderBindingTableRecordOffset:24;
    VkGeometryInstanceFlagsKHR    flags:8;
    uint64_t                      accelerationStructureReference;
} 

The struct might be handled manually

// Handled manually.
if (cppClass.Name == "VkClearColorValue"
    || cppClass.Name == "VkTransformMatrixKHR"
    || cppClass.Name == "VkAccelerationStructureInstanceKHR"
    )
{
    continue;
}

The struct "VkAccelerationStructureSRTMotionInstanceNV" has similar problem;

How to set VkDebugUtilsMessengerCreateInfoEXT.pfnUserCallback in netstandard2.0

How do you set VkDebugUtilsMessengerCreateInfoEXT.pfnUserCallback?

I was previously using 1.3.4 and updated to 1.3.16. I was using Marshal.GetFunctionPointerForDelegate() on a delegate of type vkDebugUtilsMessengerCallbackEXT but that is not possible anymore.

If I copy the new struct into my code it won't event compile

	[StructLayout(LayoutKind.Sequential)]
	public partial struct VkDebugUtilsMessengerCreateInfoEXT
	{
		public VkStructureType sType;
		public unsafe void* pNext;
		public VkDebugUtilsMessengerCreateFlagsEXT flags;
		public VkDebugUtilsMessageSeverityFlagsEXT messageSeverity;
		public VkDebugUtilsMessageTypeFlagsEXT messageType;
		#if NETSTANDARD2_0
		public unsafe delegate* unmanaged[Stdcall]<VkDebugUtilsMessageSeverityFlagsEXT, VkDebugUtilsMessageTypeFlagsEXT, VkDebugUtilsMessengerCallbackDataEXT*, void*, uint> pfnUserCallback;
		#else
		public unsafe delegate* unmanaged<VkDebugUtilsMessageSeverityFlagsEXT, VkDebugUtilsMessageTypeFlagsEXT, VkDebugUtilsMessengerCallbackDataEXT*, void*, uint> pfnUserCallback;
		#endif
		public unsafe void* pUserData;
	}

error CS8370: Feature 'function pointers' is not available in C# 7.3. Please use language version 9.0 or greater.

My project target
<TargetFrameworks>netstandard2.0</TargetFrameworks>

which finally gets referenced in a project with
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>

BTW, thanks for adding netstandard2.0 back in. I was having trouble updating to net5 since all my dependencies haven't caught up yet.

Android support?

Hi,
I was unable to get Android Vulkan code working with Vortice.Vulkan. However, if I comment out the dlerror() call in the UnixLoader.LoadNativeLibrary method then it works without problem (see the commit in https://github.com/taumuon/Vortice.Vulkan ).

Is there a reason this call is there? Can it be fixed (I have forked Vortice.Vulkan to make this change but I'd prefer to reference the official version on Nuget).

The sample code is here: https://github.com/taumuon/TexturedCube-Vortice

Thanks,

Gary

VMA with Silk.NET keeps crashing

Hello. I am trying to use your VMA and shaderc bindings, but I keep getting my app crashing. I use Silk.NET as vulkan api wrapper, and unfortunately right now I am already super invested in it to make the change. I am trying to just create an allocator and it keeps crashing on me.

In Silk.NET .Handle is actually the real value of the object, as it would be in C. I am sending these to vmaCreateAllocator, and it keeps on crashing in "OnDllImport" callback. It gets here

if (libraryName.Equals(LibName) && TryResolveVMA(assembly, searchPath, out nativeLibrary)) { return nativeLibrary; }

All I do on my side is this:

VmaAllocatorCreateInfo allocatorCreateInfo; allocatorCreateInfo.vulkanApiVersion = VkVersion.Version_1_2; allocatorCreateInfo.physicalDevice = pdev.Handle; allocatorCreateInfo.device = dev.Handle; allocatorCreateInfo.instance = instance.Handle; VmaAllocator allocator; vmaCreateAllocator(&allocatorCreateInfo, &allocator).CheckResult();

and respectively before (successfully!!!) initializing vulkan, which runs without any validation errors. I am quite helpless with what might be going on. This is on Linux operating system, more specifically on Pop_OS!

Segmentation fault

[05:45:59 DBG] App run
[05:46:00 DBG] Glfw inited
[05:46:00 DBG] Vulkan supported
[05:46:00 DBG] vulkan lib initialized
[05:46:00 DBG] vk instance creating...
[05:46:00 DBG] vk instance created
[05:46:00 DBG] vk instance loading...
[05:46:00 DBG] vk instance loaded
[05:46:00 DBG] instance created
[05:46:00 DBG] surface created
[05:46:00 DBG] device picked
[05:46:00 DBG] logical device created
[05:46:00 DBG] swapchain created
[05:46:00 DBG] imageViews created
[05:46:00 DBG] render pass created
[05:46:00 DBG] buffers created
[05:46:00 DBG] command pool created
[05:46:00 DBG] command buffers created
[05:46:00 DBG] descriptor sets created
[05:46:00 DBG] read shader bytes...
[05:46:00 DBG] shader bytes readed
[05:46:00 DBG] shader models created
[05:46:00 DBG] graphics pipeline layout creating...
[05:46:00 DBG] graphics pipeline layout created
[05:46:00 DBG] graphics pipeline creating...
Segmentation fault

my application runs fine on windows, but on linux there is a memory error when creating a graphical pipeline:
Vulkan.VkCreateGraphicsPipeline

How to compile/ initial set up error

When trying to build/set up this Vulkan I get: error MSB4237: The SDK resolver
type "DotNetMSBuildSdkResolver" failed to load. The type initializer for 'Microsoft.DotNet.MSBuildSdkResolver.VSSettin
gs' threw an exception. And I don't what to do.

Methods missing in 1.3.16 after updating from 1.3.4

I updated from 1.3.4 to 1.3.16 and a few methods no longer exist. The return is no longer an out parameter.

Old signature (1.3.4)

public static VkResult vkAllocateCommandBuffers(VkDevice device, VkCommandBufferAllocateInfo* allocateInfo, out VkCommandBuffer commandBuffers);
public static VkResult vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, VkComputePipelineCreateInfo createInfo, out VkPipeline pipeline);
public static VkResult vkCreateGraphicsPipeline(VkDevice device, VkPipelineCache pipelineCache, VkGraphicsPipelineCreateInfo createInfo, out VkPipeline pipeline);

New signature (1.3.16)

public static VkResult vkAllocateCommandBuffers(VkDevice device, VkCommandBufferAllocateInfo* allocateInfo, VkCommandBuffer* commandBuffers);
public static VkResult vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, VkComputePipelineCreateInfo createInfo, VkPipeline* pipeline);
public static VkResult vkCreateGraphicsPipeline(VkDevice device, VkPipelineCache pipelineCache, VkGraphicsPipelineCreateInfo createInfo, VkPipeline* pipeline);

Proposed signature

public static VkResult vkAllocateCommandBuffer(VkDevice device, VkCommandBufferAllocateInfo* allocateInfo, out VkCommandBuffer commandBuffer);
public static VkResult vkCreateComputePipeline(VkDevice device, VkPipelineCache pipelineCache, VkComputePipelineCreateInfo createInfo, out VkPipeline pipeline);
public static VkResult vkCreateGraphicsPipeline(VkDevice device, VkPipelineCache pipelineCache, VkGraphicsPipelineCreateInfo createInfo, out VkPipeline pipeline);

Can these methods be added back in?

vkBeginCommandBuffer flags parameter ignored in helper function

vkBeginCommandBuffer takes in flags, but then just sets OneTimeSubmit anyway?

public static VkResult vkBeginCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferUsageFlags flags)
{
VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo
{
sType = VkStructureType.CommandBufferBeginInfo,
flags = VkCommandBufferUsageFlags.OneTimeSubmit
};
return vkBeginCommandBuffer(commandBuffer, &beginInfo);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.