<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt">Please take a look, thanks.<br><br><div class="gmail_quote">On Thu, Nov 15, 2012 at 3:22 PM, Frank Henigman <span dir="ltr"><<a href="mailto:fjhenigman@google.com" target="_blank">fjhenigman@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2<br>
Reorganized code, new comments and messages to make clearer.<br>
Adopt reviewer's suggestions re ARRAY_SIZE, formatting, piglit_check_gl_error,<br>
window size.<br>
<br>
Check behavior of glGetUniformLocation, glGetUniform and glUniform(Matrix)<br>
when attempting to access inactive/non-existent array elements.<br>
---<br>
 tests/all.tests                              |    1 +<br>
 tests/shaders/CMakeLists.gl.txt              |    1 +<br>
 tests/shaders/glsl-uniform-out-of-bounds-2.c |  179 ++++++++++++++++++++++++++<br>
 3 files changed, 181 insertions(+), 0 deletions(-)<br>
 create mode 100644 tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 36c5847..2cf1ef4 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -240,6 +240,7 @@ add_plain_test(shaders, 'glsl-novertexdata')<br>
 add_plain_test(shaders, 'glsl-preprocessor-comments')<br>
 add_plain_test(shaders, 'glsl-reload-source')<br>
 add_plain_test(shaders, 'glsl-uniform-out-of-bounds')<br>
+add_plain_test(shaders, 'glsl-uniform-out-of-bounds-2')<br>
 add_plain_test(shaders, 'glsl-uniform-update')<br>
 add_plain_test(shaders, 'glsl-unused-varying')<br>
 add_plain_test(shaders, 'glsl-fs-bug25902')<br>
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt<br>
index 6ac0230..93cbf7b 100644<br>
--- a/tests/shaders/CMakeLists.gl.txt<br>
+++ b/tests/shaders/CMakeLists.gl.txt<br>
@@ -66,6 +66,7 @@ piglit_add_executable (glsl-reload-source glsl-reload-source.c)<br>
 piglit_add_executable (glsl-unused-varying glsl-unused-varying.c)<br>
 piglit_add_executable (glsl-uniform-update glsl-uniform-update.c)<br>
 piglit_add_executable (glsl-uniform-out-of-bounds glsl-uniform-out-of-bounds.c)<br>
+piglit_add_executable (glsl-uniform-out-of-bounds-2 glsl-uniform-out-of-bounds-2.c)<br>
 piglit_add_executable (glsl-fs-bug25902 glsl-fs-bug25902.c)<br>
 piglit_add_executable (glsl-fs-color-matrix glsl-fs-color-matrix.c)<br>
 piglit_add_executable (glsl-fs-exp2 glsl-fs-exp2.c)<br>
diff --git a/tests/shaders/glsl-uniform-out-of-bounds-2.c b/tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
new file mode 100644<br>
index 0000000..95210d8<br>
--- /dev/null<br>
+++ b/tests/shaders/glsl-uniform-out-of-bounds-2.c<br>
@@ -0,0 +1,179 @@<br>
+/*<br>
+ * Copyright 2012 Google Inc.<br>
+ *<br>
+ * This library is free software; you can redistribute it and/or<br>
+ * modify it under the terms of the GNU Lesser General Public<br>
+ * License as published by the Free Software Foundation; either<br>
+ * version 2.1 of the License, or (at your option) any later version.<br>
+ *<br>
+ * This library is distributed in the hope that it will be useful,<br>
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
+ * Lesser General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU Lesser General Public<br>
+ * License along with this library; if not, write to the Free Software<br>
+ * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA<br>
+ */<br>
+<br>
+/**<br>
+ * \file glsl-uniform-out-of-bounds-2.c<br>
+ *<br>
+ * glGetUniformLocation should return:<br>
+ * -1 for inactive array elements (as reported by glGetActiveUniform)<br>
+ * not -1 for active array elements (as reported by glGetActiveUniform)<br>
+ * -1 for non-existent array elements (indices outside the array)<br>
+ *<br>
+ * Write and read all active array elements and check that data out == data in.<br>
+ *<br>
+ * Write and read some invalid locations and check for GL_INVALID_OPERATION.<br>
+ *<br>
+ * \author Frank Henigman <<a href="mailto:fjhenigman@google.com">fjhenigman@google.com</a>><br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 10;<br>
+<br>
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLint prog;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       /* unreached */<br>
+       return PIGLIT_FAIL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       GLint vs, fs;<br>
+       int i, j, k;<br>
+       bool pass = true;<br>
+       GLint numActiveUniform;<br>
+       GLint min = -1, max = -1;<br>
+       GLfloat data[16] =<br>
+               { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };<br>
+       GLfloat v[16];<br>
+       GLint bogus[99];<br>
+       int nbogus = 0;<br>
+<br>
+       piglit_require_gl_version(20);<br>
+<br>
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER,<br>
+               "attribute vec4 p;\n"<br>
+               "void main() { gl_Position = p; }\n"<br>
+       );<br>
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER,<br>
+               "uniform vec4 v[4];\n"<br>
+               "uniform mat4 m[4];\n"<br>
+               "void main() { gl_FragColor = v[1] + m[1][1]; }\n"<br>
+       );<br>
+<br>
+       prog = piglit_link_simple_program(vs, fs);<br>
+       glUseProgram(prog);<br>
+       glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &numActiveUniform);<br>
+       printf("active uniforms %d\n", numActiveUniform);<br>
+<br>
+       // for each array in shader<br>
+       for (k = 0; k < numActiveUniform; ++k) {<br>
+               GLchar name[99];<br>
+               GLint numActiveElements;<br>
+               GLenum type;<br>
+               int size;<br>
+               glGetActiveUniform(prog, k, ARRAY_SIZE(name), NULL,<br>
+                                                  &numActiveElements, &type, name);<br>
+               if (name[1] != 0)<br>
+                       continue;<br>
+               if (name[0] == 'v')<br>
+                       size = 4;<br>
+               else if (name[0] == 'm')<br>
+                       size = 16;<br>
+               else<br>
+                       continue;<br>
+               printf("array '%s' active elements %d\n", name, numActiveElements);<br>
+<br>
+               // for each index in array, plus some before and after<br>
+               for (i = -2; i < 6; ++i) {<br>
+                       bool isActive = 0 <= i && i < numActiveElements;<br>
+                       GLchar element[9];<br>
+                       GLint loc;<br>
+                       sprintf(element, "%s[%d]", name, i);<br>
+                       loc = glGetUniformLocation(prog, element);<br>
+<br>
+                       // check result of glGetUniformLocation<br>
+                       if (loc == -1) {<br>
+                               if (isActive) {<br>
+                                       printf("FAIL: no location for active %s\n", element);<br>
+                                       pass = false;<br>
+                               }<br>
+                       } else {<br>
+                               if (!isActive) {<br>
+                                       printf("FAIL: got location for inactive %s\n", element);<br>
+                                       pass = false;<br>
+                               }<br>
+<br>
+                               // write location<br>
+                               if (size == 4) {<br>
+                                       glUniform4fv(loc, 1, data);<br>
+                               } else {<br>
+                                       glUniformMatrix4fv(loc, 1, GL_FALSE, data);<br>
+                               }<br>
+                               // read back<br>
+                               for (j = 0; j < size; ++j)<br>
+                                       v[j] = 0;<br>
+                               glGetUniformfv(prog, loc, v);<br>
+                               // compare<br>
+                               for (j = 0; j < size; ++j) {<br>
+                                       if (v[j] != data[j]) {<br>
+                                               printf("FAIL: wrong value in %s\n", element);<br>
+                                               pass = false;<br>
+                                               break;<br>
+                                       }<br>
+                               }<br>
+<br>
+                               if (min == -1 || loc < min)<br>
+                                       min = loc;<br>
+                               if (max == -1 || loc > max)<br>
+                                       max = loc;<br>
+                       }<br>
+               }<br>
+       }<br>
+<br>
+       // make up some bogus locations<br>
+       for (i = 1; i < 6; ++i) {<br>
+               bogus[nbogus++] = min - i;<br>
+               bogus[nbogus++] = max + i;<br>
+               bogus[nbogus++] = max + (1<<16) + i - 3;<br>
+       }<br>
+<br>
+       // test writing and reading bogus locations<br>
+       for (i = 0; i < nbogus; ++i) {<br>
+               if (bogus[i] == -1)<br>
+                       continue;<br>
+               printf("trying bogus location %d\n", bogus[i]);<br>
+               glUniform4fv(bogus[i], 1, v);<br>
+               if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {<br>
+                       printf("FAIL: wrote bogus location\n");<br>
+                       pass = false;<br>
+               }<br>
+               glUniformMatrix4fv(bogus[i], 1, GL_FALSE, v);<br>
+               if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {<br>
+                       printf("FAIL: wrote bogus location (matrix)\n");<br>
+                       pass = false;<br>
+               }<br>
+               glGetUniformfv(prog, bogus[i], v);<br>
+               if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {<br>
+                       printf("FAIL: read bogus location\n");<br>
+                       pass = false;<br>
+               }<br>
+       }<br>
+<br>
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.3<br>
<br>
</font></span></blockquote></div><br></div>