[Piglit] [PATCH 2/2] max-varyings: Use logical-OR instead of if statement to set failed.

Matt Turner mattst88 at gmail.com
Tue Mar 3 15:49:30 PST 2015


By flattening the if statements we cut 213 instructions from the
fragment shader (601 -> 388, or 35%), and we remove all register
spilling on i965.

Reduces runtime of "ext_transform_feedback-max-varyings" by
-73.0547% +/- 0.682694% (n=27).
---
 tests/spec/ext_transform_feedback/max-varyings.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tests/spec/ext_transform_feedback/max-varyings.c b/tests/spec/ext_transform_feedback/max-varyings.c
index 7028fb1..497e432 100644
--- a/tests/spec/ext_transform_feedback/max-varyings.c
+++ b/tests/spec/ext_transform_feedback/max-varyings.c
@@ -99,13 +99,11 @@ get_fs(int num_varyings)
 		"\n"
 		"void main()\n"
 		"{\n"
-		"  int i;\n"
-		"  gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
-		"  for(i = 0; i < v.length(); ++i) {\n"
-		"    if (v[i] != 4.0*i + vec4(0.0, 1.0, 2.0, 3.0)) {\n"
-		"      gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
-		"    }\n"
+		"  bool failed = false;\n"
+		"  for(int i = 0; i < v.length(); ++i) {\n"
+		"     failed = failed || (v[i] != 4.0*i + vec4(0.0, 1.0, 2.0, 3.0));\n"
 		"  }\n"
+		"  gl_FragColor = vec4(float(failed), 1.0 - float(failed), 0.0, 1.0);\n"
 		"}\n", num_varyings);
 
 	shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fstext);
-- 
2.0.5



More information about the Piglit mailing list