Commit 4e7196a1 by Corentin Wallez

UniformTest.FloatUniformStateQuery do computations in doubles

When using floats, when testing INT_MAX, the loss of precision causes an undefined behavior when casting from float to int. In this cause on clang 3.6 on Mac, the integer wrapped and became INT_MIN. Reland with warnings fixes for MSVC on standalone builds. BUG=angleproject:891 Change-Id: Ieed609840ae22e89f51c3a85cd5309c4d8bc52ea Reviewed-on: https://chromium-review.googlesource.com/303900Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent e746890e
...@@ -170,36 +170,35 @@ TEST_P(UniformTest, UniformArrayLocations) ...@@ -170,36 +170,35 @@ TEST_P(UniformTest, UniformArrayLocations)
// Test that float to integer GetUniform rounds values correctly. // Test that float to integer GetUniform rounds values correctly.
TEST_P(UniformTest, FloatUniformStateQuery) TEST_P(UniformTest, FloatUniformStateQuery)
{ {
std::vector<GLfloat> inValues; std::vector<double> inValues;
std::vector<GLfloat> expectedFValues; std::vector<GLfloat> expectedFValues;
std::vector<GLint> expectedIValues; std::vector<GLint> expectedIValues;
GLfloat intMaxF = static_cast<GLfloat>(std::numeric_limits<GLint>::max()); double intMaxD = static_cast<double>(std::numeric_limits<GLint>::max());
GLfloat intMinF = static_cast<GLfloat>(std::numeric_limits<GLint>::min()); double intMinD = static_cast<double>(std::numeric_limits<GLint>::min());
// TODO(jmadill): Investigate rounding of .5 // TODO(jmadill): Investigate rounding of .5
inValues.push_back(-1.0);
inValues.push_back(-1.0f); inValues.push_back(-0.6);
inValues.push_back(-0.6f); // inValues.push_back(-0.5); // undefined behaviour?
// inValues.push_back(-0.5f); // undefined behaviour? inValues.push_back(-0.4);
inValues.push_back(-0.4f); inValues.push_back(0.0);
inValues.push_back(0.0f); inValues.push_back(0.4);
inValues.push_back(0.4f); // inValues.push_back(0.5); // undefined behaviour?
// inValues.push_back(0.5f); // undefined behaviour? inValues.push_back(0.6);
inValues.push_back(0.6f); inValues.push_back(1.0);
inValues.push_back(1.0f); inValues.push_back(999999.2);
inValues.push_back(999999.2f); inValues.push_back(intMaxD * 2.0);
inValues.push_back(intMaxF * 2.0f); inValues.push_back(intMaxD + 1.0);
inValues.push_back(intMaxF + 1.0f); inValues.push_back(intMinD * 2.0);
inValues.push_back(intMinF * 2.0f); inValues.push_back(intMinD - 1.0);
inValues.push_back(intMinF - 1.0f);
for (double value : inValues)
for (GLfloat value : inValues)
{ {
expectedFValues.push_back(value); expectedFValues.push_back(static_cast<GLfloat>(value));
GLfloat clampedValue = std::max(intMinF, std::min(intMaxF, value)); double clampedValue = std::max(intMinD, std::min(intMaxD, value));
GLfloat rounded = roundf(clampedValue); double rounded = round(clampedValue);
expectedIValues.push_back(static_cast<GLint>(rounded)); expectedIValues.push_back(static_cast<GLint>(rounded));
} }
...@@ -208,7 +207,7 @@ TEST_P(UniformTest, FloatUniformStateQuery) ...@@ -208,7 +207,7 @@ TEST_P(UniformTest, FloatUniformStateQuery)
for (size_t index = 0; index < inValues.size(); ++index) for (size_t index = 0; index < inValues.size(); ++index)
{ {
GLfloat inValue = inValues[index]; GLfloat inValue = static_cast<GLfloat>(inValues[index]);
GLfloat expectedValue = expectedFValues[index]; GLfloat expectedValue = expectedFValues[index];
glUniform1f(mUniformFLocation, inValue); glUniform1f(mUniformFLocation, inValue);
...@@ -220,7 +219,7 @@ TEST_P(UniformTest, FloatUniformStateQuery) ...@@ -220,7 +219,7 @@ TEST_P(UniformTest, FloatUniformStateQuery)
for (size_t index = 0; index < inValues.size(); ++index) for (size_t index = 0; index < inValues.size(); ++index)
{ {
GLfloat inValue = inValues[index]; GLfloat inValue = static_cast<GLfloat>(inValues[index]);
GLint expectedValue = expectedIValues[index]; GLint expectedValue = expectedIValues[index];
glUniform1f(mUniformFLocation, inValue); glUniform1f(mUniformFLocation, inValue);
......
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