LightVK - A Vulkan C# low-level bindings
$ dotnet add package LightVKLightVK is a lightweight set of low-level Vulkan bindings for C#, automatically generated from the official vk.xml specification. It provides C# developers with near-native performance access to Vulkan APIs.
For the complex procedural steps of Vulkan, LightVK offers lightweight abstract encapsulation that simplifies development while preserving native flexibility.
Wiki: https://deepwiki.com/unknowall/LightVK
# Clone the repository
git clone https://github.com/unknowall/LightVK.git
# Navigate to the project directory
cd LightVK
# Compile
dotnet build LightVK.sln
using LightVK;
using static LightVK.VulkanDevice;
using static LightVK.VulkanNative;
// Create a Vulkan device instance
var device = new VulkanDevice();
// Initialize the device (Windows platform example)
IntPtr windowHandle = /* Your window handle */;
IntPtr instanceHandle = /* Your instance handle */;
...
// 2. Initialize VulkanDevice
device.VulkanInit(windowHandle, instanceHandle, enableValidation: true);
...
// 3. Create RenderPass
_renderPass = _device.CreateRenderPass(
_device.ChooseSurfaceFormat().format,
VkAttachmentLoadOp.VK_ATTACHMENT_LOAD_OP_CLEAR,
VkImageLayout.VK_IMAGE_LAYOUT_UNDEFINED,
VkImageLayout.VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
...
// 4. Create SwapChain
_swapChain = _device.CreateSwapChain(_renderPass, 800, 600);
...
// 5. Create Vertex Buffer
var vertices = new[]
{
new Vertex(-0.5f, -0.5f, 1.0f, 0.0f, 0.0f), // Red
new Vertex(0.5f, -0.5f, 0.0f, 1.0f, 0.0f), // Green
new Vertex(0.0f, 0.5f, 0.0f, 0.0f, 1.0f) // Blue
};
vertexBuffer = _device.CreateBuffer( (ulong)(vertices.Length * Marshal.SizeOf<Vertex>()),
VkBufferUsageFlags.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VkBufferUsageFlags.VK_BUFFER_USAGE_TRANSFER_DST_BIT);
......
The project includes a built-in VulkanDevice demo program that demonstrates the basic rendering process:
Demo project as the startup project| Module | Description |
|---|---|
| VulkanNative | Low-level API bindings (commands, enums, structs, etc.) |
| VulkanTypes | Basic data type encapsulation (VkExtent2D, VkRect2D, etc.) |
| VulkanDevice | Device management and resource encapsulation (render pipelines, swap chains, etc.) |
| VkGen | Tool to auto-generate binding code from vk.xml |
This project is open-source under the MIT License. See LICENSE.txt for details. Free for use, modification, and distribution (including commercial projects).
Contributions via PR or Issues are welcome:
Follow the existing code style, ensure cross-platform compatibility, and add comments/tests when necessary.