Crates.io | vk-mem-3-erupt |
lib.rs | vk-mem-3-erupt |
version | 0.6.0+708428c2-2023-02-02 |
source | src |
created_at | 2022-10-30 13:31:12.247747 |
updated_at | 2023-02-10 14:54:52.284814 |
description | Rust ffi bindings and idiomatic wrapper for AMD Vulkan Memory Allocator (VMA) using erupt. |
homepage | https://github.com/eigenraven/vk-mem-3-erupt |
repository | https://github.com/eigenraven/vk-mem-3-erupt |
max_upload_size | |
id | 701467 |
size | 1,892,790 |
Please make an issue/PR if the crate is out of date and I haven't updated it yet.
This is a fork of Graham Wihlidal's vk-mem-rs, but using erupt instead of ash for Vulkan bindings. All work on this crate is therefore performed by Graham Wihlidal and the team behind the VMA library. I merely modified the crate such that it can be used in conjunction with the erupt Vulkan bindings.
This crate provides an FFI layer and idiomatic rust wrappers for the excellent AMD Vulkan Memory Allocator (VMA) C/C++ library.
Memory allocation and resource (buffer and image) creation in Vulkan is difficult (comparing to older graphics API-s, like D3D11 or OpenGL) for several reasons:
This crate can help game developers to manage memory allocations and resource creation by offering some higher-level functions:
Additional features:
nonCoherentAtomSize
is respected automatically.ash
and vk_mem
Basic usage of this crate is very simple; advanced features are optional.
After you create a vk_mem::Allocator
instance, very little code is needed to create a buffer:
// Create the buffer (GPU only, 16KiB in this example)
let create_info = vk_mem::AllocationCreateInfo {
usage: vk_mem::MemoryUsage::GpuOnly,
..Default::default()
};
let (buffer, allocation, allocation_info) = allocator
.create_buffer(
&ash::vk::BufferCreateInfo::builder()
.size(16 * 1024)
.usage(ash::vk::BufferUsageFlags::VERTEX_BUFFER | ash::vk::BufferUsageFlags::TRANSFER_DST)
.build(),
&create_info,
)
.unwrap();
// Do stuff with buffer! (type is ash::vk::Buffer)
// Destroy the buffer
allocator.destroy_buffer(buffer, &allocation).unwrap();
With this one function call (vk_mem::Allocator::create_buffer
):
ash::vk::Buffer
(VkBuffer
) is created.ash::vk::DeviceMemory
(VkDeviceMemory
) block is allocated if needed.vk_mem::Allocation
is created that represents memory assigned to this buffer. It can be queried for parameters like Vulkan memory handle and offset.For MoltenVK on macOS, you need to have the proper environment variables set. Something like:
export SDK_PATH=/path/to/vulkansdk-macos-1.1.106.0
export DYLD_LIBRARY_PATH=$SDK_PATH/macOS/lib
export VK_ICD_FILENAMES=$SDK_PATH/macOS/etc/vulkan/icd.d/MoltenVK_icd.json
export VK_LAYER_PATH=$SDK_PATH/macOS/etc/vulkan/explicit_layer.d
cargo test
Add this to your Cargo.toml
:
[dependencies]
vk-mem-3-erupt = "0.4.0"
and add this to your crate root:
extern crate vk_mem;
Vulkan Memory Allocator requires C++11 threads. MinGW W64 does not support these by default, so you need to switch to the posix build. For example, on debian you need to run the following:
update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Contributions are always welcome; please look at the issue tracker to see what known improvements are documented.
Contribution to the vk-mem crate is organized under the terms of the Contributor Covenant, the maintainer of vk-mem, @gwihlidal, promises to intervene to uphold that code of conduct.