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 <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/samples/main.cc b/samples/main.cc
index f329711..50e1f7a 100644
--- a/samples/main.cc
+++ b/samples/main.cc
@@ -1109,9 +1109,6 @@
     }
 #if TINT_BUILD_GLSL_WRITER
     case Format::kGlsl: {
-      transform_inputs.Add<tint::transform::Renamer::Config>(
-          tint::transform::Renamer::Target::kGlslKeywords);
-      transform_manager.Add<tint::transform::Renamer>();
       break;
     }
 #endif  // TINT_BUILD_GLSL_WRITER
diff --git a/src/transform/glsl.cc b/src/transform/glsl.cc
index 29b10d4..9ae2371 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 @@
 
   auto* cfg = inputs.Get<Config>();
 
+  if (cfg && !cfg->entry_point.empty()) {
+    manager.Add<SingleEntryPoint>();
+    data.Add<SingleEntryPoint::Config>(cfg->entry_point);
+  }
+  manager.Add<Renamer>();
+  data.Add<Renamer::Config>(Renamer::Target::kGlslKeywords);
   manager.Add<Unshadow>();
 
   // Attempt to convert `loop`s into for-loops. This is to try and massage the
@@ -62,10 +69,6 @@
     // ZeroInitWorkgroupMemory may inject new builtin parameters.
     manager.Add<ZeroInitWorkgroupMemory>();
   }
-  if (cfg && !cfg->entry_point.empty()) {
-    manager.Add<SingleEntryPoint>();
-    data.Add<SingleEntryPoint::Config>(cfg->entry_point);
-  }
   manager.Add<CanonicalizeEntryPointIO>();
   manager.Add<SimplifyPointers>();
 
diff --git a/src/writer/glsl/test_helper.h b/src/writer/glsl/test_helper.h
index 3df482d..6701160 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 @@
 
     transform::Manager transform_manager;
     transform::DataMap transform_data;
-    transform_data.Add<transform::Renamer::Config>(
-        transform::Renamer::Target::kGlslKeywords);
-    transform_manager.Add<tint::transform::Renamer>();
     transform_manager.Add<tint::transform::Glsl>();
     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 91c2fb5..399de23 100644
--- a/test/benchmark/particles.wgsl.expected.glsl
+++ b/test/benchmark/particles.wgsl.expected.glsl
@@ -58,8 +58,8 @@
 }
 
 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 @@
 
 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 @@
 }
 
 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 @@
   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 @@
   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 @@
         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 @@
   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 471e408..f99eeaf 100644
--- a/test/bug/chromium/1236161.wgsl.expected.glsl
+++ b/test/bug/chromium/1236161.wgsl.expected.glsl
@@ -19,8 +19,8 @@
 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 bd15766..dc6627a 100644
--- a/test/var/uses/workgroup.wgsl.expected.glsl
+++ b/test/var/uses/workgroup.wgsl.expected.glsl
@@ -26,7 +26,7 @@
   b = (b * 2);
 }
 
-void main2(uint local_invocation_index_1) {
+void main2(uint local_invocation_index) {
   {
     b = 0;
   }
@@ -67,7 +67,7 @@
   no_uses();
 }
 
-void main3(uint local_invocation_index_2) {
+void main3(uint local_invocation_index) {
   {
     a = 0;
     b = 0;