From 64c5d601f89b7733091222796ff3631668fb2c25 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 17 Dec 2020 19:44:07 +0000 Subject: [PATCH] Update ComputeStorageBufferBarrierTests to use WGSL Bug: dawn:572 Change-Id: I42e971b843807602ba91f5df0aa692569ec31521 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32511 Commit-Queue: Austin Eng Reviewed-by: Corentin Wallez --- .../ComputeStorageBufferBarrierTests.cpp | 111 +++++++++++------- 1 file changed, 68 insertions(+), 43 deletions(-) diff --git a/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp b/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp index 3fe9de90d7..69c228a786 100644 --- a/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp +++ b/src/tests/end2end/ComputeStorageBufferBarrierTests.cpp @@ -31,13 +31,17 @@ TEST_P(ComputeStorageBufferBarrierTests, AddIncrement) { wgpu::Buffer buffer = utils::CreateBufferFromData( device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc); - wgpu::ShaderModule module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( - #version 450 - #define kNumValues 100 - layout(std430, set = 0, binding = 0) buffer Buf { uint buf[kNumValues]; }; - void main() { - buf[gl_GlobalInvocationID.x] += 0x1234; + wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( + [[block]] struct Buf { + [[offset(0)]] data : [[stride(4)]] array; + }; + + [[set(0), binding(0)]] var buf : [[access(read_write)]] Buf; + + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + buf.data[GlobalInvocationID.x] = buf.data[GlobalInvocationID.x] + 0x1234; } )"); @@ -78,15 +82,22 @@ TEST_P(ComputeStorageBufferBarrierTests, AddPingPong) { wgpu::Buffer bufferB = utils::CreateBufferFromData( device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc); - wgpu::ShaderModule module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( - #version 450 - #define kNumValues 100 - layout(std430, set = 0, binding = 0) buffer Src { uint src[kNumValues]; }; - layout(std430, set = 0, binding = 1) buffer Dst { uint dst[kNumValues]; }; - void main() { - uint index = gl_GlobalInvocationID.x; - dst[index] = src[index] + 0x1234; + wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( + # TODO(crbug.com/tint/386): Use the same struct. + [[block]] struct Src { + [[offset(0)]] data : [[stride(4)]] array; + }; + + [[block]] struct Dst { + [[offset(0)]] data : [[stride(4)]] array; + }; + + [[set(0), binding(0)]] var src : [[access(read_write)]] Src; + [[set(0), binding(1)]] var dst : [[access(read_write)]] Dst; + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + 0x1234; } )"); @@ -142,15 +153,23 @@ TEST_P(ComputeStorageBufferBarrierTests, StorageAndReadonlyStoragePingPongInOneP wgpu::Buffer bufferB = utils::CreateBufferFromData( device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc); - wgpu::ShaderModule module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( - #version 450 - #define kNumValues 100 - layout(std430, set = 0, binding = 0) readonly buffer Src { uint src[kNumValues]; }; - layout(std430, set = 0, binding = 1) buffer Dst { uint dst[kNumValues]; }; - void main() { - uint index = gl_GlobalInvocationID.x; - dst[index] = src[index] + 0x1234; + wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( + # TODO(crbug.com/tint/386): Use the same struct. + [[block]] struct Src { + [[offset(0)]] data : [[stride(4)]] array; + }; + + [[block]] struct Dst { + [[offset(0)]] data : [[stride(4)]] array; + }; + + [[set(0), binding(0)]] var src : [[access(read)]] Src; + [[set(0), binding(1)]] var dst : [[access(read_write)]] Dst; + + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + 0x1234; } )"); @@ -208,15 +227,18 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) { device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopySrc); - wgpu::ShaderModule module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( - #version 450 - #define kNumValues 100 - layout(std140, set = 0, binding = 0) uniform Src { uvec4 src[kNumValues / 4]; }; - layout(std430, set = 0, binding = 1) buffer Dst { uvec4 dst[kNumValues / 4]; }; - void main() { - uint index = gl_GlobalInvocationID.x; - dst[index] = src[index] + 0x1234; + wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( + [[block]] struct Buf { + [[offset(0)]] data : [[stride(16)]] array, 25>; + }; + + [[set(0), binding(0)]] var src : Buf; + [[set(0), binding(1)]] var dst : [[access(read_write)]] Buf; + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + + vec4(0x1234, 0x1234, 0x1234, 0x1234); } )"); @@ -273,15 +295,18 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPongInOnePass) { device, data.data(), bufferSize, wgpu::BufferUsage::Storage | wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopySrc); - wgpu::ShaderModule module = - utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( - #version 450 - #define kNumValues 100 - layout(std140, set = 0, binding = 0) uniform Src { uvec4 src[kNumValues / 4]; }; - layout(std430, set = 0, binding = 1) buffer Dst { uvec4 dst[kNumValues / 4]; }; - void main() { - uint index = gl_GlobalInvocationID.x; - dst[index] = src[index] + 0x1234; + wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( + [[block]] struct Buf { + [[offset(0)]] data : [[stride(16)]] array, 25>; + }; + + [[set(0), binding(0)]] var src : Buf; + [[set(0), binding(1)]] var dst : [[access(read_write)]] Buf; + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + dst.data[GlobalInvocationID.x] = src.data[GlobalInvocationID.x] + + vec4(0x1234, 0x1234, 0x1234, 0x1234); } )");