Update BufferZeroInitTests to use WGSL

Bug: dawn:572
Change-Id: Id194127831e54623df135b415ec2619016c6c6cb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/32512
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-12-22 19:56:49 +00:00 committed by Commit Bot service account
parent 84997c5ee9
commit 600798bdb1
1 changed files with 55 additions and 53 deletions

View File

@ -205,17 +205,15 @@ class BufferZeroInitTest : public DawnTest {
uint32_t vertexBufferCount = 1u) { uint32_t vertexBufferCount = 1u) {
constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm;
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, vertexShader);
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vertexShader);
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[location(0)]] var<in> i_color : vec4<f32>;
#version 450 [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) in vec4 i_color;
layout(location = 0) out vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() { fragColor = i_color;
fragColor = i_color; })");
})");
ASSERT(vertexBufferCount <= 1u); ASSERT(vertexBufferCount <= 1u);
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
@ -250,20 +248,20 @@ class BufferZeroInitTest : public DawnTest {
void TestBufferZeroInitAsVertexBuffer(uint64_t vertexBufferOffset) { void TestBufferZeroInitAsVertexBuffer(uint64_t vertexBufferOffset) {
constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm;
const char* vertexShader = R"( wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"(
#version 450 [[location(0)]] var<in> pos : vec4<f32>;
layout(location = 0) in vec4 pos; [[location(0)]] var<out> o_color : vec4<f32>;
layout(location = 0) out vec4 o_color;
void main() { [[builtin(position)]] var<out> Position : vec4<f32>;
if (pos == vec4(0.f, 0.f, 0.f, 0.f)) {
o_color = vec4(0.f, 1.f, 0.f, 1.f); [[stage(vertex)]] fn main() -> void {
if (all(pos == vec4<f32>(0.0, 0.0, 0.0, 0.0))) {
o_color = vec4<f32>(0.0, 1.0, 0.0, 1.0);
} else { } else {
o_color = vec4(1.f, 0.f, 0.f, 1.f); o_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
} }
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 1.0f; })");
})";
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader);
constexpr uint64_t kVertexAttributeSize = sizeof(float) * 4; constexpr uint64_t kVertexAttributeSize = sizeof(float) * 4;
const uint64_t vertexBufferSize = kVertexAttributeSize + vertexBufferOffset; const uint64_t vertexBufferSize = kVertexAttributeSize + vertexBufferOffset;
@ -291,19 +289,22 @@ class BufferZeroInitTest : public DawnTest {
void TestBufferZeroInitAsIndexBuffer(uint64_t indexBufferOffset) { void TestBufferZeroInitAsIndexBuffer(uint64_t indexBufferOffset) {
constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm;
const char* vertexShader = R"( wgpu::RenderPipeline renderPipeline =
#version 450 CreateRenderPipelineForTest(R"(
layout(location = 0) out vec4 o_color; [[location(0)]] var<out> o_color : vec4<f32>;
void main() {
if (gl_VertexIndex == 0u) { [[builtin(vertex_idx)]] var<in> VertexIndex : u32;
o_color = vec4(0.f, 1.f, 0.f, 1.f); [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
if (VertexIndex == 0u) {
o_color = vec4<f32>(0.0, 1.0, 0.0, 1.0);
} else { } else {
o_color = vec4(1.f, 0.f, 0.f, 1.f); o_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
} }
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 1.0f; })",
})"; 0 /* vertexBufferCount */);
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u);
// The buffer size cannot be less than 4 // The buffer size cannot be less than 4
const uint64_t indexBufferSize = sizeof(uint32_t) + indexBufferOffset; const uint64_t indexBufferSize = sizeof(uint32_t) + indexBufferOffset;
@ -335,16 +336,17 @@ class BufferZeroInitTest : public DawnTest {
constexpr wgpu::Color kClearColorGreen = {0.f, 1.f, 0.f, 1.f}; constexpr wgpu::Color kClearColorGreen = {0.f, 1.f, 0.f, 1.f};
// As long as the vertex shader is executed once, the output color will be red. // As long as the vertex shader is executed once, the output color will be red.
const char* vertexShader = R"( wgpu::RenderPipeline renderPipeline =
#version 450 CreateRenderPipelineForTest(R"(
layout(location = 0) out vec4 o_color; [[location(0)]] var<out> o_color : vec4<f32>;
void main() {
o_color = vec4(1.f, 0.f, 0.f, 1.f); [[builtin(position)]] var<out> Position : vec4<f32>;
gl_Position = vec4(0.f, 0.f, 0.f, 1.f);
gl_PointSize = 1.f; [[stage(vertex)]] fn main() -> void {
} o_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
)"; Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0); })",
0 /* vertexBufferCount */);
// Clear the color attachment to green. // Clear the color attachment to green.
wgpu::Texture colorAttachment = wgpu::Texture colorAttachment =
@ -372,17 +374,17 @@ class BufferZeroInitTest : public DawnTest {
constexpr wgpu::Color kClearColorGreen = {0.f, 1.f, 0.f, 1.f}; constexpr wgpu::Color kClearColorGreen = {0.f, 1.f, 0.f, 1.f};
// As long as the vertex shader is executed once, the output color will be red. // As long as the vertex shader is executed once, the output color will be red.
const char* vertexShader = R"( wgpu::RenderPipeline renderPipeline =
#version 450 CreateRenderPipelineForTest(R"(
layout(location = 0) out vec4 o_color; [[location(0)]] var<out> o_color : vec4<f32>;
void main() {
o_color = vec4(1.f, 0.f, 0.f, 1.f);
gl_Position = vec4(0.f, 0.f, 0.f, 1.f);
gl_PointSize = 1.f;
}
)";
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u); [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
o_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
})",
0 /* vertexBufferCount */);
wgpu::Buffer indexBuffer = wgpu::Buffer indexBuffer =
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0}); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0});