From f856903154b8b09e1bf3a25a30d7749c7fc62924 Mon Sep 17 00:00:00 2001 From: Yunchao He Date: Thu, 28 Mar 2019 17:09:23 +0000 Subject: [PATCH] Move vertex index format from RenderPipelineDesc to InputStateDesc Bug=dawn:107 Change-Id: Ia88232848995d5c4c3ac0f3137ffa518e85aa0a0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6140 Commit-Queue: Yunchao He Commit-Queue: Kai Ninomiya Reviewed-by: Kai Ninomiya --- dawn.json | 2 +- examples/CHelloTriangle.cpp | 2 +- examples/glTFViewer/glTFViewer.cpp | 2 +- src/dawn_native/RenderPipeline.cpp | 9 ++------- src/dawn_native/RenderPipeline.h | 2 -- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 3 ++- src/dawn_native/metal/CommandBufferMTL.mm | 3 ++- src/dawn_native/metal/RenderPipelineMTL.mm | 2 +- src/dawn_native/opengl/CommandBufferGL.cpp | 3 ++- src/dawn_native/vulkan/CommandBufferVk.cpp | 3 ++- src/tests/end2end/DestroyTests.cpp | 1 - src/tests/end2end/DrawIndexedTests.cpp | 1 - src/tests/end2end/DrawTests.cpp | 1 - src/tests/end2end/IndexFormatTests.cpp | 2 +- src/tests/end2end/RenderPassTests.cpp | 1 - src/tests/unittests/wire/WireArgumentTests.cpp | 2 +- src/tests/unittests/wire/WireOptionalTests.cpp | 2 +- src/utils/ComboRenderPipelineDescriptor.cpp | 3 ++- 18 files changed, 19 insertions(+), 25 deletions(-) diff --git a/dawn.json b/dawn.json index d4fec2f729..d0c7e2616b 100644 --- a/dawn.json +++ b/dawn.json @@ -622,6 +622,7 @@ "category": "structure", "extensible": true, "members": [ + {"name": "index format", "type": "index format"}, {"name": "num attributes", "type": "uint32_t"}, {"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "num attributes"}, {"name": "num inputs", "type": "uint32_t"}, @@ -864,7 +865,6 @@ {"name": "vertex stage", "type": "pipeline stage descriptor", "annotation": "const*"}, {"name": "fragment stage", "type": "pipeline stage descriptor", "annotation": "const*"}, {"name": "input state", "type": "input state descriptor", "annotation": "const*"}, - {"name": "index format", "type": "index format"}, {"name": "primitive topology", "type": "primitive topology"}, {"name": "sample count", "type": "uint32_t"}, {"name": "depth stencil state", "type": "depth stencil state descriptor", "annotation": "const*", "optional": true}, diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp index 2a981ed45f..3ef4d0296a 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -95,13 +95,13 @@ void init() { DawnInputStateDescriptor inputState; inputState.nextInChain = nullptr; + inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32; inputState.numInputs = 0; inputState.inputs = nullptr; inputState.numAttributes = 0; inputState.attributes = nullptr; descriptor.inputState = &inputState; - descriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32; descriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; descriptor.depthStencilState = nullptr; diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index 7418456592..0ec656cae9 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -238,6 +238,7 @@ namespace { auto oFSModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, hasTexture ? oFSSourceTextured : oFSSourceUntextured); utils::ComboRenderPipelineDescriptor descriptor(device); + descriptor.cInputState.indexFormat = dawn::IndexFormat::Uint16; uint32_t numAttributes = 0; uint32_t numInputs = 0; std::bitset<3> slotsSet; @@ -306,7 +307,6 @@ namespace { descriptor.layout = pipelineLayout; descriptor.cVertexStage.module = oVSModule; descriptor.cFragmentStage.module = oFSModule; - descriptor.indexFormat = dawn::IndexFormat::Uint16; descriptor.depthStencilState = &descriptor.cDepthStencilState; descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint; descriptor.cColorStates[0]->format = GetPreferredSwapChainTextureFormat(); diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 51a22b4ba2..9c2cf4e9e6 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -76,6 +76,8 @@ namespace dawn_native { if (descriptor->nextInChain != nullptr) { return DAWN_VALIDATION_ERROR("nextInChain must be nullptr"); } + DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat)); + if (descriptor->numInputs > kMaxVertexInputs) { return DAWN_VALIDATION_ERROR("Vertex Inputs number exceeds maximum"); } @@ -271,7 +273,6 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Input state must not be null"); } - DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat)); std::bitset inputsSetMask; std::bitset attributesSetMask; DAWN_TRY(ValidateInputStateDescriptor(descriptor->inputState, &inputsSetMask, @@ -338,7 +339,6 @@ namespace dawn_native { : PipelineBase(device, descriptor->layout, dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment), - mIndexFormat(descriptor->indexFormat), mInputState(*descriptor->inputState), mPrimitiveTopology(descriptor->primitiveTopology), mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr), @@ -436,11 +436,6 @@ namespace dawn_native { return &mDepthStencilState; } - dawn::IndexFormat RenderPipelineBase::GetIndexFormat() const { - ASSERT(!IsError()); - return mIndexFormat; - } - dawn::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const { ASSERT(!IsError()); return mPrimitiveTopology; diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index dcc1e1c669..3d8fbeae5b 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -52,7 +52,6 @@ namespace dawn_native { const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot); const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor(); - dawn::IndexFormat GetIndexFormat() const; dawn::PrimitiveTopology GetPrimitiveTopology() const; std::bitset GetColorAttachmentsMask() const; @@ -70,7 +69,6 @@ namespace dawn_native { private: RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); - dawn::IndexFormat mIndexFormat; InputStateDescriptor mInputState; std::bitset mAttributesSetMask; std::array mAttributeInfos; diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index a9c45c8436..95090493de 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -815,7 +815,8 @@ namespace dawn_native { namespace d3d12 { // TODO(cwallez@chromium.org): Make index buffers lazily applied, right now // this will break if the pipeline is changed for one with a different index // format after SetIndexBuffer - bufferView.Format = DXGIIndexFormat(lastPipeline->GetIndexFormat()); + bufferView.Format = + DXGIIndexFormat(lastPipeline->GetInputStateDescriptor()->indexFormat); commandList->IASetIndexBuffer(&bufferView); } break; diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 5c9058f9ea..80473834a1 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -624,7 +624,8 @@ namespace dawn_native { namespace metal { case Command::DrawIndexed: { DrawIndexedCmd* draw = mCommands.NextCommand(); - size_t formatSize = IndexFormatSize(lastPipeline->GetIndexFormat()); + size_t formatSize = + IndexFormatSize(lastPipeline->GetInputStateDescriptor()->indexFormat); // The index and instance count must be non-zero, otherwise no-op if (draw->indexCount != 0 && draw->instanceCount != 0) { diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index 65e9a1090a..9b66bfb85a 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -282,7 +282,7 @@ namespace dawn_native { namespace metal { RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor) : RenderPipelineBase(device, descriptor), - mMtlIndexType(MTLIndexFormat(GetIndexFormat())), + mMtlIndexType(MTLIndexFormat(GetInputStateDescriptor()->indexFormat)), mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) { auto mtlDevice = device->GetMTLDevice(); diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index b6c5ea3d62..3a5080f987 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -741,7 +741,8 @@ namespace dawn_native { namespace opengl { pushConstants.Apply(lastPipeline, lastPipeline); inputBuffers.Apply(); - dawn::IndexFormat indexFormat = lastPipeline->GetIndexFormat(); + dawn::IndexFormat indexFormat = + lastPipeline->GetInputStateDescriptor()->indexFormat; size_t formatSize = IndexFormatSize(indexFormat); GLenum formatType = IndexFormatType(indexFormat); diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index 283637ec26..71314b8250 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -559,7 +559,8 @@ namespace dawn_native { namespace vulkan { // TODO(cwallez@chromium.org): get the index type from the last render pipeline // and rebind if needed on pipeline change ASSERT(lastPipeline != nullptr); - VkIndexType indexType = VulkanIndexType(lastPipeline->GetIndexFormat()); + VkIndexType indexType = + VulkanIndexType(lastPipeline->GetInputStateDescriptor()->indexFormat); device->fn.CmdBindIndexBuffer( commands, indexBuffer, static_cast(cmd->offset), indexType); } break; diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp index 2c60de0541..09048202c6 100644 --- a/src/tests/end2end/DestroyTests.cpp +++ b/src/tests/end2end/DestroyTests.cpp @@ -46,7 +46,6 @@ class DestroyTest : public DawnTest { descriptor.cVertexStage.module = vsModule; descriptor.cFragmentStage.module = fsModule; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; - descriptor.indexFormat = dawn::IndexFormat::Uint32; descriptor.cInputState.numInputs = 1; descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.numAttributes = 1; diff --git a/src/tests/end2end/DrawIndexedTests.cpp b/src/tests/end2end/DrawIndexedTests.cpp index 86e3c048ba..c46d8761dc 100644 --- a/src/tests/end2end/DrawIndexedTests.cpp +++ b/src/tests/end2end/DrawIndexedTests.cpp @@ -46,7 +46,6 @@ class DrawIndexedTest : public DawnTest { descriptor.cVertexStage.module = vsModule; descriptor.cFragmentStage.module = fsModule; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; - descriptor.indexFormat = dawn::IndexFormat::Uint32; descriptor.cInputState.numInputs = 1; descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.numAttributes = 1; diff --git a/src/tests/end2end/DrawTests.cpp b/src/tests/end2end/DrawTests.cpp index 3629719878..0964267af0 100644 --- a/src/tests/end2end/DrawTests.cpp +++ b/src/tests/end2end/DrawTests.cpp @@ -46,7 +46,6 @@ class DrawTest : public DawnTest { descriptor.cVertexStage.module = vsModule; descriptor.cFragmentStage.module = fsModule; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; - descriptor.indexFormat = dawn::IndexFormat::Uint32; descriptor.cInputState.numInputs = 1; descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.numAttributes = 1; diff --git a/src/tests/end2end/IndexFormatTests.cpp b/src/tests/end2end/IndexFormatTests.cpp index 988bb4f6cc..084f74f157 100644 --- a/src/tests/end2end/IndexFormatTests.cpp +++ b/src/tests/end2end/IndexFormatTests.cpp @@ -52,7 +52,7 @@ class IndexFormatTest : public DawnTest { descriptor.cVertexStage.module = vsModule; descriptor.cFragmentStage.module = fsModule; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; - descriptor.indexFormat = format; + descriptor.cInputState.indexFormat = format; descriptor.cInputState.numInputs = 1; descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.numAttributes = 1; diff --git a/src/tests/end2end/RenderPassTests.cpp b/src/tests/end2end/RenderPassTests.cpp index 6ceb8aee94..e38b929c91 100644 --- a/src/tests/end2end/RenderPassTests.cpp +++ b/src/tests/end2end/RenderPassTests.cpp @@ -47,7 +47,6 @@ protected: descriptor.cVertexStage.module = vsModule; descriptor.cFragmentStage.module = fsModule; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; - descriptor.indexFormat = dawn::IndexFormat::Uint32; descriptor.cColorStates[0]->format = kFormat; pipeline = device.CreateRenderPipeline(&descriptor); diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp index e13b7b0d31..8ed66c8e28 100644 --- a/src/tests/unittests/wire/WireArgumentTests.cpp +++ b/src/tests/unittests/wire/WireArgumentTests.cpp @@ -99,6 +99,7 @@ TEST_F(WireArgumentTests, CStringArgument) { // Create the input state DawnInputStateDescriptor inputState; inputState.nextInChain = nullptr; + inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32; inputState.numInputs = 0; inputState.inputs = nullptr; inputState.numAttributes = 0; @@ -153,7 +154,6 @@ TEST_F(WireArgumentTests, CStringArgument) { pipelineDescriptor.sampleCount = 1; pipelineDescriptor.layout = layout; pipelineDescriptor.inputState = &inputState; - pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32; pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; pipelineDescriptor.depthStencilState = &depthStencilState; diff --git a/src/tests/unittests/wire/WireOptionalTests.cpp b/src/tests/unittests/wire/WireOptionalTests.cpp index 1c4c7b3c67..59b5206dbf 100644 --- a/src/tests/unittests/wire/WireOptionalTests.cpp +++ b/src/tests/unittests/wire/WireOptionalTests.cpp @@ -87,6 +87,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) { // Create the input state DawnInputStateDescriptor inputState; inputState.nextInChain = nullptr; + inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32; inputState.numInputs = 0; inputState.inputs = nullptr; inputState.numAttributes = 0; @@ -141,7 +142,6 @@ TEST_F(WireOptionalTests, OptionalStructPointer) { pipelineDescriptor.sampleCount = 1; pipelineDescriptor.layout = layout; pipelineDescriptor.inputState = &inputState; - pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32; pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // First case: depthStencilState is not null. diff --git a/src/utils/ComboRenderPipelineDescriptor.cpp b/src/utils/ComboRenderPipelineDescriptor.cpp index 982def8aac..794760d31f 100644 --- a/src/utils/ComboRenderPipelineDescriptor.cpp +++ b/src/utils/ComboRenderPipelineDescriptor.cpp @@ -21,6 +21,8 @@ namespace utils { ComboInputStateDescriptor::ComboInputStateDescriptor() { dawn::InputStateDescriptor* descriptor = this; + descriptor->indexFormat = dawn::IndexFormat::Uint32; + // Fill the default values for vertexInput. descriptor->numInputs = 0; dawn::VertexInputDescriptor vertexInput; @@ -48,7 +50,6 @@ namespace utils { ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor(const dawn::Device& device) { dawn::RenderPipelineDescriptor* descriptor = this; - descriptor->indexFormat = dawn::IndexFormat::Uint32; descriptor->primitiveTopology = dawn::PrimitiveTopology::TriangleList; descriptor->sampleCount = 1;