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