[Piglit] [PATCH] arb_shader_objects: Test glGetUniformLocation on an array of struct of array

Ian Romanick idr at freedesktop.org
Fri Nov 4 17:04:05 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This test passes on NVIDIA's closed-source drivera and on AMD's
closed-source driver.  Currently Mesa fails to get the location of
array elements embedded in a structure.

v2: Reduce log spam when the test passes.  Initialize pass to true so
that the test can pass.  Duh.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/all.tests                                    |    1 +
 tests/spec/arb_shader_objects/CMakeLists.gl.txt    |    1 +
 .../getuniformlocation-array-of-struct-of-array.c  |  112 ++++++++++++++++++++
 3 files changed, 114 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_shader_objects/getuniformlocation-array-of-struct-of-array.c

diff --git a/tests/all.tests b/tests/all.tests
index 5c9d133..6b18dda 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -973,6 +973,7 @@ spec['ARB_shader_objects'] = arb_shader_objects
 arb_shader_objects['getuniform'] = PlainExecTest(['arb_shader_objects-getuniform', '-auto'])
 arb_shader_objects['getuniform'].runConcurrent = True
 arb_shader_objects['bindattriblocation-scratch-name'] = concurrent_test('arb_shader_objects-bindattriblocation-scratch-name')
+arb_shader_objects['getuniformlocation-array-of-struct-of-array'] = concurrent_test('arb_shader_objects-getuniformlocation-array-of-struct-of-array')
 arb_shader_objects['clear-with-deleted'] = concurrent_test('arb_shader_objects-clear-with-deleted')
 arb_shader_objects['delete-repeat'] = concurrent_test('arb_shader_objects-delete-repeat')
 
diff --git a/tests/spec/arb_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_shader_objects/CMakeLists.gl.txt
index 0e248f2..26b4682 100644
--- a/tests/spec/arb_shader_objects/CMakeLists.gl.txt
+++ b/tests/spec/arb_shader_objects/CMakeLists.gl.txt
@@ -13,5 +13,6 @@ link_libraries (
 
 add_executable (arb_shader_objects-bindattriblocation-scratch-name bindattriblocation-scratch-name.c)
 add_executable (arb_shader_objects-getuniform getuniform.c)
+add_executable (arb_shader_objects-getuniformlocation-array-of-struct-of-array getuniformlocation-array-of-struct-of-array.c)
 add_executable (arb_shader_objects-clear-with-deleted clear-with-deleted.c)
 add_executable (arb_shader_objects-delete-repeat delete-repeat.c)
diff --git a/tests/spec/arb_shader_objects/getuniformlocation-array-of-struct-of-array.c b/tests/spec/arb_shader_objects/getuniformlocation-array-of-struct-of-array.c
new file mode 100644
index 0000000..5e5fcec
--- /dev/null
+++ b/tests/spec/arb_shader_objects/getuniformlocation-array-of-struct-of-array.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * \file getuniformlocation-array-of-struct-of-array.c
+ * Verify that the locations of members of an array of struct of array can be
+ * queried using the glGetUniformLocation API.
+ *
+ * \author Ian Romanick
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static const char *vs_code =
+	"struct S { mat4 m; vec4 v[10]; };\n"
+	"uniform S s[10];\n"
+	"uniform int i, j;\n"
+	"void main() { gl_Position = s[i].m * s[i].v[j]; }\n"
+	;
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	GLint vert;
+	GLint prog;
+	GLint loc;
+	char name[256];
+	bool pass = true;
+	unsigned i;
+	unsigned j;
+
+	piglit_require_vertex_shader();
+	vert = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
+	prog = piglit_link_simple_program(vert, 0);
+
+	/* From page 80 of the OpenGL 2.1 spec:
+	 *
+	 *     "A valid name cannot be a structure, an array of structures, or
+	 *     any portion of a single vector or a matrix."
+	 */
+	loc = piglit_GetUniformLocation(prog, "s");
+	if (loc != -1) {
+		printf("s location = %d (should be -1)\n", loc);
+		pass = false;
+	}
+
+	for (i = 0; i < 10; i++) {
+		/* From page 80 of the OpenGL 2.1 spec:
+		 *
+		 *     "A valid name cannot be a structure, an array of
+		 *     structures, or any portion of a single vector or a
+		 *     matrix."
+		 */
+		snprintf(name, sizeof(name), "s[%d]", i);
+		loc = piglit_GetUniformLocation(prog, name);
+
+		if (loc != -1) {
+			printf("%s location = %d (should be -1)\n", name, loc);
+			pass = false;
+		}
+
+		snprintf(name, sizeof(name), "s[%d].m", i);
+		loc = piglit_GetUniformLocation(prog, name);
+
+		if (loc == -1) {
+			printf("%s location = %d (should not be -1)\n",
+			       name, loc);
+			pass = false;
+		}
+
+		for (j = 0; j < 10; j++) {
+			snprintf(name, sizeof(name), "s[%d].v[%d]", i, j);
+			loc = piglit_GetUniformLocation(prog, name);
+
+			if (loc == -1) {
+				printf("%s location = %d (should not be -1)\n",
+				       name, loc);
+				pass = false;
+			}
+		}
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.6.4



More information about the Piglit mailing list