• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_COMMANDS_H_
16 #define DAWNNATIVE_COMMANDS_H_
17 
18 #include "common/Constants.h"
19 
20 #include "dawn_native/Texture.h"
21 
22 #include "dawn_native/dawn_platform.h"
23 
24 #include <array>
25 #include <bitset>
26 
27 namespace dawn_native {
28 
29     // Definition of the commands that are present in the CommandIterator given by the
30     // CommandBufferBuilder. There are not defined in CommandBuffer.h to break some header
31     // dependencies: Ref<Object> needs Object to be defined.
32 
33     enum class Command {
34         BeginComputePass,
35         BeginRenderPass,
36         CopyBufferToBuffer,
37         CopyBufferToTexture,
38         CopyTextureToBuffer,
39         CopyTextureToTexture,
40         Dispatch,
41         DispatchIndirect,
42         Draw,
43         DrawIndexed,
44         DrawIndirect,
45         DrawIndexedIndirect,
46         EndComputePass,
47         EndRenderPass,
48         InsertDebugMarker,
49         PopDebugGroup,
50         PushDebugGroup,
51         SetComputePipeline,
52         SetRenderPipeline,
53         SetStencilReference,
54         SetViewport,
55         SetScissorRect,
56         SetBlendColor,
57         SetBindGroup,
58         SetIndexBuffer,
59         SetVertexBuffers,
60     };
61 
62     struct BeginComputePassCmd {};
63 
64     struct RenderPassColorAttachmentInfo {
65         Ref<TextureViewBase> view;
66         Ref<TextureViewBase> resolveTarget;
67         dawn::LoadOp loadOp;
68         dawn::StoreOp storeOp;
69         dawn_native::Color clearColor;
70     };
71 
72     struct RenderPassDepthStencilAttachmentInfo {
73         Ref<TextureViewBase> view;
74         dawn::LoadOp depthLoadOp;
75         dawn::StoreOp depthStoreOp;
76         dawn::LoadOp stencilLoadOp;
77         dawn::StoreOp stencilStoreOp;
78         float clearDepth;
79         uint32_t clearStencil;
80     };
81 
82     struct BeginRenderPassCmd {
83         std::bitset<kMaxColorAttachments> colorAttachmentsSet;
84         RenderPassColorAttachmentInfo colorAttachments[kMaxColorAttachments];
85         bool hasDepthStencilAttachment;
86         RenderPassDepthStencilAttachmentInfo depthStencilAttachment;
87 
88         // Cache the width, height and sample count of all attachments for convenience
89         uint32_t width;
90         uint32_t height;
91         uint32_t sampleCount;
92     };
93 
94     struct BufferCopy {
95         Ref<BufferBase> buffer;
96         uint64_t offset;       // Bytes
97         uint32_t rowPitch;     // Bytes
98         uint32_t imageHeight;  // Texels
99     };
100 
101     struct TextureCopy {
102         Ref<TextureBase> texture;
103         uint32_t mipLevel;
104         uint32_t arrayLayer;
105         Origin3D origin;  // Texels
106     };
107 
108     struct CopyBufferToBufferCmd {
109         Ref<BufferBase> source;
110         uint64_t sourceOffset;
111         Ref<BufferBase> destination;
112         uint64_t destinationOffset;
113         uint64_t size;
114     };
115 
116     struct CopyBufferToTextureCmd {
117         BufferCopy source;
118         TextureCopy destination;
119         Extent3D copySize;  // Texels
120     };
121 
122     struct CopyTextureToBufferCmd {
123         TextureCopy source;
124         BufferCopy destination;
125         Extent3D copySize;  // Texels
126     };
127 
128     struct CopyTextureToTextureCmd {
129         TextureCopy source;
130         TextureCopy destination;
131         Extent3D copySize;  // Texels
132     };
133 
134     struct DispatchCmd {
135         uint32_t x;
136         uint32_t y;
137         uint32_t z;
138     };
139 
140     struct DispatchIndirectCmd {
141         Ref<BufferBase> indirectBuffer;
142         uint64_t indirectOffset;
143     };
144 
145     struct DrawCmd {
146         uint32_t vertexCount;
147         uint32_t instanceCount;
148         uint32_t firstVertex;
149         uint32_t firstInstance;
150     };
151 
152     struct DrawIndexedCmd {
153         uint32_t indexCount;
154         uint32_t instanceCount;
155         uint32_t firstIndex;
156         int32_t baseVertex;
157         uint32_t firstInstance;
158     };
159 
160     struct DrawIndirectCmd {
161         Ref<BufferBase> indirectBuffer;
162         uint64_t indirectOffset;
163     };
164 
165     struct DrawIndexedIndirectCmd {
166         Ref<BufferBase> indirectBuffer;
167         uint64_t indirectOffset;
168     };
169 
170     struct EndComputePassCmd {};
171 
172     struct EndRenderPassCmd {};
173 
174     struct InsertDebugMarkerCmd {
175         uint32_t length;
176     };
177 
178     struct PopDebugGroupCmd {};
179 
180     struct PushDebugGroupCmd {
181         uint32_t length;
182     };
183 
184     struct SetComputePipelineCmd {
185         Ref<ComputePipelineBase> pipeline;
186     };
187 
188     struct SetRenderPipelineCmd {
189         Ref<RenderPipelineBase> pipeline;
190     };
191 
192     struct SetStencilReferenceCmd {
193         uint32_t reference;
194     };
195 
196     struct SetViewportCmd {
197         float x, y, width, height, minDepth, maxDepth;
198     };
199 
200     struct SetScissorRectCmd {
201         uint32_t x, y, width, height;
202     };
203 
204     struct SetBlendColorCmd {
205         Color color;
206     };
207 
208     struct SetBindGroupCmd {
209         uint32_t index;
210         Ref<BindGroupBase> group;
211         uint32_t dynamicOffsetCount;
212     };
213 
214     struct SetIndexBufferCmd {
215         Ref<BufferBase> buffer;
216         uint64_t offset;
217     };
218 
219     struct SetVertexBuffersCmd {
220         uint32_t startSlot;
221         uint32_t count;
222     };
223 
224     // This needs to be called before the CommandIterator is freed so that the Ref<> present in
225     // the commands have a chance to run their destructor and remove internal references.
226     class CommandIterator;
227     void FreeCommands(CommandIterator* commands);
228 
229     // Helper function to allow skipping over a command when it is unimplemented, while still
230     // consuming the correct amount of data from the command iterator.
231     void SkipCommand(CommandIterator* commands, Command type);
232 
233 }  // namespace dawn_native
234 
235 #endif  // DAWNNATIVE_COMMANDS_H_
236