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