Skip to content

Commit a172204

Browse files
authored
Implement Visible Function Table (#315)
* Implement Visible Function Table * Fix formatting and doc comments * Add missing VFT related functions for IntersectionFunctionTable * Swap index and resource parameter locations
1 parent 3b57d71 commit a172204

File tree

5 files changed

+180
-10
lines changed

5 files changed

+180
-10
lines changed

Diff for: src/accelerator_structure.rs

+81-6
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,91 @@ impl IntersectionFunctionTableRef {
558558
debug_assert_eq!(offsets.len(), data.len());
559559
unsafe {
560560
msg_send![self,
561-
setBuffers: data.as_ptr()
562-
offsets: offsets.as_ptr()
563-
withRange: NSRange {
564-
location: start_index,
565-
length: data.len() as _,
566-
}
561+
setBuffers: data.as_ptr()
562+
offsets: offsets.as_ptr()
563+
withRange: NSRange {
564+
location: start_index,
565+
length: data.len() as _,
566+
}
567567
]
568568
}
569569
}
570570

571+
pub fn set_visible_function_table(
572+
&self,
573+
buffer_index: NSUInteger,
574+
visible_function_table: Option<&VisibleFunctionTableRef>,
575+
) {
576+
unsafe {
577+
msg_send![self,
578+
setVisibleFunctionTable:visible_function_table
579+
atBufferIndex:buffer_index]
580+
}
581+
}
582+
583+
pub fn set_visible_function_tables(
584+
&self,
585+
buffer_start_index: NSUInteger,
586+
visible_function_tables: &[&VisibleFunctionTableRef],
587+
) {
588+
unsafe {
589+
msg_send![self,
590+
setVisibleFunctionTables:visible_function_tables.as_ptr()
591+
withBufferRange: NSRange {
592+
location: buffer_start_index,
593+
length: visible_function_tables.len() as _,
594+
}]
595+
}
596+
}
597+
598+
pub fn gpu_resource_id(&self) -> MTLResourceID {
599+
unsafe { msg_send![self, gpuResourceID] }
600+
}
601+
}
602+
603+
/// See <https://developer.apple.com/documentation/metal/mtlvisiblefunctiontabledescriptor>
604+
pub enum MTLVisibleFunctionTableDescriptor {}
605+
606+
foreign_obj_type! {
607+
type CType = MTLVisibleFunctionTableDescriptor;
608+
pub struct VisibleFunctionTableDescriptor;
609+
type ParentType = NsObject;
610+
}
611+
612+
impl VisibleFunctionTableDescriptor {
613+
pub fn new() -> Self {
614+
unsafe {
615+
let class = class!(MTLVisibleFunctionTableDescriptor);
616+
msg_send![class, new]
617+
}
618+
}
619+
}
620+
621+
impl VisibleFunctionTableDescriptorRef {
622+
pub fn set_function_count(&self, count: NSUInteger) {
623+
unsafe { msg_send![self, setFunctionCount: count] }
624+
}
625+
}
626+
627+
/// See <https://developer.apple.com/documentation/metal/mtlvisiblefunctiontable>
628+
pub enum MTLVisibleFunctionTable {}
629+
630+
foreign_obj_type! {
631+
type CType = MTLVisibleFunctionTable;
632+
pub struct VisibleFunctionTable;
633+
type ParentType = Resource;
634+
}
635+
636+
impl VisibleFunctionTableRef {
637+
pub fn set_functions(&self, functions: &[&FunctionRef]) {
638+
let ns_array = Array::<Function>::from_slice(functions);
639+
unsafe { msg_send![self, setFunctions: ns_array] }
640+
}
641+
642+
pub fn set_function(&self, index: NSUInteger, function: &FunctionHandleRef) {
643+
unsafe { msg_send![self, setFunction: function atIndex: index] }
644+
}
645+
571646
pub fn gpu_resource_id(&self) -> MTLResourceID {
572647
unsafe { msg_send![self, gpuResourceID] }
573648
}

Diff for: src/encoder.rs

+84
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,34 @@ impl RenderCommandEncoderRef {
444444
}
445445
}
446446

447+
pub fn set_vertex_visible_function_table(
448+
&self,
449+
buffer_index: NSUInteger,
450+
visible_function_table: Option<&VisibleFunctionTableRef>,
451+
) {
452+
unsafe {
453+
msg_send![self,
454+
setVertexVisibleFunctionTable:visible_function_table
455+
atBufferIndex:buffer_index]
456+
}
457+
}
458+
459+
pub fn set_vertex_visible_function_tables(
460+
&self,
461+
buffer_start_index: NSUInteger,
462+
visible_function_tables: &[&VisibleFunctionTableRef],
463+
) {
464+
unsafe {
465+
msg_send![self,
466+
setVertexVisibleFunctionTables:visible_function_tables.as_ptr()
467+
withBufferRange: NSRange {
468+
location: buffer_start_index,
469+
length: visible_function_tables.len() as _,
470+
}
471+
]
472+
}
473+
}
474+
447475
// Specifying Resources for a Object Shader Function
448476

449477
/// Only available in (macos(13.0), ios(16.0))
@@ -866,6 +894,34 @@ impl RenderCommandEncoderRef {
866894
}
867895
}
868896

897+
pub fn set_fragment_visible_function_table(
898+
&self,
899+
buffer_index: NSUInteger,
900+
visible_function_table: Option<&VisibleFunctionTableRef>,
901+
) {
902+
unsafe {
903+
msg_send![self,
904+
setFragmentVisibleFunctionTable:visible_function_table
905+
atBufferIndex:buffer_index]
906+
}
907+
}
908+
909+
pub fn set_fragment_visible_function_tables(
910+
&self,
911+
buffer_start_index: NSUInteger,
912+
visible_function_tables: &[&VisibleFunctionTableRef],
913+
) {
914+
unsafe {
915+
msg_send![self,
916+
setFragmentVisibleFunctionTables:visible_function_tables.as_ptr()
917+
withBufferRange: NSRange {
918+
location: buffer_start_index,
919+
length: visible_function_tables.len() as _,
920+
}
921+
]
922+
}
923+
}
924+
869925
// Drawing Geometric Primitives
870926

871927
pub fn draw_primitives(
@@ -1594,6 +1650,34 @@ impl ComputeCommandEncoderRef {
15941650
}
15951651
}
15961652

1653+
pub fn set_visible_function_table(
1654+
&self,
1655+
buffer_index: NSUInteger,
1656+
visible_function_table: Option<&VisibleFunctionTableRef>,
1657+
) {
1658+
unsafe {
1659+
msg_send![self,
1660+
setVisibleFunctionTable:visible_function_table
1661+
atBufferIndex:buffer_index]
1662+
}
1663+
}
1664+
1665+
pub fn set_visible_function_tables(
1666+
&self,
1667+
buffer_start_index: NSUInteger,
1668+
visible_function_tables: &[&VisibleFunctionTableRef],
1669+
) {
1670+
unsafe {
1671+
msg_send![self,
1672+
setVisibleFunctionTables:visible_function_tables.as_ptr()
1673+
withBufferRange: NSRange {
1674+
location: buffer_start_index,
1675+
length: visible_function_tables.len() as _,
1676+
}
1677+
]
1678+
}
1679+
}
1680+
15971681
pub fn dispatch_thread_groups(
15981682
&self,
15991683
thread_groups_count: MTLSize,

Diff for: src/library.rs

-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ impl FunctionHandleRef {
263263
}
264264

265265
// TODO:
266-
// MTLVisibleFunctionTableDescriptor
267-
// MTLVisibleFunctionTable
268266
// MTLIntersectionFunctionSignature
269267
// MTLIntersectionFunctionTableDescriptor
270268
// MTLIntersectionFunctionTable

Diff for: src/pipeline/compute.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,12 @@ impl ComputePipelineStateRef {
303303
// - (nullable id <MTLComputePipelineState>)newComputePipelineStateWithAdditionalBinaryFunctions:(nonnull NSArray<id<MTLFunction>> *)functions error:(__autoreleasing NSError **)error
304304

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

309313
/// Only available on (macos(11.0), ios(14.0))
310314
pub fn new_intersection_function_table_with_descriptor(

Diff for: src/pipeline/render.rs

+9
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,15 @@ impl RenderPipelineStateRef {
722722
stage:stage]
723723
}
724724
}
725+
726+
/// Only available on (macos(11.0), ios(14.0))
727+
pub fn new_visible_function_table_with_descriptor(
728+
&self,
729+
descriptor: &VisibleFunctionTableDescriptorRef,
730+
stage: MTLRenderStages,
731+
) -> VisibleFunctionTable {
732+
unsafe { msg_send![self, newVisibleFunctionTableWithDescriptor: descriptor stage:stage] }
733+
}
725734
}
726735

727736
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptorarray>

0 commit comments

Comments
 (0)