Skip to content

Commit 5309914

Browse files
authored
📝 Add metal to README.md (#211)
* Add Metal example to README.md * Add missing rust tag to code block * Mention metal in descriptions * Move changes to lib.rs and README.tpl * Fix errors
1 parent 0f47e8e commit 5309914

3 files changed

Lines changed: 84 additions & 4 deletions

File tree

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gpu-allocator = "0.25.0"
1717

1818
![Visualizer](visualizer.png)
1919

20-
This crate provides a fully written in Rust memory allocator for Vulkan and DirectX 12.
20+
This crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal.
2121

2222
## [Windows-rs] and [winapi]
2323

@@ -130,9 +130,40 @@ drop(resource);
130130
allocator.free(allocation).unwrap();
131131
```
132132

133+
## Setting up the Metal memory allocator
134+
135+
```rust
136+
use gpu_allocator::metal::*;
137+
138+
let mut allocator = Allocator::new(&AllocatorCreateDesc {
139+
device: device.clone(),
140+
debug_settings: Default::default(),
141+
allocation_sizes: Default::default(),
142+
});
143+
```
144+
145+
## Simple Metal allocation example
146+
```rust
147+
use gpu_allocator::metal::*;
148+
use gpu_allocator::MemoryLocation;
149+
150+
let allocation_desc = AllocationCreateDesc::buffer(
151+
&device,
152+
"Example allocation",
153+
512, // size in bytes
154+
gpu_allocator::MemoryLocation::GpuOnly,
155+
);
156+
let allocation = allocator.allocate(&allocation_desc).unwrap();
157+
let resource = allocation.make_buffer().unwrap();
158+
159+
// Cleanup
160+
drop(resource);
161+
allocator.free(&allocation).unwrap();
162+
```
163+
133164
## Minimum Supported Rust Version
134165

135-
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.
166+
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.
136167

137168
## License
138169

README.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ gpu-allocator = "0.25.0"
2121

2222
## Minimum Supported Rust Version
2323

24-
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.
24+
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.
2525

2626
## License
2727

src/lib.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This crate provides a fully written in Rust memory allocator for Vulkan and DirectX 12.
1+
//! This crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal.
22
//!
33
//! # [Windows-rs] and [winapi]
44
//!
@@ -155,6 +155,55 @@
155155
//! # #[cfg(not(feature = "d3d12"))]
156156
//! # fn main() {}
157157
//! ```
158+
//!
159+
//! # Setting up the Metal memory allocator
160+
//!
161+
//! ```no_run
162+
//! # #[cfg(feature = "metal")]
163+
//! # fn main() {
164+
//! use gpu_allocator::metal::*;
165+
//!
166+
//! # let device = Arc::new(metal::Device::system_default().unwrap());
167+
//! let mut allocator = Allocator::new(&AllocatorCreateDesc {
168+
//! device: device.clone(),
169+
//! debug_settings: Default::default(),
170+
//! allocation_sizes: Default::default(),
171+
//! });
172+
//! # }
173+
//! # #[cfg(not(feature = "metal"))]
174+
//! # fn main() {}
175+
//! ```
176+
//!
177+
//! # Simple Metal allocation example
178+
//! ```no_run
179+
//! # #[cfg(feature = "metal")]
180+
//! # fn main() {
181+
//! use gpu_allocator::metal::*;
182+
//! use gpu_allocator::MemoryLocation;
183+
//! # let device = Arc::new(metal::Device::system_default().unwrap());
184+
//! # let mut allocator = Allocator::new(&AllocatorCreateDesc {
185+
//! # device: device.clone(),
186+
//! # debug_settings: Default::default(),
187+
//! # allocation_sizes: Default::default(),
188+
//! # })
189+
//! # .unwrap();
190+
//!
191+
//! let allocation_desc = AllocationCreateDesc::buffer(
192+
//! &device,
193+
//! "Example allocation",
194+
//! 512, // size in bytes
195+
//! gpu_allocator::MemoryLocation::GpuOnly,
196+
//! );
197+
//! let allocation = allocator.allocate(&allocation_desc).unwrap();
198+
//! let resource = allocation.make_buffer().unwrap();
199+
//!
200+
//! // Cleanup
201+
//! drop(resource);
202+
//! allocator.free(&allocation).unwrap();
203+
//! # }
204+
//! # #[cfg(not(feature = "metal"))]
205+
//! # fn main() {}
206+
//! ```
158207
159208
mod result;
160209
pub use result::*;

0 commit comments

Comments
 (0)