Update OpArrayLengthTests to use WGSL

Bug: dawn:572
Change-Id: Iba92adda4758fc91294f7c6d8b0be3065c786f71
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33773
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-12-22 20:11:48 +00:00 committed by Commit Bot service account
parent 04e3078a64
commit 33bf309c1d
1 changed files with 63 additions and 66 deletions

View File

@ -56,23 +56,33 @@ class OpArrayLengthTest : public DawnTest {
// Common shader code to use these buffers in shaders, assuming they are in bindgroup index
// 0.
mShaderInterface = R"(
// The length should be 1 because the buffer is 4-byte long.
layout(std430, set = 0, binding = 0) readonly buffer Buffer1 {
float data[];
} buffer1;
# TODO(crbug.com/tint/386): Use the same struct.
[[block]] struct DataBuffer1 {
[[offset(0)]] data : [[stride(4)]] array<f32>;
};
// The length should be 64 because the buffer is 256 bytes long.
layout(std430, set = 0, binding = 1) readonly buffer Buffer2 {
float data[];
} buffer2;
[[block]] struct DataBuffer2 {
[[offset(0)]] data : [[stride(4)]] array<f32>;
};
// The length should be (512 - 16*4) / 8 = 56 because the buffer is 512 bytes long
// and the structure is 8 bytes big.
struct Buffer3Data {float a; int b;};
layout(std430, set = 0, binding = 2) readonly buffer Buffer3 {
mat4 garbage;
Buffer3Data data[];
} buffer3;
# The length should be 1 because the buffer is 4-byte long.
[[set(0), binding(0)]] var<storage_buffer> buffer1 : [[access(read)]] DataBuffer1;
# The length should be 64 because the buffer is 256 bytes long.
[[set(0), binding(1)]] var<storage_buffer> buffer2 : [[access(read)]] DataBuffer2;
# The length should be (512 - 16*4) / 8 = 56 because the buffer is 512 bytes long
# and the structure is 8 bytes big.
struct Buffer3Data {
[[offset(0)]] a : f32;
[[offset(4)]] b : i32;
};
[[block]] struct Buffer3 {
[[offset(0)]] garbage : mat4x4<f32>;
[[offset(64)]] data : [[stride(8)]] array<Buffer3Data>;
};
[[set(0), binding(2)]] var<storage_buffer> buffer3 : [[access(read)]] Buffer3;
)";
// See comments in the shader for an explanation of these values
@ -118,19 +128,18 @@ TEST_P(OpArrayLengthTest, Compute) {
wgpu::ComputePipelineDescriptor pipelineDesc;
pipelineDesc.layout = pl;
pipelineDesc.computeStage.entryPoint = "main";
pipelineDesc.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute,
(R"(#version 450
layout(std430, set = 1, binding = 0) buffer ResultBuffer {
uint result[3];
};
)" + mShaderInterface + R"(
void main() {
result[0] = buffer1.data.length();
result[1] = buffer2.data.length();
result[2] = buffer3.data.length();
})")
.c_str());
pipelineDesc.computeStage.module = utils::CreateShaderModuleFromWGSL(device, (R"(
[[block]] struct ResultBuffer {
[[offset(0)]] data : [[stride(4)]] array<u32, 3>;
};
[[set(1), binding(0)]] var<storage_buffer> result : [[access(read_write)]] ResultBuffer;
)" + mShaderInterface + R"(
[[stage(compute)]] fn main() -> void {
result.data[0] = arrayLength(buffer1.data);
result.data[1] = arrayLength(buffer2.data);
result.data[2] = arrayLength(buffer3.data);
})")
.c_str());
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDesc);
// Run a single instance of the compute shader
@ -159,27 +168,21 @@ TEST_P(OpArrayLengthTest, Fragment) {
// Create the pipeline that computes the length of the buffers and writes it to the only render
// pass pixel.
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);
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
)" + mShaderInterface + R"(
layout(location = 0) out vec4 fragColor;
void main() {
fragColor.r = buffer1.data.length() / 255.0f;
fragColor.g = buffer2.data.length() / 255.0f;
fragColor.b = buffer3.data.length() / 255.0f;
fragColor.a = 0.0f;
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, (mShaderInterface + R"(
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor.r = f32(arrayLength(buffer1.data)) / 255.0;
fragColor.g = f32(arrayLength(buffer2.data)) / 255.0;
fragColor.b = f32(arrayLength(buffer3.data)) / 255.0;
fragColor.a = 0.0;
})")
.c_str());
.c_str());
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
@ -217,29 +220,23 @@ TEST_P(OpArrayLengthTest, Vertex) {
// Create the pipeline that computes the length of the buffers and writes it to the only render
// pass pixel.
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
(R"(
#version 450
)" + mShaderInterface + R"(
layout(location = 0) out vec4 pointColor;
void main() {
pointColor.r = buffer1.data.length() / 255.0f;
pointColor.g = buffer2.data.length() / 255.0f;
pointColor.b = buffer3.data.length() / 255.0f;
pointColor.a = 0.0f;
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, (mShaderInterface + R"(
[[location(0)]] var<out> pointColor : vec4<f32>;
[[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
pointColor.r = f32(arrayLength(buffer1.data)) / 255.0;
pointColor.g = f32(arrayLength(buffer2.data)) / 255.0;
pointColor.b = f32(arrayLength(buffer3.data)) / 255.0;
pointColor.a = 0.0;
gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);
gl_PointSize = 1.0;
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
})")
.c_str());
.c_str());
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
layout(location = 0) in vec4 pointColor;
void main() {
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> fragColor : vec4<f32>;
[[location(0)]] var<in> pointColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = pointColor;
})");