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 Visible Function Table #315

Merged
merged 4 commits into from
May 7, 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
87 changes: 81 additions & 6 deletions src/accelerator_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,91 @@ impl IntersectionFunctionTableRef {
debug_assert_eq!(offsets.len(), data.len());
unsafe {
msg_send![self,
setBuffers: data.as_ptr()
offsets: offsets.as_ptr()
withRange: NSRange {
location: start_index,
length: data.len() as _,
}
setBuffers: data.as_ptr()
offsets: offsets.as_ptr()
withRange: NSRange {
location: start_index,
length: data.len() as _,
}
]
}
}

pub fn set_visible_function_table(
&self,
buffer_index: NSUInteger,
FlannyH marked this conversation as resolved.
Show resolved Hide resolved
visible_function_table: Option<&VisibleFunctionTableRef>,
) {
unsafe {
msg_send![self,
setVisibleFunctionTable:visible_function_table
atBufferIndex:buffer_index]
}
}

pub fn set_visible_function_tables(
&self,
buffer_start_index: NSUInteger,
visible_function_tables: &[&VisibleFunctionTableRef],
) {
unsafe {
msg_send![self,
setVisibleFunctionTables:visible_function_tables.as_ptr()
withBufferRange: NSRange {
location: buffer_start_index,
length: visible_function_tables.len() as _,
}]
}
}

pub fn gpu_resource_id(&self) -> MTLResourceID {
unsafe { msg_send![self, gpuResourceID] }
}
}

/// See <https://developer.apple.com/documentation/metal/mtlvisiblefunctiontabledescriptor>
pub enum MTLVisibleFunctionTableDescriptor {}

foreign_obj_type! {
type CType = MTLVisibleFunctionTableDescriptor;
pub struct VisibleFunctionTableDescriptor;
type ParentType = NsObject;
}

impl VisibleFunctionTableDescriptor {
pub fn new() -> Self {
unsafe {
let class = class!(MTLVisibleFunctionTableDescriptor);
msg_send![class, new]
}
}
}

impl VisibleFunctionTableDescriptorRef {
pub fn set_function_count(&self, count: NSUInteger) {
unsafe { msg_send![self, setFunctionCount: count] }
}
}

/// See <https://developer.apple.com/documentation/metal/mtlvisiblefunctiontable>
pub enum MTLVisibleFunctionTable {}

foreign_obj_type! {
type CType = MTLVisibleFunctionTable;
pub struct VisibleFunctionTable;
type ParentType = Resource;
}

impl VisibleFunctionTableRef {
pub fn set_functions(&self, functions: &[&FunctionRef]) {
let ns_array = Array::<Function>::from_slice(functions);
unsafe { msg_send![self, setFunctions: ns_array] }
}

pub fn set_function(&self, index: NSUInteger, function: &FunctionHandleRef) {
unsafe { msg_send![self, setFunction: function atIndex: index] }
}

pub fn gpu_resource_id(&self) -> MTLResourceID {
unsafe { msg_send![self, gpuResourceID] }
}
Expand Down
84 changes: 84 additions & 0 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,34 @@ impl RenderCommandEncoderRef {
}
}

pub fn set_vertex_visible_function_table(
&self,
buffer_index: NSUInteger,
visible_function_table: Option<&VisibleFunctionTableRef>,
) {
unsafe {
msg_send![self,
setVertexVisibleFunctionTable:visible_function_table
atBufferIndex:buffer_index]
}
}

pub fn set_vertex_visible_function_tables(
&self,
buffer_start_index: NSUInteger,
visible_function_tables: &[&VisibleFunctionTableRef],
) {
unsafe {
msg_send![self,
setVertexVisibleFunctionTables:visible_function_tables.as_ptr()
withBufferRange: NSRange {
location: buffer_start_index,
length: visible_function_tables.len() as _,
}
]
}
}

// Specifying Resources for a Object Shader Function

/// Only available in (macos(13.0), ios(16.0))
Expand Down Expand Up @@ -866,6 +894,34 @@ impl RenderCommandEncoderRef {
}
}

pub fn set_fragment_visible_function_table(
&self,
buffer_index: NSUInteger,
visible_function_table: Option<&VisibleFunctionTableRef>,
) {
unsafe {
msg_send![self,
setFragmentVisibleFunctionTable:visible_function_table
atBufferIndex:buffer_index]
}
}

pub fn set_fragment_visible_function_tables(
&self,
buffer_start_index: NSUInteger,
visible_function_tables: &[&VisibleFunctionTableRef],
) {
unsafe {
msg_send![self,
setFragmentVisibleFunctionTables:visible_function_tables.as_ptr()
withBufferRange: NSRange {
location: buffer_start_index,
length: visible_function_tables.len() as _,
}
]
}
}

// Drawing Geometric Primitives

pub fn draw_primitives(
Expand Down Expand Up @@ -1594,6 +1650,34 @@ impl ComputeCommandEncoderRef {
}
}

pub fn set_visible_function_table(
&self,
buffer_index: NSUInteger,
visible_function_table: Option<&VisibleFunctionTableRef>,
) {
unsafe {
msg_send![self,
setVisibleFunctionTable:visible_function_table
atBufferIndex:buffer_index]
}
}

pub fn set_visible_function_tables(
&self,
buffer_start_index: NSUInteger,
visible_function_tables: &[&VisibleFunctionTableRef],
) {
unsafe {
msg_send![self,
setVisibleFunctionTables:visible_function_tables.as_ptr()
withBufferRange: NSRange {
location: buffer_start_index,
length: visible_function_tables.len() as _,
}
]
}
}

pub fn dispatch_thread_groups(
&self,
thread_groups_count: MTLSize,
Expand Down
2 changes: 0 additions & 2 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ impl FunctionHandleRef {
}

// TODO:
// MTLVisibleFunctionTableDescriptor
// MTLVisibleFunctionTable
// MTLIntersectionFunctionSignature
// MTLIntersectionFunctionTableDescriptor
// MTLIntersectionFunctionTable
Expand Down
8 changes: 6 additions & 2 deletions src/pipeline/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,12 @@ impl ComputePipelineStateRef {
// - (nullable id <MTLComputePipelineState>)newComputePipelineStateWithAdditionalBinaryFunctions:(nonnull NSArray<id<MTLFunction>> *)functions error:(__autoreleasing NSError **)error

// API_AVAILABLE(macos(11.0), ios(14.0));
// TODO: newVisibleFunctionTableWithDescriptor
// - (nullable id<MTLVisibleFunctionTable>)newVisibleFunctionTableWithDescriptor:(MTLVisibleFunctionTableDescriptor * __nonnull)descriptor
pub fn new_visible_function_table_with_descriptor(
&self,
descriptor: &VisibleFunctionTableDescriptorRef,
) -> VisibleFunctionTable {
unsafe { msg_send![self, newVisibleFunctionTableWithDescriptor: descriptor ] }
}

/// Only available on (macos(11.0), ios(14.0))
pub fn new_intersection_function_table_with_descriptor(
Expand Down
9 changes: 9 additions & 0 deletions src/pipeline/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@ impl RenderPipelineStateRef {
stage:stage]
}
}

/// Only available on (macos(11.0), ios(14.0))
pub fn new_visible_function_table_with_descriptor(
&self,
descriptor: &VisibleFunctionTableDescriptorRef,
stage: MTLRenderStages,
) -> VisibleFunctionTable {
unsafe { msg_send![self, newVisibleFunctionTableWithDescriptor: descriptor stage:stage] }
}
}

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