Commit 53318fa7 by Nicolas Capens

Implement floating-point conversion to the nearest representable integer.

Bug 20724899 Change-Id: I35f63709b5773c2cefe8bf2376e6d9236dfd81f9 Reviewed-on: https://swiftshader-review.googlesource.com/5090Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent d4f13f32
...@@ -3121,7 +3121,7 @@ void GetIntegerv(GLenum pname, GLint* params) ...@@ -3121,7 +3121,7 @@ void GetIntegerv(GLenum pname, GLint* params)
{ {
if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR) if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
{ {
params[i] = es2::floatToInt(floatParams[i]); params[i] = convert_float_int(floatParams[i]);
} }
else else
{ {
......
...@@ -1872,7 +1872,7 @@ GL_APICALL void GL_APIENTRY glGetIntegeri_v(GLenum target, GLuint index, GLint * ...@@ -1872,7 +1872,7 @@ GL_APICALL void GL_APIENTRY glGetIntegeri_v(GLenum target, GLuint index, GLint *
{ {
if(target == GL_DEPTH_RANGE || target == GL_COLOR_CLEAR_VALUE || target == GL_DEPTH_CLEAR_VALUE || target == GL_BLEND_COLOR) if(target == GL_DEPTH_RANGE || target == GL_COLOR_CLEAR_VALUE || target == GL_DEPTH_CLEAR_VALUE || target == GL_BLEND_COLOR)
{ {
data[i] = es2::floatToInt(floatParams[i]); data[i] = convert_float_int(floatParams[i]);
} }
else else
{ {
...@@ -3210,7 +3210,7 @@ GL_APICALL void GL_APIENTRY glGetInteger64v(GLenum pname, GLint64 *data) ...@@ -3210,7 +3210,7 @@ GL_APICALL void GL_APIENTRY glGetInteger64v(GLenum pname, GLint64 *data)
{ {
if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR) if(pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
{ {
data[i] = (GLint64)(es2::floatToInt(floatParams[i])); data[i] = (GLint64)(convert_float_int(floatParams[i]));
} }
else else
{ {
...@@ -3282,7 +3282,7 @@ GL_APICALL void GL_APIENTRY glGetInteger64i_v(GLenum target, GLuint index, GLint ...@@ -3282,7 +3282,7 @@ GL_APICALL void GL_APIENTRY glGetInteger64i_v(GLenum target, GLuint index, GLint
{ {
if(target == GL_DEPTH_RANGE || target == GL_COLOR_CLEAR_VALUE || target == GL_DEPTH_CLEAR_VALUE || target == GL_BLEND_COLOR) if(target == GL_DEPTH_RANGE || target == GL_COLOR_CLEAR_VALUE || target == GL_DEPTH_CLEAR_VALUE || target == GL_BLEND_COLOR)
{ {
data[i] = (GLint64)(es2::floatToInt(floatParams[i])); data[i] = (GLint64)(convert_float_int(floatParams[i]));
} }
else else
{ {
......
...@@ -69,6 +69,26 @@ inline unsigned int unorm(float x) ...@@ -69,6 +69,26 @@ inline unsigned int unorm(float x)
return (unsigned int)(max * x + 0.5f); return (unsigned int)(max * x + 0.5f);
} }
} }
// Converts floating-point values to the nearest representable integer
inline int convert_float_int(float x)
{
// The largest positive integer value that is exactly representable in IEEE 754 binary32 is 0x7FFFFF80.
// The next floating-point value is 128 larger and thus needs clamping to 0x7FFFFFFF.
static_assert(std::numeric_limits<float>::is_iec559, "Unsupported floating-point format");
if(x > 0x7FFFFF80)
{
return 0x7FFFFFFF;
}
if(x < (signed)0x80000000)
{
return 0x80000000;
}
return static_cast<int>(roundf(x));
}
} }
#endif // LIBGLESV2_MATHUTIL_H_ #endif // LIBGLESV2_MATHUTIL_H_
...@@ -464,11 +464,6 @@ namespace es2 ...@@ -464,11 +464,6 @@ namespace es2
return -1; return -1;
} }
GLint floatToInt(GLfloat value)
{
return static_cast<GLint>((static_cast<GLfloat>(0xFFFFFFFF) * value - 1.0f) * 0.5f);
}
bool IsCompressed(GLenum format, GLint clientVersion) bool IsCompressed(GLenum format, GLint clientVersion)
{ {
return ValidateCompressedFormat(format, clientVersion, true) == GL_NONE; return ValidateCompressedFormat(format, clientVersion, true) == GL_NONE;
......
...@@ -41,8 +41,6 @@ namespace es2 ...@@ -41,8 +41,6 @@ namespace es2
int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize); int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);
GLint floatToInt(GLfloat value);
bool IsCompressed(GLenum format, GLint clientVersion); bool IsCompressed(GLenum format, GLint clientVersion);
GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type); GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type);
GLenum ValidateCompressedFormat(GLenum format, GLint clientVersion, bool expectCompressedFormats); GLenum ValidateCompressedFormat(GLenum format, GLint clientVersion, bool expectCompressedFormats);
......
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