[Piglit] [PATCH] Test that all desktop GLSL versions can be cross-linked.
Paul Berry
stereotype441 at gmail.com
Fri Oct 18 04:52:43 CEST 2013
Verified using the NVIDIA proprietary driver for Linux (version
313.18).
---
tests/all.tests | 3 +
tests/shaders/CMakeLists.gl.txt | 1 +
tests/shaders/version-mixing.c | 264 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 268 insertions(+)
create mode 100644 tests/shaders/version-mixing.c
diff --git a/tests/all.tests b/tests/all.tests
index c919f19..9502ead 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -348,6 +348,9 @@ add_plain_test(shaders, 'useprogram-refcount-1')
add_plain_test(shaders, 'useshaderprogram-bad-type')
add_plain_test(shaders, 'useshaderprogram-bad-program')
add_plain_test(shaders, 'useshaderprogram-flushverts-1')
+for subtest in ('interstage', 'intrastage'):
+ cmdline = 'version-mixing {0}'.format(subtest)
+ shaders[cmdline] = concurrent_test(cmdline)
def add_vpfpgeneric(group, name):
group[name] = PlainExecTest(['vpfp-generic', '-auto', testsDir + '/shaders/generic/' + name + '.vpfp'])
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index fcb303b..f1cf9dd 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -168,5 +168,6 @@ piglit_add_executable (useprogram-refcount-1 useprogram-refcount-1.c)
piglit_add_executable (useshaderprogram-bad-type useshaderprogram-bad-type.c)
piglit_add_executable (useshaderprogram-bad-program useshaderprogram-bad-program.c)
piglit_add_executable (useshaderprogram-flushverts-1 useshaderprogram-flushverts-1.c)
+piglit_add_executable (version-mixing version-mixing.c)
# vim: ft=cmake:
diff --git a/tests/shaders/version-mixing.c b/tests/shaders/version-mixing.c
new file mode 100644
index 0000000..be84812
--- /dev/null
+++ b/tests/shaders/version-mixing.c
@@ -0,0 +1,264 @@
+/*
+ * 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
+ *
+ * Test that any desktop GLSL version may be linked with any other
+ * desktop GLSL version.
+ *
+ * From the GLSL 4.30 spec, section 3.3 (Preprocessor):
+ *
+ * "Shaders for the core or compatibility profiles that declare
+ * different versions can be linked together."
+ *
+ * This is a deliberate relaxation of the cross-version linking rules
+ * from previous versions of the GLSL spec (which prohibited some
+ * combinations of GLSL versions from being linked together). It was
+ * made because existing implementations didn't follow the old
+ * cross-version linking rules (see Khronos bug 8463). So it seems
+ * reasonable to expect all implementations to follow the new relaxed
+ * rules.
+ *
+ * This test can be run in two ways: "interstage" and "intrastage".
+ * "interstage" checks that a vertex shader of one version can be
+ * linked with a fragment shader of another version. "intrastage"
+ * checks that two vertex shaders of different versions can be linked
+ * together.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+ config.supports_gl_core_version = 31;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *interstage_vs =
+ "#version %d\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = vec4(0.0);\n"
+ "}\n";
+
+static const char *interstage_fs =
+ "#version %d\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = vec4(0.0);\n"
+ "}\n";
+
+static const char *intrastage_vs1 =
+ "#version %d\n"
+ "\n"
+ "void f();\n"
+ "void main()\n"
+ "{\n"
+ " f();\n"
+ "}\n";
+
+static const char *intrastage_vs2 =
+ "#version %d\n"
+ "\n"
+ "void f()\n"
+ "{\n"
+ " gl_Position = vec4(0.0);\n"
+ "}\n";
+
+static int all_glsl_versions[] = {
+ 110, 120, 130, 140, 150, 330, 400, 410, 420, 430, 440
+};
+
+
+static void
+print_usage_and_exit(const char *prog_name)
+{
+ printf("Usage: %s <subtest>\n"
+ " where <subtest> is one of:\n"
+ " interstage: test interstage linking (vs-to-fs)\n"
+ " intrastage: test intrastage linking (vs-to-vs)\n",
+ prog_name);
+ piglit_report_result(PIGLIT_FAIL);
+}
+
+
+static int
+get_max_glsl_version()
+{
+ bool es;
+ int major, minor;
+ piglit_get_glsl_version(&es, &major, &minor);
+ if (es) {
+ printf("This test should only be run on desktop GL.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ return 100 * major + minor;
+}
+
+
+/**
+ * Try compiling a shader of type \c target, whose string is formed by
+ * applying \c version to \c shader_template, and attach it to \c
+ * prog. On success, return true. If there is a problem, print an
+ * error message using \c shader_desc to describe the shader, and
+ * return false.
+ */
+static bool
+try_attach_shader(GLuint prog, const char *shader_desc, GLenum target,
+ const char *shader_template, int version)
+{
+ char *shader_text = NULL;
+ GLuint shader = glCreateShader(target);
+ GLint ok;
+
+ asprintf(&shader_text, shader_template, version);
+ glShaderSource(shader, 1, (const GLchar **) &shader_text, NULL);
+ free(shader_text);
+ glCompileShader(shader);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
+ if (!ok) {
+ printf("%s failed to compile.\n", shader_desc);
+ glDeleteShader(shader);
+ return false;
+ }
+ glAttachShader(prog, shader);
+ glDeleteShader(shader);
+ return true;
+}
+
+
+/**
+ * Test interstage linking between VS and FS, and print a message
+ * describing the result, and return true if compilation and linking
+ * succeeded.
+ */
+static bool
+test_interstage(int version_vs, int version_fs)
+{
+ GLuint prog = glCreateProgram();
+ GLint ok;
+
+ if (!try_attach_shader(prog, "vertex shader", GL_VERTEX_SHADER,
+ interstage_vs, version_vs)) {
+ glDeleteProgram(prog);
+ return false;
+ }
+ if (!try_attach_shader(prog, "fragment shader", GL_FRAGMENT_SHADER,
+ interstage_fs, version_fs)) {
+ glDeleteProgram(prog);
+ return false;
+ }
+ glLinkProgram(prog);
+ glGetProgramiv(prog, GL_LINK_STATUS, &ok);
+ if (ok)
+ printf("Success.\n");
+ else
+ printf("Link failed.\n");
+ return ok;
+}
+
+
+/**
+ * Test intrastage linking between two VS shaders, and print a message
+ * describing the result, and return true if compilation and linking
+ * succeeded.
+ */
+static bool
+test_intrastage(int version_vs1, int version_vs2)
+{
+ GLuint prog = glCreateProgram();
+ GLint ok;
+
+ if (!try_attach_shader(prog, "vertex shader 1", GL_VERTEX_SHADER,
+ intrastage_vs1, version_vs1)) {
+ glDeleteProgram(prog);
+ return false;
+ }
+ if (!try_attach_shader(prog, "vertex shader 2", GL_VERTEX_SHADER,
+ intrastage_vs2, version_vs2)) {
+ glDeleteProgram(prog);
+ return false;
+ }
+ glLinkProgram(prog);
+ glGetProgramiv(prog, GL_LINK_STATUS, &ok);
+ if (ok)
+ printf("Success.\n");
+ else
+ printf("Link failed.\n");
+ return ok;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ int i, j;
+ bool pass = true;
+ bool interstage;
+ int max_glsl_version;
+
+ /* Parse params */
+ if (argc != 2)
+ print_usage_and_exit(argv[0]);
+ if (strcmp(argv[1], "interstage") == 0)
+ interstage = true;
+ else if (strcmp(argv[1], "intrastage") == 0)
+ interstage = false;
+ else
+ print_usage_and_exit(argv[0]);
+
+ piglit_require_GLSL();
+ max_glsl_version = get_max_glsl_version();
+
+ for (i = 0; i < ARRAY_SIZE(all_glsl_versions); i++) {
+ if (all_glsl_versions[i] > max_glsl_version)
+ continue;
+ for (j = 0; j < ARRAY_SIZE(all_glsl_versions); j++) {
+ if (all_glsl_versions[j] > max_glsl_version)
+ continue;
+ printf("Testing versions %d and %d: ",
+ all_glsl_versions[i], all_glsl_versions[j]);
+ if (interstage)
+ pass = test_interstage(all_glsl_versions[i],
+ all_glsl_versions[j])
+ && pass;
+ else
+ pass = test_intrastage(all_glsl_versions[i],
+ all_glsl_versions[j])
+ && pass;
+ }
+ }
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ /* Should never be reached */
+ return PIGLIT_FAIL;
+}
--
1.8.4.1
More information about the Piglit
mailing list