From 225074a74a5150279dc20f33e22171092584715a Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 26 Nov 2020 13:22:15 +0000 Subject: [PATCH] Update TextureSubresourceTests to use WGSL Bug: dawn:572 Change-Id: I7a008c4c52c7e42cd73c4591854f8910d1a04dc7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33769 Commit-Queue: Corentin Wallez Reviewed-by: Ben Clayton --- src/tests/end2end/TextureSubresourceTests.cpp | 76 +++++++++++-------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/tests/end2end/TextureSubresourceTests.cpp b/src/tests/end2end/TextureSubresourceTests.cpp index aa6a5fa0ee..b80e8ef60c 100644 --- a/src/tests/end2end/TextureSubresourceTests.cpp +++ b/src/tests/end2end/TextureSubresourceTests.cpp @@ -49,22 +49,24 @@ class TextureSubresourceTest : public DawnTest { } void DrawTriangle(const wgpu::TextureView& view) { - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( - #version 450 - void main() { - const vec2 pos[3] = vec2[3]( - vec2(-1.f, 1.f), vec2(-1.f, -1.f), vec2(1.f, -1.f)); - gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f); - })"); + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[builtin(vertex_idx)]] var VertexIndex : u32; + [[builtin(position)]] var Position : vec4; - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( - #version 450 - layout(location = 0) out vec4 fragColor; - void main() { - fragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"); + [[stage(vertex)]] fn main() -> void { + const pos : array, 3> = array, 3>( + vec2(-1.0, 1.0), + vec2(-1.0, -1.0), + vec2( 1.0, -1.0)); + + Position = vec4(pos[VertexIndex], 0.0, 1.0); + })"); + + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[location(0)]] var fragColor : vec4; + [[stage(fragment)]] fn main() -> void { + fragColor = vec4(1.0, 0.0, 0.0, 1.0); + })"); utils::ComboRenderPipelineDescriptor descriptor(device); descriptor.vertexStage.module = vsModule; @@ -87,25 +89,33 @@ class TextureSubresourceTest : public DawnTest { } void SampleAndDraw(const wgpu::TextureView& samplerView, const wgpu::TextureView& renderView) { - wgpu::ShaderModule vsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( - #version 450 - void main() { - const vec2 pos[6] = vec2[6]( - vec2(-1.f, -1.f), vec2(1.f, 1.f), vec2(-1.f, 1.f), - vec2(-1.f, -1.f), vec2(1.f, -1.f), vec2(1.f, 1.f)); - gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f); - })"); + wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[builtin(vertex_idx)]] var VertexIndex : u32; + [[builtin(position)]] var Position : vec4; - wgpu::ShaderModule fsModule = - utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( - #version 450 - layout (set = 0, binding = 0) uniform sampler samp; - layout (set = 0, binding = 1) uniform texture2D tex; - layout (location = 0) out vec4 fragColor; - void main() { - fragColor = texture(sampler2D(tex, samp), gl_FragCoord.xy / 4); - })"); + [[stage(vertex)]] fn main() -> void { + const pos : array, 6> = array, 6>( + vec2(-1.0, -1.0), + vec2( 1.0, 1.0), + vec2(-1.0, 1.0), + vec2(-1.0, -1.0), + vec2( 1.0, -1.0), + vec2( 1.0, 1.0)); + + Position = vec4(pos[VertexIndex], 0.0, 1.0); + })"); + + wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( + [[set(0), binding(0)]] var samp : sampler; + [[set(0), binding(1)]] var tex : texture_2d; + + [[builtin(frag_coord)]] var FragCoord : vec4; + + [[location(0)]] var fragColor : vec4; + + [[stage(fragment)]] fn main() -> void { + fragColor = textureSample(tex, samp, FragCoord.xy / vec2(4.0, 4.0)); + })"); utils::ComboRenderPipelineDescriptor descriptor(device); descriptor.vertexStage.module = vsModule;