yum-mirror/VkFFT

git clone https://git.yummers.dev/yum-mirror/VkFFT

Tolmachev DmitriiMetal support in VkFFTba7001c

develop
16.7 KiB465 linesraw
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2//
3// Metal/MTLCommandBuffer.hpp
4//
5// Copyright 2020-2021 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 "MTLDefines.hpp"
24#include "MTLHeaderBridge.hpp"
25#include "MTLPrivate.hpp"
26
27#include <Foundation/Foundation.hpp>
28
29#include "MTLCommandBuffer.hpp"
30#include <functional>
31
32namespace MTL
33{
34_MTL_ENUM(NS::UInteger, CommandBufferStatus) {
35    CommandBufferStatusNotEnqueued = 0,
36    CommandBufferStatusEnqueued = 1,
37    CommandBufferStatusCommitted = 2,
38    CommandBufferStatusScheduled = 3,
39    CommandBufferStatusCompleted = 4,
40    CommandBufferStatusError = 5,
41};
42
43_MTL_ENUM(NS::UInteger, CommandBufferError) {
44    CommandBufferErrorNone = 0,
45    CommandBufferErrorTimeout = 2,
46    CommandBufferErrorPageFault = 3,
47    CommandBufferErrorAccessRevoked = 4,
48    CommandBufferErrorBlacklisted = 4,
49    CommandBufferErrorNotPermitted = 7,
50    CommandBufferErrorOutOfMemory = 8,
51    CommandBufferErrorInvalidResource = 9,
52    CommandBufferErrorMemoryless = 10,
53    CommandBufferErrorDeviceRemoved = 11,
54    CommandBufferErrorStackOverflow = 12,
55};
56
57_MTL_OPTIONS(NS::UInteger, CommandBufferErrorOption) {
58    CommandBufferErrorOptionNone = 0,
59    CommandBufferErrorOptionEncoderExecutionStatus = 1,
60};
61
62_MTL_ENUM(NS::Integer, CommandEncoderErrorState) {
63    CommandEncoderErrorStateUnknown = 0,
64    CommandEncoderErrorStateCompleted = 1,
65    CommandEncoderErrorStateAffected = 2,
66    CommandEncoderErrorStatePending = 3,
67    CommandEncoderErrorStateFaulted = 4,
68};
69
70class CommandBufferDescriptor : public NS::Copying<CommandBufferDescriptor>
71{
72public:
73    static class CommandBufferDescriptor* alloc();
74
75    class CommandBufferDescriptor*        init();
76
77    bool                                  retainedReferences() const;
78    void                                  setRetainedReferences(bool retainedReferences);
79
80    MTL::CommandBufferErrorOption         errorOptions() const;
81    void                                  setErrorOptions(MTL::CommandBufferErrorOption errorOptions);
82};
83
84class CommandBufferEncoderInfo : public NS::Referencing<CommandBufferEncoderInfo>
85{
86public:
87    NS::String*                   label() const;
88
89    NS::Array*                    debugSignposts() const;
90
91    MTL::CommandEncoderErrorState errorState() const;
92};
93
94_MTL_ENUM(NS::UInteger, DispatchType) {
95    DispatchTypeSerial = 0,
96    DispatchTypeConcurrent = 1,
97};
98
99class CommandBuffer;
100
101using CommandBufferHandler = void (^)(CommandBuffer*);
102
103using HandlerFunction = std::function<void(CommandBuffer*)>;
104
105class CommandBuffer : public NS::Referencing<CommandBuffer>
106{
107public:
108    void                                       addScheduledHandler(const HandlerFunction& function);
109
110    void                                       addCompletedHandler(const HandlerFunction& function);
111
112    class Device*                              device() const;
113
114    class CommandQueue*                        commandQueue() const;
115
116    bool                                       retainedReferences() const;
117
118    MTL::CommandBufferErrorOption              errorOptions() const;
119
120    NS::String*                                label() const;
121    void                                       setLabel(const NS::String* label);
122
123    CFTimeInterval                             kernelStartTime() const;
124
125    CFTimeInterval                             kernelEndTime() const;
126
127    class LogContainer*                        logs() const;
128
129    CFTimeInterval                             GPUStartTime() const;
130
131    CFTimeInterval                             GPUEndTime() const;
132
133    void                                       enqueue();
134
135    void                                       commit();
136
137    void                                       addScheduledHandler(const MTL::CommandBufferHandler block);
138
139    void                                       presentDrawable(const class Drawable* drawable);
140
141    void                                       presentDrawableAtTime(const class Drawable* drawable, CFTimeInterval presentationTime);
142
143    void                                       presentDrawableAfterMinimumDuration(const class Drawable* drawable, CFTimeInterval duration);
144
145    void                                       waitUntilScheduled();
146
147    void                                       addCompletedHandler(const MTL::CommandBufferHandler block);
148
149    void                                       waitUntilCompleted();
150
151    MTL::CommandBufferStatus                   status() const;
152
153    NS::Error*                                 error() const;
154
155    class BlitCommandEncoder*                  blitCommandEncoder();
156
157    class RenderCommandEncoder*                renderCommandEncoder(const class RenderPassDescriptor* renderPassDescriptor);
158
159    class ComputeCommandEncoder*               computeCommandEncoder(const class ComputePassDescriptor* computePassDescriptor);
160
161    class BlitCommandEncoder*                  blitCommandEncoder(const class BlitPassDescriptor* blitPassDescriptor);
162
163    class ComputeCommandEncoder*               computeCommandEncoder();
164
165    class ComputeCommandEncoder*               computeCommandEncoder(MTL::DispatchType dispatchType);
166
167    void                                       encodeWait(const class Event* event, uint64_t value);
168
169    void                                       encodeSignalEvent(const class Event* event, uint64_t value);
170
171    class ParallelRenderCommandEncoder*        parallelRenderCommandEncoder(const class RenderPassDescriptor* renderPassDescriptor);
172
173    class ResourceStateCommandEncoder*         resourceStateCommandEncoder();
174
175    class ResourceStateCommandEncoder*         resourceStateCommandEncoder(const class ResourceStatePassDescriptor* resourceStatePassDescriptor);
176
177    class AccelerationStructureCommandEncoder* accelerationStructureCommandEncoder();
178
179    void                                       pushDebugGroup(const NS::String* string);
180
181    void                                       popDebugGroup();
182};
183
184}
185
186// static method: alloc
187_MTL_INLINE MTL::CommandBufferDescriptor* MTL::CommandBufferDescriptor::alloc()
188{
189    return NS::Object::alloc<MTL::CommandBufferDescriptor>(_MTL_PRIVATE_CLS(MTLCommandBufferDescriptor));
190}
191
192// method: init
193_MTL_INLINE MTL::CommandBufferDescriptor* MTL::CommandBufferDescriptor::init()
194{
195    return NS::Object::init<MTL::CommandBufferDescriptor>();
196}
197
198// property: retainedReferences
199_MTL_INLINE bool MTL::CommandBufferDescriptor::retainedReferences() const
200{
201    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(retainedReferences));
202}
203
204_MTL_INLINE void MTL::CommandBufferDescriptor::setRetainedReferences(bool retainedReferences)
205{
206    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setRetainedReferences_), retainedReferences);
207}
208
209// property: errorOptions
210_MTL_INLINE MTL::CommandBufferErrorOption MTL::CommandBufferDescriptor::errorOptions() const
211{
212    return Object::sendMessage<MTL::CommandBufferErrorOption>(this, _MTL_PRIVATE_SEL(errorOptions));
213}
214
215_MTL_INLINE void MTL::CommandBufferDescriptor::setErrorOptions(MTL::CommandBufferErrorOption errorOptions)
216{
217    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setErrorOptions_), errorOptions);
218}
219
220// property: label
221_MTL_INLINE NS::String* MTL::CommandBufferEncoderInfo::label() const
222{
223    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
224}
225
226// property: debugSignposts
227_MTL_INLINE NS::Array* MTL::CommandBufferEncoderInfo::debugSignposts() const
228{
229    return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(debugSignposts));
230}
231
232// property: errorState
233_MTL_INLINE MTL::CommandEncoderErrorState MTL::CommandBufferEncoderInfo::errorState() const
234{
235    return Object::sendMessage<MTL::CommandEncoderErrorState>(this, _MTL_PRIVATE_SEL(errorState));
236}
237
238_MTL_INLINE void MTL::CommandBuffer::addScheduledHandler(const HandlerFunction& function)
239{
240    __block HandlerFunction blockFunction = function;
241
242    addScheduledHandler(^(MTL::CommandBuffer* pCommandBuffer) { blockFunction(pCommandBuffer); });
243}
244
245_MTL_INLINE void MTL::CommandBuffer::addCompletedHandler(const HandlerFunction& function)
246{
247    __block HandlerFunction blockFunction = function;
248
249    addCompletedHandler(^(MTL::CommandBuffer* pCommandBuffer) { blockFunction(pCommandBuffer); });
250}
251
252// property: device
253_MTL_INLINE MTL::Device* MTL::CommandBuffer::device() const
254{
255    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));
256}
257
258// property: commandQueue
259_MTL_INLINE MTL::CommandQueue* MTL::CommandBuffer::commandQueue() const
260{
261    return Object::sendMessage<MTL::CommandQueue*>(this, _MTL_PRIVATE_SEL(commandQueue));
262}
263
264// property: retainedReferences
265_MTL_INLINE bool MTL::CommandBuffer::retainedReferences() const
266{
267    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(retainedReferences));
268}
269
270// property: errorOptions
271_MTL_INLINE MTL::CommandBufferErrorOption MTL::CommandBuffer::errorOptions() const
272{
273    return Object::sendMessage<MTL::CommandBufferErrorOption>(this, _MTL_PRIVATE_SEL(errorOptions));
274}
275
276// property: label
277_MTL_INLINE NS::String* MTL::CommandBuffer::label() const
278{
279    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
280}
281
282_MTL_INLINE void MTL::CommandBuffer::setLabel(const NS::String* label)
283{
284    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);
285}
286
287// property: kernelStartTime
288_MTL_INLINE CFTimeInterval MTL::CommandBuffer::kernelStartTime() const
289{
290    return Object::sendMessage<CFTimeInterval>(this, _MTL_PRIVATE_SEL(kernelStartTime));
291}
292
293// property: kernelEndTime
294_MTL_INLINE CFTimeInterval MTL::CommandBuffer::kernelEndTime() const
295{
296    return Object::sendMessage<CFTimeInterval>(this, _MTL_PRIVATE_SEL(kernelEndTime));
297}
298
299// property: logs
300_MTL_INLINE MTL::LogContainer* MTL::CommandBuffer::logs() const
301{
302    return Object::sendMessage<MTL::LogContainer*>(this, _MTL_PRIVATE_SEL(logs));
303}
304
305// property: GPUStartTime
306_MTL_INLINE CFTimeInterval MTL::CommandBuffer::GPUStartTime() const
307{
308    return Object::sendMessage<CFTimeInterval>(this, _MTL_PRIVATE_SEL(GPUStartTime));
309}
310
311// property: GPUEndTime
312_MTL_INLINE CFTimeInterval MTL::CommandBuffer::GPUEndTime() const
313{
314    return Object::sendMessage<CFTimeInterval>(this, _MTL_PRIVATE_SEL(GPUEndTime));
315}
316
317// method: enqueue
318_MTL_INLINE void MTL::CommandBuffer::enqueue()
319{
320    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(enqueue));
321}
322
323// method: commit
324_MTL_INLINE void MTL::CommandBuffer::commit()
325{
326    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(commit));
327}
328
329// method: addScheduledHandler:
330_MTL_INLINE void MTL::CommandBuffer::addScheduledHandler(const MTL::CommandBufferHandler block)
331{
332    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addScheduledHandler_), block);
333}
334
335// method: presentDrawable:
336_MTL_INLINE void MTL::CommandBuffer::presentDrawable(const MTL::Drawable* drawable)
337{
338    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(presentDrawable_), drawable);
339}
340
341// method: presentDrawable:atTime:
342_MTL_INLINE void MTL::CommandBuffer::presentDrawableAtTime(const MTL::Drawable* drawable, CFTimeInterval presentationTime)
343{
344    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(presentDrawable_atTime_), drawable, presentationTime);
345}
346
347// method: presentDrawable:afterMinimumDuration:
348_MTL_INLINE void MTL::CommandBuffer::presentDrawableAfterMinimumDuration(const MTL::Drawable* drawable, CFTimeInterval duration)
349{
350    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(presentDrawable_afterMinimumDuration_), drawable, duration);
351}
352
353// method: waitUntilScheduled
354_MTL_INLINE void MTL::CommandBuffer::waitUntilScheduled()
355{
356    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitUntilScheduled));
357}
358
359// method: addCompletedHandler:
360_MTL_INLINE void MTL::CommandBuffer::addCompletedHandler(const MTL::CommandBufferHandler block)
361{
362    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addCompletedHandler_), block);
363}
364
365// method: waitUntilCompleted
366_MTL_INLINE void MTL::CommandBuffer::waitUntilCompleted()
367{
368    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitUntilCompleted));
369}
370
371// property: status
372_MTL_INLINE MTL::CommandBufferStatus MTL::CommandBuffer::status() const
373{
374    return Object::sendMessage<MTL::CommandBufferStatus>(this, _MTL_PRIVATE_SEL(status));
375}
376
377// property: error
378_MTL_INLINE NS::Error* MTL::CommandBuffer::error() const
379{
380    return Object::sendMessage<NS::Error*>(this, _MTL_PRIVATE_SEL(error));
381}
382
383// method: blitCommandEncoder
384_MTL_INLINE MTL::BlitCommandEncoder* MTL::CommandBuffer::blitCommandEncoder()
385{
386    return Object::sendMessage<MTL::BlitCommandEncoder*>(this, _MTL_PRIVATE_SEL(blitCommandEncoder));
387}
388
389// method: renderCommandEncoderWithDescriptor:
390_MTL_INLINE MTL::RenderCommandEncoder* MTL::CommandBuffer::renderCommandEncoder(const MTL::RenderPassDescriptor* renderPassDescriptor)
391{
392    return Object::sendMessage<MTL::RenderCommandEncoder*>(this, _MTL_PRIVATE_SEL(renderCommandEncoderWithDescriptor_), renderPassDescriptor);
393}
394
395// method: computeCommandEncoderWithDescriptor:
396_MTL_INLINE MTL::ComputeCommandEncoder* MTL::CommandBuffer::computeCommandEncoder(const MTL::ComputePassDescriptor* computePassDescriptor)
397{
398    return Object::sendMessage<MTL::ComputeCommandEncoder*>(this, _MTL_PRIVATE_SEL(computeCommandEncoderWithDescriptor_), computePassDescriptor);
399}
400
401// method: blitCommandEncoderWithDescriptor:
402_MTL_INLINE MTL::BlitCommandEncoder* MTL::CommandBuffer::blitCommandEncoder(const MTL::BlitPassDescriptor* blitPassDescriptor)
403{
404    return Object::sendMessage<MTL::BlitCommandEncoder*>(this, _MTL_PRIVATE_SEL(blitCommandEncoderWithDescriptor_), blitPassDescriptor);
405}
406
407// method: computeCommandEncoder
408_MTL_INLINE MTL::ComputeCommandEncoder* MTL::CommandBuffer::computeCommandEncoder()
409{
410    return Object::sendMessage<MTL::ComputeCommandEncoder*>(this, _MTL_PRIVATE_SEL(computeCommandEncoder));
411}
412
413// method: computeCommandEncoderWithDispatchType:
414_MTL_INLINE MTL::ComputeCommandEncoder* MTL::CommandBuffer::computeCommandEncoder(MTL::DispatchType dispatchType)
415{
416    return Object::sendMessage<MTL::ComputeCommandEncoder*>(this, _MTL_PRIVATE_SEL(computeCommandEncoderWithDispatchType_), dispatchType);
417}
418
419// method: encodeWaitForEvent:value:
420_MTL_INLINE void MTL::CommandBuffer::encodeWait(const MTL::Event* event, uint64_t value)
421{
422    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(encodeWaitForEvent_value_), event, value);
423}
424
425// method: encodeSignalEvent:value:
426_MTL_INLINE void MTL::CommandBuffer::encodeSignalEvent(const MTL::Event* event, uint64_t value)
427{
428    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(encodeSignalEvent_value_), event, value);
429}
430
431// method: parallelRenderCommandEncoderWithDescriptor:
432_MTL_INLINE MTL::ParallelRenderCommandEncoder* MTL::CommandBuffer::parallelRenderCommandEncoder(const MTL::RenderPassDescriptor* renderPassDescriptor)
433{
434    return Object::sendMessage<MTL::ParallelRenderCommandEncoder*>(this, _MTL_PRIVATE_SEL(parallelRenderCommandEncoderWithDescriptor_), renderPassDescriptor);
435}
436
437// method: resourceStateCommandEncoder
438_MTL_INLINE MTL::ResourceStateCommandEncoder* MTL::CommandBuffer::resourceStateCommandEncoder()
439{
440    return Object::sendMessage<MTL::ResourceStateCommandEncoder*>(this, _MTL_PRIVATE_SEL(resourceStateCommandEncoder));
441}
442
443// method: resourceStateCommandEncoderWithDescriptor:
444_MTL_INLINE MTL::ResourceStateCommandEncoder* MTL::CommandBuffer::resourceStateCommandEncoder(const MTL::ResourceStatePassDescriptor* resourceStatePassDescriptor)
445{
446    return Object::sendMessage<MTL::ResourceStateCommandEncoder*>(this, _MTL_PRIVATE_SEL(resourceStateCommandEncoderWithDescriptor_), resourceStatePassDescriptor);
447}
448
449// method: accelerationStructureCommandEncoder
450_MTL_INLINE MTL::AccelerationStructureCommandEncoder* MTL::CommandBuffer::accelerationStructureCommandEncoder()
451{
452    return Object::sendMessage<MTL::AccelerationStructureCommandEncoder*>(this, _MTL_PRIVATE_SEL(accelerationStructureCommandEncoder));
453}
454
455// method: pushDebugGroup:
456_MTL_INLINE void MTL::CommandBuffer::pushDebugGroup(const NS::String* string)
457{
458    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(pushDebugGroup_), string);
459}
460
461// method: popDebugGroup
462_MTL_INLINE void MTL::CommandBuffer::popDebugGroup()
463{
464    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(popDebugGroup));
465}