[Piglit] [PATCH] Verify that vertex shader attributes are assigned in order starting w/0

Ian Romanick idr at freedesktop.org
Sat Jun 8 13:04:59 PDT 2013


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

THIS IS NOT REQUIRED BY ANY VERSION OF THE OpenGL SPECIFICATION!

However, almost every OpenGL implementation happens to behave this way
when there is a single vertex shader compilation unit linked into the
program.  As a result, some programs accidentally rely on this behavior.
If the application was never tested on a implementation that behaves any
other way, there's a reasonable chance it has bugs without its
developers even knowing.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Chad Versace <chad.versace at linux.intel.com>
---
 tests/all.tests                            |   1 +
 tests/spec/gl-2.0/api/CMakeLists.gl.txt    |   1 +
 tests/spec/gl-2.0/api/attrib-assignments.c | 111 +++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 tests/spec/gl-2.0/api/attrib-assignments.c

diff --git a/tests/all.tests b/tests/all.tests
index 417ca08..159faee 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -630,6 +630,7 @@ gl20 = Group()
 spec['!OpenGL 2.0'] = gl20
 add_concurrent_test(gl20, 'attribs')
 add_concurrent_test(gl20, 'gl-2.0-edgeflag')
+add_plain_test(gl20, 'attrib-assignments')
 add_plain_test(gl20, 'getattriblocation-conventional')
 add_plain_test(gl20, 'clip-flag-behavior')
 add_concurrent_test(gl20, 'vertex-program-two-side enabled front back front2 back2')
diff --git a/tests/spec/gl-2.0/api/CMakeLists.gl.txt b/tests/spec/gl-2.0/api/CMakeLists.gl.txt
index f77f056..77b0f93 100644
--- a/tests/spec/gl-2.0/api/CMakeLists.gl.txt
+++ b/tests/spec/gl-2.0/api/CMakeLists.gl.txt
@@ -9,6 +9,7 @@ link_libraries (
 	${OPENGL_glu_LIBRARY}
 )
 
+piglit_add_executable (attrib-assignments attrib-assignments.c)
 piglit_add_executable (getattriblocation-conventional getattriblocation-conventional.c)
 piglit_add_executable (clip-flag-behavior clip-flag-behavior.c)
 
diff --git a/tests/spec/gl-2.0/api/attrib-assignments.c b/tests/spec/gl-2.0/api/attrib-assignments.c
new file mode 100644
index 0000000..2d17a01
--- /dev/null
+++ b/tests/spec/gl-2.0/api/attrib-assignments.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2013 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 attrib-assignments.c
+ * Verify that vertex shader attributes are assigned in order starting with 0.
+ *
+ * THIS IS NOT REQUIRED BY ANY VERSION OF THE OpenGL SPECIFICATION!
+ *
+ * However, almost every OpenGL implementation happens to behave this way when
+ * there is a single vertex shader compilation unit linked into the program.
+ * As a result, some programs accidentally rely on this behavior.  If the
+ * application was never tested on a implementation that behaves any other
+ * way, there's a reasonable chance it has bugs without its developers even
+ * knowing.
+ */
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *vs_code =
+	"attribute vec4 i00;\n"
+	"attribute vec4 i01;\n"
+	"attribute vec4 i02;\n"
+	"attribute vec4 i03;\n"
+	"attribute vec4 i04;\n"
+	"attribute vec4 i05;\n"
+	"attribute vec4 i06;\n"
+	"attribute vec4 i07;\n"
+	"attribute vec4 i08;\n"
+	"attribute vec4 i09;\n"
+	"attribute vec4 i10;\n"
+	"attribute vec4 i11;\n"
+	"attribute vec4 i12;\n"
+	"attribute vec4 i13;\n"
+	"attribute vec4 i14;\n"
+	"attribute vec4 i15;\n"
+	"varying vec4 a;\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = i00;\n"
+	"    a = i01 + i02 + i03 + i04 + i05\n"
+	"        + i06 + i07 + i08 + i09 + i10\n" 
+	"        + i11 + i12 + i13 + i14 + i15;\n" 
+	"}"
+	;
+
+static const char *fs_code =
+	"varying vec4 a;\n"
+	"void main() { gl_FragColor = a; }"
+	;
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	GLint prog;
+	GLint loc;
+	int i;
+
+	piglit_require_vertex_shader();
+	piglit_require_fragment_shader();
+
+	prog = piglit_build_simple_program(vs_code, fs_code);
+
+	for (i = 0; i < 16; i++) {
+		char name[4];
+
+		snprintf(name, sizeof(name), "i%02d", i);
+		loc = glGetAttribLocation(prog, name);
+
+		if (loc != i) {
+			fprintf(stderr,
+				"Attribute \"%s\" has location %d, "
+				"expected %d.\n",
+				name, loc, i);
+			piglit_report_result(PIGLIT_FAIL);
+		}
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
-- 
1.8.1.4



More information about the Piglit mailing list