From 584ba432e988e6c94ef5e7fc158e10fac24eefe7 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 25 Feb 2021 16:14:01 +0000 Subject: [PATCH] Update ComputeCopyStorageBufferTests to use WGSL Bug: dawn:572 Change-Id: If5cce116540bd4298824e3801ee48b2197269cd4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32505 Reviewed-by: Corentin Wallez Reviewed-by: Ben Clayton Commit-Queue: Austin Eng --- .../end2end/ComputeCopyStorageBufferTests.cpp | 120 ++++++++---------- 1 file changed, 52 insertions(+), 68 deletions(-) diff --git a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp index 5c8de7372a..f54e15d832 100644 --- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp +++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp @@ -29,7 +29,7 @@ class ComputeCopyStorageBufferTests : public DawnTest { void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { // Set up shader and pipeline - auto module = utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, shader); + auto module = utils::CreateShaderModuleFromWGSL(device, shader); wgpu::ComputePipelineDescriptor csDesc; csDesc.computeStage.module = module; @@ -88,13 +88,22 @@ void ComputeCopyStorageBufferTests::BasicTest(const char* shader) { // Test that a trivial compute-shader memcpy implementation works. TEST_P(ComputeCopyStorageBufferTests, SizedArrayOfBasic) { BasicTest(R"( - #version 450 - #define kInstances 4 - layout(std140, set = 0, binding = 0) buffer Src { uvec4 s[kInstances]; } src; - layout(std140, set = 0, binding = 1) buffer Dst { uvec4 s[kInstances]; } dst; - void main() { - uint index = gl_GlobalInvocationID.x; - if (index >= kInstances) { return; } + [[block]] struct Buf1 { + [[offset(0)]] s : [[stride(16)]] array, 4>; + }; + [[block]] struct Buf2 { + [[offset(0)]] s : [[stride(16)]] array, 4>; + }; + + // TODO(crbug.com/tint/386): Use the same struct type + [[set(0), binding(0)]] var src : Buf1; + [[set(0), binding(1)]] var dst : Buf2; + + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + var index : u32 = GlobalInvocationID.x; + if (index >= 4) { return; } dst.s[index] = src.s[index]; })"); } @@ -102,79 +111,54 @@ TEST_P(ComputeCopyStorageBufferTests, SizedArrayOfBasic) { // Test that a slightly-less-trivial compute-shader memcpy implementation works. TEST_P(ComputeCopyStorageBufferTests, SizedArrayOfStruct) { BasicTest(R"( - #version 450 - #define kInstances 4 struct S { - uvec2 a, b; // kUintsPerInstance = 4 + [[offset(0)]] a : vec2; + [[offset(8)]] b : vec2; }; - layout(std140, set = 0, binding = 0) buffer Src { S s[kInstances]; } src; - layout(std140, set = 0, binding = 1) buffer Dst { S s[kInstances]; } dst; - void main() { - uint index = gl_GlobalInvocationID.x; - if (index >= kInstances) { return; } + + [[block]] struct Buf1 { + [[offset(0)]] s : [[stride(16)]] array; + }; + [[block]] struct Buf2 { + [[offset(0)]] s : [[stride(16)]] array; + }; + + // TODO(crbug.com/tint/386): Use the same struct type + [[set(0), binding(0)]] var src : Buf1; + [[set(0), binding(1)]] var dst : Buf2; + + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + var index : u32 = GlobalInvocationID.x; + if (index >= 4) { return; } dst.s[index] = src.s[index]; })"); } // Test that a trivial compute-shader memcpy implementation works. TEST_P(ComputeCopyStorageBufferTests, UnsizedArrayOfBasic) { - // TODO(crbug.com/tint/400) - // Tint transform failure: error: invalid 0 size for array or vector - DAWN_SKIP_TEST_IF(HasToggleEnabled("use_tint_generator")); BasicTest(R"( - #version 450 - #define kInstances 4 - layout(std140, set = 0, binding = 0) buffer Src { uvec4 s[]; } src; - layout(std140, set = 0, binding = 1) buffer Dst { uvec4 s[]; } dst; - void main() { - uint index = gl_GlobalInvocationID.x; - if (index >= kInstances) { return; } + [[block]] struct Buf1 { + [[offset(0)]] s : [[stride(16)]] array>; + }; + [[block]] struct Buf2 { + [[offset(0)]] s : [[stride(16)]] array>; + }; + + // TODO(crbug.com/tint/386): Use the same struct type + [[set(0), binding(0)]] var src : Buf1; + [[set(0), binding(1)]] var dst : Buf2; + + [[builtin(global_invocation_id)]] var GlobalInvocationID : vec3; + + [[stage(compute)]] fn main() -> void { + var index : u32 = GlobalInvocationID.x; + if (index >= 4) { return; } dst.s[index] = src.s[index]; })"); } -// Test binding a sized array of SSBO descriptors. -// -// This is disabled because WebGPU doesn't currently have binding arrays (equivalent to -// VkDescriptorSetLayoutBinding::descriptorCount). https://github.com/gpuweb/gpuweb/pull/61 -TEST_P(ComputeCopyStorageBufferTests, DISABLED_SizedDescriptorArray) { - BasicTest(R"( - #version 450 - #define kInstances 4 - struct S { - uvec2 a, b; // kUintsPerInstance = 4 - }; - layout(std140, set = 0, binding = 0) buffer Src { S s; } src[kInstances]; - layout(std140, set = 0, binding = 1) buffer Dst { S s; } dst[kInstances]; - void main() { - uint index = gl_GlobalInvocationID.x; - if (index >= kInstances) { return; } - dst[index].s = src[index].s; - })"); -} - -// Test binding an unsized array of SSBO descriptors. -// -// TODO(kainino@chromium.org): This test may be somewhat wrong. I'm not sure whether this is -// supposed to be possible on the various native APIs. -// Linking on OpenGL fails with "OpenGL requires constant indexes for unsized array access(dst)". -TEST_P(ComputeCopyStorageBufferTests, DISABLED_UnsizedDescriptorArray) { - BasicTest(R"( - #version 450 - #extension GL_EXT_nonuniform_qualifier : require - #define kInstances 4 - struct S { - uvec2 a, b; // kUintsPerInstance = 4 - }; - layout(std140, set = 0, binding = 0) buffer Src { S s; } src[]; - layout(std140, set = 0, binding = 1) buffer Dst { S s; } dst[]; - void main() { - uint index = gl_GlobalInvocationID.x; - if (index >= kInstances) { return; } - dst[index].s = src[index].s; - })"); -} - DAWN_INSTANTIATE_TEST(ComputeCopyStorageBufferTests, D3D12Backend(), MetalBackend(),