Port the last BufferZeroInitTest to WGSL

It required storageBarrier() to be implemented in Tint.

Bug: dawn:572
Change-Id: I62e8d89ef7a049044f3381dc66163466d62c839d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/45604
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Corentin Wallez 2021-03-23 16:52:31 +00:00 committed by Commit Bot service account
parent be621bd0e6
commit 83ee832ebd
1 changed files with 23 additions and 39 deletions

View File

@ -200,15 +200,6 @@ class BufferZeroInitTest : public DawnTest {
EXPECT_PIXEL_RGBA8_EQ(kExpectedColor, outputTexture, 0u, 0u); EXPECT_PIXEL_RGBA8_EQ(kExpectedColor, outputTexture, 0u, 0u);
} }
void TestBufferZeroInitInBindGroup(const char* glslComputeShader,
uint64_t bufferOffset,
uint64_t boundBufferSize,
const std::vector<uint32_t>& expectedBufferData) {
return TestBufferZeroInitInBindGroup(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, glslComputeShader),
bufferOffset, boundBufferSize, expectedBufferData);
}
wgpu::RenderPipeline CreateRenderPipelineForTest(const char* vertexShader, wgpu::RenderPipeline CreateRenderPipelineForTest(const char* vertexShader,
uint32_t vertexBufferCount = 1u) { uint32_t vertexBufferCount = 1u) {
constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm;
@ -992,7 +983,8 @@ TEST_P(BufferZeroInitTest, BoundAsUniformBuffer) {
// TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES. // TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES.
DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled()); DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled());
const char* computeShader = R"( constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[block]] struct UBO { [[block]] struct UBO {
value : vec4<u32>; value : vec4<u32>;
}; };
@ -1006,11 +998,7 @@ TEST_P(BufferZeroInitTest, BoundAsUniformBuffer) {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0)); textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
} }
} }
)"; )");
constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, computeShader);
// Bind the whole buffer // Bind the whole buffer
{ {
@ -1034,7 +1022,8 @@ TEST_P(BufferZeroInitTest, BoundAsReadonlyStorageBuffer) {
// TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES. // TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES.
DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled()); DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled());
const char* computeShader = R"( constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[block]] struct SSBO { [[block]] struct SSBO {
value : vec4<u32>; value : vec4<u32>;
}; };
@ -1048,10 +1037,7 @@ TEST_P(BufferZeroInitTest, BoundAsReadonlyStorageBuffer) {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0)); textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
} }
} }
)"; )");
constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, computeShader);
// Bind the whole buffer // Bind the whole buffer
{ {
@ -1075,37 +1061,35 @@ TEST_P(BufferZeroInitTest, BoundAsStorageBuffer) {
// TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES. // TODO(crbug.com/dawn/661): Diagnose and fix this backend validation failure on GLES.
DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled()); DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled());
// TODO(crbug.com/tint/375): Enable once barriers are implemented constexpr uint32_t kBoundBufferSize = 32u;
DAWN_SKIP_TEST_IF(HasToggleEnabled("use_tint_generator")); wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
const char* computeShader = R"( [[block]] struct SSBO {
#version 450 value : array<vec4<u32>, 2>;
layout(set = 0, binding = 0, std140) buffer SSBO { };
uvec4 value[2]; [[group(0), binding(0)]] var<storage> ssbo : [[access(read_write)]] SSBO;
} ssbo; [[group(0), binding(1)]] var outImage : [[access(write)]] texture_storage_2d<rgba8unorm>;
layout(set = 0, binding = 1, rgba8) uniform writeonly image2D outImage;
void main() { [[stage(compute)]] fn main() -> void {
if (ssbo.value[0] == uvec4(0, 0, 0, 0) && ssbo.value[1] == uvec4(0, 0, 0, 0)) { if (all(ssbo.value[0] == vec4<u32>(0u, 0u, 0u, 0u)) &&
imageStore(outImage, ivec2(0, 0), vec4(0.f, 1.f, 0.f, 1.f)); all(ssbo.value[1] == vec4<u32>(0u, 0u, 0u, 0u))) {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(0.0, 1.0, 0.0, 1.0));
} else { } else {
imageStore(outImage, ivec2(0, 0), vec4(1.f, 0.f, 0.f, 1.f)); textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
} }
memoryBarrier(); storageBarrier();
barrier();
ssbo.value[0].x = 10u; ssbo.value[0].x = 10u;
ssbo.value[1].y = 20u; ssbo.value[1].y = 20u;
} }
)"; )");
constexpr uint32_t kBoundBufferSize = 32u;
// Bind the whole buffer // Bind the whole buffer
{ {
std::vector<uint32_t> expected(kBoundBufferSize / sizeof(uint32_t), 0u); std::vector<uint32_t> expected(kBoundBufferSize / sizeof(uint32_t), 0u);
expected[0] = 10u; expected[0] = 10u;
expected[5] = 20u; expected[5] = 20u;
TestBufferZeroInitInBindGroup(computeShader, 0, kBoundBufferSize, expected); TestBufferZeroInitInBindGroup(module, 0, kBoundBufferSize, expected);
} }
// Bind a range of a buffer // Bind a range of a buffer
@ -1116,7 +1100,7 @@ TEST_P(BufferZeroInitTest, BoundAsStorageBuffer) {
(kBoundBufferSize + kOffset + kExtraBytes) / sizeof(uint32_t), 0u); (kBoundBufferSize + kOffset + kExtraBytes) / sizeof(uint32_t), 0u);
expected[kOffset / sizeof(uint32_t)] = 10u; expected[kOffset / sizeof(uint32_t)] = 10u;
expected[kOffset / sizeof(uint32_t) + 5u] = 20u; expected[kOffset / sizeof(uint32_t) + 5u] = 20u;
TestBufferZeroInitInBindGroup(computeShader, kOffset, kBoundBufferSize, expected); TestBufferZeroInitInBindGroup(module, kOffset, kBoundBufferSize, expected);
} }
} }