From 0b3dfef4698f6e1d753ff67165fdc198ee40be4f Mon Sep 17 00:00:00 2001 From: Stephen White Date: Thu, 10 Feb 2022 16:22:28 +0000 Subject: [PATCH] GLSL: call renamer transform from GLSL transform. This significantly simplifies the calling code from Dawn. It does require moving the SingleEntryPoint transform above the renamer, since we need to call SEP with the original name. That is probably also an optimization, since we do the subsequent transforms with a culled AST. Bug: tint:1268 Change-Id: I1f48ec0238ea76310742c60b119311747dd3dbac Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80020 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Stephen White --- samples/main.cc | 3 --- src/transform/glsl.cc | 11 +++++--- src/writer/glsl/test_helper.h | 4 --- test/benchmark/particles.wgsl.expected.glsl | 28 ++++++++++---------- test/bug/chromium/1236161.wgsl.expected.glsl | 4 +-- test/var/uses/workgroup.wgsl.expected.glsl | 4 +-- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/samples/main.cc b/samples/main.cc index f329711cb1..50e1f7a131 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -1109,9 +1109,6 @@ int main(int argc, const char** argv) { } #if TINT_BUILD_GLSL_WRITER case Format::kGlsl: { - transform_inputs.Add( - tint::transform::Renamer::Target::kGlslKeywords); - transform_manager.Add(); break; } #endif // TINT_BUILD_GLSL_WRITER diff --git a/src/transform/glsl.cc b/src/transform/glsl.cc index 29b10d4172..9ae237139d 100644 --- a/src/transform/glsl.cc +++ b/src/transform/glsl.cc @@ -30,6 +30,7 @@ #include "src/transform/pad_array_elements.h" #include "src/transform/promote_side_effects_to_decl.h" #include "src/transform/remove_phonies.h" +#include "src/transform/renamer.h" #include "src/transform/simplify_pointers.h" #include "src/transform/single_entry_point.h" #include "src/transform/unshadow.h" @@ -50,6 +51,12 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) const { auto* cfg = inputs.Get(); + if (cfg && !cfg->entry_point.empty()) { + manager.Add(); + data.Add(cfg->entry_point); + } + manager.Add(); + data.Add(Renamer::Target::kGlslKeywords); manager.Add(); // Attempt to convert `loop`s into for-loops. This is to try and massage the @@ -62,10 +69,6 @@ Output Glsl::Run(const Program* in, const DataMap& inputs) const { // ZeroInitWorkgroupMemory may inject new builtin parameters. manager.Add(); } - if (cfg && !cfg->entry_point.empty()) { - manager.Add(); - data.Add(cfg->entry_point); - } manager.Add(); manager.Add(); diff --git a/src/writer/glsl/test_helper.h b/src/writer/glsl/test_helper.h index 3df482d1e9..670116038f 100644 --- a/src/writer/glsl/test_helper.h +++ b/src/writer/glsl/test_helper.h @@ -22,7 +22,6 @@ #include "gtest/gtest.h" #include "src/transform/glsl.h" #include "src/transform/manager.h" -#include "src/transform/renamer.h" #include "src/writer/glsl/generator_impl.h" namespace tint { @@ -81,9 +80,6 @@ class TestHelperBase : public BODY, public ProgramBuilder { transform::Manager transform_manager; transform::DataMap transform_data; - transform_data.Add( - transform::Renamer::Target::kGlslKeywords); - transform_manager.Add(); transform_manager.Add(); auto result = transform_manager.Run(program.get(), transform_data); [&]() { diff --git a/test/benchmark/particles.wgsl.expected.glsl b/test/benchmark/particles.wgsl.expected.glsl index 91c2fb5627..399de23e87 100644 --- a/test/benchmark/particles.wgsl.expected.glsl +++ b/test/benchmark/particles.wgsl.expected.glsl @@ -58,8 +58,8 @@ VertexOutput vs_main(VertexInput tint_symbol) { } void main() { - VertexInput tint_symbol_3 = VertexInput(position_1, color_1, quad_pos_1); - VertexOutput inner_result = vs_main(tint_symbol_3); + VertexInput tint_symbol_2 = VertexInput(position_1, color_1, quad_pos_1); + VertexOutput inner_result = vs_main(tint_symbol_2); gl_Position = inner_result.position; color_2 = inner_result.color; quad_pos_2 = inner_result.quad_pos; @@ -72,7 +72,7 @@ precision mediump float; layout(location = 0) in vec4 color_1; layout(location = 1) in vec2 quad_pos_1; -layout(location = 0) out vec4 value_1; +layout(location = 0) out vec4 value; struct RenderParams { mat4 modelViewProjectionMatrix; vec3 right; @@ -114,9 +114,9 @@ vec4 fs_main(VertexOutput tint_symbol) { } void main() { - VertexOutput tint_symbol_3 = VertexOutput(gl_FragCoord, color_1, quad_pos_1); - vec4 inner_result = fs_main(tint_symbol_3); - value_1 = inner_result; + VertexOutput tint_symbol_1 = VertexOutput(gl_FragCoord, color_1, quad_pos_1); + vec4 inner_result = fs_main(tint_symbol_1); + value = inner_result; return; } #version 310 es @@ -170,7 +170,7 @@ struct UBO { uint width; }; -uniform highp sampler2D tint_symbol_2_1; +uniform highp sampler2D tint_symbol_1; void simulate(uvec3 GlobalInvocationID) { rand_seed = ((sim_params.seed.xy + vec2(GlobalInvocationID.xy)) * sim_params.seed.zw); uint idx = GlobalInvocationID.x; @@ -182,8 +182,8 @@ void simulate(uvec3 GlobalInvocationID) { if ((particle.lifetime < 0.0f)) { ivec2 coord = ivec2(0, 0); { - for(int level = (textureQueryLevels(tint_symbol_2_1); - 1); (level > 0); level = (level - 1)) { - vec4 probabilites = texelFetch(tint_symbol_2_1, coord, level); + for(int level = (textureQueryLevels(tint_symbol_1); - 1); (level > 0); level = (level - 1)) { + vec4 probabilites = texelFetch(tint_symbol_1, coord, level); vec4 value = vec4(rand()); bvec4 mask = (greaterThanEqual(value, vec4(0.0f, probabilites.xyz)) & lessThan(value, probabilites)); coord = (coord * 2); @@ -191,9 +191,9 @@ void simulate(uvec3 GlobalInvocationID) { coord.y = (coord.y + (any(mask.zw) ? 1 : 0)); } } - vec2 uv = (vec2(coord) / vec2(textureSize(tint_symbol_2_1, 0))); + vec2 uv = (vec2(coord) / vec2(textureSize(tint_symbol_1, 0))); particle.position = vec3((((uv - 0.5f) * 3.0f) * vec2(1.0f, -1.0f)), 0.0f); - particle.color = texelFetch(tint_symbol_2_1, coord, 0); + particle.color = texelFetch(tint_symbol_1, coord, 0); particle.velocity.x = ((rand() - 0.5f) * 0.100000001f); particle.velocity.y = ((rand() - 0.5f) * 0.100000001f); particle.velocity.z = (rand() * 0.300000012f); @@ -322,13 +322,13 @@ void export_level(uvec3 coord) { if (all(lessThan(coord.xy, uvec2(imageSize(tex_out))))) { uint dst_offset = (coord.x + (coord.y * ubo.width)); uint src_offset = ((coord.x * 2u) + ((coord.y * 2u) * ubo.width)); - float a_1 = buf_in.weights[(src_offset + 0u)]; + float a = buf_in.weights[(src_offset + 0u)]; float b = buf_in.weights[(src_offset + 1u)]; float c = buf_in.weights[((src_offset + 0u) + ubo.width)]; float d = buf_in.weights[((src_offset + 1u) + ubo.width)]; - float sum = dot(vec4(a_1, b, c, d), vec4(1.0f)); + float sum = dot(vec4(a, b, c, d), vec4(1.0f)); buf_out.weights[dst_offset] = (sum / 4.0f); - vec4 probabilities = (vec4(a_1, (a_1 + b), ((a_1 + b) + c), sum) / max(sum, 0.0001f)); + vec4 probabilities = (vec4(a, (a + b), ((a + b) + c), sum) / max(sum, 0.0001f)); imageStore(tex_out, ivec2(coord.xy), probabilities); } } diff --git a/test/bug/chromium/1236161.wgsl.expected.glsl b/test/bug/chromium/1236161.wgsl.expected.glsl index 471e408cd6..f99eeafd81 100644 --- a/test/bug/chromium/1236161.wgsl.expected.glsl +++ b/test/bug/chromium/1236161.wgsl.expected.glsl @@ -19,8 +19,8 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; void unused_entry_point() { return; } -void i() { - float s = tint_modf(1.0f).whole; +void tint_symbol() { + float tint_symbol_1 = tint_modf(1.0f).whole; } Error parsing GLSL shader: diff --git a/test/var/uses/workgroup.wgsl.expected.glsl b/test/var/uses/workgroup.wgsl.expected.glsl index bd15766683..dc6627accb 100644 --- a/test/var/uses/workgroup.wgsl.expected.glsl +++ b/test/var/uses/workgroup.wgsl.expected.glsl @@ -26,7 +26,7 @@ void uses_b() { b = (b * 2); } -void main2(uint local_invocation_index_1) { +void main2(uint local_invocation_index) { { b = 0; } @@ -67,7 +67,7 @@ void outer() { no_uses(); } -void main3(uint local_invocation_index_2) { +void main3(uint local_invocation_index) { { a = 0; b = 0;