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

Topi Pohjolainen topi.pohjolainen at intel.com
Mon Sep 16 07:54:45 PDT 2013


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       | 290 +++++++++++++++++++++
 3 files changed, 292 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 c1ee32e..68a15d7 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2260,6 +2260,7 @@ arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_two_bufs_vs'] =
 arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_two_bufs_gs'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_two_bufs', '-auto', 'gs'])
 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 e962325..cbcc65a 100644
--- a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
+++ b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
@@ -10,5 +10,6 @@ link_libraries (
 
 piglit_add_executable (arb_transform_feedback3-ext_interleaved_two_bufs ext_interleaved_two_bufs.c)
 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..bae0dc5
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/ext_interleaved_single_gs_many_streams.c
@@ -0,0 +1,290 @@
+/*
+ * 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 = 10;
+
+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_EXT);
+
+	free(var_array);
+	free(var_strings);
+}
+
+/* TODO: use piglit utilities */
+static void
+build_and_use_program(unsigned max_streams)
+{
+	GLuint vs, gs, prog;
+	char *gs_text = generate_geometry_shader(max_streams);
+
+	prog = glCreateProgram();
+        vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_pass_thru_text);
+        glAttachShader(prog, vs);
+	
+        gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_text);
+        glAttachShader(prog, gs);
+
+	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);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	int i;
+	int pass = 1;
+	GLuint *xfb;
+	GLint max_streams, max_comps;
+	float expected[1 + 2];
+
+	piglit_require_GLSL_version(150);
+	piglit_require_extension("GL_ARB_geometry_shader4");
+	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);
+	}
+
+	build_and_use_program(max_streams);
+
+	xfb = malloc(max_streams * sizeof(GLuint));
+
+        /* Set up the transform feedback buffers. */
+        glGenBuffers(max_streams, xfb);
+	for (i = 0; i < max_streams; ++i) {
+        	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, i, xfb[i]);
+		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, sizeof(expected),
+			NULL, GL_STREAM_READ);
+	}
+
+        /* Use GL_RASTERIZER_DISCARD, since we are going to use
+	 * transform feedback for this test.
+	 */
+        glEnable(GL_RASTERIZER_DISCARD);
+
+        if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		free(xfb);
+                piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* Draw and record */
+	glBeginTransformFeedback(GL_POINTS);
+	glDrawArrays(GL_POINTS, 0, 1);
+	glEndTransformFeedback();
+
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		free(xfb);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* Check the recordings against expectations */
+	for (i = 0; i < max_streams; ++i) {
+		char label[32];
+
+		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_EXT, label, 1,
+				ARRAY_SIZE(expected), expected) &&
+				pass;
+	}
+
+	free(xfb);
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
+}
-- 
1.8.3.1



More information about the Piglit mailing list