Skip to content

Commit

Permalink
Implement Visible Function Table
Browse files Browse the repository at this point in the history
  • Loading branch information
FlannyH committed May 1, 2024
1 parent 75203a8 commit 9c158ac
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 4 deletions.
48 changes: 48 additions & 0 deletions src/accelerator_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,51 @@ impl IntersectionFunctionTableRef {
unsafe { msg_send![self, setFunction: function atIndex: index] }
}
}

// 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, function: &FunctionHandleRef, index: NSUInteger) {
unsafe { msg_send![self, setFunction: function atIndex: index] }
}

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


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

pub fn set_vertex_visible_function_tables(
&self,
visible_function_tables: &[&VisibleFunctionTableRef],
buffer_start_index: NSUInteger,
) {
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 +895,34 @@ impl RenderCommandEncoderRef {
}
}

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

pub fn set_fragment_visible_function_tables(
&self,
visible_function_tables: &[&VisibleFunctionTableRef],
buffer_start_index: NSUInteger,
) {
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 +1651,34 @@ impl ComputeCommandEncoderRef {
}
}

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

pub fn set_visible_function_tables(
&self,
visible_function_tables: &[&VisibleFunctionTableRef],
buffer_start_index: NSUInteger,
) {
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
11 changes: 11 additions & 0 deletions src/pipeline/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ impl RenderPipelineStateRef {
crate::nsstring_as_str(label)
}
}
/// 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

0 comments on commit 9c158ac

Please sign in to comment.