Port D3D12 white box tests to WGSL.

Bug: dawn:572
Change-Id: I91cc56847c4970c3f32697738edb799f7468e76f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/44760
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Corentin Wallez 2021-03-16 10:00:44 +00:00 committed by Commit Bot service account
parent debab92fac
commit 36f19daa7d
2 changed files with 90 additions and 74 deletions

View File

@ -39,22 +39,29 @@ class D3D12DescriptorHeapTests : public DawnTest {
DAWN_SKIP_TEST_IF(UsesWire()); DAWN_SKIP_TEST_IF(UsesWire());
mD3DDevice = reinterpret_cast<Device*>(device.Get()); mD3DDevice = reinterpret_cast<Device*>(device.Get());
mSimpleVSModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( mSimpleVSModule = utils::CreateShaderModuleFromWGSL(device, R"(
#version 450 [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[builtin(vertex_index)]] var<in> VertexIndex : u32;
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f));
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
})");
mSimpleFSModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[stage(vertex)]] fn main() -> void {
#version 450 const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
layout (location = 0) out vec4 fragColor; vec2<f32>(-1.0, 1.0),
layout (set = 0, binding = 0) uniform colorBuffer { vec2<f32>( 1.0, 1.0),
vec4 color; vec2<f32>(-1.0, -1.0)
}; );
void main() { Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
fragColor = color; })");
})");
mSimpleFSModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[block]] struct U {
color : vec4<f32>;
};
[[group(0), binding(0)]] var<uniform> colorBuffer : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
FragColor = colorBuffer.color;
})");
} }
utils::BasicRenderPass MakeRenderPass(uint32_t width, utils::BasicRenderPass MakeRenderPass(uint32_t width,
@ -169,19 +176,17 @@ TEST_P(D3D12DescriptorHeapTests, NoSwitchOverSamplerHeap) {
// Fill in a sampler heap with "sampler only" bindgroups (1x sampler per group) by creating a // Fill in a sampler heap with "sampler only" bindgroups (1x sampler per group) by creating a
// sampler bindgroup each draw. After HEAP_SIZE + 1 draws, the heaps WILL NOT switch over // sampler bindgroup each draw. After HEAP_SIZE + 1 draws, the heaps WILL NOT switch over
// because the sampler heap allocations are de-duplicated. // because the sampler heap allocations are de-duplicated.
renderPipelineDescriptor.vertexStage.module = renderPipelineDescriptor.vertexStage.module = 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);
})"); })");
renderPipelineDescriptor.cFragmentStage.module = renderPipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(#version 450 [[location(0)]] var<out> FragColor : vec4<f32>;
layout(set = 0, binding = 0) uniform sampler sampler0; [[group(0), binding(0)]] var sampler0 : sampler;
layout(location = 0) out vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() { FragColor = vec4<f32>(0.0, 0.0, 0.0, 0.0);
fragColor = vec4(0.0, 0.0, 0.0, 0.0);
})"); })");
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor); wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
@ -440,15 +445,15 @@ TEST_P(D3D12DescriptorHeapTests, EncodeManyUBO) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = mSimpleVSModule; pipelineDescriptor.vertexStage.module = mSimpleVSModule;
pipelineDescriptor.cFragmentStage.module = pipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[block]] struct U {
#version 450 heapSize : f32;
layout (location = 0) out float fragColor;
layout (set = 0, binding = 0) uniform buffer0 {
float heapSize;
}; };
void main() { [[group(0), binding(0)]] var<uniform> buffer0 : U;
fragColor = heapSize; [[location(0)]] var<out> FragColor : f32;
[[stage(fragment)]] fn main() -> void {
FragColor = buffer0.heapSize;
})"); })");
pipelineDescriptor.cColorStates[0].format = wgpu::TextureFormat::R32Float; pipelineDescriptor.cColorStates[0].format = wgpu::TextureFormat::R32Float;
@ -770,30 +775,36 @@ TEST_P(D3D12DescriptorHeapTests, EncodeManyUBOAndSamplers) {
{ {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = pipelineDescriptor.vertexStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[block]] struct U {
#version 450 transform : mat2x2<f32>;
layout (set = 0, binding = 0) uniform vertexUniformBuffer { };
mat2 transform; [[group(0), binding(0)]] var<uniform> buffer0 : U;
}; [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[builtin(vertex_index)]] var<in> VertexIndex : u32;
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f));
gl_Position = vec4(transform * pos[gl_VertexIndex], 0.f, 1.f);
})");
pipelineDescriptor.cFragmentStage.module = [[stage(vertex)]] fn main() -> void {
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
#version 450 vec2<f32>(-1.0, 1.0),
layout (set = 0, binding = 1) uniform sampler sampler0; vec2<f32>( 1.0, 1.0),
layout (set = 0, binding = 2) uniform texture2D texture0; vec2<f32>(-1.0, -1.0)
layout (set = 0, binding = 3) uniform buffer0 { );
vec4 color; Position = vec4<f32>(buffer0.transform * (pos[VertexIndex]), 0.0, 1.0);
}; })");
layout (location = 0) out vec4 fragColor; pipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
void main() { [[block]] struct U {
fragColor = texture(sampler2D(texture0, sampler0), gl_FragCoord.xy); color : vec4<f32>;
fragColor += color; };
})"); [[group(0), binding(1)]] var sampler0 : sampler;
[[group(0), binding(2)]] var texture0 : texture_2d<f32>;
[[group(0), binding(3)]] var<uniform> buffer0 : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
FragColor = textureSample(texture0, sampler0, FragCoord.xy) + buffer0.color;
})");
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat; pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;

View File

@ -334,24 +334,29 @@ TEST_P(D3D12DescriptorResidencyTests, SwitchedViewHeapResidency) {
// Fill in a view heap with "view only" bindgroups (1x view per group) by creating a // Fill in a view heap with "view only" bindgroups (1x view per group) by creating a
// view bindgroup each draw. After HEAP_SIZE + 1 draws, the heaps must switch over. // view bindgroup each draw. After HEAP_SIZE + 1 draws, the heaps must switch over.
renderPipelineDescriptor.vertexStage.module = renderPipelineDescriptor.vertexStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[builtin(position)]] var<out> Position : vec4<f32>;
#version 450 [[builtin(vertex_index)]] var<in> VertexIndex : u32;
void main() {
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f));
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
})");
renderPipelineDescriptor.cFragmentStage.module = [[stage(vertex)]] fn main() -> void {
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
#version 450 vec2<f32>(-1.0, 1.0),
layout (location = 0) out vec4 fragColor; vec2<f32>( 1.0, 1.0),
layout (set = 0, binding = 0) uniform colorBuffer { vec2<f32>(-1.0, -1.0)
vec4 color; );
}; Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
void main() { })");
fragColor = color;
})"); renderPipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
[[block]] struct U {
color : vec4<f32>;
};
[[group(0), binding(0)]] var<uniform> colorBuffer : U;
[[location(0)]] var<out> FragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
FragColor = colorBuffer.color;
})");
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor); wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
constexpr uint32_t kSize = 512; constexpr uint32_t kSize = 512;