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",
"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},

View File

@ -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;

View File

@ -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();

View File

@ -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<kMaxVertexInputs> inputsSetMask;
std::bitset<kMaxVertexAttributes> 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;

View File

@ -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<kMaxColorAttachments> GetColorAttachmentsMask() const;
@ -70,7 +69,6 @@ namespace dawn_native {
private:
RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
dawn::IndexFormat mIndexFormat;
InputStateDescriptor mInputState;
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
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
// 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;

View File

@ -624,7 +624,8 @@ namespace dawn_native { namespace metal {
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) {

View File

@ -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();

View File

@ -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);

View File

@ -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<VkDeviceSize>(cmd->offset), indexType);
} break;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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.

View File

@ -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;