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/QuerySet.h" 22 #include "dawn_native/RenderBundle.h" 23 #include "dawn_native/RenderPipeline.h" 24 #include "dawn_native/Texture.h" 25 26 namespace dawn_native { 27 FreeCommands(CommandIterator * commands)28 void FreeCommands(CommandIterator* commands) { 29 commands->Reset(); 30 31 Command type; 32 while (commands->NextCommandId(&type)) { 33 switch (type) { 34 case Command::BeginComputePass: { 35 BeginComputePassCmd* begin = commands->NextCommand<BeginComputePassCmd>(); 36 begin->~BeginComputePassCmd(); 37 break; 38 } 39 case Command::BeginOcclusionQuery: { 40 BeginOcclusionQueryCmd* begin = commands->NextCommand<BeginOcclusionQueryCmd>(); 41 begin->~BeginOcclusionQueryCmd(); 42 break; 43 } 44 case Command::BeginRenderPass: { 45 BeginRenderPassCmd* begin = commands->NextCommand<BeginRenderPassCmd>(); 46 begin->~BeginRenderPassCmd(); 47 break; 48 } 49 case Command::CopyBufferToBuffer: { 50 CopyBufferToBufferCmd* copy = commands->NextCommand<CopyBufferToBufferCmd>(); 51 copy->~CopyBufferToBufferCmd(); 52 break; 53 } 54 case Command::CopyBufferToTexture: { 55 CopyBufferToTextureCmd* copy = commands->NextCommand<CopyBufferToTextureCmd>(); 56 copy->~CopyBufferToTextureCmd(); 57 break; 58 } 59 case Command::CopyTextureToBuffer: { 60 CopyTextureToBufferCmd* copy = commands->NextCommand<CopyTextureToBufferCmd>(); 61 copy->~CopyTextureToBufferCmd(); 62 break; 63 } 64 case Command::CopyTextureToTexture: { 65 CopyTextureToTextureCmd* copy = 66 commands->NextCommand<CopyTextureToTextureCmd>(); 67 copy->~CopyTextureToTextureCmd(); 68 break; 69 } 70 case Command::Dispatch: { 71 DispatchCmd* dispatch = commands->NextCommand<DispatchCmd>(); 72 dispatch->~DispatchCmd(); 73 break; 74 } 75 case Command::DispatchIndirect: { 76 DispatchIndirectCmd* dispatch = commands->NextCommand<DispatchIndirectCmd>(); 77 dispatch->~DispatchIndirectCmd(); 78 break; 79 } 80 case Command::Draw: { 81 DrawCmd* draw = commands->NextCommand<DrawCmd>(); 82 draw->~DrawCmd(); 83 break; 84 } 85 case Command::DrawIndexed: { 86 DrawIndexedCmd* draw = commands->NextCommand<DrawIndexedCmd>(); 87 draw->~DrawIndexedCmd(); 88 break; 89 } 90 case Command::DrawIndirect: { 91 DrawIndirectCmd* draw = commands->NextCommand<DrawIndirectCmd>(); 92 draw->~DrawIndirectCmd(); 93 break; 94 } 95 case Command::DrawIndexedIndirect: { 96 DrawIndexedIndirectCmd* draw = commands->NextCommand<DrawIndexedIndirectCmd>(); 97 draw->~DrawIndexedIndirectCmd(); 98 break; 99 } 100 case Command::EndComputePass: { 101 EndComputePassCmd* cmd = commands->NextCommand<EndComputePassCmd>(); 102 cmd->~EndComputePassCmd(); 103 break; 104 } 105 case Command::EndOcclusionQuery: { 106 EndOcclusionQueryCmd* cmd = commands->NextCommand<EndOcclusionQueryCmd>(); 107 cmd->~EndOcclusionQueryCmd(); 108 break; 109 } 110 case Command::EndRenderPass: { 111 EndRenderPassCmd* cmd = commands->NextCommand<EndRenderPassCmd>(); 112 cmd->~EndRenderPassCmd(); 113 break; 114 } 115 case Command::ExecuteBundles: { 116 ExecuteBundlesCmd* cmd = commands->NextCommand<ExecuteBundlesCmd>(); 117 auto bundles = commands->NextData<Ref<RenderBundleBase>>(cmd->count); 118 for (size_t i = 0; i < cmd->count; ++i) { 119 (&bundles[i])->~Ref<RenderBundleBase>(); 120 } 121 cmd->~ExecuteBundlesCmd(); 122 break; 123 } 124 case Command::ClearBuffer: { 125 ClearBufferCmd* cmd = commands->NextCommand<ClearBufferCmd>(); 126 cmd->~ClearBufferCmd(); 127 break; 128 } 129 case Command::InsertDebugMarker: { 130 InsertDebugMarkerCmd* cmd = commands->NextCommand<InsertDebugMarkerCmd>(); 131 commands->NextData<char>(cmd->length + 1); 132 cmd->~InsertDebugMarkerCmd(); 133 break; 134 } 135 case Command::PopDebugGroup: { 136 PopDebugGroupCmd* cmd = commands->NextCommand<PopDebugGroupCmd>(); 137 cmd->~PopDebugGroupCmd(); 138 break; 139 } 140 case Command::PushDebugGroup: { 141 PushDebugGroupCmd* cmd = commands->NextCommand<PushDebugGroupCmd>(); 142 commands->NextData<char>(cmd->length + 1); 143 cmd->~PushDebugGroupCmd(); 144 break; 145 } 146 case Command::ResolveQuerySet: { 147 ResolveQuerySetCmd* cmd = commands->NextCommand<ResolveQuerySetCmd>(); 148 cmd->~ResolveQuerySetCmd(); 149 break; 150 } 151 case Command::SetComputePipeline: { 152 SetComputePipelineCmd* cmd = commands->NextCommand<SetComputePipelineCmd>(); 153 cmd->~SetComputePipelineCmd(); 154 break; 155 } 156 case Command::SetRenderPipeline: { 157 SetRenderPipelineCmd* cmd = commands->NextCommand<SetRenderPipelineCmd>(); 158 cmd->~SetRenderPipelineCmd(); 159 break; 160 } 161 case Command::SetStencilReference: { 162 SetStencilReferenceCmd* cmd = commands->NextCommand<SetStencilReferenceCmd>(); 163 cmd->~SetStencilReferenceCmd(); 164 break; 165 } 166 case Command::SetViewport: { 167 SetViewportCmd* cmd = commands->NextCommand<SetViewportCmd>(); 168 cmd->~SetViewportCmd(); 169 break; 170 } 171 case Command::SetScissorRect: { 172 SetScissorRectCmd* cmd = commands->NextCommand<SetScissorRectCmd>(); 173 cmd->~SetScissorRectCmd(); 174 break; 175 } 176 case Command::SetBlendConstant: { 177 SetBlendConstantCmd* cmd = commands->NextCommand<SetBlendConstantCmd>(); 178 cmd->~SetBlendConstantCmd(); 179 break; 180 } 181 case Command::SetBindGroup: { 182 SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>(); 183 if (cmd->dynamicOffsetCount > 0) { 184 commands->NextData<uint32_t>(cmd->dynamicOffsetCount); 185 } 186 cmd->~SetBindGroupCmd(); 187 break; 188 } 189 case Command::SetIndexBuffer: { 190 SetIndexBufferCmd* cmd = commands->NextCommand<SetIndexBufferCmd>(); 191 cmd->~SetIndexBufferCmd(); 192 break; 193 } 194 case Command::SetVertexBuffer: { 195 SetVertexBufferCmd* cmd = commands->NextCommand<SetVertexBufferCmd>(); 196 cmd->~SetVertexBufferCmd(); 197 break; 198 } 199 case Command::WriteBuffer: { 200 WriteBufferCmd* write = commands->NextCommand<WriteBufferCmd>(); 201 commands->NextData<uint8_t>(write->size); 202 write->~WriteBufferCmd(); 203 break; 204 } 205 case Command::WriteTimestamp: { 206 WriteTimestampCmd* cmd = commands->NextCommand<WriteTimestampCmd>(); 207 cmd->~WriteTimestampCmd(); 208 break; 209 } 210 } 211 } 212 213 commands->MakeEmptyAsDataWasDestroyed(); 214 } 215 SkipCommand(CommandIterator * commands,Command type)216 void SkipCommand(CommandIterator* commands, Command type) { 217 switch (type) { 218 case Command::BeginComputePass: 219 commands->NextCommand<BeginComputePassCmd>(); 220 break; 221 222 case Command::BeginOcclusionQuery: 223 commands->NextCommand<BeginOcclusionQueryCmd>(); 224 break; 225 226 case Command::BeginRenderPass: 227 commands->NextCommand<BeginRenderPassCmd>(); 228 break; 229 230 case Command::CopyBufferToBuffer: 231 commands->NextCommand<CopyBufferToBufferCmd>(); 232 break; 233 234 case Command::CopyBufferToTexture: 235 commands->NextCommand<CopyBufferToTextureCmd>(); 236 break; 237 238 case Command::CopyTextureToBuffer: 239 commands->NextCommand<CopyTextureToBufferCmd>(); 240 break; 241 242 case Command::CopyTextureToTexture: 243 commands->NextCommand<CopyTextureToTextureCmd>(); 244 break; 245 246 case Command::Dispatch: 247 commands->NextCommand<DispatchCmd>(); 248 break; 249 250 case Command::DispatchIndirect: 251 commands->NextCommand<DispatchIndirectCmd>(); 252 break; 253 254 case Command::Draw: 255 commands->NextCommand<DrawCmd>(); 256 break; 257 258 case Command::DrawIndexed: 259 commands->NextCommand<DrawIndexedCmd>(); 260 break; 261 262 case Command::DrawIndirect: 263 commands->NextCommand<DrawIndirectCmd>(); 264 break; 265 266 case Command::DrawIndexedIndirect: 267 commands->NextCommand<DrawIndexedIndirectCmd>(); 268 break; 269 270 case Command::EndComputePass: 271 commands->NextCommand<EndComputePassCmd>(); 272 break; 273 274 case Command::EndOcclusionQuery: 275 commands->NextCommand<EndOcclusionQueryCmd>(); 276 break; 277 278 case Command::EndRenderPass: 279 commands->NextCommand<EndRenderPassCmd>(); 280 break; 281 282 case Command::ExecuteBundles: { 283 auto* cmd = commands->NextCommand<ExecuteBundlesCmd>(); 284 commands->NextData<Ref<RenderBundleBase>>(cmd->count); 285 break; 286 } 287 288 case Command::ClearBuffer: 289 commands->NextCommand<ClearBufferCmd>(); 290 break; 291 292 case Command::InsertDebugMarker: { 293 InsertDebugMarkerCmd* cmd = commands->NextCommand<InsertDebugMarkerCmd>(); 294 commands->NextData<char>(cmd->length + 1); 295 break; 296 } 297 298 case Command::PopDebugGroup: 299 commands->NextCommand<PopDebugGroupCmd>(); 300 break; 301 302 case Command::PushDebugGroup: { 303 PushDebugGroupCmd* cmd = commands->NextCommand<PushDebugGroupCmd>(); 304 commands->NextData<char>(cmd->length + 1); 305 break; 306 } 307 308 case Command::ResolveQuerySet: { 309 commands->NextCommand<ResolveQuerySetCmd>(); 310 break; 311 } 312 313 case Command::SetComputePipeline: 314 commands->NextCommand<SetComputePipelineCmd>(); 315 break; 316 317 case Command::SetRenderPipeline: 318 commands->NextCommand<SetRenderPipelineCmd>(); 319 break; 320 321 case Command::SetStencilReference: 322 commands->NextCommand<SetStencilReferenceCmd>(); 323 break; 324 325 case Command::SetViewport: 326 commands->NextCommand<SetViewportCmd>(); 327 break; 328 329 case Command::SetScissorRect: 330 commands->NextCommand<SetScissorRectCmd>(); 331 break; 332 333 case Command::SetBlendConstant: 334 commands->NextCommand<SetBlendConstantCmd>(); 335 break; 336 337 case Command::SetBindGroup: { 338 SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>(); 339 if (cmd->dynamicOffsetCount > 0) { 340 commands->NextData<uint32_t>(cmd->dynamicOffsetCount); 341 } 342 break; 343 } 344 345 case Command::SetIndexBuffer: 346 commands->NextCommand<SetIndexBufferCmd>(); 347 break; 348 349 case Command::SetVertexBuffer: { 350 commands->NextCommand<SetVertexBufferCmd>(); 351 break; 352 } 353 354 case Command::WriteBuffer: 355 commands->NextCommand<WriteBufferCmd>(); 356 break; 357 358 case Command::WriteTimestamp: { 359 commands->NextCommand<WriteTimestampCmd>(); 360 break; 361 } 362 } 363 } 364 365 } // namespace dawn_native 366