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 <yunchao.he@intel.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/dawn.json b/dawn.json
index d4fec2f..d0c7e26 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 2a981ed..3ef4d02 100644
--- a/examples/CHelloTriangle.cpp
+++ b/examples/CHelloTriangle.cpp
@@ -95,13 +95,13 @@
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 7418456..0ec656c 100644
--- a/examples/glTFViewer/glTFViewer.cpp
+++ b/examples/glTFViewer/glTFViewer.cpp
@@ -238,6 +238,7 @@
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 @@
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 51a22b4..9c2cf4e 100644
--- a/src/dawn_native/RenderPipeline.cpp
+++ b/src/dawn_native/RenderPipeline.cpp
@@ -76,6 +76,8 @@
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 @@
return DAWN_VALIDATION_ERROR("Input state must not be null");
}
- DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
std::bitset<kMaxVertexInputs> inputsSetMask;
std::bitset<kMaxVertexAttributes> attributesSetMask;
DAWN_TRY(ValidateInputStateDescriptor(descriptor->inputState, &inputsSetMask,
@@ -338,7 +339,6 @@
: 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 @@
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 dcc1e1c..3d8fbea 100644
--- a/src/dawn_native/RenderPipeline.h
+++ b/src/dawn_native/RenderPipeline.h
@@ -52,7 +52,6 @@
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
- dawn::IndexFormat GetIndexFormat() const;
dawn::PrimitiveTopology GetPrimitiveTopology() const;
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
@@ -70,7 +69,6 @@
private:
RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
- dawn::IndexFormat mIndexFormat;
InputStateDescriptor mInputState;
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
std::array<VertexAttributeDescriptor, kMaxVertexAttributes> mAttributeInfos;
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index a9c45c8..9509049 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -815,7 +815,8 @@
// 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 5c9058f..8047383 100644
--- a/src/dawn_native/metal/CommandBufferMTL.mm
+++ b/src/dawn_native/metal/CommandBufferMTL.mm
@@ -624,7 +624,8 @@
case Command::DrawIndexed: {
DrawIndexedCmd* draw = mCommands.NextCommand<DrawIndexedCmd>();
- 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 65e9a10..9b66bfb 100644
--- a/src/dawn_native/metal/RenderPipelineMTL.mm
+++ b/src/dawn_native/metal/RenderPipelineMTL.mm
@@ -282,7 +282,7 @@
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 b6c5ea3..3a5080f 100644
--- a/src/dawn_native/opengl/CommandBufferGL.cpp
+++ b/src/dawn_native/opengl/CommandBufferGL.cpp
@@ -741,7 +741,8 @@
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 283637e..71314b8 100644
--- a/src/dawn_native/vulkan/CommandBufferVk.cpp
+++ b/src/dawn_native/vulkan/CommandBufferVk.cpp
@@ -559,7 +559,8 @@
// 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<VkDeviceSize>(cmd->offset), indexType);
} break;
diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp
index 2c60de0..0904820 100644
--- a/src/tests/end2end/DestroyTests.cpp
+++ b/src/tests/end2end/DestroyTests.cpp
@@ -46,7 +46,6 @@
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 86e3c04..c46d8761 100644
--- a/src/tests/end2end/DrawIndexedTests.cpp
+++ b/src/tests/end2end/DrawIndexedTests.cpp
@@ -46,7 +46,6 @@
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 3629719..0964267 100644
--- a/src/tests/end2end/DrawTests.cpp
+++ b/src/tests/end2end/DrawTests.cpp
@@ -46,7 +46,6 @@
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 988bb4f..084f74f 100644
--- a/src/tests/end2end/IndexFormatTests.cpp
+++ b/src/tests/end2end/IndexFormatTests.cpp
@@ -52,7 +52,7 @@
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 6ceb8ae..e38b929 100644
--- a/src/tests/end2end/RenderPassTests.cpp
+++ b/src/tests/end2end/RenderPassTests.cpp
@@ -47,7 +47,6 @@
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 e13b7b0..8ed66c8 100644
--- a/src/tests/unittests/wire/WireArgumentTests.cpp
+++ b/src/tests/unittests/wire/WireArgumentTests.cpp
@@ -99,6 +99,7 @@
// 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 @@
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 1c4c7b3..59b5206 100644
--- a/src/tests/unittests/wire/WireOptionalTests.cpp
+++ b/src/tests/unittests/wire/WireOptionalTests.cpp
@@ -87,6 +87,7 @@
// 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 @@
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 982def8..794760d 100644
--- a/src/utils/ComboRenderPipelineDescriptor.cpp
+++ b/src/utils/ComboRenderPipelineDescriptor.cpp
@@ -21,6 +21,8 @@
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 @@
ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor(const dawn::Device& device) {
dawn::RenderPipelineDescriptor* descriptor = this;
- descriptor->indexFormat = dawn::IndexFormat::Uint32;
descriptor->primitiveTopology = dawn::PrimitiveTopology::TriangleList;
descriptor->sampleCount = 1;