1 module metal.rendercommandencoder;
2 import objc.meta: selector, ObjcExtend;
3 
4 @ObjectiveC final extern(C++):
5 @nogc nothrow:
6 import metal.metal;
7 import metal.texture;
8 
9 ///The type of a top-level Metal Shading Language (MSL) function.
10 enum MTLFunctionType : NSUInteger
11 {
12     ///A vertex function you can use in a render pipeline state object.
13     Vertex = 1,
14     ///A fragment function you can use in a render pipeline state object.
15     Fragment = 2,
16     ///A kernel you can use in a compute pipeline state object.
17     Kernel = 3,
18     ///A function you can use in an intersection function table.
19     Intersection = 6,
20     ///A function you can use in a visible function table.
21     Visible = 5,
22     Mesh = 7,
23     Object = 8
24 }
25 
26 ///An object representing a function that you can add to a visible function table.
27 interface MTLFunctionHandle
28 {
29 @nogc nothrow:
30 
31     ///The device object that created the shader function.
32     @selector("device")
33     MTLDevice device();
34 
35     ///The shader function’s type.
36     @selector("functionType")
37     MTLFunctionType functionType();
38 
39     @selector("name")
40     NSString name();
41 
42 }
43 
44 ///A collection of model data for GPU-accelerated intersection of rays with the model.
45 interface MTLAccelerationStructure
46 {
47 @nogc nothrow:
48 
49     ///The size of the acceleration structure’s memory allocation, in bytes.
50     @selector("size")
51     NSUInteger size();
52 
53     // MTLResourceID gpuResourceID();
54 }
55 
56 ///A table of intersection functions that Metal calls to perform ray-tracing intersection tests.
57 interface MTLIntersectionFunctionTable
58 {
59 @nogc nothrow:
60 
61     ///Sets an entry in the table.
62     @selector("setFunction:atIndex:")
63     void setFunction(MTLFunctionHandle, NSUInteger index);
64 }
65 
66 ///A table of shader functions visible to your app that you can pass into compute commands to customize the behavior of a shader.
67 interface MTLVisibleFunctionTable
68 {
69 @nogc nothrow:
70 
71     ///Sets a table entry to point to a callable function.
72     @selector("setFunction:atIndex:")
73     void setFunction(MTLFunctionHandle, NSUInteger index);
74 
75     ///Sets a range of table entries to point to an array of callable functions.
76     @selector("setFunctions:withRange:")
77     void setFunctions(const(MTLFunctionHandle)*, NSRange range);
78 
79     // MTLResourceID gpuResourceID();
80 }
81 
82 struct MTLVertexAmplificationViewMapping
83 {
84 @nogc nothrow:
85 
86     ///An offset into the list of render targets.
87     uint renderTargetArrayIndexOffset;
88     ///An offset into the list of viewports.
89     uint viewportArrayIndexOffset;
90 }
91 
92 interface MTLRenderCommandEncoder
93 {
94 @nogc nothrow:
95 
96     mixin ObjcExtend!MTLCommandEncoder;
97 
98     @selector("setViewport:")
99     void setViewport(MTLViewport);
100 
101     ///Sets the current render pipeline state object.
102     @selector("setRenderPipelineState:")
103     void setRenderPipelineState(MTLRenderPipelineState pipelineState);
104 
105     ///Sets how to rasterize triangle and triangle strip primitives.
106     @selector("setTriangleFillMode:")
107     void setTriangleFillMode(MTLTriangleFillMode);
108 
109     ///Sets the winding order of front-facing primitives.
110     @selector("setFrontFacingWinding:")
111     void setFrontFacingWinding(MTLWinding);
112 
113     ///Specifies whether to cull primitives when front- or back-facing.
114     @selector("setCullMode:")
115     void setCullMode(MTLCullMode);
116 
117     ///Sets the depth and stencil test state.
118     @selector("setDepthStencilState:")
119     void setDepthStencilState(MTLDepthStencilState);
120 
121     ///Sets a buffer for the vertex function.
122     @selector("setVertexBuffer:offset:atIndex:")
123     void setVertexBuffer(MTLBuffer vertexBuffer, NSUInteger offset, NSUInteger index);
124 
125     ///Sets an array of buffers for the vertex function.
126     @selector("setVertexBuffers:offsets:withRange:")
127     void setVertexBuffers(const(MTLBuffer)* buffers, const(NSUInteger)* offsets, NSRange range);
128 
129     ///Sets where the data begins in a buffer already bound to the vertex shader.
130     @selector("setVertexBufferOffset:atIndex:")
131     void setVertexBufferOffset(NSUInteger offset, NSUInteger index);
132 
133     ///Sets a block of data for the vertex shader.
134     @selector("setVertexBytes:length:atIndex:")
135     void setVertexBytes(const(void)* bytes, NSUInteger length, NSUInteger index);
136 
137     ///Sets a sampler for the vertex function.
138     // @selector("setVertexSamplerState:atIndex:")
139     // void setVertexSamplerState(MTLSamplerState sampler, NSUInteger index);
140 
141     ///Sets a sampler for the vertex function, specifying clamp values for the level of detail.
142     @selector("setVertexSamplerState:lodMinClamp:lodMaxClamp:atIndex:")
143     void setVertexSamplerState(MTLSamplerState state, float lodMinClamp, float lodMaxClamp, NSUInteger index);
144 
145     ///Sets multiple samplers for the vertex function.
146     @selector("setVertexSamplerStates:withRange:")
147     void setVertexSamplerStates(const(MTLSamplerState)* samplers, NSRange range);
148 
149     ///Sets multiple samplers for the vertex function, specifying clamp values for the level of detail of each sampler.
150     @selector("setVertexSamplerStates:lodMinClamps:lodMaxClamps:withRange:")
151     void setVertexSamplerStates(
152         const(MTLSamplerState)* samplers, 
153         const(float)* lodMinClamps,
154         const(float)* lodMaxClamps,
155         NSRange range
156     );
157 
158     ///Sets a texture for the vertex function.
159     @selector("setVertexTexture:atIndex:")
160     void setVertexTexture(MTLTexture texture, NSUInteger index);
161 
162     ///Sets an array of textures for the vertex function.
163     @selector("setVertexTextures:withRange:")
164     void setVertexTextures(const(MTLTexture)* textures, NSRange range);
165 
166     ///Sets a visible function table for the vertex function.
167     @selector("setVertexVisibleFunctionTable:atBufferIndex:")
168     void setVertexVisibleFunctionTable(MTLVisibleFunctionTable, NSUInteger bufferIndex);
169 
170     ///Sets an array of visible function tables for the vertex function.
171     @selector("setVertexVisibleFunctionTables:withBufferRange:")
172     void setVertexVisibleFunctionTables(const(MTLVisibleFunctionTable)*, NSRange range);
173 
174     ///Sets a intersection function table for the vertex function.
175     @selector("setVertexIntersectionFunctionTable:atBufferIndex:")
176     void setVertexIntersectionFunctionTable(MTLIntersectionFunctionTable, NSUInteger index);
177 
178     ///Sets an array of intersection function tables for the vertex function.
179     @selector("setVertexIntersectionFunctionTables:withBufferRange:")
180     void setVertexIntersectionFunctionTables(const(MTLIntersectionFunctionTable)*, NSRange range);
181 
182     ///Sets an acceleration structure for the vertex function.
183     @selector("setVertexAccelerationStructure:atBufferIndex:")
184     void setVertexAccelerationStructure(MTLAccelerationStructure, NSUInteger bufferIndex);
185 
186     ///Sets a buffer for the fragment function.
187     @selector("setFragmentBuffer:offset:atIndex:")
188     void setFragmentBuffer(MTLBuffer, NSUInteger offset, NSUInteger index);
189     
190     ///Sets an array of buffers for the fragment function in a range of indices in the buffer argument table.
191     @selector("setFragmentBuffers:offsets:withRange:")
192     void setFragmentBuffers(const(MTLBuffer)*, const(NSUInteger)* offsets, NSRange range);
193 
194     ///Sets where the data begins in a buffer already bound to the fragment shader.
195     @selector("setFragmentBufferOffset:atIndex:")
196     void setFragmentBufferOffset(NSUInteger offset, NSInteger index);
197 
198     ///Sets a block of data for the fragment shader.
199     @selector("setFragmentBytes:length:atIndex:")
200     void setFragmentBytes(const(void)* bytes, NSUInteger length, NSUInteger index);
201 
202     ///Sets a sampler state for the fragment function at an index in the sampler state argument table.
203     @selector("setFragmentSamplerState:atIndex:")
204     void setFragmentSamplerState(MTLSamplerState, NSUInteger index);
205 
206     ///Sets an array of sampler states for the fragment function in a range of indices in the sampler state argument table.
207     @selector("setFragmentSamplerStates:withRange:")
208     void setFragmentSamplerStates(const(MTLSamplerState)*, NSRange range);
209 
210     ///Sets a sampler state for the fragment function at an index in the sampler state argument table, specifying clamp values for the minimum and maximum level of detail.
211     @selector("setFragmentSamplerState:lodMinClamp:lodMaxClamp:atIndex:")
212     void setFragmentSamplerState(MTLSamplerState, float lodMinClamp, float lodMaxClamp, NSUInteger index);
213 
214     ///Sets sampler states for the fragment function in a range of indices in the sampler state argument table, specifying clamp values for levels of detail.
215     @selector("setFragmentSamplerStates:lodMinClamps:lodMaxClamps:withRange:")
216     void setFragmentSamplerStates(
217         const(MTLSamplerState)*, 
218         const(float)* lodMinClamps,
219         const(float)* lodMaxClamps,
220         NSRange range
221     );
222 
223     ///Sets a texture for the fragment function at an index in the texture argument table.
224     @selector("setFragmentTexture:atIndex:")
225     void setFragmentTexture(MTLTexture, NSUInteger index);
226 
227     ///Sets an array of textures for the fragment function in a range of indices in the texture argument table.
228     @selector("setFragmentTextures:withRange:")
229     void setFragmentTextures(const(MTLTexture)*, NSRange range);
230 
231     ///Sets a visible function table for the fragment function.
232     @selector("setFragmentVisibleFunctionTable:atBufferIndex:")
233     void setFragmentVisibleFunctionTable(MTLVisibleFunctionTable, NSUInteger bufferIndex);
234 
235     ///Sets an array of visible function tables for the fragment function.
236     @selector("setFragmentVisibleFunctionTables:withBufferRange:")
237     void setFragmentVisibleFunctionTables(const(MTLVisibleFunctionTable)*, NSRange range);
238 
239     ///Sets a intersection function table for the fragment function.
240     @selector("setFragmentIntersectionFunctionTable:atBufferIndex:")
241     void setFragmentIntersectionFunctionTable(MTLIntersectionFunctionTable, NSUInteger bufferIndex);
242 
243     ///Sets an array of intersection function tables for the fragment function.
244     @selector("setFragmentIntersectionFunctionTables:withBufferRange:")
245     void setFragmentIntersectionFunctionTables(const(MTLIntersectionFunctionTable*), NSRange range);
246 
247     ///Sets an acceleration structure for the fragment function.
248     @selector("setFragmentAccelerationStructure:atBufferIndex:")
249     void setFragmentAccelerationStructure(MTLAccelerationStructure, NSUInteger bufferIndex);
250 
251     ///Sets the per-patch tessellation factors buffer for the tessellator.
252     @selector("setTessellationFactorBuffer:offset:instanceStride:")
253     void setTessellationFactorBuffer(MTLBuffer, NSUInteger offset, NSUInteger instanceStride);
254 
255     ///Sets the scale factor applied to the per-patch tessellation factors.
256     @selector("setTessellationFactorScale:")
257     void setTessellationFactorScale(float);
258 
259     ///Sets the number of output vertices for each input vertex, along with offsets into the layer and viewport lists.
260     @selector("setVertexAmplificationCount:viewMappings:")
261     void setVertexAmplificationCount(NSUInteger count, const(MTLVertexAmplificationViewMapping)* viewMappings);
262 
263     ///Encodes a command to render a number of instances of primitives using vertex data in contiguous array elements, starting from the base instance.
264     @selector("drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:")
265     void drawPrimitives(MTLPrimitiveType, NSUInteger vertexStart, NSUInteger vertexCount, NSUInteger instanceCount, NSUInteger baseInstance);
266 
267     ///Encodes a command to render a number of instances of primitives using vertex data in contiguous array elements.
268     @selector("drawPrimitives:vertexStart:vertexCount:instanceCount:")
269     void drawPrimitives(MTLPrimitiveType, NSUInteger vertexStart, NSUInteger vertexCount, NSUInteger instanceCount);
270 
271     ///Encodes a command to render one instance of primitives using vertex data in contiguous array elements.        
272     @selector("drawPrimitives:vertexStart:vertexCount:")
273     void drawPrimitives(MTLPrimitiveType, NSUInteger vertexStart, NSUInteger vertexCount);
274 
275     
276     ///Encodes a command to render a number of instances of primitives using an index list specified in a buffer, starting from the base vertex of the base instance.
277     @selector("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance:")
278     void drawIndexedPrimitives(
279         MTLPrimitiveType, 
280         NSUInteger indexCount,
281         MTLIndexType indexType,
282         MTLBuffer indexBuffer,
283         NSUInteger indexBufferOffset,
284         NSUInteger instanceCount,
285         NSInteger baseVertex,
286         NSUInteger baseInstance,
287     );
288 
289     ///Encodes a command to render a number of instances of primitives using an index list specified in a buffer.
290     @selector("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:")
291     void drawIndexedPrimitives(
292         MTLPrimitiveType, 
293         NSUInteger indexCount,
294         MTLIndexType indexType,
295         MTLBuffer indexBuffer,
296         NSUInteger indexBufferOffset,
297         NSUInteger instanceCount,
298     );
299 
300     ///Encodes a command to render one instance of primitives using an index list specified in a buffer.
301     @selector("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:")
302     void drawIndexedPrimitives(
303         MTLPrimitiveType, 
304         NSUInteger indexCount,
305         MTLIndexType indexType,
306         MTLBuffer indexBuffer,
307         NSUInteger indexBufferOffset,
308     );
309 
310     ///Encodes a command to render a number of instances of tessellated patches.
311     @selector("drawPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:instanceCount:baseInstance:")
312     void drawPatches(
313         NSUInteger numberOfPatchControlPoints,
314         NSUInteger patchStart,
315         NSUInteger patchCount,
316         MTLBuffer patchIndexBuffer,
317         NSUInteger patchIndexBufferOffset,
318         NSUInteger instanceCount,
319         NSUInteger baseInstance,
320     );
321 
322     ///Encodes a command to render a number of instances of tessellated patches, using a control point index buffer.
323     @selector("drawIndexedPatches:patchStart:patchCount:patchIndexBuffer:patchIndexBufferOffset:controlPointIndexBuffer:controlPointIndexBufferOffset:instanceCount:baseInstance:")
324     void drawIndexedPatches(
325         NSUInteger numberOfPatchControlPoints,
326         NSUInteger patchStart,
327         NSUInteger patchCount,
328         MTLBuffer patchIndexBuffer,
329         NSUInteger patchIndexBufferOffset,
330         MTLBuffer controlPointIndexBuffer,
331         NSUInteger controlPointIndexBufferOffset,
332         NSUInteger instanceCount,
333         NSUInteger baseInstance,
334     );
335     ///Declares that all command generation from the encoder is completed.
336     @selector("endEncoding")
337     void endEncoding();
338 }