From d10774c42f7fac99e66e343e0ee395092101ce58 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 17 Dec 2020 19:41:57 +0000 Subject: [PATCH] Update DynamicBufferOffsetTests to use WGSL Bug: dawn:572 Change-Id: I73d987e8ab09120014d2d5c802bd08f08c33bdbd Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33775 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez --- .../end2end/DynamicBufferOffsetTests.cpp | 125 +++++++++++------- 1 file changed, 76 insertions(+), 49 deletions(-) diff --git a/src/tests/end2end/DynamicBufferOffsetTests.cpp b/src/tests/end2end/DynamicBufferOffsetTests.cpp index 7984c4f7b7..c433a9a5f3 100644 --- a/src/tests/end2end/DynamicBufferOffsetTests.cpp +++ b/src/tests/end2end/DynamicBufferOffsetTests.cpp @@ -93,51 +93,67 @@ class DynamicBufferOffsetTests : public DawnTest { wgpu::Texture mColorAttachment; wgpu::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) { - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( - #version 450 - void main() { - const vec2 pos[3] = vec2[3](vec2(-1.0f, 0.0f), vec2(-1.0f, 1.0f), vec2(0.0f, 1.0f)); - gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0); - })"); + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[builtin(vertex_idx)]] var VertexIndex : u32; + [[builtin(position)]] var Position : vec4; + [[stage(vertex)]] fn main() -> void { + const pos : array, 3> = array, 3>( + vec2(-1.0, 0.0), + vec2(-1.0, 1.0), + vec2( 0.0, 1.0)); + Position = vec4(pos[VertexIndex], 0.0, 1.0); + })"); // Construct fragment shader source std::ostringstream fs; std::string multipleNumber = isInheritedPipeline ? "2" : "1"; fs << R"( - #version 450 - layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic { - uvec2 notDynamicValue; + # TODO(crbug.com/tint/386): Use the same struct. + [[block]] struct Buffer1 { + [[offset(0)]] value : vec2; }; - layout(std140, set = 0, binding = 1) buffer sBufferNotDynamic { - uvec2 notDynamicResult; - } mid; - layout(std140, set = 0, binding = 3) uniform uBuffer { - uvec2 value; + + [[block]] struct Buffer2 { + [[offset(0)]] value : vec2; }; - layout(std140, set = 0, binding = 4) buffer SBuffer { - uvec2 result; - } sBuffer; + + [[block]] struct Buffer3 { + [[offset(0)]] value : vec2; + }; + + [[block]] struct Buffer4 { + [[offset(0)]] value : vec2; + }; + + [[set(0), binding(0)]] var uBufferNotDynamic : Buffer1; + [[set(0), binding(1)]] var sBufferNotDynamic : [[access(read_write)]] Buffer2; + [[set(0), binding(3)]] var uBuffer : Buffer3; + [[set(0), binding(4)]] var sBuffer : [[access(read_write)]] Buffer4; )"; if (isInheritedPipeline) { fs << R"( - layout(std140, set = 1, binding = 0) uniform paddingBlock { - uvec2 padding; + [[block]] struct Buffer5 { + [[offset(0)]] value : vec2; }; + + [[set(1), binding(0)]] var paddingBlock : Buffer5; )"; } - fs << " layout(location = 0) out vec4 fragColor;\n"; - fs << " void main() {\n"; - fs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n"; - fs << " sBuffer.result.xy = " << multipleNumber - << " * (value.xy + mid.notDynamicResult.xy);\n"; - fs << " fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);\n"; - fs << " }\n"; + fs << "[[location(0)]] var fragColor : vec4;\n"; - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs.str().c_str()); + fs << "const multipleNumber : u32 = " << multipleNumber << "u;\n"; + fs << R"( + [[stage(fragment)]] fn main() -> void { + sBufferNotDynamic.value = uBufferNotDynamic.value.xy; + sBuffer.value = vec2(multipleNumber, multipleNumber) * (uBuffer.value.xy + sBufferNotDynamic.value.xy); + fragColor = vec4(f32(uBuffer.value.x) / 255.0, f32(uBuffer.value.y) / 255.0, + 1.0, 1.0); + } + )"; + + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, fs.str().c_str()); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); pipelineDescriptor.vertexStage.module = vsModule; @@ -161,37 +177,48 @@ class DynamicBufferOffsetTests : public DawnTest { std::ostringstream cs; std::string multipleNumber = isInheritedPipeline ? "2" : "1"; cs << R"( - #version 450 - layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic { - uvec2 notDynamicValue; + # TODO(crbug.com/tint/386): Use the same struct. + [[block]] struct Buffer1 { + [[offset(0)]] value : vec2; }; - layout(std140, set = 0, binding = 1) buffer sBufferNotDynamic { - uvec2 notDynamicResult; - } mid; - layout(std140, set = 0, binding = 3) uniform uBuffer { - uvec2 value; + + [[block]] struct Buffer2 { + [[offset(0)]] value : vec2; }; - layout(std140, set = 0, binding = 4) buffer SBuffer { - uvec2 result; - } sBuffer; + + [[block]] struct Buffer3 { + [[offset(0)]] value : vec2; + }; + + [[block]] struct Buffer4 { + [[offset(0)]] value : vec2; + }; + + [[set(0), binding(0)]] var uBufferNotDynamic : Buffer1; + [[set(0), binding(1)]] var sBufferNotDynamic : [[access(read_write)]] Buffer2; + [[set(0), binding(3)]] var uBuffer : Buffer3; + [[set(0), binding(4)]] var sBuffer : [[access(read_write)]] Buffer4; )"; if (isInheritedPipeline) { cs << R"( - layout(std140, set = 1, binding = 0) uniform paddingBlock { - uvec2 padding; + [[block]] struct Buffer5 { + [[offset(0)]] value : vec2; }; + + [[set(1), binding(0)]] var paddingBlock : Buffer5; )"; } - cs << " void main() {\n"; - cs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n"; - cs << " sBuffer.result.xy = " << multipleNumber - << " * (value.xy + mid.notDynamicResult.xy);\n"; - cs << " }\n"; + cs << "const multipleNumber : u32 = " << multipleNumber << "u;\n"; + cs << R"( + [[stage(compute)]] fn main() -> void { + sBufferNotDynamic.value = uBufferNotDynamic.value.xy; + sBuffer.value = vec2(multipleNumber, multipleNumber) * (uBuffer.value.xy + sBufferNotDynamic.value.xy); + } + )"; - wgpu::ShaderModule csModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs.str().c_str()); + wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, cs.str().c_str()); wgpu::ComputePipelineDescriptor csDesc; csDesc.computeStage.module = csModule;