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>
diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp
index 5ece48d..5dc6784 100644
--- a/src/dawn_native/RenderPipeline.cpp
+++ b/src/dawn_native/RenderPipeline.cpp
@@ -65,6 +65,11 @@
                 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 63c6a8d..bc1be28 100644
--- a/src/tests/unittests/validation/VertexInputValidationTests.cpp
+++ b/src/tests/unittests/validation/VertexInputValidationTests.cpp
@@ -280,6 +280,30 @@
     )");
 }
 
+// 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