Update GpuMemorySynchronizationTests to use WGSL

Bug: dawn:572
Change-Id: Ie16558bc104557603df99c9976b744a685592247
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33765
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-12-23 19:42:00 +00:00 committed by Commit Bot service account
parent a4fb42ac92
commit b3ab21e1e2
1 changed files with 121 additions and 140 deletions

View File

@ -42,15 +42,14 @@ class GpuMemorySyncTests : public DawnTest {
std::tuple<wgpu::ComputePipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForCompute( std::tuple<wgpu::ComputePipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForCompute(
const wgpu::Buffer& buffer) { const wgpu::Buffer& buffer) {
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( [[block]] struct Data {
#version 450 [[offset(0)]] a : i32;
layout(std140, set = 0, binding = 0) buffer Data { };
int a; [[set(0), binding(0)]] var<storage_buffer> data : [[access(read_write)]] Data;
} data; [[stage(compute)]] fn main() -> void {
void main() { data.a = data.a + 1;
data.a += 1; })");
})");
wgpu::ComputePipelineDescriptor cpDesc; wgpu::ComputePipelineDescriptor cpDesc;
cpDesc.computeStage.module = csModule; cpDesc.computeStage.module = csModule;
@ -65,25 +64,22 @@ class GpuMemorySyncTests : public DawnTest {
std::tuple<wgpu::RenderPipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForRender( std::tuple<wgpu::RenderPipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForRender(
const wgpu::Buffer& buffer, const wgpu::Buffer& buffer,
wgpu::TextureFormat colorFormat) { wgpu::TextureFormat colorFormat) {
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[builtin(position)]] var<out> Position : vec4<f32>;
#version 450 [[stage(vertex)]] fn main() -> void {
void main() { Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); })");
gl_PointSize = 1.0;
})");
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[block]] struct Data {
#version 450 [[offset(0)]] i : i32;
layout (set = 0, binding = 0) buffer Data { };
int i; [[set(0), binding(0)]] var<storage_buffer> data : [[access(read_write)]] Data;
} data; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() { data.i = data.i + 1;
data.i += 1; fragColor = vec4<f32>(f32(data.i) / 255.0, 0.0, 0.0, 1.0);
fragColor = vec4(data.i / 255.f, 0.f, 0.f, 1.f); })");
})");
utils::ComboRenderPipelineDescriptor rpDesc(device); utils::ComboRenderPipelineDescriptor rpDesc(device);
rpDesc.vertexStage.module = vsModule; rpDesc.vertexStage.module = vsModule;
@ -262,15 +258,14 @@ class StorageToUniformSyncTests : public DawnTest {
} }
std::tuple<wgpu::ComputePipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForCompute() { std::tuple<wgpu::ComputePipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForCompute() {
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( [[block]] struct Data {
#version 450 [[offset(0)]] a : f32;
layout(std140, set = 0, binding = 0) buffer Data { };
float a; [[set(0), binding(0)]] var<storage_buffer> data : [[access(read_write)]] Data;
} data; [[stage(compute)]] fn main() -> void {
void main() { data.a = 1.0;
data.a = 1.0; })");
})");
wgpu::ComputePipelineDescriptor cpDesc; wgpu::ComputePipelineDescriptor cpDesc;
cpDesc.computeStage.module = csModule; cpDesc.computeStage.module = csModule;
@ -284,24 +279,22 @@ class StorageToUniformSyncTests : public DawnTest {
std::tuple<wgpu::RenderPipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForRender( std::tuple<wgpu::RenderPipeline, wgpu::BindGroup> CreatePipelineAndBindGroupForRender(
wgpu::TextureFormat colorFormat) { wgpu::TextureFormat colorFormat) {
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[builtin(position)]] var<out> Position : vec4<f32>;
#version 450 [[stage(vertex)]] fn main() -> void {
void main() { Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); })");
gl_PointSize = 1.0;
})");
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[block]] struct Contents {
#version 450 [[offset(0)]] color : f32;
layout (set = 0, binding = 0) uniform Contents{ };
float color; [[set(0), binding(0)]] var<uniform> contents : Contents;
};
layout(location = 0) out vec4 fragColor; [[location(0)]] var<out> fragColor : vec4<f32>;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = vec4(color, 0.f, 0.f, 1.f); fragColor = vec4<f32>(contents.color, 0.0, 0.0, 1.0);
})"); })");
utils::ComboRenderPipelineDescriptor rpDesc(device); utils::ComboRenderPipelineDescriptor rpDesc(device);
rpDesc.vertexStage.module = vsModule; rpDesc.vertexStage.module = vsModule;
@ -464,35 +457,37 @@ class MultipleWriteThenMultipleReadTests : public DawnTest {
// operation in compute pass. // operation in compute pass.
TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) { TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
// Create pipeline, bind group, and different buffers for compute pass. // Create pipeline, bind group, and different buffers for compute pass.
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( [[block]] struct VBContents {
#version 450 [[offset(0)]] pos : [[stride(16)]] array<vec4<f32>, 4>;
layout(std140, set = 0, binding = 0) buffer VBContents {
vec4 pos[4];
}; };
[[set(0), binding(0)]] var<storage_buffer> vbContents : [[access(read_write)]] VBContents;
layout(std140, set = 0, binding = 1) buffer IBContents { [[block]] struct IBContents {
ivec4 indices[2]; [[offset(0)]] indices : [[stride(16)]] array<vec4<i32>, 2>;
}; };
[[set(0), binding(1)]] var<storage_buffer> ibContents : [[access(read_write)]] IBContents;
layout(std140, set = 0, binding = 2) buffer UniformContents { # TODO(crbug.com/tint/386): Use the same struct.
float color0; [[block]] struct ColorContents1 {
[[offset(0)]] color : f32;
}; };
[[block]] struct ColorContents2 {
layout(std140, set = 0, binding = 3) buffer ReadonlyStorageContents { [[offset(0)]] color : f32;
float color1;
}; };
[[set(0), binding(2)]] var<storage_buffer> uniformContents : [[access(read_write)]] ColorContents1;
[[set(0), binding(3)]] var<storage_buffer> storageContents : [[access(read_write)]] ColorContents2;
void main() { [[stage(compute)]] fn main() -> void {
pos[0] = vec4(-1.f, 1.f, 0.f, 1.f); vbContents.pos[0] = vec4<f32>(-1.0, 1.0, 0.0, 1.0);
pos[1] = vec4(1.f, 1.f, 0.f, 1.f); vbContents.pos[1] = vec4<f32>(1.0, 1.0, 0.0, 1.0);
pos[2] = vec4(1.f, -1.f, 0.f, 1.f); vbContents.pos[2] = vec4<f32>(1.0, -1.0, 0.0, 1.0);
pos[3] = vec4(-1.f, -1.f, 0.f, 1.f); vbContents.pos[3] = vec4<f32>(-1.0, -1.0, 0.0, 1.0);
int dummy = 0; const dummy : i32 = 0;
indices[0] = ivec4(0, 1, 2, 0); ibContents.indices[0] = vec4<i32>(0, 1, 2, 0);
indices[1] = ivec4(2, 3, dummy, dummy); ibContents.indices[1] = vec4<i32>(2, 3, dummy, dummy);
color0 = 1.0; uniformContents.color = 1.0;
color1 = 1.0; storageContents.color = 1.0;
})"); })");
wgpu::ComputePipelineDescriptor cpDesc; wgpu::ComputePipelineDescriptor cpDesc;
@ -508,12 +503,12 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
wgpu::Buffer uniformBuffer = wgpu::Buffer uniformBuffer =
CreateZeroedBuffer(sizeof(float), wgpu::BufferUsage::Uniform | wgpu::BufferUsage::Storage | CreateZeroedBuffer(sizeof(float), wgpu::BufferUsage::Uniform | wgpu::BufferUsage::Storage |
wgpu::BufferUsage::CopyDst); wgpu::BufferUsage::CopyDst);
wgpu::Buffer readonlyStorageBuffer = wgpu::Buffer storageBuffer =
CreateZeroedBuffer(sizeof(float), wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst); CreateZeroedBuffer(sizeof(float), wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopyDst);
wgpu::BindGroup bindGroup0 = utils::MakeBindGroup( wgpu::BindGroup bindGroup0 = utils::MakeBindGroup(
device, cp.GetBindGroupLayout(0), device, cp.GetBindGroupLayout(0),
{{0, vertexBuffer}, {1, indexBuffer}, {2, uniformBuffer}, {3, readonlyStorageBuffer}}); {{0, vertexBuffer}, {1, indexBuffer}, {2, uniformBuffer}, {3, storageBuffer}});
// Write data into storage buffers in compute pass. // Write data into storage buffers in compute pass.
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::ComputePassEncoder pass0 = encoder.BeginComputePass(); wgpu::ComputePassEncoder pass0 = encoder.BeginComputePass();
@ -523,28 +518,24 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
pass0.EndPass(); pass0.EndPass();
// Create pipeline, bind group, and reuse buffers in render pass. // Create pipeline, bind group, and reuse buffers in render pass.
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[location(0)]] var<in> pos : vec4<f32>;
#version 450 [[builtin(position)]] var<out> Position: vec4<f32>;
layout(location = 0) in vec4 pos; [[stage(vertex)]] fn main() -> void {
void main() { Position = pos;
gl_Position = pos;
})"); })");
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[block]] struct Buf {
#version 450 [[offset(0)]] color : f32;
layout (set = 0, binding = 0) uniform UniformBuffer {
float color0;
}; };
layout (set = 0, binding = 1) readonly buffer ReadonlyStorageBuffer { [[set(0), binding(0)]] var<uniform> uniformBuffer : Buf;
float color1; [[set(0), binding(1)]] var<storage_buffer> storageBuffer : [[access(read)]] Buf;
};
layout(location = 0) out vec4 fragColor; [[location(0)]] var<out> fragColor : vec4<f32>;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = vec4(color0, color1, 0.f, 1.f); fragColor = vec4<f32>(uniformBuffer.color, storageBuffer.color, 0.0, 1.0);
})"); })");
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
@ -561,8 +552,8 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
wgpu::RenderPipeline rp = device.CreateRenderPipeline(&rpDesc); wgpu::RenderPipeline rp = device.CreateRenderPipeline(&rpDesc);
wgpu::BindGroup bindGroup1 = utils::MakeBindGroup( wgpu::BindGroup bindGroup1 = utils::MakeBindGroup(device, rp.GetBindGroupLayout(0),
device, rp.GetBindGroupLayout(0), {{0, uniformBuffer}, {1, readonlyStorageBuffer}}); {{0, uniformBuffer}, {1, storageBuffer}});
// Read data in buffers in render pass. // Read data in buffers in render pass.
wgpu::RenderPassEncoder pass1 = encoder.BeginRenderPass(&renderPass.renderPassInfo); wgpu::RenderPassEncoder pass1 = encoder.BeginRenderPass(&renderPass.renderPassInfo);
@ -589,31 +580,26 @@ TEST_P(MultipleWriteThenMultipleReadTests, SeparateBuffers) {
// buffer in render pass depend on the write operation in compute pass. // buffer in render pass depend on the write operation in compute pass.
TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) { TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) {
// Create pipeline, bind group, and a complex buffer for compute pass. // Create pipeline, bind group, and a complex buffer for compute pass.
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( [[block]] struct Contents {
#version 450 [[offset(0)]] pos : [[stride(16)]] array<vec4<f32>, 4>;
layout(std140, set = 0, binding = 0) buffer Contents { [[offset(256)]] indices : [[stride(16)]] array<vec4<i32>, 2>;
// Every single float (and every float in an array, and every single vec2, vec3, and [[offset(512)]] color0 : f32;
// every column in mat2/mat3, etc) uses the same amount of memory as vec4 (float4). [[offset(768)]] color1 : f32;
vec4 pos[4];
vec4 padding0[12];
ivec4 indices[2];
ivec4 padding1[14];
float color0;
float padding2[15];
float color1;
}; };
void main() { [[set(0), binding(0)]] var<storage_buffer> contents : [[access(read_write)]] Contents;
pos[0] = vec4(-1.f, 1.f, 0.f, 1.f);
pos[1] = vec4(1.f, 1.f, 0.f, 1.f); [[stage(compute)]] fn main() -> void {
pos[2] = vec4(1.f, -1.f, 0.f, 1.f); contents.pos[0] = vec4<f32>(-1.0, 1.0, 0.0, 1.0);
pos[3] = vec4(-1.f, -1.f, 0.f, 1.f); contents.pos[1] = vec4<f32>(1.0, 1.0, 0.0, 1.0);
int dummy = 0; contents.pos[2] = vec4<f32>(1.0, -1.0, 0.0, 1.0);
indices[0] = ivec4(0, 1, 2, 0); contents.pos[3] = vec4<f32>(-1.0, -1.0, 0.0, 1.0);
indices[1] = ivec4(2, 3, dummy, dummy); const dummy : i32 = 0;
color0 = 1.0; contents.indices[0] = vec4<i32>(0, 1, 2, 0);
color1 = 1.0; contents.indices[1] = vec4<i32>(2, 3, dummy, dummy);
contents.color0 = 1.0;
contents.color1 = 1.0;
})"); })");
wgpu::ComputePipelineDescriptor cpDesc; wgpu::ComputePipelineDescriptor cpDesc;
@ -625,9 +611,9 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) {
char padding0[256 - sizeof(float) * 16]; char padding0[256 - sizeof(float) * 16];
int indices[2][4]; int indices[2][4];
char padding1[256 - sizeof(int) * 8]; char padding1[256 - sizeof(int) * 8];
float color0[4]; float color0;
char padding2[256 - sizeof(float) * 4]; char padding2[256 - sizeof(float)];
float color1[4]; float color1;
}; };
wgpu::Buffer buffer = CreateZeroedBuffer( wgpu::Buffer buffer = CreateZeroedBuffer(
sizeof(Data), wgpu::BufferUsage::Vertex | wgpu::BufferUsage::Index | sizeof(Data), wgpu::BufferUsage::Vertex | wgpu::BufferUsage::Index |
@ -645,28 +631,23 @@ TEST_P(MultipleWriteThenMultipleReadTests, OneBuffer) {
pass0.EndPass(); pass0.EndPass();
// Create pipeline, bind group, and reuse the buffer in render pass. // Create pipeline, bind group, and reuse the buffer in render pass.
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[location(0)]] var<in> pos : vec4<f32>;
#version 450 [[builtin(position)]] var<out> Position : vec4<f32>;
layout(location = 0) in vec4 pos; [[stage(vertex)]] fn main() -> void {
void main() { Position = pos;
gl_Position = pos;
})"); })");
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[block]] struct Buf {
#version 450 [[offset(0)]] color : f32;
layout (set = 0, binding = 0) uniform UniformBuffer {
float color0;
}; };
[[set(0), binding(0)]] var<uniform> uniformBuffer : Buf;
[[set(0), binding(1)]] var<storage_buffer> storageBuffer : [[access(read)]] Buf;
layout (set = 0, binding = 1) readonly buffer ReadonlyStorageBuffer { [[location(0)]] var<out> fragColor : vec4<f32>;
float color1; [[stage(fragment)]] fn main() -> void {
}; fragColor = vec4<f32>(uniformBuffer.color, storageBuffer.color, 0.0, 1.0);
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(color0, color1, 0.f, 1.f);
})"); })");
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);