HLSL writer: Translate the built-in function "mix" into "lerp"
The built-in function "mix" in WGSL should be translated into the
intrinsic function "lerp" in HLSL according to the HLSL document.
With this patch the dawn sample CubeReflection will be able to run
correctly with tint generator on D3D12 backend.
Bug: tint:758
Change-Id: I7e84987c02fd2090d5e7af8f4aba995fc95a6fdb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49601
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc
index 198456b..98e8592 100644
--- a/src/writer/hlsl/generator_impl.cc
+++ b/src/writer/hlsl/generator_impl.cc
@@ -1179,7 +1179,6 @@
case sem::IntrinsicType::kTan:
case sem::IntrinsicType::kTanh:
case sem::IntrinsicType::kTrunc:
- case sem::IntrinsicType::kMix:
case sem::IntrinsicType::kSign:
case sem::IntrinsicType::kAbs:
case sem::IntrinsicType::kMax:
@@ -1231,6 +1230,9 @@
case sem::IntrinsicType::kIsNan:
out = "isnan";
break;
+ case sem::IntrinsicType::kMix:
+ out = "lerp";
+ break;
case sem::IntrinsicType::kReverseBits:
out = "reversebits";
break;
diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc
index 19336fd..bb8e198 100644
--- a/src/writer/hlsl/generator_impl_intrinsic_test.cc
+++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc
@@ -230,6 +230,7 @@
IntrinsicData{IntrinsicType::kMax, ParamType::kU32, "max"},
IntrinsicData{IntrinsicType::kMin, ParamType::kF32, "min"},
IntrinsicData{IntrinsicType::kMin, ParamType::kU32, "min"},
+ IntrinsicData{IntrinsicType::kMix, ParamType::kF32, "lerp"},
IntrinsicData{IntrinsicType::kNormalize, ParamType::kF32, "normalize"},
IntrinsicData{IntrinsicType::kPow, ParamType::kF32, "pow"},
IntrinsicData{IntrinsicType::kReflect, ParamType::kF32, "reflect"},