Construct VertexAttributeDescriptor, in order to match web idl

The parameters about vertex attribute were encapsulated in
VertexAttributeDescriptor in web idl. This change construct
this descriptor accordingly.

BUG=dawn:107

Change-Id: Ia1c6e53af951d8f2a0c0b69bdca09291c2661e50
Reviewed-on: https://dawn-review.googlesource.com/c/4620
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
Yunchao He
2019-02-14 00:35:39 +00:00
committed by Commit Bot service account
parent 445869d2b0
commit b2207737ab
18 changed files with 207 additions and 73 deletions

View File

@@ -26,10 +26,17 @@ class DrawIndexedTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::InputState inputState = device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
.GetResult();
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
dawn::InputState inputState =
device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(&attribute)
.GetResult();
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450

View File

@@ -26,10 +26,16 @@ class DrawTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
dawn::InputState inputState =
device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
.SetAttribute(&attribute)
.GetResult();
dawn::ShaderModule vsModule =

View File

@@ -31,10 +31,17 @@ class IndexFormatTest : public DawnTest {
utils::BasicRenderPass renderPass;
dawn::RenderPipeline MakeTestPipeline(dawn::IndexFormat format) {
dawn::InputState inputState = device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
.GetResult();
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
dawn::InputState inputState =
device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(&attribute)
.GetResult();
dawn::ShaderModule vsModule = utils::CreateShaderModule(device, dawn::ShaderStage::Vertex, R"(
#version 450

View File

@@ -149,7 +149,13 @@ class InputStateTest : public DawnTest {
}
for (const auto& attribute : attributes) {
builder.SetAttribute(attribute.location, attribute.slot, attribute.format, attribute.offset);
dawn::VertexAttributeDescriptor descriptor;
descriptor.shaderLocation = attribute.location;
descriptor.inputSlot = attribute.slot;
descriptor.offset = attribute.offset;
descriptor.format = attribute.format;
builder.SetAttribute(&descriptor);
}
return builder.GetResult();

View File

@@ -165,10 +165,16 @@ class PrimitiveTopologyTest : public DawnTest {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult();
.SetAttribute(&attribute)
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult();
vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices), dawn::BufferUsageBit::Vertex);
}

View File

@@ -60,11 +60,23 @@ TEST_F(InputStateTest, EmptyIsOk) {
// Check validation that pipeline vertex inputs are backed by attributes in the input state
TEST_F(InputStateTest, PipelineCompatibility) {
dawn::VertexAttributeDescriptor attribute1;
attribute1.shaderLocation = 0;
attribute1.inputSlot = 0;
attribute1.offset = 0;
attribute1.format = dawn::VertexFormat::FloatR32;
dawn::VertexAttributeDescriptor attribute2;
attribute2.shaderLocation = 1;
attribute2.inputSlot = 0;
attribute2.offset = sizeof(float);
attribute2.format = dawn::VertexFormat::FloatR32;
dawn::InputState state = AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 2 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32, sizeof(float))
.GetResult();
.SetInput(0, 2 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(&attribute1)
.SetAttribute(&attribute2)
.GetResult();
// Control case: pipeline with one input per attribute
CreatePipeline(true, state, R"(
@@ -103,9 +115,15 @@ TEST_F(InputStateTest, StrideZero) {
.GetResult();
// Works ok with attributes at a large-ish offset
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 128;
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 128)
.SetAttribute(&attribute)
.GetResult();
}
@@ -139,60 +157,87 @@ TEST_F(InputStateTest, SetInputOutOfBounds) {
// Test that we cannot set an already set attribute
TEST_F(InputStateTest, AlreadySetAttribute) {
// Control case, setting last attribute
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
// Oh no, attribute 0 is set twice
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.SetAttribute(&attribute)
.GetResult();
}
// Check out of bounds condition on SetAttribute
TEST_F(InputStateTest, SetAttributeOutOfBounds) {
// Control case, setting last attribute
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = kMaxVertexAttributes - 1;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(kMaxVertexAttributes - 1, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
// Test OOB
attribute.shaderLocation = kMaxVertexAttributes;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(kMaxVertexAttributes, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
}
// Check that all attributes must be backed by an input
TEST_F(InputStateTest, RequireInputForAttribute) {
// Control case
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
// Attribute 0 uses input 1 which doesn't exist
attribute.inputSlot = 1;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 1, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
}
// Check OOB checks for an attribute's input
TEST_F(InputStateTest, SetAttributeOOBCheckForInputs) {
// Control case
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
// Could crash if we didn't check for OOB
attribute.inputSlot = 1000000;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetAttribute(0, 1000000, dawn::VertexFormat::FloatR32, 0)
.SetAttribute(&attribute)
.GetResult();
}

View File

@@ -71,8 +71,14 @@ class VertexBufferValidationTest : public ValidationTest {
dawn::InputState MakeInputState(unsigned int numInputs) {
auto builder = device.CreateInputStateBuilder();
dawn::VertexAttributeDescriptor attribute;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32;
for (unsigned int i = 0; i < numInputs; ++i) {
builder.SetAttribute(i, i, dawn::VertexFormat::FloatR32G32B32, 0);
attribute.shaderLocation = i;
attribute.inputSlot = i;
builder.SetAttribute(&attribute);
builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
}
return builder.GetResult();