Port MultisampledRenderingTests to WGSL.

Bug: dawn:572
Change-Id: I9e76b39c0df705cc3fde5058e618c1ecb2c446f7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44761
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Corentin Wallez 2021-03-19 09:48:11 +00:00 committed by Commit Bot service account
parent f84daa070f
commit 5709060143
1 changed files with 86 additions and 61 deletions

View File

@ -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<f32>;
depth : f32;
};
void main() {
fragColor = color;
gl_FragDepth = depth;
[[group(0), binding(0)]] var<uniform> uBuffer : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[builtin(frag_depth)]] var<out> 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<f32>;
};
void main() {
fragColor = color;
[[group(0), binding(0)]] var<uniform> uBuffer : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[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<f32>;
color1 : vec4<f32>;
};
void main() {
fragColor1 = color1;
fragColor2 = color2;
[[group(0), binding(0)]] var<uniform> uBuffer : U;
[[location(0)]] var<out> FragColor0 : vec4<f32>;
[[location(1)]] var<out> FragColor1 : vec4<f32>;
[[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<out> Position : vec4<f32>;
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
[[stage(vertex)]] fn main() -> void {
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, 1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>( 1.0, -1.0)
);
Position = vec4<f32>(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<out> Position : vec4<f32>;
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
[[stage(vertex)]] fn main() -> void {
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, 1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, -1.0)
);
Position = vec4<f32>(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<f32>;
};
void main() {
fragColor = color;
gl_SampleMask[0] = 6;
[[group(0), binding(0)]] var<uniform> uBuffer : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[builtin(sample_mask_out)]] var<out> 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<f32>;
color1 : vec4<f32>;
};
void main() {
fragColor1 = color1;
fragColor2 = color2;
gl_SampleMask[0] = 6;
[[group(0), binding(0)]] var<uniform> uBuffer : U;
[[location(0)]] var<out> FragColor0 : vec4<f32>;
[[location(1)]] var<out> FragColor1 : vec4<f32>;
[[builtin(sample_mask_out)]] var<out> SampleMask : u32;
[[stage(fragment)]] fn main() -> void {
FragColor0 = uBuffer.color0;
FragColor1 = uBuffer.color1;
SampleMask = 6u;
})";
wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 2, false);