mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Add more validations for input state
This change sets limit for stride in VertexInputDescriptor and offset in VertexAttributeDescriptor, and adds validation code for them. It also uses existing descriptors to replace redundant definitions. BUG=dawn:107 Change-Id: Ifbb07f48ec9a5baae8ae8d21865dc384670b759a Reviewed-on: https://dawn-review.googlesource.com/c/4901 Commit-Queue: Yunchao He <yunchao.he@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
fda0617505
commit
87bf834109
@@ -146,9 +146,9 @@ TEST_F(InputStateTest, AlreadySetInput) {
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Check out of bounds condition on SetInput
|
||||
TEST_F(InputStateTest, SetInputOutOfBounds) {
|
||||
// Control case, setting last input
|
||||
// Check out of bounds condition on input slot
|
||||
TEST_F(InputStateTest, SetInputSlotOutOfBounds) {
|
||||
// Control case, setting last input slot
|
||||
dawn::VertexInputDescriptor input;
|
||||
input.inputSlot = kMaxVertexInputs - 1;
|
||||
input.stride = 0;
|
||||
@@ -156,11 +156,25 @@ TEST_F(InputStateTest, SetInputOutOfBounds) {
|
||||
|
||||
AssertWillBeSuccess(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
|
||||
|
||||
// Test OOB
|
||||
// Test input slot OOB
|
||||
input.inputSlot = kMaxVertexInputs;
|
||||
AssertWillBeError(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
|
||||
}
|
||||
|
||||
// Check out of bounds condition on input stride
|
||||
TEST_F(InputStateTest, SetInputStrideOutOfBounds) {
|
||||
// Control case, setting max input stride
|
||||
dawn::VertexInputDescriptor input;
|
||||
input.inputSlot = 0;
|
||||
input.stride = kMaxVertexInputStride;
|
||||
input.stepMode = dawn::InputStepMode::Vertex;
|
||||
AssertWillBeSuccess(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
|
||||
|
||||
// Test input stride OOB
|
||||
input.stride = kMaxVertexInputStride + 1;
|
||||
AssertWillBeError(device.CreateInputStateBuilder()).SetInput(&input).GetResult();
|
||||
}
|
||||
|
||||
// Test that we cannot set an already set attribute
|
||||
TEST_F(InputStateTest, AlreadySetAttribute) {
|
||||
// Control case, setting last attribute
|
||||
@@ -183,9 +197,9 @@ TEST_F(InputStateTest, AlreadySetAttribute) {
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Check out of bounds condition on SetAttribute
|
||||
TEST_F(InputStateTest, SetAttributeOutOfBounds) {
|
||||
// Control case, setting last attribute
|
||||
// Check out of bounds condition on attribute shader location
|
||||
TEST_F(InputStateTest, SetAttributeLocationOutOfBounds) {
|
||||
// Control case, setting last attribute shader location
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.shaderLocation = kMaxVertexAttributes - 1;
|
||||
attribute.inputSlot = 0;
|
||||
@@ -197,7 +211,7 @@ TEST_F(InputStateTest, SetAttributeOutOfBounds) {
|
||||
.SetAttribute(&attribute)
|
||||
.GetResult();
|
||||
|
||||
// Test OOB
|
||||
// Test attribute location OOB
|
||||
attribute.shaderLocation = kMaxVertexAttributes;
|
||||
AssertWillBeError(device.CreateInputStateBuilder())
|
||||
.SetInput(&kBaseInput)
|
||||
@@ -205,6 +219,40 @@ TEST_F(InputStateTest, SetAttributeOutOfBounds) {
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Check attribute offset out of bounds
|
||||
TEST_F(InputStateTest, SetAttributeOffsetOutOfBounds) {
|
||||
// Control case, setting max attribute offset for FloatR32 vertex format
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.shaderLocation = 0;
|
||||
attribute.inputSlot = 0;
|
||||
attribute.offset = kMaxVertexAttributeEnd - sizeof(dawn::VertexFormat::FloatR32);
|
||||
attribute.format = dawn::VertexFormat::FloatR32;
|
||||
AssertWillBeSuccess(device.CreateInputStateBuilder())
|
||||
.SetInput(&kBaseInput)
|
||||
.SetAttribute(&attribute)
|
||||
.GetResult();
|
||||
|
||||
// Test attribute offset out of bounds
|
||||
attribute.offset = kMaxVertexAttributeEnd - 1;
|
||||
AssertWillBeError(device.CreateInputStateBuilder())
|
||||
.SetInput(&kBaseInput)
|
||||
.SetAttribute(&attribute)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Check attribute offset overflow
|
||||
TEST_F(InputStateTest, SetAttributeOffsetOverflow) {
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.shaderLocation = 0;
|
||||
attribute.inputSlot = 0;
|
||||
attribute.offset = std::numeric_limits<uint32_t>::max();
|
||||
attribute.format = dawn::VertexFormat::FloatR32;
|
||||
AssertWillBeError(device.CreateInputStateBuilder())
|
||||
.SetInput(&kBaseInput)
|
||||
.SetAttribute(&attribute)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Check that all attributes must be backed by an input
|
||||
TEST_F(InputStateTest, RequireInputForAttribute) {
|
||||
// Control case
|
||||
|
||||
Reference in New Issue
Block a user