tint: const eval of refract builtin

Bug: tint:1581
Change-Id: Iff64e8a680fbbc82e1f8efe2e2f8e05af8e3692c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111920
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def
index efa7f4f..fb75c97 100644
--- a/src/tint/intrinsics.def
+++ b/src/tint/intrinsics.def
@@ -519,7 +519,7 @@
 @const fn radians<T: fa_f32_f16>(T) -> T
 @const fn radians<N: num, T: fa_f32_f16>(vec<N, T>) -> vec<N, T>
 @const fn reflect<N: num, T: fa_f32_f16>(vec<N, T>, vec<N, T>) -> vec<N, T>
-fn refract<N: num, T: f32_f16>(vec<N, T>, vec<N, T>, T) -> vec<N, T>
+@const fn refract<N: num, T: fa_f32_f16>(vec<N, T>, vec<N, T>, T) -> vec<N, T>
 @const fn reverseBits<T: iu32>(T) -> T
 @const fn reverseBits<N: num, T: iu32>(vec<N, T>) -> vec<N, T>
 @const fn round<T: fa_f32_f16>(@test_value(3.4) T) -> T
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index 95eefe0..b7674dc 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -2954,6 +2954,104 @@
     return r;
 }
 
+ConstEval::Result ConstEval::refract(const sem::Type* ty,
+                                     utils::VectorRef<const sem::Constant*> args,
+                                     const Source& source) {
+    auto* vec_ty = ty->As<sem::Vector>();
+    auto* el_ty = vec_ty->type();
+
+    auto compute_k = [&](auto e3, auto dot_e2_e1) -> ConstEval::Result {
+        using NumberT = decltype(e3);
+        // let k = 1.0 - e3 * e3 * (1.0 - dot(e2, e1) * dot(e2, e1))
+        auto e3_squared = Mul(source, e3, e3);
+        if (!e3_squared) {
+            return utils::Failure;
+        }
+        auto dot_e2_e1_squared = Mul(source, dot_e2_e1, dot_e2_e1);
+        if (!dot_e2_e1_squared) {
+            return utils::Failure;
+        }
+        auto r = Sub(source, NumberT(1), dot_e2_e1_squared.Get());
+        if (!r) {
+            return utils::Failure;
+        }
+        r = Mul(source, e3_squared.Get(), r.Get());
+        if (!r) {
+            return utils::Failure;
+        }
+        r = Sub(source, NumberT(1), r.Get());
+        if (!r) {
+            return utils::Failure;
+        }
+        return CreateElement(builder, source, el_ty, r.Get());
+    };
+
+    auto compute_e2_scale = [&](auto e3, auto dot_e2_e1, auto k) -> ConstEval::Result {
+        // e3 * dot(e2, e1) + sqrt(k)
+        auto sqrt_k = Sqrt(source, k);
+        if (!sqrt_k) {
+            return utils::Failure;
+        }
+        auto r = Mul(source, e3, dot_e2_e1);
+        if (!r) {
+            return utils::Failure;
+        }
+        r = Add(source, r.Get(), sqrt_k.Get());
+        if (!r) {
+            return utils::Failure;
+        }
+        return CreateElement(builder, source, el_ty, r.Get());
+    };
+
+    auto calculate = [&]() -> ConstEval::Result {
+        auto* e1 = args[0];
+        auto* e2 = args[1];
+        auto* e3 = args[2];
+
+        // For the incident vector e1 and surface normal e2, and the ratio of indices of refraction
+        // e3, let k = 1.0 - e3 * e3 * (1.0 - dot(e2, e1) * dot(e2, e1)). If k < 0.0, returns the
+        // refraction vector 0.0, otherwise return the refraction vector e3 * e1 - (e3 * dot(e2, e1)
+        // + sqrt(k)) * e2.
+
+        // dot(e2, e1)
+        auto dot_e2_e1 = Dot(source, e2, e1);
+        if (!dot_e2_e1) {
+            return utils::Failure;
+        }
+
+        // let k = 1.0 - e3 * e3 * (1.0 - dot(e2, e1) * dot(e2, e1))
+        auto k = Dispatch_fa_f32_f16(compute_k, e3, dot_e2_e1.Get());
+        if (!k) {
+            return utils::Failure;
+        }
+
+        // If k < 0.0, returns the refraction vector 0.0
+        if (k.Get()->As<AFloat>() < 0) {
+            return ZeroValue(builder, ty);
+        }
+
+        // Otherwise return the refraction vector e3 * e1 - (e3 * dot(e2, e1) + sqrt(k)) * e2
+        auto e1_scaled = Mul(source, ty, e3, e1);
+        if (!e1_scaled) {
+            return utils::Failure;
+        }
+        auto e2_scale = Dispatch_fa_f32_f16(compute_e2_scale, e3, dot_e2_e1.Get(), k.Get());
+        if (!e2_scale) {
+            return utils::Failure;
+        }
+        auto e2_scaled = Mul(source, ty, e2_scale.Get(), e2);
+        if (!e1_scaled) {
+            return utils::Failure;
+        }
+        return Sub(source, ty, e1_scaled.Get(), e2_scaled.Get());
+    };
+    auto r = calculate();
+    if (!r) {
+        AddNote("when calculating refract", source);
+    }
+    return r;
+}
+
 ConstEval::Result ConstEval::reverseBits(const sem::Type* ty,
                                          utils::VectorRef<const sem::Constant*> args,
                                          const Source& source) {
diff --git a/src/tint/resolver/const_eval.h b/src/tint/resolver/const_eval.h
index 1a16a79..d92dc3f 100644
--- a/src/tint/resolver/const_eval.h
+++ b/src/tint/resolver/const_eval.h
@@ -800,6 +800,15 @@
                    utils::VectorRef<const sem::Constant*> args,
                    const Source& source);
 
+    /// refract builtin
+    /// @param ty the expression type
+    /// @param args the input arguments
+    /// @param source the source location of the conversion
+    /// @return the result value, or null if the value cannot be calculated
+    Result refract(const sem::Type* ty,
+                   utils::VectorRef<const sem::Constant*> args,
+                   const Source& source);
+
     /// reverseBits builtin
     /// @param ty the expression type
     /// @param args the input arguments
diff --git a/src/tint/resolver/const_eval_builtin_test.cc b/src/tint/resolver/const_eval_builtin_test.cc
index 1860886..b7f506c 100644
--- a/src/tint/resolver/const_eval_builtin_test.cc
+++ b/src/tint/resolver/const_eval_builtin_test.cc
@@ -1983,11 +1983,91 @@
     Reflect,
     ResolverConstEvalBuiltinTest,
     testing::Combine(testing::Values(sem::BuiltinType::kReflect),
-                     testing::ValuesIn(
-                         // ReflectCases<f32>())));
-                         Concat(ReflectCases<AFloat>(),  //
-                                ReflectCases<f32>(),     //
-                                ReflectCases<f16>()))));
+                     testing::ValuesIn(Concat(ReflectCases<AFloat>(),  //
+                                              ReflectCases<f32>(),     //
+                                              ReflectCases<f16>()))));
+
+template <typename T>
+std::vector<Case> RefractCases() {
+    // Returns "eta" (Greek letter) that denotes the ratio of indices of refraction for the input
+    // and output vector angles from the normal vector.
+    auto eta = [](auto angle1, auto angle2) {
+        // Snell's law: sin(angle1) / sin(angle2) == n2 / n1
+        // We want the ratio of n1 to n2, so sin(angle2) / sin(angle1)
+        auto angle1_rads = T(angle1) * kPi<T> / T(180);
+        auto angle2_rads = T(angle2) * kPi<T> / T(180);
+        return T(std::sin(angle2_rads) / std::sin(angle1_rads));
+    };
+
+    auto zero = Vec(T(0), T(0), T(0));
+    auto pos_y = Vec(T(0), T(1), T(0));
+    auto neg_y = Vec(T(0), -T(1), T(0));
+    auto pos_x = Vec(T(1), T(0), T(0));
+    auto neg_x = Vec(-T(1), T(0), T(0));
+    auto cos_45 = T(0.70710678118654752440084436210485);
+    auto cos_30 = T(0.86602540378443864676372317075294);
+    auto down_right = Vec(T(cos_45), -T(cos_45), T(0));
+    auto up_right = Vec(T(cos_45), T(cos_45), T(0));
+
+    auto eps = 0.001;
+    if constexpr (std::is_same_v<T, f16>) {
+        eps = 0.1;
+    }
+
+    auto r = std::vector<Case>{
+        // e3 (eta) == 1, no refraction, so input is same as output
+        C({down_right, pos_y, Val(T(1))}, down_right),
+        C({neg_y, pos_y, Val(T(1))}, neg_y),
+        // Varying etas
+        C({down_right, pos_y, Val(eta(45, 45))}, down_right).FloatComp(eps),  // e3 == 1
+        C({down_right, pos_y, Val(eta(45, 30))}, Vec(T(0.5), -T(cos_30), T(0))).FloatComp(eps),
+        C({down_right, pos_y, Val(eta(45, 60))}, Vec(T(cos_30), -T(0.5), T(0))).FloatComp(eps),
+        C({down_right, pos_y, Val(eta(45, 90))}, Vec(T(1), T(0), T(0))).FloatComp(eps),
+        // Flip input and normal, same result
+        C({up_right, neg_y, Val(eta(45, 45))}, up_right).FloatComp(eps),  // e3 == 1
+        C({up_right, neg_y, Val(eta(45, 30))}, Vec(T(0.5), T(cos_30), T(0))).FloatComp(eps),
+        C({up_right, neg_y, Val(eta(45, 60))}, Vec(T(cos_30), T(0.5), T(0))).FloatComp(eps),
+        C({up_right, neg_y, Val(eta(45, 90))}, Vec(T(1), T(0), T(0))).FloatComp(eps),
+        // Flip only normal, result is flipped
+        C({down_right, neg_y, Val(eta(45, 45))}, up_right).FloatComp(eps),  // e3 == 1
+        C({down_right, neg_y, Val(eta(45, 30))}, Vec(T(0.5), T(cos_30), T(0))).FloatComp(eps),
+        C({down_right, neg_y, Val(eta(45, 60))}, Vec(T(cos_30), T(0.5), T(0))).FloatComp(eps),
+        C({down_right, neg_y, Val(eta(45, 90))}, Vec(T(1), T(0), T(0))).FloatComp(eps),
+
+        // If k < 0.0, returns the refraction vector 0.0
+        C({down_right, pos_y, Val(T(2))}, zero).FloatComp(eps),
+
+        // A few more with a different normal (e2)
+        C({down_right, neg_x, Val(eta(45, 45))}, down_right).FloatComp(eps),  // e3 == 1
+        C({down_right, neg_x, Val(eta(45, 30))}, Vec(cos_30, -T(0.5), T(0))).FloatComp(eps),
+        C({down_right, neg_x, Val(eta(45, 60))}, Vec(T(0.5), -T(cos_30), T(0))).FloatComp(eps),
+    };
+
+    auto error_msg = [](auto a, const char* op, auto b) {
+        return "12:34 error: " + OverflowErrorMessage(a, op, b) + R"(
+12:34 note: when calculating refract)";
+    };
+    ConcatInto(  //
+        r,
+        std::vector<Case>{
+            // Overflow the dot product operation
+            E({Vec(T::Highest(), T::Highest(), T(0)), Vec(T(1), T(1), T(0)), Val(T(1))},
+              error_msg(T::Highest(), "+", T::Highest())),
+            E({Vec(T::Lowest(), T::Lowest(), T(0)), Vec(T(1), T(1), T(0)), Val(T(1))},
+              error_msg(T::Lowest(), "+", T::Lowest())),
+            // Overflow the k^2 operation
+            E({down_right, pos_y, Val(T::Highest())}, error_msg(T::Highest(), "*", T::Highest())),
+        });
+
+    return r;
+}
+INSTANTIATE_TEST_SUITE_P(  //
+    Refract,
+    ResolverConstEvalBuiltinTest,
+    testing::Combine(testing::Values(sem::BuiltinType::kRefract),
+                     testing::ValuesIn(Concat(RefractCases<AFloat>(),  //
+                                              RefractCases<f32>(),     //
+                                              RefractCases<f16>()))));
 
 template <typename T>
 std::vector<Case> RadiansCases() {
diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl
index 94044bf..d0752da 100644
--- a/src/tint/resolver/intrinsic_table.inl
+++ b/src/tint/resolver/intrinsic_table.inl
@@ -13710,12 +13710,12 @@
     /* num parameters */ 3,
     /* num template types */ 1,
     /* num template numbers */ 1,
-    /* template types */ &kTemplateTypes[26],
+    /* template types */ &kTemplateTypes[23],
     /* template numbers */ &kTemplateNumbers[4],
     /* parameters */ &kParameters[477],
     /* return matcher indices */ &kMatcherIndices[30],
     /* flags */ OverloadFlags(OverloadFlag::kIsBuiltin, OverloadFlag::kSupportsVertexPipeline, OverloadFlag::kSupportsFragmentPipeline, OverloadFlag::kSupportsComputePipeline),
-    /* const eval */ nullptr,
+    /* const eval */ &ConstEval::refract,
   },
   {
     /* [450] */
@@ -14421,7 +14421,7 @@
   },
   {
     /* [64] */
-    /* fn refract<N : num, T : f32_f16>(vec<N, T>, vec<N, T>, T) -> vec<N, T> */
+    /* fn refract<N : num, T : fa_f32_f16>(vec<N, T>, vec<N, T>, T) -> vec<N, T> */
     /* num overloads */ 1,
     /* overloads */ &kOverloads[449],
   },
diff --git a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.dxc.hlsl
index 7e12794..036961c 100644
--- a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_0594ba() {
-  vector<float16_t, 4> res = refract((float16_t(1.0h)).xxxx, (float16_t(1.0h)).xxxx, float16_t(1.0h));
+  vector<float16_t, 4> res = (float16_t(-7.0h)).xxxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.glsl
index c5293b5..093b8e6 100644
--- a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_0594ba() {
-  f16vec4 res = refract(f16vec4(1.0hf), f16vec4(1.0hf), 1.0hf);
+  f16vec4 res = f16vec4(-7.0hf);
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void refract_0594ba() {
-  f16vec4 res = refract(f16vec4(1.0hf), f16vec4(1.0hf), 1.0hf);
+  f16vec4 res = f16vec4(-7.0hf);
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_0594ba() {
-  f16vec4 res = refract(f16vec4(1.0hf), f16vec4(1.0hf), 1.0hf);
+  f16vec4 res = f16vec4(-7.0hf);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.msl
index e5623fa..b48045b 100644
--- a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_0594ba() {
-  half4 res = refract(half4(1.0h), half4(1.0h), 1.0h);
+  half4 res = half4(-7.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.spvasm
index 9c59d3b..ce2973d 100644
--- a/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/0594ba.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 34
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %16 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -37,38 +36,37 @@
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
      %v4half = OpTypeVector %half 4
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v4half %half_0x1p_0 %half_0x1p_0 %half_0x1p_0 %half_0x1p_0
+%half_n0x1_cp_2 = OpConstant %half -0x1.cp+2
+         %16 = OpConstantComposite %v4half %half_n0x1_cp_2 %half_n0x1_cp_2 %half_n0x1_cp_2 %half_n0x1_cp_2
 %_ptr_Function_v4half = OpTypePointer Function %v4half
-         %21 = OpConstantNull %v4half
-         %22 = OpTypeFunction %v4float
+         %19 = OpConstantNull %v4half
+         %20 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %refract_0594ba = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_v4half Function %21
-         %13 = OpExtInst %v4half %16 Refract %18 %18 %half_0x1p_0
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_v4half Function %19
+               OpStore %res %16
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %refract_0594ba
+%vertex_main_inner = OpFunction %v4float None %20
+         %22 = OpLabel
+         %23 = OpFunctionCall %void %refract_0594ba
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %25 = OpLabel
+         %26 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %26
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %refract_0594ba
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_0594ba
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %refract_0594ba
+         %32 = OpLabel
+         %33 = OpFunctionCall %void %refract_0594ba
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.dxc.hlsl
index 4a35894..c1b7878 100644
--- a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_570cb3() {
-  vector<float16_t, 2> res = refract((float16_t(1.0h)).xx, (float16_t(1.0h)).xx, float16_t(1.0h));
+  vector<float16_t, 2> res = (float16_t(-3.0h)).xx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.glsl
index b0f0ad1..8b473a1 100644
--- a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_570cb3() {
-  f16vec2 res = refract(f16vec2(1.0hf), f16vec2(1.0hf), 1.0hf);
+  f16vec2 res = f16vec2(-3.0hf);
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void refract_570cb3() {
-  f16vec2 res = refract(f16vec2(1.0hf), f16vec2(1.0hf), 1.0hf);
+  f16vec2 res = f16vec2(-3.0hf);
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_570cb3() {
-  f16vec2 res = refract(f16vec2(1.0hf), f16vec2(1.0hf), 1.0hf);
+  f16vec2 res = f16vec2(-3.0hf);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.msl
index 1414d82..77ac3c5 100644
--- a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_570cb3() {
-  half2 res = refract(half2(1.0h), half2(1.0h), 1.0h);
+  half2 res = half2(-3.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.spvasm
index 63fcc15..8b8e556 100644
--- a/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/570cb3.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 34
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %16 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -37,38 +36,37 @@
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
      %v2half = OpTypeVector %half 2
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v2half %half_0x1p_0 %half_0x1p_0
+%half_n0x1_8p_1 = OpConstant %half -0x1.8p+1
+         %16 = OpConstantComposite %v2half %half_n0x1_8p_1 %half_n0x1_8p_1
 %_ptr_Function_v2half = OpTypePointer Function %v2half
-         %21 = OpConstantNull %v2half
-         %22 = OpTypeFunction %v4float
+         %19 = OpConstantNull %v2half
+         %20 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %refract_570cb3 = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_v2half Function %21
-         %13 = OpExtInst %v2half %16 Refract %18 %18 %half_0x1p_0
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_v2half Function %19
+               OpStore %res %16
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %refract_570cb3
+%vertex_main_inner = OpFunction %v4float None %20
+         %22 = OpLabel
+         %23 = OpFunctionCall %void %refract_570cb3
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %25 = OpLabel
+         %26 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %26
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %refract_570cb3
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_570cb3
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %refract_570cb3
+         %32 = OpLabel
+         %33 = OpFunctionCall %void %refract_570cb3
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.dxc.hlsl
index d8c3de8..9a37846 100644
--- a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_7e02e6() {
-  float4 res = refract((1.0f).xxxx, (1.0f).xxxx, 1.0f);
+  float4 res = (-7.0f).xxxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.fxc.hlsl
index d8c3de8..9a37846 100644
--- a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void refract_7e02e6() {
-  float4 res = refract((1.0f).xxxx, (1.0f).xxxx, 1.0f);
+  float4 res = (-7.0f).xxxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.glsl
index 5c8bd1e..7c268cc 100644
--- a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void refract_7e02e6() {
-  vec4 res = refract(vec4(1.0f), vec4(1.0f), 1.0f);
+  vec4 res = vec4(-7.0f);
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void refract_7e02e6() {
-  vec4 res = refract(vec4(1.0f), vec4(1.0f), 1.0f);
+  vec4 res = vec4(-7.0f);
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void refract_7e02e6() {
-  vec4 res = refract(vec4(1.0f), vec4(1.0f), 1.0f);
+  vec4 res = vec4(-7.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.msl
index a44d158..4d49f47 100644
--- a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_7e02e6() {
-  float4 res = refract(float4(1.0f), float4(1.0f), 1.0f);
+  float4 res = float4(-7.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.spvasm
index 6cfa75a..8c8e3ad 100644
--- a/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/7e02e6.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 32
+; Bound: 31
 ; Schema: 0
                OpCapability Shader
-         %14 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -31,36 +30,36 @@
 %vertex_point_size = OpVariable %_ptr_Output_float Output %8
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
-    %float_1 = OpConstant %float 1
-         %16 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
+   %float_n7 = OpConstant %float -7
+         %14 = OpConstantComposite %v4float %float_n7 %float_n7 %float_n7 %float_n7
 %_ptr_Function_v4float = OpTypePointer Function %v4float
-         %19 = OpTypeFunction %v4float
+         %17 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %refract_7e02e6 = OpFunction %void None %9
          %12 = OpLabel
         %res = OpVariable %_ptr_Function_v4float Function %5
-         %13 = OpExtInst %v4float %14 Refract %16 %16 %float_1
-               OpStore %res %13
+               OpStore %res %14
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %19
-         %21 = OpLabel
-         %22 = OpFunctionCall %void %refract_7e02e6
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %refract_7e02e6
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %24 = OpLabel
-         %25 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %25
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %void %refract_7e02e6
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %refract_7e02e6
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %30 = OpLabel
-         %31 = OpFunctionCall %void %refract_7e02e6
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_7e02e6
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.dxc.hlsl
index 5e25ebc..1de0940 100644
--- a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_8984af() {
-  vector<float16_t, 3> res = refract((float16_t(1.0h)).xxx, (float16_t(1.0h)).xxx, float16_t(1.0h));
+  vector<float16_t, 3> res = (float16_t(-5.0h)).xxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.glsl
index 5bfbd94..0de3f68 100644
--- a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.glsl
@@ -2,7 +2,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_8984af() {
-  f16vec3 res = refract(f16vec3(1.0hf), f16vec3(1.0hf), 1.0hf);
+  f16vec3 res = f16vec3(-5.0hf);
 }
 
 vec4 vertex_main() {
@@ -23,7 +23,7 @@
 precision mediump float;
 
 void refract_8984af() {
-  f16vec3 res = refract(f16vec3(1.0hf), f16vec3(1.0hf), 1.0hf);
+  f16vec3 res = f16vec3(-5.0hf);
 }
 
 void fragment_main() {
@@ -38,7 +38,7 @@
 #extension GL_AMD_gpu_shader_half_float : require
 
 void refract_8984af() {
-  f16vec3 res = refract(f16vec3(1.0hf), f16vec3(1.0hf), 1.0hf);
+  f16vec3 res = f16vec3(-5.0hf);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.msl
index 977ac05..9f75260 100644
--- a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_8984af() {
-  half3 res = refract(half3(1.0h), half3(1.0h), 1.0h);
+  half3 res = half3(-5.0h);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.spvasm
index 7192390..48e5cfd 100644
--- a/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/8984af.wgsl.expected.spvasm
@@ -1,14 +1,13 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 36
+; Bound: 34
 ; Schema: 0
                OpCapability Shader
                OpCapability Float16
                OpCapability UniformAndStorageBuffer16BitAccess
                OpCapability StorageBuffer16BitAccess
                OpCapability StorageInputOutput16
-         %16 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -37,38 +36,37 @@
           %9 = OpTypeFunction %void
        %half = OpTypeFloat 16
      %v3half = OpTypeVector %half 3
-%half_0x1p_0 = OpConstant %half 0x1p+0
-         %18 = OpConstantComposite %v3half %half_0x1p_0 %half_0x1p_0 %half_0x1p_0
+%half_n0x1_4p_2 = OpConstant %half -0x1.4p+2
+         %16 = OpConstantComposite %v3half %half_n0x1_4p_2 %half_n0x1_4p_2 %half_n0x1_4p_2
 %_ptr_Function_v3half = OpTypePointer Function %v3half
-         %21 = OpConstantNull %v3half
-         %22 = OpTypeFunction %v4float
+         %19 = OpConstantNull %v3half
+         %20 = OpTypeFunction %v4float
     %float_1 = OpConstant %float 1
 %refract_8984af = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_v3half Function %21
-         %13 = OpExtInst %v3half %16 Refract %18 %18 %half_0x1p_0
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_v3half Function %19
+               OpStore %res %16
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %22
-         %24 = OpLabel
-         %25 = OpFunctionCall %void %refract_8984af
+%vertex_main_inner = OpFunction %v4float None %20
+         %22 = OpLabel
+         %23 = OpFunctionCall %void %refract_8984af
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %27 = OpLabel
-         %28 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %28
+         %25 = OpLabel
+         %26 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %26
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %31 = OpLabel
-         %32 = OpFunctionCall %void %refract_8984af
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_8984af
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %34 = OpLabel
-         %35 = OpFunctionCall %void %refract_8984af
+         %32 = OpLabel
+         %33 = OpFunctionCall %void %refract_8984af
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl
new file mode 100644
index 0000000..bf858d6
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<4, fa>, vec<4, fa>, fa) -> vec<4, fa>
+fn refract_8c192a() {
+  var res = refract(vec4(1.), vec4(1.), 1.);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_8c192a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_8c192a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_8c192a();
+}
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..ad89208
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_8c192a() {
+  float4 res = (-7.0f).xxxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_8c192a();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..ad89208
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_8c192a() {
+  float4 res = (-7.0f).xxxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_8c192a();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.glsl
new file mode 100644
index 0000000..1a30d60
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+vec4 vertex_main() {
+  refract_8c192a();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+void fragment_main() {
+  refract_8c192a();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+void compute_main() {
+  refract_8c192a();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.msl
new file mode 100644
index 0000000..ec3928e
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_8c192a() {
+  float4 res = float4(-7.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+kernel void compute_main() {
+  refract_8c192a();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.spvasm
new file mode 100644
index 0000000..6f9326d
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.spvasm
@@ -0,0 +1,65 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 31
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_8c192a "refract_8c192a"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+   %float_n7 = OpConstant %float -7
+         %14 = OpConstantComposite %v4float %float_n7 %float_n7 %float_n7 %float_n7
+%_ptr_Function_v4float = OpTypePointer Function %v4float
+         %17 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_8c192a = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v4float Function %5
+               OpStore %res %14
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %refract_8c192a
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %refract_8c192a
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_8c192a
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.wgsl
new file mode 100644
index 0000000..15b5d9e
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/8c192a.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn refract_8c192a() {
+  var res = refract(vec4(1.0), vec4(1.0), 1.0);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_8c192a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_8c192a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_8c192a();
+}
diff --git a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.dxc.hlsl
index 0fa2f16..66e3464 100644
--- a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_cbc1d2() {
-  float3 res = refract((1.0f).xxx, (1.0f).xxx, 1.0f);
+  float3 res = (-5.0f).xxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.fxc.hlsl
index 0fa2f16..66e3464 100644
--- a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void refract_cbc1d2() {
-  float3 res = refract((1.0f).xxx, (1.0f).xxx, 1.0f);
+  float3 res = (-5.0f).xxx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.glsl
index 45dc14b..4190d98 100644
--- a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void refract_cbc1d2() {
-  vec3 res = refract(vec3(1.0f), vec3(1.0f), 1.0f);
+  vec3 res = vec3(-5.0f);
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void refract_cbc1d2() {
-  vec3 res = refract(vec3(1.0f), vec3(1.0f), 1.0f);
+  vec3 res = vec3(-5.0f);
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void refract_cbc1d2() {
-  vec3 res = refract(vec3(1.0f), vec3(1.0f), 1.0f);
+  vec3 res = vec3(-5.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.msl
index dbec949..70bb490 100644
--- a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_cbc1d2() {
-  float3 res = refract(float3(1.0f), float3(1.0f), 1.0f);
+  float3 res = float3(-5.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.spvasm
index 5591003..c57564d 100644
--- a/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/cbc1d2.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 34
+; Bound: 33
 ; Schema: 0
                OpCapability Shader
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -32,37 +31,37 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
     %v3float = OpTypeVector %float 3
-    %float_1 = OpConstant %float 1
-         %17 = OpConstantComposite %v3float %float_1 %float_1 %float_1
+   %float_n5 = OpConstant %float -5
+         %15 = OpConstantComposite %v3float %float_n5 %float_n5 %float_n5
 %_ptr_Function_v3float = OpTypePointer Function %v3float
-         %20 = OpConstantNull %v3float
-         %21 = OpTypeFunction %v4float
+         %18 = OpConstantNull %v3float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %refract_cbc1d2 = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_v3float Function %20
-         %13 = OpExtInst %v3float %15 Refract %17 %17 %float_1
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %res %15
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %21
-         %23 = OpLabel
-         %24 = OpFunctionCall %void %refract_cbc1d2
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_cbc1d2
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %26 = OpLabel
-         %27 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %27
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %29 = OpLabel
-         %30 = OpFunctionCall %void %refract_cbc1d2
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_cbc1d2
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %32 = OpLabel
-         %33 = OpFunctionCall %void %refract_cbc1d2
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_cbc1d2
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.dxc.hlsl
index ef5d945..835d5c0 100644
--- a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.dxc.hlsl
@@ -1,5 +1,5 @@
 void refract_cd905f() {
-  float2 res = refract((1.0f).xx, (1.0f).xx, 1.0f);
+  float2 res = (-3.0f).xx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.fxc.hlsl
index ef5d945..835d5c0 100644
--- a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.fxc.hlsl
+++ b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.fxc.hlsl
@@ -1,5 +1,5 @@
 void refract_cd905f() {
-  float2 res = refract((1.0f).xx, (1.0f).xx, 1.0f);
+  float2 res = (-3.0f).xx;
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.glsl
index d0928e7..a962857 100644
--- a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.glsl
@@ -1,7 +1,7 @@
 #version 310 es
 
 void refract_cd905f() {
-  vec2 res = refract(vec2(1.0f), vec2(1.0f), 1.0f);
+  vec2 res = vec2(-3.0f);
 }
 
 vec4 vertex_main() {
@@ -21,7 +21,7 @@
 precision mediump float;
 
 void refract_cd905f() {
-  vec2 res = refract(vec2(1.0f), vec2(1.0f), 1.0f);
+  vec2 res = vec2(-3.0f);
 }
 
 void fragment_main() {
@@ -35,7 +35,7 @@
 #version 310 es
 
 void refract_cd905f() {
-  vec2 res = refract(vec2(1.0f), vec2(1.0f), 1.0f);
+  vec2 res = vec2(-3.0f);
 }
 
 void compute_main() {
diff --git a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.msl
index 1ba00a8..75ac067 100644
--- a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.msl
+++ b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.msl
@@ -2,7 +2,7 @@
 
 using namespace metal;
 void refract_cd905f() {
-  float2 res = refract(float2(1.0f), float2(1.0f), 1.0f);
+  float2 res = float2(-3.0f);
 }
 
 struct tint_symbol {
diff --git a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.spvasm
index 9a6516e..845a4de 100644
--- a/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.spvasm
+++ b/test/tint/builtins/gen/literal/refract/cd905f.wgsl.expected.spvasm
@@ -1,10 +1,9 @@
 ; SPIR-V
 ; Version: 1.3
 ; Generator: Google Tint Compiler; 0
-; Bound: 34
+; Bound: 33
 ; Schema: 0
                OpCapability Shader
-         %15 = OpExtInstImport "GLSL.std.450"
                OpMemoryModel Logical GLSL450
                OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
                OpEntryPoint Fragment %fragment_main "fragment_main"
@@ -32,37 +31,37 @@
        %void = OpTypeVoid
           %9 = OpTypeFunction %void
     %v2float = OpTypeVector %float 2
-    %float_1 = OpConstant %float 1
-         %17 = OpConstantComposite %v2float %float_1 %float_1
+   %float_n3 = OpConstant %float -3
+         %15 = OpConstantComposite %v2float %float_n3 %float_n3
 %_ptr_Function_v2float = OpTypePointer Function %v2float
-         %20 = OpConstantNull %v2float
-         %21 = OpTypeFunction %v4float
+         %18 = OpConstantNull %v2float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
 %refract_cd905f = OpFunction %void None %9
          %12 = OpLabel
-        %res = OpVariable %_ptr_Function_v2float Function %20
-         %13 = OpExtInst %v2float %15 Refract %17 %17 %float_1
-               OpStore %res %13
+        %res = OpVariable %_ptr_Function_v2float Function %18
+               OpStore %res %15
                OpReturn
                OpFunctionEnd
-%vertex_main_inner = OpFunction %v4float None %21
-         %23 = OpLabel
-         %24 = OpFunctionCall %void %refract_cd905f
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_cd905f
                OpReturnValue %5
                OpFunctionEnd
 %vertex_main = OpFunction %void None %9
-         %26 = OpLabel
-         %27 = OpFunctionCall %v4float %vertex_main_inner
-               OpStore %value %27
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
                OpStore %vertex_point_size %float_1
                OpReturn
                OpFunctionEnd
 %fragment_main = OpFunction %void None %9
-         %29 = OpLabel
-         %30 = OpFunctionCall %void %refract_cd905f
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_cd905f
                OpReturn
                OpFunctionEnd
 %compute_main = OpFunction %void None %9
-         %32 = OpLabel
-         %33 = OpFunctionCall %void %refract_cd905f
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_cd905f
                OpReturn
                OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl
new file mode 100644
index 0000000..ba0362c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<2, fa>, vec<2, fa>, fa) -> vec<2, fa>
+fn refract_cf1629() {
+  var res = refract(vec2(1.), vec2(1.), 1.);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_cf1629();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_cf1629();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_cf1629();
+}
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..125f05c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_cf1629() {
+  float2 res = (-3.0f).xx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_cf1629();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..125f05c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_cf1629() {
+  float2 res = (-3.0f).xx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_cf1629();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.glsl
new file mode 100644
index 0000000..3aa7137
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+vec4 vertex_main() {
+  refract_cf1629();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+void fragment_main() {
+  refract_cf1629();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+void compute_main() {
+  refract_cf1629();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.msl
new file mode 100644
index 0000000..b163611
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_cf1629() {
+  float2 res = float2(-3.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+kernel void compute_main() {
+  refract_cf1629();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.spvasm
new file mode 100644
index 0000000..ebc5b0e
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.spvasm
@@ -0,0 +1,67 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 33
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_cf1629 "refract_cf1629"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+    %v2float = OpTypeVector %float 2
+   %float_n3 = OpConstant %float -3
+         %15 = OpConstantComposite %v2float %float_n3 %float_n3
+%_ptr_Function_v2float = OpTypePointer Function %v2float
+         %18 = OpConstantNull %v2float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_cf1629 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v2float Function %18
+               OpStore %res %15
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_cf1629
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_cf1629
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_cf1629
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.wgsl
new file mode 100644
index 0000000..546b617
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/cf1629.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn refract_cf1629() {
+  var res = refract(vec2(1.0), vec2(1.0), 1.0);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_cf1629();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_cf1629();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_cf1629();
+}
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl
new file mode 100644
index 0000000..9a4b45a
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl
@@ -0,0 +1,43 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<3, fa>, vec<3, fa>, fa) -> vec<3, fa>
+fn refract_d7569b() {
+  var res = refract(vec3(1.), vec3(1.), 1.);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_d7569b();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_d7569b();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_d7569b();
+}
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..d462891
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_d7569b() {
+  float3 res = (-5.0f).xxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_d7569b();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..d462891
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_d7569b() {
+  float3 res = (-5.0f).xxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_d7569b();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.glsl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.glsl
new file mode 100644
index 0000000..c83ef7b
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+vec4 vertex_main() {
+  refract_d7569b();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+void fragment_main() {
+  refract_d7569b();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+void compute_main() {
+  refract_d7569b();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.msl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.msl
new file mode 100644
index 0000000..c164d6c
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_d7569b() {
+  float3 res = float3(-5.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+kernel void compute_main() {
+  refract_d7569b();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.spvasm b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.spvasm
new file mode 100644
index 0000000..e9daaa6
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.spvasm
@@ -0,0 +1,67 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 33
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_d7569b "refract_d7569b"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+    %v3float = OpTypeVector %float 3
+   %float_n5 = OpConstant %float -5
+         %15 = OpConstantComposite %v3float %float_n5 %float_n5 %float_n5
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %18 = OpConstantNull %v3float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_d7569b = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %res %15
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_d7569b
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_d7569b
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_d7569b
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.wgsl b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.wgsl
new file mode 100644
index 0000000..abd4e9f
--- /dev/null
+++ b/test/tint/builtins/gen/literal/refract/d7569b.wgsl.expected.wgsl
@@ -0,0 +1,19 @@
+fn refract_d7569b() {
+  var res = refract(vec3(1.0), vec3(1.0), 1.0);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_d7569b();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_d7569b();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_d7569b();
+}
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl b/test/tint/builtins/gen/var/refract/8c192a.wgsl
new file mode 100644
index 0000000..903f0df
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl
@@ -0,0 +1,46 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<4, fa>, vec<4, fa>, fa) -> vec<4, fa>
+fn refract_8c192a() {
+  const arg_0 = vec4(1.);
+  const arg_1 = vec4(1.);
+  const arg_2 = 1.;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_8c192a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_8c192a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_8c192a();
+}
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..ad89208
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_8c192a() {
+  float4 res = (-7.0f).xxxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_8c192a();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..ad89208
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_8c192a() {
+  float4 res = (-7.0f).xxxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_8c192a();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.glsl b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.glsl
new file mode 100644
index 0000000..1a30d60
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+vec4 vertex_main() {
+  refract_8c192a();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+void fragment_main() {
+  refract_8c192a();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_8c192a() {
+  vec4 res = vec4(-7.0f);
+}
+
+void compute_main() {
+  refract_8c192a();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.msl b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.msl
new file mode 100644
index 0000000..ec3928e
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_8c192a() {
+  float4 res = float4(-7.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_8c192a();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_8c192a();
+  return;
+}
+
+kernel void compute_main() {
+  refract_8c192a();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.spvasm b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.spvasm
new file mode 100644
index 0000000..6f9326d
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.spvasm
@@ -0,0 +1,65 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 31
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_8c192a "refract_8c192a"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+   %float_n7 = OpConstant %float -7
+         %14 = OpConstantComposite %v4float %float_n7 %float_n7 %float_n7 %float_n7
+%_ptr_Function_v4float = OpTypePointer Function %v4float
+         %17 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_8c192a = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v4float Function %5
+               OpStore %res %14
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %17
+         %19 = OpLabel
+         %20 = OpFunctionCall %void %refract_8c192a
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %22 = OpLabel
+         %23 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %23
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %26 = OpLabel
+         %27 = OpFunctionCall %void %refract_8c192a
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %29 = OpLabel
+         %30 = OpFunctionCall %void %refract_8c192a
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.wgsl b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.wgsl
new file mode 100644
index 0000000..ccec330
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/8c192a.wgsl.expected.wgsl
@@ -0,0 +1,22 @@
+fn refract_8c192a() {
+  const arg_0 = vec4(1.0);
+  const arg_1 = vec4(1.0);
+  const arg_2 = 1.0;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_8c192a();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_8c192a();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_8c192a();
+}
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl b/test/tint/builtins/gen/var/refract/cf1629.wgsl
new file mode 100644
index 0000000..d7197e0
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl
@@ -0,0 +1,46 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<2, fa>, vec<2, fa>, fa) -> vec<2, fa>
+fn refract_cf1629() {
+  const arg_0 = vec2(1.);
+  const arg_1 = vec2(1.);
+  const arg_2 = 1.;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_cf1629();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_cf1629();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_cf1629();
+}
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..125f05c
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_cf1629() {
+  float2 res = (-3.0f).xx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_cf1629();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..125f05c
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_cf1629() {
+  float2 res = (-3.0f).xx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_cf1629();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.glsl b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.glsl
new file mode 100644
index 0000000..3aa7137
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+vec4 vertex_main() {
+  refract_cf1629();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+void fragment_main() {
+  refract_cf1629();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_cf1629() {
+  vec2 res = vec2(-3.0f);
+}
+
+void compute_main() {
+  refract_cf1629();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.msl b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.msl
new file mode 100644
index 0000000..b163611
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_cf1629() {
+  float2 res = float2(-3.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_cf1629();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_cf1629();
+  return;
+}
+
+kernel void compute_main() {
+  refract_cf1629();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.spvasm b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.spvasm
new file mode 100644
index 0000000..ebc5b0e
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.spvasm
@@ -0,0 +1,67 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 33
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_cf1629 "refract_cf1629"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+    %v2float = OpTypeVector %float 2
+   %float_n3 = OpConstant %float -3
+         %15 = OpConstantComposite %v2float %float_n3 %float_n3
+%_ptr_Function_v2float = OpTypePointer Function %v2float
+         %18 = OpConstantNull %v2float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_cf1629 = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v2float Function %18
+               OpStore %res %15
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_cf1629
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_cf1629
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_cf1629
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.wgsl b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.wgsl
new file mode 100644
index 0000000..d31618c
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/cf1629.wgsl.expected.wgsl
@@ -0,0 +1,22 @@
+fn refract_cf1629() {
+  const arg_0 = vec2(1.0);
+  const arg_1 = vec2(1.0);
+  const arg_2 = 1.0;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_cf1629();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_cf1629();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_cf1629();
+}
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl b/test/tint/builtins/gen/var/refract/d7569b.wgsl
new file mode 100644
index 0000000..fe92eff
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl
@@ -0,0 +1,46 @@
+// Copyright 2022 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+////////////////////////////////////////////////////////////////////////////////
+// File generated by tools/src/cmd/gen
+// using the template:
+//   test/tint/builtins/gen/gen.wgsl.tmpl
+//
+// Do not modify this file directly
+////////////////////////////////////////////////////////////////////////////////
+
+
+// fn refract(vec<3, fa>, vec<3, fa>, fa) -> vec<3, fa>
+fn refract_d7569b() {
+  const arg_0 = vec3(1.);
+  const arg_1 = vec3(1.);
+  const arg_2 = 1.;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_d7569b();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_d7569b();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_d7569b();
+}
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..d462891
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.dxc.hlsl
@@ -0,0 +1,30 @@
+void refract_d7569b() {
+  float3 res = (-5.0f).xxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_d7569b();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.fxc.hlsl b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..d462891
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.fxc.hlsl
@@ -0,0 +1,30 @@
+void refract_d7569b() {
+  float3 res = (-5.0f).xxx;
+}
+
+struct tint_symbol {
+  float4 value : SV_Position;
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return (0.0f).xxxx;
+}
+
+tint_symbol vertex_main() {
+  const float4 inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = (tint_symbol)0;
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+  refract_d7569b();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.glsl b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.glsl
new file mode 100644
index 0000000..c83ef7b
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.glsl
@@ -0,0 +1,49 @@
+#version 310 es
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+vec4 vertex_main() {
+  refract_d7569b();
+  return vec4(0.0f);
+}
+
+void main() {
+  gl_PointSize = 1.0;
+  vec4 inner_result = vertex_main();
+  gl_Position = inner_result;
+  gl_Position.y = -(gl_Position.y);
+  gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
+  return;
+}
+#version 310 es
+precision mediump float;
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+void fragment_main() {
+  refract_d7569b();
+}
+
+void main() {
+  fragment_main();
+  return;
+}
+#version 310 es
+
+void refract_d7569b() {
+  vec3 res = vec3(-5.0f);
+}
+
+void compute_main() {
+  refract_d7569b();
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  compute_main();
+  return;
+}
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.msl b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.msl
new file mode 100644
index 0000000..c164d6c
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.msl
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void refract_d7569b() {
+  float3 res = float3(-5.0f);
+}
+
+struct tint_symbol {
+  float4 value [[position]];
+};
+
+float4 vertex_main_inner() {
+  refract_d7569b();
+  return float4(0.0f);
+}
+
+vertex tint_symbol vertex_main() {
+  float4 const inner_result = vertex_main_inner();
+  tint_symbol wrapper_result = {};
+  wrapper_result.value = inner_result;
+  return wrapper_result;
+}
+
+fragment void fragment_main() {
+  refract_d7569b();
+  return;
+}
+
+kernel void compute_main() {
+  refract_d7569b();
+  return;
+}
+
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.spvasm b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.spvasm
new file mode 100644
index 0000000..e9daaa6
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.spvasm
@@ -0,0 +1,67 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 33
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint Vertex %vertex_main "vertex_main" %value %vertex_point_size
+               OpEntryPoint Fragment %fragment_main "fragment_main"
+               OpEntryPoint GLCompute %compute_main "compute_main"
+               OpExecutionMode %fragment_main OriginUpperLeft
+               OpExecutionMode %compute_main LocalSize 1 1 1
+               OpName %value "value"
+               OpName %vertex_point_size "vertex_point_size"
+               OpName %refract_d7569b "refract_d7569b"
+               OpName %res "res"
+               OpName %vertex_main_inner "vertex_main_inner"
+               OpName %vertex_main "vertex_main"
+               OpName %fragment_main "fragment_main"
+               OpName %compute_main "compute_main"
+               OpDecorate %value BuiltIn Position
+               OpDecorate %vertex_point_size BuiltIn PointSize
+      %float = OpTypeFloat 32
+    %v4float = OpTypeVector %float 4
+%_ptr_Output_v4float = OpTypePointer Output %v4float
+          %5 = OpConstantNull %v4float
+      %value = OpVariable %_ptr_Output_v4float Output %5
+%_ptr_Output_float = OpTypePointer Output %float
+          %8 = OpConstantNull %float
+%vertex_point_size = OpVariable %_ptr_Output_float Output %8
+       %void = OpTypeVoid
+          %9 = OpTypeFunction %void
+    %v3float = OpTypeVector %float 3
+   %float_n5 = OpConstant %float -5
+         %15 = OpConstantComposite %v3float %float_n5 %float_n5 %float_n5
+%_ptr_Function_v3float = OpTypePointer Function %v3float
+         %18 = OpConstantNull %v3float
+         %19 = OpTypeFunction %v4float
+    %float_1 = OpConstant %float 1
+%refract_d7569b = OpFunction %void None %9
+         %12 = OpLabel
+        %res = OpVariable %_ptr_Function_v3float Function %18
+               OpStore %res %15
+               OpReturn
+               OpFunctionEnd
+%vertex_main_inner = OpFunction %v4float None %19
+         %21 = OpLabel
+         %22 = OpFunctionCall %void %refract_d7569b
+               OpReturnValue %5
+               OpFunctionEnd
+%vertex_main = OpFunction %void None %9
+         %24 = OpLabel
+         %25 = OpFunctionCall %v4float %vertex_main_inner
+               OpStore %value %25
+               OpStore %vertex_point_size %float_1
+               OpReturn
+               OpFunctionEnd
+%fragment_main = OpFunction %void None %9
+         %28 = OpLabel
+         %29 = OpFunctionCall %void %refract_d7569b
+               OpReturn
+               OpFunctionEnd
+%compute_main = OpFunction %void None %9
+         %31 = OpLabel
+         %32 = OpFunctionCall %void %refract_d7569b
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.wgsl b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.wgsl
new file mode 100644
index 0000000..2349c31
--- /dev/null
+++ b/test/tint/builtins/gen/var/refract/d7569b.wgsl.expected.wgsl
@@ -0,0 +1,22 @@
+fn refract_d7569b() {
+  const arg_0 = vec3(1.0);
+  const arg_1 = vec3(1.0);
+  const arg_2 = 1.0;
+  var res = refract(arg_0, arg_1, arg_2);
+}
+
+@vertex
+fn vertex_main() -> @builtin(position) vec4<f32> {
+  refract_d7569b();
+  return vec4<f32>();
+}
+
+@fragment
+fn fragment_main() {
+  refract_d7569b();
+}
+
+@compute @workgroup_size(1)
+fn compute_main() {
+  refract_d7569b();
+}