From 1f93b119394daf1d0ce2ef546bba0e367977d5a4 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Wed, 15 Jun 2022 16:06:47 +0000 Subject: [PATCH] Validate zero-attribute for VertexBufferNotUsed buffers Add a validation to ensure zero-attribute for unused vertex buffer slots (stepMode = VertexBufferNotUsed). Fuzz tests found that non-zero-attribute with unused vertex buffer can cause an error in swiftshader. We may be able to think input data having non-zero-attribute with unused vertex buffe is malformed. Refusing such input data can avoid the error. Bug: chromium:1333293 Change-Id: Ib58d526bdaefa683e459b5c813e348b72e81e13e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93560 Reviewed-by: Corentin Wallez Commit-Queue: Takahiro Kokoro: Kokoro --- src/dawn/native/RenderPipeline.cpp | 5 +++++ .../validation/VertexStateValidationTests.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp index 3c914e602a..1830b10ca8 100644 --- a/src/dawn/native/RenderPipeline.cpp +++ b/src/dawn/native/RenderPipeline.cpp @@ -99,6 +99,11 @@ MaybeError ValidateVertexBufferLayout( DAWN_INVALID_IF(buffer->arrayStride % 4 != 0, "Vertex buffer arrayStride (%u) is not a multiple of 4.", buffer->arrayStride); + DAWN_INVALID_IF( + buffer->stepMode == wgpu::VertexStepMode::VertexBufferNotUsed && buffer->attributeCount > 0, + "attributeCount (%u) is not zero although vertex buffer stepMode is %s.", + buffer->attributeCount, wgpu::VertexStepMode::VertexBufferNotUsed); + for (uint32_t i = 0; i < buffer->attributeCount; ++i) { DAWN_TRY_CONTEXT(ValidateVertexAttribute(device, &buffer->attributes[i], metadata, buffer->arrayStride, attributesSetMask), diff --git a/src/dawn/tests/unittests/validation/VertexStateValidationTests.cpp b/src/dawn/tests/unittests/validation/VertexStateValidationTests.cpp index 422fa9fc41..32ed09e9ee 100644 --- a/src/dawn/tests/unittests/validation/VertexStateValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/VertexStateValidationTests.cpp @@ -427,3 +427,18 @@ TEST_F(VertexStateTest, BaseTypeMatchingForInexistentInput) { DoTest(wgpu::VertexFormat::Uint8x4); DoTest(wgpu::VertexFormat::Sint32x2); } + +// Test that non-zero attributeCount with VertexBufferNotUsed stepMode is invalid +TEST_F(VertexStateTest, UnusedBufferZeroAttribute) { + // Non-zero attributeCount with non-VertexBufferNotUsed is valid + utils::ComboVertexState state; + state.vertexBufferCount = 1; + state.cVertexBuffers[0].arrayStride = 0; + state.cVertexBuffers[0].attributeCount = 1; + state.cVertexBuffers[0].stepMode = wgpu::VertexStepMode::Vertex; + CreatePipeline(true, state, kPlaceholderVertexShader); + + // Non-zero attributeCount with VertexBufferNotUsed is invalid + state.cVertexBuffers[0].stepMode = wgpu::VertexStepMode::VertexBufferNotUsed; + CreatePipeline(false, state, kPlaceholderVertexShader); +}