Commit a4e5223a by apatrick@chromium.org

In generated shaders, output +INF and -INF as largest single precision floating point number.

C++ streams seem to use the representation 1.$ for INF and that isn't valid syntax in GLSL or HLSL. Also preserve the sign of INF in constant expressions that divide by zero. I can't figure out what to do about 0/0 because the shader models we are using do not support NaN. Treating it as +INF as before. Review URL: https://codereview.appspot.com/7057046 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1644 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 0a67e5e1
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1642 #define BUILD_REVISION 1644
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -1162,7 +1162,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1162,7 +1162,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EbtFloat: case EbtFloat:
if (rightUnionArray[i] == 0.0f) { if (rightUnionArray[i] == 0.0f) {
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
tempConstArray[i].setFConst(FLT_MAX); tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX);
} else } else
tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst()); tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
break; break;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "compiler/OutputGLSLBase.h" #include "compiler/OutputGLSLBase.h"
#include "compiler/debug.h" #include "compiler/debug.h"
#include <limits.h>
namespace namespace
{ {
TString arrayBrackets(const TType& type) TString arrayBrackets(const TType& type)
...@@ -155,7 +157,7 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type, ...@@ -155,7 +157,7 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type,
{ {
switch (pConstUnion->getType()) switch (pConstUnion->getType())
{ {
case EbtFloat: out << pConstUnion->getFConst(); break; case EbtFloat: out << std::min(FLT_MAX, std::max(-FLT_MAX, pConstUnion->getFConst())); break;
case EbtInt: out << pConstUnion->getIConst(); break; case EbtInt: out << pConstUnion->getIConst(); break;
case EbtBool: out << pConstUnion->getBConst(); break; case EbtBool: out << pConstUnion->getBConst(); break;
default: UNREACHABLE(); default: UNREACHABLE();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "compiler/SearchSymbol.h" #include "compiler/SearchSymbol.h"
#include "compiler/DetectDiscontinuity.h" #include "compiler/DetectDiscontinuity.h"
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <algorithm> #include <algorithm>
...@@ -2565,7 +2566,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con ...@@ -2565,7 +2566,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con
{ {
switch (constUnion->getType()) switch (constUnion->getType())
{ {
case EbtFloat: out << constUnion->getFConst(); break; case EbtFloat: out << std::min(FLT_MAX, std::max(-FLT_MAX, constUnion->getFConst())); break;
case EbtInt: out << constUnion->getIConst(); break; case EbtInt: out << constUnion->getIConst(); break;
case EbtBool: out << constUnion->getBConst(); break; case EbtBool: out << constUnion->getBConst(); break;
default: UNREACHABLE(); default: UNREACHABLE();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment