writer/msl: Fix texture intrinsic generation

Wrap the texture expression in parentheses when it has lower
precendence than the function call operator.

Cast integer coordinates to unsigned integers as required by MSL.

Fixed: tint:536
Change-Id: I957e6be3c51044959e25e0be96c2d2c65db18187
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53962
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/test/intrinsics/gen/textureSampleBias/53b9f7.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/53b9f7.wgsl.expected.msl
index 3ceac72..fed3c2a 100644
--- a/test/intrinsics/gen/textureSampleBias/53b9f7.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/53b9f7.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_53b9f7() {
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
+void textureSampleBias_53b9f7(texturecube<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float3(), bias(1.0f));
 }
 
-fragment void fragment_main() {
-  textureSampleBias_53b9f7();
+fragment void fragment_main(texturecube<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_53b9f7(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_fXClsP.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
-               ^
-tint_fXClsP.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/65ac50.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/65ac50.wgsl.expected.msl
index aa25372..b524707 100644
--- a/test/intrinsics/gen/textureSampleBias/65ac50.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/65ac50.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_65ac50() {
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f), int2());
+void textureSampleBias_65ac50(texture2d_array<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float2(), 1, bias(1.0f), int2());
 }
 
-fragment void fragment_main() {
-  textureSampleBias_65ac50();
+fragment void fragment_main(texture2d_array<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_65ac50(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_VENNtZ.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f), int2());
-               ^
-tint_VENNtZ.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f), int2());
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/6a9113.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/6a9113.wgsl.expected.msl
index e696093..32ca94e 100644
--- a/test/intrinsics/gen/textureSampleBias/6a9113.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/6a9113.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_6a9113() {
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f));
+void textureSampleBias_6a9113(texture2d<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float2(), bias(1.0f));
 }
 
-fragment void fragment_main() {
-  textureSampleBias_6a9113();
+fragment void fragment_main(texture2d<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_6a9113(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_n6HLQB.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f));
-               ^
-tint_n6HLQB.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f));
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/80e579.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/80e579.wgsl.expected.msl
index e185887..a0bcaf3 100644
--- a/test/intrinsics/gen/textureSampleBias/80e579.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/80e579.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_80e579() {
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f));
+void textureSampleBias_80e579(texture2d_array<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float2(), 1, bias(1.0f));
 }
 
-fragment void fragment_main() {
-  textureSampleBias_80e579();
+fragment void fragment_main(texture2d_array<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_80e579(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_VVVRdp.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f));
-               ^
-tint_VVVRdp.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float2(), 1, bias(1.0f));
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/81c19a.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/81c19a.wgsl.expected.msl
index 3569b2b..cc9704b 100644
--- a/test/intrinsics/gen/textureSampleBias/81c19a.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/81c19a.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_81c19a() {
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f), int2());
+void textureSampleBias_81c19a(texture2d<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float2(), bias(1.0f), int2());
 }
 
-fragment void fragment_main() {
-  textureSampleBias_81c19a();
+fragment void fragment_main(texture2d<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_81c19a(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_Zl326D.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f), int2());
-               ^
-tint_Zl326D.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float2(), bias(1.0f), int2());
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/d3fa1b.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/d3fa1b.wgsl.expected.msl
index ee3b17b..459f852 100644
--- a/test/intrinsics/gen/textureSampleBias/d3fa1b.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/d3fa1b.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_d3fa1b() {
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
+void textureSampleBias_d3fa1b(texture3d<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float3(), bias(1.0f));
 }
 
-fragment void fragment_main() {
-  textureSampleBias_d3fa1b();
+fragment void fragment_main(texture3d<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_d3fa1b(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_21BT87.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
-               ^
-tint_21BT87.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f));
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/df91bb.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/df91bb.wgsl.expected.msl
index ca72483..679cfa2 100644
--- a/test/intrinsics/gen/textureSampleBias/df91bb.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/df91bb.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_df91bb() {
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f), int3());
+void textureSampleBias_df91bb(texture3d<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float3(), bias(1.0f), int3());
 }
 
-fragment void fragment_main() {
-  textureSampleBias_df91bb();
+fragment void fragment_main(texture3d<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_df91bb(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_Y31ZCA.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f), int3());
-               ^
-tint_Y31ZCA.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float3(), bias(1.0f), int3());
-                            ^
-2 errors generated.
diff --git a/test/intrinsics/gen/textureSampleBias/eed7c4.wgsl.expected.msl b/test/intrinsics/gen/textureSampleBias/eed7c4.wgsl.expected.msl
index 37c07b0..6c3eee0 100644
--- a/test/intrinsics/gen/textureSampleBias/eed7c4.wgsl.expected.msl
+++ b/test/intrinsics/gen/textureSampleBias/eed7c4.wgsl.expected.msl
@@ -1,25 +1,12 @@
-SKIP: FAILED
-
-
-
-Validation Failure:
 #include <metal_stdlib>
 
 using namespace metal;
-void textureSampleBias_eed7c4() {
-  float4 res = arg_0.sample(arg_1, float3(), 1, bias(1.0f));
+void textureSampleBias_eed7c4(texturecube_array<float, access::sample> tint_symbol, sampler tint_symbol_1) {
+  float4 res = tint_symbol.sample(tint_symbol_1, float3(), 1, bias(1.0f));
 }
 
-fragment void fragment_main() {
-  textureSampleBias_eed7c4();
+fragment void fragment_main(texturecube_array<float, access::sample> tint_symbol_2 [[texture(0)]], sampler tint_symbol_3 [[sampler(1)]]) {
+  textureSampleBias_eed7c4(tint_symbol_2, tint_symbol_3);
   return;
 }
 
-
-tint_FJH9UG.metal:5:16: error: use of undeclared identifier 'arg_0'
-  float4 res = arg_0.sample(arg_1, float3(), 1, bias(1.0f));
-               ^
-tint_FJH9UG.metal:5:29: error: use of undeclared identifier 'arg_1'
-  float4 res = arg_0.sample(arg_1, float3(), 1, bias(1.0f));
-                            ^
-2 errors generated.