Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement creating acceleration structures on a Heap #316

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,14 @@ impl DeviceRef {
unsafe { msg_send![self, heapBufferSizeAndAlignWithLength: length options: options] }
}

/// Only available on macos(13.0), ios(16.0)
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
72 changes: 72 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 Expand Up @@ -197,6 +260,11 @@ impl HeapDescriptorRef {
unsafe { msg_send![self, hazardTrackingMode] }
}

/// Only available on macos(10.15), ios(13.0)
pub fn set_hazard_tracking_mode(&self, hazard_tracking_mode: MTLHazardTrackingMode) {
FlannyH marked this conversation as resolved.
Show resolved Hide resolved
unsafe { msg_send![self, setHazardTrackingMode: hazard_tracking_mode] }
}

/// Only available on macos(10.15), ios(13.0)
pub fn resource_options(&self) -> MTLResourceOptions {
unsafe { msg_send![self, resourceOptions] }
Expand All @@ -206,4 +274,8 @@ impl HeapDescriptorRef {
pub fn heap_type(&self) -> MTLHeapType {
unsafe { msg_send![self, type] }
}
/// Only available on macos(10.15), ios(13.0)
pub fn set_heap_type(&self, type_: MTLHeapType) {
unsafe { msg_send![self, setType: type_] }
}
}
Loading