Tweak GlobalVariables.rte test, and adjust .stage output

Adds trivial name mangling to the .stage output, so we can verify that
it's working in all places (declarations, references, etc). Also added
another global variable whose initializer is - in turn - another global.

Bug: skia:11295
Change-Id: Ic220bfae0a6d1eeeba66ade30d3d781af15c5dea
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371477
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/resources/sksl/runtime/GlobalVariables.rte b/resources/sksl/runtime/GlobalVariables.rte
index 7c1b1fc..862aaa0 100644
--- a/resources/sksl/runtime/GlobalVariables.rte
+++ b/resources/sksl/runtime/GlobalVariables.rte
@@ -1,6 +1,7 @@
 /*#pragma settings NoInline*/
 
 float gInitialized = -1.0;
+float gInitializedFromOther = -gInitialized;
 float gUninitialized;
 
 void init_globals() {
@@ -9,5 +10,5 @@
 
 float4 main() {
     init_globals();
-    return float4(0, -gInitialized, 0, gUninitialized);
+    return float4(0, gInitializedFromOther, 0, gUninitialized);
 }
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index 410ff2f..b2fc6e5 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -401,6 +401,10 @@
                     public:
                         using String = SkSL::String;
 
+                        String getMangledName(const char* name) override {
+                            return String(name) + "_0";
+                        }
+
                         String declareUniform(const SkSL::VarDeclaration* decl) override {
                             fOutput += decl->description();
                             if (decl->var().type().name() == "fragmentProcessor") {
diff --git a/tests/sksl/runtime/GlobalVariables.stage b/tests/sksl/runtime/GlobalVariables.stage
index 2e48474..68f5a10 100644
--- a/tests/sksl/runtime/GlobalVariables.stage
+++ b/tests/sksl/runtime/GlobalVariables.stage
@@ -1,9 +1,9 @@
-void init_globals()
+void init_globals_0()
 {
 	gUninitialized = gInitialized + 2.0;
 }
 float4 main()
 {
-	init_globals();
-	return half4(float4(0.0, -gInitialized, 0.0, gUninitialized));
+	init_globals_0();
+	return half4(float4(0.0, gInitializedFromOther, 0.0, gUninitialized));
 }
diff --git a/tests/sksl/runtime/LoopFloat.stage b/tests/sksl/runtime/LoopFloat.stage
index 2871c80..cb7d6ab 100644
--- a/tests/sksl/runtime/LoopFloat.stage
+++ b/tests/sksl/runtime/LoopFloat.stage
@@ -1,4 +1,4 @@
-float return_loop()
+float return_loop_0()
 {
 	for (float i = 0.0;i < 10.0; ++i) 
 	{
@@ -34,5 +34,5 @@
 	{
 		_7_sum += _8_i;
 	}
-	return half4(half4(half(return_loop()), half(_1_sum), half(_4_sum), half(_7_sum)));
+	return half4(half4(half(return_loop_0()), half(_1_sum), half(_4_sum), half(_7_sum)));
 }
diff --git a/tests/sksl/runtime/LoopInt.stage b/tests/sksl/runtime/LoopInt.stage
index d256ba0..297b107 100644
--- a/tests/sksl/runtime/LoopInt.stage
+++ b/tests/sksl/runtime/LoopInt.stage
@@ -1,4 +1,4 @@
-int return_loop()
+int return_loop_0()
 {
 	for (int i = 0;i < 10; ++i) 
 	{
@@ -29,5 +29,5 @@
 		}
 		_4_sum += _5_i;
 	}
-	return half4(half4(half(return_loop()), half(_1_sum), half(_4_sum), 1.0));
+	return half4(half4(half(return_loop_0()), half(_1_sum), half(_4_sum), 1.0));
 }
diff --git a/tests/sksl/runtime/VectorIndexing.stage b/tests/sksl/runtime/VectorIndexing.stage
index 23e92af..f8bdefe 100644
--- a/tests/sksl/runtime/VectorIndexing.stage
+++ b/tests/sksl/runtime/VectorIndexing.stage
@@ -2,7 +2,7 @@
 uniform float4 u2;
 uniform float4 u3;
 uniform float4 u4;
-float index_clamped_out_of_bounds()
+float index_clamped_out_of_bounds_0()
 {
 	for (int i = 7;i < 8; i++) 
 	{
@@ -21,5 +21,5 @@
 	{
 		_5_prod *= u3[_6_i < 2 ? 0 : _6_i];
 	}
-	return half4(float4(u1.x, _2_sum, _5_prod, index_clamped_out_of_bounds()));
+	return half4(float4(u1.x, _2_sum, _5_prod, index_clamped_out_of_bounds_0()));
 }