From 6dd1d37da86ecdfb610be453ef6f6b7108d4f33b Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 21 Apr 2021 20:26:31 +0000 Subject: [PATCH] unittests: Add a position return value for vertex shaders Fixes new validation errors added with: https://dawn-review.googlesource.com/c/tint/+/48560 Change-Id: Icb9a3bc46574c365a812685d01aab336a11792c1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48681 Auto-Submit: Ben Clayton Reviewed-by: Ryan Harrison Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- .../validation/BindGroupValidationTests.cpp | 12 ++++--- .../GetBindGroupLayoutValidationTests.cpp | 36 ++++++++++++------- .../MinimumBufferSizeValidationTests.cpp | 6 ++-- .../RenderBundleValidationTests.cpp | 3 +- .../RenderPipelineValidationTests.cpp | 3 +- .../validation/ResourceUsageTrackingTests.cpp | 9 +++-- .../validation/UnsafeAPIValidationTests.cpp | 6 +++- 7 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp index 724ee9cd8a..f7ca6b8b3d 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -1084,7 +1084,8 @@ class SetBindGroupValidationTest : public ValidationTest { wgpu::RenderPipeline CreateRenderPipeline() { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -1487,7 +1488,8 @@ class SetBindGroupPersistenceValidationTest : public ValidationTest { ValidationTest::SetUp(); mVsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); } @@ -1689,7 +1691,8 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest { const char* fsShader, std::vector bindGroupLayout) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, fsShader); @@ -2061,7 +2064,8 @@ class ComparisonSamplerBindingTest : public ValidationTest { wgpu::RenderPipeline CreateFragmentPipeline(wgpu::BindGroupLayout* bindGroupLayout, const char* fragmentSource) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, fragmentSource); diff --git a/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp b/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp index eddef24994..95ee2cd62a 100644 --- a/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp +++ b/src/tests/unittests/validation/GetBindGroupLayoutValidationTests.cpp @@ -21,7 +21,8 @@ class GetBindGroupLayoutTests : public ValidationTest { protected: wgpu::RenderPipeline RenderPipelineFromFragmentShader(const char* shader) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, shader); @@ -50,9 +51,10 @@ TEST_F(GetBindGroupLayoutTests, SameObject) { [[group(0), binding(0)]] var uniform0 : S; [[group(1), binding(0)]] var uniform1 : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : vec4 = uniform0.pos; pos = uniform1.pos; + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -473,9 +475,10 @@ TEST_F(GetBindGroupLayoutTests, DuplicateBinding) { [[group(0), binding(0)]] var uniform0 : S; [[group(1), binding(0)]] var uniform1 : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : vec4 = uniform0.pos; pos = uniform1.pos; + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -509,8 +512,9 @@ TEST_F(GetBindGroupLayoutTests, MinBufferSize) { }; [[group(0), binding(0)]] var uniforms : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : f32 = uniforms.pos; + return vec4(); })"); wgpu::ShaderModule vsModule64 = utils::CreateShaderModule(device, R"( @@ -519,8 +523,9 @@ TEST_F(GetBindGroupLayoutTests, MinBufferSize) { }; [[group(0), binding(0)]] var uniforms : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : mat4x4 = uniforms.pos; + return vec4(); })"); wgpu::ShaderModule fsModule4 = utils::CreateShaderModule(device, R"( @@ -594,13 +599,15 @@ TEST_F(GetBindGroupLayoutTests, StageAggregation) { DAWN_SKIP_TEST_IF(UsesWire()); wgpu::ShaderModule vsModuleNoSampler = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule vsModuleSampler = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var mySampler: sampler; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { let s : sampler = mySampler; + return vec4(); })"); wgpu::ShaderModule fsModuleNoSampler = utils::CreateShaderModule(device, R"( @@ -664,8 +671,9 @@ TEST_F(GetBindGroupLayoutTests, ConflictingBindingType) { }; [[group(0), binding(0)]] var ubo : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : vec4 = ubo.pos; + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -691,8 +699,9 @@ TEST_F(GetBindGroupLayoutTests, ConflictingBindingTextureMultisampling) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var myTexture : texture_2d; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { textureDimensions(myTexture); + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -715,8 +724,9 @@ TEST_F(GetBindGroupLayoutTests, ConflictingBindingViewDimension) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var myTexture : texture_2d; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { textureDimensions(myTexture); + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -739,8 +749,9 @@ TEST_F(GetBindGroupLayoutTests, ConflictingBindingTextureComponentType) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var myTexture : texture_2d; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { textureDimensions(myTexture); + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -833,8 +844,9 @@ TEST_F(GetBindGroupLayoutTests, Reflection) { }; [[group(0), binding(0)]] var uniforms : S; - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { var pos : vec4 = uniforms.pos; + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( diff --git a/src/tests/unittests/validation/MinimumBufferSizeValidationTests.cpp b/src/tests/unittests/validation/MinimumBufferSizeValidationTests.cpp index 7aaf5aabe6..7338045d48 100644 --- a/src/tests/unittests/validation/MinimumBufferSizeValidationTests.cpp +++ b/src/tests/unittests/validation/MinimumBufferSizeValidationTests.cpp @@ -123,8 +123,10 @@ namespace { // Creates a vertex shader with given bindings std::string CreateVertexShaderWithBindings(const std::vector& bindings) { - return kStructs + GenerateBindingString(bindings) + "[[stage(vertex)]] fn main() {\n" + - GenerateReferenceString(bindings, wgpu::ShaderStage::Vertex) + "}"; + return kStructs + GenerateBindingString(bindings) + + "[[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 {\n" + + GenerateReferenceString(bindings, wgpu::ShaderStage::Vertex) + + "\n return vec4(); " + "}"; } // Creates a fragment shader with given bindings diff --git a/src/tests/unittests/validation/RenderBundleValidationTests.cpp b/src/tests/unittests/validation/RenderBundleValidationTests.cpp index cad2341c97..c5984e7529 100644 --- a/src/tests/unittests/validation/RenderBundleValidationTests.cpp +++ b/src/tests/unittests/validation/RenderBundleValidationTests.cpp @@ -33,7 +33,8 @@ namespace { }; [[group(0), binding(0)]] var uniforms : S; - [[stage(vertex)]] fn main([[location(0)]] pos : vec2) { + [[stage(vertex)]] fn main([[location(0)]] pos : vec2) -> [[builtin(position)]] vec4 { + return vec4(); })"); fsModule = utils::CreateShaderModule(device, R"( diff --git a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp index 3b63b7ab83..ba23b63eea 100644 --- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp @@ -486,8 +486,9 @@ TEST_F(RenderPipelineValidationTest, StorageBufferInVertexShaderNoLayout) { data : array; }; [[group(0), binding(0)]] var dst : [[access(read_write)]] Dst; - [[stage(vertex)]] fn main([[builtin(vertex_index)]] VertexIndex : u32) { + [[stage(vertex)]] fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { dst.data[VertexIndex] = 0x1234u; + return vec4(); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/unittests/validation/ResourceUsageTrackingTests.cpp b/src/tests/unittests/validation/ResourceUsageTrackingTests.cpp index 0fca1091e5..918411a587 100644 --- a/src/tests/unittests/validation/ResourceUsageTrackingTests.cpp +++ b/src/tests/unittests/validation/ResourceUsageTrackingTests.cpp @@ -47,7 +47,8 @@ namespace { // pipeline. But those bind groups in caller can be used for validation for other purposes. wgpu::RenderPipeline CreateNoOpRenderPipeline() { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -772,7 +773,8 @@ namespace { // Create a passthrough render pipeline with a readonly buffer wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -1550,7 +1552,8 @@ namespace { { // Create a passthrough render pipeline with a readonly storage texture wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( diff --git a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp index d6e5b4f209..8c6986bfd7 100644 --- a/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp +++ b/src/tests/unittests/validation/UnsafeAPIValidationTests.cpp @@ -65,7 +65,11 @@ TEST_F(UnsafeAPIValidationTest, DrawIndexedIndirectDisallowed) { bundleDesc.cColorFormats[0] = renderPass.attachmentFormat; utils::ComboRenderPipelineDescriptor2 desc; - desc.vertex.module = utils::CreateShaderModule(device, "[[stage(vertex)]] fn main() {}"); + desc.vertex.module = utils::CreateShaderModule( + device, + R"([[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(); + })"); desc.cFragment.module = utils::CreateShaderModule(device, "[[stage(fragment)]] fn main() {}"); wgpu::RenderPipeline pipeline = device.CreateRenderPipeline2(&desc);