Fix clamping of NaN values.
We pass integer uniforms as floating-point ones, which can cause an
exception when converting them to fixed-point values. For example an
integer value of -1 would be 0xFFFFFFFF which is Not-a-Number in
IEEE-754 floating-point and can't be cast to an integer.
In this case we don't actually care about the result because the fixed-
point number is only used by the fixed-function pipeline. A safe but
still fast way to compare floating-point numbers including NaNs is to
treat them as one's complement integers, which can easily be converted
into two's complement representation.
Also rename bitCast<> to bit_cast<> to match the C++20 function.
Change-Id: Id588d25ab70d31eda2800c24a8df539d6a3411d4
Reviewed-on: https://swiftshader-review.googlesource.com/c/21708
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/OpenGL/compiler/Intermediate.cpp b/src/OpenGL/compiler/Intermediate.cpp
index ee77a2f..9f68dc7 100644
--- a/src/OpenGL/compiler/Intermediate.cpp
+++ b/src/OpenGL/compiler/Intermediate.cpp
@@ -1974,7 +1974,7 @@
case EOpFloatBitsToInt:
switch(basicType) {
case EbtFloat:
- tempConstArray[i].setIConst(sw::bitCast<int>(unionArray[i].getFConst()));
+ tempConstArray[i].setIConst(sw::bit_cast<int>(unionArray[i].getFConst()));
type.setBasicType(EbtInt);
break;
default:
@@ -1986,7 +1986,7 @@
case EOpFloatBitsToUint:
switch(basicType) {
case EbtFloat:
- tempConstArray[i].setUConst(sw::bitCast<unsigned int>(unionArray[i].getFConst()));
+ tempConstArray[i].setUConst(sw::bit_cast<unsigned int>(unionArray[i].getFConst()));
type.setBasicType(EbtUInt);
break;
default:
@@ -1997,7 +1997,7 @@
case EOpIntBitsToFloat:
switch(basicType) {
case EbtInt:
- tempConstArray[i].setFConst(sw::bitCast<float>(unionArray[i].getIConst()));
+ tempConstArray[i].setFConst(sw::bit_cast<float>(unionArray[i].getIConst()));
type.setBasicType(EbtFloat);
break;
default:
@@ -2008,7 +2008,7 @@
case EOpUintBitsToFloat:
switch(basicType) {
case EbtUInt:
- tempConstArray[i].setFConst(sw::bitCast<float>(unionArray[i].getUConst()));
+ tempConstArray[i].setFConst(sw::bit_cast<float>(unionArray[i].getUConst()));
type.setBasicType(EbtFloat);
break;
default: