https://github.com/ab4d/vma-cs
C# wrapper for the Vulkan Memory Allocator library
https://github.com/ab4d/vma-cs
Last synced: about 1 year ago
JSON representation
C# wrapper for the Vulkan Memory Allocator library
- Host: GitHub
- URL: https://github.com/ab4d/vma-cs
- Owner: ab4d
- License: mit
- Created: 2019-09-03T21:28:20.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-23T08:28:09.000Z (about 6 years ago)
- Last Synced: 2025-04-13T17:04:13.629Z (about 1 year ago)
- Language: C#
- Size: 402 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VMA-CS
C# wrapper for the Vulkan Memory Allocator (VMA) library
(https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
The Vulkan Memory Allocator (VMA) library provides a simple and easy to integrate API to help you allocate memory for Vulkan buffer and image storage.
This project contains a VMA.cs file that can be included in your project and provides a .Net wrapper for the native VMA library.
## Native VMA library
VMA library is originally defined in a single C++ header file (vk_mem_alloc.h). To use it in a .Net project, the library needs to be compiled into a native dll.
This project comes with a precompiled library for win-x86 and win-x64 (**see compile-vma folder**).
There are also instructions and windows bat files to compile newer versions of the library or versions with different #define options.
## Usage
To use the VMA library in a .Net project, copy the VMA.cs file from this project to your project.
Then add the native vk_mem_alloc.dll to the output path of your project (use the version for your target platform).
The following code shows a usage sample with VulkanSharp library (https://github.com/mono/VulkanSharp):
```csharp
private void TestVma(Device vulkanDevice, PhysicalDevice physicalDevice)
{
var vmaAllocatorCreateInfo = new VMA.VmaAllocatorCreateInfo()
{
device = ((IMarshalling)vulkanDevice).Handle,
physicalDevice = ((IMarshalling)physicalDevice).Handle
};
var result = (Vulkan.Result)VMA.vmaCreateAllocator(ref vmaAllocatorCreateInfo, out var allocatorPtr);
if (result != Result.Success)
{
// Cannot create VMA allocator
}
var allocatorCreateInfo = new VMA.VmaAllocationCreateInfo()
{
usage = VMA.VmaMemoryUsage.VMA_MEMORY_USAGE_GPU_ONLY
};
var bufferCreateInfo = new BufferCreateInfo()
{
Size = 65536,
Usage = BufferUsageFlags.VertexBuffer | BufferUsageFlags.TransferDst
};
result = (Vulkan.Result)VMA.vmaCreateBuffer(allocatorPtr, ((IMarshalling)bufferCreateInfo).Handle, ref allocatorCreateInfo, out var pBuffer, out var pAllocation, IntPtr.Zero);
if (result == Result.Success)
{
// Use the pBuffer ...
VMA.vmaDestroyBuffer(allocatorPtr, pBuffer, pAllocation); // Dispose pBuffer and pAllocation
}
VMA.vmaDestroyAllocator(allocatorPtr);
}
```
## Contributors
This project was created by Caleb Cornett (TheSpydog) - https://github.com/TheSpydog
The development is continued by Andrej Benedik (AB4D) - https://github.com/ab4d
AB4D company works on advanced 3D visualizations for .Net. See https://www.ab4d.com for more info.