yum-mirror/VkFFT
git clone https://git.yummers.dev/yum-mirror/VkFFT
ba7001c
v1.3.1
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 ) { 35CommandBufferStatusNotEnqueued = 0 , 36CommandBufferStatusEnqueued = 1 , 37CommandBufferStatusCommitted = 2 , 38CommandBufferStatusScheduled = 3 , 39CommandBufferStatusCompleted = 4 , 40CommandBufferStatusError = 5 , 41} ; 42 43_MTL_ENUM ( NS :: UInteger , CommandBufferError ) { 44CommandBufferErrorNone = 0 , 45CommandBufferErrorTimeout = 2 , 46CommandBufferErrorPageFault = 3 , 47CommandBufferErrorAccessRevoked = 4 , 48CommandBufferErrorBlacklisted = 4 , 49CommandBufferErrorNotPermitted = 7 , 50CommandBufferErrorOutOfMemory = 8 , 51CommandBufferErrorInvalidResource = 9 , 52CommandBufferErrorMemoryless = 10 , 53CommandBufferErrorDeviceRemoved = 11 , 54CommandBufferErrorStackOverflow = 12 , 55} ; 56 57_MTL_OPTIONS ( NS :: UInteger , CommandBufferErrorOption ) { 58CommandBufferErrorOptionNone = 0 , 59CommandBufferErrorOptionEncoderExecutionStatus = 1 , 60} ; 61 62_MTL_ENUM ( NS :: Integer , CommandEncoderErrorState ) { 63CommandEncoderErrorStateUnknown = 0 , 64CommandEncoderErrorStateCompleted = 1 , 65CommandEncoderErrorStateAffected = 2 , 66CommandEncoderErrorStatePending = 3 , 67CommandEncoderErrorStateFaulted = 4 , 68} ; 69 70class CommandBufferDescriptor : public NS :: Copying < CommandBufferDescriptor > 71{ 72public : 73static class CommandBufferDescriptor * alloc () ; 74 75class CommandBufferDescriptor * init () ; 76 77bool retainedReferences () const ; 78void setRetainedReferences ( bool retainedReferences ) ; 79 80MTL :: CommandBufferErrorOption errorOptions () const ; 81void setErrorOptions ( MTL :: CommandBufferErrorOption errorOptions ) ; 82} ; 83 84class CommandBufferEncoderInfo : public NS :: Referencing < CommandBufferEncoderInfo > 85{ 86public : 87NS :: String * label () const ; 88 89NS :: Array * debugSignposts () const ; 90 91MTL :: CommandEncoderErrorState errorState () const ; 92} ; 93 94_MTL_ENUM ( NS :: UInteger , DispatchType ) { 95DispatchTypeSerial = 0 , 96DispatchTypeConcurrent = 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 : 108void addScheduledHandler ( const HandlerFunction & function ) ; 109 110void addCompletedHandler ( const HandlerFunction & function ) ; 111 112class Device * device () const ; 113 114class CommandQueue * commandQueue () const ; 115 116bool retainedReferences () const ; 117 118MTL :: CommandBufferErrorOption errorOptions () const ; 119 120NS :: String * label () const ; 121void setLabel ( const NS :: String * label ) ; 122 123CFTimeInterval kernelStartTime () const ; 124 125CFTimeInterval kernelEndTime () const ; 126 127class LogContainer * logs () const ; 128 129CFTimeInterval GPUStartTime () const ; 130 131CFTimeInterval GPUEndTime () const ; 132 133void enqueue () ; 134 135void commit () ; 136 137void addScheduledHandler ( const MTL :: CommandBufferHandler block ) ; 138 139void presentDrawable ( const class Drawable * drawable ) ; 140 141void presentDrawableAtTime ( const class Drawable * drawable , CFTimeInterval presentationTime ) ; 142 143void presentDrawableAfterMinimumDuration ( const class Drawable * drawable , CFTimeInterval duration ) ; 144 145void waitUntilScheduled () ; 146 147void addCompletedHandler ( const MTL :: CommandBufferHandler block ) ; 148 149void waitUntilCompleted () ; 150 151MTL :: CommandBufferStatus status () const ; 152 153NS :: Error * error () const ; 154 155class BlitCommandEncoder * blitCommandEncoder () ; 156 157class RenderCommandEncoder * renderCommandEncoder ( const class RenderPassDescriptor * renderPassDescriptor ) ; 158 159class ComputeCommandEncoder * computeCommandEncoder ( const class ComputePassDescriptor * computePassDescriptor ) ; 160 161class BlitCommandEncoder * blitCommandEncoder ( const class BlitPassDescriptor * blitPassDescriptor ) ; 162 163class ComputeCommandEncoder * computeCommandEncoder () ; 164 165class ComputeCommandEncoder * computeCommandEncoder ( MTL :: DispatchType dispatchType ) ; 166 167void encodeWait ( const class Event * event , uint64_t value ) ; 168 169void encodeSignalEvent ( const class Event * event , uint64_t value ) ; 170 171class ParallelRenderCommandEncoder * parallelRenderCommandEncoder ( const class RenderPassDescriptor * renderPassDescriptor ) ; 172 173class ResourceStateCommandEncoder * resourceStateCommandEncoder () ; 174 175class ResourceStateCommandEncoder * resourceStateCommandEncoder ( const class ResourceStatePassDescriptor * resourceStatePassDescriptor ) ; 176 177class AccelerationStructureCommandEncoder * accelerationStructureCommandEncoder () ; 178 179void pushDebugGroup ( const NS :: String * string ) ; 180 181void popDebugGroup () ; 182} ; 183 184} 185 186// static method: alloc 187_MTL_INLINE MTL :: CommandBufferDescriptor * MTL :: CommandBufferDescriptor :: alloc () 188{ 189return NS :: Object :: alloc < MTL :: CommandBufferDescriptor > ( _MTL_PRIVATE_CLS ( MTLCommandBufferDescriptor )) ; 190} 191 192// method: init 193_MTL_INLINE MTL :: CommandBufferDescriptor * MTL :: CommandBufferDescriptor :: init () 194{ 195return NS :: Object :: init < MTL :: CommandBufferDescriptor > () ; 196} 197 198// property: retainedReferences 199_MTL_INLINE bool MTL :: CommandBufferDescriptor :: retainedReferences () const 200{ 201return Object :: sendMessage < bool > ( this , _MTL_PRIVATE_SEL ( retainedReferences )) ; 202} 203 204_MTL_INLINE void MTL :: CommandBufferDescriptor :: setRetainedReferences ( bool retainedReferences ) 205{ 206Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( setRetainedReferences_ ) , retainedReferences ) ; 207} 208 209// property: errorOptions 210_MTL_INLINE MTL :: CommandBufferErrorOption MTL :: CommandBufferDescriptor :: errorOptions () const 211{ 212return Object :: sendMessage < MTL :: CommandBufferErrorOption > ( this , _MTL_PRIVATE_SEL ( errorOptions )) ; 213} 214 215_MTL_INLINE void MTL :: CommandBufferDescriptor :: setErrorOptions ( MTL :: CommandBufferErrorOption errorOptions ) 216{ 217Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( setErrorOptions_ ) , errorOptions ) ; 218} 219 220// property: label 221_MTL_INLINE NS :: String * MTL :: CommandBufferEncoderInfo :: label () const 222{ 223return Object :: sendMessage < NS :: String *> ( this , _MTL_PRIVATE_SEL ( label )) ; 224} 225 226// property: debugSignposts 227_MTL_INLINE NS :: Array * MTL :: CommandBufferEncoderInfo :: debugSignposts () const 228{ 229return Object :: sendMessage < NS :: Array *> ( this , _MTL_PRIVATE_SEL ( debugSignposts )) ; 230} 231 232// property: errorState 233_MTL_INLINE MTL :: CommandEncoderErrorState MTL :: CommandBufferEncoderInfo :: errorState () const 234{ 235return 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 242addScheduledHandler ( ^ ( MTL :: CommandBuffer * pCommandBuffer ) { blockFunction ( pCommandBuffer ) ; }) ; 243} 244 245_MTL_INLINE void MTL :: CommandBuffer :: addCompletedHandler ( const HandlerFunction & function ) 246{ 247__block HandlerFunction blockFunction = function ; 248 249addCompletedHandler ( ^ ( MTL :: CommandBuffer * pCommandBuffer ) { blockFunction ( pCommandBuffer ) ; }) ; 250} 251 252// property: device 253_MTL_INLINE MTL :: Device * MTL :: CommandBuffer :: device () const 254{ 255return Object :: sendMessage < MTL :: Device *> ( this , _MTL_PRIVATE_SEL ( device )) ; 256} 257 258// property: commandQueue 259_MTL_INLINE MTL :: CommandQueue * MTL :: CommandBuffer :: commandQueue () const 260{ 261return Object :: sendMessage < MTL :: CommandQueue *> ( this , _MTL_PRIVATE_SEL ( commandQueue )) ; 262} 263 264// property: retainedReferences 265_MTL_INLINE bool MTL :: CommandBuffer :: retainedReferences () const 266{ 267return Object :: sendMessage < bool > ( this , _MTL_PRIVATE_SEL ( retainedReferences )) ; 268} 269 270// property: errorOptions 271_MTL_INLINE MTL :: CommandBufferErrorOption MTL :: CommandBuffer :: errorOptions () const 272{ 273return Object :: sendMessage < MTL :: CommandBufferErrorOption > ( this , _MTL_PRIVATE_SEL ( errorOptions )) ; 274} 275 276// property: label 277_MTL_INLINE NS :: String * MTL :: CommandBuffer :: label () const 278{ 279return Object :: sendMessage < NS :: String *> ( this , _MTL_PRIVATE_SEL ( label )) ; 280} 281 282_MTL_INLINE void MTL :: CommandBuffer :: setLabel ( const NS :: String * label ) 283{ 284Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( setLabel_ ) , label ) ; 285} 286 287// property: kernelStartTime 288_MTL_INLINE CFTimeInterval MTL :: CommandBuffer :: kernelStartTime () const 289{ 290return Object :: sendMessage < CFTimeInterval > ( this , _MTL_PRIVATE_SEL ( kernelStartTime )) ; 291} 292 293// property: kernelEndTime 294_MTL_INLINE CFTimeInterval MTL :: CommandBuffer :: kernelEndTime () const 295{ 296return Object :: sendMessage < CFTimeInterval > ( this , _MTL_PRIVATE_SEL ( kernelEndTime )) ; 297} 298 299// property: logs 300_MTL_INLINE MTL :: LogContainer * MTL :: CommandBuffer :: logs () const 301{ 302return Object :: sendMessage < MTL :: LogContainer *> ( this , _MTL_PRIVATE_SEL ( logs )) ; 303} 304 305// property: GPUStartTime 306_MTL_INLINE CFTimeInterval MTL :: CommandBuffer :: GPUStartTime () const 307{ 308return Object :: sendMessage < CFTimeInterval > ( this , _MTL_PRIVATE_SEL ( GPUStartTime )) ; 309} 310 311// property: GPUEndTime 312_MTL_INLINE CFTimeInterval MTL :: CommandBuffer :: GPUEndTime () const 313{ 314return Object :: sendMessage < CFTimeInterval > ( this , _MTL_PRIVATE_SEL ( GPUEndTime )) ; 315} 316 317// method: enqueue 318_MTL_INLINE void MTL :: CommandBuffer :: enqueue () 319{ 320Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( enqueue )) ; 321} 322 323// method: commit 324_MTL_INLINE void MTL :: CommandBuffer :: commit () 325{ 326Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( commit )) ; 327} 328 329// method: addScheduledHandler: 330_MTL_INLINE void MTL :: CommandBuffer :: addScheduledHandler ( const MTL :: CommandBufferHandler block ) 331{ 332Object :: 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{ 338Object :: 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{ 344Object :: 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{ 350Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( presentDrawable_afterMinimumDuration_ ) , drawable , duration ) ; 351} 352 353// method: waitUntilScheduled 354_MTL_INLINE void MTL :: CommandBuffer :: waitUntilScheduled () 355{ 356Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( waitUntilScheduled )) ; 357} 358 359// method: addCompletedHandler: 360_MTL_INLINE void MTL :: CommandBuffer :: addCompletedHandler ( const MTL :: CommandBufferHandler block ) 361{ 362Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( addCompletedHandler_ ) , block ) ; 363} 364 365// method: waitUntilCompleted 366_MTL_INLINE void MTL :: CommandBuffer :: waitUntilCompleted () 367{ 368Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( waitUntilCompleted )) ; 369} 370 371// property: status 372_MTL_INLINE MTL :: CommandBufferStatus MTL :: CommandBuffer :: status () const 373{ 374return Object :: sendMessage < MTL :: CommandBufferStatus > ( this , _MTL_PRIVATE_SEL ( status )) ; 375} 376 377// property: error 378_MTL_INLINE NS :: Error * MTL :: CommandBuffer :: error () const 379{ 380return Object :: sendMessage < NS :: Error *> ( this , _MTL_PRIVATE_SEL ( error )) ; 381} 382 383// method: blitCommandEncoder 384_MTL_INLINE MTL :: BlitCommandEncoder * MTL :: CommandBuffer :: blitCommandEncoder () 385{ 386return 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{ 392return 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{ 398return 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{ 404return Object :: sendMessage < MTL :: BlitCommandEncoder *> ( this , _MTL_PRIVATE_SEL ( blitCommandEncoderWithDescriptor_ ) , blitPassDescriptor ) ; 405} 406 407// method: computeCommandEncoder 408_MTL_INLINE MTL :: ComputeCommandEncoder * MTL :: CommandBuffer :: computeCommandEncoder () 409{ 410return 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{ 416return 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{ 422Object :: 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{ 428Object :: 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{ 434return Object :: sendMessage < MTL :: ParallelRenderCommandEncoder *> ( this , _MTL_PRIVATE_SEL ( parallelRenderCommandEncoderWithDescriptor_ ) , renderPassDescriptor ) ; 435} 436 437// method: resourceStateCommandEncoder 438_MTL_INLINE MTL :: ResourceStateCommandEncoder * MTL :: CommandBuffer :: resourceStateCommandEncoder () 439{ 440return 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{ 446return Object :: sendMessage < MTL :: ResourceStateCommandEncoder *> ( this , _MTL_PRIVATE_SEL ( resourceStateCommandEncoderWithDescriptor_ ) , resourceStatePassDescriptor ) ; 447} 448 449// method: accelerationStructureCommandEncoder 450_MTL_INLINE MTL :: AccelerationStructureCommandEncoder * MTL :: CommandBuffer :: accelerationStructureCommandEncoder () 451{ 452return 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{ 458Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( pushDebugGroup_ ) , string ) ; 459} 460 461// method: popDebugGroup 462_MTL_INLINE void MTL :: CommandBuffer :: popDebugGroup () 463{ 464Object :: sendMessage < void > ( this , _MTL_PRIVATE_SEL ( popDebugGroup )) ; 465}