Vertex buffer stride size needs to be a multiple of 4 bytes

Metal requests that stride size of vertex buffer needs to be a multiple of 4 bytes. Dawn
should also follow the restriction.

BUG=dawn:130

Change-Id: I92eb67e944ab170a5dac5305c930bae507cb034d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10621
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Yan, Shaobo 2019-08-29 08:20:02 +00:00 committed by Commit Bot service account
parent ca0eac314b
commit b58435c6f9
2 changed files with 29 additions and 0 deletions

View File

@ -65,6 +65,11 @@ namespace dawn_native {
return DAWN_VALIDATION_ERROR("Setting input stride out of bounds");
}
if (buffer->stride % 4 != 0) {
return DAWN_VALIDATION_ERROR(
"Stride of Vertex buffer needs to be multiple of 4 bytes");
}
for (uint32_t i = 0; i < buffer->attributeCount; ++i) {
DAWN_TRY(ValidateVertexAttributeDescriptor(&buffer->attributes[i], buffer->stride,
attributesSetMask));

View File

@ -280,6 +280,30 @@ TEST_F(VertexInputTest, SetInputStrideOutOfBounds) {
)");
}
// Check multiple of 4 bytes constraint on input stride
TEST_F(VertexInputTest, SetInputStrideNotAligned) {
// Control case, setting input stride 4 bytes.
utils::ComboVertexInputDescriptor state;
state.bufferCount = 1;
state.cBuffers[0].stride = 4;
state.cBuffers[0].attributeCount = 1;
CreatePipeline(true, state, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
}
)");
// Test input stride not multiple of 4 bytes
state.cBuffers[0].stride = 2;
CreatePipeline(false, state, R"(
#version 450
void main() {
gl_Position = vec4(0.0);
}
)");
}
// Test that we cannot set an already set attribute
TEST_F(VertexInputTest, AlreadySetAttribute) {
// Control case, setting attribute 0