Commit 40f48ab8 by Alexis Hetu Committed by Alexis Hétu

Unsigned int GLSL parsing fixed

Unsigned integers in GLSL were being parsed using the regular integer parser, so it was limited to INT_MAX. All values from INT_MAX + 1 to UINT_MAX could not be parsed properly. Also, added constant folding for the 4 bit conversion glsl functions. Fixes shader compilation issue in the Epic Zen Garden example: https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.html (unfortunately, the screen is still black, so there are other issues left) Fixes WebGL 2 test: conformance2/glsl3/float-parsing.html Change-Id: Iae52b2c8e083f0e1a22599e5a583297b9850444d Reviewed-on: https://swiftshader-review.googlesource.com/16648Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 26a86758
......@@ -74,6 +74,18 @@ namespace sw
b = t;
}
template <typename destType, typename sourceType>
destType bitCast(const sourceType &source)
{
union
{
sourceType s;
destType d;
} sd;
sd.s = source;
return sd.d;
}
inline int iround(float x)
{
return (int)floor(x + 0.5f);
......
......@@ -492,7 +492,7 @@ int uint_constant(TParseContext *context)
return 0;
}
if (!atoi_clamp(yytext, &(yylval->lex.i)))
if (!atou_clamp(yytext, &(yylval->lex.u)))
yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return UINTCONSTANT;
......
......@@ -3724,7 +3724,7 @@ int uint_constant(TParseContext *context)
return 0;
}
if (!atoi_clamp(yytext, &(yylval->lex.i)))
if (!atou_clamp(yytext, &(yylval->lex.u)))
yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return UINTCONSTANT;
......
......@@ -32,3 +32,11 @@ bool atoi_clamp(const char *str, int *value)
*value = std::numeric_limits<int>::max();
return success;
}
bool atou_clamp(const char *str, unsigned int *value)
{
bool success = pp::numeric_lex_int(str, value);
if(!success)
*value = std::numeric_limits<unsigned int>::max();
return success;
}
......@@ -21,14 +21,18 @@ extern "C" {
// atof_clamp is like atof but
// 1. it forces C locale, i.e. forcing '.' as decimal point.
// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
// 2. it sets the value to FLT_MAX if overflow happens.
// Return false if overflow happens.
bool atof_clamp(const char *str, float *value);
// If overflow happens, clamp the value to INT_MIN or INT_MAX.
// If overflow happens, value is set to INT_MAX.
// Return false if overflow happens.
bool atoi_clamp(const char *str, int *value);
// If overflow happens, value is set to UINT_MAX.
// Return false if overflow happens.
bool atou_clamp(const char *str, unsigned int *value);
#ifdef __cplusplus
} // end extern "C"
#endif
......
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