From a91fb3e977e4ab0d4054cb0db28a9f3e362a59e9 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 24 Sep 2024 23:21:09 -0700 Subject: [PATCH] Add AccelerationStructurePassDescriptor Also renames "accelerator_structure" module for consistency --- ...structure.rs => acceleration_structure.rs} | 0 src/acceleration_structure_pass.rs | 108 ++++++++++++++++++ src/commandbuffer.rs | 7 ++ src/device.rs | 5 +- src/encoder.rs | 6 +- src/lib.rs | 6 +- 6 files changed, 123 insertions(+), 9 deletions(-) rename src/{accelerator_structure.rs => acceleration_structure.rs} (100%) create mode 100644 src/acceleration_structure_pass.rs diff --git a/src/accelerator_structure.rs b/src/acceleration_structure.rs similarity index 100% rename from src/accelerator_structure.rs rename to src/acceleration_structure.rs diff --git a/src/acceleration_structure_pass.rs b/src/acceleration_structure_pass.rs new file mode 100644 index 0000000..b08156a --- /dev/null +++ b/src/acceleration_structure_pass.rs @@ -0,0 +1,108 @@ +use super::{CounterSampleBufferRef, NSUInteger}; + +/// See +pub enum MTLAccelerationStructurePassDescriptor {} + +foreign_obj_type! { + type CType = MTLAccelerationStructurePassDescriptor; + pub struct AccelerationStructurePassDescriptor; +} + +impl AccelerationStructurePassDescriptor { + /// Creates a default compute pass descriptor with no attachments. + pub fn new<'a>() -> &'a AccelerationStructurePassDescriptorRef { + unsafe { + msg_send![ + class!(MTLAccelerationStructurePassDescriptor), + accelerationStructurePassDescriptor + ] + } + } +} + +impl AccelerationStructurePassDescriptorRef { + pub fn sample_buffer_attachments( + &self, + ) -> &AccelerationStructurePassSampleBufferAttachmentDescriptorArrayRef { + unsafe { msg_send![self, sampleBufferAttachments] } + } +} + +/// See +pub enum MTLAccelerationStructurePassSampleBufferAttachmentDescriptorArray {} + +foreign_obj_type! { + type CType = MTLAccelerationStructurePassSampleBufferAttachmentDescriptorArray; + pub struct AccelerationStructurePassSampleBufferAttachmentDescriptorArray; +} + +impl AccelerationStructurePassSampleBufferAttachmentDescriptorArrayRef { + pub fn object_at( + &self, + index: NSUInteger, + ) -> Option<&AccelerationStructurePassSampleBufferAttachmentDescriptorRef> { + unsafe { msg_send![self, objectAtIndexedSubscript: index] } + } + + pub fn set_object_at( + &self, + index: NSUInteger, + attachment: Option<&AccelerationStructurePassSampleBufferAttachmentDescriptorRef>, + ) { + unsafe { + msg_send![self, setObject:attachment + atIndexedSubscript:index] + } + } +} + +/// See +pub enum MTLAccelerationStructurePassSampleBufferAttachmentDescriptor {} + +foreign_obj_type! { + type CType = MTLAccelerationStructurePassSampleBufferAttachmentDescriptor; + pub struct AccelerationStructurePassSampleBufferAttachmentDescriptor; +} + +impl AccelerationStructurePassSampleBufferAttachmentDescriptor { + pub fn new() -> Self { + let class = class!(MTLAccelerationStructurePassSampleBufferAttachmentDescriptor); + unsafe { msg_send![class, new] } + } +} + +impl AccelerationStructurePassSampleBufferAttachmentDescriptorRef { + pub fn sample_buffer(&self) -> &CounterSampleBufferRef { + unsafe { msg_send![self, sampleBuffer] } + } + + pub fn set_sample_buffer(&self, sample_buffer: &CounterSampleBufferRef) { + unsafe { msg_send![self, setSampleBuffer: sample_buffer] } + } + + pub fn start_of_encoder_sample_index(&self) -> NSUInteger { + unsafe { msg_send![self, startOfEncoderSampleIndex] } + } + + pub fn set_start_of_encoder_sample_index(&self, start_of_encoder_sample_index: NSUInteger) { + unsafe { + msg_send![ + self, + setStartOfEncoderSampleIndex: start_of_encoder_sample_index + ] + } + } + + pub fn end_of_encoder_sample_index(&self) -> NSUInteger { + unsafe { msg_send![self, endOfEncoderSampleIndex] } + } + + pub fn set_end_of_encoder_sample_index(&self, end_of_encoder_sample_index: NSUInteger) { + unsafe { + msg_send![ + self, + setEndOfEncoderSampleIndex: end_of_encoder_sample_index + ] + } + } +} diff --git a/src/commandbuffer.rs b/src/commandbuffer.rs index 26fea2e..a7c829c 100644 --- a/src/commandbuffer.rs +++ b/src/commandbuffer.rs @@ -154,6 +154,13 @@ impl CommandBufferRef { unsafe { msg_send![self, accelerationStructureCommandEncoder] } } + pub fn acceleration_structure_command_encoder_with_descriptor( + &self, + descriptor: &AccelerationStructurePassDescriptorRef, + ) -> &AccelerationStructureCommandEncoderRef { + unsafe { msg_send![self, accelerationStructureCommandEncoderWithDescriptor: descriptor] } + } + pub fn encode_signal_event(&self, event: &EventRef, new_value: u64) { unsafe { msg_send![self, diff --git a/src/device.rs b/src/device.rs index 12e43ae..330a013 100644 --- a/src/device.rs +++ b/src/device.rs @@ -2109,10 +2109,7 @@ impl DeviceRef { unsafe { msg_send![self, accelerationStructureSizesWithDescriptor: desc] } } - pub fn new_acceleration_structure_with_size( - &self, - size: NSUInteger, - ) -> accelerator_structure::AccelerationStructure { + pub fn new_acceleration_structure_with_size(&self, size: NSUInteger) -> AccelerationStructure { unsafe { msg_send![self, newAccelerationStructureWithSize: size] } } diff --git a/src/encoder.rs b/src/encoder.rs index 9156172..e737a2f 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -418,7 +418,7 @@ impl RenderCommandEncoderRef { pub fn set_vertex_acceleration_structure( &self, index: NSUInteger, - accel: Option<&accelerator_structure::AccelerationStructureRef>, + accel: Option<&AccelerationStructureRef>, ) { unsafe { msg_send![ @@ -868,7 +868,7 @@ impl RenderCommandEncoderRef { pub fn set_fragment_acceleration_structure( &self, index: NSUInteger, - accel: Option<&accelerator_structure::AccelerationStructureRef>, + accel: Option<&AccelerationStructureRef>, ) { unsafe { msg_send![ @@ -1815,7 +1815,7 @@ impl ComputeCommandEncoderRef { pub fn set_acceleration_structure( &self, index: NSUInteger, - accel: Option<&accelerator_structure::AccelerationStructureRef>, + accel: Option<&AccelerationStructureRef>, ) { unsafe { msg_send![ diff --git a/src/lib.rs b/src/lib.rs index 0d400d6..0b5c6d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -536,7 +536,8 @@ impl MetalLayerRef { } } -mod accelerator_structure; +mod acceleration_structure; +mod acceleration_structure_pass; mod argument; mod blitpass; mod buffer; @@ -567,7 +568,8 @@ mod vertexdescriptor; #[rustfmt::skip] pub use { - accelerator_structure::*, + acceleration_structure::*, + acceleration_structure_pass::*, argument::*, blitpass::*, buffer::*,