1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use objc2::{Message, msg_send, runtime::ProtocolObject};
use super::types::*;
use crate::util::ref_slice_as_ptr;
use crate::*;
pub trait MTL4CommandQueueExt: MTL4CommandQueue + Message {
/// Enqueues an array of command buffers for execution.
/// The order of command buffers in the slice is meaningful, especially for
/// suspending/resuming render passes.
fn commit(&self, command_buffers: &[&ProtocolObject<dyn MTL4CommandBuffer>])
where
Self: Sized,
{
let ptr = ref_slice_as_ptr(command_buffers);
unsafe { msg_send![self, commit: ptr, count: command_buffers.len()] }
}
/// Enqueues an array of command buffers for execution with a set of options.
/// Provide an `MTL4CommitOptions` instance to configure the commit operation.
fn commit_with_options(
&self,
command_buffers: &[&ProtocolObject<dyn MTL4CommandBuffer>],
options: &MTL4CommitOptions,
) where
Self: Sized,
{
let ptr = ref_slice_as_ptr(command_buffers);
unsafe { msg_send![self, commit: ptr, count: command_buffers.len(), options: options] }
}
/// Marks an array of residency sets as part of this command queue.
/// Ensures that Metal makes them resident during execution of all command buffers committed
/// to this queue. Each command queue supports up to 32 unique residency set instances.
fn add_residency_sets(&self, residency_sets: &[&ProtocolObject<dyn MTLResidencySet>])
where
Self: Sized,
{
let ptr = ref_slice_as_ptr(residency_sets);
unsafe { msg_send![self, addResidencySets: ptr, count: residency_sets.len()] }
}
/// Removes multiple residency sets from the command queue. After calling this method only
/// the remaining residency sets remain resident during execution of committed command buffers.
fn remove_residency_sets(&self, residency_sets: &[&ProtocolObject<dyn MTLResidencySet>])
where
Self: Sized,
{
let ptr = ref_slice_as_ptr(residency_sets);
unsafe { msg_send![self, removeResidencySets: ptr, count: residency_sets.len()] }
}
/// Updates multiple regions within a placement sparse texture to alias specific tiles
/// of a Metal heap. Pass `None` for `heap` only when performing unmap operations.
fn update_texture_mappings(
&self,
texture: &ProtocolObject<dyn MTLTexture>,
heap: Option<&ProtocolObject<dyn MTLHeap>>,
operations: &[MTL4UpdateSparseTextureMappingOperation],
) where
Self: Sized,
{
unsafe {
msg_send![
self,
updateTextureMappings: texture,
heap: heap,
operations: operations.as_ptr(),
count: operations.len()
]
}
}
/// Copies multiple regions within a source placement sparse texture to a destination
/// placement sparse texture. Both textures must have the same `placementSparsePageSize`.
fn copy_texture_mappings(
&self,
source: &ProtocolObject<dyn MTLTexture>,
destination: &ProtocolObject<dyn MTLTexture>,
operations: &[MTL4CopySparseTextureMappingOperation],
) where
Self: Sized,
{
unsafe {
msg_send![
self,
copyTextureMappingsFromTexture: source,
toTexture: destination,
operations: operations.as_ptr(),
count: operations.len()
]
}
}
/// Updates multiple regions within a placement sparse buffer to alias specific tiles
/// from a Metal heap. Pass `None` for `heap` only when performing unmap operations.
fn update_buffer_mappings(
&self,
buffer: &ProtocolObject<dyn MTLBuffer>,
heap: Option<&ProtocolObject<dyn MTLHeap>>,
operations: &[MTL4UpdateSparseBufferMappingOperation],
) where
Self: Sized,
{
unsafe {
msg_send![
self,
updateBufferMappings: buffer,
heap: heap,
operations: operations.as_ptr(),
count: operations.len()
]
}
}
/// Copies multiple offsets within a source placement sparse buffer to a destination
/// placement sparse buffer. Both buffers must have the same `placementSparsePageSize`.
fn copy_buffer_mappings(
&self,
source: &ProtocolObject<dyn MTLBuffer>,
destination: &ProtocolObject<dyn MTLBuffer>,
operations: &[MTL4CopySparseBufferMappingOperation],
) where
Self: Sized,
{
unsafe {
msg_send![
self,
copyBufferMappingsFromBuffer: source,
toBuffer: destination,
operations: operations.as_ptr(),
count: operations.len()
]
}
}
}
impl<T: MTL4CommandQueue + Message> MTL4CommandQueueExt for T {}