Skip to content

Commit

Permalink
refactor: swap ash for vulkanalia (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
msuess committed May 27, 2024
1 parent 018a0da commit 740d4b4
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 423 deletions.
114 changes: 0 additions & 114 deletions CHANGES.md

This file was deleted.

30 changes: 17 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "vk-mem"
version = "0.4.0"
authors = ["Graham Wihlidal <[email protected]>", "Zhixing Zhang <[email protected]>"]
description = "Rust ffi bindings and idiomatic wrapper for AMD Vulkan Memory Allocator (VMA)"
homepage = "https://github.com/gwihlidal/vk-mem-rs"
repository = "https://github.com/gwihlidal/vk-mem-rs"
documentation = "https://docs.rs/vk-mem"
name = "vk-mem-vulkanalia"
version = "0.1.0+vk-mem-0.4.0"
authors = ["Marco Süß <[email protected]>"]
description = "Rust ffi bindings and idiomatic wrapper for AMD Vulkan Memory Allocator (VMA) using vulkanalia instead of ash. Fork of vk-mem."
homepage = "https://github.com/msuess/vk-mem-vulkanalia"
repository = "https://github.com/msuess/vk-mem-vulkanalia"
documentation = "https://docs.rs/vk-mem-vulkanalia"
readme = "README.md"
keywords = ["vulkan", "vk", "ash", "memory", "allocator"]
keywords = ["vulkan", "vk", "vulkanalia", "memory", "allocator"]
categories = ["api-bindings", "rendering", "rendering::engine", "rendering::graphics-api", ]
license = "MIT/Apache-2.0"
build = "build.rs"
Expand All @@ -22,12 +22,15 @@ include = [
edition = "2021"

[badges]
travis-ci = { repository = "gwihlidal/vk-mem-rs" }
maintenance = { status = "actively-developed" }

[dependencies]
ash = { version = "0.38", default-features = false }
bitflags = "2.5"
vulkanalia = { version = "0.23.0", default-features = false }
vulkanalia-sys = { version = "0.23.0", default-features = false }

[dev-dependencies]
vulkanalia = { version = "0.23.0", features = ["libloading", "provisional"] }

[build-dependencies]
cc = "1.0"
Expand All @@ -42,8 +45,9 @@ opt-level = 3
codegen-units = 1

[features]
default = ["loaded"]
default = ["std", "libloading"]
generate_bindings=["bindgen"]
linked=["ash/linked"]
loaded=["ash/loaded"]
libloading=["vulkanalia/libloading"]
recording=[]
std=["vulkanalia/std", "vulkanalia-sys/std"]
no_std_error=["vulkanalia/no_std_error", "vulkanalia-sys/no_std_error"]
58 changes: 24 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
vk-mem
========
# vk-mem-vulkanalia

[![vk-mem on travis-ci.com](https://travis-ci.com/gwihlidal/vk-mem-rs.svg?branch=master)](https://travis-ci.com/gwihlidal/vk-mem-rs)
[![Latest version](https://img.shields.io/crates/v/vk-mem.svg)](https://crates.io/crates/vk-mem)
[![Documentation](https://docs.rs/vk-mem/badge.svg)](https://docs.rs/vk-mem)
[![Lines of Code](https://tokei.rs/b1/github/gwihlidal/vk-mem-rs)](https://github.com/gwihlidal/vk-mem-rs)
[![Latest version](https://img.shields.io/crates/v/vk-mem-vulkanalia.svg)](https://crates.io/crates/vk-mem-vulkanalia)
[![Documentation](https://docs.rs/vk-mem/badge.svg)](https://docs.rs/vk-mem-vulkanalia)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![APACHE2](https://img.shields.io/badge/license-APACHE2-blue.svg)

This crate provides an FFI layer and idiomatic rust wrappers for the excellent AMD Vulkan Memory Allocator (VMA) C/C++ library.
This crate is a fork of [vk-mem](https://crates.io/vk-mem) using [vulkanalia](https://crates.io/vulkanalia) instead of [ash](https://crates.io/ash). It provides an FFI layer and idiomatic rust wrappers for the excellent AMD Vulkan Memory Allocator (VMA) C/C++ library.

- [Documentation](https://docs.rs/vk-mem)
- [Release Notes](https://github.com/gwihlidal/vk-mem-rs/releases)
- [Documentation](https://docs.rs/vk-mem-vulkanalia)
- [Release Notes](https://github.com/msuess/vk-mem-vulkanalia/releases)
- [vk-mem GitHub](https://github.com/gwihlidal/vk-mem-rs)
- [VMA GitHub](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
- [VMA Documentation](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/)
- [GPU Open Announce](https://gpuopen.com/gaming-product/vulkan-memory-allocator/)
Expand Down Expand Up @@ -79,45 +77,44 @@ Additional features:

- Extensive unit tests and examples.
- Some unit tests already, but not full coverage
- Example isn't written - likely will port the VMA sample to `ash` and `vk_mem`
- Example isn't written - likely will port the VMA sample to `vulkanalia` and `vk_mem_vulkanalia`
- Record and replay allocations, for in-depth analysis of memory usage, resource transitions, etc
- Check for correctness, measure performance, and gather statistics.

## Example

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:
After you create a `vk_mem_vulkanalia::Allocator` instance, very little code is needed to create a buffer:

```rust
// Create the buffer (GPU only, 16KiB in this example)
let create_info = vk_mem::AllocationCreateInfo {
usage: vk_mem::MemoryUsage::GpuOnly,
let create_info = vk_mem_vulkanalia::AllocationCreateInfo {
usage: vk_mem_vulkanalia::MemoryUsage::GpuOnly,
..Default::default()
};

let (buffer, allocation, allocation_info) = allocator
.create_buffer(
&ash::vk::BufferCreateInfo::builder()
&vulkanalia::vk::BufferCreateInfo::builder()
.size(16 * 1024)
.usage(ash::vk::BufferUsageFlags::VERTEX_BUFFER | ash::vk::BufferUsageFlags::TRANSFER_DST)
.build(),
.usage(vulkanalia::vk::BufferUsageFlags::VERTEX_BUFFER | vulkanalia::vk::BufferUsageFlags::TRANSFER_DST),
&create_info,
)
.unwrap();

// Do stuff with buffer! (type is ash::vk::Buffer)
// Do stuff with buffer! (type is vulkanalia::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.
- `vulkanalia::vk::Buffer` (`VkBuffer`) is created.
- `vulkanalia::vk::DeviceMemory` (`VkDeviceMemory`) block is allocated if needed.
- An unused region of the memory block is bound to this buffer.
- `vk_mem::Allocation` is created that represents memory assigned to this buffer. It can be queried for parameters like Vulkan memory handle and offset.
- `vk_mem_vulkanalia::Allocation` is created that represents memory assigned to this buffer. It can be queried for parameters like Vulkan memory handle and offset.

## MoltenVK

Expand All @@ -137,13 +134,13 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
vk-mem = "0.3.0"
vk-mem-vulkanalia = "0.1.0+vk-mem-0.4.0"
```

and add this to your crate root:

```rust
extern crate vk_mem;
extern crate vk_mem_vulkanalia;
```

## Compiling using MinGW W64
Expand Down Expand Up @@ -171,26 +168,19 @@ at your option.
## Credits and Special Thanks

- [Adam Sawicki - AMD](https://github.com/adam-sawicki-amd) (Author of C/C++ library)
- [Maik Klein](https://github.com/MaikKlein) (Author of ash - Vulkan rust bindings)
- [Johan Andersson](https://github.com/repi) (Contributions)
- [Patrick Minogue](https://github.com/afpatmin) (Contributions)
- [Layl Conway](https://github.com/LaylConway) (Contributions)
- [aloucks](https://github.com/aloucks) (Contributions)
- [Henrik Rydgård](https://github.com/hrydgard) (Contributions)
- [msiglreith](https://github.com/msiglreith) (Contributions)
- [Maksym Pavlenko](https://github.com/mxpv) (Contributions)
- [Brandon Pollack](https://github.com/brandonpollack23) (Contributions)
- [Kyle Mayes](https://github.com/KyleMayes) (Author of vulkanalia - Vulkan rust bindings)
- [Graham Wihlidal](https://github.com/gwihlidal) (Author of vk-mem)

## Contribution

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](https://github.com/gwihlidal/vk-mem-rs/issues) to see what known improvements are documented.
Contributions are always welcome; please look at the [issue tracker](https://github.com/msuess/vk-mem-vulkanalia/issues) to see what known improvements are documented.

## Code of Conduct

Contribution to the vk-mem crate is organized under the terms of the
Contributor Covenant, the maintainer of vk-mem, @Neo-Zhixing, promises to
Contribution to the vk-mem-vulkanalia crate is organized under the terms of the
Contributor Covenant, the maintainer of vk-mem-vulkanalia, @msuess, promises to
intervene to uphold that code of conduct.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fn main() {
#[cfg(not(debug_assertions))]
build.define("NDEBUG", "");

// We want to use the loader in ash, instead of requiring us to link
// in vulkan.dll/.dylib in addition to ash. This is especially important
// We want to use the loader in vulkanalia, instead of requiring us to link
// in vulkan.dll/.dylib in addition to vulkanalia. This is especially important
// for MoltenVK, where there is no default installation path, unlike
// Linux (pkconfig) and Windows (VULKAN_SDK environment variable).
build.define("VMA_STATIC_VULKAN_FUNCTIONS", "0");

// This prevents VMA from trying to fetch any remaining pointers
// that are still null after using the loader in ash, which can
// that are still null after using the loader in vulkanalia, which can
// cause linker errors.
build.define("VMA_DYNAMIC_VULKAN_FUNCTIONS", "0");

Expand Down
4 changes: 2 additions & 2 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate ash;
extern crate vk_mem;
extern crate vulkanalia;
extern crate vk_mem_vulkanalia;

/*
use ash::extensions::DebugReport;
Expand Down
Loading

0 comments on commit 740d4b4

Please sign in to comment.