Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Metal/MTLComputePipeline.hpp
21345 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Metal/MTLComputePipeline.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 "MTLAllocation.hpp"
25
#include "MTLDefines.hpp"
26
#include "MTLHeaderBridge.hpp"
27
#include "MTLPipeline.hpp"
28
#include "MTLPrivate.hpp"
29
#include "MTLTypes.hpp"
30
31
namespace MTL
32
{
33
class ComputePipelineDescriptor;
34
class ComputePipelineReflection;
35
class ComputePipelineState;
36
class Device;
37
class Function;
38
class FunctionHandle;
39
class IntersectionFunctionTable;
40
class IntersectionFunctionTableDescriptor;
41
class LinkedFunctions;
42
class PipelineBufferDescriptorArray;
43
class StageInputOutputDescriptor;
44
class VisibleFunctionTable;
45
class VisibleFunctionTableDescriptor;
46
47
}
48
namespace MTL4
49
{
50
class BinaryFunction;
51
52
}
53
namespace MTL
54
{
55
class ComputePipelineReflection : public NS::Referencing<ComputePipelineReflection>
56
{
57
public:
58
static ComputePipelineReflection* alloc();
59
60
NS::Array* arguments() const;
61
62
NS::Array* bindings() const;
63
64
ComputePipelineReflection* init();
65
};
66
class ComputePipelineDescriptor : public NS::Copying<ComputePipelineDescriptor>
67
{
68
public:
69
static ComputePipelineDescriptor* alloc();
70
71
NS::Array* binaryArchives() const;
72
73
PipelineBufferDescriptorArray* buffers() const;
74
75
Function* computeFunction() const;
76
77
ComputePipelineDescriptor* init();
78
79
NS::Array* insertLibraries() const;
80
81
NS::String* label() const;
82
83
LinkedFunctions* linkedFunctions() const;
84
85
NS::UInteger maxCallStackDepth() const;
86
87
NS::UInteger maxTotalThreadsPerThreadgroup() const;
88
89
NS::Array* preloadedLibraries() const;
90
91
Size requiredThreadsPerThreadgroup() const;
92
93
void reset();
94
95
void setBinaryArchives(const NS::Array* binaryArchives);
96
97
void setComputeFunction(const MTL::Function* computeFunction);
98
99
void setInsertLibraries(const NS::Array* insertLibraries);
100
101
void setLabel(const NS::String* label);
102
103
void setLinkedFunctions(const MTL::LinkedFunctions* linkedFunctions);
104
105
void setMaxCallStackDepth(NS::UInteger maxCallStackDepth);
106
107
void setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup);
108
109
void setPreloadedLibraries(const NS::Array* preloadedLibraries);
110
111
void setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup);
112
113
void setShaderValidation(MTL::ShaderValidation shaderValidation);
114
115
void setStageInputDescriptor(const MTL::StageInputOutputDescriptor* stageInputDescriptor);
116
117
void setSupportAddingBinaryFunctions(bool supportAddingBinaryFunctions);
118
119
void setSupportIndirectCommandBuffers(bool supportIndirectCommandBuffers);
120
121
void setThreadGroupSizeIsMultipleOfThreadExecutionWidth(bool threadGroupSizeIsMultipleOfThreadExecutionWidth);
122
123
ShaderValidation shaderValidation() const;
124
125
StageInputOutputDescriptor* stageInputDescriptor() const;
126
127
bool supportAddingBinaryFunctions() const;
128
129
bool supportIndirectCommandBuffers() const;
130
131
bool threadGroupSizeIsMultipleOfThreadExecutionWidth() const;
132
};
133
class ComputePipelineState : public NS::Referencing<ComputePipelineState, Allocation>
134
{
135
public:
136
Device* device() const;
137
138
FunctionHandle* functionHandle(const NS::String* name);
139
FunctionHandle* functionHandle(const MTL4::BinaryFunction* function);
140
FunctionHandle* functionHandle(const MTL::Function* function);
141
142
ResourceID gpuResourceID() const;
143
144
NS::UInteger imageblockMemoryLength(MTL::Size imageblockDimensions);
145
146
NS::String* label() const;
147
148
NS::UInteger maxTotalThreadsPerThreadgroup() const;
149
150
ComputePipelineState* newComputePipelineStateWithBinaryFunctions(const NS::Array* additionalBinaryFunctions, NS::Error** error);
151
ComputePipelineState* newComputePipelineState(const NS::Array* functions, NS::Error** error);
152
153
IntersectionFunctionTable* newIntersectionFunctionTable(const MTL::IntersectionFunctionTableDescriptor* descriptor);
154
155
VisibleFunctionTable* newVisibleFunctionTable(const MTL::VisibleFunctionTableDescriptor* descriptor);
156
157
ComputePipelineReflection* reflection() const;
158
159
Size requiredThreadsPerThreadgroup() const;
160
161
ShaderValidation shaderValidation() const;
162
163
NS::UInteger staticThreadgroupMemoryLength() const;
164
165
bool supportIndirectCommandBuffers() const;
166
167
NS::UInteger threadExecutionWidth() const;
168
};
169
170
}
171
_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineReflection::alloc()
172
{
173
return NS::Object::alloc<MTL::ComputePipelineReflection>(_MTL_PRIVATE_CLS(MTLComputePipelineReflection));
174
}
175
176
_MTL_INLINE NS::Array* MTL::ComputePipelineReflection::arguments() const
177
{
178
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(arguments));
179
}
180
181
_MTL_INLINE NS::Array* MTL::ComputePipelineReflection::bindings() const
182
{
183
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(bindings));
184
}
185
186
_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineReflection::init()
187
{
188
return NS::Object::init<MTL::ComputePipelineReflection>();
189
}
190
191
_MTL_INLINE MTL::ComputePipelineDescriptor* MTL::ComputePipelineDescriptor::alloc()
192
{
193
return NS::Object::alloc<MTL::ComputePipelineDescriptor>(_MTL_PRIVATE_CLS(MTLComputePipelineDescriptor));
194
}
195
196
_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::binaryArchives() const
197
{
198
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(binaryArchives));
199
}
200
201
_MTL_INLINE MTL::PipelineBufferDescriptorArray* MTL::ComputePipelineDescriptor::buffers() const
202
{
203
return Object::sendMessage<MTL::PipelineBufferDescriptorArray*>(this, _MTL_PRIVATE_SEL(buffers));
204
}
205
206
_MTL_INLINE MTL::Function* MTL::ComputePipelineDescriptor::computeFunction() const
207
{
208
return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(computeFunction));
209
}
210
211
_MTL_INLINE MTL::ComputePipelineDescriptor* MTL::ComputePipelineDescriptor::init()
212
{
213
return NS::Object::init<MTL::ComputePipelineDescriptor>();
214
}
215
216
_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::insertLibraries() const
217
{
218
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(insertLibraries));
219
}
220
221
_MTL_INLINE NS::String* MTL::ComputePipelineDescriptor::label() const
222
{
223
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
224
}
225
226
_MTL_INLINE MTL::LinkedFunctions* MTL::ComputePipelineDescriptor::linkedFunctions() const
227
{
228
return Object::sendMessage<MTL::LinkedFunctions*>(this, _MTL_PRIVATE_SEL(linkedFunctions));
229
}
230
231
_MTL_INLINE NS::UInteger MTL::ComputePipelineDescriptor::maxCallStackDepth() const
232
{
233
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxCallStackDepth));
234
}
235
236
_MTL_INLINE NS::UInteger MTL::ComputePipelineDescriptor::maxTotalThreadsPerThreadgroup() const
237
{
238
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTotalThreadsPerThreadgroup));
239
}
240
241
_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::preloadedLibraries() const
242
{
243
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(preloadedLibraries));
244
}
245
246
_MTL_INLINE MTL::Size MTL::ComputePipelineDescriptor::requiredThreadsPerThreadgroup() const
247
{
248
return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(requiredThreadsPerThreadgroup));
249
}
250
251
_MTL_INLINE void MTL::ComputePipelineDescriptor::reset()
252
{
253
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(reset));
254
}
255
256
_MTL_INLINE void MTL::ComputePipelineDescriptor::setBinaryArchives(const NS::Array* binaryArchives)
257
{
258
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBinaryArchives_), binaryArchives);
259
}
260
261
_MTL_INLINE void MTL::ComputePipelineDescriptor::setComputeFunction(const MTL::Function* computeFunction)
262
{
263
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setComputeFunction_), computeFunction);
264
}
265
266
_MTL_INLINE void MTL::ComputePipelineDescriptor::setInsertLibraries(const NS::Array* insertLibraries)
267
{
268
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInsertLibraries_), insertLibraries);
269
}
270
271
_MTL_INLINE void MTL::ComputePipelineDescriptor::setLabel(const NS::String* label)
272
{
273
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);
274
}
275
276
_MTL_INLINE void MTL::ComputePipelineDescriptor::setLinkedFunctions(const MTL::LinkedFunctions* linkedFunctions)
277
{
278
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLinkedFunctions_), linkedFunctions);
279
}
280
281
_MTL_INLINE void MTL::ComputePipelineDescriptor::setMaxCallStackDepth(NS::UInteger maxCallStackDepth)
282
{
283
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxCallStackDepth_), maxCallStackDepth);
284
}
285
286
_MTL_INLINE void MTL::ComputePipelineDescriptor::setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup)
287
{
288
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxTotalThreadsPerThreadgroup_), maxTotalThreadsPerThreadgroup);
289
}
290
291
_MTL_INLINE void MTL::ComputePipelineDescriptor::setPreloadedLibraries(const NS::Array* preloadedLibraries)
292
{
293
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPreloadedLibraries_), preloadedLibraries);
294
}
295
296
_MTL_INLINE void MTL::ComputePipelineDescriptor::setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup)
297
{
298
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setRequiredThreadsPerThreadgroup_), requiredThreadsPerThreadgroup);
299
}
300
301
_MTL_INLINE void MTL::ComputePipelineDescriptor::setShaderValidation(MTL::ShaderValidation shaderValidation)
302
{
303
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setShaderValidation_), shaderValidation);
304
}
305
306
_MTL_INLINE void MTL::ComputePipelineDescriptor::setStageInputDescriptor(const MTL::StageInputOutputDescriptor* stageInputDescriptor)
307
{
308
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStageInputDescriptor_), stageInputDescriptor);
309
}
310
311
_MTL_INLINE void MTL::ComputePipelineDescriptor::setSupportAddingBinaryFunctions(bool supportAddingBinaryFunctions)
312
{
313
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportAddingBinaryFunctions_), supportAddingBinaryFunctions);
314
}
315
316
_MTL_INLINE void MTL::ComputePipelineDescriptor::setSupportIndirectCommandBuffers(bool supportIndirectCommandBuffers)
317
{
318
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportIndirectCommandBuffers_), supportIndirectCommandBuffers);
319
}
320
321
_MTL_INLINE void MTL::ComputePipelineDescriptor::setThreadGroupSizeIsMultipleOfThreadExecutionWidth(bool threadGroupSizeIsMultipleOfThreadExecutionWidth)
322
{
323
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setThreadGroupSizeIsMultipleOfThreadExecutionWidth_), threadGroupSizeIsMultipleOfThreadExecutionWidth);
324
}
325
326
_MTL_INLINE MTL::ShaderValidation MTL::ComputePipelineDescriptor::shaderValidation() const
327
{
328
return Object::sendMessage<MTL::ShaderValidation>(this, _MTL_PRIVATE_SEL(shaderValidation));
329
}
330
331
_MTL_INLINE MTL::StageInputOutputDescriptor* MTL::ComputePipelineDescriptor::stageInputDescriptor() const
332
{
333
return Object::sendMessage<MTL::StageInputOutputDescriptor*>(this, _MTL_PRIVATE_SEL(stageInputDescriptor));
334
}
335
336
_MTL_INLINE bool MTL::ComputePipelineDescriptor::supportAddingBinaryFunctions() const
337
{
338
return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportAddingBinaryFunctions));
339
}
340
341
_MTL_INLINE bool MTL::ComputePipelineDescriptor::supportIndirectCommandBuffers() const
342
{
343
return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportIndirectCommandBuffers));
344
}
345
346
_MTL_INLINE bool MTL::ComputePipelineDescriptor::threadGroupSizeIsMultipleOfThreadExecutionWidth() const
347
{
348
return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(threadGroupSizeIsMultipleOfThreadExecutionWidth));
349
}
350
351
_MTL_INLINE MTL::Device* MTL::ComputePipelineState::device() const
352
{
353
return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));
354
}
355
356
_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const NS::String* name)
357
{
358
return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithName_), name);
359
}
360
361
_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const MTL4::BinaryFunction* function)
362
{
363
return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithBinaryFunction_), function);
364
}
365
366
_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const MTL::Function* function)
367
{
368
return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithFunction_), function);
369
}
370
371
_MTL_INLINE MTL::ResourceID MTL::ComputePipelineState::gpuResourceID() const
372
{
373
return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(gpuResourceID));
374
}
375
376
_MTL_INLINE NS::UInteger MTL::ComputePipelineState::imageblockMemoryLength(MTL::Size imageblockDimensions)
377
{
378
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(imageblockMemoryLengthForDimensions_), imageblockDimensions);
379
}
380
381
_MTL_INLINE NS::String* MTL::ComputePipelineState::label() const
382
{
383
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
384
}
385
386
_MTL_INLINE NS::UInteger MTL::ComputePipelineState::maxTotalThreadsPerThreadgroup() const
387
{
388
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTotalThreadsPerThreadgroup));
389
}
390
391
_MTL_INLINE MTL::ComputePipelineState* MTL::ComputePipelineState::newComputePipelineStateWithBinaryFunctions(const NS::Array* additionalBinaryFunctions, NS::Error** error)
392
{
393
return Object::sendMessage<MTL::ComputePipelineState*>(this, _MTL_PRIVATE_SEL(newComputePipelineStateWithBinaryFunctions_error_), additionalBinaryFunctions, error);
394
}
395
396
_MTL_INLINE MTL::ComputePipelineState* MTL::ComputePipelineState::newComputePipelineState(const NS::Array* functions, NS::Error** error)
397
{
398
return Object::sendMessage<MTL::ComputePipelineState*>(this, _MTL_PRIVATE_SEL(newComputePipelineStateWithAdditionalBinaryFunctions_error_), functions, error);
399
}
400
401
_MTL_INLINE MTL::IntersectionFunctionTable* MTL::ComputePipelineState::newIntersectionFunctionTable(const MTL::IntersectionFunctionTableDescriptor* descriptor)
402
{
403
return Object::sendMessage<MTL::IntersectionFunctionTable*>(this, _MTL_PRIVATE_SEL(newIntersectionFunctionTableWithDescriptor_), descriptor);
404
}
405
406
_MTL_INLINE MTL::VisibleFunctionTable* MTL::ComputePipelineState::newVisibleFunctionTable(const MTL::VisibleFunctionTableDescriptor* descriptor)
407
{
408
return Object::sendMessage<MTL::VisibleFunctionTable*>(this, _MTL_PRIVATE_SEL(newVisibleFunctionTableWithDescriptor_), descriptor);
409
}
410
411
_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineState::reflection() const
412
{
413
return Object::sendMessage<MTL::ComputePipelineReflection*>(this, _MTL_PRIVATE_SEL(reflection));
414
}
415
416
_MTL_INLINE MTL::Size MTL::ComputePipelineState::requiredThreadsPerThreadgroup() const
417
{
418
return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(requiredThreadsPerThreadgroup));
419
}
420
421
_MTL_INLINE MTL::ShaderValidation MTL::ComputePipelineState::shaderValidation() const
422
{
423
return Object::sendMessage<MTL::ShaderValidation>(this, _MTL_PRIVATE_SEL(shaderValidation));
424
}
425
426
_MTL_INLINE NS::UInteger MTL::ComputePipelineState::staticThreadgroupMemoryLength() const
427
{
428
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(staticThreadgroupMemoryLength));
429
}
430
431
_MTL_INLINE bool MTL::ComputePipelineState::supportIndirectCommandBuffers() const
432
{
433
return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportIndirectCommandBuffers));
434
}
435
436
_MTL_INLINE NS::UInteger MTL::ComputePipelineState::threadExecutionWidth() const
437
{
438
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(threadExecutionWidth));
439
}
440
441