Path: blob/master/thirdparty/metal-cpp/Metal/MTLComputePipeline.hpp
21345 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Metal/MTLComputePipeline.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 "MTLAllocation.hpp"24#include "MTLDefines.hpp"25#include "MTLHeaderBridge.hpp"26#include "MTLPipeline.hpp"27#include "MTLPrivate.hpp"28#include "MTLTypes.hpp"2930namespace MTL31{32class ComputePipelineDescriptor;33class ComputePipelineReflection;34class ComputePipelineState;35class Device;36class Function;37class FunctionHandle;38class IntersectionFunctionTable;39class IntersectionFunctionTableDescriptor;40class LinkedFunctions;41class PipelineBufferDescriptorArray;42class StageInputOutputDescriptor;43class VisibleFunctionTable;44class VisibleFunctionTableDescriptor;4546}47namespace MTL448{49class BinaryFunction;5051}52namespace MTL53{54class ComputePipelineReflection : public NS::Referencing<ComputePipelineReflection>55{56public:57static ComputePipelineReflection* alloc();5859NS::Array* arguments() const;6061NS::Array* bindings() const;6263ComputePipelineReflection* init();64};65class ComputePipelineDescriptor : public NS::Copying<ComputePipelineDescriptor>66{67public:68static ComputePipelineDescriptor* alloc();6970NS::Array* binaryArchives() const;7172PipelineBufferDescriptorArray* buffers() const;7374Function* computeFunction() const;7576ComputePipelineDescriptor* init();7778NS::Array* insertLibraries() const;7980NS::String* label() const;8182LinkedFunctions* linkedFunctions() const;8384NS::UInteger maxCallStackDepth() const;8586NS::UInteger maxTotalThreadsPerThreadgroup() const;8788NS::Array* preloadedLibraries() const;8990Size requiredThreadsPerThreadgroup() const;9192void reset();9394void setBinaryArchives(const NS::Array* binaryArchives);9596void setComputeFunction(const MTL::Function* computeFunction);9798void setInsertLibraries(const NS::Array* insertLibraries);99100void setLabel(const NS::String* label);101102void setLinkedFunctions(const MTL::LinkedFunctions* linkedFunctions);103104void setMaxCallStackDepth(NS::UInteger maxCallStackDepth);105106void setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup);107108void setPreloadedLibraries(const NS::Array* preloadedLibraries);109110void setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup);111112void setShaderValidation(MTL::ShaderValidation shaderValidation);113114void setStageInputDescriptor(const MTL::StageInputOutputDescriptor* stageInputDescriptor);115116void setSupportAddingBinaryFunctions(bool supportAddingBinaryFunctions);117118void setSupportIndirectCommandBuffers(bool supportIndirectCommandBuffers);119120void setThreadGroupSizeIsMultipleOfThreadExecutionWidth(bool threadGroupSizeIsMultipleOfThreadExecutionWidth);121122ShaderValidation shaderValidation() const;123124StageInputOutputDescriptor* stageInputDescriptor() const;125126bool supportAddingBinaryFunctions() const;127128bool supportIndirectCommandBuffers() const;129130bool threadGroupSizeIsMultipleOfThreadExecutionWidth() const;131};132class ComputePipelineState : public NS::Referencing<ComputePipelineState, Allocation>133{134public:135Device* device() const;136137FunctionHandle* functionHandle(const NS::String* name);138FunctionHandle* functionHandle(const MTL4::BinaryFunction* function);139FunctionHandle* functionHandle(const MTL::Function* function);140141ResourceID gpuResourceID() const;142143NS::UInteger imageblockMemoryLength(MTL::Size imageblockDimensions);144145NS::String* label() const;146147NS::UInteger maxTotalThreadsPerThreadgroup() const;148149ComputePipelineState* newComputePipelineStateWithBinaryFunctions(const NS::Array* additionalBinaryFunctions, NS::Error** error);150ComputePipelineState* newComputePipelineState(const NS::Array* functions, NS::Error** error);151152IntersectionFunctionTable* newIntersectionFunctionTable(const MTL::IntersectionFunctionTableDescriptor* descriptor);153154VisibleFunctionTable* newVisibleFunctionTable(const MTL::VisibleFunctionTableDescriptor* descriptor);155156ComputePipelineReflection* reflection() const;157158Size requiredThreadsPerThreadgroup() const;159160ShaderValidation shaderValidation() const;161162NS::UInteger staticThreadgroupMemoryLength() const;163164bool supportIndirectCommandBuffers() const;165166NS::UInteger threadExecutionWidth() const;167};168169}170_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineReflection::alloc()171{172return NS::Object::alloc<MTL::ComputePipelineReflection>(_MTL_PRIVATE_CLS(MTLComputePipelineReflection));173}174175_MTL_INLINE NS::Array* MTL::ComputePipelineReflection::arguments() const176{177return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(arguments));178}179180_MTL_INLINE NS::Array* MTL::ComputePipelineReflection::bindings() const181{182return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(bindings));183}184185_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineReflection::init()186{187return NS::Object::init<MTL::ComputePipelineReflection>();188}189190_MTL_INLINE MTL::ComputePipelineDescriptor* MTL::ComputePipelineDescriptor::alloc()191{192return NS::Object::alloc<MTL::ComputePipelineDescriptor>(_MTL_PRIVATE_CLS(MTLComputePipelineDescriptor));193}194195_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::binaryArchives() const196{197return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(binaryArchives));198}199200_MTL_INLINE MTL::PipelineBufferDescriptorArray* MTL::ComputePipelineDescriptor::buffers() const201{202return Object::sendMessage<MTL::PipelineBufferDescriptorArray*>(this, _MTL_PRIVATE_SEL(buffers));203}204205_MTL_INLINE MTL::Function* MTL::ComputePipelineDescriptor::computeFunction() const206{207return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(computeFunction));208}209210_MTL_INLINE MTL::ComputePipelineDescriptor* MTL::ComputePipelineDescriptor::init()211{212return NS::Object::init<MTL::ComputePipelineDescriptor>();213}214215_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::insertLibraries() const216{217return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(insertLibraries));218}219220_MTL_INLINE NS::String* MTL::ComputePipelineDescriptor::label() const221{222return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));223}224225_MTL_INLINE MTL::LinkedFunctions* MTL::ComputePipelineDescriptor::linkedFunctions() const226{227return Object::sendMessage<MTL::LinkedFunctions*>(this, _MTL_PRIVATE_SEL(linkedFunctions));228}229230_MTL_INLINE NS::UInteger MTL::ComputePipelineDescriptor::maxCallStackDepth() const231{232return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxCallStackDepth));233}234235_MTL_INLINE NS::UInteger MTL::ComputePipelineDescriptor::maxTotalThreadsPerThreadgroup() const236{237return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTotalThreadsPerThreadgroup));238}239240_MTL_INLINE NS::Array* MTL::ComputePipelineDescriptor::preloadedLibraries() const241{242return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(preloadedLibraries));243}244245_MTL_INLINE MTL::Size MTL::ComputePipelineDescriptor::requiredThreadsPerThreadgroup() const246{247return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(requiredThreadsPerThreadgroup));248}249250_MTL_INLINE void MTL::ComputePipelineDescriptor::reset()251{252Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(reset));253}254255_MTL_INLINE void MTL::ComputePipelineDescriptor::setBinaryArchives(const NS::Array* binaryArchives)256{257Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBinaryArchives_), binaryArchives);258}259260_MTL_INLINE void MTL::ComputePipelineDescriptor::setComputeFunction(const MTL::Function* computeFunction)261{262Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setComputeFunction_), computeFunction);263}264265_MTL_INLINE void MTL::ComputePipelineDescriptor::setInsertLibraries(const NS::Array* insertLibraries)266{267Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInsertLibraries_), insertLibraries);268}269270_MTL_INLINE void MTL::ComputePipelineDescriptor::setLabel(const NS::String* label)271{272Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);273}274275_MTL_INLINE void MTL::ComputePipelineDescriptor::setLinkedFunctions(const MTL::LinkedFunctions* linkedFunctions)276{277Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLinkedFunctions_), linkedFunctions);278}279280_MTL_INLINE void MTL::ComputePipelineDescriptor::setMaxCallStackDepth(NS::UInteger maxCallStackDepth)281{282Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxCallStackDepth_), maxCallStackDepth);283}284285_MTL_INLINE void MTL::ComputePipelineDescriptor::setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup)286{287Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxTotalThreadsPerThreadgroup_), maxTotalThreadsPerThreadgroup);288}289290_MTL_INLINE void MTL::ComputePipelineDescriptor::setPreloadedLibraries(const NS::Array* preloadedLibraries)291{292Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPreloadedLibraries_), preloadedLibraries);293}294295_MTL_INLINE void MTL::ComputePipelineDescriptor::setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup)296{297Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setRequiredThreadsPerThreadgroup_), requiredThreadsPerThreadgroup);298}299300_MTL_INLINE void MTL::ComputePipelineDescriptor::setShaderValidation(MTL::ShaderValidation shaderValidation)301{302Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setShaderValidation_), shaderValidation);303}304305_MTL_INLINE void MTL::ComputePipelineDescriptor::setStageInputDescriptor(const MTL::StageInputOutputDescriptor* stageInputDescriptor)306{307Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStageInputDescriptor_), stageInputDescriptor);308}309310_MTL_INLINE void MTL::ComputePipelineDescriptor::setSupportAddingBinaryFunctions(bool supportAddingBinaryFunctions)311{312Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportAddingBinaryFunctions_), supportAddingBinaryFunctions);313}314315_MTL_INLINE void MTL::ComputePipelineDescriptor::setSupportIndirectCommandBuffers(bool supportIndirectCommandBuffers)316{317Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportIndirectCommandBuffers_), supportIndirectCommandBuffers);318}319320_MTL_INLINE void MTL::ComputePipelineDescriptor::setThreadGroupSizeIsMultipleOfThreadExecutionWidth(bool threadGroupSizeIsMultipleOfThreadExecutionWidth)321{322Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setThreadGroupSizeIsMultipleOfThreadExecutionWidth_), threadGroupSizeIsMultipleOfThreadExecutionWidth);323}324325_MTL_INLINE MTL::ShaderValidation MTL::ComputePipelineDescriptor::shaderValidation() const326{327return Object::sendMessage<MTL::ShaderValidation>(this, _MTL_PRIVATE_SEL(shaderValidation));328}329330_MTL_INLINE MTL::StageInputOutputDescriptor* MTL::ComputePipelineDescriptor::stageInputDescriptor() const331{332return Object::sendMessage<MTL::StageInputOutputDescriptor*>(this, _MTL_PRIVATE_SEL(stageInputDescriptor));333}334335_MTL_INLINE bool MTL::ComputePipelineDescriptor::supportAddingBinaryFunctions() const336{337return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportAddingBinaryFunctions));338}339340_MTL_INLINE bool MTL::ComputePipelineDescriptor::supportIndirectCommandBuffers() const341{342return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportIndirectCommandBuffers));343}344345_MTL_INLINE bool MTL::ComputePipelineDescriptor::threadGroupSizeIsMultipleOfThreadExecutionWidth() const346{347return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(threadGroupSizeIsMultipleOfThreadExecutionWidth));348}349350_MTL_INLINE MTL::Device* MTL::ComputePipelineState::device() const351{352return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));353}354355_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const NS::String* name)356{357return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithName_), name);358}359360_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const MTL4::BinaryFunction* function)361{362return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithBinaryFunction_), function);363}364365_MTL_INLINE MTL::FunctionHandle* MTL::ComputePipelineState::functionHandle(const MTL::Function* function)366{367return Object::sendMessage<MTL::FunctionHandle*>(this, _MTL_PRIVATE_SEL(functionHandleWithFunction_), function);368}369370_MTL_INLINE MTL::ResourceID MTL::ComputePipelineState::gpuResourceID() const371{372return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(gpuResourceID));373}374375_MTL_INLINE NS::UInteger MTL::ComputePipelineState::imageblockMemoryLength(MTL::Size imageblockDimensions)376{377return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(imageblockMemoryLengthForDimensions_), imageblockDimensions);378}379380_MTL_INLINE NS::String* MTL::ComputePipelineState::label() const381{382return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));383}384385_MTL_INLINE NS::UInteger MTL::ComputePipelineState::maxTotalThreadsPerThreadgroup() const386{387return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTotalThreadsPerThreadgroup));388}389390_MTL_INLINE MTL::ComputePipelineState* MTL::ComputePipelineState::newComputePipelineStateWithBinaryFunctions(const NS::Array* additionalBinaryFunctions, NS::Error** error)391{392return Object::sendMessage<MTL::ComputePipelineState*>(this, _MTL_PRIVATE_SEL(newComputePipelineStateWithBinaryFunctions_error_), additionalBinaryFunctions, error);393}394395_MTL_INLINE MTL::ComputePipelineState* MTL::ComputePipelineState::newComputePipelineState(const NS::Array* functions, NS::Error** error)396{397return Object::sendMessage<MTL::ComputePipelineState*>(this, _MTL_PRIVATE_SEL(newComputePipelineStateWithAdditionalBinaryFunctions_error_), functions, error);398}399400_MTL_INLINE MTL::IntersectionFunctionTable* MTL::ComputePipelineState::newIntersectionFunctionTable(const MTL::IntersectionFunctionTableDescriptor* descriptor)401{402return Object::sendMessage<MTL::IntersectionFunctionTable*>(this, _MTL_PRIVATE_SEL(newIntersectionFunctionTableWithDescriptor_), descriptor);403}404405_MTL_INLINE MTL::VisibleFunctionTable* MTL::ComputePipelineState::newVisibleFunctionTable(const MTL::VisibleFunctionTableDescriptor* descriptor)406{407return Object::sendMessage<MTL::VisibleFunctionTable*>(this, _MTL_PRIVATE_SEL(newVisibleFunctionTableWithDescriptor_), descriptor);408}409410_MTL_INLINE MTL::ComputePipelineReflection* MTL::ComputePipelineState::reflection() const411{412return Object::sendMessage<MTL::ComputePipelineReflection*>(this, _MTL_PRIVATE_SEL(reflection));413}414415_MTL_INLINE MTL::Size MTL::ComputePipelineState::requiredThreadsPerThreadgroup() const416{417return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(requiredThreadsPerThreadgroup));418}419420_MTL_INLINE MTL::ShaderValidation MTL::ComputePipelineState::shaderValidation() const421{422return Object::sendMessage<MTL::ShaderValidation>(this, _MTL_PRIVATE_SEL(shaderValidation));423}424425_MTL_INLINE NS::UInteger MTL::ComputePipelineState::staticThreadgroupMemoryLength() const426{427return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(staticThreadgroupMemoryLength));428}429430_MTL_INLINE bool MTL::ComputePipelineState::supportIndirectCommandBuffers() const431{432return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportIndirectCommandBuffers));433}434435_MTL_INLINE NS::UInteger MTL::ComputePipelineState::threadExecutionWidth() const436{437return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(threadExecutionWidth));438}439440441