diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 5ece48dd49..5dc6784995 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -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)); diff --git a/src/tests/unittests/validation/VertexInputValidationTests.cpp b/src/tests/unittests/validation/VertexInputValidationTests.cpp index 63c6a8d4fb..bc1be28807 100644 --- a/src/tests/unittests/validation/VertexInputValidationTests.cpp +++ b/src/tests/unittests/validation/VertexInputValidationTests.cpp @@ -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