[Piglit] [WIP 3/4] tests/spec: ARB_transform_feedback3 interleaved in separate buffers

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


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/all.tests                                    |   2 +
 .../spec/arb_transform_feedback3/CMakeLists.gl.txt |   1 +
 .../ext_interleaved_single_stream_many_buffers.c   | 334 +++++++++++++++++++++
 tests/spec/arb_transform_feedback3/xfb3_common.h   |  48 +++
 4 files changed, 385 insertions(+)
 create mode 100644 tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
 create mode 100644 tests/spec/arb_transform_feedback3/xfb3_common.h

diff --git a/tests/all.tests b/tests/all.tests
index bdebd17..c1ee32e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2258,6 +2258,8 @@ for param in ['gl_NextBuffer-1', 'gl_NextBuffer-2', 'gl_SkipComponents1-1',
 
 arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_two_bufs_vs'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_two_bufs', '-auto', '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_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 614ccd6..e962325 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_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)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c b/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
new file mode 100644
index 0000000..25dbddb
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/ext_interleaved_single_stream_many_buffers.c
@@ -0,0 +1,334 @@
+/*
+ * 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_stream_many_buffers.c 
+ *
+ * Records interleaved varyings using single vertex stream into separate
+ * buffers. The test tries to use as many buffers the tested GL-stack can
+ * support trying to ouput the maximum amount of supported varyings evenly
+ * between the buffers.
+ * The test can be executed in two different ways: the stream originating from
+ * vertex shader or from single geometry shader instance.
+ *
+ * Recording both vertex shader and geometry shader outputs in parallel is not
+ * supported by the extension. The spec says:
+ *
+ * "When a geometry shader is active (see section 2.12), transform feedback
+ *  records the values of the selected geometry shader output variables from the
+ *  emitted vertices. Otherwise, the values of the selected vertex shader output
+ *  variables are recorded."
+ * 
+ * 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_shader(const char *prologue, unsigned prologue_len,
+		const char *epilogue, unsigned epilogue_len,
+		unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	unsigned i;
+	char *res;
+	char *curr;
+	static const char output_decl[] = "out float x%u_out;\n";
+	static const char output_assign[] = "  x%u_out = %u.0;\n";
+	static const char main_opening[] = "void main() {\n";
+	const unsigned int_extra = formatted_int_extra_space(
+						n_bufs * n_vars_per_buf);
+
+	curr = res = malloc(prologue_len + sizeof(main_opening) +
+			n_bufs * n_vars_per_buf *
+				(sizeof(output_decl) + int_extra +
+				 sizeof(output_assign) + 2 * int_extra) +
+			epilogue_len);
+
+	curr += snprintf(curr, prologue_len, prologue);
+
+	for (i = 0; i < n_bufs * n_vars_per_buf; ++i)
+		curr += sprintf(curr, output_decl, i);
+
+	curr += sprintf(curr, main_opening);
+
+	for (i = 0; i < n_bufs * n_vars_per_buf; ++i)
+		curr += sprintf(curr, output_assign, i, i);
+
+	curr += snprintf(curr, epilogue_len, epilogue);
+
+	return res;
+}
+
+static char *
+generate_geometry_shader(unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	static const char prologue[] =
+		"#version 150\n"
+		"#extension GL_ARB_gpu_shader5 : enable\n"
+		"layout(points) in;\n"
+		"layout(points, max_vertices = 1) out;\n";
+	static const char epilogue[] = "  EmitVertex();\n}\n";
+
+	return generate_shader(prologue, sizeof(prologue),
+			epilogue, sizeof(epilogue), n_bufs, n_vars_per_buf);
+}
+
+static char *
+generate_vertex_shader(unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	static const char prologue[] = "#version 150\n";
+	static const char epilogue[] = "  }\n";
+
+	return generate_shader(prologue, sizeof(prologue),
+			epilogue, sizeof(epilogue), n_bufs, n_vars_per_buf);
+}
+
+static void
+setup_varyings(GLuint prog, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	/**
+	 * 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 var_template[] = "x%u_out";
+	const unsigned int_extra = formatted_int_extra_space(
+						n_bufs * n_vars_per_buf);
+	/* Every 'n' buffers are separated by 'n - 1' separator strings */
+	const unsigned var_n = n_bufs * n_vars_per_buf + n_bufs - 1;
+	char *var_strings;
+	const char **var_array;
+	const char **curr_var;
+	unsigned i, j, pos;
+
+	var_strings = (char *)malloc(n_bufs * n_vars_per_buf *
+				(sizeof(var_template) + int_extra) +
+				(n_bufs - 1) * sizeof(separator));
+	var_array = (const char**)malloc(var_n * sizeof(const char *));
+
+	for (i = 0, pos = 0, curr_var = var_array; i < n_bufs; ++i) {
+		if (i != 0) {
+			*curr_var++ = var_strings + pos;
+			pos += sprintf(var_strings + pos, separator);
+			++pos; /* terminator */
+		}
+
+		for (j = 0; j < n_vars_per_buf; ++j) {
+			*curr_var++ = var_strings + pos;
+			pos += sprintf(var_strings + pos, var_template,
+					i * n_vars_per_buf + j);
+			++pos; /* 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_strings);
+	free(var_array);
+}
+
+/* TODO: use piglit utilities */
+static void
+build_and_use_program(bool use_gs, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	GLuint vs, gs, prog;
+	const char *gs_text, *vs_text;
+
+	if (use_gs) {
+		gs_text = generate_geometry_shader(n_bufs, n_vars_per_buf);
+		vs_text = vs_pass_thru_text;
+	} else {
+		gs_text = NULL;
+		vs_text = generate_vertex_shader(n_bufs, n_vars_per_buf);
+	}
+
+	prog = glCreateProgram();
+        vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+        glAttachShader(prog, vs);
+
+	if (vs_text != vs_pass_thru_text)
+		free((void *)vs_text);
+	
+	if (gs_text) {
+		gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_text);
+		glAttachShader(prog, gs);
+		free((void *)gs_text);
+	}
+
+	/**
+	 * In the EXT-style the recorded varyings need to be set before
+	 * linking.
+	 */
+	setup_varyings(prog, n_bufs, n_vars_per_buf);
+
+	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 int
+probe_buffers(GLuint *xfb, unsigned n_bufs, unsigned n_vars_per_buf)
+{
+	int i, j;
+	int pass = 1;
+	float *expected = malloc(n_vars_per_buf * sizeof(float));
+
+	for (i = 0; i < n_bufs; ++i) {
+		char label[32];
+
+		sprintf(label, "buf[%u]", i);
+
+		for (j = 0; j < n_vars_per_buf; ++j)
+			expected[j] = (i * n_vars_per_buf) + j;
+
+		pass = piglit_probe_buffer(xfb[i],
+				GL_TRANSFORM_FEEDBACK_BUFFER_EXT, label, 1,
+				n_vars_per_buf, expected) && pass;
+	}
+
+	free(expected);
+
+	return pass;
+}
+
+static void
+print_usage_and_exit(const char *prog_name)
+{
+	printf("Usage: %s <subtest>\n"
+	       "  where <subtest> is one of the following:\n"
+	       "    gs\n"
+	       "    vs\n", prog_name);
+	piglit_report_result(PIGLIT_FAIL);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	int pass, i;
+	bool use_gs;
+	GLuint *xfb;
+	GLint max_bufs, max_xfb_comps, max_comps;
+
+	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");
+
+	if (argc != 2)
+		print_usage_and_exit(argv[0]);
+	if (strcmp(argv[1], "vs") == 0)
+                use_gs = false;
+        else if (strcmp(argv[1], "gs") == 0)
+                use_gs = true;
+        else
+                print_usage_and_exit(argv[0]);
+
+	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_bufs);
+	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
+		&max_xfb_comps);
+	glGetIntegerv(GL_MAX_VARYING_COMPONENTS, &max_comps);
+
+	if (!max_bufs || !max_comps) {
+		printf("Maximum amount of buffers and components need to be"
+			"positive (%u:%u).\n", max_bufs, max_xfb_comps);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* Get the number of varyings - each consumes four components */
+	max_xfb_comps /= 4;
+
+	if (max_bufs > max_xfb_comps) {
+		printf("Maximum amount of buffers exceeds maximum amount of "
+			"varyings (%u:%u).\n", max_bufs, max_xfb_comps);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	build_and_use_program(use_gs, max_bufs, max_xfb_comps / max_bufs);
+
+	xfb = malloc(max_bufs * sizeof(GLuint));
+
+        /* Set up the transform feedback buffers. */
+        glGenBuffers(max_bufs, xfb);
+	for (i = 0; i < max_bufs; ++i) {
+        	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, i, xfb[i]);
+		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
+			(max_xfb_comps / max_bufs) * sizeof(float), 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);
+	}
+
+	pass = probe_buffers(xfb, max_bufs, max_xfb_comps / max_bufs);
+	free(xfb);
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
+}
diff --git a/tests/spec/arb_transform_feedback3/xfb3_common.h b/tests/spec/arb_transform_feedback3/xfb3_common.h
new file mode 100644
index 0000000..4065590
--- /dev/null
+++ b/tests/spec/arb_transform_feedback3/xfb3_common.h
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+#ifndef XFB3_COMMON_H
+#define XFB3_COMMON_H
+
+#include <math.h>
+
+static const char vs_pass_thru_text[] =
+	"#version 150\n"
+	"void main() {\n"
+	"  gl_Position = vec4(0.0);\n"
+	"}\n";
+
+/**
+ * Resolve how many characters are needed to format string representation for
+ * integer value "n_vars". All format specifiers in the test cases are the same
+ * ,"%u", resulting in two characters (strlen("%u")) per value being reserved
+ * when the space for the formatted string is determined.
+ */
+static unsigned
+formatted_int_extra_space(unsigned n_vars)
+{
+	unsigned total = (unsigned)ceil(log10(n_vars));
+
+	return total > 2 ? total - 2 : 0;
+}
+
+#endif /* XFB3_COMMON_H */
-- 
1.8.3.1



More information about the Piglit mailing list