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

Gregory Hainaut gregory.hainaut at gmail.com
Fri Sep 25 12:21:58 PDT 2015


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

"Validated" on Nvidia driver
---
 .../arb_separate_shader_objects/CMakeLists.gl.txt  |   1 +
 .../rendezvous_by_name.c                           | 219 +++++++++++++++++++++
 2 files changed, 220 insertions(+)
 create mode 100644 tests/spec/arb_separate_shader_objects/rendezvous_by_name.c

diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
index b596f67..a835187 100644
--- a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
@@ -19,5 +19,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..2248f16
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/rendezvous_by_name.c
@@ -0,0 +1,219 @@
+/*
+ * 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_deadcode_name;
+static GLuint pipeline_deadcode_location;
+
+static const char *vs_code_deadcode_name_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"
+	"out vec3 a;\n"
+	"out vec3 b;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = piglit_vertex;\n"
+	"    a = vec3(0, 0, 1);\n"
+	"    b = vec3(1, 0, 0);\n"
+	"}\n"
+	;
+
+static const char *vs_code_deadcode_location_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"
+	"out vec3 a;\n"
+	"out vec3 b;\n"
+	"layout(location = 0) out vec3 c;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = piglit_vertex;\n"
+	"    a = vec3(0, 0, 1);\n"
+	"    b = vec3(1, 0, 0);\n"
+	"    c = vec3(0, 1, 0);\n"
+	"}\n"
+	;
+
+static const char *fs_code_deadcode_name_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"
+	"in vec3 a; /* should get vec3(0, 0, 1) */\n"
+	"in vec3 b; /* should get vec3(1, 0, 0) */\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    out_color = vec4(b.xyx, 1);\n"
+	"}\n"
+	;
+
+static const char *fs_code_deadcode_location_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"
+	"layout(location = 0) in vec3 c; /* should get vec3(0,1,0) */\n"
+	"in vec3 a; /* should get vec3(0, 0, 1) */\n"
+	"in vec3 b; /* should get vec3(1, 0, 0) */\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"    out_color = vec4((b + a), 1);\n"
+	"}\n"
+	;
+
+enum piglit_result
+piglit_display(void)
+{
+	static const float expected[] = {
+		1.0f, 0.0f, 1.0f, 1.0f
+	};
+	bool pass;
+
+	glClearColor(0.1f, 0.1f, 0.1f, 0.1f);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glBindProgramPipeline(pipeline_deadcode_name);
+	piglit_draw_rect(-1, -1, 1, 2);
+
+	glBindProgramPipeline(pipeline_deadcode_location);
+	piglit_draw_rect(0, -1, 1, 2);
+	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+				      expected);
+
+	piglit_present_results();
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	unsigned glsl_version;
+	GLuint vs_prog_deadcode_name;
+	GLuint vs_prog_deadcode_location;
+	GLuint fs_prog_deadcode_name;
+	GLuint fs_prog_deadcode_location;
+	bool es;
+	int glsl_major;
+	int glsl_minor;
+	char *source;
+
+	piglit_require_vertex_shader();
+	piglit_require_fragment_shader();
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+	piglit_require_extension("GL_ARB_explicit_attrib_location");
+
+	/* 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);
+
+	asprintf(&source, vs_code_deadcode_name_template, glsl_version);
+	vs_prog_deadcode_name = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
+					 (const GLchar *const *) &source);
+	piglit_link_check_status(vs_prog_deadcode_name);
+	free(source);
+
+	asprintf(&source, vs_code_deadcode_location_template, glsl_version);
+	vs_prog_deadcode_location = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,
+					 (const GLchar *const *) &source);
+	piglit_link_check_status(vs_prog_deadcode_location);
+	free(source);
+
+	asprintf(&source, fs_code_deadcode_name_template, glsl_version);
+	fs_prog_deadcode_name =
+		glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
+				       (const GLchar *const *) &source);
+	piglit_link_check_status(fs_prog_deadcode_name);
+	free(source);
+
+	asprintf(&source, fs_code_deadcode_location_template, glsl_version);
+	fs_prog_deadcode_location =
+		glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,
+				       (const GLchar *const *) &source);
+	piglit_link_check_status(fs_prog_deadcode_location);
+	free(source);
+
+	glGenProgramPipelines(1, &pipeline_deadcode_name);
+	glUseProgramStages(pipeline_deadcode_name,
+			   GL_VERTEX_SHADER_BIT,
+			   vs_prog_deadcode_name);
+	glUseProgramStages(pipeline_deadcode_name,
+			   GL_FRAGMENT_SHADER_BIT,
+			   fs_prog_deadcode_name);
+	piglit_program_pipeline_check_status(pipeline_deadcode_name);
+
+	glGenProgramPipelines(1, &pipeline_deadcode_location);
+	glUseProgramStages(pipeline_deadcode_location,
+			   GL_VERTEX_SHADER_BIT,
+			   vs_prog_deadcode_location);
+	glUseProgramStages(pipeline_deadcode_location,
+			   GL_FRAGMENT_SHADER_BIT,
+			   fs_prog_deadcode_location);
+	piglit_program_pipeline_check_status(pipeline_deadcode_location);
+
+	if (!piglit_check_gl_error(0))
+		piglit_report_result(PIGLIT_FAIL);
+}
-- 
2.1.4



More information about the Piglit mailing list