From 57090601433d245c24903578ff58e5ba70356f81 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 19 Mar 2021 09:48:11 +0000 Subject: [PATCH] Port MultisampledRenderingTests to WGSL. Bug: dawn:572 Change-Id: I9e76b39c0df705cc3fde5058e618c1ecb2c446f7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44761 Auto-Submit: Corentin Wallez Reviewed-by: Austin Eng Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton --- .../end2end/MultisampledRenderingTests.cpp | 147 ++++++++++-------- 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/src/tests/end2end/MultisampledRenderingTests.cpp b/src/tests/end2end/MultisampledRenderingTests.cpp index 7023fcb17b..62e0ae835e 100644 --- a/src/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/tests/end2end/MultisampledRenderingTests.cpp @@ -41,26 +41,29 @@ class MultisampledRenderingTest : public DawnTest { uint32_t sampleMask = 0xFFFFFFFF, bool alphaToCoverageEnabled = false, bool flipTriangle = false) { - const char* kFsOneOutputWithDepth = - R"(#version 450 - layout(location = 0) out vec4 fragColor; - layout (std140, set = 0, binding = 0) uniform uBuffer { - vec4 color; - float depth; + const char* kFsOneOutputWithDepth = R"( + [[block]] struct U { + color : vec4; + depth : f32; }; - void main() { - fragColor = color; - gl_FragDepth = depth; + [[group(0), binding(0)]] var uBuffer : U; + [[location(0)]] var FragColor : vec4; + [[builtin(frag_depth)]] var FragDepth : f32; + + [[stage(fragment)]] fn main() -> void { + FragColor = uBuffer.color; + FragDepth = uBuffer.depth; })"; - const char* kFsOneOutputWithoutDepth = - R"(#version 450 - layout(location = 0) out vec4 fragColor; - layout (std140, set = 0, binding = 0) uniform uBuffer { - vec4 color; + const char* kFsOneOutputWithoutDepth = R"( + [[block]] struct U { + color : vec4; }; - void main() { - fragColor = color; + [[group(0), binding(0)]] var uBuffer : U; + [[location(0)]] var FragColor : vec4; + + [[stage(fragment)]] fn main() -> void { + FragColor = uBuffer.color; })"; const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth; @@ -72,17 +75,18 @@ class MultisampledRenderingTest : public DawnTest { wgpu::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest( uint32_t sampleMask = 0xFFFFFFFF, bool alphaToCoverageEnabled = false) { - const char* kFsTwoOutputs = - R"(#version 450 - layout(location = 0) out vec4 fragColor1; - layout(location = 1) out vec4 fragColor2; - layout (std140, set = 0, binding = 0) uniform uBuffer { - vec4 color1; - vec4 color2; + const char* kFsTwoOutputs = R"( + [[block]] struct U { + color0 : vec4; + color1 : vec4; }; - void main() { - fragColor1 = color1; - fragColor2 = color2; + [[group(0), binding(0)]] var uBuffer : U; + [[location(0)]] var FragColor0 : vec4; + [[location(1)]] var FragColor1 : vec4; + + [[stage(fragment)]] fn main() -> void { + FragColor0 = uBuffer.color0; + FragColor1 = uBuffer.color1; })"; return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false, sampleMask, @@ -206,31 +210,40 @@ 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"(#version 450 - const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(1.f, -1.f)); - void main() { - gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0); + const char* vs = R"( + [[builtin(position)]] var Position : vec4; + [[builtin(vertex_index)]] var VertexIndex : u32; + + [[stage(vertex)]] fn main() -> void { + const 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); })"; // Draw a bottom-left triangle. - const char* vsFlipped = - R"(#version 450 - const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f)); - void main() { - gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0); + const char* vsFlipped = R"( + [[builtin(position)]] var Position : vec4; + [[builtin(vertex_index)]] var VertexIndex : u32; + + [[stage(vertex)]] fn main() -> void { + const 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); })"; if (flipTriangle) { - pipelineDescriptor.vertex.module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsFlipped); + pipelineDescriptor.vertex.module = utils::CreateShaderModuleFromWGSL(device, vsFlipped); } else { - pipelineDescriptor.vertex.module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs); + pipelineDescriptor.vertex.module = utils::CreateShaderModuleFromWGSL(device, vs); } - pipelineDescriptor.cFragment.module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs); + pipelineDescriptor.cFragment.module = utils::CreateShaderModuleFromWGSL(device, fs); if (hasDepthStencilAttachment) { wgpu::DepthStencilState* depthStencil = @@ -741,6 +754,10 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut // supported on some platforms. DAWN_SKIP_TEST_IF(HasToggleEnabled("disable_sample_variables")); + // TODO(cwallez@chromium.org): Fails on Metal / D3D12 because SPIRV-Cross produces bad shaders + // for the SPIR-V outputted by Tint. Reenable once we use Tint's MSL / HLSL generators. + DAWN_SKIP_TEST_IF(IsD3D12() || IsMetal()); + constexpr bool kTestDepth = false; wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder(); @@ -751,15 +768,17 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut // Thus the final mask includes only the third sample. constexpr float kMSAACoverage = 0.25f; constexpr uint32_t kSampleMask = kFirstSampleMaskBit | kThirdSampleMaskBit; - const char* fs = - R"(#version 450 - layout(location = 0) out vec4 fragColor; - layout (std140, set = 0, binding = 0) uniform uBuffer { - vec4 color; + const char* fs = R"( + [[block]] struct U { + color : vec4; }; - void main() { - fragColor = color; - gl_SampleMask[0] = 6; + [[group(0), binding(0)]] var uBuffer : U; + [[location(0)]] var FragColor : vec4; + [[builtin(sample_mask_out)]] var SampleMask : u32; + + [[stage(fragment)]] fn main() -> void { + FragColor = uBuffer.color; + SampleMask = 6u; })"; wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 1, false, kSampleMask); @@ -792,6 +811,10 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargetsWithShaderOut // supported on some platforms. DAWN_SKIP_TEST_IF(HasToggleEnabled("disable_sample_variables")); + // TODO(cwallez@chromium.org): Fails on Metal / D3D12 because SPIRV-Cross produces bad shaders + // for the SPIR-V outputted by Tint. Reenable once we use Tint's MSL / HLSL generators. + DAWN_SKIP_TEST_IF(IsD3D12() || IsMetal()); + wgpu::TextureView multisampledColorView2 = CreateTextureForRenderAttachment(kColorFormat, kSampleCount).CreateView(); wgpu::Texture resolveTexture2 = CreateTextureForRenderAttachment(kColorFormat, 1); @@ -801,18 +824,20 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargetsWithShaderOut // The second and third samples are included in the shader-output mask, // only the first one is covered by the triangle. constexpr float kMSAACoverage = 0.25f; - const char* fs = - R"(#version 450 - layout(location = 0) out vec4 fragColor1; - layout(location = 1) out vec4 fragColor2; - layout (std140, set = 0, binding = 0) uniform uBuffer { - vec4 color1; - vec4 color2; + const char* fs = R"( + [[block]] struct U { + color0 : vec4; + color1 : vec4; }; - void main() { - fragColor1 = color1; - fragColor2 = color2; - gl_SampleMask[0] = 6; + [[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() -> void { + FragColor0 = uBuffer.color0; + FragColor1 = uBuffer.color1; + SampleMask = 6u; })"; wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 2, false);