Attribute offset needs to be multiple of 4 bytes

Metal requires offset to be 4 bytes aligned. This CL makes sure a
validation error is fired when offset is not a multiple of 4.

See https://developer.apple.com/documentation/metal/mtlvertexattributedescriptor/1515785-offset

Bug: dawn:22
Change-Id: I8be26fc1851e3aea7cfdbd5c92dfb4169fdaed5e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11902
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
François Beaufort 2019-10-09 06:12:10 +00:00 committed by Commit Bot service account
parent e986cb9254
commit c932f33093
2 changed files with 29 additions and 1 deletions

View File

@ -49,6 +49,10 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds");
}
if (attribute->offset % 4 != 0) {
return DAWN_VALIDATION_ERROR("Attribute offset needs to be a multiple of 4 bytes");
}
if ((*attributesSetMask)[attribute->shaderLocation]) {
return DAWN_VALIDATION_ERROR("Setting already set attribute");
}
@ -67,7 +71,7 @@ namespace dawn_native {
if (buffer->stride % 4 != 0) {
return DAWN_VALIDATION_ERROR(
"Stride of Vertex buffer needs to be multiple of 4 bytes");
"Stride of Vertex buffer needs to be a multiple of 4 bytes");
}
for (uint32_t i = 0; i < buffer->attributeCount; ++i) {

View File

@ -418,6 +418,30 @@ TEST_F(VertexInputTest, SetAttributeOffsetOutOfBounds) {
)");
}
// Check multiple of 4 bytes constraint on offset
TEST_F(VertexInputTest, SetOffsetNotAligned) {
// Control case, setting offset 4 bytes.
utils::ComboVertexInputDescriptor state;
state.bufferCount = 1;
state.cBuffers[0].attributeCount = 1;
state.cAttributes[0].offset = 4;
CreatePipeline(true, state, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
}
)");
// Test offset not multiple of 4 bytes
state.cAttributes[0].offset = 2;
CreatePipeline(false, state, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
}
)");
}
// Check attribute offset overflow
TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
utils::ComboVertexInputDescriptor state;