From fe66cbe7bb657f436de86d85f6c9a8da796236cc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 16 Jun 2021 09:19:36 +0000 Subject: [PATCH] writer/hlsl: Implement fma() Change-Id: I30763381bcb0588379e0896f014fa9756b5f3395 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54324 Kokoro: Kokoro Reviewed-by: David Neto --- src/writer/hlsl/generator_impl.cc | 10 ++++---- src/writer/hlsl/generator_impl_import_test.cc | 2 +- .../hlsl/generator_impl_intrinsic_test.cc | 2 +- .../gen/fma/26a7a9.wgsl.expected.hlsl | 25 +------------------ .../gen/fma/6a3283.wgsl.expected.hlsl | 25 +------------------ .../gen/fma/c10ba3.wgsl.expected.hlsl | 25 +------------------ .../gen/fma/e17c5c.wgsl.expected.hlsl | 25 +------------------ 7 files changed, 11 insertions(+), 103 deletions(-) diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index f159791861..eded04894f 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -528,11 +528,9 @@ bool GeneratorImpl::EmitCall(std::ostream& pre, if (auto* intrinsic = call->Target()->As()) { if (intrinsic->IsTexture()) { return EmitTextureCall(pre, out, expr, intrinsic); - } - if (intrinsic->Type() == sem::IntrinsicType::kSelect) { + } else if (intrinsic->Type() == sem::IntrinsicType::kSelect) { return EmitSelectCall(pre, out, expr); - } - if (intrinsic->Type() == sem::IntrinsicType::kFrexp) { + } else if (intrinsic->Type() == sem::IntrinsicType::kFrexp) { return EmitFrexpCall(pre, out, expr, intrinsic); } else if (intrinsic->Type() == sem::IntrinsicType::kIsNormal) { return EmitIsNormalCall(pre, out, expr, intrinsic); @@ -1177,7 +1175,6 @@ std::string GeneratorImpl::generate_builtin_name( case sem::IntrinsicType::kExp: case sem::IntrinsicType::kExp2: case sem::IntrinsicType::kFloor: - case sem::IntrinsicType::kFma: case sem::IntrinsicType::kFrexp: case sem::IntrinsicType::kLdexp: case sem::IntrinsicType::kLength: @@ -1228,6 +1225,9 @@ std::string GeneratorImpl::generate_builtin_name( case sem::IntrinsicType::kFract: out = "frac"; break; + case sem::IntrinsicType::kFma: + out = "mad"; + break; case sem::IntrinsicType::kFwidth: case sem::IntrinsicType::kFwidthCoarse: case sem::IntrinsicType::kFwidthFine: diff --git a/src/writer/hlsl/generator_impl_import_test.cc b/src/writer/hlsl/generator_impl_import_test.cc index cec626fcba..201f34591c 100644 --- a/src/writer/hlsl/generator_impl_import_test.cc +++ b/src/writer/hlsl/generator_impl_import_test.cc @@ -201,7 +201,7 @@ INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Import, HlslImportData_TripleParamTest, testing::Values(HlslImportData{"faceForward", "faceforward"}, - HlslImportData{"fma", "fma"}, + HlslImportData{"fma", "mad"}, HlslImportData{"clamp", "clamp"}, HlslImportData{"smoothStep", "smoothstep"})); diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index ee4a206ebe..0e5a619440 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -217,7 +217,7 @@ INSTANTIATE_TEST_SUITE_P( IntrinsicData{IntrinsicType::kFaceForward, ParamType::kF32, "faceforward"}, IntrinsicData{IntrinsicType::kFloor, ParamType::kF32, "floor"}, - IntrinsicData{IntrinsicType::kFma, ParamType::kF32, "fma"}, + IntrinsicData{IntrinsicType::kFma, ParamType::kF32, "mad"}, IntrinsicData{IntrinsicType::kFract, ParamType::kF32, "frac"}, IntrinsicData{IntrinsicType::kFwidth, ParamType::kF32, "fwidth"}, IntrinsicData{IntrinsicType::kFwidthCoarse, ParamType::kF32, "fwidth"}, diff --git a/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl b/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl index 6c1e754e01..c9733c7d03 100644 --- a/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl +++ b/test/intrinsics/gen/fma/26a7a9.wgsl.expected.hlsl @@ -1,10 +1,5 @@ -SKIP: FAILED - - - -Validation Failure: void fma_26a7a9() { - float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f)); + float2 res = mad(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f)); } struct tint_symbol { @@ -27,21 +22,3 @@ void compute_main() { fma_26a7a9(); return; } - -tint_9GH744:2:16: error: no matching function for call to 'fma' - float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_9GH744:2:16: error: no matching function for call to 'fma' - float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_9GH744:2:16: error: no matching function for call to 'fma' - float2 res = fma(float2(0.0f, 0.0f), float2(0.0f, 0.0f), float2(0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - diff --git a/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl b/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl index 5e9e0c92e1..d6d98d3dcd 100644 --- a/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl +++ b/test/intrinsics/gen/fma/6a3283.wgsl.expected.hlsl @@ -1,10 +1,5 @@ -SKIP: FAILED - - - -Validation Failure: void fma_6a3283() { - float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)); + float4 res = mad(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)); } struct tint_symbol { @@ -27,21 +22,3 @@ void compute_main() { fma_6a3283(); return; } - -tint_GZ5kFN:2:16: error: no matching function for call to 'fma' - float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_GZ5kFN:2:16: error: no matching function for call to 'fma' - float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_GZ5kFN:2:16: error: no matching function for call to 'fma' - float4 res = fma(float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - diff --git a/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl b/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl index 3181c25e15..eead041818 100644 --- a/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl +++ b/test/intrinsics/gen/fma/c10ba3.wgsl.expected.hlsl @@ -1,10 +1,5 @@ -SKIP: FAILED - - - -Validation Failure: void fma_c10ba3() { - float res = fma(1.0f, 1.0f, 1.0f); + float res = mad(1.0f, 1.0f, 1.0f); } struct tint_symbol { @@ -27,21 +22,3 @@ void compute_main() { fma_c10ba3(); return; } - -tint_tqaLcU:2:15: error: no matching function for call to 'fma' - float res = fma(1.0f, 1.0f, 1.0f); - ^~~ -note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument - - -tint_tqaLcU:2:15: error: no matching function for call to 'fma' - float res = fma(1.0f, 1.0f, 1.0f); - ^~~ -note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument - - -tint_tqaLcU:2:15: error: no matching function for call to 'fma' - float res = fma(1.0f, 1.0f, 1.0f); - ^~~ -note: candidate function not viable: no known conversion from 'float' to 'double' for 1st argument - diff --git a/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl b/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl index aa67a89177..958567bb86 100644 --- a/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl +++ b/test/intrinsics/gen/fma/e17c5c.wgsl.expected.hlsl @@ -1,10 +1,5 @@ -SKIP: FAILED - - - -Validation Failure: void fma_e17c5c() { - float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f)); + float3 res = mad(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f)); } struct tint_symbol { @@ -27,21 +22,3 @@ void compute_main() { fma_e17c5c(); return; } - -tint_NJUQps:2:16: error: no matching function for call to 'fma' - float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_NJUQps:2:16: error: no matching function for call to 'fma' - float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument - - -tint_NJUQps:2:16: error: no matching function for call to 'fma' - float3 res = fma(float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f)); - ^~~ -note: candidate function not viable: no known conversion from 'vector' to 'vector' for 1st argument -