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

@ -594,6 +594,16 @@
{"value": 1, "name": "uint32"} {"value": 1, "name": "uint32"}
] ]
}, },
"vertex attribute descriptor": {
"category": "structure",
"extensible": false,
"members": [
{"name": "shader location", "type": "uint32_t"},
{"name": "input slot", "type": "uint32_t"},
{"name": "offset", "type": "uint32_t"},
{"name": "format", "type": "vertex format"}
]
},
"input state": { "input state": {
"category": "object" "category": "object"
}, },
@ -607,10 +617,7 @@
{ {
"name": "set attribute", "name": "set attribute",
"args": [ "args": [
{"name": "shader location", "type": "uint32_t"}, {"name": "attribute", "type": "vertex attribute descriptor", "annotation": "const*"}
{"name": "binding slot", "type": "uint32_t"},
{"name": "format", "type": "vertex format"},
{"name": "offset", "type": "uint32_t"}
] ]
}, },
{ {

View File

@ -114,13 +114,31 @@ void initRender() {
} }
)"); )");
dawn::VertexAttributeDescriptor attribute1;
attribute1.shaderLocation = 0;
attribute1.inputSlot = 0;
attribute1.offset = offsetof(Particle, pos);
attribute1.format = dawn::VertexFormat::FloatR32G32;
dawn::VertexAttributeDescriptor attribute2;
attribute2.shaderLocation = 1;
attribute2.inputSlot = 0;
attribute2.offset = offsetof(Particle, vel);
attribute2.format = dawn::VertexFormat::FloatR32G32;
dawn::VertexAttributeDescriptor attribute3;
attribute3.shaderLocation = 2;
attribute3.inputSlot = 1;
attribute3.offset = 0;
attribute3.format = dawn::VertexFormat::FloatR32G32;
dawn::InputState inputState = device.CreateInputStateBuilder() dawn::InputState inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, pos)) .SetAttribute(&attribute1)
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, vel)) .SetAttribute(&attribute2)
.SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance) .SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance)
.SetAttribute(2, 1, dawn::VertexFormat::FloatR32G32, 0) .SetAttribute(&attribute3)
.SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex) .SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
depthStencilView = CreateDefaultDepthStencilView(device); depthStencilView = CreateDefaultDepthStencilView(device);

View File

@ -111,10 +111,15 @@ void init() {
fragColor = texture(sampler2D(myTexture, mySampler), gl_FragCoord.xy / vec2(640.0, 480.0)); fragColor = texture(sampler2D(myTexture, mySampler), gl_FragCoord.xy / vec2(640.0, 480.0));
})"); })");
dawn::VertexAttributeDescriptor attribute;
attribute.shaderLocation = 0;
attribute.inputSlot = 0;
attribute.offset = 0;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
auto inputState = device.CreateInputStateBuilder() auto inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0) .SetAttribute(&attribute)
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex) .SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {

View File

@ -156,11 +156,23 @@ void init() {
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0); fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
})"); })");
dawn::VertexAttributeDescriptor attribute1;
attribute1.shaderLocation = 0;
attribute1.inputSlot = 0;
attribute1.offset = 0;
attribute1.format = dawn::VertexFormat::FloatR32G32B32;
dawn::VertexAttributeDescriptor attribute2;
attribute2.shaderLocation = 1;
attribute2.inputSlot = 0;
attribute2.offset = 3 * sizeof(float);
attribute2.format = dawn::VertexFormat::FloatR32G32B32;
auto inputState = device.CreateInputStateBuilder() auto inputState = device.CreateInputStateBuilder()
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32, 0) .SetAttribute(&attribute1)
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32B32, 3 * sizeof(float)) .SetAttribute(&attribute2)
.SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex) .SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex)
.GetResult(); .GetResult();
auto bgl = utils::MakeBindGroupLayout( auto bgl = utils::MakeBindGroupLayout(
device, { device, {

View File

@ -247,16 +247,25 @@ namespace {
fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type); fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type);
continue; continue;
} }
dawn::VertexAttributeDescriptor attribute;
attribute.offset = 0;
attribute.format = format;
if (iParameter.semantic == "POSITION") { if (iParameter.semantic == "POSITION") {
builder.SetAttribute(0, 0, format, 0); attribute.shaderLocation = 0;
attribute.inputSlot = 0;
builder.SetAttribute(&attribute);
builder.SetInput(0, static_cast<uint32_t>(stridePos), dawn::InputStepMode::Vertex); builder.SetInput(0, static_cast<uint32_t>(stridePos), dawn::InputStepMode::Vertex);
slotsSet.set(0); slotsSet.set(0);
} else if (iParameter.semantic == "NORMAL") { } else if (iParameter.semantic == "NORMAL") {
builder.SetAttribute(1, 1, format, 0); attribute.shaderLocation = 1;
attribute.inputSlot = 1;
builder.SetAttribute(&attribute);
builder.SetInput(1, static_cast<uint32_t>(strideNor), dawn::InputStepMode::Vertex); builder.SetInput(1, static_cast<uint32_t>(strideNor), dawn::InputStepMode::Vertex);
slotsSet.set(1); slotsSet.set(1);
} else if (iParameter.semantic == "TEXCOORD_0") { } else if (iParameter.semantic == "TEXCOORD_0") {
builder.SetAttribute(2, 2, format, 0); attribute.shaderLocation = 2;
attribute.inputSlot = 2;
builder.SetAttribute(&attribute);
builder.SetInput(2, static_cast<uint32_t>(strideTxc), dawn::InputStepMode::Vertex); builder.SetInput(2, static_cast<uint32_t>(strideTxc), dawn::InputStepMode::Vertex);
slotsSet.set(2); slotsSet.set(2);
} else { } else {
@ -268,7 +277,13 @@ namespace {
if (slotsSet[i]) { if (slotsSet[i]) {
continue; continue;
} }
builder.SetAttribute(i, i, dawn::VertexFormat::FloatR32G32B32A32, 0); dawn::VertexAttributeDescriptor attribute;
attribute.offset = 0;
attribute.shaderLocation = i;
attribute.inputSlot = i;
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
builder.SetAttribute(&attribute);
builder.SetInput(i, 0, dawn::InputStepMode::Vertex); builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
} }
auto inputState = builder.GetResult(); auto inputState = builder.GetResult();

View File

@ -117,7 +117,7 @@ namespace dawn_native {
InputStateBase* InputStateBuilder::GetResultImpl() { InputStateBase* InputStateBuilder::GetResultImpl() {
for (uint32_t location = 0; location < kMaxVertexAttributes; ++location) { for (uint32_t location = 0; location < kMaxVertexAttributes; ++location) {
if (mAttributesSetMask[location] && if (mAttributesSetMask[location] &&
!mInputsSetMask[mAttributeInfos[location].bindingSlot]) { !mInputsSetMask[mAttributeInfos[location].inputSlot]) {
HandleError("Attribute uses unset input"); HandleError("Attribute uses unset input");
return nullptr; return nullptr;
} }
@ -126,28 +126,25 @@ namespace dawn_native {
return GetDevice()->CreateInputState(this); return GetDevice()->CreateInputState(this);
} }
void InputStateBuilder::SetAttribute(uint32_t shaderLocation, void InputStateBuilder::SetAttribute(const VertexAttributeDescriptor* attribute) {
uint32_t bindingSlot, if (attribute->shaderLocation >= kMaxVertexAttributes) {
dawn::VertexFormat format,
uint32_t offset) {
if (shaderLocation >= kMaxVertexAttributes) {
HandleError("Setting attribute out of bounds"); HandleError("Setting attribute out of bounds");
return; return;
} }
if (bindingSlot >= kMaxVertexInputs) { if (attribute->inputSlot >= kMaxVertexInputs) {
HandleError("Binding slot out of bounds"); HandleError("Binding slot out of bounds");
return; return;
} }
if (mAttributesSetMask[shaderLocation]) { if (mAttributesSetMask[attribute->shaderLocation]) {
HandleError("Setting already set attribute"); HandleError("Setting already set attribute");
return; return;
} }
mAttributesSetMask.set(shaderLocation); mAttributesSetMask.set(attribute->shaderLocation);
auto& info = mAttributeInfos[shaderLocation]; auto& info = mAttributeInfos[attribute->shaderLocation];
info.bindingSlot = bindingSlot; info.inputSlot = attribute->inputSlot;
info.format = format; info.offset = attribute->offset;
info.offset = offset; info.format = attribute->format;
} }
void InputStateBuilder::SetInput(uint32_t bindingSlot, void InputStateBuilder::SetInput(uint32_t bindingSlot,

View File

@ -37,7 +37,7 @@ namespace dawn_native {
InputStateBase(InputStateBuilder* builder); InputStateBase(InputStateBuilder* builder);
struct AttributeInfo { struct AttributeInfo {
uint32_t bindingSlot; uint32_t inputSlot;
dawn::VertexFormat format; dawn::VertexFormat format;
uint32_t offset; uint32_t offset;
}; };
@ -64,10 +64,7 @@ namespace dawn_native {
InputStateBuilder(DeviceBase* device); InputStateBuilder(DeviceBase* device);
// Dawn API // Dawn API
void SetAttribute(uint32_t shaderLocation, void SetAttribute(const VertexAttributeDescriptor* attribute);
uint32_t bindingSlot,
dawn::VertexFormat format,
uint32_t offset);
void SetInput(uint32_t bindingSlot, uint32_t stride, dawn::InputStepMode stepMode); void SetInput(uint32_t bindingSlot, uint32_t stride, dawn::InputStepMode stepMode);
private: private:

View File

@ -78,9 +78,9 @@ namespace dawn_native { namespace d3d12 {
inputElementDescriptor.SemanticName = "TEXCOORD"; inputElementDescriptor.SemanticName = "TEXCOORD";
inputElementDescriptor.SemanticIndex = static_cast<uint32_t>(i); inputElementDescriptor.SemanticIndex = static_cast<uint32_t>(i);
inputElementDescriptor.Format = VertexFormatType(attribute.format); inputElementDescriptor.Format = VertexFormatType(attribute.format);
inputElementDescriptor.InputSlot = attribute.bindingSlot; inputElementDescriptor.InputSlot = attribute.inputSlot;
const InputInfo& input = GetInput(attribute.bindingSlot); const InputInfo& input = GetInput(attribute.inputSlot);
inputElementDescriptor.AlignedByteOffset = attribute.offset; inputElementDescriptor.AlignedByteOffset = attribute.offset;
inputElementDescriptor.InputSlotClass = InputStepModeFunction(input.stepMode); inputElementDescriptor.InputSlotClass = InputStepModeFunction(input.stepMode);

View File

@ -71,7 +71,7 @@ namespace dawn_native { namespace metal {
auto attribDesc = [MTLVertexAttributeDescriptor new]; auto attribDesc = [MTLVertexAttributeDescriptor new];
attribDesc.format = VertexFormatType(info.format); attribDesc.format = VertexFormatType(info.format);
attribDesc.offset = info.offset; attribDesc.offset = info.offset;
attribDesc.bufferIndex = kMaxBindingsPerGroup + info.bindingSlot; attribDesc.bufferIndex = kMaxBindingsPerGroup + info.inputSlot;
mMtlVertexDescriptor.attributes[i] = attribDesc; mMtlVertexDescriptor.attributes[i] = attribDesc;
[attribDesc release]; [attribDesc release];
} }

View File

@ -29,8 +29,8 @@ namespace dawn_native { namespace opengl {
auto attribute = GetAttribute(location); auto attribute = GetAttribute(location);
glEnableVertexAttribArray(location); glEnableVertexAttribArray(location);
attributesUsingInput[attribute.bindingSlot][location] = true; attributesUsingInput[attribute.inputSlot][location] = true;
auto input = GetInput(attribute.bindingSlot); auto input = GetInput(attribute.inputSlot);
if (input.stride == 0) { if (input.stride == 0) {
// Emulate a stride of zero (constant vertex attribute) by // Emulate a stride of zero (constant vertex attribute) by

View File

@ -85,7 +85,7 @@ namespace dawn_native { namespace vulkan {
auto& attributeDesc = mAttributes[attributeCount]; auto& attributeDesc = mAttributes[attributeCount];
attributeDesc.location = i; attributeDesc.location = i;
attributeDesc.binding = attributeInfo.bindingSlot; attributeDesc.binding = attributeInfo.inputSlot;
attributeDesc.format = VulkanVertexFormat(attributeInfo.format); attributeDesc.format = VulkanVertexFormat(attributeInfo.format);
attributeDesc.offset = attributeInfo.offset; attributeDesc.offset = attributeInfo.offset;

View File

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

View File

@ -26,10 +26,16 @@ class DrawTest : public DawnTest {
renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); 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 = dawn::InputState inputState =
device.CreateInputStateBuilder() device.CreateInputStateBuilder()
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex) .SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0) .SetAttribute(&attribute)
.GetResult(); .GetResult();
dawn::ShaderModule vsModule = dawn::ShaderModule vsModule =

View File

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

View File

@ -149,7 +149,13 @@ class InputStateTest : public DawnTest {
} }
for (const auto& attribute : attributes) { 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(); return builder.GetResult();

View File

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

View File

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