1 module metal.blitcommandencoder;
2 
3 version(D_ObjectiveC):
4 extern(Objective-C):
5 import metal.metal;
6 import metal.texture;
7 
8 ///The options that enable behavior for some blit operations.
9 enum MTLBlitOption : NSUInteger
10 {
11     ///A blit option that copies the depth portion of a combined depth and stencil texture to or from a buffer.
12     DepthFromDepthStencil = 1 << 0,
13     ///A blit option that copies the stencil portion of a combined depth and stencil texture to or from a buffer.
14     StencilFromDepthStencil = 1 << 1,
15     ///A blit option that copies PVRTC data between a texture and a buffer.
16     RowLinearPVRTC = 1 << 2,
17     ///A blit option that clears other blit options, which removes any optional behavior for a blit operation.
18     None = 0
19 }
20 
21 ///An interface you can use to encode GPU commands that copy and modify the underlying memory of various Metal resources.
22 extern interface MTLBlitCommandEncoder : MTLCommandEncoder
23 {
24     ///Encodes a command that fills a buffer with a constant value for each byte.
25     @selector("fillBuffer:range:value:")
26     void fillBuffer(MTLBuffer buffer, NSRange range, ubyte value);
27 
28     ///Encodes a command that generates mipmaps for a texture from the base mipmap level up to the highest mipmap level.
29     @selector("generateMipmapsForTexture:")
30     void generateMipmapsForTexture(MTLTexture);
31 
32     ///Encodes a command that copies data from one buffer into another.
33     @selector("copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:")
34     void copyFromBuffer(
35         MTLBuffer sourceBuffer,
36         NSUInteger sourceOffset,
37         MTLBuffer destinationBuffer,
38         NSUInteger destinationOffset,
39         NSUInteger size
40     );
41 
42     ///Encodes a command that copies data from one texture to another.
43     @selector("copyFromTexture:toTexture:")
44     void copyFromTexture(MTLTexture source, MTLTexture ddestination);
45 
46     ///Encodes a command that copies slices of a texture to another texture’s slices.
47     @selector("copyFromTexture:sourceSlice:sourceLevel:toTexture:destinationSlice:destinationLevel:sliceCount:levelCount:")
48     void copyFromTexture(
49         MTLTexture sourceTexture, 
50         NSUInteger sourceSlice,
51         NSUInteger sourceLevel,
52         MTLTexture destinationTexture,
53         NSUInteger destinationSlice,
54         NSUInteger destinationLevel,
55         NSUInteger sliceCount,
56         NSUInteger levelCount,
57     );
58 
59     ///Encodes a command that copies image data from a texture’s slice into another slice.
60     @selector("copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:")
61     void copyFromTexture(
62         MTLTexture sourceTexture,
63         NSUInteger sourceSlice,
64         NSUInteger sourceLevel,
65         MTLOrigin sourceOrigin,
66         MTLSize sourceSize,
67         MTLTexture destinationTexture,
68         NSUInteger destinationSlice,
69         NSUInteger destinationLevel,
70         MTLOrigin destinationOrigin,
71     );
72 
73     ///Encodes a command to copy image data from a source buffer into a destination texture.
74     @selector("copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:")
75     void copyFromBuffer(MTLBuffer sourceBuffer,
76         NSUInteger sourceOffset,
77         NSUInteger sourceBytesPerRow,
78         NSUInteger sourceBytesPerImage,
79         MTLSize sourceSize,
80         MTLTexture destinationTexture,
81         NSUInteger destinationSlice,
82         NSUInteger destinationLevel,
83         MTLOrigin destinationOrigin,
84     );
85 
86     ///Encodes a command to copy image data from a source buffer into a destination texture.
87     @selector("copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:")
88     void copyFromBuffer(MTLBuffer sourceBuffer,
89         NSUInteger sourceOffset,
90         NSUInteger sourceBytesPerRow,
91         NSUInteger sourceBytesPerImage,
92         MTLSize sourceSize,
93         MTLTexture destinationTexture,
94         NSUInteger destinationSlice,
95         NSUInteger destinationLevel,
96         MTLOrigin destinationOrigin,
97         MTLBlitOption options,
98     );
99 
100     ///Encodes a command that copies image data from a texture slice to a buffer.
101     @selector("copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:")
102     void copyFromTexture(MTLTexture sourceTexture, 
103         NSUInteger sourceSlice,
104         NSUInteger sourceLevel,
105         MTLOrigin sourceOrigin,
106         MTLSize sourceSize,
107         MTLBuffer destinationBuffer,
108         NSUInteger destinationOffset,
109         NSUInteger destinationBytesPerRow,
110         NSUInteger destinationBytesPerImage,
111     );
112 
113     ///Encodes a command that copies image data from a texture slice to a buffer, and provides options for special texture formats.
114     @selector("copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:")
115     void copyFromTexture(MTLTexture sourceTexture, 
116         NSUInteger sourceSlice,
117         NSUInteger sourceLevel,
118         MTLOrigin sourceOrigin,
119         MTLSize sourceSize,
120         MTLBuffer destinationBuffer,
121         NSUInteger destinationOffset,
122         NSUInteger destinationBytesPerRow,
123         NSUInteger destinationBytesPerImage,
124         MTLBlitOption options,
125     );
126 
127     ///Encodes a command that improves the performance of the GPU’s accesses to a texture.
128     @selector("optimizeContentsForGPUAccess:")
129     void optimizeContentsForGPUAccess(MTLTexture texture);
130 
131     ///Encodes a command that improves the performance of the GPU’s accesses to a specific portion of a texture.
132     @selector("optimizeContentsForGPUAccess:slice:level:")
133     void optimizeContentsForGPUAccess(MTLTexture texture, 
134         NSUInteger slice,
135         NSUInteger level
136     );
137 
138     ///Encodes a command that improves the performance of the CPU’s accesses to a texture.
139     @selector("optimizeContentsForCPUAccess:")
140     void optimizeContentsForCPUAccess(MTLTexture texture);
141 
142     ///Encodes a command that improves the performance of the CPU’s accesses to a specific portion of a texture.
143     @selector("optimizeContentsForCPUAccess:slice:level:")
144     void optimizeContentsForCPUAccess(MTLTexture texture, 
145         NSUInteger slice,
146         NSUInteger level
147     );
148 
149     ///Encodes a command that synchronizes the CPU’s copy of a managed resource, such as a buffer or texture, so that it matches the GPU’s copy.
150     @selector("synchronizeResource:")
151     void synchronizeResource(MTLResource resource);
152 
153     ///Encodes a command that synchronizes a part of the CPU’s copy of a texture so that it matches the GPU’s copy.
154     @selector("synchronizeTexture:slice:level:")
155     void synchronizeTexture(MTLTexture texture,
156         NSUInteger slice,
157         NSUInteger level,
158     );
159 
160     ///Encodes a command that instructs the GPU to update a fence, which can signal a pass that’s waiting for it.
161     @selector("updateFence:")
162     void updateFence(MTLFence);
163 
164     ///Encodes a command that instructs the GPU to wait until a pass updates a fence.
165     @selector("waitForFence:")
166     void waitForFence(MTLFence);
167 
168     // ///Encodes a command that copies commands from one indirect command buffer into another.
169     // @selector("copyIndirectCommandBuffer:sourceRange:destination:destinationIndex:")
170     // void copyIndirectCommandBuffer(MTLIndirectCommandBuffer source, 
171     //     NSRange sourceRange,
172     //     MTLIndirectCommandBuffer destination,
173     //     NSUInteger destinationIndex,
174     // );
175 
176     // ///Encodes a command that resets a range of commands in an indirect command buffer.
177     // @selector("resetCommandsInBuffer:withRange:")
178     // void resetCommandsInBuffer(MTLIndirectCommandBuffer buffer, NSRange range);
179 
180     // ///Encodes a command that can improve the performance of a range of commands within an indirect command buffer.
181     // @selector("optimizeIndirectCommandBuffer:withRange:")
182     // void optimizeIndirectCommandBuffer(
183     //     MTLIndirectCommandBuffer indirectCommandBuffer, 
184     //     NSRange range
185     // );
186 
187     // ///Encodes a command that samples the GPU’s hardware counters during a blit pass and stores the data in a counter sample buffer.
188     // @selector("sampleCountersInBuffer:atSampleIndex:withBarrier:")
189     // void sampleCountersInBuffer(MTLCounterSampleBuffer sampleBuffer, 
190     //     NSUInteger sampleIndex, 
191     //     BOOL barrier,
192     // );
193 
194     // ///Encodes a command that resolves the data from the samples in a sample counter buffer and stores the results into a buffer.
195     // @selector("resolveCounters:inRange:destinationBuffer:destinationOffset:")
196     // void resolveCounters(MTLCounterSampleBuffer sampleBuffer, 
197     //     NSRange range,
198     //     MTLBuffer destinationBuffer,
199     //     NSUInteger destinationOffset,
200     // );
201 
202     ///Encodes a command that retrieves a sparse texture’s access data for a specific region, mipmap level, and slice.
203     @selector("getTextureAccessCounters:region:mipLevel:slice:resetCounters:countersBuffer:countersBufferOffset:")
204     void getTextureAccessCounters(MTLTexture texture, 
205         MTLRegion region,
206         NSUInteger mipLevel,
207         NSUInteger slice,
208         BOOL resetCounters,
209         MTLBuffer countersBuffer,
210         NSUInteger countersBufferOffset,
211     );
212 
213     ///Encodes a command that resets a sparse texture’s access data for a specific region, mipmap level, and slice.
214     @selector("resetTextureAccessCounters:region:mipLevel:slice:")
215     void resetTextureAccessCounters(MTLTexture texture,
216         MTLRegion region,
217         NSUInteger mipLevel,
218         NSUInteger slice,
219     );
220 }
221