writer/hlsl: Implement fma()

Change-Id: I30763381bcb0588379e0896f014fa9756b5f3395
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54324
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2021-06-16 09:19:36 +00:00 committed by Ben Clayton
parent 35ce0d1993
commit fe66cbe7bb
7 changed files with 11 additions and 103 deletions

View File

@ -528,11 +528,9 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
if (auto* intrinsic = call->Target()->As<sem::Intrinsic>()) {
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:

View File

@ -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"}));

View File

@ -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"},

View File

@ -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<float, 2>' to 'vector<double, 2>' 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<float, 2>' to 'vector<double, 2>' 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<float, 2>' to 'vector<double, 2>' for 1st argument

View File

@ -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<float, 4>' to 'vector<double, 4>' 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<float, 4>' to 'vector<double, 4>' 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<float, 4>' to 'vector<double, 4>' for 1st argument

View File

@ -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

View File

@ -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<float, 3>' to 'vector<double, 3>' 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<float, 3>' to 'vector<double, 3>' 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<float, 3>' to 'vector<double, 3>' for 1st argument