MTLIndirectCommandBuffer.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLIndirectCommandBuffer.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 "MTLIndirectCommandBuffer.hpp" 30 #include "MTLResource.hpp" 31 #include "MTLTypes.hpp" 32 33 namespace MTL 34 { 35 _MTL_OPTIONS(NS::UInteger, IndirectCommandType) { 36 IndirectCommandTypeDraw = 1, 37 IndirectCommandTypeDrawIndexed = 2, 38 IndirectCommandTypeDrawPatches = 4, 39 IndirectCommandTypeDrawIndexedPatches = 8, 40 IndirectCommandTypeConcurrentDispatch = 32, 41 IndirectCommandTypeConcurrentDispatchThreads = 64, 42 IndirectCommandTypeDrawMeshThreadgroups = 128, 43 IndirectCommandTypeDrawMeshThreads = 256, 44 }; 45 46 struct IndirectCommandBufferExecutionRange 47 { 48 uint32_t location; 49 uint32_t length; 50 } _MTL_PACKED; 51 52 class IndirectCommandBufferDescriptor : public NS::Copying<IndirectCommandBufferDescriptor> 53 { 54 public: 55 static class IndirectCommandBufferDescriptor* alloc(); 56 57 class IndirectCommandBufferDescriptor* init(); 58 59 MTL::IndirectCommandType commandTypes() const; 60 void setCommandTypes(MTL::IndirectCommandType commandTypes); 61 62 bool inheritPipelineState() const; 63 void setInheritPipelineState(bool inheritPipelineState); 64 65 bool inheritBuffers() const; 66 void setInheritBuffers(bool inheritBuffers); 67 68 NS::UInteger maxVertexBufferBindCount() const; 69 void setMaxVertexBufferBindCount(NS::UInteger maxVertexBufferBindCount); 70 71 NS::UInteger maxFragmentBufferBindCount() const; 72 void setMaxFragmentBufferBindCount(NS::UInteger maxFragmentBufferBindCount); 73 74 NS::UInteger maxKernelBufferBindCount() const; 75 void setMaxKernelBufferBindCount(NS::UInteger maxKernelBufferBindCount); 76 77 NS::UInteger maxKernelThreadgroupMemoryBindCount() const; 78 void setMaxKernelThreadgroupMemoryBindCount(NS::UInteger maxKernelThreadgroupMemoryBindCount); 79 80 NS::UInteger maxObjectBufferBindCount() const; 81 void setMaxObjectBufferBindCount(NS::UInteger maxObjectBufferBindCount); 82 83 NS::UInteger maxMeshBufferBindCount() const; 84 void setMaxMeshBufferBindCount(NS::UInteger maxMeshBufferBindCount); 85 86 NS::UInteger maxObjectThreadgroupMemoryBindCount() const; 87 void setMaxObjectThreadgroupMemoryBindCount(NS::UInteger maxObjectThreadgroupMemoryBindCount); 88 89 bool supportRayTracing() const; 90 void setSupportRayTracing(bool supportRayTracing); 91 92 bool supportDynamicAttributeStride() const; 93 void setSupportDynamicAttributeStride(bool supportDynamicAttributeStride); 94 }; 95 96 class IndirectCommandBuffer : public NS::Referencing<IndirectCommandBuffer, Resource> 97 { 98 public: 99 NS::UInteger size() const; 100 101 MTL::ResourceID gpuResourceID() const; 102 103 void reset(NS::Range range); 104 105 class IndirectRenderCommand* indirectRenderCommand(NS::UInteger commandIndex); 106 107 class IndirectComputeCommand* indirectComputeCommand(NS::UInteger commandIndex); 108 }; 109 110 } 111 112 // static method: alloc 113 _MTL_INLINE MTL::IndirectCommandBufferDescriptor* MTL::IndirectCommandBufferDescriptor::alloc() 114 { 115 return NS::Object::alloc<MTL::IndirectCommandBufferDescriptor>(_MTL_PRIVATE_CLS(MTLIndirectCommandBufferDescriptor)); 116 } 117 118 // method: init 119 _MTL_INLINE MTL::IndirectCommandBufferDescriptor* MTL::IndirectCommandBufferDescriptor::init() 120 { 121 return NS::Object::init<MTL::IndirectCommandBufferDescriptor>(); 122 } 123 124 // property: commandTypes 125 _MTL_INLINE MTL::IndirectCommandType MTL::IndirectCommandBufferDescriptor::commandTypes() const 126 { 127 return Object::sendMessage<MTL::IndirectCommandType>(this, _MTL_PRIVATE_SEL(commandTypes)); 128 } 129 130 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setCommandTypes(MTL::IndirectCommandType commandTypes) 131 { 132 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCommandTypes_), commandTypes); 133 } 134 135 // property: inheritPipelineState 136 _MTL_INLINE bool MTL::IndirectCommandBufferDescriptor::inheritPipelineState() const 137 { 138 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(inheritPipelineState)); 139 } 140 141 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setInheritPipelineState(bool inheritPipelineState) 142 { 143 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInheritPipelineState_), inheritPipelineState); 144 } 145 146 // property: inheritBuffers 147 _MTL_INLINE bool MTL::IndirectCommandBufferDescriptor::inheritBuffers() const 148 { 149 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(inheritBuffers)); 150 } 151 152 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setInheritBuffers(bool inheritBuffers) 153 { 154 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInheritBuffers_), inheritBuffers); 155 } 156 157 // property: maxVertexBufferBindCount 158 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxVertexBufferBindCount() const 159 { 160 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxVertexBufferBindCount)); 161 } 162 163 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxVertexBufferBindCount(NS::UInteger maxVertexBufferBindCount) 164 { 165 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxVertexBufferBindCount_), maxVertexBufferBindCount); 166 } 167 168 // property: maxFragmentBufferBindCount 169 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxFragmentBufferBindCount() const 170 { 171 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxFragmentBufferBindCount)); 172 } 173 174 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxFragmentBufferBindCount(NS::UInteger maxFragmentBufferBindCount) 175 { 176 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxFragmentBufferBindCount_), maxFragmentBufferBindCount); 177 } 178 179 // property: maxKernelBufferBindCount 180 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxKernelBufferBindCount() const 181 { 182 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxKernelBufferBindCount)); 183 } 184 185 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxKernelBufferBindCount(NS::UInteger maxKernelBufferBindCount) 186 { 187 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxKernelBufferBindCount_), maxKernelBufferBindCount); 188 } 189 190 // property: maxKernelThreadgroupMemoryBindCount 191 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxKernelThreadgroupMemoryBindCount() const 192 { 193 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxKernelThreadgroupMemoryBindCount)); 194 } 195 196 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxKernelThreadgroupMemoryBindCount(NS::UInteger maxKernelThreadgroupMemoryBindCount) 197 { 198 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxKernelThreadgroupMemoryBindCount_), maxKernelThreadgroupMemoryBindCount); 199 } 200 201 // property: maxObjectBufferBindCount 202 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxObjectBufferBindCount() const 203 { 204 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxObjectBufferBindCount)); 205 } 206 207 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxObjectBufferBindCount(NS::UInteger maxObjectBufferBindCount) 208 { 209 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxObjectBufferBindCount_), maxObjectBufferBindCount); 210 } 211 212 // property: maxMeshBufferBindCount 213 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxMeshBufferBindCount() const 214 { 215 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxMeshBufferBindCount)); 216 } 217 218 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxMeshBufferBindCount(NS::UInteger maxMeshBufferBindCount) 219 { 220 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxMeshBufferBindCount_), maxMeshBufferBindCount); 221 } 222 223 // property: maxObjectThreadgroupMemoryBindCount 224 _MTL_INLINE NS::UInteger MTL::IndirectCommandBufferDescriptor::maxObjectThreadgroupMemoryBindCount() const 225 { 226 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxObjectThreadgroupMemoryBindCount)); 227 } 228 229 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setMaxObjectThreadgroupMemoryBindCount(NS::UInteger maxObjectThreadgroupMemoryBindCount) 230 { 231 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxObjectThreadgroupMemoryBindCount_), maxObjectThreadgroupMemoryBindCount); 232 } 233 234 // property: supportRayTracing 235 _MTL_INLINE bool MTL::IndirectCommandBufferDescriptor::supportRayTracing() const 236 { 237 return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportRayTracing)); 238 } 239 240 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setSupportRayTracing(bool supportRayTracing) 241 { 242 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportRayTracing_), supportRayTracing); 243 } 244 245 // property: supportDynamicAttributeStride 246 _MTL_INLINE bool MTL::IndirectCommandBufferDescriptor::supportDynamicAttributeStride() const 247 { 248 return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportDynamicAttributeStride)); 249 } 250 251 _MTL_INLINE void MTL::IndirectCommandBufferDescriptor::setSupportDynamicAttributeStride(bool supportDynamicAttributeStride) 252 { 253 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportDynamicAttributeStride_), supportDynamicAttributeStride); 254 } 255 256 // property: size 257 _MTL_INLINE NS::UInteger MTL::IndirectCommandBuffer::size() const 258 { 259 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(size)); 260 } 261 262 // property: gpuResourceID 263 _MTL_INLINE MTL::ResourceID MTL::IndirectCommandBuffer::gpuResourceID() const 264 { 265 return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(gpuResourceID)); 266 } 267 268 // method: resetWithRange: 269 _MTL_INLINE void MTL::IndirectCommandBuffer::reset(NS::Range range) 270 { 271 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(resetWithRange_), range); 272 } 273 274 // method: indirectRenderCommandAtIndex: 275 _MTL_INLINE MTL::IndirectRenderCommand* MTL::IndirectCommandBuffer::indirectRenderCommand(NS::UInteger commandIndex) 276 { 277 return Object::sendMessage<MTL::IndirectRenderCommand*>(this, _MTL_PRIVATE_SEL(indirectRenderCommandAtIndex_), commandIndex); 278 } 279 280 // method: indirectComputeCommandAtIndex: 281 _MTL_INLINE MTL::IndirectComputeCommand* MTL::IndirectCommandBuffer::indirectComputeCommand(NS::UInteger commandIndex) 282 { 283 return Object::sendMessage<MTL::IndirectComputeCommand*>(this, _MTL_PRIVATE_SEL(indirectComputeCommandAtIndex_), commandIndex); 284 }