Update DepthStencilSamplingTests to use WGSL
Bug: dawn:572 Change-Id: I8e90175e2201250ca7e67ec955226871bdb70a97 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32514 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
600798bdb1
commit
04e3078a64
|
@ -69,47 +69,40 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
|
|
||||||
wgpu::RenderPipeline CreateSamplingRenderPipeline(std::vector<TestAspect> aspects,
|
wgpu::RenderPipeline CreateSamplingRenderPipeline(std::vector<TestAspect> aspects,
|
||||||
uint32_t componentIndex) {
|
uint32_t componentIndex) {
|
||||||
wgpu::ShaderModule vsModule =
|
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
|
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||||
#version 450
|
[[stage(vertex)]] fn main() -> void {
|
||||||
void main() {
|
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
|
||||||
gl_Position = vec4(0.f, 0.f, 0.f, 1.f);
|
})");
|
||||||
gl_PointSize = 1.0;
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
|
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
|
||||||
|
|
||||||
std::ostringstream shaderSource;
|
std::ostringstream shaderSource;
|
||||||
std::ostringstream shaderBody;
|
std::ostringstream shaderBody;
|
||||||
shaderSource << R"(
|
|
||||||
#version 450
|
|
||||||
layout(set = 0, binding = 0) uniform sampler samp;
|
|
||||||
)";
|
|
||||||
|
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
for (TestAspect aspect : aspects) {
|
for (TestAspect aspect : aspects) {
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
case TestAspect::Depth:
|
case TestAspect::Depth:
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + index
|
shaderSource << "[[set(0), binding(" << index << ")]] var<uniform_constant> tex"
|
||||||
<< ") uniform texture2D tex" << index << ";\n";
|
<< index << " : texture_2d<f32>;\n";
|
||||||
|
|
||||||
shaderSource << "layout(location = " << index << ") out float result" << index
|
shaderSource << "[[location(" << index << ")]] var<out> result" << index
|
||||||
<< ";\n";
|
<< " : f32;\n";
|
||||||
|
|
||||||
shaderBody << "result" << index << " = texture(sampler2D(tex" << index
|
shaderBody << "\nresult" << index << " = textureLoad(tex" << index
|
||||||
<< ", samp), vec2(0.5, 0.5))[" << componentIndex << "];\n";
|
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];\n";
|
||||||
pipelineDescriptor.cColorStates[index].format = wgpu::TextureFormat::R32Float;
|
pipelineDescriptor.cColorStates[index].format = wgpu::TextureFormat::R32Float;
|
||||||
break;
|
break;
|
||||||
case TestAspect::Stencil:
|
case TestAspect::Stencil:
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + index
|
shaderSource << "[[set(0), binding(" << index << ")]] var<uniform_constant> tex"
|
||||||
<< ") uniform utexture2D tex" << index << ";\n";
|
<< index << " : texture_2d<u32>;\n";
|
||||||
|
|
||||||
shaderSource << "layout(location = " << index << ") out uint result" << index
|
shaderSource << "[[location(" << index << ")]] var<out> result" << index
|
||||||
<< ";\n";
|
<< " : u32;\n";
|
||||||
|
|
||||||
shaderBody << "result" << index << " = texelFetch(usampler2D(tex" << index
|
shaderBody << "\nresult" << index << " = textureLoad(tex" << index
|
||||||
<< ", samp), ivec2(0, 0), 0)[" << componentIndex << "];\n";
|
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];\n";
|
||||||
pipelineDescriptor.cColorStates[index].format = wgpu::TextureFormat::R8Uint;
|
pipelineDescriptor.cColorStates[index].format = wgpu::TextureFormat::R8Uint;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -117,10 +110,10 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderSource << "void main() { " << shaderBody.str() << " }";
|
shaderSource << "[[stage(fragment)]] fn main() -> void { " << shaderBody.str() << "\n}";
|
||||||
|
|
||||||
wgpu::ShaderModule fsModule = utils::CreateShaderModule(
|
wgpu::ShaderModule fsModule =
|
||||||
device, utils::SingleShaderStage::Fragment, shaderSource.str().c_str());
|
utils::CreateShaderModuleFromWGSL(device, shaderSource.str().c_str());
|
||||||
pipelineDescriptor.vertexStage.module = vsModule;
|
pipelineDescriptor.vertexStage.module = vsModule;
|
||||||
pipelineDescriptor.cFragmentStage.module = fsModule;
|
pipelineDescriptor.cFragmentStage.module = fsModule;
|
||||||
pipelineDescriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
|
pipelineDescriptor.primitiveTopology = wgpu::PrimitiveTopology::PointList;
|
||||||
|
@ -134,46 +127,50 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
std::ostringstream shaderSource;
|
std::ostringstream shaderSource;
|
||||||
std::ostringstream shaderBody;
|
std::ostringstream shaderBody;
|
||||||
shaderSource << R"(
|
shaderSource << R"(
|
||||||
#version 450
|
[[block]] struct DepthResult {
|
||||||
layout(set = 0, binding = 0) uniform sampler samp;
|
[[offset(0)]] value : f32;
|
||||||
)";
|
};
|
||||||
|
[[block]] struct StencilResult {
|
||||||
|
[[offset(0)]] value : u32;
|
||||||
|
};)";
|
||||||
|
shaderSource << "\n";
|
||||||
|
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
for (TestAspect aspect : aspects) {
|
for (TestAspect aspect : aspects) {
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
case TestAspect::Depth:
|
case TestAspect::Depth:
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + 2 * index
|
shaderSource << "[[set(0), binding(" << 2 * index
|
||||||
<< ") uniform texture2D tex" << index << ";\n";
|
<< ")]] var<uniform_constant> tex" << index
|
||||||
|
<< " : texture_2d<f32>;\n";
|
||||||
|
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + 2 * index + 1
|
shaderSource << "[[set(0), binding(" << 2 * index + 1
|
||||||
<< ") writeonly buffer Result" << index << " {\n"
|
<< ")]] var<storage_buffer> result" << index
|
||||||
<< " float result" << index << ";\n"
|
<< " : DepthResult;\n";
|
||||||
<< "};\n";
|
|
||||||
|
|
||||||
shaderBody << "result" << index << " = texture(sampler2D(tex" << index
|
shaderBody << "\nresult" << index << ".value = textureLoad(tex" << index
|
||||||
<< ", samp), vec2(0.5, 0.5))[" << componentIndex << "];\n";
|
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];";
|
||||||
break;
|
break;
|
||||||
case TestAspect::Stencil:
|
case TestAspect::Stencil:
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + 2 * index
|
shaderSource << "[[set(0), binding(" << 2 * index
|
||||||
<< ") uniform utexture2D tex" << index << ";\n";
|
<< ")]] var<uniform_constant> tex" << index
|
||||||
|
<< " : texture_2d<u32>;\n";
|
||||||
|
|
||||||
shaderSource << "layout(set = 0, binding = " << 1 + 2 * index + 1
|
shaderSource << "[[set(0), binding(" << 2 * index + 1
|
||||||
<< ") writeonly buffer Result" << index << " {\n"
|
<< ")]] var<storage_buffer> result" << index
|
||||||
<< " uint result" << index << ";\n"
|
<< " : StencilResult;\n";
|
||||||
<< "};\n";
|
|
||||||
|
|
||||||
shaderBody << "result" << index << " = texelFetch(usampler2D(tex" << index
|
shaderBody << "\nresult" << index << ".value = textureLoad(tex" << index
|
||||||
<< ", samp), ivec2(0, 0), 0)[" << componentIndex << "];\n";
|
<< ", vec2<i32>(0, 0), 0)[" << componentIndex << "];";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderSource << "void main() { " << shaderBody.str() << " }";
|
shaderSource << "[[stage(compute)]] fn main() -> void { " << shaderBody.str() << "\n}";
|
||||||
|
|
||||||
wgpu::ShaderModule csModule = utils::CreateShaderModule(
|
wgpu::ShaderModule csModule =
|
||||||
device, utils::SingleShaderStage::Compute, shaderSource.str().c_str());
|
utils::CreateShaderModuleFromWGSL(device, shaderSource.str().c_str());
|
||||||
|
|
||||||
wgpu::ComputePipelineDescriptor pipelineDescriptor;
|
wgpu::ComputePipelineDescriptor pipelineDescriptor;
|
||||||
pipelineDescriptor.computeStage.module = csModule;
|
pipelineDescriptor.computeStage.module = csModule;
|
||||||
|
@ -183,30 +180,25 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
wgpu::RenderPipeline CreateComparisonRenderPipeline() {
|
wgpu::RenderPipeline CreateComparisonRenderPipeline() {
|
||||||
wgpu::ShaderModule vsModule =
|
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
|
[[builtin(position)]] var<out> Position : vec4<f32>;
|
||||||
#version 450
|
[[stage(vertex)]] fn main() -> void {
|
||||||
void main() {
|
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
|
||||||
gl_Position = vec4(0.f, 0.f, 0.f, 1.f);
|
})");
|
||||||
gl_PointSize = 1.0;
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
|
|
||||||
wgpu::ShaderModule fsModule =
|
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
|
[[set(0), binding(0)]] var<uniform_constant> samp : sampler_comparison;
|
||||||
#version 450
|
[[set(0), binding(1)]] var<uniform_constant> tex : texture_depth_2d;
|
||||||
layout(set = 0, binding = 0) uniform samplerShadow samp;
|
[[block]] struct Uniforms {
|
||||||
layout(set = 0, binding = 1) uniform texture2D tex;
|
[[offset(0)]] compareRef : f32;
|
||||||
layout(set = 0, binding = 2) uniform Uniforms {
|
|
||||||
float compareRef;
|
|
||||||
};
|
};
|
||||||
|
[[set(0), binding(2)]] var<uniform> uniforms : Uniforms;
|
||||||
|
|
||||||
layout(location = 0) out float samplerResult;
|
[[location(0)]] var<out> samplerResult : f32;
|
||||||
|
|
||||||
void main() {
|
[[stage(fragment)]] fn main() -> void {
|
||||||
samplerResult = texture(sampler2DShadow(tex, samp), vec3(0.5, 0.5, compareRef));
|
samplerResult = textureSampleCompare(tex, samp, vec2<f32>(0.5, 0.5), uniforms.compareRef);
|
||||||
}
|
})");
|
||||||
)");
|
|
||||||
|
|
||||||
// TODO(dawn:367): Cannot use GetBindGroupLayout for comparison samplers without shader
|
// TODO(dawn:367): Cannot use GetBindGroupLayout for comparison samplers without shader
|
||||||
// reflection data.
|
// reflection data.
|
||||||
|
@ -226,22 +218,22 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
wgpu::ComputePipeline CreateComparisonComputePipeline() {
|
wgpu::ComputePipeline CreateComparisonComputePipeline() {
|
||||||
wgpu::ShaderModule csModule =
|
wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||||
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"(
|
[[set(0), binding(0)]] var<uniform_constant> samp : sampler_comparison;
|
||||||
#version 450
|
[[set(0), binding(1)]] var<uniform_constant> tex : texture_depth_2d;
|
||||||
layout(set = 0, binding = 0) uniform samplerShadow samp;
|
[[block]] struct Uniforms {
|
||||||
layout(set = 0, binding = 1) uniform texture2D tex;
|
[[offset(0)]] compareRef : f32;
|
||||||
layout(set = 0, binding = 2) uniform Uniforms {
|
|
||||||
float compareRef;
|
|
||||||
};
|
|
||||||
layout(set = 0, binding = 3) writeonly buffer SamplerResult {
|
|
||||||
float samplerResult;
|
|
||||||
};
|
};
|
||||||
|
[[set(0), binding(2)]] var<uniform> uniforms : Uniforms;
|
||||||
|
|
||||||
void main() {
|
[[block]] struct SamplerResult {
|
||||||
samplerResult = texture(sampler2DShadow(tex, samp), vec3(0.5, 0.5, compareRef));
|
[[offset(0)]] value : f32;
|
||||||
}
|
};
|
||||||
)");
|
[[set(0), binding(3)]] var<storage_buffer> samplerResult : SamplerResult;
|
||||||
|
|
||||||
|
[[stage(compute)]] fn main() -> void {
|
||||||
|
samplerResult.value = textureSampleCompare(tex, samp, vec2<f32>(0.5, 0.5), uniforms.compareRef);
|
||||||
|
})");
|
||||||
|
|
||||||
// TODO(dawn:367): Cannot use GetBindGroupLayout without shader reflection data.
|
// TODO(dawn:367): Cannot use GetBindGroupLayout without shader reflection data.
|
||||||
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
|
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
|
||||||
|
@ -310,9 +302,6 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
std::vector<T> expectedValues) {
|
std::vector<T> expectedValues) {
|
||||||
ASSERT(textureValues.size() == expectedValues.size());
|
ASSERT(textureValues.size() == expectedValues.size());
|
||||||
|
|
||||||
wgpu::SamplerDescriptor samplerDesc;
|
|
||||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
|
||||||
|
|
||||||
wgpu::Texture outputTexture;
|
wgpu::Texture outputTexture;
|
||||||
wgpu::Texture inputTexture = CreateInputTexture(format);
|
wgpu::Texture inputTexture = CreateInputTexture(format);
|
||||||
wgpu::TextureViewDescriptor inputViewDesc = {};
|
wgpu::TextureViewDescriptor inputViewDesc = {};
|
||||||
|
@ -327,12 +316,8 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wgpu::BindGroup bindGroup =
|
wgpu::BindGroup bindGroup = utils::MakeBindGroup(
|
||||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
device, pipeline.GetBindGroupLayout(0), {{0, inputTexture.CreateView(&inputViewDesc)}});
|
||||||
{
|
|
||||||
{0, sampler},
|
|
||||||
{1, inputTexture.CreateView(&inputViewDesc)},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (size_t i = 0; i < textureValues.size(); ++i) {
|
for (size_t i = 0; i < textureValues.size(); ++i) {
|
||||||
// Set the input depth texture to the provided texture value
|
// Set the input depth texture to the provided texture value
|
||||||
|
@ -371,9 +356,6 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
std::vector<T> expectedValues) {
|
std::vector<T> expectedValues) {
|
||||||
ASSERT(textureValues.size() == expectedValues.size());
|
ASSERT(textureValues.size() == expectedValues.size());
|
||||||
|
|
||||||
wgpu::SamplerDescriptor samplerDesc;
|
|
||||||
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
|
|
||||||
|
|
||||||
wgpu::Texture inputTexture = CreateInputTexture(format);
|
wgpu::Texture inputTexture = CreateInputTexture(format);
|
||||||
wgpu::TextureViewDescriptor inputViewDesc = {};
|
wgpu::TextureViewDescriptor inputViewDesc = {};
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
|
@ -387,9 +369,9 @@ class DepthStencilSamplingTest : public DawnTest {
|
||||||
|
|
||||||
wgpu::Buffer outputBuffer = CreateOutputBuffer();
|
wgpu::Buffer outputBuffer = CreateOutputBuffer();
|
||||||
|
|
||||||
wgpu::BindGroup bindGroup = utils::MakeBindGroup(
|
wgpu::BindGroup bindGroup =
|
||||||
device, pipeline.GetBindGroupLayout(0),
|
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||||
{{0, sampler}, {1, inputTexture.CreateView(&inputViewDesc)}, {2, outputBuffer}});
|
{{0, inputTexture.CreateView(&inputViewDesc)}, {1, outputBuffer}});
|
||||||
|
|
||||||
for (size_t i = 0; i < textureValues.size(); ++i) {
|
for (size_t i = 0; i < textureValues.size(); ++i) {
|
||||||
// Set the input depth texture to the provided texture value
|
// Set the input depth texture to the provided texture value
|
||||||
|
@ -644,9 +626,8 @@ TEST_P(DepthStencilSamplingTest, SampleDepthAndStencilRender) {
|
||||||
wgpu::BindGroup bindGroup =
|
wgpu::BindGroup bindGroup =
|
||||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||||
{
|
{
|
||||||
{0, sampler},
|
{0, inputTexture.CreateView(&depthViewDesc)},
|
||||||
{1, inputTexture.CreateView(&depthViewDesc)},
|
{1, inputTexture.CreateView(&stencilViewDesc)},
|
||||||
{2, inputTexture.CreateView(&stencilViewDesc)},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
wgpu::Texture depthOutput = CreateOutputTexture(wgpu::TextureFormat::R32Float);
|
wgpu::Texture depthOutput = CreateOutputTexture(wgpu::TextureFormat::R32Float);
|
||||||
|
@ -691,11 +672,10 @@ TEST_P(DepthStencilSamplingTest, SampleDepthAndStencilRender) {
|
||||||
|
|
||||||
wgpu::BindGroup bindGroup =
|
wgpu::BindGroup bindGroup =
|
||||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||||
{{0, sampler},
|
{{0, inputTexture.CreateView(&depthViewDesc)},
|
||||||
{1, inputTexture.CreateView(&depthViewDesc)},
|
{1, depthOutput},
|
||||||
{2, depthOutput},
|
{2, inputTexture.CreateView(&stencilViewDesc)},
|
||||||
{3, inputTexture.CreateView(&stencilViewDesc)},
|
{3, stencilOutput}});
|
||||||
{4, stencilOutput}});
|
|
||||||
|
|
||||||
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
|
||||||
// Initialize both depth and stencil aspects.
|
// Initialize both depth and stencil aspects.
|
||||||
|
|
Loading…
Reference in New Issue