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>
This commit is contained in:
Yunchao He 2019-03-28 17:09:23 +00:00 committed by Commit Bot service account
parent 27a294c2e8
commit f856903154
18 changed files with 19 additions and 25 deletions

View File

@ -622,6 +622,7 @@
"category": "structure", "category": "structure",
"extensible": true, "extensible": true,
"members": [ "members": [
{"name": "index format", "type": "index format"},
{"name": "num attributes", "type": "uint32_t"}, {"name": "num attributes", "type": "uint32_t"},
{"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "num attributes"}, {"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "num attributes"},
{"name": "num inputs", "type": "uint32_t"}, {"name": "num inputs", "type": "uint32_t"},
@ -864,7 +865,6 @@
{"name": "vertex stage", "type": "pipeline stage descriptor", "annotation": "const*"}, {"name": "vertex stage", "type": "pipeline stage descriptor", "annotation": "const*"},
{"name": "fragment 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": "input state", "type": "input state descriptor", "annotation": "const*"},
{"name": "index format", "type": "index format"},
{"name": "primitive topology", "type": "primitive topology"}, {"name": "primitive topology", "type": "primitive topology"},
{"name": "sample count", "type": "uint32_t"}, {"name": "sample count", "type": "uint32_t"},
{"name": "depth stencil state", "type": "depth stencil state descriptor", "annotation": "const*", "optional": true}, {"name": "depth stencil state", "type": "depth stencil state descriptor", "annotation": "const*", "optional": true},

View File

@ -95,13 +95,13 @@ void init() {
DawnInputStateDescriptor inputState; DawnInputStateDescriptor inputState;
inputState.nextInChain = nullptr; inputState.nextInChain = nullptr;
inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32;
inputState.numInputs = 0; inputState.numInputs = 0;
inputState.inputs = nullptr; inputState.inputs = nullptr;
inputState.numAttributes = 0; inputState.numAttributes = 0;
inputState.attributes = nullptr; inputState.attributes = nullptr;
descriptor.inputState = &inputState; descriptor.inputState = &inputState;
descriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
descriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; descriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
descriptor.depthStencilState = nullptr; descriptor.depthStencilState = nullptr;

View File

@ -238,6 +238,7 @@ namespace {
auto oFSModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, hasTexture ? oFSSourceTextured : oFSSourceUntextured); auto oFSModule = utils::CreateShaderModule(device, dawn::ShaderStage::Fragment, hasTexture ? oFSSourceTextured : oFSSourceUntextured);
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.cInputState.indexFormat = dawn::IndexFormat::Uint16;
uint32_t numAttributes = 0; uint32_t numAttributes = 0;
uint32_t numInputs = 0; uint32_t numInputs = 0;
std::bitset<3> slotsSet; std::bitset<3> slotsSet;
@ -306,7 +307,6 @@ namespace {
descriptor.layout = pipelineLayout; descriptor.layout = pipelineLayout;
descriptor.cVertexStage.module = oVSModule; descriptor.cVertexStage.module = oVSModule;
descriptor.cFragmentStage.module = oFSModule; descriptor.cFragmentStage.module = oFSModule;
descriptor.indexFormat = dawn::IndexFormat::Uint16;
descriptor.depthStencilState = &descriptor.cDepthStencilState; descriptor.depthStencilState = &descriptor.cDepthStencilState;
descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint; descriptor.cDepthStencilState.format = dawn::TextureFormat::D32FloatS8Uint;
descriptor.cColorStates[0]->format = GetPreferredSwapChainTextureFormat(); descriptor.cColorStates[0]->format = GetPreferredSwapChainTextureFormat();

View File

@ -76,6 +76,8 @@ namespace dawn_native {
if (descriptor->nextInChain != nullptr) { if (descriptor->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr"); return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
} }
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
if (descriptor->numInputs > kMaxVertexInputs) { if (descriptor->numInputs > kMaxVertexInputs) {
return DAWN_VALIDATION_ERROR("Vertex Inputs number exceeds maximum"); 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"); return DAWN_VALIDATION_ERROR("Input state must not be null");
} }
DAWN_TRY(ValidateIndexFormat(descriptor->indexFormat));
std::bitset<kMaxVertexInputs> inputsSetMask; std::bitset<kMaxVertexInputs> inputsSetMask;
std::bitset<kMaxVertexAttributes> attributesSetMask; std::bitset<kMaxVertexAttributes> attributesSetMask;
DAWN_TRY(ValidateInputStateDescriptor(descriptor->inputState, &inputsSetMask, DAWN_TRY(ValidateInputStateDescriptor(descriptor->inputState, &inputsSetMask,
@ -338,7 +339,6 @@ namespace dawn_native {
: PipelineBase(device, : PipelineBase(device,
descriptor->layout, descriptor->layout,
dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment), dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment),
mIndexFormat(descriptor->indexFormat),
mInputState(*descriptor->inputState), mInputState(*descriptor->inputState),
mPrimitiveTopology(descriptor->primitiveTopology), mPrimitiveTopology(descriptor->primitiveTopology),
mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr), mHasDepthStencilAttachment(descriptor->depthStencilState != nullptr),
@ -436,11 +436,6 @@ namespace dawn_native {
return &mDepthStencilState; return &mDepthStencilState;
} }
dawn::IndexFormat RenderPipelineBase::GetIndexFormat() const {
ASSERT(!IsError());
return mIndexFormat;
}
dawn::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const { dawn::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mPrimitiveTopology; return mPrimitiveTopology;

View File

@ -52,7 +52,6 @@ namespace dawn_native {
const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot); const ColorStateDescriptor* GetColorStateDescriptor(uint32_t attachmentSlot);
const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor(); const DepthStencilStateDescriptor* GetDepthStencilStateDescriptor();
dawn::IndexFormat GetIndexFormat() const;
dawn::PrimitiveTopology GetPrimitiveTopology() const; dawn::PrimitiveTopology GetPrimitiveTopology() const;
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const; std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
@ -70,7 +69,6 @@ namespace dawn_native {
private: private:
RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
dawn::IndexFormat mIndexFormat;
InputStateDescriptor mInputState; InputStateDescriptor mInputState;
std::bitset<kMaxVertexAttributes> mAttributesSetMask; std::bitset<kMaxVertexAttributes> mAttributesSetMask;
std::array<VertexAttributeDescriptor, kMaxVertexAttributes> mAttributeInfos; std::array<VertexAttributeDescriptor, kMaxVertexAttributes> mAttributeInfos;

View File

@ -815,7 +815,8 @@ namespace dawn_native { namespace d3d12 {
// TODO(cwallez@chromium.org): Make index buffers lazily applied, right now // 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 // this will break if the pipeline is changed for one with a different index
// format after SetIndexBuffer // format after SetIndexBuffer
bufferView.Format = DXGIIndexFormat(lastPipeline->GetIndexFormat()); bufferView.Format =
DXGIIndexFormat(lastPipeline->GetInputStateDescriptor()->indexFormat);
commandList->IASetIndexBuffer(&bufferView); commandList->IASetIndexBuffer(&bufferView);
} break; } break;

View File

@ -624,7 +624,8 @@ namespace dawn_native { namespace metal {
case Command::DrawIndexed: { case Command::DrawIndexed: {
DrawIndexedCmd* draw = mCommands.NextCommand<DrawIndexedCmd>(); 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 // The index and instance count must be non-zero, otherwise no-op
if (draw->indexCount != 0 && draw->instanceCount != 0) { if (draw->indexCount != 0 && draw->instanceCount != 0) {

View File

@ -282,7 +282,7 @@ namespace dawn_native { namespace metal {
RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor) RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor)
: RenderPipelineBase(device, descriptor), : RenderPipelineBase(device, descriptor),
mMtlIndexType(MTLIndexFormat(GetIndexFormat())), mMtlIndexType(MTLIndexFormat(GetInputStateDescriptor()->indexFormat)),
mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) { mMtlPrimitiveTopology(MTLPrimitiveTopology(GetPrimitiveTopology())) {
auto mtlDevice = device->GetMTLDevice(); auto mtlDevice = device->GetMTLDevice();

View File

@ -741,7 +741,8 @@ namespace dawn_native { namespace opengl {
pushConstants.Apply(lastPipeline, lastPipeline); pushConstants.Apply(lastPipeline, lastPipeline);
inputBuffers.Apply(); inputBuffers.Apply();
dawn::IndexFormat indexFormat = lastPipeline->GetIndexFormat(); dawn::IndexFormat indexFormat =
lastPipeline->GetInputStateDescriptor()->indexFormat;
size_t formatSize = IndexFormatSize(indexFormat); size_t formatSize = IndexFormatSize(indexFormat);
GLenum formatType = IndexFormatType(indexFormat); GLenum formatType = IndexFormatType(indexFormat);

View File

@ -559,7 +559,8 @@ namespace dawn_native { namespace vulkan {
// TODO(cwallez@chromium.org): get the index type from the last render pipeline // TODO(cwallez@chromium.org): get the index type from the last render pipeline
// and rebind if needed on pipeline change // and rebind if needed on pipeline change
ASSERT(lastPipeline != nullptr); ASSERT(lastPipeline != nullptr);
VkIndexType indexType = VulkanIndexType(lastPipeline->GetIndexFormat()); VkIndexType indexType =
VulkanIndexType(lastPipeline->GetInputStateDescriptor()->indexFormat);
device->fn.CmdBindIndexBuffer( device->fn.CmdBindIndexBuffer(
commands, indexBuffer, static_cast<VkDeviceSize>(cmd->offset), indexType); commands, indexBuffer, static_cast<VkDeviceSize>(cmd->offset), indexType);
} break; } break;

View File

@ -46,7 +46,6 @@ class DestroyTest : public DawnTest {
descriptor.cVertexStage.module = vsModule; descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.cInputState.numInputs = 1; descriptor.cInputState.numInputs = 1;
descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float);
descriptor.cInputState.numAttributes = 1; descriptor.cInputState.numAttributes = 1;

View File

@ -46,7 +46,6 @@ class DrawIndexedTest : public DawnTest {
descriptor.cVertexStage.module = vsModule; descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.cInputState.numInputs = 1; descriptor.cInputState.numInputs = 1;
descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float);
descriptor.cInputState.numAttributes = 1; descriptor.cInputState.numAttributes = 1;

View File

@ -46,7 +46,6 @@ class DrawTest : public DawnTest {
descriptor.cVertexStage.module = vsModule; descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.cInputState.numInputs = 1; descriptor.cInputState.numInputs = 1;
descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float);
descriptor.cInputState.numAttributes = 1; descriptor.cInputState.numAttributes = 1;

View File

@ -52,7 +52,7 @@ class IndexFormatTest : public DawnTest {
descriptor.cVertexStage.module = vsModule; descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = format; descriptor.cInputState.indexFormat = format;
descriptor.cInputState.numInputs = 1; descriptor.cInputState.numInputs = 1;
descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float); descriptor.cInputState.cInputs[0].stride = 4 * sizeof(float);
descriptor.cInputState.numAttributes = 1; descriptor.cInputState.numAttributes = 1;

View File

@ -47,7 +47,6 @@ protected:
descriptor.cVertexStage.module = vsModule; descriptor.cVertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip; descriptor.primitiveTopology = dawn::PrimitiveTopology::TriangleStrip;
descriptor.indexFormat = dawn::IndexFormat::Uint32;
descriptor.cColorStates[0]->format = kFormat; descriptor.cColorStates[0]->format = kFormat;
pipeline = device.CreateRenderPipeline(&descriptor); pipeline = device.CreateRenderPipeline(&descriptor);

View File

@ -99,6 +99,7 @@ TEST_F(WireArgumentTests, CStringArgument) {
// Create the input state // Create the input state
DawnInputStateDescriptor inputState; DawnInputStateDescriptor inputState;
inputState.nextInChain = nullptr; inputState.nextInChain = nullptr;
inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32;
inputState.numInputs = 0; inputState.numInputs = 0;
inputState.inputs = nullptr; inputState.inputs = nullptr;
inputState.numAttributes = 0; inputState.numAttributes = 0;
@ -153,7 +154,6 @@ TEST_F(WireArgumentTests, CStringArgument) {
pipelineDescriptor.sampleCount = 1; pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout; pipelineDescriptor.layout = layout;
pipelineDescriptor.inputState = &inputState; pipelineDescriptor.inputState = &inputState;
pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
pipelineDescriptor.depthStencilState = &depthStencilState; pipelineDescriptor.depthStencilState = &depthStencilState;

View File

@ -87,6 +87,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
// Create the input state // Create the input state
DawnInputStateDescriptor inputState; DawnInputStateDescriptor inputState;
inputState.nextInChain = nullptr; inputState.nextInChain = nullptr;
inputState.indexFormat = DAWN_INDEX_FORMAT_UINT32;
inputState.numInputs = 0; inputState.numInputs = 0;
inputState.inputs = nullptr; inputState.inputs = nullptr;
inputState.numAttributes = 0; inputState.numAttributes = 0;
@ -141,7 +142,6 @@ TEST_F(WireOptionalTests, OptionalStructPointer) {
pipelineDescriptor.sampleCount = 1; pipelineDescriptor.sampleCount = 1;
pipelineDescriptor.layout = layout; pipelineDescriptor.layout = layout;
pipelineDescriptor.inputState = &inputState; pipelineDescriptor.inputState = &inputState;
pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
// First case: depthStencilState is not null. // First case: depthStencilState is not null.

View File

@ -21,6 +21,8 @@ namespace utils {
ComboInputStateDescriptor::ComboInputStateDescriptor() { ComboInputStateDescriptor::ComboInputStateDescriptor() {
dawn::InputStateDescriptor* descriptor = this; dawn::InputStateDescriptor* descriptor = this;
descriptor->indexFormat = dawn::IndexFormat::Uint32;
// Fill the default values for vertexInput. // Fill the default values for vertexInput.
descriptor->numInputs = 0; descriptor->numInputs = 0;
dawn::VertexInputDescriptor vertexInput; dawn::VertexInputDescriptor vertexInput;
@ -48,7 +50,6 @@ namespace utils {
ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor(const dawn::Device& device) { ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor(const dawn::Device& device) {
dawn::RenderPipelineDescriptor* descriptor = this; dawn::RenderPipelineDescriptor* descriptor = this;
descriptor->indexFormat = dawn::IndexFormat::Uint32;
descriptor->primitiveTopology = dawn::PrimitiveTopology::TriangleList; descriptor->primitiveTopology = dawn::PrimitiveTopology::TriangleList;
descriptor->sampleCount = 1; descriptor->sampleCount = 1;