GLSL: implement abs() on unsigned arguments.

It's a no-op.

Bug: tint:1458
Change-Id: Ib97c409fd806da1c97ac867f21ef42b8a18c178c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82364
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc
index 0daf65e..4ce15d5 100644
--- a/src/tint/writer/glsl/generator_impl.cc
+++ b/src/tint/writer/glsl/generator_impl.cc
@@ -684,6 +684,11 @@
   if (builtin->Type() == sem::BuiltinType::kFma && version_.IsES()) {
     return EmitEmulatedFMA(out, expr);
   }
+  if (builtin->Type() == sem::BuiltinType::kAbs &&
+      TypeOf(expr->args[0])->UnwrapRef()->is_unsigned_scalar_or_vector()) {
+    // GLSL does not support abs() on unsigned arguments. However, it's a no-op.
+    return EmitExpression(out, expr->args[0]);
+  }
   if (builtin->IsBarrier()) {
     return EmitBarrierCall(out, builtin);
   }
diff --git a/test/tint/builtins/gen/abs/1ce782.wgsl.expected.glsl b/test/tint/builtins/gen/abs/1ce782.wgsl.expected.glsl
index 1360342..f5eb6aa 100644
--- a/test/tint/builtins/gen/abs/1ce782.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/abs/1ce782.wgsl.expected.glsl
@@ -1,9 +1,7 @@
-SKIP: FAILED
-
 #version 310 es
 
 void abs_1ce782() {
-  uvec4 res = abs(uvec4(0u, 0u, 0u, 0u));
+  uvec4 res = uvec4(0u, 0u, 0u, 0u);
 }
 
 vec4 vertex_main() {
@@ -18,19 +16,11 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 4-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 void abs_1ce782() {
-  uvec4 res = abs(uvec4(0u, 0u, 0u, 0u));
+  uvec4 res = uvec4(0u, 0u, 0u, 0u);
 }
 
 void fragment_main() {
@@ -41,18 +31,10 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'abs' : no matching overloaded function found 
-ERROR: 0:5: '=' :  cannot convert from ' const float' to ' temp mediump 4-component vector of uint'
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 void abs_1ce782() {
-  uvec4 res = abs(uvec4(0u, 0u, 0u, 0u));
+  uvec4 res = uvec4(0u, 0u, 0u, 0u);
 }
 
 void compute_main() {
@@ -64,11 +46,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 4-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
diff --git a/test/tint/builtins/gen/abs/467cd1.wgsl.expected.glsl b/test/tint/builtins/gen/abs/467cd1.wgsl.expected.glsl
index 7e6bf0f..935bd0e 100644
--- a/test/tint/builtins/gen/abs/467cd1.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/abs/467cd1.wgsl.expected.glsl
@@ -1,9 +1,7 @@
-SKIP: FAILED
-
 #version 310 es
 
 void abs_467cd1() {
-  uint res = abs(1u);
+  uint res = 1u;
 }
 
 vec4 vertex_main() {
@@ -18,19 +16,11 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 void abs_467cd1() {
-  uint res = abs(1u);
+  uint res = 1u;
 }
 
 void fragment_main() {
@@ -41,18 +31,10 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'abs' : no matching overloaded function found 
-ERROR: 0:5: '=' :  cannot convert from ' const float' to ' temp mediump uint'
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 void abs_467cd1() {
-  uint res = abs(1u);
+  uint res = 1u;
 }
 
 void compute_main() {
@@ -64,11 +46,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
diff --git a/test/tint/builtins/gen/abs/7326de.wgsl.expected.glsl b/test/tint/builtins/gen/abs/7326de.wgsl.expected.glsl
index f7d2dd3..3addb9f 100644
--- a/test/tint/builtins/gen/abs/7326de.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/abs/7326de.wgsl.expected.glsl
@@ -1,9 +1,7 @@
-SKIP: FAILED
-
 #version 310 es
 
 void abs_7326de() {
-  uvec3 res = abs(uvec3(0u, 0u, 0u));
+  uvec3 res = uvec3(0u, 0u, 0u);
 }
 
 vec4 vertex_main() {
@@ -18,19 +16,11 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 3-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 void abs_7326de() {
-  uvec3 res = abs(uvec3(0u, 0u, 0u));
+  uvec3 res = uvec3(0u, 0u, 0u);
 }
 
 void fragment_main() {
@@ -41,18 +31,10 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'abs' : no matching overloaded function found 
-ERROR: 0:5: '=' :  cannot convert from ' const float' to ' temp mediump 3-component vector of uint'
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 void abs_7326de() {
-  uvec3 res = abs(uvec3(0u, 0u, 0u));
+  uvec3 res = uvec3(0u, 0u, 0u);
 }
 
 void compute_main() {
@@ -64,11 +46,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 3-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
diff --git a/test/tint/builtins/gen/abs/7f28e6.wgsl.expected.glsl b/test/tint/builtins/gen/abs/7f28e6.wgsl.expected.glsl
index 88eec14..c077eaa 100644
--- a/test/tint/builtins/gen/abs/7f28e6.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/abs/7f28e6.wgsl.expected.glsl
@@ -1,9 +1,7 @@
-SKIP: FAILED
-
 #version 310 es
 
 void abs_7f28e6() {
-  uvec2 res = abs(uvec2(0u, 0u));
+  uvec2 res = uvec2(0u, 0u);
 }
 
 vec4 vertex_main() {
@@ -18,19 +16,11 @@
   gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 2-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 precision mediump float;
 
 void abs_7f28e6() {
-  uvec2 res = abs(uvec2(0u, 0u));
+  uvec2 res = uvec2(0u, 0u);
 }
 
 void fragment_main() {
@@ -41,18 +31,10 @@
   fragment_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:5: 'abs' : no matching overloaded function found 
-ERROR: 0:5: '=' :  cannot convert from ' const float' to ' temp mediump 2-component vector of uint'
-ERROR: 0:5: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
 #version 310 es
 
 void abs_7f28e6() {
-  uvec2 res = abs(uvec2(0u, 0u));
+  uvec2 res = uvec2(0u, 0u);
 }
 
 void compute_main() {
@@ -64,11 +46,3 @@
   compute_main();
   return;
 }
-Error parsing GLSL shader:
-ERROR: 0:4: 'abs' : no matching overloaded function found 
-ERROR: 0:4: '=' :  cannot convert from ' const float' to ' temp highp 2-component vector of uint'
-ERROR: 0:4: '' : compilation terminated 
-ERROR: 3 compilation errors.  No code generated.
-
-
-
diff --git a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl
index 3da3b8e..5104880 100644
--- a/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/textureDimensions/ba1481.wgsl.expected.glsl
@@ -1,6 +1,6 @@
 SKIP: FAILED
 
-../../src/tint/writer/glsl/generator_impl.cc:2572 internal compiler error: Multiplanar external texture transform was not run.
+../../src/tint/writer/glsl/generator_impl.cc:2577 internal compiler error: Multiplanar external texture transform was not run.
 
 
 ********************************************************************
diff --git a/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl b/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl
index 3da3b8e..5104880 100644
--- a/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/textureLoad/8acf41.wgsl.expected.glsl
@@ -1,6 +1,6 @@
 SKIP: FAILED
 
-../../src/tint/writer/glsl/generator_impl.cc:2572 internal compiler error: Multiplanar external texture transform was not run.
+../../src/tint/writer/glsl/generator_impl.cc:2577 internal compiler error: Multiplanar external texture transform was not run.
 
 
 ********************************************************************
diff --git a/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl b/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl
index 3da3b8e..5104880 100644
--- a/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/textureSampleLevel/979816.wgsl.expected.glsl
@@ -1,6 +1,6 @@
 SKIP: FAILED
 
-../../src/tint/writer/glsl/generator_impl.cc:2572 internal compiler error: Multiplanar external texture transform was not run.
+../../src/tint/writer/glsl/generator_impl.cc:2577 internal compiler error: Multiplanar external texture transform was not run.
 
 
 ********************************************************************