MTLComputeCommandEncoder.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLComputeCommandEncoder.hpp 4 // 5 // Copyright 2020-2024 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 "MTLCommandEncoder.hpp" 31 #include "MTLTypes.hpp" 32 33 namespace MTL 34 { 35 struct DispatchThreadgroupsIndirectArguments 36 { 37 uint32_t threadgroupsPerGrid[3]; 38 } _MTL_PACKED; 39 40 struct StageInRegionIndirectArguments 41 { 42 uint32_t stageInOrigin[3]; 43 uint32_t stageInSize[3]; 44 } _MTL_PACKED; 45 46 class ComputeCommandEncoder : public NS::Referencing<ComputeCommandEncoder, CommandEncoder> 47 { 48 public: 49 MTL::DispatchType dispatchType() const; 50 51 void setComputePipelineState(const class ComputePipelineState* state); 52 53 void setBytes(const void* bytes, NS::UInteger length, NS::UInteger index); 54 55 void setBuffer(const class Buffer* buffer, NS::UInteger offset, NS::UInteger index); 56 57 void setBufferOffset(NS::UInteger offset, NS::UInteger index); 58 59 void setBuffers(const class Buffer* const buffers[], const NS::UInteger offsets[], NS::Range range); 60 61 void setBuffer(const class Buffer* buffer, NS::UInteger offset, NS::UInteger stride, NS::UInteger index); 62 63 void setBuffers(const class Buffer* const buffers[], const NS::UInteger* offsets, const NS::UInteger* strides, NS::Range range); 64 65 void setBufferOffset(NS::UInteger offset, NS::UInteger stride, NS::UInteger index); 66 67 void setBytes(const void* bytes, NS::UInteger length, NS::UInteger stride, NS::UInteger index); 68 69 void setVisibleFunctionTable(const class VisibleFunctionTable* visibleFunctionTable, NS::UInteger bufferIndex); 70 71 void setVisibleFunctionTables(const class VisibleFunctionTable* const visibleFunctionTables[], NS::Range range); 72 73 void setIntersectionFunctionTable(const class IntersectionFunctionTable* intersectionFunctionTable, NS::UInteger bufferIndex); 74 75 void setIntersectionFunctionTables(const class IntersectionFunctionTable* const intersectionFunctionTables[], NS::Range range); 76 77 void setAccelerationStructure(const class AccelerationStructure* accelerationStructure, NS::UInteger bufferIndex); 78 79 void setTexture(const class Texture* texture, NS::UInteger index); 80 81 void setTextures(const class Texture* const textures[], NS::Range range); 82 83 void setSamplerState(const class SamplerState* sampler, NS::UInteger index); 84 85 void setSamplerStates(const class SamplerState* const samplers[], NS::Range range); 86 87 void setSamplerState(const class SamplerState* sampler, float lodMinClamp, float lodMaxClamp, NS::UInteger index); 88 89 void setSamplerStates(const class SamplerState* const samplers[], const float lodMinClamps[], const float lodMaxClamps[], NS::Range range); 90 91 void setThreadgroupMemoryLength(NS::UInteger length, NS::UInteger index); 92 93 void setImageblockWidth(NS::UInteger width, NS::UInteger height); 94 95 void setStageInRegion(MTL::Region region); 96 97 void setStageInRegion(const class Buffer* indirectBuffer, NS::UInteger indirectBufferOffset); 98 99 void dispatchThreadgroups(MTL::Size threadgroupsPerGrid, MTL::Size threadsPerThreadgroup); 100 101 void dispatchThreadgroups(const class Buffer* indirectBuffer, NS::UInteger indirectBufferOffset, MTL::Size threadsPerThreadgroup); 102 103 void dispatchThreads(MTL::Size threadsPerGrid, MTL::Size threadsPerThreadgroup); 104 105 void updateFence(const class Fence* fence); 106 107 void waitForFence(const class Fence* fence); 108 109 void useResource(const class Resource* resource, MTL::ResourceUsage usage); 110 111 void useResources(const class Resource* const resources[], NS::UInteger count, MTL::ResourceUsage usage); 112 113 void useHeap(const class Heap* heap); 114 115 void useHeaps(const class Heap* const heaps[], NS::UInteger count); 116 117 void executeCommandsInBuffer(const class IndirectCommandBuffer* indirectCommandBuffer, NS::Range executionRange); 118 119 void executeCommandsInBuffer(const class IndirectCommandBuffer* indirectCommandbuffer, const class Buffer* indirectRangeBuffer, NS::UInteger indirectBufferOffset); 120 121 void memoryBarrier(MTL::BarrierScope scope); 122 123 void memoryBarrier(const class Resource* const resources[], NS::UInteger count); 124 125 void sampleCountersInBuffer(const class CounterSampleBuffer* sampleBuffer, NS::UInteger sampleIndex, bool barrier); 126 }; 127 128 } 129 130 // property: dispatchType 131 _MTL_INLINE MTL::DispatchType MTL::ComputeCommandEncoder::dispatchType() const 132 { 133 return Object::sendMessage<MTL::DispatchType>(this, _MTL_PRIVATE_SEL(dispatchType)); 134 } 135 136 // method: setComputePipelineState: 137 _MTL_INLINE void MTL::ComputeCommandEncoder::setComputePipelineState(const MTL::ComputePipelineState* state) 138 { 139 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setComputePipelineState_), state); 140 } 141 142 // method: setBytes:length:atIndex: 143 _MTL_INLINE void MTL::ComputeCommandEncoder::setBytes(const void* bytes, NS::UInteger length, NS::UInteger index) 144 { 145 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBytes_length_atIndex_), bytes, length, index); 146 } 147 148 // method: setBuffer:offset:atIndex: 149 _MTL_INLINE void MTL::ComputeCommandEncoder::setBuffer(const MTL::Buffer* buffer, NS::UInteger offset, NS::UInteger index) 150 { 151 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBuffer_offset_atIndex_), buffer, offset, index); 152 } 153 154 // method: setBufferOffset:atIndex: 155 _MTL_INLINE void MTL::ComputeCommandEncoder::setBufferOffset(NS::UInteger offset, NS::UInteger index) 156 { 157 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBufferOffset_atIndex_), offset, index); 158 } 159 160 // method: setBuffers:offsets:withRange: 161 _MTL_INLINE void MTL::ComputeCommandEncoder::setBuffers(const MTL::Buffer* const buffers[], const NS::UInteger offsets[], NS::Range range) 162 { 163 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBuffers_offsets_withRange_), buffers, offsets, range); 164 } 165 166 // method: setBuffer:offset:attributeStride:atIndex: 167 _MTL_INLINE void MTL::ComputeCommandEncoder::setBuffer(const MTL::Buffer* buffer, NS::UInteger offset, NS::UInteger stride, NS::UInteger index) 168 { 169 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBuffer_offset_attributeStride_atIndex_), buffer, offset, stride, index); 170 } 171 172 // method: setBuffers:offsets:attributeStrides:withRange: 173 _MTL_INLINE void MTL::ComputeCommandEncoder::setBuffers(const MTL::Buffer* const buffers[], const NS::UInteger* offsets, const NS::UInteger* strides, NS::Range range) 174 { 175 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBuffers_offsets_attributeStrides_withRange_), buffers, offsets, strides, range); 176 } 177 178 // method: setBufferOffset:attributeStride:atIndex: 179 _MTL_INLINE void MTL::ComputeCommandEncoder::setBufferOffset(NS::UInteger offset, NS::UInteger stride, NS::UInteger index) 180 { 181 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBufferOffset_attributeStride_atIndex_), offset, stride, index); 182 } 183 184 // method: setBytes:length:attributeStride:atIndex: 185 _MTL_INLINE void MTL::ComputeCommandEncoder::setBytes(const void* bytes, NS::UInteger length, NS::UInteger stride, NS::UInteger index) 186 { 187 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBytes_length_attributeStride_atIndex_), bytes, length, stride, index); 188 } 189 190 // method: setVisibleFunctionTable:atBufferIndex: 191 _MTL_INLINE void MTL::ComputeCommandEncoder::setVisibleFunctionTable(const MTL::VisibleFunctionTable* visibleFunctionTable, NS::UInteger bufferIndex) 192 { 193 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setVisibleFunctionTable_atBufferIndex_), visibleFunctionTable, bufferIndex); 194 } 195 196 // method: setVisibleFunctionTables:withBufferRange: 197 _MTL_INLINE void MTL::ComputeCommandEncoder::setVisibleFunctionTables(const MTL::VisibleFunctionTable* const visibleFunctionTables[], NS::Range range) 198 { 199 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setVisibleFunctionTables_withBufferRange_), visibleFunctionTables, range); 200 } 201 202 // method: setIntersectionFunctionTable:atBufferIndex: 203 _MTL_INLINE void MTL::ComputeCommandEncoder::setIntersectionFunctionTable(const MTL::IntersectionFunctionTable* intersectionFunctionTable, NS::UInteger bufferIndex) 204 { 205 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setIntersectionFunctionTable_atBufferIndex_), intersectionFunctionTable, bufferIndex); 206 } 207 208 // method: setIntersectionFunctionTables:withBufferRange: 209 _MTL_INLINE void MTL::ComputeCommandEncoder::setIntersectionFunctionTables(const MTL::IntersectionFunctionTable* const intersectionFunctionTables[], NS::Range range) 210 { 211 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setIntersectionFunctionTables_withBufferRange_), intersectionFunctionTables, range); 212 } 213 214 // method: setAccelerationStructure:atBufferIndex: 215 _MTL_INLINE void MTL::ComputeCommandEncoder::setAccelerationStructure(const MTL::AccelerationStructure* accelerationStructure, NS::UInteger bufferIndex) 216 { 217 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setAccelerationStructure_atBufferIndex_), accelerationStructure, bufferIndex); 218 } 219 220 // method: setTexture:atIndex: 221 _MTL_INLINE void MTL::ComputeCommandEncoder::setTexture(const MTL::Texture* texture, NS::UInteger index) 222 { 223 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTexture_atIndex_), texture, index); 224 } 225 226 // method: setTextures:withRange: 227 _MTL_INLINE void MTL::ComputeCommandEncoder::setTextures(const MTL::Texture* const textures[], NS::Range range) 228 { 229 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTextures_withRange_), textures, range); 230 } 231 232 // method: setSamplerState:atIndex: 233 _MTL_INLINE void MTL::ComputeCommandEncoder::setSamplerState(const MTL::SamplerState* sampler, NS::UInteger index) 234 { 235 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSamplerState_atIndex_), sampler, index); 236 } 237 238 // method: setSamplerStates:withRange: 239 _MTL_INLINE void MTL::ComputeCommandEncoder::setSamplerStates(const MTL::SamplerState* const samplers[], NS::Range range) 240 { 241 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSamplerStates_withRange_), samplers, range); 242 } 243 244 // method: setSamplerState:lodMinClamp:lodMaxClamp:atIndex: 245 _MTL_INLINE void MTL::ComputeCommandEncoder::setSamplerState(const MTL::SamplerState* sampler, float lodMinClamp, float lodMaxClamp, NS::UInteger index) 246 { 247 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSamplerState_lodMinClamp_lodMaxClamp_atIndex_), sampler, lodMinClamp, lodMaxClamp, index); 248 } 249 250 // method: setSamplerStates:lodMinClamps:lodMaxClamps:withRange: 251 _MTL_INLINE void MTL::ComputeCommandEncoder::setSamplerStates(const MTL::SamplerState* const samplers[], const float lodMinClamps[], const float lodMaxClamps[], NS::Range range) 252 { 253 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSamplerStates_lodMinClamps_lodMaxClamps_withRange_), samplers, lodMinClamps, lodMaxClamps, range); 254 } 255 256 // method: setThreadgroupMemoryLength:atIndex: 257 _MTL_INLINE void MTL::ComputeCommandEncoder::setThreadgroupMemoryLength(NS::UInteger length, NS::UInteger index) 258 { 259 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setThreadgroupMemoryLength_atIndex_), length, index); 260 } 261 262 // method: setImageblockWidth:height: 263 _MTL_INLINE void MTL::ComputeCommandEncoder::setImageblockWidth(NS::UInteger width, NS::UInteger height) 264 { 265 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setImageblockWidth_height_), width, height); 266 } 267 268 // method: setStageInRegion: 269 _MTL_INLINE void MTL::ComputeCommandEncoder::setStageInRegion(MTL::Region region) 270 { 271 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStageInRegion_), region); 272 } 273 274 // method: setStageInRegionWithIndirectBuffer:indirectBufferOffset: 275 _MTL_INLINE void MTL::ComputeCommandEncoder::setStageInRegion(const MTL::Buffer* indirectBuffer, NS::UInteger indirectBufferOffset) 276 { 277 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStageInRegionWithIndirectBuffer_indirectBufferOffset_), indirectBuffer, indirectBufferOffset); 278 } 279 280 // method: dispatchThreadgroups:threadsPerThreadgroup: 281 _MTL_INLINE void MTL::ComputeCommandEncoder::dispatchThreadgroups(MTL::Size threadgroupsPerGrid, MTL::Size threadsPerThreadgroup) 282 { 283 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(dispatchThreadgroups_threadsPerThreadgroup_), threadgroupsPerGrid, threadsPerThreadgroup); 284 } 285 286 // method: dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup: 287 _MTL_INLINE void MTL::ComputeCommandEncoder::dispatchThreadgroups(const MTL::Buffer* indirectBuffer, NS::UInteger indirectBufferOffset, MTL::Size threadsPerThreadgroup) 288 { 289 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(dispatchThreadgroupsWithIndirectBuffer_indirectBufferOffset_threadsPerThreadgroup_), indirectBuffer, indirectBufferOffset, threadsPerThreadgroup); 290 } 291 292 // method: dispatchThreads:threadsPerThreadgroup: 293 _MTL_INLINE void MTL::ComputeCommandEncoder::dispatchThreads(MTL::Size threadsPerGrid, MTL::Size threadsPerThreadgroup) 294 { 295 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(dispatchThreads_threadsPerThreadgroup_), threadsPerGrid, threadsPerThreadgroup); 296 } 297 298 // method: updateFence: 299 _MTL_INLINE void MTL::ComputeCommandEncoder::updateFence(const MTL::Fence* fence) 300 { 301 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(updateFence_), fence); 302 } 303 304 // method: waitForFence: 305 _MTL_INLINE void MTL::ComputeCommandEncoder::waitForFence(const MTL::Fence* fence) 306 { 307 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(waitForFence_), fence); 308 } 309 310 // method: useResource:usage: 311 _MTL_INLINE void MTL::ComputeCommandEncoder::useResource(const MTL::Resource* resource, MTL::ResourceUsage usage) 312 { 313 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(useResource_usage_), resource, usage); 314 } 315 316 // method: useResources:count:usage: 317 _MTL_INLINE void MTL::ComputeCommandEncoder::useResources(const MTL::Resource* const resources[], NS::UInteger count, MTL::ResourceUsage usage) 318 { 319 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(useResources_count_usage_), resources, count, usage); 320 } 321 322 // method: useHeap: 323 _MTL_INLINE void MTL::ComputeCommandEncoder::useHeap(const MTL::Heap* heap) 324 { 325 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(useHeap_), heap); 326 } 327 328 // method: useHeaps:count: 329 _MTL_INLINE void MTL::ComputeCommandEncoder::useHeaps(const MTL::Heap* const heaps[], NS::UInteger count) 330 { 331 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(useHeaps_count_), heaps, count); 332 } 333 334 // method: executeCommandsInBuffer:withRange: 335 _MTL_INLINE void MTL::ComputeCommandEncoder::executeCommandsInBuffer(const MTL::IndirectCommandBuffer* indirectCommandBuffer, NS::Range executionRange) 336 { 337 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(executeCommandsInBuffer_withRange_), indirectCommandBuffer, executionRange); 338 } 339 340 // method: executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: 341 _MTL_INLINE void MTL::ComputeCommandEncoder::executeCommandsInBuffer(const MTL::IndirectCommandBuffer* indirectCommandbuffer, const MTL::Buffer* indirectRangeBuffer, NS::UInteger indirectBufferOffset) 342 { 343 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(executeCommandsInBuffer_indirectBuffer_indirectBufferOffset_), indirectCommandbuffer, indirectRangeBuffer, indirectBufferOffset); 344 } 345 346 // method: memoryBarrierWithScope: 347 _MTL_INLINE void MTL::ComputeCommandEncoder::memoryBarrier(MTL::BarrierScope scope) 348 { 349 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(memoryBarrierWithScope_), scope); 350 } 351 352 // method: memoryBarrierWithResources:count: 353 _MTL_INLINE void MTL::ComputeCommandEncoder::memoryBarrier(const MTL::Resource* const resources[], NS::UInteger count) 354 { 355 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(memoryBarrierWithResources_count_), resources, count); 356 } 357 358 // method: sampleCountersInBuffer:atSampleIndex:withBarrier: 359 _MTL_INLINE void MTL::ComputeCommandEncoder::sampleCountersInBuffer(const MTL::CounterSampleBuffer* sampleBuffer, NS::UInteger sampleIndex, bool barrier) 360 { 361 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(sampleCountersInBuffer_atSampleIndex_withBarrier_), sampleBuffer, sampleIndex, barrier); 362 }