// Copyright 2018 The Dawn Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "dawn/native/Commands.h" #include "dawn/native/BindGroup.h" #include "dawn/native/Buffer.h" #include "dawn/native/CommandAllocator.h" #include "dawn/native/ComputePipeline.h" #include "dawn/native/QuerySet.h" #include "dawn/native/RenderBundle.h" #include "dawn/native/RenderPipeline.h" #include "dawn/native/Texture.h" namespace dawn::native { void FreeCommands(CommandIterator* commands) { commands->Reset(); Command type; while (commands->NextCommandId(&type)) { switch (type) { case Command::BeginComputePass: { BeginComputePassCmd* begin = commands->NextCommand(); begin->~BeginComputePassCmd(); break; } case Command::BeginOcclusionQuery: { BeginOcclusionQueryCmd* begin = commands->NextCommand(); begin->~BeginOcclusionQueryCmd(); break; } case Command::BeginRenderPass: { BeginRenderPassCmd* begin = commands->NextCommand(); begin->~BeginRenderPassCmd(); break; } case Command::CopyBufferToBuffer: { CopyBufferToBufferCmd* copy = commands->NextCommand(); copy->~CopyBufferToBufferCmd(); break; } case Command::CopyBufferToTexture: { CopyBufferToTextureCmd* copy = commands->NextCommand(); copy->~CopyBufferToTextureCmd(); break; } case Command::CopyTextureToBuffer: { CopyTextureToBufferCmd* copy = commands->NextCommand(); copy->~CopyTextureToBufferCmd(); break; } case Command::CopyTextureToTexture: { CopyTextureToTextureCmd* copy = commands->NextCommand(); copy->~CopyTextureToTextureCmd(); break; } case Command::Dispatch: { DispatchCmd* dispatch = commands->NextCommand(); dispatch->~DispatchCmd(); break; } case Command::DispatchIndirect: { DispatchIndirectCmd* dispatch = commands->NextCommand(); dispatch->~DispatchIndirectCmd(); break; } case Command::Draw: { DrawCmd* draw = commands->NextCommand(); draw->~DrawCmd(); break; } case Command::DrawIndexed: { DrawIndexedCmd* draw = commands->NextCommand(); draw->~DrawIndexedCmd(); break; } case Command::DrawIndirect: { DrawIndirectCmd* draw = commands->NextCommand(); draw->~DrawIndirectCmd(); break; } case Command::DrawIndexedIndirect: { DrawIndexedIndirectCmd* draw = commands->NextCommand(); draw->~DrawIndexedIndirectCmd(); break; } case Command::EndComputePass: { EndComputePassCmd* cmd = commands->NextCommand(); cmd->~EndComputePassCmd(); break; } case Command::EndOcclusionQuery: { EndOcclusionQueryCmd* cmd = commands->NextCommand(); cmd->~EndOcclusionQueryCmd(); break; } case Command::EndRenderPass: { EndRenderPassCmd* cmd = commands->NextCommand(); cmd->~EndRenderPassCmd(); break; } case Command::ExecuteBundles: { ExecuteBundlesCmd* cmd = commands->NextCommand(); auto bundles = commands->NextData>(cmd->count); for (size_t i = 0; i < cmd->count; ++i) { (&bundles[i])->~Ref(); } cmd->~ExecuteBundlesCmd(); break; } case Command::ClearBuffer: { ClearBufferCmd* cmd = commands->NextCommand(); cmd->~ClearBufferCmd(); break; } case Command::InsertDebugMarker: { InsertDebugMarkerCmd* cmd = commands->NextCommand(); commands->NextData(cmd->length + 1); cmd->~InsertDebugMarkerCmd(); break; } case Command::PopDebugGroup: { PopDebugGroupCmd* cmd = commands->NextCommand(); cmd->~PopDebugGroupCmd(); break; } case Command::PushDebugGroup: { PushDebugGroupCmd* cmd = commands->NextCommand(); commands->NextData(cmd->length + 1); cmd->~PushDebugGroupCmd(); break; } case Command::ResolveQuerySet: { ResolveQuerySetCmd* cmd = commands->NextCommand(); cmd->~ResolveQuerySetCmd(); break; } case Command::SetComputePipeline: { SetComputePipelineCmd* cmd = commands->NextCommand(); cmd->~SetComputePipelineCmd(); break; } case Command::SetRenderPipeline: { SetRenderPipelineCmd* cmd = commands->NextCommand(); cmd->~SetRenderPipelineCmd(); break; } case Command::SetStencilReference: { SetStencilReferenceCmd* cmd = commands->NextCommand(); cmd->~SetStencilReferenceCmd(); break; } case Command::SetViewport: { SetViewportCmd* cmd = commands->NextCommand(); cmd->~SetViewportCmd(); break; } case Command::SetScissorRect: { SetScissorRectCmd* cmd = commands->NextCommand(); cmd->~SetScissorRectCmd(); break; } case Command::SetBlendConstant: { SetBlendConstantCmd* cmd = commands->NextCommand(); cmd->~SetBlendConstantCmd(); break; } case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands->NextCommand(); if (cmd->dynamicOffsetCount > 0) { commands->NextData(cmd->dynamicOffsetCount); } cmd->~SetBindGroupCmd(); break; } case Command::SetIndexBuffer: { SetIndexBufferCmd* cmd = commands->NextCommand(); cmd->~SetIndexBufferCmd(); break; } case Command::SetVertexBuffer: { SetVertexBufferCmd* cmd = commands->NextCommand(); cmd->~SetVertexBufferCmd(); break; } case Command::WriteBuffer: { WriteBufferCmd* write = commands->NextCommand(); commands->NextData(write->size); write->~WriteBufferCmd(); break; } case Command::WriteTimestamp: { WriteTimestampCmd* cmd = commands->NextCommand(); cmd->~WriteTimestampCmd(); break; } } } commands->MakeEmptyAsDataWasDestroyed(); } void SkipCommand(CommandIterator* commands, Command type) { switch (type) { case Command::BeginComputePass: commands->NextCommand(); break; case Command::BeginOcclusionQuery: commands->NextCommand(); break; case Command::BeginRenderPass: commands->NextCommand(); break; case Command::CopyBufferToBuffer: commands->NextCommand(); break; case Command::CopyBufferToTexture: commands->NextCommand(); break; case Command::CopyTextureToBuffer: commands->NextCommand(); break; case Command::CopyTextureToTexture: commands->NextCommand(); break; case Command::Dispatch: commands->NextCommand(); break; case Command::DispatchIndirect: commands->NextCommand(); break; case Command::Draw: commands->NextCommand(); break; case Command::DrawIndexed: commands->NextCommand(); break; case Command::DrawIndirect: commands->NextCommand(); break; case Command::DrawIndexedIndirect: commands->NextCommand(); break; case Command::EndComputePass: commands->NextCommand(); break; case Command::EndOcclusionQuery: commands->NextCommand(); break; case Command::EndRenderPass: commands->NextCommand(); break; case Command::ExecuteBundles: { auto* cmd = commands->NextCommand(); commands->NextData>(cmd->count); break; } case Command::ClearBuffer: commands->NextCommand(); break; case Command::InsertDebugMarker: { InsertDebugMarkerCmd* cmd = commands->NextCommand(); commands->NextData(cmd->length + 1); break; } case Command::PopDebugGroup: commands->NextCommand(); break; case Command::PushDebugGroup: { PushDebugGroupCmd* cmd = commands->NextCommand(); commands->NextData(cmd->length + 1); break; } case Command::ResolveQuerySet: { commands->NextCommand(); break; } case Command::SetComputePipeline: commands->NextCommand(); break; case Command::SetRenderPipeline: commands->NextCommand(); break; case Command::SetStencilReference: commands->NextCommand(); break; case Command::SetViewport: commands->NextCommand(); break; case Command::SetScissorRect: commands->NextCommand(); break; case Command::SetBlendConstant: commands->NextCommand(); break; case Command::SetBindGroup: { SetBindGroupCmd* cmd = commands->NextCommand(); if (cmd->dynamicOffsetCount > 0) { commands->NextData(cmd->dynamicOffsetCount); } break; } case Command::SetIndexBuffer: commands->NextCommand(); break; case Command::SetVertexBuffer: { commands->NextCommand(); break; } case Command::WriteBuffer: commands->NextCommand(); break; case Command::WriteTimestamp: { commands->NextCommand(); break; } } } TimestampWrite::TimestampWrite() = default; TimestampWrite::~TimestampWrite() = default; BeginComputePassCmd::BeginComputePassCmd() = default; BeginComputePassCmd::~BeginComputePassCmd() = default; BeginOcclusionQueryCmd::BeginOcclusionQueryCmd() = default; BeginOcclusionQueryCmd::~BeginOcclusionQueryCmd() = default; RenderPassColorAttachmentInfo::RenderPassColorAttachmentInfo() = default; RenderPassColorAttachmentInfo::~RenderPassColorAttachmentInfo() = default; RenderPassDepthStencilAttachmentInfo::RenderPassDepthStencilAttachmentInfo() = default; RenderPassDepthStencilAttachmentInfo::~RenderPassDepthStencilAttachmentInfo() = default; BeginRenderPassCmd::BeginRenderPassCmd() = default; BeginRenderPassCmd::~BeginRenderPassCmd() = default; BufferCopy::BufferCopy() = default; BufferCopy::~BufferCopy() = default; TextureCopy::TextureCopy() = default; TextureCopy::TextureCopy(const TextureCopy&) = default; TextureCopy::~TextureCopy() = default; CopyBufferToBufferCmd::CopyBufferToBufferCmd() = default; CopyBufferToBufferCmd::~CopyBufferToBufferCmd() = default; DispatchIndirectCmd::DispatchIndirectCmd() = default; DispatchIndirectCmd::~DispatchIndirectCmd() = default; DrawIndirectCmd::DrawIndirectCmd() = default; DrawIndirectCmd::~DrawIndirectCmd() = default; EndComputePassCmd::EndComputePassCmd() = default; EndComputePassCmd::~EndComputePassCmd() = default; EndOcclusionQueryCmd::EndOcclusionQueryCmd() = default; EndOcclusionQueryCmd::~EndOcclusionQueryCmd() = default; EndRenderPassCmd::EndRenderPassCmd() = default; EndRenderPassCmd::~EndRenderPassCmd() = default; ClearBufferCmd::ClearBufferCmd() = default; ClearBufferCmd::~ClearBufferCmd() = default; ResolveQuerySetCmd::ResolveQuerySetCmd() = default; ResolveQuerySetCmd::~ResolveQuerySetCmd() = default; SetComputePipelineCmd::SetComputePipelineCmd() = default; SetComputePipelineCmd::~SetComputePipelineCmd() = default; SetRenderPipelineCmd::SetRenderPipelineCmd() = default; SetRenderPipelineCmd::~SetRenderPipelineCmd() = default; SetBindGroupCmd::SetBindGroupCmd() = default; SetBindGroupCmd::~SetBindGroupCmd() = default; SetIndexBufferCmd::SetIndexBufferCmd() = default; SetIndexBufferCmd::~SetIndexBufferCmd() = default; SetVertexBufferCmd::SetVertexBufferCmd() = default; SetVertexBufferCmd::~SetVertexBufferCmd() = default; WriteBufferCmd::WriteBufferCmd() = default; WriteBufferCmd::~WriteBufferCmd() = default; WriteTimestampCmd::WriteTimestampCmd() = default; WriteTimestampCmd::~WriteTimestampCmd() = default; } // namespace dawn::native