[Mesa-dev] [PATCH 2/3] add 3 news tests for arb_separate_shader_objects

gregory hainaut gregory.hainaut at gmail.com
Thu Mar 28 10:32:30 PDT 2013


* 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...
Note: Nvidia seems to crash on glDeleteProgramPipelines 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."

Note: Nvidia seems to be fine.

* 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...
---
 tests/all.tests                                    |    7 +
 tests/spec/CMakeLists.txt                          |    1 +
 .../arb_separate_shader_objects/CMakeLists.gl.txt  |   14 +
 .../arb_separate_shader_objects/CMakeLists.txt     |    1 +
 .../GetProgramPipelineiv.c                         |  279 +++++++++++++++
 .../IsProgramPipeline.c                            |  113 ++++++
 .../mix_pipeline_useprogram.c                      |  361 ++++++++++++++++++++
 7 files changed, 776 insertions(+)
 create mode 100644 tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_separate_shader_objects/CMakeLists.txt
 create mode 100644 tests/spec/arb_separate_shader_objects/GetProgramPipelineiv.c
 create mode 100644 tests/spec/arb_separate_shader_objects/IsProgramPipeline.c
 create mode 100644 tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c

diff --git a/tests/all.tests b/tests/all.tests
index 20120d1..2cbf3c4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1079,6 +1079,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
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..81f6978
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/GetProgramPipelineiv.c
@@ -0,0 +1,279 @@
+/*
+ * 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) {
+	printf("Attach program (%d) to stage (%s). Expected to be supported: %s\n", program,
+			piglit_get_gl_enum_name(stage), supported ? "yes" : "no");
+	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"
+		"in vec4 position;\n"
+		"\n"
+		"void main()\n"
+		"{\n"
+		"	gl_Position = position;\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, 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_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..f17e876
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/IsProgramPipeline.c
@@ -0,0 +1,113 @@
+/*
+ * 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);
+
+	printf("glGenProgramPipelines with negative n value\n");
+	glGenProgramPipelines( -1, id);
+	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
+
+	printf("glGenProgramPipelines with correct n value\n");
+	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);
+	}
+
+	printf("glDeleteProgramPipelines with negative n value\n");
+	glDeleteProgramPipelines( -1, id);
+	pass &= piglit_check_gl_error(GL_INVALID_VALUE);
+
+	printf("glDeleteProgramPipelines with correct n value\n");
+	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..b76ee54
--- /dev/null
+++ b/tests/spec/arb_separate_shader_objects/mix_pipeline_useprogram.c
@@ -0,0 +1,361 @@
+/*
+ * 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};
+	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);
+
+	/* 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: with bad uniform  */
+	pass &= draw(gb);
+
+	/* 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);
+}
-- 
1.7.10.4


More information about the mesa-dev mailing list