[Piglit] [PATCH] shaders: Make glsl-fs-lots-of-tex less susceptable to rounding error.

Jason Ekstrand jason at jlekstrand.net
Fri Jul 11 13:01:29 PDT 2014


The only reason this test passed before is because we were rounding wrong
in texture upload.  Previously, the shader started with 0.01, effectively
multiplied it by 34, and then compared it to 0.4.  The problem is that,
when converting from float to unsigned byte, you get 0.01 * 255 = 2.55.
Previously, we were rounding this up to 3.  Then 3 * 34 = 102 and
102 / 255 = 0.4.  However, the OpenGL spec specifies that you should simply
cast the floating point value to the integer value and this rounds down to
2.  The result is that you get 2 * 34 = 68 and 68 / 255 = 2.667 which is
nowhere close to 0.4.

The new version simply starts with 0.4 and then divides by 4 at the end of
the shader to get back to 0.4.

Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
---
 tests/shaders/glsl-fs-lots-of-tex.shader_test | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/shaders/glsl-fs-lots-of-tex.shader_test b/tests/shaders/glsl-fs-lots-of-tex.shader_test
index a31778f..9056774 100644
--- a/tests/shaders/glsl-fs-lots-of-tex.shader_test
+++ b/tests/shaders/glsl-fs-lots-of-tex.shader_test
@@ -34,12 +34,13 @@ void main()
 	vec4 p = texture2D(tex, cst.xy) + texture2D(tex, cst.xy);
 	vec4 q = texture2D(tex, cst.xy) + texture2D(tex, cst.xy);
 
-	gl_FragColor = a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q;
+	vec4 sum = a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q;
+	gl_FragColor = sum / 34.0f;
 }
 
 [test]
 uniform int tex 0
 uniform vec4 cst 0.0 0.0 0.0 0.0
-texture checkerboard 0 0 (8, 8) (0.01, 0.0, 0.0, 0.0) (0.01, 0.0, 0.0, 0.0)
+texture checkerboard 0 0 (8, 8) (0.4, 0.0, 0.0, 0.0) (0.4, 0.0, 0.0, 0.0)
 draw rect -1 -1 2 2
 relative probe rgb (0.75, 0.75) (0.4, 0.0, 0.0)
-- 
2.0.0



More information about the Piglit mailing list