Skip to main content

cidre/mtl/
intersection_function_table.rs

1use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};
2
3#[derive(Debug, Copy, Clone, Eq, PartialEq)]
4#[repr(usize)]
5pub enum IntersectionFnSignature {
6    ///
7    /// No signature
8    ///
9    None = 0,
10
11    ///
12    /// The intersection functions are entitled to read the built-in instance_id as described in
13    /// the Metal Shading Language Guide.
14    ///
15    Instancing = (1 << 0),
16
17    ///
18    /// The triangle intersection functions are entitled to to read the built-in barycentric_coord
19    /// and front_facing as described in the Metal Shading Language Guide.
20    ///
21    TriangleData = (1 << 1),
22
23    ///
24    /// The intersection functions are entitled to query world_space_origin and
25    /// world_space_direction as described in the Metal Shading Language Guide.
26    ///
27    WorldSpaceData = (1 << 2),
28
29    ///
30    /// The intersection functions may be called from intersectors using the
31    /// instance_motion intersection tag as described in the Metal Shading Language Guide.
32    ///
33    InstanceMotion = (1 << 3),
34
35    ///
36    /// The intersection functions are entitled to query time, motion_start_time,
37    /// motion_end_time and key_frame_count as described in the Metal Shading Language Guide.
38    ///
39    PrimitiveMotion = (1 << 4),
40
41    ///
42    /// The intersection functions may be called from intersectors using the
43    /// extended_limits intersection tag as described in the Metal Shading Language Guide.
44    ///
45    ExtendedLimits = (1 << 5),
46}
47
48define_obj_type!(pub Desc(ns::Id), MTL_INTERSECTION_FUNCTION_TABLE_DESCRIPTOR);
49
50impl Desc {
51    /// The number of functions in the table.
52    #[objc::msg_send(functionCount)]
53    pub fn fn_count(&self) -> usize;
54
55    #[objc::msg_send(setFunctionCount:)]
56    pub fn set_fn_count(&mut self, val: usize);
57}
58
59define_obj_type!(pub IntersectionFnTable(mtl::Res));
60
61impl IntersectionFnTable {
62    define_mtl!(gpu_res_id);
63
64    #[objc::msg_send(setBuffer:atIndex:)]
65    pub fn set_buf_at(&mut self, buf: Option<&mtl::Buf>, index: usize);
66
67    #[objc::msg_send(setBuffers:offsets:withRange:)]
68    pub fn set_bufs(
69        &mut self,
70        buffers: *const Option<&mtl::Buf>,
71        offsets: *const usize,
72        range: ns::Range,
73    );
74
75    #[objc::msg_send(setFunction:atIndex:)]
76    pub fn set_fn_at<H: mtl::FnHandle>(&mut self, function: Option<&H>, index: usize);
77
78    #[objc::msg_send(setFunctions:withRange:)]
79    pub fn set_fns_with_range<H: mtl::FnHandle>(
80        &mut self,
81        functions: *const Option<&H>,
82        range: ns::Range,
83    );
84
85    #[objc::msg_send(setOpaqueTriangleIntersectionFunctionWithSignature:atIndex:)]
86    pub fn set_opaque_triangle_intersection_fn_with_signature(
87        &mut self,
88        signature: mtl::IntersectionFnSignature,
89        index: usize,
90    );
91
92    #[objc::msg_send(setOpaqueTriangleIntersectionFunctionWithSignature:withRange:)]
93    pub fn set_opaque_triangle_intersection_fn_with_signature_with_range(
94        &mut self,
95        signature: mtl::IntersectionFnSignature,
96        range: ns::Range,
97    );
98
99    #[objc::msg_send(setVisibleFunctionTable:atBufferIndex:)]
100    pub fn set_visible_fn_table(
101        &mut self,
102        function_table: Option<&mtl::VisibleFnTable>,
103        buffer_index: usize,
104    );
105
106    #[objc::msg_send(setVisibleFunctionTables:withBufferRange:)]
107    pub fn set_visible_fn_tables(
108        &mut self,
109        function_tables: *const Option<&mtl::VisibleFnTable>,
110        buffer_range: ns::Range,
111    );
112}
113
114unsafe extern "C" {
115    static MTL_INTERSECTION_FUNCTION_TABLE_DESCRIPTOR: &'static objc::Class<Desc>;
116}