From 30c03a5d5075a5935c66eb5a82a85b4f87ddf116 Mon Sep 17 00:00:00 2001 From: Zhaoming Jiang Date: Fri, 30 Apr 2021 08:47:06 +0000 Subject: [PATCH] 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 Reviewed-by: Corentin Wallez Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton --- src/writer/hlsl/generator_impl.cc | 4 +++- src/writer/hlsl/generator_impl_intrinsic_test.cc | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 198456b532..98e85929b2 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -1179,7 +1179,6 @@ std::string GeneratorImpl::generate_builtin_name( 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 @@ std::string GeneratorImpl::generate_builtin_name( 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 19336fdca0..bb8e198618 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -230,6 +230,7 @@ INSTANTIATE_TEST_SUITE_P( 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"},