• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #include "dawn_native/Commands.h"
16 
17 #include "dawn_native/BindGroup.h"
18 #include "dawn_native/Buffer.h"
19 #include "dawn_native/CommandAllocator.h"
20 #include "dawn_native/ComputePipeline.h"
21 #include "dawn_native/RenderPipeline.h"
22 #include "dawn_native/Texture.h"
23 
24 namespace dawn_native {
25 
FreeCommands(CommandIterator * commands)26     void FreeCommands(CommandIterator* commands) {
27         commands->Reset();
28 
29         Command type;
30         while (commands->NextCommandId(&type)) {
31             switch (type) {
32                 case Command::BeginComputePass: {
33                     BeginComputePassCmd* begin = commands->NextCommand<BeginComputePassCmd>();
34                     begin->~BeginComputePassCmd();
35                 } break;
36                 case Command::BeginRenderPass: {
37                     BeginRenderPassCmd* begin = commands->NextCommand<BeginRenderPassCmd>();
38                     begin->~BeginRenderPassCmd();
39                 } break;
40                 case Command::CopyBufferToBuffer: {
41                     CopyBufferToBufferCmd* copy = commands->NextCommand<CopyBufferToBufferCmd>();
42                     copy->~CopyBufferToBufferCmd();
43                 } break;
44                 case Command::CopyBufferToTexture: {
45                     CopyBufferToTextureCmd* copy = commands->NextCommand<CopyBufferToTextureCmd>();
46                     copy->~CopyBufferToTextureCmd();
47                 } break;
48                 case Command::CopyTextureToBuffer: {
49                     CopyTextureToBufferCmd* copy = commands->NextCommand<CopyTextureToBufferCmd>();
50                     copy->~CopyTextureToBufferCmd();
51                 } break;
52                 case Command::CopyTextureToTexture: {
53                     CopyTextureToTextureCmd* copy =
54                         commands->NextCommand<CopyTextureToTextureCmd>();
55                     copy->~CopyTextureToTextureCmd();
56                 } break;
57                 case Command::Dispatch: {
58                     DispatchCmd* dispatch = commands->NextCommand<DispatchCmd>();
59                     dispatch->~DispatchCmd();
60                 } break;
61                 case Command::DispatchIndirect: {
62                     DispatchIndirectCmd* dispatch = commands->NextCommand<DispatchIndirectCmd>();
63                     dispatch->~DispatchIndirectCmd();
64                 } break;
65                 case Command::Draw: {
66                     DrawCmd* draw = commands->NextCommand<DrawCmd>();
67                     draw->~DrawCmd();
68                 } break;
69                 case Command::DrawIndexed: {
70                     DrawIndexedCmd* draw = commands->NextCommand<DrawIndexedCmd>();
71                     draw->~DrawIndexedCmd();
72                 } break;
73                 case Command::DrawIndirect: {
74                     DrawIndirectCmd* draw = commands->NextCommand<DrawIndirectCmd>();
75                     draw->~DrawIndirectCmd();
76                 } break;
77                 case Command::DrawIndexedIndirect: {
78                     DrawIndexedIndirectCmd* draw = commands->NextCommand<DrawIndexedIndirectCmd>();
79                     draw->~DrawIndexedIndirectCmd();
80                 } break;
81                 case Command::EndComputePass: {
82                     EndComputePassCmd* cmd = commands->NextCommand<EndComputePassCmd>();
83                     cmd->~EndComputePassCmd();
84                 } break;
85                 case Command::EndRenderPass: {
86                     EndRenderPassCmd* cmd = commands->NextCommand<EndRenderPassCmd>();
87                     cmd->~EndRenderPassCmd();
88                 } break;
89                 case Command::InsertDebugMarker: {
90                     InsertDebugMarkerCmd* cmd = commands->NextCommand<InsertDebugMarkerCmd>();
91                     commands->NextData<char>(cmd->length + 1);
92                     cmd->~InsertDebugMarkerCmd();
93                 } break;
94                 case Command::PopDebugGroup: {
95                     PopDebugGroupCmd* cmd = commands->NextCommand<PopDebugGroupCmd>();
96                     cmd->~PopDebugGroupCmd();
97                 } break;
98                 case Command::PushDebugGroup: {
99                     PushDebugGroupCmd* cmd = commands->NextCommand<PushDebugGroupCmd>();
100                     commands->NextData<char>(cmd->length + 1);
101                     cmd->~PushDebugGroupCmd();
102                 } break;
103                 case Command::SetComputePipeline: {
104                     SetComputePipelineCmd* cmd = commands->NextCommand<SetComputePipelineCmd>();
105                     cmd->~SetComputePipelineCmd();
106                 } break;
107                 case Command::SetRenderPipeline: {
108                     SetRenderPipelineCmd* cmd = commands->NextCommand<SetRenderPipelineCmd>();
109                     cmd->~SetRenderPipelineCmd();
110                 } break;
111                 case Command::SetStencilReference: {
112                     SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>();
113                     cmd->~SetStencilReferenceCmd();
114                 } break;
115                 case Command::SetViewport: {
116                     SetViewportCmd* cmd = commands->NextCommand<SetViewportCmd>();
117                     cmd->~SetViewportCmd();
118                 } break;
119                 case Command::SetScissorRect: {
120                     SetScissorRectCmd* cmd = commands->NextCommand<SetScissorRectCmd>();
121                     cmd->~SetScissorRectCmd();
122                 } break;
123                 case Command::SetBlendColor: {
124                     SetBlendColorCmd* cmd = commands->NextCommand<SetBlendColorCmd>();
125                     cmd->~SetBlendColorCmd();
126                 } break;
127                 case Command::SetBindGroup: {
128                     SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>();
129                     if (cmd->dynamicOffsetCount > 0) {
130                         commands->NextData<uint64_t>(cmd->dynamicOffsetCount);
131                     }
132                     cmd->~SetBindGroupCmd();
133                 } break;
134                 case Command::SetIndexBuffer: {
135                     SetIndexBufferCmd* cmd = commands->NextCommand<SetIndexBufferCmd>();
136                     cmd->~SetIndexBufferCmd();
137                 } break;
138                 case Command::SetVertexBuffers: {
139                     SetVertexBuffersCmd* cmd = commands->NextCommand<SetVertexBuffersCmd>();
140                     auto buffers = commands->NextData<Ref<BufferBase>>(cmd->count);
141                     for (size_t i = 0; i < cmd->count; ++i) {
142                         (&buffers[i])->~Ref<BufferBase>();
143                     }
144                     commands->NextData<uint64_t>(cmd->count);
145                     cmd->~SetVertexBuffersCmd();
146                 } break;
147             }
148         }
149         commands->DataWasDestroyed();
150     }
151 
SkipCommand(CommandIterator * commands,Command type)152     void SkipCommand(CommandIterator* commands, Command type) {
153         switch (type) {
154             case Command::BeginComputePass:
155                 commands->NextCommand<BeginComputePassCmd>();
156                 break;
157 
158             case Command::BeginRenderPass:
159                 commands->NextCommand<BeginRenderPassCmd>();
160                 break;
161 
162             case Command::CopyBufferToBuffer:
163                 commands->NextCommand<CopyBufferToBufferCmd>();
164                 break;
165 
166             case Command::CopyBufferToTexture:
167                 commands->NextCommand<CopyBufferToTextureCmd>();
168                 break;
169 
170             case Command::CopyTextureToBuffer:
171                 commands->NextCommand<CopyTextureToBufferCmd>();
172                 break;
173 
174             case Command::CopyTextureToTexture:
175                 commands->NextCommand<CopyTextureToTextureCmd>();
176                 break;
177 
178             case Command::Dispatch:
179                 commands->NextCommand<DispatchCmd>();
180                 break;
181 
182             case Command::DispatchIndirect:
183                 commands->NextCommand<DispatchIndirectCmd>();
184                 break;
185 
186             case Command::Draw:
187                 commands->NextCommand<DrawCmd>();
188                 break;
189 
190             case Command::DrawIndexed:
191                 commands->NextCommand<DrawIndexedCmd>();
192                 break;
193 
194             case Command::DrawIndirect:
195                 commands->NextCommand<DrawIndirectCmd>();
196                 break;
197 
198             case Command::DrawIndexedIndirect:
199                 commands->NextCommand<DrawIndexedIndirectCmd>();
200                 break;
201 
202             case Command::EndComputePass:
203                 commands->NextCommand<EndComputePassCmd>();
204                 break;
205 
206             case Command::EndRenderPass:
207                 commands->NextCommand<EndRenderPassCmd>();
208                 break;
209 
210             case Command::InsertDebugMarker: {
211                 InsertDebugMarkerCmd* cmd = commands->NextCommand<InsertDebugMarkerCmd>();
212                 commands->NextData<char>(cmd->length + 1);
213             } break;
214 
215             case Command::PopDebugGroup:
216                 commands->NextCommand<PopDebugGroupCmd>();
217                 break;
218 
219             case Command::PushDebugGroup: {
220                 PushDebugGroupCmd* cmd = commands->NextCommand<PushDebugGroupCmd>();
221                 commands->NextData<char>(cmd->length + 1);
222             } break;
223 
224             case Command::SetComputePipeline:
225                 commands->NextCommand<SetComputePipelineCmd>();
226                 break;
227 
228             case Command::SetRenderPipeline:
229                 commands->NextCommand<SetRenderPipelineCmd>();
230                 break;
231 
232             case Command::SetStencilReference:
233                 commands->NextCommand<SetStencilReferenceCmd>();
234                 break;
235 
236             case Command::SetViewport:
237                 commands->NextCommand<SetViewportCmd>();
238                 break;
239 
240             case Command::SetScissorRect:
241                 commands->NextCommand<SetScissorRectCmd>();
242                 break;
243 
244             case Command::SetBlendColor:
245                 commands->NextCommand<SetBlendColorCmd>();
246                 break;
247 
248             case Command::SetBindGroup:
249                 commands->NextCommand<SetBindGroupCmd>();
250                 break;
251 
252             case Command::SetIndexBuffer:
253                 commands->NextCommand<SetIndexBufferCmd>();
254                 break;
255 
256             case Command::SetVertexBuffers: {
257                 auto* cmd = commands->NextCommand<SetVertexBuffersCmd>();
258                 commands->NextData<Ref<BufferBase>>(cmd->count);
259                 commands->NextData<uint64_t>(cmd->count);
260             } break;
261         }
262     }
263 
264 }  // namespace dawn_native
265