Skip to main content

mtl_gpu/encoder/compute_encoder/
indirect.rs

1//! Indirect command execution and counter sampling methods for ComputeCommandEncoder.
2
3use std::ffi::c_void;
4
5use mtl_foundation::{Referencing, UInteger};
6use mtl_sys::sel;
7
8use super::ComputeCommandEncoder;
9
10impl ComputeCommandEncoder {
11    // =========================================================================
12    // Indirect Command Execution
13    // =========================================================================
14
15    /// Execute commands from an indirect command buffer (raw pointer version).
16    ///
17    /// C++ equivalent: `void executeCommandsInBuffer(const IndirectCommandBuffer*, NS::Range)`
18    ///
19    /// # Safety
20    ///
21    /// The indirect command buffer pointer must be valid.
22    pub unsafe fn execute_commands_in_buffer_ptr(
23        &self,
24        indirect_command_buffer: *const c_void,
25        offset: UInteger,
26        length: UInteger,
27    ) {
28        let range = mtl_foundation::Range::new(offset, length);
29        unsafe {
30            mtl_sys::msg_send_2::<(), *const c_void, mtl_foundation::Range>(
31                self.as_ptr(),
32                sel!(executeCommandsInBuffer: withRange:),
33                indirect_command_buffer,
34                range,
35            );
36        }
37    }
38
39    /// Execute commands from an indirect command buffer with indirect range (raw pointer version).
40    ///
41    /// C++ equivalent: `void executeCommandsInBuffer(const IndirectCommandBuffer*, const Buffer*, NS::UInteger)`
42    ///
43    /// # Safety
44    ///
45    /// The indirect command buffer and range buffer pointers must be valid.
46    pub unsafe fn execute_commands_in_buffer_with_indirect_range_ptr(
47        &self,
48        indirect_command_buffer: *const c_void,
49        indirect_range_buffer: *const c_void,
50        indirect_buffer_offset: UInteger,
51    ) {
52        unsafe {
53            mtl_sys::msg_send_3::<(), *const c_void, *const c_void, UInteger>(
54                self.as_ptr(),
55                sel!(executeCommandsInBuffer: indirectBuffer: indirectBufferOffset:),
56                indirect_command_buffer,
57                indirect_range_buffer,
58                indirect_buffer_offset,
59            );
60        }
61    }
62
63    // =========================================================================
64    // Counter Sampling
65    // =========================================================================
66
67    /// Sample counters (raw pointer version).
68    ///
69    /// C++ equivalent: `void sampleCountersInBuffer(...)`
70    ///
71    /// # Safety
72    ///
73    /// The sample buffer pointer must be a valid counter sample buffer object.
74    pub unsafe fn sample_counters_in_buffer_ptr(
75        &self,
76        sample_buffer: *const c_void,
77        sample_index: UInteger,
78        barrier: bool,
79    ) {
80        unsafe {
81            mtl_sys::msg_send_3::<(), *const c_void, UInteger, bool>(
82                self.as_ptr(),
83                sel!(sampleCountersInBuffer: atSampleIndex: withBarrier:),
84                sample_buffer,
85                sample_index,
86                barrier,
87            );
88        }
89    }
90}