Fix the vertex attribute offset alignment rule.

Bug: dawn:130
Change-Id: Ib5fa24bf5520cb1ffe1653f1504dff244df928b4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44300
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Corentin Wallez 2021-03-15 14:52:53 +00:00 committed by Commit Bot service account
parent 693b76bcd5
commit a94c9acd01
2 changed files with 21 additions and 5 deletions

View File

@ -60,8 +60,9 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds"); return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds");
} }
if (attribute->offset % 4 != 0) { if (attribute->offset % dawn::VertexFormatComponentSize(attribute->format) != 0) {
return DAWN_VALIDATION_ERROR("Attribute offset needs to be a multiple of 4 bytes"); return DAWN_VALIDATION_ERROR(
"Attribute offset needs to be a multiple of the size format's components");
} }
if ((*attributesSetMask)[attribute->shaderLocation]) { if ((*attributesSetMask)[attribute->shaderLocation]) {

View File

@ -292,17 +292,32 @@ TEST_F(VertexStateTest, SetAttributeOffsetOutOfBounds) {
CreatePipeline(false, state, kDummyVertexShader); CreatePipeline(false, state, kDummyVertexShader);
} }
// Check multiple of 4 bytes constraint on offset // Check the "component byte size" alignment constraint for the offset.
TEST_F(VertexStateTest, SetOffsetNotAligned) { TEST_F(VertexStateTest, SetOffsetNotAligned) {
// Control case, setting offset 4 bytes. // Control case, setting the offset at the correct alignments.
utils::ComboVertexStateDescriptor state; utils::ComboVertexStateDescriptor state;
state.vertexBufferCount = 1; state.vertexBufferCount = 1;
state.cVertexBuffers[0].attributeCount = 1; state.cVertexBuffers[0].attributeCount = 1;
state.cAttributes[0].format = wgpu::VertexFormat::Float32;
state.cAttributes[0].offset = 4; state.cAttributes[0].offset = 4;
CreatePipeline(true, state, kDummyVertexShader); CreatePipeline(true, state, kDummyVertexShader);
// Test offset not multiple of 4 bytes state.cAttributes[0].format = wgpu::VertexFormat::Snorm16x2;
state.cAttributes[0].offset = 2; state.cAttributes[0].offset = 2;
CreatePipeline(true, state, kDummyVertexShader);
state.cAttributes[0].format = wgpu::VertexFormat::Uint8x2;
state.cAttributes[0].offset = 1;
CreatePipeline(true, state, kDummyVertexShader);
// Test offset not multiple of the component byte size.
state.cAttributes[0].format = wgpu::VertexFormat::Float32;
state.cAttributes[0].offset = 2;
CreatePipeline(false, state, kDummyVertexShader);
state.cAttributes[0].format = wgpu::VertexFormat::Snorm16x2;
state.cAttributes[0].offset = 1;
CreatePipeline(false, state, kDummyVertexShader); CreatePipeline(false, state, kDummyVertexShader);
} }