[Piglit] [PATCH 1/2] SSO: new test to ensure correct deadcode optimization

Gregory Hainaut gregory.hainaut at gmail.com
Tue Nov 3 11:09:49 PST 2015


Related to mesa issue: https://bugs.freedesktop.org/show_bug.cgi?id=79783

Mostly "Validated" on Nvidia driver. Nvidia fails to link vs_fs_prog_separate_inactive

v3: add the test to all.py

v2:
* Test both output and input are still active
* Test real interstage variable are still optimized
* Mix rendezvous by name and location

Signed-off-by: Gregory Hainaut <gregory.hainaut at gmail.com>
---
 tests/all.py                                       |   2 +
 .../arb_separate_shader_objects/CMakeLists.gl.txt  |   1 +
 .../rendezvous_by_name.c                           | 358 +++++++++++++++++++++
 3 files changed, 361 insertions(+)
 create mode 100644 tests/spec/arb_separate_shader_objects/rendezvous_by_name.c

diff --git a/tests/all.py b/tests/all.py
index acfc586..35c330b 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2145,6 +2145,8 @@ with profile.group_manager(
       'UseProgramStages - non-separable program')
     g(['arb_separate_shader_object-ProgramUniform-coverage'],
       'ProgramUniform coverage')
+    g(['arb_separate_shader_object-rendezvous_by_name'],
+      'Rendez vous by name')
     g(['arb_separate_shader_object-rendezvous_by_location', '-fbo'],
       'Rendezvous by location', run_concurrent=False)
     g(['arb_separate_shader_object-rendezvous_by_location-5-stages'],
diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
index f1b15c0..9ab6606 100644
--- a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
@@ -18,5 +18,6 @@ piglit_add_executable (arb_separate_shader_object-ProgramUniform-coverage Progra
 piglit_add_executable (arb_separate_shader_object-rendezvous_by_location rendezvous_by_location.c)
 piglit_add_executable (arb_separate_shader_object-rendezvous_by_location-3-stages rendezvous_by_location-3-stages.c)
 piglit_add_executable (arb_separate_shader_object-rendezvous_by_location-5-stages rendezvous_by_location-5-stages.c)
+piglit_add_executable (arb_separate_shader_object-rendezvous_by_name rendezvous_by_name.c)
 piglit_add_executable (arb_separate_shader_object-UseProgramStages-non-separable UseProgramStages-non-separable.c)
 piglit_add_executable (arb_separate_shader_object-ValidateProgramPipeline ValidateProgramPipeline.c)
diff --git a/tests/spec/arb_separate_shader_objects/rendezvous_by_name.c b/tests/spec/arb_separate_shader_objects/rendezvous_by_name.c
new file mode 100644
index 0000000..c8d3b20
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/rendezvous_by_name.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright © 2015 Gregory Hainaut <gregory.hainaut at gmail.com>
+ *
+ * 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 rendezvous_by_name.c
+ * Simple test for separate shader objects that use rendezvous-by-name.
+ *
+ * Related to issue: https://bugs.freedesktop.org/show_bug.cgi?id=79783
+ *
+ * The test ensures deadcode optimization of input variables doesn't break
+ * the rendezvous by name of the variables.
+ */
+#include "piglit-util-gl.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 GLuint pipeline_3_out_1_in[2];
+static GLuint pipeline_1_out_3_in[2];
+static GLuint pipeline_inactive;
+static GLint  vs_fs_prog_inactive;
+
+static const char *vs_code_3_out_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: require\n"
+	"\n"
+	"layout(location = 0) in vec4 piglit_vertex;\n"
+	"\n"
+	"%s out vec4 blue;\n"
+	"out vec4 green;\n"
+	"out vec4 red;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = piglit_vertex;\n"
+	"    red   = vec4(1, 0, 0, 0);\n"
+	"    green = vec4(0, 1, 0, 0);\n"
+	"    blue  = vec4(0, 0, 1, 0);\n"
+	"}\n"
+	;
+
+static const char *vs_code_1_out_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: require\n"
+	"\n"
+	"layout(location = 0) in vec4 piglit_vertex;\n"
+	"\n"
+	"%s out vec4 blue;\n"
+	"out vec4 green;\n"
+	"out vec4 red;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = piglit_vertex;\n"
+	"    green = vec4(0, 1, 0, 0);\n"
+	"}\n"
+	;
+
+static const char *vs_code_inactive_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: require\n"
+	"\n"
+	"layout(location = 0) in vec4 piglit_vertex;\n"
+	"\n"
+	"#define MAX_VARYING %d\n"
+	"out vec4 a_dummy[MAX_VARYING];\n"
+	"out vec4 green;\n"
+	"out vec4 z_dummy[MAX_VARYING];\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = piglit_vertex;\n"
+	"    green = vec4(0, 1, 0, 0);\n"
+	"    for(int i = 0; i < MAX_VARYING; i++) {\n"
+	"        a_dummy[i] = vec4(1, 0, 0, 1);\n"
+	"        z_dummy[i] = vec4(0, 0, 1, 1);\n"
+	"    }\n"
+	"}\n"
+	;
+
+static const char *fs_code_1_in_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: enable\n"
+	"\n"
+	"#if __VERSION__ >= 130\n"
+	"layout(location = 0) out vec4 out_color;\n"
+	"#else\n"
+	"#define out_color gl_FragColor\n"
+	"#endif\n"
+	"\n"
+	"%s in vec4 blue;\n"
+	"in vec4 green;\n"
+	"in vec4 red;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    out_color = vec4(green.xyz, 1);\n"
+	"}\n"
+	;
+
+static const char *fs_code_3_in_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: enable\n"
+	"\n"
+	"#if __VERSION__ >= 130\n"
+	"layout(location = 0, index = 0) out vec4 out_color;\n"
+	"layout(location = 0, index = 1) out vec4 avoid_opt;\n"
+	"#else\n"
+	"#define out_color gl_FragColor\n"
+	"#endif\n"
+	"\n"
+	"%s in vec4 blue;\n"
+	"in vec4 green;\n"
+	"in vec4 red;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    out_color = vec4(green.xyz, 1);\n"
+	"    avoid_opt = vec4(blue + red);\n"
+	"}\n"
+	;
+
+static const char *fs_code_inactive_template =
+	"#version %d\n"
+	"#extension GL_ARB_separate_shader_objects: require\n"
+	"#extension GL_ARB_explicit_attrib_location: enable\n"
+	"\n"
+	"#if __VERSION__ >= 130\n"
+	"layout(location = 0) out vec4 out_color;\n"
+	"#else\n"
+	"#define out_color gl_FragColor\n"
+	"#endif\n"
+	"\n"
+	"#define MAX_VARYING %d\n"
+	"in vec4 a_dummy[MAX_VARYING];\n"
+	"in vec4 green;\n"
+	"in vec4 z_dummy[MAX_VARYING];\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    out_color = vec4(green.xyz, 1);\n"
+	"}\n"
+	;
+
+static const char *qualifiers[2] = {
+	"",
+	"layout(location = 0)"
+};
+
+enum piglit_result
+piglit_display(void)
+{
+	static const float expected[] = {
+		0.0f, 1.0f, 0.0f, 1.0f
+	};
+	bool pass = true;
+
+	glClearColor(0.1f, 0.1f, 0.1f, 0.1f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/*
+	 * Test 1: 3 active output in the VS + 1 active input in the FS. Only rendezvous by name
+	 * Screen location: bottom left
+	 */
+	glBindProgramPipeline(pipeline_3_out_1_in[0]);
+	piglit_draw_rect(-1, -1, 0.5, 1);
+
+	/*
+	 * Test 2: 3 active output in the VS + 1 active input in the FS. Mix rendezvous by name & location
+	 * Screen location: bottom middle
+	 */
+	glBindProgramPipeline(pipeline_3_out_1_in[1]);
+	piglit_draw_rect(-0.5, -1, 0.5, 1);
+
+	/*
+	 * Test 3: 1 active output in the VS + 3 active input in the FS. Only rendezvous by name
+	 * Screen location: top left
+	 */
+	glBindProgramPipeline(pipeline_1_out_3_in[0]);
+	piglit_draw_rect(-1, 0, 0.5, 1);
+
+	/*
+	 * Test 4: 1 active output in the VS + 3 active input in the FS. Mix rendezvous by name & location
+	 * Screen location: top middle
+	 */
+	glBindProgramPipeline(pipeline_1_out_3_in[1]);
+	piglit_draw_rect(-0.5, 0, 0.5, 1);
+
+	/*
+	 * Test 5: Link separate VS/FS together. Expect to optimize inactive variables
+	 * Screen location: bottom right
+	 */
+	glBindProgramPipeline(pipeline_inactive);
+	piglit_draw_rect(0, -1, 1, 1);
+
+	/*
+	 * Test 6: Link VS/FS together. Expect to optimize inactive variables
+	 * Screen location: top right
+	 */
+	glBindProgramPipeline(0);
+	glUseProgram(vs_fs_prog_inactive);
+	piglit_draw_rect(0, 0, 1, 1);
+
+	pass &= piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+				      expected);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+GLuint format_and_link_program(GLenum type, const char* code, unsigned glsl_version, unsigned qualifier)
+{
+	char *source;
+	GLuint prog;
+
+	asprintf(&source, code, glsl_version, qualifiers[qualifier]);
+	prog = glCreateShaderProgramv(type, 1,
+			(const GLchar *const *) &source);
+
+	piglit_link_check_status(prog);
+	free(source);
+
+	return prog;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	unsigned i;
+	unsigned glsl_version;
+	GLuint vs_prog_3_out[2];
+	GLuint vs_prog_1_out[2];
+	GLuint fs_prog_3_in[2];
+	GLuint fs_prog_1_in[2];
+	GLuint vs_fs_prog_separate_inactive;
+	bool es;
+	int glsl_major;
+	int glsl_minor;
+	char *vs_source;
+	char *fs_source;
+	GLint max_varying;
+	bool pass = true;
+
+	piglit_require_vertex_shader();
+	piglit_require_fragment_shader();
+	piglit_require_GLSL_version(130); /* Support layout index on output color */
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+	piglit_require_extension("GL_ARB_explicit_attrib_location");
+	piglit_require_extension("GL_ARB_blend_func_extended");
+
+	/* Some NVIDIA drivers have issues with layout qualifiers, 'in'
+	 * keywords, and 'out' keywords in "lower" GLSL versions.  If the
+	 * driver supports GLSL >= 1.40, use 1.40.  Otherwise, pick the
+	 * highest version that the driver supports.
+	 */
+	piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);
+	glsl_version = ((glsl_major * 100) + glsl_minor) >= 140
+		? 140 : ((glsl_major * 100) + glsl_minor);
+
+	glGetIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varying);
+	max_varying = (max_varying / 4u) - 1u;
+
+	/*
+	 * Program compilation and link
+	 */
+	for (i = 0; i < 2; i++) {
+		printf("Compile vs_prog_3_out[%d]\n", i);
+		vs_prog_3_out[i] = format_and_link_program(GL_VERTEX_SHADER,
+				vs_code_3_out_template, glsl_version, i);
+
+		printf("Compile vs_prog_1_out[%d]\n", i);
+		vs_prog_1_out[i] = format_and_link_program(GL_VERTEX_SHADER,
+				vs_code_1_out_template, glsl_version, i);
+
+		printf("Compile fs_prog_3_in[%d]\n", i);
+		fs_prog_3_in[i] = format_and_link_program(GL_FRAGMENT_SHADER,
+				fs_code_3_in_template, glsl_version, i);
+
+		printf("Compile fs_prog_1_in[%d]\n", i);
+		fs_prog_1_in[i] = format_and_link_program(GL_FRAGMENT_SHADER,
+				fs_code_1_in_template, glsl_version, i);
+	}
+
+	asprintf(&vs_source, vs_code_inactive_template, glsl_version, max_varying);
+	asprintf(&fs_source, fs_code_inactive_template, glsl_version, max_varying);
+
+	printf("Compile vs_fs_prog_separate_inactive\n");
+	vs_fs_prog_separate_inactive = piglit_build_simple_program_unlinked(vs_source, fs_source);
+	/* Manual linking so we can pack 2 separate-aware shaders into a single program */
+	glProgramParameteri(vs_fs_prog_separate_inactive, GL_PROGRAM_SEPARABLE, GL_TRUE);
+	glLinkProgram(vs_fs_prog_separate_inactive);
+	if (!piglit_link_check_status(vs_fs_prog_separate_inactive)) {
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	printf("Compile vs_fs_prog_inactive\n");
+	vs_fs_prog_inactive = piglit_build_simple_program(vs_source, fs_source);
+
+	free(vs_source);
+	free(fs_source);
+
+	/*
+	 * Pipeline creation
+	 */
+	glGenProgramPipelines(2, pipeline_3_out_1_in);
+	glGenProgramPipelines(2, pipeline_1_out_3_in);
+	for (i = 0; i < 2; i++) {
+		glBindProgramPipeline(pipeline_3_out_1_in[i]);
+		glUseProgramStages(pipeline_3_out_1_in[i],
+				GL_VERTEX_SHADER_BIT, vs_prog_3_out[i]);
+		glUseProgramStages(pipeline_3_out_1_in[i],
+				GL_FRAGMENT_SHADER_BIT, fs_prog_1_in[i]);
+
+		glBindProgramPipeline(pipeline_1_out_3_in[i]);
+		glUseProgramStages(pipeline_1_out_3_in[i],
+				GL_VERTEX_SHADER_BIT, vs_prog_1_out[i]);
+		glUseProgramStages(pipeline_1_out_3_in[i],
+				GL_FRAGMENT_SHADER_BIT, fs_prog_3_in[i]);
+	}
+
+	glGenProgramPipelines(1, &pipeline_inactive);
+	glBindProgramPipeline(pipeline_inactive);
+	glUseProgramStages(pipeline_inactive,
+			GL_VERTEX_SHADER_BIT | GL_FRAGMENT_SHADER_BIT,
+			vs_fs_prog_separate_inactive);
+
+	if (!piglit_check_gl_error(0) || !pass)
+		piglit_report_result(PIGLIT_FAIL);
+}
-- 
2.1.4



More information about the Piglit mailing list