[Piglit] [v2 4/7] tests/spec: ARB_transform_feedback3 interleaved in multiple streams

Topi Pohjolainen topi.pohjolainen at intel.com
Fri Oct 4 09:22:09 PDT 2013


v2:
  - fixed indentation: spaces -> tabs (Ian)
  - require core/compatibility version 3.2 instead of
    ARB_geometry_shader4 which is not going to be supported by
    mesa (Ian)
  - drop _EXT, use core names instead (Ian)
  - now using piglit_build_simple_program_multiple_shaders()

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/all.tests                                    |   1 +
 .../spec/arb_transform_feedback3/CMakeLists.gl.txt |   1 +
 .../ext_interleaved_single_gs_many_streams.c       | 346 +++++++++++++++++++++
 3 files changed, 348 insertions(+)
 create mode 100644 tests/spec/arb_transform_feedback3/ext_interleaved_single_gs_many_streams.c

diff --git a/tests/all.tests b/tests/all.tests
index 6f92947..73343f6 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2306,6 +2306,7 @@ for param in ['gl_NextBuffer-1', 'gl_NextBuffer-2', 'gl_SkipComponents1-1',
 
 arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers_vs'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers', '-auto', 'vs'])
 arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers_gs'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_single_stream_many_buffers', '-auto', 'gs'])
+arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_single_gs_many_streams'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_single_gs_many_streams', '-auto'])
 
 arb_uniform_buffer_object = Group()
 spec['ARB_uniform_buffer_object'] = arb_uniform_buffer_object
diff --git a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
index a202233..3bcdeb0 100644
--- a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
+++ b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
@@ -9,5 +9,6 @@ link_libraries (
 )
 
 piglit_add_executable (arb_transform_feedback3-ext_interleaved_single_stream_many_buffers ext_interleaved_single_stream_many_buffers.c)
+piglit_add_executable (arb_transform_feedback3-ext_interleaved_single_gs_many_streams ext_interleaved_single_gs_many_streams.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_transform_feedback3/ext_interleaved_single_gs_many_streams.c b/tests/spec/arb_transform_feedback3/ext_interleaved_single_gs_many_streams.c
new file mode 100644
index 0000000..54bbb84
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/ext_interleaved_single_gs_many_streams.c
@@ -0,0 +1,346 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * 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"
+#include "xfb3_common.h"
+
+/**
+ * @file ext_interleaved_single_gs_many_streams.c 
+ *
+ * Record varyings using multiple vertex streams originating from the same
+ * geometry shader instance. The test uses the maximum amount of streams
+ * supported by the implementation. Each stream records an interleaved set of
+ * two attributes into its own transform feedback buffer - the spec does not
+ * allow one to record multiple streams into one single buffer:
+ *
+ * "All varyings assigned to a given binding point are required to come from a
+ *  single vertex stream."
+ *
+ * This test uses the "EXT"-style GLSL transform feedback.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 32;
+	config.supports_gl_core_version = 32;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static char *
+generate_geometry_shader(unsigned n_streams)
+{
+	unsigned i;
+	char *res;
+	char *curr;
+	static const char prologue[] =
+		"#version 150\n"
+		"#extension GL_ARB_gpu_shader5 : enable\n"
+		"layout(points) in;\n"
+		"layout(points, max_vertices = %u) out;\n";
+	static const char output_per_stream[] =
+		"layout(points, stream = %u) out;\n"
+		"out float x1_for_stream_%u_out;\n"
+		"out vec2 x2_for_stream_%u_out;\n";
+	static const char main_opening[] = "void main() {\n";
+	static const char vertex_emission_per_stream[] =
+		"  gl_Position = gl_in[0].gl_Position;\n"
+		"  x1_for_stream_%u_out = %u.0 + 1.0;\n"
+		"  x2_for_stream_%u_out = vec2(%u.0 + 2.0, %u.0 + 3.0);\n"
+		"  EmitStreamVertex(%u);\n";
+	static const char main_closing[] = "}\n";
+	const unsigned int_extra = formatted_int_extra_space(2 * n_streams);
+
+	curr = res = malloc(sizeof(prologue) + int_extra +
+			sizeof(main_opening) +
+			n_streams * (sizeof(vertex_emission_per_stream) +
+				     5 * int_extra +
+				     sizeof(output_per_stream) +
+				     3 * int_extra) +
+			sizeof(main_closing));
+
+	curr += sprintf(curr, prologue, n_streams);
+
+	for (i = 0; i < n_streams; ++i)
+		curr += sprintf(curr, output_per_stream, i, i, i);
+
+	curr += sprintf(curr, main_opening);
+
+	/**
+	 * Generate vertex emission for each stream explicitly. The argument
+	 * for 'EmitStreamVertex()' cannot be simply a loop variable. The spec
+	 * for GL_ARB_gpu_shader5 says:
+	 *
+	 *   "The argument <stream> must be a constant integral expression."
+	 */
+	for (i = 0; i < n_streams; ++i)
+		curr += sprintf(curr, vertex_emission_per_stream,
+				i, i, i, i, i, i);
+
+	curr += sprintf(curr, main_closing);
+
+	return res;
+}
+
+static void
+setup_varyings(GLuint prog, unsigned n_streams)
+{
+	/**
+	 * The spec for ARB_transform_feedback3 says:
+	 *
+	 * If a string in <varyings> is "gl_NextBuffer", it does not identify a
+	 * varying variable, but instead serves as a buffer separator value to 
+	 * direct subsequent varyings at the next transform feedback binding
+	 * point.
+	 */
+	static const char separator[] = "gl_NextBuffer";
+	static const char x1_template[] = "x1_for_stream_%u_out";
+	static const char x2_template[] = "x2_for_stream_%u_out";
+	const unsigned int_extra = formatted_int_extra_space(2 * n_streams);
+	/* Varyings for 'n' streams are separated by 'n - 1' separators.*/
+	const unsigned var_n = 2 * n_streams + n_streams - 1;
+	char *var_strings;
+	char *curr;
+	const char **var_array;
+	const char **curr_var;
+	unsigned i;
+
+	curr = var_strings = (char *)malloc(n_streams *
+					(sizeof(x1_template) + int_extra +
+					 sizeof(x2_template) + int_extra) +
+				     (n_streams - 1) * sizeof(separator));
+	curr_var = var_array = (const char**)malloc(var_n *
+						sizeof(const char *));
+
+	for (i = 0; i < n_streams; ++i) {
+		if (i != 0) {
+			*curr_var++ = curr;
+			curr += sprintf(curr, separator);
+			++curr; /* terminator */
+		}
+
+		*curr_var++ = curr;
+		curr += sprintf(curr, x1_template, i);
+		++curr; /* terminator */
+
+		*curr_var++ = curr;
+		curr += sprintf(curr, x2_template, i);
+		++curr; /* terminator */
+	}
+
+	/**
+	 * It should be noticed that when mixed mode is used, i.e., where
+	 * one records multiple attributes per buffer but also uses separate
+	 * buffers, the mode must be set to interleaved.
+	 */
+	glTransformFeedbackVaryings(prog, var_n, var_array,
+				GL_INTERLEAVED_ATTRIBS);
+
+	free(var_array);
+	free(var_strings);
+}
+
+static void
+build_and_use_program(unsigned max_streams)
+{
+	char *gs_text = generate_geometry_shader(max_streams);
+
+	GLuint prog = piglit_build_simple_program_multiple_shaders(
+				GL_VERTEX_SHADER, vs_pass_thru_text,
+				GL_GEOMETRY_SHADER, gs_text, 0);
+	free(gs_text);
+
+	/**
+	 * In the EXT-style the recorded varyings need to be set before linking.
+	 */
+	setup_varyings(prog, max_streams);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glLinkProgram(prog);
+	if (!piglit_link_check_status(prog))
+		piglit_report_result(PIGLIT_FAIL);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glUseProgram(prog);
+}
+
+static void
+probe_buffers(unsigned max_streams, GLuint *xfb, GLuint *generated_queries,
+	      GLuint *written_queries)
+{
+	unsigned i;
+	float expected[1 + 2];
+	int pass = 1;
+
+	/* Check the recordings against expectations */
+	for (i = 0; i < max_streams; ++i) {
+		char label[32];
+		GLuint query_result;
+
+		glGetQueryObjectuiv(generated_queries[i], GL_QUERY_RESULT,
+				&query_result);
+		if (query_result != 1) {
+			printf("Expected one primitive generated, got %u for "
+				"stream %u\n", query_result, i);
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		glGetQueryObjectuiv(written_queries[i], GL_QUERY_RESULT,
+				&query_result);
+		if (query_result != 1) {
+			printf("Expected one primitive written, got %u for "
+				"stream %u\n", query_result, i);
+			piglit_report_result(PIGLIT_FAIL);
+		}
+
+		sprintf(label, "stream[%u]", i);
+
+		expected[0] = i + 1; /* x1[0] */
+		expected[1] = i + 2; /* x2[0] */
+		expected[2] = i + 3; /* x2[1] */
+
+		pass = piglit_probe_buffer(xfb[i], GL_TRANSFORM_FEEDBACK_BUFFER,
+				label, 1, ARRAY_SIZE(expected), expected) &&
+				pass;
+	}
+
+	free(xfb);
+	free(generated_queries);
+	free(written_queries);
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+static void
+check_driver(GLint *max_streams, GLint *max_comps)
+{
+	piglit_require_GLSL_version(150);
+	piglit_require_extension("GL_ARB_transform_feedback3");
+	piglit_require_extension("GL_ARB_gpu_shader5");
+
+	glGetIntegerv(GL_MAX_VERTEX_STREAMS, max_streams);
+	if (!*max_streams) {
+		printf("Number of vertex streams supported is zero\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
+		max_comps);
+	if (!*max_comps) {
+		printf("Number of interleaved components is zero\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* Get the number of varyings - each consumes four components */
+	*max_comps /= 4;
+
+	if (2 * *max_streams > *max_comps) {
+		printf("Test uses two attributes/stream - only %u(%u streams) "
+			"attributes supported by the stack\n",
+			*max_comps, *max_streams);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+static void
+setup_tfb(unsigned n, GLuint **xfb, GLuint **generated_queries,
+	GLuint **written_queries)
+{
+	int i;
+
+	*xfb = malloc(n * sizeof(GLuint));
+	*generated_queries = malloc(n * sizeof(GLuint));
+	*written_queries = malloc(n * sizeof(GLuint));
+
+	/* Set up the transform feedback buffers and queries. */
+	glGenBuffers(n, *xfb);
+	glGenQueries(n, *generated_queries);
+	glGenQueries(n, *written_queries);
+	for (i = 0; i < n; ++i) {
+		glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, i, (*xfb)[i]);
+		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,
+			(1 + 2) * sizeof(float), NULL, GL_STREAM_READ);
+
+		glBeginQueryIndexed(GL_PRIMITIVES_GENERATED, i,
+			(*generated_queries)[i]);
+		glBeginQueryIndexed(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, i,
+			(*written_queries)[i]);
+	}
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		free(*xfb);
+		free(*generated_queries);
+		free(*written_queries);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	int i;
+	GLuint *xfb, *generated_queries, *written_queries;
+	GLint max_streams, max_comps;
+	GLuint vao;
+
+	check_driver(&max_streams, &max_comps);
+
+	build_and_use_program(max_streams);
+
+	setup_tfb(max_streams, &xfb, &generated_queries, &written_queries);
+
+	/* Test only records using transform feedback. */
+	glEnable(GL_RASTERIZER_DISCARD);
+
+	/* Test is run under desktop OpenGL 3.2 -> use of VAOs is required */
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	/* Draw and record */
+	glBeginTransformFeedback(GL_POINTS);
+	glDrawArrays(GL_POINTS, 0, 1);
+	glEndTransformFeedback();
+
+	for (i = 0; i < max_streams; ++i) {
+		glEndQueryIndexed(GL_PRIMITIVES_GENERATED, i);
+		glEndQueryIndexed(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, i);
+	}
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		free(xfb);
+		free(generated_queries);
+		free(written_queries);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	probe_buffers(max_streams, xfb, generated_queries, written_queries);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
+}
-- 
1.8.3.1



More information about the Piglit mailing list