Skip to content

Commit

Permalink
Add skeleton for Metal Allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
FlannyH committed Jan 25, 2024
1 parent ba273bc commit 29ff2af
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ ash = { version = ">=0.34, <=0.37", optional = true, default-features = false, f
egui = { version = "0.24", optional = true, default-features = false }
egui_extras = { version = "0.24", optional = true, default-features = false }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
metal = { version = "0.27.0", default-features = false, features = [
"link",
"dispatch",
] }

[target.'cfg(windows)'.dependencies]
# Only needed for public-winapi interop helpers
winapi = { version = "0.3.9", features = ["d3d12", "winerror", "impl-default", "impl-debug"], optional = true }
Expand Down Expand Up @@ -88,3 +94,6 @@ d3d12 = ["windows"]
public-winapi = ["dep:winapi"]

default = ["d3d12", "vulkan"]

[patch.crates-io]
metal = { git = "https://github.com/Traverse-Research/metal-rs", rev = "d40f71a" }
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ pub mod vulkan;
#[cfg(all(windows, feature = "d3d12"))]
pub mod d3d12;

// todo(lily): add a feature toggle for metal?
#[cfg(all(any(target_os = "macos", target_os = "ios")))]
pub mod metal;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum MemoryLocation {
/// The allocated resource is stored at an unknown memory location; let the driver decide what's the best location
Expand Down
37 changes: 37 additions & 0 deletions src/metal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![deny(clippy::unimplemented, clippy::unwrap_used, clippy::ok_expect)]
use crate::Result;
use log::Level;

pub struct Allocation {}
pub struct AllocationCreateDesc {}
pub struct Allocator {}
pub struct AllocatorCreateDesc {}
pub struct ResourceCreateDesc {}
pub struct Resource {}

impl Allocator {
pub fn device(&self) -> &metal::Device {
todo!()
}
pub fn new(_desc: &AllocatorCreateDesc) -> Result<Self> {
todo!()
}
pub fn allocate(&mut self, _desc: &AllocationCreateDesc) -> Result<Allocation> {
todo!()
}
pub fn free(&mut self, _allocation: Allocation) -> Result<()> {
todo!()
}
pub fn rename_allocation(&mut self, _allocation: &mut Allocation, _name: &str) -> Result<()> {
todo!()
}
pub fn report_memory_leaks(&self, _log_level: Level) {
todo!()
}
pub fn create_resource(&mut self, _desc: &ResourceCreateDesc) -> Result<Resource> {
todo!()
}
pub fn free_resource(&mut self, mut _resource: Resource) -> Result<()> {
todo!()
}
}

0 comments on commit 29ff2af

Please sign in to comment.