diff --git a/README.md b/README.md index 36182b1..ac87130 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ gpu-allocator = "0.25.0" ![Visualizer](visualizer.png) -This crate provides a fully written in Rust memory allocator for Vulkan and DirectX 12. +This crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal. ## [Windows-rs] and [winapi] @@ -130,9 +130,40 @@ drop(resource); allocator.free(allocation).unwrap(); ``` +## Setting up the Metal memory allocator + +```rust +use gpu_allocator::metal::*; + +let mut allocator = Allocator::new(&AllocatorCreateDesc { + device: device.clone(), + debug_settings: Default::default(), + allocation_sizes: Default::default(), +}); +``` + +## Simple Metal allocation example +```rust +use gpu_allocator::metal::*; +use gpu_allocator::MemoryLocation; + +let allocation_desc = AllocationCreateDesc::buffer( + &device, + "Example allocation", + 512, // size in bytes + gpu_allocator::MemoryLocation::GpuOnly, +); +let allocation = allocator.allocate(&allocation_desc).unwrap(); +let resource = allocation.make_buffer().unwrap(); + +// Cleanup +drop(resource); +allocator.free(&allocation).unwrap(); +``` + ## Minimum Supported Rust Version -The MSRV for this crate and the `vulkan` and `d3d12` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI. +The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI. ## License diff --git a/README.tpl b/README.tpl index ca9388c..b8acff5 100644 --- a/README.tpl +++ b/README.tpl @@ -21,7 +21,7 @@ gpu-allocator = "0.25.0" ## Minimum Supported Rust Version -The MSRV for this crate and the `vulkan` and `d3d12` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI. +The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.65. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI. ## License diff --git a/src/lib.rs b/src/lib.rs index 52f5301..0274485 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! This crate provides a fully written in Rust memory allocator for Vulkan and DirectX 12. +//! This crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal. //! //! # [Windows-rs] and [winapi] //! @@ -155,6 +155,55 @@ //! # #[cfg(not(feature = "d3d12"))] //! # fn main() {} //! ``` +//! +//! # Setting up the Metal memory allocator +//! +//! ```no_run +//! # #[cfg(feature = "metal")] +//! # fn main() { +//! use gpu_allocator::metal::*; +//! +//! # let device = Arc::new(metal::Device::system_default().unwrap()); +//! let mut allocator = Allocator::new(&AllocatorCreateDesc { +//! device: device.clone(), +//! debug_settings: Default::default(), +//! allocation_sizes: Default::default(), +//! }); +//! # } +//! # #[cfg(not(feature = "metal"))] +//! # fn main() {} +//! ``` +//! +//! # Simple Metal allocation example +//! ```no_run +//! # #[cfg(feature = "metal")] +//! # fn main() { +//! use gpu_allocator::metal::*; +//! use gpu_allocator::MemoryLocation; +//! # let device = Arc::new(metal::Device::system_default().unwrap()); +//! # let mut allocator = Allocator::new(&AllocatorCreateDesc { +//! # device: device.clone(), +//! # debug_settings: Default::default(), +//! # allocation_sizes: Default::default(), +//! # }) +//! # .unwrap(); +//! +//! let allocation_desc = AllocationCreateDesc::buffer( +//! &device, +//! "Example allocation", +//! 512, // size in bytes +//! gpu_allocator::MemoryLocation::GpuOnly, +//! ); +//! let allocation = allocator.allocate(&allocation_desc).unwrap(); +//! let resource = allocation.make_buffer().unwrap(); +//! +//! // Cleanup +//! drop(resource); +//! allocator.free(&allocation).unwrap(); +//! # } +//! # #[cfg(not(feature = "metal"))] +//! # fn main() {} +//! ``` mod result; pub use result::*;