GLSL: fix isNormal.

(I know it's deprecated, I'm just being a completist.)

Bug: tint:1222
Change-Id: Ie7716d2f5dd2d2bd2245ba2b0fe7ed8705574de0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80141
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White
2022-02-11 14:35:14 +00:00
committed by Tint LUCI CQ
parent 723f999ac2
commit 6f9ac3524a
7 changed files with 92 additions and 166 deletions

View File

@@ -970,21 +970,27 @@ bool GeneratorImpl::EmitIsNormalCall(std::ostream& out,
[&](TextBuffer* b, const std::vector<std::string>& params) {
auto* input_ty = builtin->Parameters()[0]->Type();
std::string width;
std::string vec_type;
if (auto* vec = input_ty->As<sem::Vector>()) {
width = std::to_string(vec->Width());
vec_type = "uvec" + std::to_string(vec->Width());
} else {
vec_type = "uint";
}
constexpr auto* kExponentMask = "0x7f80000";
constexpr auto* kMinNormalExponent = "0x0080000";
constexpr auto* kMaxNormalExponent = "0x7f00000";
constexpr auto* kExponentMask = "0x7f80000u";
constexpr auto* kMinNormalExponent = "0x0080000u";
constexpr auto* kMaxNormalExponent = "0x7f00000u";
line(b) << "uint" << width << " exponent = asuint(" << params[0]
line(b) << vec_type << " exponent = floatBitsToUint(" << params[0]
<< ") & " << kExponentMask << ";";
line(b) << "uint" << width << " clamped = "
line(b) << vec_type << " clamped = "
<< "clamp(exponent, " << kMinNormalExponent << ", "
<< kMaxNormalExponent << ");";
line(b) << "return clamped == exponent;";
if (input_ty->Is<sem::Vector>()) {
line(b) << "return equal(clamped, exponent);";
} else {
line(b) << "return clamped == exponent;";
}
return true;
});
}

View File

@@ -415,7 +415,6 @@ void main() {
)"));
}
#if 0
TEST_F(GlslGeneratorImplTest_Builtin, IsNormal_Scalar) {
auto* val = Var("val", ty.f32());
auto* call = Call("isNormal", val);
@@ -424,10 +423,23 @@ TEST_F(GlslGeneratorImplTest_Builtin, IsNormal_Scalar) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
uint tint_isnormal_exponent = asuint(val) & 0x7f80000;
uint tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
(tint_isnormal_clamped == tint_isnormal_exponent);
EXPECT_THAT(gen.result(), HasSubstr(R"(ion 310 es
bool tint_isNormal(float param_0) {
uint exponent = floatBitsToUint(param_0) & 0x7f80000u;
uint clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
return clamped == exponent;
}
void test_function() {
float val = 0.0f;
bool tint_symbol = tint_isNormal(val);
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
test_function();
)"));
}
@@ -439,13 +451,25 @@ TEST_F(GlslGeneratorImplTest_Builtin, IsNormal_Vector) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate()) << gen.error();
EXPECT_THAT(gen.result(), HasSubstr(R"(
uvec3 tint_isnormal_exponent = asuint(val) & 0x7f80000;
uvec3 tint_isnormal_clamped = clamp(tint_isnormal_exponent, 0x0080000, 0x7f00000);
(tint_isnormal_clamped == tint_isnormal_exponent);
EXPECT_THAT(gen.result(), HasSubstr(R"( 310 es
bvec3 tint_isNormal(vec3 param_0) {
uvec3 exponent = floatBitsToUint(param_0) & 0x7f80000u;
uvec3 clamped = clamp(exponent, 0x0080000u, 0x7f00000u);
return equal(clamped, exponent);
}
void test_function() {
vec3 val = vec3(0.0f, 0.0f, 0.0f);
bvec3 tint_symbol = tint_isNormal(val);
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
test_function();
)"));
}
#endif
TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Scalar) {
auto* val = Var("val", ty.f32());