Skip to content

Commit

Permalink
Implement creating acceleration structures on a Heap
Browse files Browse the repository at this point in the history
  • Loading branch information
FlannyH committed May 1, 2024
1 parent 75203a8 commit 03e6a01
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,13 @@ impl DeviceRef {
unsafe { msg_send![self, heapBufferSizeAndAlignWithLength: length options: options] }
}

pub fn heap_acceleration_structure_size_and_align_with_size(
&self,
size: NSUInteger,
) -> MTLSizeAndAlign {
unsafe { msg_send![self, heapAccelerationStructureSizeAndAlignWithSize: size] }
}

pub fn heap_texture_size_and_align(
&self,
descriptor: &TextureDescriptorRef,
Expand Down
63 changes: 63 additions & 0 deletions src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,69 @@ impl HeapRef {
}
}
}

/// Only available on macOS 13.0+ & iOS 16.0+
pub fn new_acceleration_structure_with_descriptor(
&self,
descriptor: &AccelerationStructureDescriptorRef,
) -> Option<AccelerationStructure> {
unsafe {
let ptr: *mut MTLAccelerationStructure =
msg_send![self, newAccelerationStructureWithDescriptor: descriptor];
if !ptr.is_null() {
Some(AccelerationStructure::from_ptr(ptr))
} else {
None
}
}
}

/// Only available on macOS 13.0+ & iOS 16.0+
pub fn new_acceleration_structure_with_descriptor_offset(
&self,
descriptor: &AccelerationStructureDescriptorRef,
offset: u64,
) -> Option<AccelerationStructure> {
unsafe {
let ptr: *mut MTLAccelerationStructure = msg_send![self, newAccelerationStructureWithDescriptor:descriptor
offset:offset];
if !ptr.is_null() {
Some(AccelerationStructure::from_ptr(ptr))
} else {
None
}
}
}

/// Only available on macOS 13.0+ & iOS 16.0+
pub fn new_acceleration_structure_with_size(&self, size: u64) -> Option<AccelerationStructure> {
unsafe {
let ptr: *mut MTLAccelerationStructure =
msg_send![self, newAccelerationStructureWithSize:size];
if !ptr.is_null() {
Some(AccelerationStructure::from_ptr(ptr))
} else {
None
}
}
}

/// Only available on macOS 13.0+ & iOS 16.0+
pub fn new_acceleration_structure_with_size_offset(
&self,
size: u64,
offset: u64,
) -> Option<AccelerationStructure> {
unsafe {
let ptr: *mut MTLAccelerationStructure = msg_send![self, newAccelerationStructureWithSize:size
offset:offset];
if !ptr.is_null() {
Some(AccelerationStructure::from_ptr(ptr))
} else {
None
}
}
}
}

/// See <https://developer.apple.com/documentation/metal/mtlheapdescriptor/>
Expand Down

0 comments on commit 03e6a01

Please sign in to comment.