Update DynamicBufferOffsetTests to use WGSL

Bug: dawn:572
Change-Id: I73d987e8ab09120014d2d5c802bd08f08c33bdbd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33775
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-12-17 19:41:57 +00:00 committed by Commit Bot service account
parent ee977a0df8
commit d10774c42f
1 changed files with 76 additions and 49 deletions

View File

@ -93,51 +93,67 @@ class DynamicBufferOffsetTests : public DawnTest {
wgpu::Texture mColorAttachment; wgpu::Texture mColorAttachment;
wgpu::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) { wgpu::RenderPipeline CreateRenderPipeline(bool isInheritedPipeline = false) {
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[builtin(vertex_idx)]] var<in> VertexIndex : u32;
#version 450 [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[stage(vertex)]] fn main() -> void {
const vec2 pos[3] = vec2[3](vec2(-1.0f, 0.0f), vec2(-1.0f, 1.0f), vec2(0.0f, 1.0f)); const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0); vec2<f32>(-1.0, 0.0),
})"); vec2<f32>(-1.0, 1.0),
vec2<f32>( 0.0, 1.0));
Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
})");
// Construct fragment shader source // Construct fragment shader source
std::ostringstream fs; std::ostringstream fs;
std::string multipleNumber = isInheritedPipeline ? "2" : "1"; std::string multipleNumber = isInheritedPipeline ? "2" : "1";
fs << R"( fs << R"(
#version 450 # TODO(crbug.com/tint/386): Use the same struct.
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic { [[block]] struct Buffer1 {
uvec2 notDynamicValue; [[offset(0)]] value : vec2<u32>;
}; };
layout(std140, set = 0, binding = 1) buffer sBufferNotDynamic {
uvec2 notDynamicResult; [[block]] struct Buffer2 {
} mid; [[offset(0)]] value : vec2<u32>;
layout(std140, set = 0, binding = 3) uniform uBuffer {
uvec2 value;
}; };
layout(std140, set = 0, binding = 4) buffer SBuffer {
uvec2 result; [[block]] struct Buffer3 {
} sBuffer; [[offset(0)]] value : vec2<u32>;
};
[[block]] struct Buffer4 {
[[offset(0)]] value : vec2<u32>;
};
[[set(0), binding(0)]] var<uniform> uBufferNotDynamic : Buffer1;
[[set(0), binding(1)]] var<storage_buffer> sBufferNotDynamic : [[access(read_write)]] Buffer2;
[[set(0), binding(3)]] var<uniform> uBuffer : Buffer3;
[[set(0), binding(4)]] var<storage_buffer> sBuffer : [[access(read_write)]] Buffer4;
)"; )";
if (isInheritedPipeline) { if (isInheritedPipeline) {
fs << R"( fs << R"(
layout(std140, set = 1, binding = 0) uniform paddingBlock { [[block]] struct Buffer5 {
uvec2 padding; [[offset(0)]] value : vec2<u32>;
}; };
[[set(1), binding(0)]] var<uniform> paddingBlock : Buffer5;
)"; )";
} }
fs << " layout(location = 0) out vec4 fragColor;\n"; fs << "[[location(0)]] var<out> fragColor : vec4<f32>;\n";
fs << " void main() {\n";
fs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n";
fs << " sBuffer.result.xy = " << multipleNumber
<< " * (value.xy + mid.notDynamicResult.xy);\n";
fs << " fragColor = vec4(value.x / 255.0f, value.y / 255.0f, 1.0f, 1.0f);\n";
fs << " }\n";
wgpu::ShaderModule fsModule = fs << "const multipleNumber : u32 = " << multipleNumber << "u;\n";
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs.str().c_str()); fs << R"(
[[stage(fragment)]] fn main() -> void {
sBufferNotDynamic.value = uBufferNotDynamic.value.xy;
sBuffer.value = vec2<u32>(multipleNumber, multipleNumber) * (uBuffer.value.xy + sBufferNotDynamic.value.xy);
fragColor = vec4<f32>(f32(uBuffer.value.x) / 255.0, f32(uBuffer.value.y) / 255.0,
1.0, 1.0);
}
)";
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, fs.str().c_str());
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device); utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = vsModule; pipelineDescriptor.vertexStage.module = vsModule;
@ -161,37 +177,48 @@ class DynamicBufferOffsetTests : public DawnTest {
std::ostringstream cs; std::ostringstream cs;
std::string multipleNumber = isInheritedPipeline ? "2" : "1"; std::string multipleNumber = isInheritedPipeline ? "2" : "1";
cs << R"( cs << R"(
#version 450 # TODO(crbug.com/tint/386): Use the same struct.
layout(std140, set = 0, binding = 0) uniform uBufferNotDynamic { [[block]] struct Buffer1 {
uvec2 notDynamicValue; [[offset(0)]] value : vec2<u32>;
}; };
layout(std140, set = 0, binding = 1) buffer sBufferNotDynamic {
uvec2 notDynamicResult; [[block]] struct Buffer2 {
} mid; [[offset(0)]] value : vec2<u32>;
layout(std140, set = 0, binding = 3) uniform uBuffer {
uvec2 value;
}; };
layout(std140, set = 0, binding = 4) buffer SBuffer {
uvec2 result; [[block]] struct Buffer3 {
} sBuffer; [[offset(0)]] value : vec2<u32>;
};
[[block]] struct Buffer4 {
[[offset(0)]] value : vec2<u32>;
};
[[set(0), binding(0)]] var<uniform> uBufferNotDynamic : Buffer1;
[[set(0), binding(1)]] var<storage_buffer> sBufferNotDynamic : [[access(read_write)]] Buffer2;
[[set(0), binding(3)]] var<uniform> uBuffer : Buffer3;
[[set(0), binding(4)]] var<storage_buffer> sBuffer : [[access(read_write)]] Buffer4;
)"; )";
if (isInheritedPipeline) { if (isInheritedPipeline) {
cs << R"( cs << R"(
layout(std140, set = 1, binding = 0) uniform paddingBlock { [[block]] struct Buffer5 {
uvec2 padding; [[offset(0)]] value : vec2<u32>;
}; };
[[set(1), binding(0)]] var<uniform> paddingBlock : Buffer5;
)"; )";
} }
cs << " void main() {\n"; cs << "const multipleNumber : u32 = " << multipleNumber << "u;\n";
cs << " mid.notDynamicResult.xy = notDynamicValue.xy;\n"; cs << R"(
cs << " sBuffer.result.xy = " << multipleNumber [[stage(compute)]] fn main() -> void {
<< " * (value.xy + mid.notDynamicResult.xy);\n"; sBufferNotDynamic.value = uBufferNotDynamic.value.xy;
cs << " }\n"; sBuffer.value = vec2<u32>(multipleNumber, multipleNumber) * (uBuffer.value.xy + sBufferNotDynamic.value.xy);
}
)";
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, cs.str().c_str());
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs.str().c_str());
wgpu::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
csDesc.computeStage.module = csModule; csDesc.computeStage.module = csModule;