tint/hlsl: don't use min16float to implement quantizeToF16

min16float is not required to convert its input to an 16-bit float.
Instead, use f32tof16, and f16tof32.

This is also required to be able to enable the IEEE strictness option on
FXC, otherwise FXC emits an error X4028: expression has a minimum
precision type and cannot be marked precise

Bug: tint:1887
Change-Id: I2268c9336b8e873b36e6532984838054fe4dedbd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125920
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2023-03-31 08:00:33 +00:00 committed by Dawn LUCI CQ
parent 73f2405304
commit 51249b83e6
10 changed files with 13 additions and 12 deletions

View File

@ -2106,12 +2106,13 @@ bool GeneratorImpl::EmitSignCall(utils::StringStream& out,
bool GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out,
const ast::CallExpression* expr,
const sem::Builtin* builtin) {
// Emulate by casting to min16float and back again.
// Cast to f16 and back
std::string width;
if (auto* vec = builtin->ReturnType()->As<type::Vector>()) {
width = std::to_string(vec->Width());
}
out << "float" << width << "(min16float" << width << "(";
out << "f16tof32(f32tof16"
<< "(";
if (!EmitExpression(out, expr->args[0])) {
return false;
}

View File

@ -275,7 +275,7 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Scalar) {
utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("float(min16float(v))"));
EXPECT_EQ(out.str(), std::string("f16tof32(f32tof16(v))"));
}
TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Vector) {
@ -288,7 +288,7 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Vector) {
utils::StringStream out;
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
EXPECT_EQ(out.str(), std::string("float3(min16float3(v))"));
EXPECT_EQ(out.str(), std::string("f16tof32(f32tof16(v))"));
}
} // namespace

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_12e50e() {
float arg_0 = 1.0f;
float res = float(min16float(arg_0));
float res = f16tof32(f32tof16(arg_0));
prevent_dce.Store(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_12e50e() {
float arg_0 = 1.0f;
float res = float(min16float(arg_0));
float res = f16tof32(f32tof16(arg_0));
prevent_dce.Store(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_2cddf3() {
float2 arg_0 = (1.0f).xx;
float2 res = float2(min16float2(arg_0));
float2 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store2(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_2cddf3() {
float2 arg_0 = (1.0f).xx;
float2 res = float2(min16float2(arg_0));
float2 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store2(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_cba294() {
float4 arg_0 = (1.0f).xxxx;
float4 res = float4(min16float4(arg_0));
float4 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store4(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_cba294() {
float4 arg_0 = (1.0f).xxxx;
float4 res = float4(min16float4(arg_0));
float4 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store4(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_e8fd14() {
float3 arg_0 = (1.0f).xxx;
float3 res = float3(min16float3(arg_0));
float3 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store3(0u, asuint(res));
}

View File

@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
void quantizeToF16_e8fd14() {
float3 arg_0 = (1.0f).xxx;
float3 res = float3(min16float3(arg_0));
float3 res = f16tof32(f32tof16(arg_0));
prevent_dce.Store3(0u, asuint(res));
}