Output infinity and NaN literals correctly in shaders

Previously infinity and NaN resulting from constant folding would be
clamped to finite 32-bit float range when they were written in shader
output. Now they are written as a bit pattern in case the shader
version allows it.

This does not guarantee that NaNs work, but this is fine, since ESSL
3.00.6 spec has very loose requirements when it comes to NaNs.

BUG=angleproject:1654
TEST=angle_end2end_tests

Change-Id: I9997000beeaa8ed22523c22d5cf6929cdfc93f60
Reviewed-on: https://chromium-review.googlesource.com/417301
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index 6860edc..47c75fd 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -7,6 +7,7 @@
 #include "compiler/translator/OutputGLSLBase.h"
 
 #include "common/debug.h"
+#include "common/mathutil.h"
 
 #include <cfloat>
 
@@ -112,6 +113,18 @@
     }
 }
 
+void TOutputGLSLBase::writeFloat(TInfoSinkBase &out, float f)
+{
+    if ((gl::isInf(f) || gl::isNaN(f)) && mShaderVersion >= 300)
+    {
+        out << "uintBitsToFloat(" << gl::bitCast<uint32_t>(f) << "u)";
+    }
+    else
+    {
+        out << std::min(FLT_MAX, std::max(-FLT_MAX, f));
+    }
+}
+
 void TOutputGLSLBase::writeTriplet(
     Visit visit, const char *preStr, const char *inStr, const char *postStr)
 {
@@ -329,8 +342,8 @@
             switch (pConstUnion->getType())
             {
               case EbtFloat:
-                out << std::min(FLT_MAX, std::max(-FLT_MAX, pConstUnion->getFConst()));
-                break;
+                  writeFloat(out, pConstUnion->getFConst());
+                  break;
               case EbtInt:
                 out << pConstUnion->getIConst();
                 break;