[Piglit] [PATCH 4/6] sso: new test mix_pipeline_useprogram:

Gregory Hainaut gregory.hainaut at gmail.com
Sat May 25 03:29:29 PDT 2013


the goal is to test the state mix of glUseProgram/glBindProgramPipeline/glActiveProgram.
Ian R. quote:
 "In this case, either the UseProgram state or the BindProgramPipeline state.
  If UseProgram sets a non-zero program, that state is used.  Otherwise the
  BindProgramPipeline state is used.....In this case, I think AMD's
  behavior is incorrect."

Note: Nvidia seems to be fine.

V4:
* split into a separate commit
* Merge the 2 vertex shaders with the help of the __VERSION__ macro
* Properly set shader version with asprintf
* Use standard bool
* Split test into subtest
* Fix expected of GL_PROGRAM_PIPELINE_BINDING (based on nvidia behavior)

Note: vertex shader doesn't work with FGLRX. It would require GLSL150 but that mean
you can't use fixed pipeline anymore...
---
 tests/all.tests                                    |    1 +
 .../mix_pipeline_useprogram.c                      |  389 ++++++++++++++++++++
 2 files changed, 390 insertions(+)
 create mode 100644 tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c

diff --git a/tests/all.tests b/tests/all.tests
index e8dfcbe..7894ad9 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1105,6 +1105,7 @@ arb_separate_shader_objects = Group()
 spec['ARB_separate_shader_objects'] = arb_separate_shader_objects
 arb_separate_shader_objects['sso-GetProgramPipelineiv'] = concurrent_test('arb_separate_shader_object-GetProgramPipelineiv')
 arb_separate_shader_objects['sso-IsProgramPipeline'] = concurrent_test('arb_separate_shader_object-IsProgramPipeline')
+arb_separate_shader_objects['sso-mix_pipeline_useprogram'] = concurrent_test('arb_separate_shader_object-mix_pipeline_useprogram')
 
 # Group ARB_sampler_objects
 arb_sampler_objects = Group()
diff --git a/tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c b/tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c
new file mode 100644
index 0000000..bd682bb
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c
@@ -0,0 +1,389 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+/*
+ * If no current program object has been established by UseProgram, the pro-
+ * gram objects used for each shader stage and for uniform updates are taken from
+ * the bound program pipeline object, if any. If there is a current program object
+ * established by UseProgram, the bound program pipeline object has no effect on
+ * rendering or uniform updates. When a bound program pipeline object is used for
+ * rendering, individual shader executables are taken from its program objects as de-
+ * scribed in the discussion of UseProgram in section 7.3).
+ */
+
+/*
+ *   The executable code for an individual shader stage is taken from the
+ *   current program for that stage.  If there is a current program object
+ *   for any shader stage or for uniform updates established by UseProgram,
+ *   UseShaderProgramEXT, or ActiveProgramEXT, the current program for that
+ *   stage (if any) is considered current.  Otherwise, if there is a bound
+ *   program pipeline object ...
+ *
+ * Note that with these rules, it's not possible to mix program objects bound
+ * to the context with program objects bound to a program pipeline object; if
+ * any program is bound to the context, the current pipeline object is
+ * ignored.
+ */
+
+/*
+ *4.  How do the glUniform* commands determine what program object
+ *       to query?
+ *
+ *       RESOLVED:  In a program pipeline object, this extension provides
+ *       separate program binding points for each stage, as well as an "active"
+ *       program specified by glActiveShaderProgram.  When glUniform is called
+ *       when a program pipeline object is active, the active program specifies
+ *       the program used by glUniform* commands.  This active program is
+ *       simply a selector and doesn't actually control any rendering
+ *       operation.
+ *
+ *       The active program can be queried with glGetProgramPipelineiv with a
+ *       <pname> of GL_ACTIVE_PROGRAM.
+ *
+ *       When a non-zero program is passed to UseProgram, any subsequent
+ *       uniform updates will affect that program, ignoring the active program
+ *       in any bound pipeline object.  For example:
+ *
+ *         glUseProgram(0);
+ *         glBindProgramPipeline(1);
+ *         glActiveProgram(1, 2);
+ *         glUniform1f(0, 3.0);          // affects program 2
+ *         glUseProgram(3);
+ *         glUniform1f(0, 3.0);          // affects program 3
+ *         glUseProgram(0);
+ *         glUniform1f(0, 3.0);          // affects program 2
+ *
+ *
+ *       As an alternative to setting the GL_ACTIVE_PROGRAM selector
+ *       with glActiveShaderProgram, applications are instead encouraged
+ *       to use the glProgramUniform* commands introduced by the
+ *       EXT_direct_state_access extension which do not depend on a
+ *       selector but specify the program object with which to update
+ *       the specified uniform location explicitly.
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = 32;
+	config.window_height = 32;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint prog;
+static GLuint pipe;
+static bool pass = true;
+static bool subtest = true;
+
+static bool
+check(GLenum pname, GLint expected) {
+	GLint value = 0;
+	glGetIntegerv(pname, &value);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+	if (value != expected) {
+		fprintf(stderr, "Failed to get %s expected %d got %d\n", piglit_get_gl_enum_name(pname), expected, value);
+		return false;
+	} else {
+		return true;
+	}
+}
+
+static void
+bind_program(bool enable) {
+	if (enable) {
+		glUseProgram(prog);
+		printf("Enable monolithic program\n");
+		subtest &= check(GL_CURRENT_PROGRAM, prog);
+	} else {
+		glUseProgram(0);
+		printf("Disable monolithic program\n");
+		subtest &= check(GL_CURRENT_PROGRAM, 0);
+	}
+}
+
+static void
+bind_pipeline(bool enable) {
+	if (enable) {
+		glBindProgramPipeline(pipe);
+		printf("Bind pipeline\n");
+	} else {
+		glBindProgramPipeline(0);
+		printf("Unbind pipeline\n");
+	}
+}
+
+static bool
+draw(float expected[4]) {
+	piglit_draw_rect(-1, -1, 2, 2);
+	return piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, expected);
+}
+
+static bool
+set_and_check_uniform(GLint program, float expected) {
+	float value;
+	glUniform1f(0, expected);
+	glGetUniformfv(program, 0, &value);
+	if (value != expected) {
+		fprintf(stderr, "Failed to get uniform value of %d, expected %f, got %f\n", program, expected, value);
+		return false;
+	}
+	return true;
+}
+
+static void
+report_subtest(char* msg)
+{
+	if (subtest)
+		piglit_report_subtest_result(PIGLIT_PASS, msg);
+	else
+		piglit_report_subtest_result(PIGLIT_FAIL, msg);
+
+	pass &= subtest;
+	subtest = true;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLint active_shader_pipe;
+	GLint uniform_loc_pipe;
+	GLint uniform_loc_prog;
+	float red[4] = {1.0, 0.0, 0.0, 1.0};
+	float green[4] = {0.0, 1.0, 0.0, 1.0};
+	float blue[4] = {0.0, 0.0, 1.0, 1.0};
+	float gb[4] = {0.0, 1.0, 1.0, 1.0};
+
+	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, &active_shader_pipe);
+	uniform_loc_pipe = glGetUniformLocation(active_shader_pipe, "blue");
+	uniform_loc_prog = glGetUniformLocation(prog, "blue");
+	/* otherwise it is difficult which program is really updated */
+	assert(uniform_loc_prog == 0);
+	assert(uniform_loc_pipe == 0);
+
+	/* wrong setup: stop here */
+	if (!pass) return PIGLIT_FAIL;
+
+	/* Set up fixed function to draw blue if we lose our shader. */
+	glColor4f(0.0, 0.0, 1.0, 1.0);
+
+	/* TEST 1: BindPipeline after UseProgram */
+	printf("TEST 1\n");
+	bind_program(true);
+	subtest &= set_and_check_uniform(prog, 1.0);
+	bind_pipeline(true);
+	/* It must ignore the pipeline */
+	subtest &= set_and_check_uniform(prog, 0.0);
+	/* But the pipeline is attached to the binding point */
+	subtest &= check(GL_PROGRAM_PIPELINE_BINDING, 0);
+
+	/* UseProgram rendering */
+	subtest &= draw(red);
+
+	report_subtest("TEST_1");
+
+	/* TEST 2: BindPipeline without UseProgram */
+	printf("TEST 2\n");
+	bind_program(false);
+	bind_pipeline(true);
+	subtest &= set_and_check_uniform(active_shader_pipe, 1.0);
+	subtest &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+
+	/* Pipeline rendering  */
+	subtest &= draw(green);
+
+	report_subtest("TEST_2");
+
+	/* TEST 3: UseProgram after BindPipeline */
+	printf("TEST 3\n");
+	bind_program(true);
+	subtest &= check(GL_PROGRAM_PIPELINE_BINDING, 0);
+
+	report_subtest("TEST_3");
+
+	/* UseProgram rendering */
+	subtest &= draw(red);
+
+	/* TEST 4: UseProgram(0) after BindPipeline  */
+	printf("TEST 4\n");
+	bind_program(false);
+	bind_pipeline(true);
+	subtest &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+
+	/* Sanity check */
+	/* Pipeline rendering  */
+	subtest &= draw(green);
+
+	bind_program(false);
+
+	/* Pipeline rendering  */
+	subtest &= draw(green);
+
+	bind_pipeline(true);
+	subtest &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+	subtest &= draw(green);
+
+	report_subtest("TEST_4");
+
+	/* TEST 5: like previous test but use a real program before UseProgram(0) */
+	printf("TEST 5\n");
+	bind_program(false);
+	bind_pipeline(true);
+
+	/* Sanity check */
+	/* Pipeline rendering  */
+	subtest &= draw(green);
+
+	/* Set wrong uniform value */
+	subtest &= set_and_check_uniform(active_shader_pipe, 0.0);
+
+	bind_program(true);
+	bind_program(false);
+
+	/* Pipeline rendering: with bad uniform  */
+	subtest &= draw(gb);
+
+	/* pipeline program must be still active */
+	subtest &= set_and_check_uniform(active_shader_pipe, 1.0);
+
+	bind_pipeline(true);
+	/* Pipeline rendering  */
+	subtest &= draw(green);
+
+	report_subtest("TEST_5");
+
+	/* TEST 6: Sanity check */
+	printf("TEST 6\n");
+	bind_program(false);
+	bind_pipeline(false);
+	/* Fixed function rendering */
+	subtest &= draw(blue);
+
+	report_subtest("TEST_6");
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLint bad_vs_prog;
+	GLint vs_prog;
+	GLint fs_prog;
+	GLint vs, vs_s, fs_g, fs_r;
+	const char *vs_source =
+		"#version 110\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *vs_source_sep =
+		"#version 110\n"
+		"#extension GL_ARB_separate_shader_objects : enable\n"
+		"#if __VERSION__ > 140\n"
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"};\n"
+		"#endif\n"
+		"\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *fs_source_r =
+		"#version 110\n"
+		"uniform float blue;\n"
+		"void main()\n"
+		"{\n"
+		"	gl_FragColor = vec4(1.0, 0.0, blue, 1.0);\n"
+		"}\n";
+	const char *fs_source_g =
+		"#version 110\n"
+		"#extension GL_ARB_separate_shader_objects : enable\n"
+		"uniform float blue;\n"
+		"void main()\n"
+		"{\n"
+		"	gl_FragColor = vec4(0.0, 1.0, 1.0 - blue, 1.0);\n"
+		"}\n";
+
+	pass = true;
+
+	piglit_require_gl_version(20);
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+
+	/* Standard program (ie not separate) */
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+	fs_r = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source_r);
+	prog = piglit_link_simple_program(vs, fs_r);
+	pass &= piglit_link_check_status(prog);
+
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	/* Now create program for the pipeline program */
+	vs_s = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source_sep);
+	fs_g = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source_g);
+
+	bad_vs_prog = glCreateProgram();
+	glProgramParameteri(bad_vs_prog, GL_PROGRAM_SEPARABLE, GL_FALSE);
+	glAttachShader(bad_vs_prog, vs_s);
+	glLinkProgram(bad_vs_prog);
+	pass &= piglit_link_check_status(bad_vs_prog);
+
+	vs_prog     = glCreateProgram();
+	glProgramParameteri(vs_prog, GL_PROGRAM_SEPARABLE, GL_TRUE);
+	glAttachShader(vs_prog, vs_s);
+	glLinkProgram(vs_prog);
+	pass &= piglit_link_check_status(vs_prog);
+
+	fs_prog     = glCreateProgram();
+	glProgramParameteri(fs_prog, GL_PROGRAM_SEPARABLE, GL_TRUE);
+	glAttachShader(fs_prog, fs_g);
+	glLinkProgram(fs_prog);
+	pass &= piglit_link_check_status(fs_prog);
+
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	glGenProgramPipelines(1, &pipe);
+
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	/* Program without GL_PROGRAM_SEPARABLE must failed */
+	glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT, bad_vs_prog);
+	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
+
+	glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT, vs_prog);
+	glUseProgramStages(pipe, GL_FRAGMENT_SHADER_BIT, fs_prog);
+	glActiveShaderProgram(pipe, fs_prog);
+	pass &= piglit_program_pipeline_check_status(pipe);
+
+	pass &= check(GL_PROGRAM_PIPELINE_BINDING, 0);
+	pass &= check(GL_CURRENT_PROGRAM, 0);
+
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+}
-- 
1.7.10.4



More information about the Piglit mailing list