From 600798bdb19f6dd14ee2e0ed31d75a5dc3a635b2 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 22 Dec 2020 19:56:49 +0000 Subject: [PATCH] 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 Reviewed-by: Corentin Wallez --- src/tests/end2end/BufferZeroInitTests.cpp | 108 +++++++++++----------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/tests/end2end/BufferZeroInitTests.cpp b/src/tests/end2end/BufferZeroInitTests.cpp index 244d83fff6..00f76ccb69 100644 --- a/src/tests/end2end/BufferZeroInitTests.cpp +++ b/src/tests/end2end/BufferZeroInitTests.cpp @@ -205,17 +205,15 @@ class BufferZeroInitTest : public DawnTest { uint32_t vertexBufferCount = 1u) { constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vertexShader); + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, vertexShader); - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( - #version 450 - layout(location = 0) in vec4 i_color; - layout(location = 0) out vec4 fragColor; - void main() { - fragColor = i_color; - })"); + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[location(0)]] var i_color : vec4; + [[location(0)]] var fragColor : vec4; + + [[stage(fragment)]] fn main() -> void { + fragColor = i_color; + })"); ASSERT(vertexBufferCount <= 1u); utils::ComboRenderPipelineDescriptor descriptor(device); @@ -250,20 +248,20 @@ class BufferZeroInitTest : public DawnTest { void TestBufferZeroInitAsVertexBuffer(uint64_t vertexBufferOffset) { constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; - const char* vertexShader = R"( - #version 450 - layout(location = 0) in vec4 pos; - layout(location = 0) out vec4 o_color; - void main() { - if (pos == vec4(0.f, 0.f, 0.f, 0.f)) { - o_color = vec4(0.f, 1.f, 0.f, 1.f); + wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(R"( + [[location(0)]] var pos : vec4; + [[location(0)]] var o_color : vec4; + + [[builtin(position)]] var Position : vec4; + + [[stage(vertex)]] fn main() -> void { + if (all(pos == vec4(0.0, 0.0, 0.0, 0.0))) { + o_color = vec4(0.0, 1.0, 0.0, 1.0); } else { - o_color = vec4(1.f, 0.f, 0.f, 1.f); + o_color = vec4(1.0, 0.0, 0.0, 1.0); } - gl_Position = vec4(0.f, 0.f, 0.f, 1.f); - gl_PointSize = 1.0f; - })"; - wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader); + Position = vec4(0.0, 0.0, 0.0, 1.0); + })"); constexpr uint64_t kVertexAttributeSize = sizeof(float) * 4; const uint64_t vertexBufferSize = kVertexAttributeSize + vertexBufferOffset; @@ -291,19 +289,22 @@ class BufferZeroInitTest : public DawnTest { void TestBufferZeroInitAsIndexBuffer(uint64_t indexBufferOffset) { constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; - const char* vertexShader = R"( - #version 450 - layout(location = 0) out vec4 o_color; - void main() { - if (gl_VertexIndex == 0u) { - o_color = vec4(0.f, 1.f, 0.f, 1.f); + wgpu::RenderPipeline renderPipeline = + CreateRenderPipelineForTest(R"( + [[location(0)]] var o_color : vec4; + + [[builtin(vertex_idx)]] var VertexIndex : u32; + [[builtin(position)]] var Position : vec4; + + [[stage(vertex)]] fn main() -> void { + if (VertexIndex == 0u) { + o_color = vec4(0.0, 1.0, 0.0, 1.0); } else { - o_color = vec4(1.f, 0.f, 0.f, 1.f); + o_color = vec4(1.0, 0.0, 0.0, 1.0); } - gl_Position = vec4(0.f, 0.f, 0.f, 1.f); - gl_PointSize = 1.0f; - })"; - wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u); + Position = vec4(0.0, 0.0, 0.0, 1.0); + })", + 0 /* vertexBufferCount */); // The buffer size cannot be less than 4 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}; // As long as the vertex shader is executed once, the output color will be red. - const char* vertexShader = R"( - #version 450 - layout(location = 0) out vec4 o_color; - 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, 0); + wgpu::RenderPipeline renderPipeline = + CreateRenderPipelineForTest(R"( + [[location(0)]] var o_color : vec4; + + [[builtin(position)]] var Position : vec4; + + [[stage(vertex)]] fn main() -> void { + o_color = vec4(1.0, 0.0, 0.0, 1.0); + Position = vec4(0.0, 0.0, 0.0, 1.0); + })", + 0 /* vertexBufferCount */); // Clear the color attachment to green. wgpu::Texture colorAttachment = @@ -372,17 +374,17 @@ class BufferZeroInitTest : public DawnTest { 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. - const char* vertexShader = R"( - #version 450 - layout(location = 0) out vec4 o_color; - 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(R"( + [[location(0)]] var o_color : vec4; - wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u); + [[builtin(position)]] var Position : vec4; + + [[stage(vertex)]] fn main() -> void { + o_color = vec4(1.0, 0.0, 0.0, 1.0); + Position = vec4(0.0, 0.0, 0.0, 1.0); + })", + 0 /* vertexBufferCount */); wgpu::Buffer indexBuffer = utils::CreateBufferFromData(device, wgpu::BufferUsage::Index, {0});