Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Metal/MTL4CommandQueue.hpp
21066 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Metal/MTL4CommandQueue.hpp
4
//
5
// Copyright 2020-2025 Apple Inc.
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
// http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
20
21
#pragma once
22
23
#include "../Foundation/Foundation.hpp"
24
#include "MTL4CommitFeedback.hpp"
25
#include "MTLDefines.hpp"
26
#include "MTLHeaderBridge.hpp"
27
#include "MTLPrivate.hpp"
28
#include "MTLResourceStateCommandEncoder.hpp"
29
#include "MTLTypes.hpp"
30
#include <cstdint>
31
#include <dispatch/dispatch.h>
32
33
namespace MTL
34
{
35
class Buffer;
36
class Device;
37
class Drawable;
38
class Event;
39
class Heap;
40
class ResidencySet;
41
class Texture;
42
}
43
44
namespace MTL4
45
{
46
class CommandBuffer;
47
class CommandQueueDescriptor;
48
class CommitOptions;
49
struct CopySparseBufferMappingOperation;
50
struct CopySparseTextureMappingOperation;
51
struct UpdateSparseBufferMappingOperation;
52
struct UpdateSparseTextureMappingOperation;
53
_MTL_ENUM(NS::Integer, CommandQueueError) {
54
CommandQueueErrorNone = 0,
55
CommandQueueErrorTimeout = 1,
56
CommandQueueErrorNotPermitted = 2,
57
CommandQueueErrorOutOfMemory = 3,
58
CommandQueueErrorDeviceRemoved = 4,
59
CommandQueueErrorAccessRevoked = 5,
60
CommandQueueErrorInternal = 6,
61
};
62
63
struct UpdateSparseTextureMappingOperation
64
{
65
MTL::SparseTextureMappingMode mode;
66
MTL::Region textureRegion;
67
NS::UInteger textureLevel;
68
NS::UInteger textureSlice;
69
NS::UInteger heapOffset;
70
} _MTL_PACKED;
71
72
struct CopySparseTextureMappingOperation
73
{
74
MTL::Region sourceRegion;
75
NS::UInteger sourceLevel;
76
NS::UInteger sourceSlice;
77
MTL::Origin destinationOrigin;
78
NS::UInteger destinationLevel;
79
NS::UInteger destinationSlice;
80
} _MTL_PACKED;
81
82
struct UpdateSparseBufferMappingOperation
83
{
84
MTL::SparseTextureMappingMode mode;
85
NS::Range bufferRange;
86
NS::UInteger heapOffset;
87
} _MTL_PACKED;
88
89
struct CopySparseBufferMappingOperation
90
{
91
NS::Range sourceRange;
92
NS::UInteger destinationOffset;
93
} _MTL_PACKED;
94
95
class CommitOptions : public NS::Referencing<CommitOptions>
96
{
97
public:
98
void addFeedbackHandler(const MTL4::CommitFeedbackHandler block);
99
void addFeedbackHandler(const MTL4::CommitFeedbackHandlerFunction& function);
100
101
static CommitOptions* alloc();
102
103
CommitOptions* init();
104
};
105
class CommandQueueDescriptor : public NS::Copying<CommandQueueDescriptor>
106
{
107
public:
108
static CommandQueueDescriptor* alloc();
109
110
dispatch_queue_t feedbackQueue() const;
111
112
CommandQueueDescriptor* init();
113
114
NS::String* label() const;
115
116
void setFeedbackQueue(const dispatch_queue_t feedbackQueue);
117
118
void setLabel(const NS::String* label);
119
};
120
class CommandQueue : public NS::Referencing<CommandQueue>
121
{
122
public:
123
void addResidencySet(const MTL::ResidencySet* residencySet);
124
void addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);
125
126
void commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count);
127
void commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count, const MTL4::CommitOptions* options);
128
129
void copyBufferMappingsFromBuffer(const MTL::Buffer* sourceBuffer, const MTL::Buffer* destinationBuffer, const MTL4::CopySparseBufferMappingOperation* operations, NS::UInteger count);
130
131
void copyTextureMappingsFromTexture(const MTL::Texture* sourceTexture, const MTL::Texture* destinationTexture, const MTL4::CopySparseTextureMappingOperation* operations, NS::UInteger count);
132
133
MTL::Device* device() const;
134
135
NS::String* label() const;
136
137
void removeResidencySet(const MTL::ResidencySet* residencySet);
138
void removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);
139
140
void signalDrawable(const MTL::Drawable* drawable);
141
142
void signalEvent(const MTL::Event* event, uint64_t value);
143
144
void updateBufferMappings(const MTL::Buffer* buffer, const MTL::Heap* heap, const MTL4::UpdateSparseBufferMappingOperation* operations, NS::UInteger count);
145
146
void updateTextureMappings(const MTL::Texture* texture, const MTL::Heap* heap, const MTL4::UpdateSparseTextureMappingOperation* operations, NS::UInteger count);
147
148
void wait(const MTL::Event* event, uint64_t value);
149
void wait(const MTL::Drawable* drawable);
150
};
151
152
}
153
154
_MTL_INLINE void MTL4::CommitOptions::addFeedbackHandler(const MTL4::CommitFeedbackHandler block)
155
{
156
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addFeedbackHandler_), block);
157
}
158
159
_MTL_INLINE void MTL4::CommitOptions::addFeedbackHandler(const MTL4::CommitFeedbackHandlerFunction& function)
160
{
161
__block MTL4::CommitFeedbackHandlerFunction blockFunction = function;
162
addFeedbackHandler(^(MTL4::CommitFeedback* pFeedback) { blockFunction(pFeedback); });
163
}
164
165
_MTL_INLINE MTL4::CommitOptions* MTL4::CommitOptions::alloc()
166
{
167
return NS::Object::alloc<MTL4::CommitOptions>(_MTL_PRIVATE_CLS(MTL4CommitOptions));
168
}
169
170
_MTL_INLINE MTL4::CommitOptions* MTL4::CommitOptions::init()
171
{
172
return NS::Object::init<MTL4::CommitOptions>();
173
}
174
175
_MTL_INLINE MTL4::CommandQueueDescriptor* MTL4::CommandQueueDescriptor::alloc()
176
{
177
return NS::Object::alloc<MTL4::CommandQueueDescriptor>(_MTL_PRIVATE_CLS(MTL4CommandQueueDescriptor));
178
}
179
180
_MTL_INLINE dispatch_queue_t MTL4::CommandQueueDescriptor::feedbackQueue() const
181
{
182
return Object::sendMessage<dispatch_queue_t>(this, _MTL_PRIVATE_SEL(feedbackQueue));
183
}
184
185
_MTL_INLINE MTL4::CommandQueueDescriptor* MTL4::CommandQueueDescriptor::init()
186
{
187
return NS::Object::init<MTL4::CommandQueueDescriptor>();
188
}
189
190
_MTL_INLINE NS::String* MTL4::CommandQueueDescriptor::label() const
191
{
192
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
193
}
194
195
_MTL_INLINE void MTL4::CommandQueueDescriptor::setFeedbackQueue(const dispatch_queue_t feedbackQueue)
196
{
197
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setFeedbackQueue_), feedbackQueue);
198
}
199
200
_MTL_INLINE void MTL4::CommandQueueDescriptor::setLabel(const NS::String* label)
201
{
202
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);
203
}
204
205
_MTL_INLINE void MTL4::CommandQueue::addResidencySet(const MTL::ResidencySet* residencySet)
206
{
207
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySet_), residencySet);
208
}
209
210
_MTL_INLINE void MTL4::CommandQueue::addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)
211
{
212
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySets_count_), residencySets, count);
213
}
214
215
_MTL_INLINE void MTL4::CommandQueue::commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count)
216
{
217
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(commit_count_), commandBuffers, count);
218
}
219
220
_MTL_INLINE void MTL4::CommandQueue::commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count, const MTL4::CommitOptions* options)
221
{
222
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(commit_count_options_), commandBuffers, count, options);
223
}
224
225
_MTL_INLINE void MTL4::CommandQueue::copyBufferMappingsFromBuffer(const MTL::Buffer* sourceBuffer, const MTL::Buffer* destinationBuffer, const MTL4::CopySparseBufferMappingOperation* operations, NS::UInteger count)
226
{
227
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(copyBufferMappingsFromBuffer_toBuffer_operations_count_), sourceBuffer, destinationBuffer, operations, count);
228
}
229
230
_MTL_INLINE void MTL4::CommandQueue::copyTextureMappingsFromTexture(const MTL::Texture* sourceTexture, const MTL::Texture* destinationTexture, const MTL4::CopySparseTextureMappingOperation* operations, NS::UInteger count)
231
{
232
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(copyTextureMappingsFromTexture_toTexture_operations_count_), sourceTexture, destinationTexture, operations, count);
233
}
234
235
_MTL_INLINE MTL::Device* MTL4::CommandQueue::device() const
236
{
237
return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));
238
}
239
240
_MTL_INLINE NS::String* MTL4::CommandQueue::label() const
241
{
242
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
243
}
244
245
_MTL_INLINE void MTL4::CommandQueue::removeResidencySet(const MTL::ResidencySet* residencySet)
246
{
247
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySet_), residencySet);
248
}
249
250
_MTL_INLINE void MTL4::CommandQueue::removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)
251
{
252
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySets_count_), residencySets, count);
253
}
254
255
_MTL_INLINE void MTL4::CommandQueue::signalDrawable(const MTL::Drawable* drawable)
256
{
257
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(signalDrawable_), drawable);
258
}
259
260
_MTL_INLINE void MTL4::CommandQueue::signalEvent(const MTL::Event* event, uint64_t value)
261
{
262
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(signalEvent_value_), event, value);
263
}
264
265
_MTL_INLINE void MTL4::CommandQueue::updateBufferMappings(const MTL::Buffer* buffer, const MTL::Heap* heap, const MTL4::UpdateSparseBufferMappingOperation* operations, NS::UInteger count)
266
{
267
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(updateBufferMappings_heap_operations_count_), buffer, heap, operations, count);
268
}
269
270
_MTL_INLINE void MTL4::CommandQueue::updateTextureMappings(const MTL::Texture* texture, const MTL::Heap* heap, const MTL4::UpdateSparseTextureMappingOperation* operations, NS::UInteger count)
271
{
272
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(updateTextureMappings_heap_operations_count_), texture, heap, operations, count);
273
}
274
275
_MTL_INLINE void MTL4::CommandQueue::wait(const MTL::Event* event, uint64_t value)
276
{
277
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitForEvent_value_), event, value);
278
}
279
280
_MTL_INLINE void MTL4::CommandQueue::wait(const MTL::Drawable* drawable)
281
{
282
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitForDrawable_), drawable);
283
}
284
285