Path: blob/master/thirdparty/metal-cpp/Metal/MTL4CommandQueue.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Metal/MTL4CommandQueue.hpp3//4// Copyright 2020-2025 Apple Inc.5//6// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.17//18//-------------------------------------------------------------------------------------------------------------------------------------------------------------1920#pragma once2122#include "../Foundation/Foundation.hpp"23#include "MTL4CommitFeedback.hpp"24#include "MTLDefines.hpp"25#include "MTLHeaderBridge.hpp"26#include "MTLPrivate.hpp"27#include "MTLResourceStateCommandEncoder.hpp"28#include "MTLTypes.hpp"29#include <cstdint>30#include <dispatch/dispatch.h>3132namespace MTL33{34class Buffer;35class Device;36class Drawable;37class Event;38class Heap;39class ResidencySet;40class Texture;41}4243namespace MTL444{45class CommandBuffer;46class CommandQueueDescriptor;47class CommitOptions;48struct CopySparseBufferMappingOperation;49struct CopySparseTextureMappingOperation;50struct UpdateSparseBufferMappingOperation;51struct UpdateSparseTextureMappingOperation;52_MTL_ENUM(NS::Integer, CommandQueueError) {53CommandQueueErrorNone = 0,54CommandQueueErrorTimeout = 1,55CommandQueueErrorNotPermitted = 2,56CommandQueueErrorOutOfMemory = 3,57CommandQueueErrorDeviceRemoved = 4,58CommandQueueErrorAccessRevoked = 5,59CommandQueueErrorInternal = 6,60};6162struct UpdateSparseTextureMappingOperation63{64MTL::SparseTextureMappingMode mode;65MTL::Region textureRegion;66NS::UInteger textureLevel;67NS::UInteger textureSlice;68NS::UInteger heapOffset;69} _MTL_PACKED;7071struct CopySparseTextureMappingOperation72{73MTL::Region sourceRegion;74NS::UInteger sourceLevel;75NS::UInteger sourceSlice;76MTL::Origin destinationOrigin;77NS::UInteger destinationLevel;78NS::UInteger destinationSlice;79} _MTL_PACKED;8081struct UpdateSparseBufferMappingOperation82{83MTL::SparseTextureMappingMode mode;84NS::Range bufferRange;85NS::UInteger heapOffset;86} _MTL_PACKED;8788struct CopySparseBufferMappingOperation89{90NS::Range sourceRange;91NS::UInteger destinationOffset;92} _MTL_PACKED;9394class CommitOptions : public NS::Referencing<CommitOptions>95{96public:97void addFeedbackHandler(const MTL4::CommitFeedbackHandler block);98void addFeedbackHandler(const MTL4::CommitFeedbackHandlerFunction& function);99100static CommitOptions* alloc();101102CommitOptions* init();103};104class CommandQueueDescriptor : public NS::Copying<CommandQueueDescriptor>105{106public:107static CommandQueueDescriptor* alloc();108109dispatch_queue_t feedbackQueue() const;110111CommandQueueDescriptor* init();112113NS::String* label() const;114115void setFeedbackQueue(const dispatch_queue_t feedbackQueue);116117void setLabel(const NS::String* label);118};119class CommandQueue : public NS::Referencing<CommandQueue>120{121public:122void addResidencySet(const MTL::ResidencySet* residencySet);123void addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);124125void commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count);126void commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count, const MTL4::CommitOptions* options);127128void copyBufferMappingsFromBuffer(const MTL::Buffer* sourceBuffer, const MTL::Buffer* destinationBuffer, const MTL4::CopySparseBufferMappingOperation* operations, NS::UInteger count);129130void copyTextureMappingsFromTexture(const MTL::Texture* sourceTexture, const MTL::Texture* destinationTexture, const MTL4::CopySparseTextureMappingOperation* operations, NS::UInteger count);131132MTL::Device* device() const;133134NS::String* label() const;135136void removeResidencySet(const MTL::ResidencySet* residencySet);137void removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);138139void signalDrawable(const MTL::Drawable* drawable);140141void signalEvent(const MTL::Event* event, uint64_t value);142143void updateBufferMappings(const MTL::Buffer* buffer, const MTL::Heap* heap, const MTL4::UpdateSparseBufferMappingOperation* operations, NS::UInteger count);144145void updateTextureMappings(const MTL::Texture* texture, const MTL::Heap* heap, const MTL4::UpdateSparseTextureMappingOperation* operations, NS::UInteger count);146147void wait(const MTL::Event* event, uint64_t value);148void wait(const MTL::Drawable* drawable);149};150151}152153_MTL_INLINE void MTL4::CommitOptions::addFeedbackHandler(const MTL4::CommitFeedbackHandler block)154{155Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addFeedbackHandler_), block);156}157158_MTL_INLINE void MTL4::CommitOptions::addFeedbackHandler(const MTL4::CommitFeedbackHandlerFunction& function)159{160__block MTL4::CommitFeedbackHandlerFunction blockFunction = function;161addFeedbackHandler(^(MTL4::CommitFeedback* pFeedback) { blockFunction(pFeedback); });162}163164_MTL_INLINE MTL4::CommitOptions* MTL4::CommitOptions::alloc()165{166return NS::Object::alloc<MTL4::CommitOptions>(_MTL_PRIVATE_CLS(MTL4CommitOptions));167}168169_MTL_INLINE MTL4::CommitOptions* MTL4::CommitOptions::init()170{171return NS::Object::init<MTL4::CommitOptions>();172}173174_MTL_INLINE MTL4::CommandQueueDescriptor* MTL4::CommandQueueDescriptor::alloc()175{176return NS::Object::alloc<MTL4::CommandQueueDescriptor>(_MTL_PRIVATE_CLS(MTL4CommandQueueDescriptor));177}178179_MTL_INLINE dispatch_queue_t MTL4::CommandQueueDescriptor::feedbackQueue() const180{181return Object::sendMessage<dispatch_queue_t>(this, _MTL_PRIVATE_SEL(feedbackQueue));182}183184_MTL_INLINE MTL4::CommandQueueDescriptor* MTL4::CommandQueueDescriptor::init()185{186return NS::Object::init<MTL4::CommandQueueDescriptor>();187}188189_MTL_INLINE NS::String* MTL4::CommandQueueDescriptor::label() const190{191return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));192}193194_MTL_INLINE void MTL4::CommandQueueDescriptor::setFeedbackQueue(const dispatch_queue_t feedbackQueue)195{196Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setFeedbackQueue_), feedbackQueue);197}198199_MTL_INLINE void MTL4::CommandQueueDescriptor::setLabel(const NS::String* label)200{201Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);202}203204_MTL_INLINE void MTL4::CommandQueue::addResidencySet(const MTL::ResidencySet* residencySet)205{206Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySet_), residencySet);207}208209_MTL_INLINE void MTL4::CommandQueue::addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)210{211Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySets_count_), residencySets, count);212}213214_MTL_INLINE void MTL4::CommandQueue::commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count)215{216Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(commit_count_), commandBuffers, count);217}218219_MTL_INLINE void MTL4::CommandQueue::commit(const MTL4::CommandBuffer* const commandBuffers[], NS::UInteger count, const MTL4::CommitOptions* options)220{221Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(commit_count_options_), commandBuffers, count, options);222}223224_MTL_INLINE void MTL4::CommandQueue::copyBufferMappingsFromBuffer(const MTL::Buffer* sourceBuffer, const MTL::Buffer* destinationBuffer, const MTL4::CopySparseBufferMappingOperation* operations, NS::UInteger count)225{226Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(copyBufferMappingsFromBuffer_toBuffer_operations_count_), sourceBuffer, destinationBuffer, operations, count);227}228229_MTL_INLINE void MTL4::CommandQueue::copyTextureMappingsFromTexture(const MTL::Texture* sourceTexture, const MTL::Texture* destinationTexture, const MTL4::CopySparseTextureMappingOperation* operations, NS::UInteger count)230{231Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(copyTextureMappingsFromTexture_toTexture_operations_count_), sourceTexture, destinationTexture, operations, count);232}233234_MTL_INLINE MTL::Device* MTL4::CommandQueue::device() const235{236return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));237}238239_MTL_INLINE NS::String* MTL4::CommandQueue::label() const240{241return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));242}243244_MTL_INLINE void MTL4::CommandQueue::removeResidencySet(const MTL::ResidencySet* residencySet)245{246Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySet_), residencySet);247}248249_MTL_INLINE void MTL4::CommandQueue::removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)250{251Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySets_count_), residencySets, count);252}253254_MTL_INLINE void MTL4::CommandQueue::signalDrawable(const MTL::Drawable* drawable)255{256Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(signalDrawable_), drawable);257}258259_MTL_INLINE void MTL4::CommandQueue::signalEvent(const MTL::Event* event, uint64_t value)260{261Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(signalEvent_value_), event, value);262}263264_MTL_INLINE void MTL4::CommandQueue::updateBufferMappings(const MTL::Buffer* buffer, const MTL::Heap* heap, const MTL4::UpdateSparseBufferMappingOperation* operations, NS::UInteger count)265{266Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(updateBufferMappings_heap_operations_count_), buffer, heap, operations, count);267}268269_MTL_INLINE void MTL4::CommandQueue::updateTextureMappings(const MTL::Texture* texture, const MTL::Heap* heap, const MTL4::UpdateSparseTextureMappingOperation* operations, NS::UInteger count)270{271Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(updateTextureMappings_heap_operations_count_), texture, heap, operations, count);272}273274_MTL_INLINE void MTL4::CommandQueue::wait(const MTL::Event* event, uint64_t value)275{276Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitForEvent_value_), event, value);277}278279_MTL_INLINE void MTL4::CommandQueue::wait(const MTL::Drawable* drawable)280{281Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitForDrawable_), drawable);282}283284285