mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 08:57:26 +00:00
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:
committed by
Commit Bot service account
parent
445869d2b0
commit
b2207737ab
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user