[Piglit] [RFC] ARB_separate_shader_objects test

gregory hainaut gregory.hainaut at gmail.com
Tue Mar 26 12:56:30 PDT 2013


Hello,

I made a couple of test for the ARB_separate_shader_objects extensions. I tryed to validate
 them as much as possible on the FGLRX driver. I'm sorry I'm a complete noob on git so 
I 'cat' the diff output... I will try to do better next time. Anyway here a description
 of the test and the issue encounter on FGLRX.
piglit_link_check_status
* Add piglit_program_pipeline_check_status/quiet that behave as
piglit_link_check_status/quiet but for pipeline object.

* Update ext_transform_feedback to expect new INVALID_OPERATION. (spec chapter 13.2.2)
Note: FGLRX don't report any of the expected errors...

* new test IsProgramPipeline: check the Pipeline object state creation. GenPipeline 
only reserved name. I also take the opportunity to test negative value
on glGenProgramPipelines and glDeleteProgramPipelines.
Note: FGLRX don't follow the spec besides crash on glGenProgramPipelines because of -1...

* new test mix_pipeline_useprogram: the goal is to test the state mix of 
glUseProgram/glBindProgramPipeline/glActiveProgram. Ian 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."

* new test GetProgramPipelineiv: bind various stages (including geometry and tesselation
to the pipeline and check the result with GetProgramPipelineiv. I take also the opportunity to use
glCreateShaderProgramv.  Note: I got an GL_INVALID_VALUE when glActiveShaderProgram is
called with a program that isn't bound to any stage to the pipeline. For me there isn't such limitation in the spec 
but I could be wrong.
Spec quote: 
"An INVALID_VALUE error is generated if program is not the name of ei-
ther a program or shader object.
An INVALID_OPERATION error is generated if program is the name of a
shader object."

General note: I duplicate the vertex shader for differents GL version. On GLSL 150+ built-in must be 
redeclared. However previous version doesn't support in/out block so it is up to the GLSL compiler to
include them inplicitely. I try to force on older version of GLSL but it doesn't work on FGLRX and still 
need the redeclaration...

Plese find below my (really too big) patch.

Cheers,
Gregory

diff --git a/tests/all.tests b/tests/all.tests
index 20120d1..b1cd028 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1079,6 +1080,13 @@ add_concurrent_test(arb_occlusion_query, 'occlusion_query_meta_fragments')
 add_concurrent_test(arb_occlusion_query, 'occlusion_query_meta_no_fragments')
 add_concurrent_test(arb_occlusion_query, 'occlusion_query_order')
 
+# Group ARB_separate_shader_objects
+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()
 spec['ARB_sampler_objects'] = arb_sampler_objects
@@ -1899,7 +1907,9 @@ for mode in ['interleaved_ok_base', 'interleaved_ok_range',
              'bind_range_offset_2', 'bind_range_offset_3',
              'bind_range_offset_5', 'bind_offset_offset_1',
              'bind_offset_offset_2', 'bind_offset_offset_3',
-             'bind_offset_offset_5', 'not_a_program']:
+             'bind_offset_offset_5', 'not_a_program',
+             'useprogstage_noactive', 'useprogstage_active',
+             'bind_pipeline']:
         test_name = 'api-errors {0}'.format(mode)
         ext_transform_feedback[test_name] = concurrent_test(
                 'ext_transform_feedback-{0}'.format(test_name))
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 18b1d37..97efd36 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -15,6 +15,7 @@ add_subdirectory (arb_robustness)
 add_subdirectory (arb_sampler_objects)
 add_subdirectory (arb_seamless_cube_map)
 add_subdirectory (amd_seamless_cubemap_per_texture)
+add_subdirectory (arb_separate_shader_objects)
 add_subdirectory (arb_shader_texture_lod/execution)
 add_subdirectory (arb_shader_objects)
 add_subdirectory (arb_sync)
diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
new file mode 100644
index 0000000..e651956
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (arb_separate_shader_object-IsProgramPipeline IsProgramPipeline.c)
+piglit_add_executable (arb_separate_shader_object-GetProgramPipelineiv GetProgramPipelineiv.c)
+piglit_add_executable (arb_separate_shader_object-mix_pipeline_useprogram mix_pipeline_useprogram.c)
diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_separate_shader_objects/GetProgramPipelineiv.c b/tests/spec/arb_separate_shader_objects/GetProgramPipelineiv.c
new file mode 100644
index 0000000..c6fd430
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/GetProgramPipelineiv.c
@@ -0,0 +1,277 @@
+/*
+ * 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.
+ */
+
+#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 GLboolean pass;
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+static GLint
+stage2bitfield(GLint stage) {
+	switch(stage) {
+		case GL_VERTEX_SHADER: return GL_VERTEX_SHADER_BIT;
+		case GL_FRAGMENT_SHADER: return GL_FRAGMENT_SHADER_BIT;
+		case GL_GEOMETRY_SHADER: return GL_GEOMETRY_SHADER_BIT;
+		case GL_TESS_CONTROL_SHADER: return GL_TESS_CONTROL_SHADER_BIT;
+		case GL_TESS_EVALUATION_SHADER:return GL_TESS_EVALUATION_SHADER_BIT;
+		case GL_COMPUTE_SHADER: return GL_COMPUTE_SHADER_BIT;
+		default:return 0;
+	}
+	return 0;
+}
+
+static void
+check_stage(GLint pipe, GLint expected, GLint stage, GLboolean supported) {
+	GLint param = 0;
+	glGetProgramPipelineiv(pipe, stage, &param);
+
+	if (!supported) {
+		pass &= piglit_check_gl_error(GL_INVALID_ENUM);
+	} else if (param != expected) {
+		fprintf(stderr, "Failed to get program of stage %s.\n", piglit_get_gl_enum_name(stage));
+		pass = GL_FALSE;
+	}
+}
+
+static void
+use_stage_and_check(GLint pipe, GLint program, GLint stage, GLboolean supported) {
+	glUseProgramStages(pipe, stage2bitfield(stage), program);
+	if (!supported) {
+		pass &= piglit_check_gl_error(GL_INVALID_VALUE);
+	} else {
+		pass &= piglit_check_gl_error(GL_NO_ERROR);
+	}
+
+	check_stage(pipe, program, stage, supported);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLint vs, fs, gs, tcs, tes;
+	GLint ver;
+	GLuint pipe = 0;
+	GLint param = 0;
+	char version[100];
+	const char *shader_source[2];
+
+	const char *vs_source_150 =
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"};\n"
+		"\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *vs_source_140 =
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *fs_source =
+		"void main()\n"
+		"{\n"
+		"	gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
+		"}\n";
+	const char *gs_source =
+		"in gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"} gl_in[];\n"
+		"\n"
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"};\n"
+		"\n"
+		"layout(triangles) in;\n"
+		"layout(triangle_strip, max_vertices = 3) out;\n"
+		"void main() {\n"
+		"  for(int i = 0; i < gl_in.length(); i++) {\n"
+		"    gl_Position = gl_in[i].gl_Position;\n"
+		"    EmitVertex();\n"
+		"  }\n"
+		"  EndPrimitive();\n"
+		"}\n";
+	const char *tc_source =
+		"in gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"} gl_in[];\n"
+		"\n"
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"} gl_out[];\n"
+		"\n"
+		"layout( vertices = 3 )  out;\n"
+		"void main( )\n"
+		"{\n"
+		"        gl_out[ gl_InvocationID ].gl_Position = gl_in[ gl_InvocationID ].gl_Position;\n"
+		"        gl_TessLevelOuter[0] = 1.0;\n"
+		"        gl_TessLevelOuter[1] = 1.0;\n"
+		"        gl_TessLevelOuter[2] = 1.0;\n"
+		"        gl_TessLevelInner[0] = 1.0;\n"
+		"        gl_TessLevelInner[1] = 1.0;\n"
+		"}\n";
+	const char *te_source =
+		"in gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"} gl_in[];\n"
+		"\n"
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"    float gl_PointSize;\n"
+		"    float gl_ClipDistance[];\n"
+		"};\n"
+		"\n"
+		"layout( triangles, equal_spacing)  in;\n"
+		" \n"
+		"void main( )\n"
+		"{\n"
+		"        vec4 p0 = gl_in[0].gl_Position;\n"
+		"        vec4 p1 = gl_in[1].gl_Position;\n"
+		"        vec4 p2 = gl_in[2].gl_Position;\n"
+		" \n"
+		"        vec3 p = gl_TessCoord.xyz;\n"
+		" \n"
+		"        gl_Position = p0*p.x + p1*p.y + p2*p.z;\n"
+		"}\n";
+
+	piglit_require_gl_version(20);
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+
+	pass = GL_TRUE;
+
+	if (piglit_get_gl_version() >= 43) {
+		ver = 430;
+	} else if (piglit_get_gl_version() >= 40) {
+		ver = 400;
+	} else if(piglit_get_gl_version() >= 32) {
+		ver = 150;
+	} else {
+		ver = 120;
+	}
+	snprintf(version, 99, "#version %d\n\n#extension GL_ARB_separate_shader_objects : enable\n\n", ver);
+	version[99] = '\0';
+
+	shader_source[0] = version;
+	if (piglit_get_gl_version() >= 40) {
+		shader_source[1] = tc_source;
+		tcs = glCreateShaderProgramv(GL_TESS_CONTROL_SHADER, 2, shader_source);
+		pass &= piglit_link_check_status(tcs);
+
+		shader_source[1] = te_source;
+		tes = glCreateShaderProgramv(GL_TESS_EVALUATION_SHADER, 2, shader_source);
+		pass &= piglit_link_check_status(tes);
+	} else {
+		tcs = 0;
+		tes = 0;
+	}
+
+	if (piglit_get_gl_version() >= 32) {
+		shader_source[1] = gs_source;
+		gs = glCreateShaderProgramv(GL_GEOMETRY_SHADER, 2, shader_source);
+		pass &= piglit_link_check_status(gs);
+	} else {
+		gs = 0;
+	}
+
+	shader_source[1] = fs_source;
+	fs = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 2, shader_source);
+	pass &= piglit_link_check_status(fs);
+
+	if (piglit_get_gl_version() >= 32)
+		shader_source[1] = vs_source_150;
+	else
+		shader_source[1] = vs_source_140;
+	vs = glCreateShaderProgramv(GL_VERTEX_SHADER, 2, shader_source);
+	pass &= piglit_link_check_status(vs);
+
+	glGenProgramPipelines(1, &pipe);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	glActiveShaderProgram(pipe, fs);
+	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, &param);
+	if (param != fs) {
+		fprintf(stderr, "Failed to get Active Program.\n");
+		pass = GL_FALSE;
+	}
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	use_stage_and_check(pipe, vs, GL_VERTEX_SHADER, GL_TRUE);
+	use_stage_and_check(pipe, fs, GL_FRAGMENT_SHADER, GL_TRUE);
+	use_stage_and_check(pipe, fs, GL_FRAGMENT_SHADER, GL_TRUE);
+	use_stage_and_check(pipe, gs, GL_GEOMETRY_SHADER, (piglit_get_gl_version() >= 32));
+	use_stage_and_check(pipe, tes, GL_TESS_EVALUATION_SHADER, (piglit_get_gl_version() >= 40));
+	use_stage_and_check(pipe, tcs, GL_TESS_CONTROL_SHADER, (piglit_get_gl_version() >= 40));
+
+	glActiveShaderProgram(pipe, vs);
+	glGetProgramPipelineiv(pipe, GL_ACTIVE_PROGRAM, &param);
+	if (param != vs) {
+		fprintf(stderr, "Failed to get Active Program.\n");
+		pass = GL_FALSE;
+	}
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+
+	glUseProgramStages(pipe, GL_ALL_SHADER_BITS, 0);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	check_stage(pipe, 0, GL_VERTEX_SHADER, GL_TRUE);
+	check_stage(pipe, 0, GL_FRAGMENT_SHADER, GL_TRUE);
+	check_stage(pipe, 0, GL_FRAGMENT_SHADER, GL_TRUE);
+	check_stage(pipe, 0, GL_GEOMETRY_SHADER, (piglit_get_gl_version() >= 32));
+	check_stage(pipe, 0, GL_TESS_EVALUATION_SHADER, (piglit_get_gl_version() >= 40));
+	check_stage(pipe, 0, GL_TESS_CONTROL_SHADER, (piglit_get_gl_version() >= 40));
+
+
+	piglit_present_results();
+
+	if (pass)
+		piglit_report_result(PIGLIT_PASS);
+	else
+		piglit_report_result(PIGLIT_FAIL);
+}
diff --git a/tests/spec/arb_separate_shader_objects/IsProgramPipeline.c b/tests/spec/arb_separate_shader_objects/IsProgramPipeline.c
new file mode 100644
index 0000000..aba3406
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/IsProgramPipeline.c
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+/*
+ * The command
+ * void GenProgramPipelines( sizei n, uint *pipelines );
+ * returns n previously unused program pipeline object names in pipelines. These
+ * names are marked as used, for the purposes of GenProgramPipelines only, but
+ * they acquire state only when they are first bound.
+ */
+
+#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 GLboolean pass;
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+static void
+IsProgramPipeline(GLuint pipe, GLboolean expected) {
+	GLboolean status = glIsProgramPipeline(pipe);
+	if(status != expected) {
+		pass &= GL_FALSE;
+		fprintf(stderr, "Pipeline %d has wrong IsProgramPipeline. Expected %d, got %d\n", pipe, expected, status);
+	}
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLuint id[4] = {0, 0, 0};
+	int i;
+	GLint dummy;
+
+	piglit_require_gl_version(20);
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+
+	pass = GL_TRUE;
+
+	assert(glGetError() == GL_NO_ERROR);
+
+	glGenProgramPipelines( -1, id);
+	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
+
+	glGenProgramPipelines( 4, id);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	for (i = 0; i < 4 ; i++) {
+		IsProgramPipeline(id[i], GL_FALSE);
+	}
+
+	glBindProgramPipeline(id[0]);
+	glUseProgramStages(id[1], GL_ALL_SHADER_BITS, 0);
+	glActiveShaderProgram(id[2], 0);
+	glGetProgramPipelineiv(id[3], GL_VERTEX_SHADER, &dummy);
+	/* Flush any errors. The goal is to check that object acquire a state */
+	while (glGetError() != GL_NO_ERROR)
+		;
+
+	for (i = 0; i < 4 ; i++) {
+		IsProgramPipeline(id[i], GL_TRUE);
+	}
+
+	glDeleteProgramPipelines( -1, id);
+	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
+
+	glDeleteProgramPipelines( 4, id);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	piglit_present_results();
+
+	if (pass)
+		piglit_report_result(PIGLIT_PASS);
+	else
+		piglit_report_result(PIGLIT_FAIL);
+}
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..dcf3e57
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c
@@ -0,0 +1,359 @@
+/*
+ * 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 GLboolean pass = GL_TRUE;
+
+static GLboolean
+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(GLboolean enable) {
+	if (enable) {
+		glUseProgram(prog);
+		printf("Enable monolithic program\n");
+		pass &= check(GL_CURRENT_PROGRAM, prog);
+	} else {
+		glUseProgram(0);
+		printf("Disable monolithic program\n");
+		pass &= check(GL_CURRENT_PROGRAM, 0);
+	}
+}
+
+static void
+bind_pipeline(GLboolean enable) {
+	if (enable) {
+		glBindProgramPipeline(pipe);
+		printf("Bind pipeline\n");
+	} else {
+		glBindProgramPipeline(0);
+		printf("Unbind pipeline\n");
+	}
+}
+
+static GLboolean
+draw(float expected[4]) {
+	piglit_draw_rect(-1, -1, 2, 2);
+	return piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, expected);
+}
+
+static GLboolean
+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 GL_FALSE;
+	}
+	return GL_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};
+
+	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);
+
+	/* 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(GL_TRUE);
+	pass &= set_and_check_uniform(prog, 1.0);
+	bind_pipeline(GL_TRUE);
+	/* It must ignore the pipeline */
+	pass &= set_and_check_uniform(prog, 0.0);
+
+	/* UseProgram rendering */
+	pass &= draw(red);
+
+	/* TEST 2: BindPipeline without UseProgram */
+	printf("TEST 2\n");
+	bind_program(GL_FALSE);
+	bind_pipeline(GL_TRUE);
+	pass &= set_and_check_uniform(active_shader_pipe, 1.0);
+	pass &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	/* TEST 3: UseProgram after BindPipeline */
+	printf("TEST 3\n");
+	bind_program(GL_TRUE);
+
+	/* UseProgram rendering */
+	pass &= draw(red);
+
+	/* TEST 4: UseProgram(0) after BindPipeline  */
+	printf("TEST 4\n");
+	bind_program(GL_FALSE);
+	bind_pipeline(GL_TRUE);
+	pass &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+
+	/* Sanity check */
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	bind_program(GL_FALSE);
+
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	bind_pipeline(GL_TRUE);
+	pass &= check(GL_PROGRAM_PIPELINE_BINDING, pipe);
+	pass &= draw(green);
+
+	/* TEST 5: like previous test but use a real program before UseProgram(0) */
+	printf("TEST 5\n");
+	bind_program(GL_FALSE);
+	bind_pipeline(GL_TRUE);
+
+	/* Sanity check */
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	/* Set wrong uniform value */
+	pass &= set_and_check_uniform(active_shader_pipe, 0.0);
+
+	bind_program(GL_TRUE);
+	bind_program(GL_FALSE);
+
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	/* pipeline program must be still active */
+	pass &= set_and_check_uniform(active_shader_pipe, 1.0);
+
+	bind_pipeline(GL_TRUE);
+	/* Pipeline rendering  */
+	pass &= draw(green);
+
+	/* TEST 6: Sanity check */
+	printf("TEST 6\n");
+	bind_program(GL_FALSE);
+	bind_pipeline(GL_FALSE);
+	/* Fixed function rendering */
+	pass &= draw(blue);
+
+	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 =
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *vs_source_sep_150 =
+		"#extension GL_ARB_separate_shader_objects : enable\n"
+		"out gl_PerVertex {\n"
+		"    vec4 gl_Position;\n"
+		"};\n"
+		"\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *vs_source_sep_140 =
+		"#extension GL_ARB_separate_shader_objects : enable\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = gl_Vertex;\n"
+		"}\n";
+	const char *fs_source_r =
+		"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 =
+		"#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 = GL_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);
+
+
+	/* Now create program for the pipeline program */
+	if (piglit_get_gl_version() >= 32)
+		vs_s = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source_sep_150);
+	else
+		vs_s = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source_sep_140);
+	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);
+}
diff --git a/tests/spec/ext_transform_feedback/api-errors.c b/tests/spec/ext_transform_feedback/api-errors.c
index 04470b2..ba4fff8 100644
--- a/tests/spec/ext_transform_feedback/api-errors.c
+++ b/tests/spec/ext_transform_feedback/api-errors.c
@@ -78,6 +78,9 @@ enum test_mode {
 	BIND_BAD_SIZE,
 	BIND_BAD_OFFSET,
 	NOT_A_PROGRAM,
+	USEPROGSTAGE_ACTIVE,
+	USEPROGSTAGE_NOACTIVE,
+	BIND_PIPELINE
 };
 
 enum bind_mode {
@@ -97,6 +100,32 @@ static const char *vstext =
 	"  gl_Position = vec4(1.0);\n"
 	"}\n";
 
+static const char *vstext_sep_150 =
+	"#extension GL_ARB_separate_shader_objects : enable\n"
+	"out gl_PerVertex {\n"
+	"    vec4 gl_Position;\n"
+	"};\n"
+	"varying vec4 foo;\n"
+	"varying vec4 bar;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"  foo = vec4(1.0);\n"
+	"  bar = vec4(1.0);\n"
+	"  gl_Position = vec4(1.0);\n"
+	"}\n";
+static const char *vstext_sep_140 =
+	"#extension GL_ARB_separate_shader_objects : enable\n"
+	"varying vec4 foo;\n"
+	"varying vec4 bar;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"  foo = vec4(1.0);\n"
+	"  bar = vec4(1.0);\n"
+	"  gl_Position = vec4(1.0);\n"
+	"}\n";
+
 static const char *varyings[] = { "foo", "bar" };
 
 static struct test_desc
@@ -151,6 +180,10 @@ static struct test_desc
 	{ "bind_offset_offset_3",    BIND_BAD_OFFSET,      3, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
 	{ "bind_offset_offset_5",    BIND_BAD_OFFSET,      5, OFFSET, GL_INTERLEAVED_ATTRIBS, 1 },
 	{ "not_a_program",           NOT_A_PROGRAM,        0, BASE,   GL_INTERLEAVED_ATTRIBS, 1 },
+	{ "useprogstage_noactive",   USEPROGSTAGE_NOACTIVE,0, BASE,   GL_INTERLEAVED_ATTRIBS, 1 },
+	{ "useprogstage_active",     USEPROGSTAGE_ACTIVE,  0, BASE,   GL_INTERLEAVED_ATTRIBS, 1 },
+	{ "bind_pipeline",           BIND_PIPELINE,        0, BASE,   GL_INTERLEAVED_ATTRIBS, 1 },
+
 };
 
 static void
@@ -186,6 +219,7 @@ do_test(const struct test_desc *test)
 {
 	GLuint vs;
 	GLuint progs[2];
+	GLuint pipes[2];
 	GLuint bufs[NUM_BUFFERS];
 	float initial_xfb_buffer_contents[XFB_BUFFER_SIZE];
 	GLboolean pass = GL_TRUE;
@@ -193,6 +227,10 @@ do_test(const struct test_desc *test)
 	int num_varyings = test->mode == NO_VARYINGS ? 0 : test->num_buffers;
 	GLint max_separate_attribs;
 
+	if (test->mode == USEPROGSTAGE_ACTIVE || test->mode == USEPROGSTAGE_NOACTIVE || test->mode == BIND_PIPELINE) {
+		piglit_require_extension("GL_ARB_separate_shader_objects");
+	}
+
 	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
 		      &max_separate_attribs);
 	printf("MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTIBS=%i\n",
@@ -200,7 +238,19 @@ do_test(const struct test_desc *test)
 
 	printf("Compile vertex shader\n");
 	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
-	if (test->mode == NOT_A_PROGRAM) {
+	if (test->mode == USEPROGSTAGE_ACTIVE || test->mode == USEPROGSTAGE_NOACTIVE || test->mode == BIND_PIPELINE) {
+		/* Note, we can't use glCreateShaderProgramv because the setup of transform feedback
+		 * must be done before linking
+		 */
+		if (piglit_get_gl_version() >= 32)
+			vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext_sep_150);
+		else
+			vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext_sep_140);
+		progs[0] = glCreateProgram();
+		glProgramParameteri(progs[0], GL_PROGRAM_SEPARABLE, GL_TRUE);
+		glAttachShader(progs[0], vs);
+
+	} else if (test->mode == NOT_A_PROGRAM) {
 		printf("Create a program and then delete it\n");
 		progs[0] = glCreateProgram();
 		glDeleteProgram(progs[0]);
@@ -227,6 +277,15 @@ do_test(const struct test_desc *test)
 	glLinkProgram(progs[0]);
 	pass = piglit_link_check_status(progs[0]) && pass;
 
+	if (test->mode == USEPROGSTAGE_ACTIVE || test->mode == USEPROGSTAGE_NOACTIVE || test->mode == BIND_PIPELINE) {
+		printf("Create 2nd program for the pipeline\n");
+		if (piglit_get_gl_version() >= 32)
+			progs[1] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &vstext_sep_150);
+		else
+			progs[1] = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &vstext_sep_140);
+		pass = piglit_link_check_status(progs[1]) && pass;
+	}
+
 	if (test->mode == USEPROG_ACTIVE || test->mode == LINK_OTHER_ACTIVE) {
 		printf("Prepare 2nd program\n");
 		progs[1] = glCreateProgram();
@@ -238,7 +297,13 @@ do_test(const struct test_desc *test)
 		pass = piglit_link_check_status(progs[1]) && pass;
 	}
 
-	if (test->mode == SKIP_USE_PROGRAM) {
+	if (test->mode == USEPROGSTAGE_ACTIVE || test->mode == USEPROGSTAGE_NOACTIVE || test->mode == BIND_PIPELINE) {
+		printf("Use pipeline\n");
+		glGenProgramPipelines(2, pipes);
+		glUseProgramStages(pipes[0], GL_VERTEX_SHADER_BIT, progs[0]);
+		glUseProgramStages(pipes[1], GL_VERTEX_SHADER_BIT, progs[1]);
+		glBindProgramPipeline(pipes[0]);
+	} else if (test->mode == SKIP_USE_PROGRAM) {
 		printf("Don't use program\n");
 	} else {
 		printf("Use program\n");
@@ -325,6 +390,21 @@ do_test(const struct test_desc *test)
 		do_bind(test, bufs[0], 0);
 		pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
 		break;
+	case USEPROGSTAGE_ACTIVE:
+		printf("Use new program stage\n");
+		glUseProgramStages(pipes[0], GL_VERTEX_SHADER_BIT, progs[1]);
+		pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
+		break;
+	case USEPROGSTAGE_NOACTIVE:
+		printf("Use new program stage\n");
+		glUseProgramStages(pipes[1], GL_VERTEX_SHADER_BIT, progs[1]);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+		break;
+	case BIND_PIPELINE:
+		printf("Bind a new pipeline\n");
+		pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
+		glBindProgramPipeline(pipes[1]);
+		break;
 	default:
 		break;
 	}
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index c67e58a..d7a0266 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -213,6 +213,45 @@ link_check_status(GLint prog, FILE *output)
 	return ok;
 }
 
+/* Same function as above but for program pipeline */
+static GLboolean
+program_pipeline_check_status(GLuint pipeline, FILE *output)
+{
+	GLchar *info = NULL;
+	GLint size;
+	GLint ok;
+
+	piglit_require_extension("GL_ARB_separate_shader_objects");
+
+	glValidateProgramPipeline(pipeline);
+	glGetProgramPipelineiv(pipeline, GL_VALIDATE_STATUS, &ok);
+
+	/* Some drivers return a size of 1 for an empty log.  This is the size
+	 * of a log that contains only a terminating NUL character.
+	 */
+	glGetProgramPipelineiv(pipeline, GL_INFO_LOG_LENGTH, &size);
+	if (size > 1) {
+		info = malloc(size);
+		glGetProgramPipelineInfoLog(pipeline, size, NULL, info);
+	}
+
+	if (!ok) {
+		fprintf(output, "Failed to validate the pipeline: %s\n",
+			(info != NULL) ? info : "<empty log>");
+	}
+	else if (0 && info != NULL) {
+		/* Enable this to get extra linking info.
+		 * Even if there's no link errors, the info log may
+		 * have some remarks.
+		 */
+		printf("Pipeline validataion warning: %s\n", info);
+	}
+
+	free(info);
+
+	return ok;
+}
+
 GLboolean
 piglit_link_check_status(GLint prog)
 {
@@ -234,6 +273,17 @@ piglit_link_check_status_quiet(GLint prog)
 	return link_check_status(prog, stdout);
 }
 
+GLboolean
+piglit_program_pipeline_check_status(GLuint pipeline)
+{
+	return program_pipeline_check_status(pipeline, stderr);
+}
+
+GLboolean
+piglit_program_pipeline_check_status_quiet(GLuint pipeline)
+{
+	return program_pipeline_check_status(pipeline, stdout);
+}
 
 GLint piglit_link_simple_program(GLint vs, GLint fs)
 {
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index 12cf731..0bb7792 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -34,6 +34,8 @@ GLuint piglit_compile_shader(GLenum target, const char *filename);
 GLuint piglit_compile_shader_text(GLenum target, const char *text);
 GLboolean piglit_link_check_status(GLint prog);
 GLboolean piglit_link_check_status_quiet(GLint prog);
+GLboolean piglit_program_pipeline_check_status(GLuint pipeline);
+GLboolean piglit_program_pipeline_check_status_quiet(GLuint pipeline);
 GLint piglit_link_simple_program(GLint vs, GLint fs);
 
 #if defined(PIGLIT_USE_OPENGL_ES1)


More information about the Piglit mailing list