Construct VertexInputDescriptor, in order to match web idl

BUG=dawn:107

Change-Id: Ic219fb98a88a7ac597fbdc592f604f27b76d756b
Reviewed-on: https://dawn-review.googlesource.com/c/4721
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 23:56:07 +00:00
committed by Commit Bot service account
parent e7bb3fd119
commit 4dec7371a2
14 changed files with 136 additions and 65 deletions

View File

@@ -17,6 +17,12 @@
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/DawnHelpers.h"
constexpr static dawn::VertexInputDescriptor kBaseInput = {
0, // inputSlot
0, // stride
dawn::InputStepMode::Vertex, // stepMode
};
class InputStateTest : public ValidationTest {
protected:
void CreatePipeline(bool success, const dawn::InputState& inputState, std::string vertexSource) {
@@ -70,8 +76,13 @@ TEST_F(InputStateTest, PipelineCompatibility) {
attribute2.offset = sizeof(float);
attribute2.format = dawn::VertexFormat::FloatR32;
dawn::VertexInputDescriptor input;
input.inputSlot = 0;
input.stride = 2 * sizeof(float);
input.stepMode = dawn::InputStepMode::Vertex;
dawn::InputState state = AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 2 * sizeof(float), dawn::InputStepMode::Vertex)
.SetInput(&input)
.SetAttribute(&attribute1)
.SetAttribute(&attribute2)
.GetResult();
@@ -108,9 +119,7 @@ TEST_F(InputStateTest, PipelineCompatibility) {
// Test that a stride of 0 is valid
TEST_F(InputStateTest, StrideZero) {
// Works ok without attributes
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.GetResult();
AssertWillBeSuccess(device.CreateInputStateBuilder()).SetInput(&kBaseInput).GetResult();
// Works ok with attributes at a large-ish offset
dawn::VertexAttributeDescriptor attribute;
@@ -120,7 +129,7 @@ TEST_F(InputStateTest, StrideZero) {
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
}
@@ -128,28 +137,28 @@ TEST_F(InputStateTest, StrideZero) {
// Test that we cannot set an already set input
TEST_F(InputStateTest, AlreadySetInput) {
// Control case
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.GetResult();
AssertWillBeSuccess(device.CreateInputStateBuilder()).SetInput(&kBaseInput).GetResult();
// Oh no, input 0 is set twice
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetInput(&kBaseInput)
.GetResult();
}
// Check out of bounds condition on SetInput
TEST_F(InputStateTest, SetInputOutOfBounds) {
// Control case, setting last input
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(kMaxVertexInputs - 1, 0, dawn::InputStepMode::Vertex)
.GetResult();
dawn::VertexInputDescriptor input;
input.inputSlot = kMaxVertexInputs - 1;
input.stride = 0;
input.stepMode = dawn::InputStepMode::Vertex;
AssertWillBeSuccess(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
// Test OOB
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(kMaxVertexInputs, 0, dawn::InputStepMode::Vertex)
.GetResult();
input.inputSlot = kMaxVertexInputs;
AssertWillBeError(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
}
// Test that we cannot set an already set attribute
@@ -162,13 +171,13 @@ TEST_F(InputStateTest, AlreadySetAttribute) {
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
// Oh no, attribute 0 is set twice
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.SetAttribute(&attribute)
.GetResult();
@@ -184,14 +193,14 @@ TEST_F(InputStateTest, SetAttributeOutOfBounds) {
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
// Test OOB
attribute.shaderLocation = kMaxVertexAttributes;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
}
@@ -206,14 +215,14 @@ TEST_F(InputStateTest, RequireInputForAttribute) {
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
// Attribute 0 uses input 1 which doesn't exist
attribute.inputSlot = 1;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
}
@@ -228,14 +237,14 @@ TEST_F(InputStateTest, SetAttributeOOBCheckForInputs) {
attribute.format = dawn::VertexFormat::FloatR32;
AssertWillBeSuccess(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
// Could crash if we didn't check for OOB
attribute.inputSlot = 1000000;
AssertWillBeError(device.CreateInputStateBuilder())
.SetInput(0, 0, dawn::InputStepMode::Vertex)
.SetInput(&kBaseInput)
.SetAttribute(&attribute)
.GetResult();
}

View File

@@ -75,11 +75,16 @@ class VertexBufferValidationTest : public ValidationTest {
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32;
dawn::VertexInputDescriptor input;
input.stride = 0;
input.stepMode = dawn::InputStepMode::Vertex;
for (unsigned int i = 0; i < numInputs; ++i) {
attribute.shaderLocation = i;
attribute.inputSlot = i;
input.inputSlot = i;
builder.SetAttribute(&attribute);
builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
builder.SetInput(&input);
}
return builder.GetResult();
}