From 33bf309c1d45e4da80ba77913eab9dadfc8f5e26 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 22 Dec 2020 20:11:48 +0000 Subject: [PATCH] Update OpArrayLengthTests to use WGSL Bug: dawn:572 Change-Id: Iba92adda4758fc91294f7c6d8b0be3065c786f71 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33773 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez --- src/tests/end2end/OpArrayLengthTests.cpp | 129 +++++++++++------------ 1 file changed, 63 insertions(+), 66 deletions(-) diff --git a/src/tests/end2end/OpArrayLengthTests.cpp b/src/tests/end2end/OpArrayLengthTests.cpp index 884378cdc9..8cb1e1fc95 100644 --- a/src/tests/end2end/OpArrayLengthTests.cpp +++ b/src/tests/end2end/OpArrayLengthTests.cpp @@ -56,23 +56,33 @@ class OpArrayLengthTest : public DawnTest { // Common shader code to use these buffers in shaders, assuming they are in bindgroup index // 0. mShaderInterface = R"( - // The length should be 1 because the buffer is 4-byte long. - layout(std430, set = 0, binding = 0) readonly buffer Buffer1 { - float data[]; - } buffer1; + # TODO(crbug.com/tint/386): Use the same struct. + [[block]] struct DataBuffer1 { + [[offset(0)]] data : [[stride(4)]] array; + }; - // The length should be 64 because the buffer is 256 bytes long. - layout(std430, set = 0, binding = 1) readonly buffer Buffer2 { - float data[]; - } buffer2; + [[block]] struct DataBuffer2 { + [[offset(0)]] data : [[stride(4)]] array; + }; - // The length should be (512 - 16*4) / 8 = 56 because the buffer is 512 bytes long - // and the structure is 8 bytes big. - struct Buffer3Data {float a; int b;}; - layout(std430, set = 0, binding = 2) readonly buffer Buffer3 { - mat4 garbage; - Buffer3Data data[]; - } buffer3; + # The length should be 1 because the buffer is 4-byte long. + [[set(0), binding(0)]] var buffer1 : [[access(read)]] DataBuffer1; + + # The length should be 64 because the buffer is 256 bytes long. + [[set(0), binding(1)]] var buffer2 : [[access(read)]] DataBuffer2; + + # The length should be (512 - 16*4) / 8 = 56 because the buffer is 512 bytes long + # and the structure is 8 bytes big. + struct Buffer3Data { + [[offset(0)]] a : f32; + [[offset(4)]] b : i32; + }; + + [[block]] struct Buffer3 { + [[offset(0)]] garbage : mat4x4; + [[offset(64)]] data : [[stride(8)]] array; + }; + [[set(0), binding(2)]] var buffer3 : [[access(read)]] Buffer3; )"; // See comments in the shader for an explanation of these values @@ -118,19 +128,18 @@ TEST_P(OpArrayLengthTest, Compute) { wgpu::ComputePipelineDescriptor pipelineDesc; pipelineDesc.layout = pl; pipelineDesc.computeStage.entryPoint = "main"; - pipelineDesc.computeStage.module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, - (R"(#version 450 - layout(std430, set = 1, binding = 0) buffer ResultBuffer { - uint result[3]; - }; - )" + mShaderInterface + R"( - void main() { - result[0] = buffer1.data.length(); - result[1] = buffer2.data.length(); - result[2] = buffer3.data.length(); - })") - .c_str()); + pipelineDesc.computeStage.module = utils::CreateShaderModuleFromWGSL(device, (R"( + [[block]] struct ResultBuffer { + [[offset(0)]] data : [[stride(4)]] array; + }; + [[set(1), binding(0)]] var result : [[access(read_write)]] ResultBuffer; + )" + mShaderInterface + R"( + [[stage(compute)]] fn main() -> void { + result.data[0] = arrayLength(buffer1.data); + result.data[1] = arrayLength(buffer2.data); + result.data[2] = arrayLength(buffer3.data); + })") + .c_str()); wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc); // Run a single instance of the compute shader @@ -159,27 +168,21 @@ TEST_P(OpArrayLengthTest, Fragment) { // Create the pipeline that computes the length of the buffers and writes it to the only render // pass pixel. - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( - #version 450 - void main() { - gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f); - gl_PointSize = 1.0; + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[builtin(position)]] var Position : vec4; + [[stage(vertex)]] fn main() -> void { + Position = vec4(0.0, 0.0, 0.0, 1.0); })"); - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, - (R"( - #version 450 - )" + mShaderInterface + R"( - layout(location = 0) out vec4 fragColor; - void main() { - fragColor.r = buffer1.data.length() / 255.0f; - fragColor.g = buffer2.data.length() / 255.0f; - fragColor.b = buffer3.data.length() / 255.0f; - fragColor.a = 0.0f; + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, (mShaderInterface + R"( + [[location(0)]] var fragColor : vec4; + [[stage(fragment)]] fn main() -> void { + fragColor.r = f32(arrayLength(buffer1.data)) / 255.0; + fragColor.g = f32(arrayLength(buffer2.data)) / 255.0; + fragColor.b = f32(arrayLength(buffer3.data)) / 255.0; + fragColor.a = 0.0; })") - .c_str()); + .c_str()); utils::ComboRenderPipelineDescriptor descriptor(device); descriptor.vertexStage.module = vsModule; @@ -217,29 +220,23 @@ TEST_P(OpArrayLengthTest, Vertex) { // Create the pipeline that computes the length of the buffers and writes it to the only render // pass pixel. - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, - (R"( - #version 450 - )" + mShaderInterface + R"( - layout(location = 0) out vec4 pointColor; - void main() { - pointColor.r = buffer1.data.length() / 255.0f; - pointColor.g = buffer2.data.length() / 255.0f; - pointColor.b = buffer3.data.length() / 255.0f; - pointColor.a = 0.0f; + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, (mShaderInterface + R"( + [[location(0)]] var pointColor : vec4; + [[builtin(position)]] var Position : vec4; + [[stage(vertex)]] fn main() -> void { + pointColor.r = f32(arrayLength(buffer1.data)) / 255.0; + pointColor.g = f32(arrayLength(buffer2.data)) / 255.0; + pointColor.b = f32(arrayLength(buffer3.data)) / 255.0; + pointColor.a = 0.0; - gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f); - gl_PointSize = 1.0; + Position = vec4(0.0, 0.0, 0.0, 1.0); })") - .c_str()); + .c_str()); - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( - #version 450 - layout(location = 0) out vec4 fragColor; - layout(location = 0) in vec4 pointColor; - void main() { + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[location(0)]] var fragColor : vec4; + [[location(0)]] var pointColor : vec4; + [[stage(fragment)]] fn main() -> void { fragColor = pointColor; })");