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:
parent
73f2405304
commit
51249b83e6
|
@ -2106,12 +2106,13 @@ bool GeneratorImpl::EmitSignCall(utils::StringStream& out,
|
||||||
bool GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out,
|
bool GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out,
|
||||||
const ast::CallExpression* expr,
|
const ast::CallExpression* expr,
|
||||||
const sem::Builtin* builtin) {
|
const sem::Builtin* builtin) {
|
||||||
// Emulate by casting to min16float and back again.
|
// Cast to f16 and back
|
||||||
std::string width;
|
std::string width;
|
||||||
if (auto* vec = builtin->ReturnType()->As<type::Vector>()) {
|
if (auto* vec = builtin->ReturnType()->As<type::Vector>()) {
|
||||||
width = std::to_string(vec->Width());
|
width = std::to_string(vec->Width());
|
||||||
}
|
}
|
||||||
out << "float" << width << "(min16float" << width << "(";
|
out << "f16tof32(f32tof16"
|
||||||
|
<< "(";
|
||||||
if (!EmitExpression(out, expr->args[0])) {
|
if (!EmitExpression(out, expr->args[0])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,7 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Scalar) {
|
||||||
|
|
||||||
utils::StringStream out;
|
utils::StringStream out;
|
||||||
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
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) {
|
TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Vector) {
|
||||||
|
@ -288,7 +288,7 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_QuantizeToF16_Vector) {
|
||||||
|
|
||||||
utils::StringStream out;
|
utils::StringStream out;
|
||||||
ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.error();
|
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
|
} // namespace
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_12e50e() {
|
void quantizeToF16_12e50e() {
|
||||||
float arg_0 = 1.0f;
|
float arg_0 = 1.0f;
|
||||||
float res = float(min16float(arg_0));
|
float res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store(0u, asuint(res));
|
prevent_dce.Store(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_12e50e() {
|
void quantizeToF16_12e50e() {
|
||||||
float arg_0 = 1.0f;
|
float arg_0 = 1.0f;
|
||||||
float res = float(min16float(arg_0));
|
float res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store(0u, asuint(res));
|
prevent_dce.Store(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_2cddf3() {
|
void quantizeToF16_2cddf3() {
|
||||||
float2 arg_0 = (1.0f).xx;
|
float2 arg_0 = (1.0f).xx;
|
||||||
float2 res = float2(min16float2(arg_0));
|
float2 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store2(0u, asuint(res));
|
prevent_dce.Store2(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_2cddf3() {
|
void quantizeToF16_2cddf3() {
|
||||||
float2 arg_0 = (1.0f).xx;
|
float2 arg_0 = (1.0f).xx;
|
||||||
float2 res = float2(min16float2(arg_0));
|
float2 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store2(0u, asuint(res));
|
prevent_dce.Store2(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_cba294() {
|
void quantizeToF16_cba294() {
|
||||||
float4 arg_0 = (1.0f).xxxx;
|
float4 arg_0 = (1.0f).xxxx;
|
||||||
float4 res = float4(min16float4(arg_0));
|
float4 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store4(0u, asuint(res));
|
prevent_dce.Store4(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_cba294() {
|
void quantizeToF16_cba294() {
|
||||||
float4 arg_0 = (1.0f).xxxx;
|
float4 arg_0 = (1.0f).xxxx;
|
||||||
float4 res = float4(min16float4(arg_0));
|
float4 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store4(0u, asuint(res));
|
prevent_dce.Store4(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_e8fd14() {
|
void quantizeToF16_e8fd14() {
|
||||||
float3 arg_0 = (1.0f).xxx;
|
float3 arg_0 = (1.0f).xxx;
|
||||||
float3 res = float3(min16float3(arg_0));
|
float3 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store3(0u, asuint(res));
|
prevent_dce.Store3(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ RWByteAddressBuffer prevent_dce : register(u0, space2);
|
||||||
|
|
||||||
void quantizeToF16_e8fd14() {
|
void quantizeToF16_e8fd14() {
|
||||||
float3 arg_0 = (1.0f).xxx;
|
float3 arg_0 = (1.0f).xxx;
|
||||||
float3 res = float3(min16float3(arg_0));
|
float3 res = f16tof32(f32tof16(arg_0));
|
||||||
prevent_dce.Store3(0u, asuint(res));
|
prevent_dce.Store3(0u, asuint(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue