From e87ea2bedc8bc9e4cdd49039337119494846db7e Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Wed, 14 Apr 2021 17:05:07 +0000 Subject: [PATCH] Update WGSL syntax for end2end tests Changes I/O to use function parameters and return values, removes unnecessary "-> void" return types, and changes "const" to "let". BUG: dawn:755 Change-Id: Iabbfcc280fae37d73cba6a2f7e2215ed579a04e0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/47700 Reviewed-by: Brandon Jones Reviewed-by: Kai Ninomiya Commit-Queue: Brandon Jones --- src/tests/end2end/BindGroupTests.cpp | 97 ++++++--------- src/tests/end2end/BufferZeroInitTests.cpp | 75 ++++++----- src/tests/end2end/ClipSpaceTests.cpp | 17 +-- src/tests/end2end/ColorStateTests.cpp | 55 ++++---- .../end2end/CompressedTextureFormatTests.cpp | 29 +++-- .../end2end/ComputeCopyStorageBufferTests.cpp | 21 ++-- src/tests/end2end/ComputeDispatchTests.cpp | 6 +- .../end2end/ComputeSharedMemoryTests.cpp | 10 +- .../ComputeStorageBufferBarrierTests.cpp | 22 ++-- .../end2end/CopyTextureForBrowserTests.cpp | 18 +-- .../end2end/CreatePipelineAsyncTests.cpp | 30 ++--- src/tests/end2end/CullingTests.cpp | 20 ++- src/tests/end2end/D3D12CachingTests.cpp | 44 ++----- src/tests/end2end/D3D12VideoViewsTests.cpp | 55 ++++---- src/tests/end2end/DeprecatedAPITests.cpp | 14 +-- src/tests/end2end/DepthBiasTests.cpp | 26 ++-- src/tests/end2end/DepthStencilCopyTests.cpp | 41 +++--- .../end2end/DepthStencilSamplingTests.cpp | 16 +-- src/tests/end2end/DepthStencilStateTests.cpp | 15 +-- src/tests/end2end/DestroyTests.cpp | 12 +- src/tests/end2end/DeviceLostTests.cpp | 7 +- .../end2end/DrawIndexedIndirectTests.cpp | 12 +- src/tests/end2end/DrawIndexedTests.cpp | 12 +- src/tests/end2end/DrawIndirectTests.cpp | 12 +- src/tests/end2end/DrawTests.cpp | 12 +- .../end2end/DynamicBufferOffsetTests.cpp | 19 ++- src/tests/end2end/EntryPointTests.cpp | 14 +-- src/tests/end2end/FirstIndexOffsetTests.cpp | 2 +- .../end2end/GpuMemorySynchronizationTests.cpp | 48 +++---- src/tests/end2end/IOSurfaceWrappingTests.cpp | 28 +++-- src/tests/end2end/IndexFormatTests.cpp | 22 ++-- .../end2end/MultisampledRenderingTests.cpp | 89 +++++++------ .../end2end/MultisampledSamplingTests.cpp | 22 ++-- src/tests/end2end/ObjectCachingTests.cpp | 45 +++---- src/tests/end2end/OpArrayLengthTests.cpp | 38 +++--- src/tests/end2end/PrimitiveStateTests.cpp | 11 +- src/tests/end2end/PrimitiveTopologyTests.cpp | 12 +- src/tests/end2end/QueryTests.cpp | 14 +-- src/tests/end2end/RenderBundleTests.cpp | 12 +- src/tests/end2end/RenderPassLoadOpTests.cpp | 15 +-- src/tests/end2end/RenderPassTests.cpp | 15 +-- .../end2end/SamplerFilterAnisotropicTests.cpp | 35 +++--- src/tests/end2end/SamplerTests.cpp | 19 ++- src/tests/end2end/ScissorTests.cpp | 15 +-- src/tests/end2end/ShaderTests.cpp | 2 +- src/tests/end2end/StorageTextureTests.cpp | 61 +++++---- .../end2end/SwapChainValidationTests.cpp | 10 +- src/tests/end2end/TextureFormatTests.cpp | 24 ++-- src/tests/end2end/TextureSubresourceTests.cpp | 34 ++--- src/tests/end2end/TextureViewTests.cpp | 64 +++++----- src/tests/end2end/TextureZeroInitTests.cpp | 28 +++-- .../end2end/VertexBufferRobustnessTests.cpp | 19 +-- src/tests/end2end/VertexFormatTests.cpp | 48 ++++--- src/tests/end2end/VertexStateTests.cpp | 117 ++++++++++-------- .../end2end/ViewportOrientationTests.cpp | 11 +- src/tests/end2end/ViewportTests.cpp | 25 ++-- 56 files changed, 737 insertions(+), 859 deletions(-) diff --git a/src/tests/end2end/BindGroupTests.cpp b/src/tests/end2end/BindGroupTests.cpp index 8566678516..6406014126 100644 --- a/src/tests/end2end/BindGroupTests.cpp +++ b/src/tests/end2end/BindGroupTests.cpp @@ -46,16 +46,14 @@ class BindGroupTests : public DawnTest { wgpu::ShaderModule MakeSimpleVSModule() const { return utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); } @@ -63,8 +61,6 @@ class BindGroupTests : public DawnTest { ASSERT(bindingTypes.size() <= kMaxBindGroups); std::ostringstream fs; - fs << "[[location(0)]] var fragColor : vec4;\n"; - for (size_t i = 0; i < bindingTypes.size(); ++i) { fs << "[[block]] struct Buffer" << i << R"( { color : vec4; @@ -84,10 +80,12 @@ class BindGroupTests : public DawnTest { } } - fs << "\n[[stage(fragment)]] fn main() {\n"; + fs << "\n[[stage(fragment)]] fn main() -> [[location(0)]] vec4{\n"; + fs << "var fragColor : vec4 = vec4();\n"; for (size_t i = 0; i < bindingTypes.size(); ++i) { fs << "fragColor = fragColor + buffer" << i << ".color;\n"; } + fs << "return fragColor;\n"; fs << "}\n"; return utils::CreateShaderModule(device, fs.str().c_str()); } @@ -165,17 +163,15 @@ TEST_P(BindGroupTests, ReusedUBO) { [[group(0), binding(0)]] var vertexUbo : VertexUniformBuffer; - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); var transform : mat2x2 = mat2x2(vertexUbo.transform.xy, vertexUbo.transform.zw); - Position = vec4(transform * pos[VertexIndex], 0.0, 1.0); + return vec4(transform * pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -184,10 +180,8 @@ TEST_P(BindGroupTests, ReusedUBO) { }; [[group(0), binding(1)]] var fragmentUbo : FragmentUniformBuffer; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = fragmentUbo.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return fragmentUbo.color; })"); utils::ComboRenderPipelineDescriptor2 textureDescriptor; @@ -246,28 +240,24 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { }; [[group(0), binding(0)]] var vertexUbo : VertexUniformBuffer; - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); var transform : mat2x2 = mat2x2(vertexUbo.transform.xy, vertexUbo.transform.zw); - Position = vec4(transform * pos[VertexIndex], 0.0, 1.0); + return vec4(transform * pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(1)]] var samp : sampler; [[group(0), binding(2)]] var tex : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(tex, samp, FragCoord.xy); + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> [[location(0)]] vec4 { + return textureSample(tex, samp, FragCoord.xy); })"); utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; @@ -361,16 +351,14 @@ TEST_P(BindGroupTests, MultipleBindLayouts) { [[group(0), binding(0)]] var vertexUbo1 : VertexUniformBuffer1; [[group(1), binding(0)]] var vertexUbo2 : VertexUniformBuffer2; - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); - Position = vec4(mat2x2( + return vec4(mat2x2( vertexUbo1.transform.xy + vertexUbo2.transform.xy, vertexUbo1.transform.zw + vertexUbo2.transform.zw ) * pos[VertexIndex], 0.0, 1.0); @@ -390,10 +378,8 @@ TEST_P(BindGroupTests, MultipleBindLayouts) { [[group(0), binding(1)]] var fragmentUbo1 : FragmentUniformBuffer1; [[group(1), binding(1)]] var fragmentUbo2 : FragmentUniformBuffer2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = fragmentUbo1.color + fragmentUbo2.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return fragmentUbo1.color + fragmentUbo2.color; })"); utils::ComboRenderPipelineDescriptor2 textureDescriptor; @@ -951,16 +937,14 @@ TEST_P(BindGroupTests, ArbitraryBindingNumbers) { utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -982,10 +966,8 @@ TEST_P(BindGroupTests, ArbitraryBindingNumbers) { [[group(0), binding(47)]] var ubo2 : Ubo2; [[group(0), binding(111)]] var ubo3 : Ubo3; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = ubo1.color + 2.0 * ubo2.color + 4.0 * ubo3.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return ubo1.color + 2.0 * ubo2.color + 4.0 * ubo3.color; })"); utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; @@ -1107,16 +1089,14 @@ TEST_P(BindGroupTests, ReadonlyStorage) { utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; pipelineDescriptor.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( @@ -1125,9 +1105,8 @@ TEST_P(BindGroupTests, ReadonlyStorage) { }; [[group(0), binding(0)]] var buffer0 : [[access(read)]] Buffer0; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = buffer0.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return buffer0.color; })"); constexpr uint32_t kRTSize = 4; diff --git a/src/tests/end2end/BufferZeroInitTests.cpp b/src/tests/end2end/BufferZeroInitTests.cpp index 22879f8b59..0be8244d64 100644 --- a/src/tests/end2end/BufferZeroInitTests.cpp +++ b/src/tests/end2end/BufferZeroInitTests.cpp @@ -207,11 +207,9 @@ class BufferZeroInitTest : public DawnTest { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, vertexShader); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var i_color : vec4; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = i_color; + [[stage(fragment)]] + fn main([[location(0)]] i_color : vec4) -> [[location(0)]] vec4 { + return i_color; })"); ASSERT(vertexBufferCount <= 1u); @@ -248,18 +246,20 @@ class BufferZeroInitTest : public DawnTest { constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"( - [[location(0)]] var pos : vec4; - [[location(0)]] var o_color : vec4; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main([[location(0)]] pos : vec4) -> VertexOut { + var output : VertexOut; if (all(pos == vec4(0.0, 0.0, 0.0, 0.0))) { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + output.color = vec4(0.0, 1.0, 0.0, 1.0); } else { - o_color = vec4(1.0, 0.0, 0.0, 1.0); + output.color = vec4(1.0, 0.0, 0.0, 1.0); } - Position = vec4(0.0, 0.0, 0.0, 1.0); + output.position = vec4(0.0, 0.0, 0.0, 1.0); + return output; })"); constexpr uint64_t kVertexAttributeSize = sizeof(float) * 4; @@ -290,18 +290,21 @@ class BufferZeroInitTest : public DawnTest { wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"( - [[location(0)]] var o_color : vec4; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOut { + var output : VertexOut; if (VertexIndex == 0u) { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + output.color = vec4(0.0, 1.0, 0.0, 1.0); } else { - o_color = vec4(1.0, 0.0, 0.0, 1.0); + output.color = vec4(1.0, 0.0, 0.0, 1.0); } - Position = vec4(0.0, 0.0, 0.0, 1.0); + output.position = vec4(0.0, 0.0, 0.0, 1.0); + return output; })", 0 /* vertexBufferCount */); @@ -337,13 +340,16 @@ class BufferZeroInitTest : public DawnTest { // As long as the vertex shader is executed once, the output color will be red. wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"( - [[location(0)]] var o_color : vec4; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - o_color = vec4(1.0, 0.0, 0.0, 1.0); - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> VertexOut { + var output : VertexOut; + output.color = vec4(1.0, 0.0, 0.0, 1.0); + output.position = vec4(0.0, 0.0, 0.0, 1.0); + return output; })", 0 /* vertexBufferCount */); @@ -375,13 +381,16 @@ class BufferZeroInitTest : public DawnTest { // As long as the vertex shader is executed once, the output color will be red. wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"( - [[location(0)]] var o_color : vec4; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - o_color = vec4(1.0, 0.0, 0.0, 1.0); - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> VertexOut { + var output : VertexOut; + output.color = vec4(1.0, 0.0, 0.0, 1.0); + output.position = vec4(0.0, 0.0, 0.0, 1.0); + return output; })", 0 /* vertexBufferCount */); wgpu::Buffer indexBuffer = diff --git a/src/tests/end2end/ClipSpaceTests.cpp b/src/tests/end2end/ClipSpaceTests.cpp index 886641e467..d126f2273a 100644 --- a/src/tests/end2end/ClipSpaceTests.cpp +++ b/src/tests/end2end/ClipSpaceTests.cpp @@ -26,7 +26,7 @@ class ClipSpaceTest : public DawnTest { // 1. The depth value of the top-left one is >= 0.5 // 2. The depth value of the bottom-right one is <= 0.5 pipelineDescriptor.vertex.module = utils::CreateShaderModule(device, R"( - const pos : array, 6> = array, 6>( + let pos : array, 6> = array, 6>( vec3(-1.0, 1.0, 1.0), vec3(-1.0, -1.0, 0.5), vec3( 1.0, 1.0, 0.5), @@ -34,19 +34,14 @@ class ClipSpaceTest : public DawnTest { vec3(-1.0, -1.0, 0.5), vec3( 1.0, -1.0, 0.0)); - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - Position = vec4(pos[VertexIndex], 1.0); - return; + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(pos[VertexIndex], 1.0); })"); pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4;; - [[stage(fragment)]] fn main() { - fragColor = vec4(1.0, 0.0, 0.0, 1.0); - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); })"); wgpu::DepthStencilState* depthStencil = pipelineDescriptor.EnableDepthStencil(); diff --git a/src/tests/end2end/ColorStateTests.cpp b/src/tests/end2end/ColorStateTests.cpp index 7e51cc1b87..4940d3743d 100644 --- a/src/tests/end2end/ColorStateTests.cpp +++ b/src/tests/end2end/ColorStateTests.cpp @@ -35,16 +35,13 @@ class ColorStateTest : public DawnTest { DAWN_SKIP_TEST_IF(IsD3D12() && IsWARP()); vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); - return; + return vec4(pos[VertexIndex], 0.0, 1.0); } )"); @@ -66,11 +63,8 @@ class ColorStateTest : public DawnTest { [[group(0), binding(0)]] var myUbo : MyBlock; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = myUbo.color; - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return myUbo.color; } )"); @@ -799,17 +793,20 @@ TEST_P(ColorStateTest, IndependentColorState) { [[group(0), binding(0)]] var myUbo : MyBlock; - [[location(0)]] var fragColor0 : vec4; - [[location(1)]] var fragColor1 : vec4; - [[location(2)]] var fragColor2 : vec4; - [[location(3)]] var fragColor3 : vec4; + struct FragmentOut { + [[location(0)]] fragColor0 : vec4; + [[location(1)]] fragColor1 : vec4; + [[location(2)]] fragColor2 : vec4; + [[location(3)]] fragColor3 : vec4; + }; - [[stage(fragment)]] fn main() { - fragColor0 = myUbo.color0; - fragColor1 = myUbo.color1; - fragColor2 = myUbo.color2; - fragColor3 = myUbo.color3; - return; + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.fragColor0 = myUbo.color0; + output.fragColor1 = myUbo.color1; + output.fragColor2 = myUbo.color2; + output.fragColor3 = myUbo.color3; + return output; } )"); @@ -915,11 +912,8 @@ TEST_P(ColorStateTest, DefaultBlendColor) { [[group(0), binding(0)]] var myUbo : MyBlock; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = myUbo.color; - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return myUbo.color; } )"); @@ -1042,11 +1036,8 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) { [[group(0), binding(0)]] var myUbo : MyBlock; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = myUbo.color; - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return myUbo.color; } )"); diff --git a/src/tests/end2end/CompressedTextureFormatTests.cpp b/src/tests/end2end/CompressedTextureFormatTests.cpp index e763899b38..efe4a24486 100644 --- a/src/tests/end2end/CompressedTextureFormatTests.cpp +++ b/src/tests/end2end/CompressedTextureFormatTests.cpp @@ -140,31 +140,30 @@ class CompressedTextureBCFormatTest : public DawnTest { utils::ComboRenderPipelineDescriptor2 renderPipelineDescriptor; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[location(0)]] var texCoord : vec2 ; + struct VertexOut { + [[location(0)]] texCoord : vec2 ; + [[builtin(position)]] position : vec4; + }; - [[builtin(vertex_index)]] var VertexIndex : u32; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOut { + let pos : array, 3> = array, 3>( vec2(-3.0, 1.0), vec2( 3.0, 1.0), vec2( 0.0, -2.0) ); - Position = vec4(pos[VertexIndex], 0.0, 1.0); - texCoord = vec2(Position.x / 2.0, -Position.y / 2.0) + vec2(0.5, 0.5); - return; + var output : VertexOut; + output.position = vec4(pos[VertexIndex], 0.0, 1.0); + output.texCoord = vec2(output.position.x / 2.0, -output.position.y / 2.0) + vec2(0.5, 0.5); + return output; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, texCoord); - return; + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, texCoord); })"); renderPipelineDescriptor.vertex.module = vsModule; renderPipelineDescriptor.cFragment.module = fsModule; diff --git a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp index 1cdf2c7b82..f41da7bebc 100644 --- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp +++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp @@ -99,10 +99,9 @@ TEST_P(ComputeCopyStorageBufferTests, SizedArrayOfBasic) { [[set(0), binding(0)]] var src : [[access(read_write)]] Buf1; [[set(0), binding(1)]] var dst : [[access(read_write)]] Buf2; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - - [[stage(compute)]] fn main() { - var index : u32 = GlobalInvocationID.x; + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { + let index : u32 = GlobalInvocationID.x; if (index >= 4u) { return; } dst.s[index] = src.s[index]; })"); @@ -127,10 +126,9 @@ TEST_P(ComputeCopyStorageBufferTests, SizedArrayOfStruct) { [[set(0), binding(0)]] var src : [[access(read_write)]] Buf1; [[set(0), binding(1)]] var dst : [[access(read_write)]] Buf2; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - - [[stage(compute)]] fn main() { - var index : u32 = GlobalInvocationID.x; + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { + let index : u32 = GlobalInvocationID.x; if (index >= 4u) { return; } dst.s[index] = src.s[index]; })"); @@ -150,10 +148,9 @@ TEST_P(ComputeCopyStorageBufferTests, UnsizedArrayOfBasic) { [[set(0), binding(0)]] var src : [[access(read_write)]] Buf1; [[set(0), binding(1)]] var dst : [[access(read_write)]] Buf2; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - - [[stage(compute)]] fn main() { - var index : u32 = GlobalInvocationID.x; + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { + let index : u32 = GlobalInvocationID.x; if (index >= 4u) { return; } dst.s[index] = src.s[index]; })"); diff --git a/src/tests/end2end/ComputeDispatchTests.cpp b/src/tests/end2end/ComputeDispatchTests.cpp index e343091a59..93d844fa96 100644 --- a/src/tests/end2end/ComputeDispatchTests.cpp +++ b/src/tests/end2end/ComputeDispatchTests.cpp @@ -39,11 +39,9 @@ class ComputeDispatchTests : public DawnTest { [[group(0), binding(0)]] var input : InputBuf; [[group(0), binding(1)]] var output : [[access(read_write)]] OutputBuf; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - [[stage(compute), workgroup_size(1, 1, 1)]] - fn main() { - const dispatch : vec3 = input.expectedDispatch; + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { + let dispatch : vec3 = input.expectedDispatch; if (dispatch.x == 0u || dispatch.y == 0u || dispatch.z == 0u) { output.workGroups = vec3(0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu); diff --git a/src/tests/end2end/ComputeSharedMemoryTests.cpp b/src/tests/end2end/ComputeSharedMemoryTests.cpp index c0a2e23d1e..8ac321291f 100644 --- a/src/tests/end2end/ComputeSharedMemoryTests.cpp +++ b/src/tests/end2end/ComputeSharedMemoryTests.cpp @@ -71,10 +71,8 @@ void ComputeSharedMemoryTests::BasicTest(const char* shader) { // Basic shared memory test TEST_P(ComputeSharedMemoryTests, Basic) { BasicTest(R"( - const kTileSize : u32 = 4; - const kInstances : u32 = 11; - - [[builtin(local_invocation_id)]] var LocalInvocationID : vec3; + let kTileSize : u32 = 4u; + let kInstances : u32 = 11u; [[block]] struct Dst { x : u32; @@ -84,8 +82,8 @@ TEST_P(ComputeSharedMemoryTests, Basic) { var tmp : u32; [[stage(compute), workgroup_size(4,4,1)]] - fn main() { - var index : u32 = LocalInvocationID.y * kTileSize + LocalInvocationID.x; + fn main([[builtin(local_invocation_id)]] LocalInvocationID : vec3) { + let index : u32 = LocalInvocationID.y * kTileSize + LocalInvocationID.x; if (index == 0u) { tmp = 0u; } diff --git a/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp b/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp index 06c8a6e62a..3c85edf682 100644 --- a/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp +++ b/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp @@ -38,9 +38,8 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) { [[group(0), binding(0)]] var buf : [[access(read_write)]] Buf; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - - [[stage(compute)]] fn main() { + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { buf.data[GlobalInvocationID.x] = buf.data[GlobalInvocationID.x] + 0x1234u; } )"); @@ -94,9 +93,9 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) { [[group(0), binding(0)]] var src : [[access(read_write)]] Src; [[group(0), binding(1)]] var dst : [[access(read_write)]] Dst; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - [[stage(compute)]] fn main() { + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + 0x1234u; } )"); @@ -166,9 +165,8 @@ TEST_P(ComputeStorageBufferBarrierTests, StorageAndReadonlyStoragePingPongInOneP [[group(0), binding(0)]] var src : [[access(read)]] Src; [[group(0), binding(1)]] var dst : [[access(read_write)]] Dst; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - - [[stage(compute)]] fn main() { + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + 0x1234u; } )"); @@ -234,9 +232,9 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) { [[group(0), binding(0)]] var src : Buf; [[group(0), binding(1)]] var dst : [[access(read_write)]] Buf; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - [[stage(compute)]] fn main() { + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + vec4(0x1234u, 0x1234u, 0x1234u, 0x1234u); } @@ -302,9 +300,9 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPongInOnePass) { [[group(0), binding(0)]] var src : Buf; [[group(0), binding(1)]] var dst : [[access(read_write)]] Buf; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; - [[stage(compute)]] fn main() { + [[stage(compute)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + vec4(0x1234u, 0x1234u, 0x1234u, 0x1234u); } diff --git a/src/tests/end2end/CopyTextureForBrowserTests.cpp b/src/tests/end2end/CopyTextureForBrowserTests.cpp index fd03f62fa6..5a71ea6cd0 100644 --- a/src/tests/end2end/CopyTextureForBrowserTests.cpp +++ b/src/tests/end2end/CopyTextureForBrowserTests.cpp @@ -148,16 +148,16 @@ class CopyTextureForBrowserTests : public DawnTest { [[group(0), binding(1)]] var dst : texture_2d; [[group(0), binding(2)]] var output : [[access(read_write)]] OutputBuf; [[group(0), binding(3)]] var uniforms : Uniforms; - [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; fn aboutEqual(value : f32, expect : f32) -> bool { // The value diff should be smaller than the hard coded tolerance. return abs(value - expect) < 0.001; } - [[stage(compute), workgroup_size(1, 1, 1)]] fn main() { - var srcSize : vec2 = textureDimensions(src); - var dstSize : vec2 = textureDimensions(dst); - var dstTexCoord : vec2 = vec2(GlobalInvocationID.xy); - var nonCoveredColor : vec4 = + [[stage(compute), workgroup_size(1, 1, 1)]] + fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3) { + let srcSize : vec2 = textureDimensions(src); + let dstSize : vec2 = textureDimensions(dst); + let dstTexCoord : vec2 = vec2(GlobalInvocationID.xy); + let nonCoveredColor : vec4 = vec4(0.0, 1.0, 0.0, 1.0); // should be green var success : bool = true; @@ -179,8 +179,8 @@ class CopyTextureForBrowserTests : public DawnTest { srcTexCoord.y = u32(srcSize.y) - srcTexCoord.y - 1u; } - var srcColor : vec4 = textureLoad(src, vec2(srcTexCoord), 0); - var dstColor : vec4 = textureLoad(dst, vec2(dstTexCoord), 0); + let srcColor : vec4 = textureLoad(src, vec2(srcTexCoord), 0); + let dstColor : vec4 = textureLoad(dst, vec2(dstTexCoord), 0); // Not use loop and variable index format to workaround // crbug.com/tint/638. @@ -196,7 +196,7 @@ class CopyTextureForBrowserTests : public DawnTest { aboutEqual(dstColor.a, srcColor.a); } } - var outputIndex : u32 = GlobalInvocationID.y * u32(dstSize.x) + + let outputIndex : u32 = GlobalInvocationID.y * u32(dstSize.x) + GlobalInvocationID.x; if (success) { output.result[outputIndex] = 1u; diff --git a/src/tests/end2end/CreatePipelineAsyncTests.cpp b/src/tests/end2end/CreatePipelineAsyncTests.cpp index 362fc1b4e1..f65f71bd68 100644 --- a/src/tests/end2end/CreatePipelineAsyncTests.cpp +++ b/src/tests/end2end/CreatePipelineAsyncTests.cpp @@ -147,14 +147,12 @@ TEST_P(CreatePipelineAsyncTest, BasicUseOfCreateRenderPipelineAsync) { utils::ComboRenderPipelineDescriptor2 renderPipelineDescriptor; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var o_color : vec4; - [[stage(fragment)]] fn main() { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); renderPipelineDescriptor.vertex.module = vsModule; renderPipelineDescriptor.cFragment.module = fsModule; @@ -217,14 +215,12 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineFailed) { utils::ComboRenderPipelineDescriptor2 renderPipelineDescriptor; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var o_color : vec4; - [[stage(fragment)]] fn main() { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); renderPipelineDescriptor.vertex.module = vsModule; renderPipelineDescriptor.cFragment.module = fsModule; @@ -281,14 +277,12 @@ TEST_P(CreatePipelineAsyncTest, ReleaseDeviceBeforeCallbackOfCreateComputePipeli TEST_P(CreatePipelineAsyncTest, ReleaseDeviceBeforeCallbackOfCreateRenderPipelineAsync) { utils::ComboRenderPipelineDescriptor2 renderPipelineDescriptor; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var o_color : vec4; - [[stage(fragment)]] fn main() { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); renderPipelineDescriptor.vertex.module = vsModule; renderPipelineDescriptor.cFragment.module = fsModule; diff --git a/src/tests/end2end/CullingTests.cpp b/src/tests/end2end/CullingTests.cpp index ec05127fab..b23f885245 100644 --- a/src/tests/end2end/CullingTests.cpp +++ b/src/tests/end2end/CullingTests.cpp @@ -26,7 +26,7 @@ class CullingTest : public DawnTest { // 1. The top-left one is counterclockwise (CCW) // 2. The bottom-right one is clockwise (CW) pipelineDescriptor.vertex.module = utils::CreateShaderModule(device, R"( - const pos : array, 6> = array, 6>( + let pos : array, 6> = array, 6>( vec2(-1.0, 1.0), vec2(-1.0, 0.0), vec2( 0.0, 1.0), @@ -34,26 +34,20 @@ class CullingTest : public DawnTest { vec2( 1.0, 0.0), vec2( 1.0, -1.0)); - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - Position = vec4(pos[VertexIndex], 0.0, 1.0); - return; + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(pos[VertexIndex], 0.0, 1.0); })"); // FragCoord of pixel(x, y) in framebuffer coordinate is (x + 0.5, y + 0.5). And we use // RGBA8 format for the back buffer. So (FragCoord.xy - vec2(0.5)) / 255 in shader code // will make the pixel's R and G channels exactly equal to the pixel's x and y coordinates. pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4;; - [[builtin(frag_coord)]] var FragCoord : vec4; - - [[stage(fragment)]] fn main() { - fragColor = vec4( + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> [[location(0)]] vec4 { + return vec4( (FragCoord.xy - vec2(0.5, 0.5)) / vec2(255.0, 255.0), 0.0, 1.0); - return; })"); // Set culling mode and front face according to the parameters diff --git a/src/tests/end2end/D3D12CachingTests.cpp b/src/tests/end2end/D3D12CachingTests.cpp index 1295caa27c..d3328b1a2a 100644 --- a/src/tests/end2end/D3D12CachingTests.cpp +++ b/src/tests/end2end/D3D12CachingTests.cpp @@ -101,18 +101,12 @@ TEST_P(D3D12CachingTests, SameShaderNoCache) { mPersistentCache.mIsDisabled = true; wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn vertex_main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); - return; + [[stage(vertex)]] fn vertex_main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); } - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn fragment_main() { - outColor = vec4(1.0, 0.0, 0.0, 1.0); - return; + [[stage(fragment)]] fn fragment_main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); } )"); @@ -148,18 +142,12 @@ TEST_P(D3D12CachingTests, SameShaderNoCache) { // entrypoints) TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPointsPerStage) { wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn vertex_main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); - return; + [[stage(vertex)]] fn vertex_main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); } - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn fragment_main() { - outColor = vec4(1.0, 0.0, 0.0, 1.0); - return; + [[stage(fragment)]] fn fragment_main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); } )"); @@ -193,18 +181,12 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPointsPerStage) { // Modify the WGSL shader functions and make sure it doesn't hit. wgpu::ShaderModule newModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn vertex_main() { - Position = vec4(1.0, 1.0, 1.0, 1.0); - return; + [[stage(vertex)]] fn vertex_main() -> [[builtin(position)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); } - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn fragment_main() { - outColor = vec4(1.0, 1.0, 1.0, 1.0); - return; + [[stage(fragment)]] fn fragment_main() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); } )"); @@ -233,12 +215,10 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPoints) { [[stage(compute)]] fn write1() { data.data = 1u; - return; } [[stage(compute)]] fn write42() { data.data = 42u; - return; } )"); diff --git a/src/tests/end2end/D3D12VideoViewsTests.cpp b/src/tests/end2end/D3D12VideoViewsTests.cpp index dfe5af6967..d5250a1667 100644 --- a/src/tests/end2end/D3D12VideoViewsTests.cpp +++ b/src/tests/end2end/D3D12VideoViewsTests.cpp @@ -231,13 +231,14 @@ namespace { // Vertex shader used to render a sampled texture into a quad. wgpu::ShaderModule GetTestVertexShaderModule() const { return utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[location(0)]] var texCoord : vec2 ; + struct VertexOut { + [[location(0)]] texCoord : vec2 ; + [[builtin(position)]] position : vec4; + }; - [[builtin(vertex_index)]] var VertexIndex : u32; - - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOut { + let pos : array, 6> = array, 6>( vec2(-1.0, 1.0), vec2(-1.0, -1.0), vec2(1.0, -1.0), @@ -245,8 +246,10 @@ namespace { vec2(1.0, -1.0), vec2(1.0, 1.0) ); - Position = vec4(pos[VertexIndex], 0.0, 1.0); - texCoord = vec2(Position.xy * 0.5) + vec2(0.5, 0.5); + var output : VertexOut; + output.position = vec4(pos[VertexIndex], 0.0, 1.0); + output.texCoord = vec2(output.position.xy * 0.5) + vec2(0.5, 0.5); + return output; })"); } @@ -297,12 +300,10 @@ TEST_P(D3D12VideoViewsTests, NV12SampleYtoR) { [[set(0), binding(0)]] var sampler0 : sampler; [[set(0), binding(1)]] var texture : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - var y : f32 = textureSample(texture, sampler0, texCoord).r; - fragColor = vec4(y, 0.0, 0.0, 1.0); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + let y : f32 = textureSample(texture, sampler0, texCoord).r; + return vec4(y, 0.0, 0.0, 1.0); })"); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass( @@ -350,13 +351,11 @@ TEST_P(D3D12VideoViewsTests, NV12SampleUVtoRG) { [[set(0), binding(0)]] var sampler0 : sampler; [[set(0), binding(1)]] var texture : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - var u : f32 = textureSample(texture, sampler0, texCoord).r; - var v : f32 = textureSample(texture, sampler0, texCoord).g; - fragColor = vec4(u, v, 0.0, 1.0); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + let u : f32 = textureSample(texture, sampler0, texCoord).r; + let v : f32 = textureSample(texture, sampler0, texCoord).g; + return vec4(u, v, 0.0, 1.0); })"); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass( @@ -413,14 +412,12 @@ TEST_P(D3D12VideoViewsTests, NV12SampleYUVtoRGB) { [[set(0), binding(1)]] var lumaTexture : texture_2d; [[set(0), binding(2)]] var chromaTexture : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - var y : f32 = textureSample(lumaTexture, sampler0, texCoord).r; - var u : f32 = textureSample(chromaTexture, sampler0, texCoord).r; - var v : f32 = textureSample(chromaTexture, sampler0, texCoord).g; - fragColor = vec4(y, u, v, 1.0); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + let y : f32 = textureSample(lumaTexture, sampler0, texCoord).r; + let u : f32 = textureSample(chromaTexture, sampler0, texCoord).r; + let v : f32 = textureSample(chromaTexture, sampler0, texCoord).g; + return vec4(y, u, v, 1.0); })"); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass( diff --git a/src/tests/end2end/DeprecatedAPITests.cpp b/src/tests/end2end/DeprecatedAPITests.cpp index 9d95bad3a8..a7c8c0bf9e 100644 --- a/src/tests/end2end/DeprecatedAPITests.cpp +++ b/src/tests/end2end/DeprecatedAPITests.cpp @@ -497,20 +497,14 @@ class VertexFormatDeprecationTests : public DeprecationTests { : "vec4(f32(a), 0.0, 0.0, 1.0)"; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, (attribute + R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - Position = )" + attribAccess + R"(; - return; + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return )" + attribAccess + R"(; } )") .c_str()); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn main() { - outColor = vec4(1.0, 1.0, 1.0, 1.0); - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); } )"); diff --git a/src/tests/end2end/DepthBiasTests.cpp b/src/tests/end2end/DepthBiasTests.cpp index 5cc22d6ba3..6ce037e021 100644 --- a/src/tests/end2end/DepthBiasTests.cpp +++ b/src/tests/end2end/DepthBiasTests.cpp @@ -36,36 +36,32 @@ class DepthBiasTests : public DawnTest { case QuadAngle::Flat: // Draw a square at z = 0.25 vertexSource = R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2(-1.0, -1.0), vec2( 1.0, -1.0), vec2(-1.0, 1.0), vec2(-1.0, 1.0), vec2( 1.0, -1.0), vec2( 1.0, 1.0)); - Position = vec4(pos[VertexIndex], 0.25, 1.0); - return; + return vec4(pos[VertexIndex], 0.25, 1.0); })"; break; case QuadAngle::TiltedX: // Draw a square ranging from 0 to 0.5, bottom to top vertexSource = R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec3(-1.0, -1.0, 0.0), vec3( 1.0, -1.0, 0.0), vec3(-1.0, 1.0, 0.5), vec3(-1.0, 1.0, 0.5), vec3( 1.0, -1.0, 0.0), vec3( 1.0, 1.0, 0.5)); - Position = vec4(pos[VertexIndex], 1.0); - return; + return vec4(pos[VertexIndex], 1.0); })"; break; } @@ -73,10 +69,8 @@ class DepthBiasTests : public DawnTest { wgpu::ShaderModule vertexModule = utils::CreateShaderModule(device, vertexSource); wgpu::ShaderModule fragmentModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4;; - [[stage(fragment)]] fn main() { - fragColor = vec4(1.0, 0.0, 0.0, 1.0); - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); })"); { diff --git a/src/tests/end2end/DepthStencilCopyTests.cpp b/src/tests/end2end/DepthStencilCopyTests.cpp index 166a9260be..b585133543 100644 --- a/src/tests/end2end/DepthStencilCopyTests.cpp +++ b/src/tests/end2end/DepthStencilCopyTests.cpp @@ -29,18 +29,16 @@ class DepthStencilCopyTests : public DawnTest { // Draw a square in the bottom left quarter of the screen. mVertexModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2(-1.0, -1.0), vec2( 0.0, -1.0), vec2(-1.0, 0.0), vec2(-1.0, 0.0), vec2( 0.0, -1.0), vec2( 0.0, 0.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); } @@ -74,9 +72,8 @@ class DepthStencilCopyTests : public DawnTest { desc->vertex.module = mVertexModule; std::string fsSource = R"( - [[builtin(frag_depth)]] var FragDepth : f32; - [[stage(fragment)]] fn main() { - FragDepth = )" + std::to_string(regionDepth) + + [[stage(fragment)]] fn main() -> [[builtin(frag_depth)]] f32 { + return )" + std::to_string(regionDepth) + ";\n}"; desc->cFragment.module = utils::CreateShaderModule(device, fsSource.c_str()); @@ -239,29 +236,31 @@ class DepthStencilCopyTests : public DawnTest { utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; pipelineDescriptor.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, -1.0), vec2( 3.0, -1.0), vec2(-1.0, 3.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); // Sample the input texture and write out depth. |result| will only be set to 1 if we // pass the depth test. pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var texture0 : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; - [[location(0)]] var result : u32; - [[builtin(frag_depth)]] var FragDepth : f32; + struct FragmentOut { + [[location(0)]] result : u32; + [[builtin(frag_depth)]] fragDepth : f32; + }; - [[stage(fragment)]] fn main() { - result = 1u; - FragDepth = textureLoad(texture0, vec2(FragCoord.xy), 0)[0]; + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> FragmentOut { + var output : FragmentOut; + output.result = 1u; + output.fragDepth = textureLoad(texture0, vec2(FragCoord.xy), 0)[0]; + return output; })"); // Pass the depth test only if the depth is equal. diff --git a/src/tests/end2end/DepthStencilSamplingTests.cpp b/src/tests/end2end/DepthStencilSamplingTests.cpp index 28274d539f..c03349b838 100644 --- a/src/tests/end2end/DepthStencilSamplingTests.cpp +++ b/src/tests/end2end/DepthStencilSamplingTests.cpp @@ -66,9 +66,8 @@ class DepthStencilSamplingTest : public DawnTest { wgpu::RenderPipeline CreateSamplingRenderPipeline(std::vector aspects, uint32_t componentIndex) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; @@ -173,9 +172,8 @@ class DepthStencilSamplingTest : public DawnTest { wgpu::RenderPipeline CreateComparisonRenderPipeline() { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -186,10 +184,8 @@ class DepthStencilSamplingTest : public DawnTest { }; [[group(0), binding(2)]] var uniforms : Uniforms; - [[location(0)]] var samplerResult : f32; - - [[stage(fragment)]] fn main() { - samplerResult = textureSampleCompare(tex, samp, vec2(0.5, 0.5), uniforms.compareRef); + [[stage(fragment)]] fn main() -> [[location(0)]] f32 { + return textureSampleCompare(tex, samp, vec2(0.5, 0.5), uniforms.compareRef); })"); // TODO(dawn:367): Cannot use GetBindGroupLayout for comparison samplers without shader diff --git a/src/tests/end2end/DepthStencilStateTests.cpp b/src/tests/end2end/DepthStencilStateTests.cpp index 0c011434e7..dbd118deda 100644 --- a/src/tests/end2end/DepthStencilStateTests.cpp +++ b/src/tests/end2end/DepthStencilStateTests.cpp @@ -61,18 +61,17 @@ class DepthStencilStateTest : public DawnTest { depth : f32; }; [[group(0), binding(0)]] var ubo : UBO; - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2(-1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0), // front-facing vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0)); // back-facing - Position = vec4(pos[VertexIndex], ubo.depth, 1.0); + return vec4(pos[VertexIndex], ubo.depth, 1.0); })"); fsModule = utils::CreateShaderModule(device, R"( @@ -82,10 +81,8 @@ class DepthStencilStateTest : public DawnTest { }; [[group(0), binding(0)]] var ubo : UBO; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = vec4(ubo.color, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(ubo.color, 1.0); })"); } diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp index eaa7b7f84d..88bf140a3f 100644 --- a/src/tests/end2end/DestroyTests.cpp +++ b/src/tests/end2end/DestroyTests.cpp @@ -28,16 +28,14 @@ class DestroyTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/DeviceLostTests.cpp b/src/tests/end2end/DeviceLostTests.cpp index 3055e008c1..d420a0a559 100644 --- a/src/tests/end2end/DeviceLostTests.cpp +++ b/src/tests/end2end/DeviceLostTests.cpp @@ -212,10 +212,9 @@ TEST_P(DeviceLostTest, CreateShaderModuleFails) { SetCallbackAndLoseForTesting(); ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, R"( - [[location(0)]] var color : vec4; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = color; + [[stage(fragment)]] + fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; })")); } diff --git a/src/tests/end2end/DrawIndexedIndirectTests.cpp b/src/tests/end2end/DrawIndexedIndirectTests.cpp index 0da508f7df..55702abe78 100644 --- a/src/tests/end2end/DrawIndexedIndirectTests.cpp +++ b/src/tests/end2end/DrawIndexedIndirectTests.cpp @@ -27,16 +27,14 @@ class DrawIndexedIndirectTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/DrawIndexedTests.cpp b/src/tests/end2end/DrawIndexedTests.cpp index 3c696ac927..3d3cf24f0e 100644 --- a/src/tests/end2end/DrawIndexedTests.cpp +++ b/src/tests/end2end/DrawIndexedTests.cpp @@ -27,16 +27,14 @@ class DrawIndexedTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/DrawIndirectTests.cpp b/src/tests/end2end/DrawIndirectTests.cpp index 4887f7a260..8cb9e57204 100644 --- a/src/tests/end2end/DrawIndirectTests.cpp +++ b/src/tests/end2end/DrawIndirectTests.cpp @@ -27,16 +27,14 @@ class DrawIndirectTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/DrawTests.cpp b/src/tests/end2end/DrawTests.cpp index dc30a55112..eefd43ebb1 100644 --- a/src/tests/end2end/DrawTests.cpp +++ b/src/tests/end2end/DrawTests.cpp @@ -27,16 +27,14 @@ class DrawTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/DynamicBufferOffsetTests.cpp b/src/tests/end2end/DynamicBufferOffsetTests.cpp index afabe47e64..6f557ffbd1 100644 --- a/src/tests/end2end/DynamicBufferOffsetTests.cpp +++ b/src/tests/end2end/DynamicBufferOffsetTests.cpp @@ -94,14 +94,13 @@ class DynamicBufferOffsetTests : public DawnTest { wgpu::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 0.0), vec2(-1.0, 1.0), vec2( 0.0, 1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); // Construct fragment shader source @@ -141,14 +140,12 @@ class DynamicBufferOffsetTests : public DawnTest { )"; } - fs << "[[location(0)]] var fragColor : vec4;\n"; - - fs << "const multipleNumber : u32 = " << multipleNumber << "u;\n"; + fs << "let multipleNumber : u32 = " << multipleNumber << "u;\n"; fs << R"( - [[stage(fragment)]] fn main() { + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { sBufferNotDynamic.value = uBufferNotDynamic.value.xy; sBuffer.value = vec2(multipleNumber, multipleNumber) * (uBuffer.value.xy + sBufferNotDynamic.value.xy); - fragColor = vec4(f32(uBuffer.value.x) / 255.0, f32(uBuffer.value.y) / 255.0, + return vec4(f32(uBuffer.value.x) / 255.0, f32(uBuffer.value.y) / 255.0, 1.0, 1.0); } )"; @@ -210,7 +207,7 @@ class DynamicBufferOffsetTests : public DawnTest { )"; } - cs << "const multipleNumber : u32 = " << multipleNumber << "u;\n"; + cs << "let multipleNumber : u32 = " << multipleNumber << "u;\n"; cs << R"( [[stage(compute)]] fn main() { sBufferNotDynamic.value = uBufferNotDynamic.value.xy; diff --git a/src/tests/end2end/EntryPointTests.cpp b/src/tests/end2end/EntryPointTests.cpp index f0bd0622cc..e27390d697 100644 --- a/src/tests/end2end/EntryPointTests.cpp +++ b/src/tests/end2end/EntryPointTests.cpp @@ -24,18 +24,12 @@ TEST_P(EntryPointTests, FragAndVertexSameModule) { // TODO(crbug.com/dawn/658): Crashes on bots DAWN_SKIP_TEST_IF(IsOpenGL() || IsOpenGLES()); wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn vertex_main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); - return; + [[stage(vertex)]] fn vertex_main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); } - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn fragment_main() { - outColor = vec4(1.0, 0.0, 0.0, 1.0); - return; + [[stage(fragment)]] fn fragment_main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); } )"); diff --git a/src/tests/end2end/FirstIndexOffsetTests.cpp b/src/tests/end2end/FirstIndexOffsetTests.cpp index d64b926e91..46d2d6b1aa 100644 --- a/src/tests/end2end/FirstIndexOffsetTests.cpp +++ b/src/tests/end2end/FirstIndexOffsetTests.cpp @@ -121,7 +121,7 @@ void FirstIndexOffsetTests::TestImpl(DrawMode mode, [[group(0), binding(0)]] var idx_vals : [[access(read_write)]] IndexVals; - [[stage(fragment)]] fn main() { + [[stage(fragment)]] fn main() { )"; if ((checkIndex & CheckIndex::Vertex) != 0) { diff --git a/src/tests/end2end/GpuMemorySynchronizationTests.cpp b/src/tests/end2end/GpuMemorySynchronizationTests.cpp index fe768b5d0f..674eb6f47d 100644 --- a/src/tests/end2end/GpuMemorySynchronizationTests.cpp +++ b/src/tests/end2end/GpuMemorySynchronizationTests.cpp @@ -58,9 +58,8 @@ class GpuMemorySyncTests : public DawnTest { const wgpu::Buffer& buffer, wgpu::TextureFormat colorFormat) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -68,10 +67,9 @@ class GpuMemorySyncTests : public DawnTest { i : i32; }; [[group(0), binding(0)]] var data : [[access(read_write)]] Data; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { data.i = data.i + 1; - fragColor = vec4(f32(data.i) / 255.0, 0.0, 0.0, 1.0); + return vec4(f32(data.i) / 255.0, 0.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 rpDesc; @@ -335,9 +333,8 @@ class StorageToUniformSyncTests : public DawnTest { std::tuple CreatePipelineAndBindGroupForRender( wgpu::TextureFormat colorFormat) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -346,9 +343,8 @@ class StorageToUniformSyncTests : public DawnTest { }; [[group(0), binding(0)]] var contents : Contents; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(contents.color, 0.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(contents.color, 0.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 rpDesc; @@ -538,7 +534,7 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) { vbContents.pos[1] = vec4(1.0, 1.0, 0.0, 1.0); vbContents.pos[2] = vec4(1.0, -1.0, 0.0, 1.0); vbContents.pos[3] = vec4(-1.0, -1.0, 0.0, 1.0); - const dummy : i32 = 0; + let dummy : i32 = 0; ibContents.indices[0] = vec4(0, 1, 2, 0); ibContents.indices[1] = vec4(2, 3, dummy, dummy); uniformContents.color = 1.0; @@ -574,10 +570,9 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) { // Create pipeline, bind group, and reuse buffers in render pass. wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position: vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -588,9 +583,8 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) { [[group(0), binding(0)]] var uniformBuffer : Buf; [[group(0), binding(1)]] var storageBuffer : [[access(read)]] Buf; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(uniformBuffer.color, storageBuffer.color, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(uniformBuffer.color, storageBuffer.color, 0.0, 1.0); })"); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); @@ -655,7 +649,7 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) { contents.pos[1] = vec4(1.0, 1.0, 0.0, 1.0); contents.pos[2] = vec4(1.0, -1.0, 0.0, 1.0); contents.pos[3] = vec4(-1.0, -1.0, 0.0, 1.0); - const dummy : i32 = 0; + let dummy : i32 = 0; contents.indices[0] = vec4(0, 1, 2, 0); contents.indices[1] = vec4(2, 3, dummy, dummy); contents.color0 = 1.0; @@ -692,10 +686,9 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) { // Create pipeline, bind group, and reuse the buffer in render pass. wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( @@ -705,9 +698,8 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) { [[group(0), binding(0)]] var uniformBuffer : Buf; [[group(0), binding(1)]] var storageBuffer : [[access(read)]] Buf; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(uniformBuffer.color, storageBuffer.color, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(uniformBuffer.color, storageBuffer.color, 0.0, 1.0); })"); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); diff --git a/src/tests/end2end/IOSurfaceWrappingTests.cpp b/src/tests/end2end/IOSurfaceWrappingTests.cpp index 74a060ab5b..df9417c6d9 100644 --- a/src/tests/end2end/IOSurfaceWrappingTests.cpp +++ b/src/tests/end2end/IOSurfaceWrappingTests.cpp @@ -248,12 +248,14 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase { wgpu::RenderPipeline pipeline; { wgpu::ShaderModule vs = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[location(0)]] var o_texCoord : vec2; - [[builtin(position)]] var Position : vec4; + struct VertexOut { + [[location(0)]] texCoord : vec2; + [[builtin(position)]] position : vec4; + }; - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOut { + let pos : array, 6> = array, 6>( vec2(-2.0, -2.0), vec2(-2.0, 2.0), vec2( 2.0, -2.0), @@ -261,7 +263,7 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase { vec2( 2.0, -2.0), vec2( 2.0, 2.0)); - const texCoord : array, 6> = array, 6>( + let texCoord : array, 6> = array, 6>( vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 0.0), @@ -269,19 +271,19 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase { vec2(1.0, 0.0), vec2(1.0, 1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); - o_texCoord = texCoord[VertexIndex]; + var output : VertexOut; + output.position = vec4(pos[VertexIndex], 0.0, 1.0); + output.texCoord = texCoord[VertexIndex]; + return output; } )"); wgpu::ShaderModule fs = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, texCoord); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, texCoord); } )"); diff --git a/src/tests/end2end/IndexFormatTests.cpp b/src/tests/end2end/IndexFormatTests.cpp index 9c9ff198c7..ae4a12e07e 100644 --- a/src/tests/end2end/IndexFormatTests.cpp +++ b/src/tests/end2end/IndexFormatTests.cpp @@ -33,22 +33,22 @@ class IndexFormatTest : public DawnTest { wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format, wgpu::PrimitiveTopology primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(vertex_index)]] var idx : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { + struct VertexIn { + [[location(0)]] pos : vec4; + [[builtin(vertex_index)]] idx : u32; + }; + + [[stage(vertex)]] fn main(input : VertexIn) -> [[builtin(position)]] vec4 { // 0xFFFFFFFE is a designated invalid index used by some tests. - if (idx == 0xFFFFFFFEu) { - Position = vec4(0.0, 0.0, 0.0, 1.0); - } else { - Position = pos; + if (input.idx == 0xFFFFFFFEu) { + return vec4(0.0, 0.0, 0.0, 1.0); } + return input.pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/MultisampledRenderingTests.cpp b/src/tests/end2end/MultisampledRenderingTests.cpp index 5d1968db4e..3fae96232e 100644 --- a/src/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/tests/end2end/MultisampledRenderingTests.cpp @@ -50,12 +50,17 @@ class MultisampledRenderingTest : public DawnTest { depth : f32; }; [[group(0), binding(0)]] var uBuffer : U; - [[location(0)]] var FragColor : vec4; - [[builtin(frag_depth)]] var FragDepth : f32; - [[stage(fragment)]] fn main() { - FragColor = uBuffer.color; - FragDepth = uBuffer.depth; + struct FragmentOut { + [[location(0)]] color : vec4; + [[builtin(frag_depth)]] depth : f32; + }; + + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.color = uBuffer.color; + output.depth = uBuffer.depth; + return output; })"; const char* kFsOneOutputWithoutDepth = R"( @@ -63,10 +68,9 @@ class MultisampledRenderingTest : public DawnTest { color : vec4; }; [[group(0), binding(0)]] var uBuffer : U; - [[location(0)]] var FragColor : vec4; - [[stage(fragment)]] fn main() { - FragColor = uBuffer.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return uBuffer.color; })"; const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth; @@ -84,12 +88,17 @@ class MultisampledRenderingTest : public DawnTest { color1 : vec4; }; [[group(0), binding(0)]] var uBuffer : U; - [[location(0)]] var FragColor0 : vec4; - [[location(1)]] var FragColor1 : vec4; - [[stage(fragment)]] fn main() { - FragColor0 = uBuffer.color0; - FragColor1 = uBuffer.color1; + struct FragmentOut { + [[location(0)]] color0 : vec4; + [[location(1)]] color1 : vec4; + }; + + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.color0 = uBuffer.color0; + output.color1 = uBuffer.color1; + return output; })"; return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false, sampleMask, @@ -214,30 +223,26 @@ class MultisampledRenderingTest : public DawnTest { // Draw a bottom-right triangle. In standard 4xMSAA pattern, for the pixels on diagonal, // only two of the samples will be touched. const char* vs = R"( - [[builtin(position)]] var Position : vec4; - [[builtin(vertex_index)]] var VertexIndex : u32; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0) ); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"; // Draw a bottom-left triangle. const char* vsFlipped = R"( - [[builtin(position)]] var Position : vec4; - [[builtin(vertex_index)]] var VertexIndex : u32; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2(-1.0, -1.0) ); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"; if (flipTriangle) { @@ -776,12 +781,17 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut color : vec4; }; [[group(0), binding(0)]] var uBuffer : U; - [[location(0)]] var FragColor : vec4; - [[builtin(sample_mask_out)]] var SampleMask : u32; - [[stage(fragment)]] fn main() { - FragColor = uBuffer.color; - SampleMask = 6u; + struct FragmentOut { + [[location(0)]] color : vec4; + [[builtin(sample_mask_out)]] sampleMask : u32; + }; + + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.color = uBuffer.color; + output.sampleMask = 6u; + return output; })"; wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 1, false, kSampleMask); @@ -833,14 +843,19 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargetsWithShaderOut color1 : vec4; }; [[group(0), binding(0)]] var uBuffer : U; - [[location(0)]] var FragColor0 : vec4; - [[location(1)]] var FragColor1 : vec4; - [[builtin(sample_mask_out)]] var SampleMask : u32; - [[stage(fragment)]] fn main() { - FragColor0 = uBuffer.color0; - FragColor1 = uBuffer.color1; - SampleMask = 6u; + struct FragmentOut { + [[location(0)]] color0 : vec4; + [[location(1)]] color1 : vec4; + [[builtin(sample_mask_out)]] sampleMask : u32; + }; + + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.color0 = uBuffer.color0; + output.color1 = uBuffer.color1; + output.sampleMask = 6u; + return output; })"; wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 2, false); diff --git a/src/tests/end2end/MultisampledSamplingTests.cpp b/src/tests/end2end/MultisampledSamplingTests.cpp index cfa53070ee..5fec69fc98 100644 --- a/src/tests/end2end/MultisampledSamplingTests.cpp +++ b/src/tests/end2end/MultisampledSamplingTests.cpp @@ -54,18 +54,22 @@ class MultisampledSamplingTest : public DawnTest { utils::ComboRenderPipelineDescriptor2 desc; desc.vertex.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec2; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(pos, 0.0, 1.0); + [[stage(vertex)]] + fn main([[location(0)]] pos : vec2) -> [[builtin(position)]] vec4 { + return vec4(pos, 0.0, 1.0); })"); desc.cFragment.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : f32; - [[builtin(frag_depth)]] var FragDepth : f32; - [[stage(fragment)]] fn main() { - fragColor = 1.0; - FragDepth = 0.7; + struct FragmentOut { + [[location(0)]] color : f32; + [[builtin(frag_depth)]] depth : f32; + }; + + [[stage(fragment)]] fn main() -> FragmentOut { + var output : FragmentOut; + output.color = 1.0; + output.depth = 0.7; + return output; })"); desc.primitive.stripIndexFormat = wgpu::IndexFormat::Uint32; diff --git a/src/tests/end2end/ObjectCachingTests.cpp b/src/tests/end2end/ObjectCachingTests.cpp index 3be9e998f6..630437cc7e 100644 --- a/src/tests/end2end/ObjectCachingTests.cpp +++ b/src/tests/end2end/ObjectCachingTests.cpp @@ -104,19 +104,16 @@ TEST_P(ObjectCachingTest, PipelineLayoutDeduplication) { // Test that ShaderModules are correctly deduplicated. TEST_P(ObjectCachingTest, ShaderModuleDeduplication) { wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); wgpu::ShaderModule sameModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); wgpu::ShaderModule otherModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); EXPECT_NE(module.Get(), otherModule.Get()); @@ -212,9 +209,8 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) { utils::ComboRenderPipelineDescriptor2 desc; desc.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); desc.cFragment.module = utils::CreateShaderModule(device, R"( [[stage(fragment)]] fn main() { @@ -236,19 +232,16 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnLayout) { // Test that RenderPipelines are correctly deduplicated wrt. their vertex module TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnVertexModule) { wgpu::ShaderModule module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); wgpu::ShaderModule sameModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); wgpu::ShaderModule otherModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(1.0, 1.0, 1.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); })"); EXPECT_NE(module.Get(), otherModule.Get()); @@ -281,9 +274,8 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) { [[stage(fragment)]] fn main() { })"); wgpu::ShaderModule otherModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); EXPECT_NE(module.Get(), otherModule.Get()); @@ -291,9 +283,8 @@ TEST_P(ObjectCachingTest, RenderPipelineDeduplicationOnFragmentModule) { utils::ComboRenderPipelineDescriptor2 desc; desc.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 0.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 0.0); })"); desc.cFragment.module = module; diff --git a/src/tests/end2end/OpArrayLengthTests.cpp b/src/tests/end2end/OpArrayLengthTests.cpp index efc02fed5a..f8f13e0200 100644 --- a/src/tests/end2end/OpArrayLengthTests.cpp +++ b/src/tests/end2end/OpArrayLengthTests.cpp @@ -165,18 +165,18 @@ TEST_P(OpArrayLengthTest, Fragment) { // Create the pipeline that computes the length of the buffers and writes it to the only render // pass pixel. wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, (mShaderInterface + R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + var fragColor : vec4; fragColor.r = f32(arrayLength(buffer1.data)) / 255.0; fragColor.g = f32(arrayLength(buffer2.data)) / 255.0; fragColor.b = f32(arrayLength(buffer3.data)) / 255.0; fragColor.a = 0.0; + return fragColor; })") .c_str()); @@ -218,23 +218,27 @@ TEST_P(OpArrayLengthTest, Vertex) { // Create the pipeline that computes the length of the buffers and writes it to the only render // pass pixel. wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, (mShaderInterface + R"( - [[location(0)]] var pointColor : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - pointColor.r = f32(arrayLength(buffer1.data)) / 255.0; - pointColor.g = f32(arrayLength(buffer2.data)) / 255.0; - pointColor.b = f32(arrayLength(buffer3.data)) / 255.0; - pointColor.a = 0.0; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> VertexOut { + var output : VertexOut; + output.color.r = f32(arrayLength(buffer1.data)) / 255.0; + output.color.g = f32(arrayLength(buffer2.data)) / 255.0; + output.color.b = f32(arrayLength(buffer3.data)) / 255.0; + output.color.a = 0.0; + + output.position = vec4(0.0, 0.0, 0.0, 1.0); + return output; })") .c_str()); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[location(0)]] var pointColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = pointColor; + [[stage(fragment)]] + fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/PrimitiveStateTests.cpp b/src/tests/end2end/PrimitiveStateTests.cpp index 470f5aeefe..6b67390ad7 100644 --- a/src/tests/end2end/PrimitiveStateTests.cpp +++ b/src/tests/end2end/PrimitiveStateTests.cpp @@ -50,10 +50,9 @@ class DepthClampingTest : public DawnTest { depth : f32; }; [[group(0), binding(0)]] var ubo : UBO; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, ubo.depth, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, ubo.depth, 1.0); })"); fsModule = utils::CreateShaderModule(device, R"( @@ -63,10 +62,8 @@ class DepthClampingTest : public DawnTest { }; [[group(0), binding(0)]] var ubo : UBO; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = vec4(ubo.color, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(ubo.color, 1.0); })"); } diff --git a/src/tests/end2end/PrimitiveTopologyTests.cpp b/src/tests/end2end/PrimitiveTopologyTests.cpp index 155987c837..adb7dc6c34 100644 --- a/src/tests/end2end/PrimitiveTopologyTests.cpp +++ b/src/tests/end2end/PrimitiveTopologyTests.cpp @@ -154,16 +154,14 @@ class PrimitiveTopologyTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices), diff --git a/src/tests/end2end/QueryTests.cpp b/src/tests/end2end/QueryTests.cpp index 746ba59463..c09a921bd6 100644 --- a/src/tests/end2end/QueryTests.cpp +++ b/src/tests/end2end/QueryTests.cpp @@ -81,20 +81,18 @@ class OcclusionQueryTests : public QueryTests { // Create basic render pipeline vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2( 1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/RenderBundleTests.cpp b/src/tests/end2end/RenderBundleTests.cpp index 74a489da13..d1ddb164e1 100644 --- a/src/tests/end2end/RenderBundleTests.cpp +++ b/src/tests/end2end/RenderBundleTests.cpp @@ -32,21 +32,19 @@ class RenderBundleTest : public DawnTest { renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var pos : vec4; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = pos; + [[stage(vertex)]] + fn main([[location(0)]] pos : vec4) -> [[builtin(position)]] vec4 { + return pos; })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; [[block]] struct Ubo { color : vec4; }; [[group(0), binding(0)]] var fragmentUniformBuffer : Ubo; - [[stage(fragment)]] fn main() { - fragColor = fragmentUniformBuffer.color; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return fragmentUniformBuffer.color; })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp index 6193b529cb..f6dc853292 100644 --- a/src/tests/end2end/RenderPassLoadOpTests.cpp +++ b/src/tests/end2end/RenderPassLoadOpTests.cpp @@ -77,11 +77,9 @@ class RenderPassLoadOpTests : public DawnTest { // draws a blue quad on the right half of the screen const char* vsSource = R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2( 0.0, -1.0), vec2( 1.0, -1.0), vec2( 0.0, 1.0), @@ -89,13 +87,12 @@ class RenderPassLoadOpTests : public DawnTest { vec2( 1.0, -1.0), vec2( 1.0, 1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"; const char* fsSource = R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 0.0, 1.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 0.0, 1.0, 1.0); })"; blueQuad = DrawQuad(device, vsSource, fsSource); } diff --git a/src/tests/end2end/RenderPassTests.cpp b/src/tests/end2end/RenderPassTests.cpp index e262403fcd..896f3d5ee1 100644 --- a/src/tests/end2end/RenderPassTests.cpp +++ b/src/tests/end2end/RenderPassTests.cpp @@ -27,22 +27,19 @@ class RenderPassTest : public DawnTest { // Shaders to draw a bottom-left triangle in blue. mVSModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2( 1.0, -1.0), vec2(-1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 0.0, 1.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 0.0, 1.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/SamplerFilterAnisotropicTests.cpp b/src/tests/end2end/SamplerFilterAnisotropicTests.cpp index 4487396778..3cc3f117a3 100644 --- a/src/tests/end2end/SamplerFilterAnisotropicTests.cpp +++ b/src/tests/end2end/SamplerFilterAnisotropicTests.cpp @@ -42,31 +42,38 @@ class SamplerFilterAnisotropicTest : public DawnTest { matrix : mat4x4; }; - [[location(0)]] var position : vec4; - [[location(1)]] var uv : vec2; + struct VertexIn { + [[location(0)]] position : vec4; + [[location(1)]] uv : vec2; + }; [[group(0), binding(2)]] var uniforms : Uniforms; - [[builtin(position)]] var Position : vec4; - [[location(0)]] var fragUV : vec2; + struct VertexOut { + [[location(0)]] uv : vec2; + [[builtin(position)]] position : vec4; + }; - [[stage(vertex)]] fn main() { - fragUV = uv; - Position = uniforms.matrix * position; + [[stage(vertex)]] + fn main(input : VertexIn) -> VertexOut { + var output : VertexOut; + output.uv = input.uv; + output.position = uniforms.matrix * input.position; + return output; } )"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; + struct FragmentIn { + [[location(0)]] uv: vec2; + [[builtin(frag_coord)]] fragCoord : vec4; + }; - [[location(0)]] var fragUV: vec2; - - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, fragUV); + [[stage(fragment)]] + fn main(input : FragmentIn) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, input.uv); })"); utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; diff --git a/src/tests/end2end/SamplerTests.cpp b/src/tests/end2end/SamplerTests.cpp index fe10de2d0d..ca031fbdfc 100644 --- a/src/tests/end2end/SamplerTests.cpp +++ b/src/tests/end2end/SamplerTests.cpp @@ -55,30 +55,25 @@ class SamplerTest : public DawnTest { mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); auto vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2(-2.0, -2.0), vec2(-2.0, 2.0), vec2( 2.0, -2.0), vec2(-2.0, 2.0), vec2( 2.0, -2.0), vec2( 2.0, 2.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); } )"); auto fsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; - - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, FragCoord.xy / vec2(2.0, 2.0)); + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, FragCoord.xy / vec2(2.0, 2.0)); })"); utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; diff --git a/src/tests/end2end/ScissorTests.cpp b/src/tests/end2end/ScissorTests.cpp index 993ae41a38..b3bcf392ae 100644 --- a/src/tests/end2end/ScissorTests.cpp +++ b/src/tests/end2end/ScissorTests.cpp @@ -21,10 +21,7 @@ class ScissorTest : public DawnTest { protected: wgpu::RenderPipeline CreateQuadPipeline(wgpu::TextureFormat format) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - const pos : array, 6> = array, 6>( + let pos : array, 6> = array, 6>( vec2(-1.0, -1.0), vec2(-1.0, 1.0), vec2( 1.0, -1.0), @@ -32,14 +29,14 @@ class ScissorTest : public DawnTest { vec2(-1.0, 1.0), vec2( 1.0, -1.0)); - [[stage(vertex)]] fn main() { - Position = vec4(pos[VertexIndex], 0.5, 1.0); + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(pos[VertexIndex], 0.5, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/ShaderTests.cpp b/src/tests/end2end/ShaderTests.cpp index 08e6efdd2f..cdc9abe9b4 100644 --- a/src/tests/end2end/ShaderTests.cpp +++ b/src/tests/end2end/ShaderTests.cpp @@ -38,7 +38,7 @@ TEST_P(ShaderTests, ComputeLog2) { [[group(0), binding(0)]] var buf : [[access(read_write)]] Buf; [[stage(compute)]] fn main() { - const factor : f32 = 1.0001; + let factor : f32 = 1.0001; buf.data[0] = u32(log2(1.0 * factor)); buf.data[1] = u32(log2(2.0 * factor)); diff --git a/src/tests/end2end/StorageTextureTests.cpp b/src/tests/end2end/StorageTextureTests.cpp index 9a2e86cb75..e6a1744af0 100644 --- a/src/tests/end2end/StorageTextureTests.cpp +++ b/src/tests/end2end/StorageTextureTests.cpp @@ -273,7 +273,7 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { // On Windows Intel drivers the tests will fail if tolerance <= 0.00000001f. return R"( fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { - const tolerance : f32 = 0.0000001; + let tolerance : f32 = 0.0000001; return all(abs(pixel - expected) < vec4(tolerance, tolerance, tolerance, tolerance)); })"; @@ -297,7 +297,7 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { << GetComparisonFunction(format) << "\n"; ostream << "fn doTest() -> bool {\n"; ostream << " var size : vec2 = textureDimensions(storageImage0);\n"; - ostream << " const layerCount : i32 = " << layerCount << ";\n"; + ostream << " let layerCount : i32 = " << layerCount << ";\n"; ostream << " for (var layer : i32 = 0; layer < layerCount; layer = layer + 1) {\n"; ostream << " for (var y : i32 = 0; y < size.y; y = y + 1) {\n"; ostream << " for (var x : i32 = 0; x < size.x; x = x + 1) {\n"; @@ -331,8 +331,8 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { ostream << GetImageDeclaration(format, "write", is2DArray, 0) << "\n"; ostream << "[[stage(" << stage << ")]]\n"; ostream << "fn main() {\n"; - ostream << " var size : vec2 = textureDimensions(storageImage0);\n"; - ostream << " const layerCount : i32 = " << layerCount << ";\n"; + ostream << " let size : vec2 = textureDimensions(storageImage0);\n"; + ostream << " let layerCount : i32 = " << layerCount << ";\n"; ostream << " for (var layer : i32 = 0; layer < layerCount; layer = layer + 1) {\n"; ostream << " for (var y : i32 = 0; y < size.y; y = y + 1) {\n"; ostream << " for (var x : i32 = 0; x < size.x; x = x + 1) {\n"; @@ -359,8 +359,8 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { ostream << GetImageDeclaration(format, "write", is2DArray, 0) << "\n"; ostream << GetImageDeclaration(format, "read", is2DArray, 1) << "\n"; ostream << "[[stage(compute)]] fn main() {\n"; - ostream << " var size : vec2 = textureDimensions(storageImage0);\n"; - ostream << " const layerCount : i32 = " << layerCount << ";\n"; + ostream << " let size : vec2 = textureDimensions(storageImage0);\n"; + ostream << " let layerCount : i32 = " << layerCount << ";\n"; ostream << " for (var layer : i32 = 0; layer < layerCount; layer = layer + 1) {\n"; ostream << " for (var y : i32 = 0; y < size.y; y = y + 1) {\n"; ostream << " for (var x : i32 = 0; x < size.x; x = x + 1) {\n"; @@ -648,9 +648,9 @@ fn IsEqualTo(pixel : vec4, expected : vec4) -> bool { static constexpr wgpu::TextureFormat kRenderAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; const char* kSimpleVertexShader = R"( -[[builtin(position)]] var position : vec4; -[[stage(vertex)]] fn main() { - position = vec4(0.0, 0.0, 0.0, 1.0); +; +[[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"; const char* kComputeExpectedValue = "1 + x + size.x * (y + size.y * layer)"; @@ -746,23 +746,26 @@ TEST_P(StorageTextureTests, ReadonlyStorageTextureInVertexShader) { // uses green as the output color, otherwise uses red instead. std::ostringstream vsStream; vsStream << R"( -[[builtin(position)]] var position : vec4; -[[location(0)]] var o_color : vec4; +struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; +}; )" << CommonReadOnlyTestCode(format) << R"( -[[stage(vertex)]] fn main() { - position = vec4(0.0, 0.0, 0.0, 1.0); +[[stage(vertex)]] fn main() -> VertexOut { + var output : VertexOut; + output.position = vec4(0.0, 0.0, 0.0, 1.0); if (doTest()) { - o_color = vec4(0.0, 1.0, 0.0, 1.0); + output.color = vec4(0.0, 1.0, 0.0, 1.0); } else { - o_color = vec4(1.0, 0.0, 0.0, 1.0); + output.color = vec4(1.0, 0.0, 0.0, 1.0); } + return output; })"; const char* kFragmentShader = R"( -[[location(0)]] var o_color : vec4; -[[location(0)]] var fragColor : vec4; -[[stage(fragment)]] fn main() { - fragColor = o_color; +[[stage(fragment)]] +fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; })"; CheckDrawsGreen(vsStream.str().c_str(), kFragmentShader, readonlyStorageTexture); } @@ -791,16 +794,12 @@ TEST_P(StorageTextureTests, ReadonlyStorageTextureInFragmentShader) { // uses green as the output color if the pixel value is expected, otherwise uses red // instead. std::ostringstream fsStream; - fsStream << R"( -[[location(0)]] var o_color : vec4; -)" << CommonReadOnlyTestCode(format) - << R"( -[[stage(fragment)]] fn main() { + fsStream << CommonReadOnlyTestCode(format) << R"( +[[stage(fragment)]] fn main() -> [[location(0)]] vec4 { if (doTest()) { - o_color = vec4(0.0, 1.0, 0.0, 1.0); - } else { - o_color = vec4(1.0, 0.0, 0.0, 1.0); + return vec4(0.0, 1.0, 0.0, 1.0); } + return vec4(1.0, 0.0, 0.0, 1.0); })"; CheckDrawsGreen(kSimpleVertexShader, fsStream.str().c_str(), readonlyStorageTexture); } @@ -1180,15 +1179,13 @@ TEST_P(StorageTextureZeroInitTests, ReadonlyStorageTextureClearsToZeroInRenderPa const char* kVertexShader = kSimpleVertexShader; const std::string kFragmentShader = std::string(R"( [[group(0), binding(0)]] var srcImage : [[access(read)]] texture_storage_2d; -[[location(0)]] var o_color : vec4; )") + kCommonReadOnlyZeroInitTestCode + R"( -[[stage(fragment)]] fn main() { +[[stage(fragment)]] fn main() -> [[location(0)]] vec4 { if (doTest()) { - o_color = vec4(0.0, 1.0, 0.0, 1.0); - } else { - o_color = vec4(1.0, 0.0, 0.0, 1.0); + return vec4(0.0, 1.0, 0.0, 1.0); } + return vec4(1.0, 0.0, 0.0, 1.0); })"; CheckDrawsGreen(kVertexShader, kFragmentShader.c_str(), readonlyStorageTexture); } diff --git a/src/tests/end2end/SwapChainValidationTests.cpp b/src/tests/end2end/SwapChainValidationTests.cpp index 1584e295b5..8bb488fff3 100644 --- a/src/tests/end2end/SwapChainValidationTests.cpp +++ b/src/tests/end2end/SwapChainValidationTests.cpp @@ -222,14 +222,12 @@ TEST_P(SwapChainValidationTests, ViewDestroyedAfterPresent) { TEST_P(SwapChainValidationTests, ReturnedViewCharacteristics) { utils::ComboRenderPipelineDescriptor2 pipelineDesc; pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); // Validation will check that the sample count of the view matches this format. pipelineDesc.multisample.count = 1; diff --git a/src/tests/end2end/TextureFormatTests.cpp b/src/tests/end2end/TextureFormatTests.cpp index f5edb89bb8..fc15b30385 100644 --- a/src/tests/end2end/TextureFormatTests.cpp +++ b/src/tests/end2end/TextureFormatTests.cpp @@ -143,16 +143,14 @@ class TextureFormatTest : public DawnTest { utils::ComboRenderPipelineDescriptor2 desc; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-3.0, -1.0), vec2( 3.0, -1.0), vec2( 0.0, 2.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); // Compute the WGSL type of the texture's data. @@ -160,11 +158,15 @@ class TextureFormatTest : public DawnTest { std::ostringstream fsSource; fsSource << "[[group(0), binding(0)]] var myTexture : texture_2d<" << type << ">;\n"; - fsSource << "[[builtin(frag_coord)]] var FragCoord : vec4;\n"; - fsSource << "[[location(0)]] var fragColor : vec4<" << type << ">;\n"; - fsSource << "[[stage(fragment)]] fn main() {\n"; - fsSource << " fragColor = textureLoad(myTexture, vec2(FragCoord.xy), 0);\n"; - fsSource << "}"; + fsSource << "struct FragmentOut {\n"; + fsSource << " [[location(0)]] color : vec4<" << type << ">;\n"; + fsSource << R"(}; + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> FragmentOut { + var output : FragmentOut; + output.color = textureLoad(myTexture, vec2(FragCoord.xy), 0); + return output; + })"; wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, fsSource.str().c_str()); diff --git a/src/tests/end2end/TextureSubresourceTests.cpp b/src/tests/end2end/TextureSubresourceTests.cpp index 5044805aa5..a21d2d0437 100644 --- a/src/tests/end2end/TextureSubresourceTests.cpp +++ b/src/tests/end2end/TextureSubresourceTests.cpp @@ -50,22 +50,19 @@ class TextureSubresourceTest : public DawnTest { void DrawTriangle(const wgpu::TextureView& view) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 3> = array, 3>( vec2(-1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(1.0, 0.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; @@ -90,11 +87,9 @@ class TextureSubresourceTest : public DawnTest { void SampleAndDraw(const wgpu::TextureView& samplerView, const wgpu::TextureView& renderView) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + let pos : array, 6> = array, 6>( vec2(-1.0, -1.0), vec2( 1.0, 1.0), vec2(-1.0, 1.0), @@ -102,19 +97,16 @@ class TextureSubresourceTest : public DawnTest { vec2( 1.0, -1.0), vec2( 1.0, 1.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + return vec4(pos[VertexIndex], 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var samp : sampler; [[group(0), binding(1)]] var tex : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; - - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = textureSample(tex, samp, FragCoord.xy / vec2(4.0, 4.0)); + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> [[location(0)]] vec4 { + return textureSample(tex, samp, FragCoord.xy / vec2(4.0, 4.0)); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index f487b9ffa5..1b137f713d 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -61,26 +61,31 @@ namespace { wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) { return utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[location(0)]] var TexCoord : vec2; - [[stage(vertex)]] fn main() { - const pos : array, 6> = array, 6>( + struct VertexOut { + [[location(0)]] texCoord : vec2; + [[builtin(position)]] position : vec4; + }; + + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOut { + var output : VertexOut; + let pos : array, 6> = array, 6>( vec2(-2., -2.), vec2(-2., 2.), vec2( 2., -2.), vec2(-2., 2.), vec2( 2., -2.), vec2( 2., 2.)); - const texCoord : array, 6> = array, 6>( + let texCoord : array, 6> = array, 6>( vec2(0., 0.), vec2(0., 1.), vec2(1., 0.), vec2(0., 1.), vec2(1., 0.), vec2(1., 1.)); - Position = vec4(pos[VertexIndex], 0., 1.); - TexCoord = texCoord[VertexIndex]; + output.position = vec4(pos[VertexIndex], 0., 1.); + output.texCoord = texCoord[VertexIndex]; + return output; } )"); } @@ -216,11 +221,10 @@ class TextureViewSamplingTest : public DawnTest { const char* fragmentShader = R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, texCoord); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, texCoord); } )"; @@ -255,13 +259,12 @@ class TextureViewSamplingTest : public DawnTest { const char* fragmentShader = R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d_array; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, texCoord, 0) + - textureSample(texture0, sampler0, texCoord, 1) + - textureSample(texture0, sampler0, texCoord, 2); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, texCoord, 0) + + textureSample(texture0, sampler0, texCoord, 1) + + textureSample(texture0, sampler0, texCoord, 2); } )"; @@ -292,13 +295,11 @@ class TextureViewSamplingTest : public DawnTest { [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : )" << textureType << R"(; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { var sc : f32 = 2.0 * texCoord.x - 1.0; var tc : f32 = 2.0 * texCoord.y - 1.0; - fragColor = textureSample(texture0, sampler0, vec3()" + return textureSample(texture0, sampler0, vec3()" << coordToCubeMapFace << ")"; if (isCubeMapArray) { @@ -365,13 +366,12 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) { const char* fragmentShader = R"( [[group(0), binding(0)]] var sampler0 : sampler; [[group(0), binding(1)]] var texture0 : texture_2d_array; - [[location(0)]] var texCoord : vec2; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = textureSample(texture0, sampler0, texCoord, 0) + - textureSample(texture0, sampler0, texCoord, 1) + - textureSample(texture0, sampler0, texCoord, 2); + [[stage(fragment)]] + fn main([[location(0)]] texCoord : vec2) -> [[location(0)]] vec4 { + return textureSample(texture0, sampler0, texCoord, 0) + + textureSample(texture0, sampler0, texCoord, 1) + + textureSample(texture0, sampler0, texCoord, 2); } )"; @@ -496,10 +496,8 @@ class TextureViewRenderingTest : public DawnTest { renderPassInfo.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; const char* oneColorFragmentShader = R"( - [[location(0)]] var fragColor : vec4; - - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); } )"; wgpu::ShaderModule oneColorFsModule = diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp index 665abe51bb..ce7fcaf29e 100644 --- a/src/tests/end2end/TextureZeroInitTests.cpp +++ b/src/tests/end2end/TextureZeroInitTests.cpp @@ -69,9 +69,9 @@ class TextureZeroInitTest : public DawnTest { utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; pipelineDescriptor.vertex.module = CreateBasicVertexShaderForTest(depth); const char* fs = R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(1.0, 0.0, 0.0, 1.0); + ; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); } )"; pipelineDescriptor.cFragment.module = utils::CreateShaderModule(device, fs); @@ -83,7 +83,7 @@ class TextureZeroInitTest : public DawnTest { } wgpu::ShaderModule CreateBasicVertexShaderForTest(float depth = 0.f) { std::string source = R"( - const pos : array, 6> = array, 6>( + let pos : array, 6> = array, 6>( vec2(-1.0, -1.0), vec2(-1.0, 1.0), vec2( 1.0, -1.0), @@ -92,11 +92,9 @@ class TextureZeroInitTest : public DawnTest { vec2( 1.0, -1.0) ); - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - Position = vec4(pos[VertexIndex], )" + + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(pos[VertexIndex], )" + std::to_string(depth) + R"(, 1.0); })"; return utils::CreateShaderModule(device, source.c_str()); @@ -104,10 +102,14 @@ class TextureZeroInitTest : public DawnTest { wgpu::ShaderModule CreateSampledTextureFragmentShaderForTest() { return utils::CreateShaderModule(device, R"( [[group(0), binding(0)]] var texture0 : texture_2d; - [[builtin(frag_coord)]] var FragCoord : vec4; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = textureLoad(texture0, vec2(FragCoord.xy), 0); + struct FragmentOut { + [[location(0)]] color : vec4; + }; + [[stage(fragment)]] + fn main([[builtin(frag_coord)]] FragCoord : vec4) -> FragmentOut { + var output : FragmentOut; + output.color = textureLoad(texture0, vec2(FragCoord.xy), 0); + return output; } )"); } diff --git a/src/tests/end2end/VertexBufferRobustnessTests.cpp b/src/tests/end2end/VertexBufferRobustnessTests.cpp index befcd7ab8f..725356053c 100644 --- a/src/tests/end2end/VertexBufferRobustnessTests.cpp +++ b/src/tests/end2end/VertexBufferRobustnessTests.cpp @@ -33,17 +33,13 @@ class VertexBufferRobustnessTest : public DawnTest { wgpu::ShaderModule CreateVertexModule(const std::string& attributes, const std::string& successExpression) { return utils::CreateShaderModule(device, (attributes + R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { if ()" + successExpression + R"() { // Success case, move the vertex out of the viewport - Position = vec4(-10.0, 0.0, 0.0, 1.0); - } else { - // Failure case, move the vertex inside the viewport - Position = vec4(0.0, 0.0, 0.0, 1.0); + return vec4(-10.0, 0.0, 0.0, 1.0); } - return; + // Failure case, move the vertex inside the viewport + return vec4(0.0, 0.0, 0.0, 1.0); } )") .c_str()); @@ -58,11 +54,8 @@ class VertexBufferRobustnessTest : public DawnTest { bool expectation) { wgpu::ShaderModule vsModule = CreateVertexModule(attributes, successExpression); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var outColor : vec4; - - [[stage(fragment)]] fn main() { - outColor = vec4(1.0, 1.0, 1.0, 1.0); - return; + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); } )"); diff --git a/src/tests/end2end/VertexFormatTests.cpp b/src/tests/end2end/VertexFormatTests.cpp index d702e7d526..2d2a6a552e 100644 --- a/src/tests/end2end/VertexFormatTests.cpp +++ b/src/tests/end2end/VertexFormatTests.cpp @@ -232,19 +232,22 @@ class VertexFormatTest : public DawnTest { std::string expectedDataType = ShaderTypeGenerator(isFloat, isNormalized, isUnsigned, 1); std::ostringstream vs; - vs << "[[location(0)]] var test : " << variableType << ";\n"; + vs << "struct VertexIn {\n"; + vs << " [[location(0)]] test : " << variableType << ";\n"; + vs << " [[builtin(vertex_index)]] VertexIndex : u32;\n"; + vs << "};\n"; + // Because x86 CPU using "extended // precision"(https://en.wikipedia.org/wiki/Extended_precision) during float // math(https://developer.nvidia.com/sites/default/files/akamai/cuda/files/NVIDIA-CUDA-Floating-Point.pdf), // move normalization and Float16ToFloat32 into shader to generate // expected value. vs << R"( - [[location(0)]] var color : vec4; fn Float16ToFloat32(fp16 : u32) -> f32 { - const magic : u32 = (254u - 15u) << 23u; - const was_inf_nan : u32 = (127u + 16u) << 23u; + let magic : u32 = (254u - 15u) << 23u; + let was_inf_nan : u32 = (127u + 16u) << 23u; var fp32u : u32 = (fp16 & 0x7FFFu) << 13u; - const fp32 : f32 = bitcast(fp32u) * bitcast(magic); + let fp32 : f32 = bitcast(fp32u) * bitcast(magic); fp32u = bitcast(fp32); if (fp32 >= bitcast(was_inf_nan)) { fp32u = fp32u | (255u << 23u); @@ -253,14 +256,19 @@ class VertexFormatTest : public DawnTest { return bitcast(fp32u); } - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - const pos : array, 3> = array, 3>( + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; + + [[stage(vertex)]] + fn main(input : VertexIn) -> VertexOut { + let pos : array, 3> = array, 3>( vec2(-1.0, -1.0), vec2( 2.0, 0.0), vec2( 0.0, 2.0)); - Position = vec4(pos[VertexIndex], 0.0, 1.0); + var output : VertexOut; + output.position = vec4(pos[input.VertexIndex], 0.0, 1.0); )"; // Declare expected values. @@ -310,8 +318,8 @@ class VertexFormatTest : public DawnTest { std::string expectedVal = "expectedVal" + std::to_string(component); vs << " var " << testVal << " : " << expectedDataType << ";\n"; vs << " var " << expectedVal << " : " << expectedDataType << ";\n"; - vs << " " << testVal << " = test" << suffix << ";\n"; - vs << " " << expectedVal << " = expected[VertexIndex]" + vs << " " << testVal << " = input.test" << suffix << ";\n"; + vs << " " << expectedVal << " = expected[input.VertexIndex]" << "[" << component << "];\n"; if (!isInputTypeFloat) { // Integer / unsigned integer need to match exactly. vs << " success = success && (" << testVal << " == " << expectedVal << ");\n"; @@ -322,8 +330,8 @@ class VertexFormatTest : public DawnTest { vs << " if (isNan(" << expectedVal << ")) {\n"; vs << " success = success && isNan(" << testVal << ");\n"; vs << " } else {\n"; - vs << " const testValFloatToUint : u32 = bitcast(" << testVal << ");\n"; - vs << " const expectedValFloatToUint : u32 = bitcast(" << expectedVal + vs << " let testValFloatToUint : u32 = bitcast(" << testVal << ");\n"; + vs << " let expectedValFloatToUint : u32 = bitcast(" << expectedVal << ");\n"; vs << " success = success && max(testValFloatToUint, " "expectedValFloatToUint)"; @@ -333,18 +341,18 @@ class VertexFormatTest : public DawnTest { } vs << R"( if (success) { - color = vec4(0.0, 1.0, 0.0, 1.0); + output.color = vec4(0.0, 1.0, 0.0, 1.0); } else { - color = vec4(1.0, 0.0, 0.0, 1.0); + output.color = vec4(1.0, 0.0, 0.0, 1.0); } + return output; })"; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, vs.str().c_str()); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var color : vec4; - [[location(0)]] var FragColor : vec4; - [[stage(fragment)]] fn main() { - FragColor = color; + [[stage(fragment)]] + fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; })"); uint32_t bytesPerComponents = BytesPerComponents(format); diff --git a/src/tests/end2end/VertexStateTests.cpp b/src/tests/end2end/VertexStateTests.cpp index 61a3636cec..36b9fd8772 100644 --- a/src/tests/end2end/VertexStateTests.cpp +++ b/src/tests/end2end/VertexStateTests.cpp @@ -70,45 +70,56 @@ class VertexStateTest : public DawnTest { int multiplier, const std::vector& testSpec) { std::ostringstream vs; + vs << "struct VertexIn {\n"; // TODO(cwallez@chromium.org): this only handles float attributes, we should extend it to // other types Adds line of the form - // [[location(1) var input1 : vec4; + // [[location(1) input1 : vec4; for (const auto& input : testSpec) { - vs << "[[location(" << input.location << ")]] var input" << input.location + vs << "[[location(" << input.location << ")]] input" << input.location << " : vec4;\n"; } - vs << "[[builtin(vertex_index)]] var VertexIndex : u32;\n"; - vs << "[[builtin(instance_index)]] var InstanceIndex : u32;\n"; - vs << "[[location(0)]] var color : vec4;\n"; - vs << "[[builtin(position)]] var Position : vec4;\n"; - vs << "[[stage(vertex)]] fn main() {\n"; + vs << R"( + [[builtin(vertex_index)]] VertexIndex : u32; + [[builtin(instance_index)]] InstanceIndex : u32; + }; + + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; + + [[stage(vertex)]] fn main(input : VertexIn) -> VertexOut { + var output : VertexOut; + )"; // Hard code the triangle in the shader so that we don't have to add a vertex input for it. // Also this places the triangle in the grid based on its VertexID and InstanceID - vs << " const pos : array, 3> = array, 3>(\n" + vs << " let pos : array, 3> = array, 3>(\n" " vec2(0.5, 1.0), vec2(0.0, 0.0), vec2(1.0, 0.0));\n"; - vs << " var offset : vec2 = vec2(f32(VertexIndex / 3u), " - "f32(InstanceIndex));\n"; - vs << " var worldPos : vec2 = pos[VertexIndex % 3u] + offset;\n"; + vs << " var offset : vec2 = vec2(f32(input.VertexIndex / 3u), " + "f32(input.InstanceIndex));\n"; + vs << " var worldPos : vec2 = pos[input.VertexIndex % 3u] + offset;\n"; vs << " var position : vec4 = vec4(0.5 * worldPos - vec2(1.0, 1.0), 0.0, " "1.0);\n"; - vs << " Position = vec4(position.x, -position.y, position.z, position.w);\n"; + vs << " output.position = vec4(position.x, -position.y, position.z, position.w);\n"; // Perform the checks by successively ANDing a boolean vs << " var success : bool = true;\n"; for (const auto& input : testSpec) { for (int component = 0; component < 4; ++component) { - vs << " success = success && (input" << input.location << "[" << component + vs << " success = success && (input.input" << input.location << "[" << component << "] == "; if (ShouldComponentBeDefault(input.format, component)) { vs << (component == 3 ? "1.0" : "0.0"); } else { if (input.step == InputStepMode::Vertex) { - vs << "f32(" << multiplier << "u * VertexIndex) + " << component << ".0"; + vs << "f32(" << multiplier << "u * input.VertexIndex) + " << component + << ".0"; } else { - vs << "f32(" << multiplier << "u * InstanceIndex) + " << component << ".0"; + vs << "f32(" << multiplier << "u * input.InstanceIndex) + " << component + << ".0"; } } vs << ");\n"; @@ -116,19 +127,20 @@ class VertexStateTest : public DawnTest { } // Choose the color - vs << " if (success) {\n"; - vs << " color = vec4(0.0, 1.0, 0.0, 1.0);\n"; - vs << " } else {\n"; - vs << " color = vec4(1.0, 0.0, 0.0, 1.0);\n"; - vs << " }\n"; - vs << "}\n"; + vs << R"( + if (success) { + output.color = vec4(0.0, 1.0, 0.0, 1.0); + } else { + output.color = vec4(1.0, 0.0, 0.0, 1.0); + } + return output; + })"; wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, vs.str().c_str()); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var color : vec4; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = color; + [[stage(fragment)]] + fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; } )"); @@ -570,36 +582,41 @@ TEST_P(VertexStateTest, OverlappingVertexAttributes) { utils::ComboRenderPipelineDescriptor2 pipelineDesc; pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var attr0 : vec4; - [[location(1)]] var attr1 : vec2; - [[location(2)]] var attr2 : vec4; - [[location(3)]] var attr3 : f32; + struct VertexIn { + [[location(0)]] attr0 : vec4; + [[location(1)]] attr1 : vec2; + [[location(2)]] attr2 : vec4; + [[location(3)]] attr3 : f32; + }; - [[location(0)]] var color : vec4; - [[builtin(position)]] var Position : vec4; + struct VertexOut { + [[location(0)]] color : vec4; + [[builtin(position)]] position : vec4; + }; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main(input : VertexIn) -> VertexOut { + var output : VertexOut; + output.position = vec4(0.0, 0.0, 0.0, 1.0); var success : bool = ( - attr0.x == 1.0 && - attr1.x == 2u && - attr1.y == 3u && - attr2.z == 4.0 && - attr2.w == 5.0 && - attr3 == 1.0 + input.attr0.x == 1.0 && + input.attr1.x == 2u && + input.attr1.y == 3u && + input.attr2.z == 4.0 && + input.attr2.w == 5.0 && + input.attr3 == 1.0 ); if (success) { - color = vec4(0.0, 1.0, 0.0, 1.0); + output.color = vec4(0.0, 1.0, 0.0, 1.0); } else { - color = vec4(1.0, 0.0, 0.0, 1.0); + output.color = vec4(1.0, 0.0, 0.0, 1.0); } + return output; })"); pipelineDesc.cFragment.module = utils::CreateShaderModule(device, R"( - [[location(0)]] var color : vec4; - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = color; + [[stage(fragment)]] + fn main([[location(0)]] color : vec4) -> [[location(0)]] vec4 { + return color; })"); pipelineDesc.vertex.bufferCount = vertexState.vertexBufferCount; pipelineDesc.vertex.buffers = &vertexState.cVertexBuffers[0]; @@ -642,15 +659,13 @@ TEST_P(OptionalVertexStateTest, Basic) { utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - [[stage(vertex)]] fn main() { - Position = vec4(0.0, 0.0, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(0.0, 0.0, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/ViewportOrientationTests.cpp b/src/tests/end2end/ViewportOrientationTests.cpp index 372bba36d7..2f62f4297e 100644 --- a/src/tests/end2end/ViewportOrientationTests.cpp +++ b/src/tests/end2end/ViewportOrientationTests.cpp @@ -24,16 +24,13 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) { utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 2, 2); wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( - [[builtin(position)]] var Position : vec4; - - [[stage(vertex)]] fn main() { - Position = vec4(-0.5, 0.5, 0.0, 1.0); + [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4 { + return vec4(-0.5, 0.5, 0.0, 1.0); })"); wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(0.0, 1.0, 0.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(0.0, 1.0, 0.0, 1.0); })"); utils::ComboRenderPipelineDescriptor2 descriptor; diff --git a/src/tests/end2end/ViewportTests.cpp b/src/tests/end2end/ViewportTests.cpp index 3f448f5d00..68bb1f41eb 100644 --- a/src/tests/end2end/ViewportTests.cpp +++ b/src/tests/end2end/ViewportTests.cpp @@ -23,10 +23,7 @@ class ViewportTest : public DawnTest { DawnTest::SetUp(); mQuadVS = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - const pos : array, 6> = array, 6>( + let pos : array, 6> = array, 6>( vec2(-1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, 1.0), @@ -34,14 +31,14 @@ class ViewportTest : public DawnTest { vec2(-1.0, -1.0), vec2( 1.0, -1.0)); - [[stage(vertex)]] fn main() { - Position = vec4(pos[VertexIndex], 0.0, 1.0); + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(pos[VertexIndex], 0.0, 1.0); })"); mQuadFS = utils::CreateShaderModule(device, R"( - [[location(0)]] var fragColor : vec4; - [[stage(fragment)]] fn main() { - fragColor = vec4(1.0, 1.0, 1.0, 1.0); + [[stage(fragment)]] fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); })"); } @@ -96,16 +93,14 @@ class ViewportTest : public DawnTest { // Create a pipeline drawing 3 points at depth 1.0, 0.5 and 0.0. utils::ComboRenderPipelineDescriptor2 pipelineDesc; pipelineDesc.vertex.module = utils::CreateShaderModule(device, R"( - [[builtin(vertex_index)]] var VertexIndex : u32; - [[builtin(position)]] var Position : vec4; - - const points : array, 3> = array, 3>( + let points : array, 3> = array, 3>( vec3(-0.9, 0.0, 1.0), vec3( 0.0, 0.0, 0.5), vec3( 0.9, 0.0, 0.0)); - [[stage(vertex)]] fn main() { - Position = vec4(points[VertexIndex], 1.0); + [[stage(vertex)]] + fn main([[builtin(vertex_index)]] VertexIndex : u32) -> [[builtin(position)]] vec4 { + return vec4(points[VertexIndex], 1.0); })"); pipelineDesc.cFragment.module = mQuadFS; pipelineDesc.cFragment.targetCount = 0;