From 8fe781b92694c4af5d622dc82e676d39776cecd6 Mon Sep 17 00:00:00 2001 From: jasper Date: Mon, 14 Oct 2024 20:46:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8B=20Simplify=20the=20metal=20=20inte?= =?UTF-8?q?rface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/metal/mod.rs | 53 ++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/src/metal/mod.rs b/src/metal/mod.rs index aa10980..5c1c360 100644 --- a/src/metal/mod.rs +++ b/src/metal/mod.rs @@ -39,55 +39,24 @@ pub struct Allocation { } impl Allocation { - pub fn heap(&self) -> &ProtocolObject { + /// Return the backing heap for this allocation + pub unsafe fn heap(&self) -> &ProtocolObject { &self.heap } - pub fn make_buffer(&self) -> Option>> { - let resource = unsafe { - self.heap.newBufferWithLength_options_offset( - self.size as usize, - self.heap.resourceOptions(), - self.offset as usize, - ) - }; - if let Some(resource) = &resource { - if let Some(name) = &self.name { - resource.setLabel(Some(&NSString::from_str(name))); - } - } - resource + /// Returns the size of the allocation + pub fn size(&self) -> u64 { + self.size } - pub fn make_texture( - &self, - desc: &MTLTextureDescriptor, - ) -> Option>> { - let resource = unsafe { - self.heap - .newTextureWithDescriptor_offset(desc, self.offset as usize) - }; - if let Some(resource) = &resource { - if let Some(name) = &self.name { - resource.setLabel(Some(&NSString::from_str(name))); - } - } - resource + /// Returns the offset of the allocation on the [`ID3D12Heap`]. + /// When creating a placed resources, this offset needs to be supplied as well. + pub fn offset(&self) -> u64 { + self.offset } - pub fn make_acceleration_structure( - &self, - ) -> Option>> { - let resource = unsafe { - self.heap - .newAccelerationStructureWithSize_offset(self.size as usize, self.offset as usize) - }; - if let Some(resource) = &resource { - if let Some(name) = &self.name { - resource.setLabel(Some(&NSString::from_str(name))); - } - } - resource + pub fn name(&self) -> Option<&str> { + self.name.as_ref().map(|s| s.as_ref()) } fn is_null(&self) -> bool {