Skip to main content

mtl_gpu/enums/
argument.rs

1//! Argument enumerations.
2//!
3//! Corresponds to `Metal/MTLArgument.hpp`.
4
5use mtl_foundation::{Integer, UInteger};
6
7/// Index type for indexed drawing.
8///
9/// C++ equivalent: `MTL::IndexType`
10#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct IndexType(pub UInteger);
13
14impl IndexType {
15    pub const UINT16: Self = Self(0);
16    pub const UINT32: Self = Self(1);
17}
18
19/// Binding type for shader arguments.
20///
21/// C++ equivalent: `MTL::BindingType`
22#[repr(transparent)]
23#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
24pub struct BindingType(pub Integer);
25
26impl BindingType {
27    pub const BUFFER: Self = Self(0);
28    pub const THREADGROUP_MEMORY: Self = Self(1);
29    pub const TEXTURE: Self = Self(2);
30    pub const SAMPLER: Self = Self(3);
31    pub const IMAGEBLOCK_DATA: Self = Self(16);
32    pub const IMAGEBLOCK: Self = Self(17);
33    pub const VISIBLE_FUNCTION_TABLE: Self = Self(24);
34    pub const PRIMITIVE_ACCELERATION_STRUCTURE: Self = Self(25);
35    pub const INSTANCE_ACCELERATION_STRUCTURE: Self = Self(26);
36    pub const INTERSECTION_FUNCTION_TABLE: Self = Self(27);
37    pub const OBJECT_PAYLOAD: Self = Self(34);
38    pub const TENSOR: Self = Self(37);
39}
40
41/// Argument type for shader arguments.
42///
43/// C++ equivalent: `MTL::ArgumentType`
44#[repr(transparent)]
45#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
46pub struct ArgumentType(pub UInteger);
47
48impl ArgumentType {
49    pub const BUFFER: Self = Self(0);
50    pub const THREADGROUP_MEMORY: Self = Self(1);
51    pub const TEXTURE: Self = Self(2);
52    pub const SAMPLER: Self = Self(3);
53    pub const IMAGEBLOCK_DATA: Self = Self(16);
54    pub const IMAGEBLOCK: Self = Self(17);
55    pub const VISIBLE_FUNCTION_TABLE: Self = Self(24);
56    pub const PRIMITIVE_ACCELERATION_STRUCTURE: Self = Self(25);
57    pub const INSTANCE_ACCELERATION_STRUCTURE: Self = Self(26);
58    pub const INTERSECTION_FUNCTION_TABLE: Self = Self(27);
59}
60
61/// Binding access mode.
62///
63/// C++ equivalent: `MTL::BindingAccess`
64///
65/// Note: ArgumentAccess is an alias with the same values.
66#[repr(transparent)]
67#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
68pub struct BindingAccess(pub UInteger);
69
70impl BindingAccess {
71    pub const READ_ONLY: Self = Self(0);
72    pub const READ_WRITE: Self = Self(1);
73    pub const WRITE_ONLY: Self = Self(2);
74}
75
76/// Argument access mode (alias for BindingAccess).
77///
78/// C++ equivalent: `MTL::ArgumentAccess`
79pub type ArgumentAccess = BindingAccess;
80
81// Re-export the access constants under the ArgumentAccess name for compatibility
82impl BindingAccess {
83    /// Alias for READ_ONLY (ArgumentAccess compatibility)
84    pub const ARGUMENT_ACCESS_READ_ONLY: Self = Self::READ_ONLY;
85    /// Alias for READ_WRITE (ArgumentAccess compatibility)
86    pub const ARGUMENT_ACCESS_READ_WRITE: Self = Self::READ_WRITE;
87    /// Alias for WRITE_ONLY (ArgumentAccess compatibility)
88    pub const ARGUMENT_ACCESS_WRITE_ONLY: Self = Self::WRITE_ONLY;
89}
90
91#[cfg(test)]
92mod tests {
93    use super::*;
94
95    #[test]
96    fn test_index_type_values() {
97        assert_eq!(IndexType::UINT16.0, 0);
98        assert_eq!(IndexType::UINT32.0, 1);
99    }
100
101    #[test]
102    fn test_binding_type_values() {
103        assert_eq!(BindingType::BUFFER.0, 0);
104        assert_eq!(BindingType::TEXTURE.0, 2);
105        assert_eq!(BindingType::TENSOR.0, 37);
106    }
107
108    #[test]
109    fn test_binding_access_values() {
110        assert_eq!(BindingAccess::READ_ONLY.0, 0);
111        assert_eq!(BindingAccess::READ_WRITE.0, 1);
112        assert_eq!(BindingAccess::WRITE_ONLY.0, 2);
113    }
114}