Commit 7aa4cae2 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. BUG=angleproject:891 Change-Id: Ieb3199fd33c25e7da8d154f88658e06f01d53c0e Reviewed-on: https://chromium-review.googlesource.com/303338 Tryjob-Request: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 25e563fe
...@@ -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));
} }
......
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