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:
parent
f84daa070f
commit
5709060143
|
@ -41,26 +41,29 @@ class MultisampledRenderingTest : public DawnTest {
|
||||||
uint32_t sampleMask = 0xFFFFFFFF,
|
uint32_t sampleMask = 0xFFFFFFFF,
|
||||||
bool alphaToCoverageEnabled = false,
|
bool alphaToCoverageEnabled = false,
|
||||||
bool flipTriangle = false) {
|
bool flipTriangle = false) {
|
||||||
const char* kFsOneOutputWithDepth =
|
const char* kFsOneOutputWithDepth = R"(
|
||||||
R"(#version 450
|
[[block]] struct U {
|
||||||
layout(location = 0) out vec4 fragColor;
|
color : vec4<f32>;
|
||||||
layout (std140, set = 0, binding = 0) uniform uBuffer {
|
depth : f32;
|
||||||
vec4 color;
|
|
||||||
float depth;
|
|
||||||
};
|
};
|
||||||
void main() {
|
[[group(0), binding(0)]] var<uniform> uBuffer : U;
|
||||||
fragColor = color;
|
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||||
gl_FragDepth = depth;
|
[[builtin(frag_depth)]] var<out> FragDepth : f32;
|
||||||
|
|
||||||
|
[[stage(fragment)]] fn main() -> void {
|
||||||
|
FragColor = uBuffer.color;
|
||||||
|
FragDepth = uBuffer.depth;
|
||||||
})";
|
})";
|
||||||
|
|
||||||
const char* kFsOneOutputWithoutDepth =
|
const char* kFsOneOutputWithoutDepth = R"(
|
||||||
R"(#version 450
|
[[block]] struct U {
|
||||||
layout(location = 0) out vec4 fragColor;
|
color : vec4<f32>;
|
||||||
layout (std140, set = 0, binding = 0) uniform uBuffer {
|
|
||||||
vec4 color;
|
|
||||||
};
|
};
|
||||||
void main() {
|
[[group(0), binding(0)]] var<uniform> uBuffer : U;
|
||||||
fragColor = color;
|
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||||
|
|
||||||
|
[[stage(fragment)]] fn main() -> void {
|
||||||
|
FragColor = uBuffer.color;
|
||||||
})";
|
})";
|
||||||
|
|
||||||
const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth;
|
const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth;
|
||||||
|
@ -72,17 +75,18 @@ class MultisampledRenderingTest : public DawnTest {
|
||||||
wgpu::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest(
|
wgpu::RenderPipeline CreateRenderPipelineWithTwoOutputsForTest(
|
||||||
uint32_t sampleMask = 0xFFFFFFFF,
|
uint32_t sampleMask = 0xFFFFFFFF,
|
||||||
bool alphaToCoverageEnabled = false) {
|
bool alphaToCoverageEnabled = false) {
|
||||||
const char* kFsTwoOutputs =
|
const char* kFsTwoOutputs = R"(
|
||||||
R"(#version 450
|
[[block]] struct U {
|
||||||
layout(location = 0) out vec4 fragColor1;
|
color0 : vec4<f32>;
|
||||||
layout(location = 1) out vec4 fragColor2;
|
color1 : vec4<f32>;
|
||||||
layout (std140, set = 0, binding = 0) uniform uBuffer {
|
|
||||||
vec4 color1;
|
|
||||||
vec4 color2;
|
|
||||||
};
|
};
|
||||||
void main() {
|
[[group(0), binding(0)]] var<uniform> uBuffer : U;
|
||||||
fragColor1 = color1;
|
[[location(0)]] var<out> FragColor0 : vec4<f32>;
|
||||||
fragColor2 = color2;
|
[[location(1)]] var<out> FragColor1 : vec4<f32>;
|
||||||
|
|
||||||
|
[[stage(fragment)]] fn main() -> void {
|
||||||
|
FragColor0 = uBuffer.color0;
|
||||||
|
FragColor1 = uBuffer.color1;
|
||||||
})";
|
})";
|
||||||
|
|
||||||
return CreateRenderPipelineForTest(kFsTwoOutputs, 2, false, sampleMask,
|
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,
|
// Draw a bottom-right triangle. In standard 4xMSAA pattern, for the pixels on diagonal,
|
||||||
// only two of the samples will be touched.
|
// only two of the samples will be touched.
|
||||||
const char* vs =
|
const char* vs = R"(
|
||||||
R"(#version 450
|
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||||
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(1.f, -1.f));
|
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
[[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.
|
// Draw a bottom-left triangle.
|
||||||
const char* vsFlipped =
|
const char* vsFlipped = R"(
|
||||||
R"(#version 450
|
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||||
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f));
|
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
[[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) {
|
if (flipTriangle) {
|
||||||
pipelineDescriptor.vertex.module =
|
pipelineDescriptor.vertex.module = utils::CreateShaderModuleFromWGSL(device, vsFlipped);
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsFlipped);
|
|
||||||
} else {
|
} else {
|
||||||
pipelineDescriptor.vertex.module =
|
pipelineDescriptor.vertex.module = utils::CreateShaderModuleFromWGSL(device, vs);
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pipelineDescriptor.cFragment.module =
|
pipelineDescriptor.cFragment.module = utils::CreateShaderModuleFromWGSL(device, fs);
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
|
|
||||||
|
|
||||||
if (hasDepthStencilAttachment) {
|
if (hasDepthStencilAttachment) {
|
||||||
wgpu::DepthStencilState* depthStencil =
|
wgpu::DepthStencilState* depthStencil =
|
||||||
|
@ -741,6 +754,10 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut
|
||||||
// supported on some platforms.
|
// supported on some platforms.
|
||||||
DAWN_SKIP_TEST_IF(HasToggleEnabled("disable_sample_variables"));
|
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;
|
constexpr bool kTestDepth = false;
|
||||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
|
|
||||||
|
@ -751,15 +768,17 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DTextureWithSampleMaskAndShaderOut
|
||||||
// Thus the final mask includes only the third sample.
|
// Thus the final mask includes only the third sample.
|
||||||
constexpr float kMSAACoverage = 0.25f;
|
constexpr float kMSAACoverage = 0.25f;
|
||||||
constexpr uint32_t kSampleMask = kFirstSampleMaskBit | kThirdSampleMaskBit;
|
constexpr uint32_t kSampleMask = kFirstSampleMaskBit | kThirdSampleMaskBit;
|
||||||
const char* fs =
|
const char* fs = R"(
|
||||||
R"(#version 450
|
[[block]] struct U {
|
||||||
layout(location = 0) out vec4 fragColor;
|
color : vec4<f32>;
|
||||||
layout (std140, set = 0, binding = 0) uniform uBuffer {
|
|
||||||
vec4 color;
|
|
||||||
};
|
};
|
||||||
void main() {
|
[[group(0), binding(0)]] var<uniform> uBuffer : U;
|
||||||
fragColor = color;
|
[[location(0)]] var<out> FragColor : vec4<f32>;
|
||||||
gl_SampleMask[0] = 6;
|
[[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);
|
wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 1, false, kSampleMask);
|
||||||
|
@ -792,6 +811,10 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargetsWithShaderOut
|
||||||
// supported on some platforms.
|
// supported on some platforms.
|
||||||
DAWN_SKIP_TEST_IF(HasToggleEnabled("disable_sample_variables"));
|
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 =
|
wgpu::TextureView multisampledColorView2 =
|
||||||
CreateTextureForRenderAttachment(kColorFormat, kSampleCount).CreateView();
|
CreateTextureForRenderAttachment(kColorFormat, kSampleCount).CreateView();
|
||||||
wgpu::Texture resolveTexture2 = CreateTextureForRenderAttachment(kColorFormat, 1);
|
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,
|
// The second and third samples are included in the shader-output mask,
|
||||||
// only the first one is covered by the triangle.
|
// only the first one is covered by the triangle.
|
||||||
constexpr float kMSAACoverage = 0.25f;
|
constexpr float kMSAACoverage = 0.25f;
|
||||||
const char* fs =
|
const char* fs = R"(
|
||||||
R"(#version 450
|
[[block]] struct U {
|
||||||
layout(location = 0) out vec4 fragColor1;
|
color0 : vec4<f32>;
|
||||||
layout(location = 1) out vec4 fragColor2;
|
color1 : vec4<f32>;
|
||||||
layout (std140, set = 0, binding = 0) uniform uBuffer {
|
|
||||||
vec4 color1;
|
|
||||||
vec4 color2;
|
|
||||||
};
|
};
|
||||||
void main() {
|
[[group(0), binding(0)]] var<uniform> uBuffer : U;
|
||||||
fragColor1 = color1;
|
[[location(0)]] var<out> FragColor0 : vec4<f32>;
|
||||||
fragColor2 = color2;
|
[[location(1)]] var<out> FragColor1 : vec4<f32>;
|
||||||
gl_SampleMask[0] = 6;
|
[[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);
|
wgpu::RenderPipeline pipeline = CreateRenderPipelineForTest(fs, 2, false);
|
||||||
|
|
Loading…
Reference in New Issue