[Piglit] [PATCH 2/2] Transform feedback: Test reading back buffer binding state.

Paul Berry stereotype441 at gmail.com
Tue Jan 3 13:27:49 PST 2012


This test verifies that the GL "Get" functions can be used to read
back the state of transform feedback buffers (binding points, buffer
start, and buffer size), and that the state updates properly when
buffers are bound.
---
 tests/all.tests                                    |    4 +
 .../spec/ext_transform_feedback/CMakeLists.gl.txt  |    1 +
 .../spec/ext_transform_feedback/get-buffer-state.c |  206 ++++++++++++++++++++
 3 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/ext_transform_feedback/get-buffer-state.c

diff --git a/tests/all.tests b/tests/all.tests
index 0290f4c..9ad78fa 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1422,6 +1422,10 @@ ext_transform_feedback['discard-clear'] = concurrent_test('ext_transform_feedbac
 ext_transform_feedback['discard-copypixels'] = concurrent_test('ext_transform_feedback-discard-copypixels')
 ext_transform_feedback['discard-drawarrays'] = concurrent_test('ext_transform_feedback-discard-drawarrays')
 ext_transform_feedback['discard-drawpixels'] = concurrent_test('ext_transform_feedback-discard-drawpixels')
+for mode in ['main_binding', 'indexed_binding', 'buffer_start', 'buffer_size']:
+        test_name = 'get-buffer-state {0}'.format(mode)
+        ext_transform_feedback[test_name] = PlainExecTest(
+                'ext_transform_feedback-{0} -auto'.format(test_name))
 ext_transform_feedback['immediate-reuse'] = concurrent_test('ext_transform_feedback-immediate-reuse')
 for mode in ['output', 'prims_generated', 'prims_written']:
         test_name = 'intervening-read {0}'.format(mode)
diff --git a/tests/spec/ext_transform_feedback/CMakeLists.gl.txt b/tests/spec/ext_transform_feedback/CMakeLists.gl.txt
index 305f589..a4fa307 100644
--- a/tests/spec/ext_transform_feedback/CMakeLists.gl.txt
+++ b/tests/spec/ext_transform_feedback/CMakeLists.gl.txt
@@ -22,6 +22,7 @@ add_executable (ext_transform_feedback-discard-copypixels discard-copypixels.c)
 add_executable (ext_transform_feedback-discard-drawarrays discard-drawarrays.c)
 add_executable (ext_transform_feedback-discard-drawpixels discard-drawpixels.c)
 add_executable (ext_transform_feedback-generatemipmap generatemipmap.c)
+add_executable (ext_transform_feedback-get-buffer-state get-buffer-state.c)
 add_executable (ext_transform_feedback-position position.c)
 add_executable (ext_transform_feedback-immediate-reuse immediate-reuse.c)
 add_executable (ext_transform_feedback-interleaved interleaved.c)
diff --git a/tests/spec/ext_transform_feedback/get-buffer-state.c b/tests/spec/ext_transform_feedback/get-buffer-state.c
new file mode 100644
index 0000000..bfa1985
--- /dev/null
+++ b/tests/spec/ext_transform_feedback/get-buffer-state.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+/**
+ * \file get-buffer-state.c
+ *
+ * Test that "Get" functions can be used to query the state of
+ * transform feedback buffers.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 16;
+int piglit_height = 16;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
+
+#define XFB_BUFFER_SIZE 12
+
+enum test_mode {
+	MAIN,
+	INDEXED,
+};
+
+static struct test_desc
+{
+	const char *name;
+	enum test_mode mode;
+	GLenum param;
+} tests[] = {
+	/* name              mode     param */
+	{ "main_binding",    MAIN,    GL_TRANSFORM_FEEDBACK_BUFFER_BINDING },
+	{ "indexed_binding", INDEXED, GL_TRANSFORM_FEEDBACK_BUFFER_BINDING },
+	{ "buffer_start",    INDEXED, GL_TRANSFORM_FEEDBACK_BUFFER_START },
+	{ "buffer_size",     INDEXED, GL_TRANSFORM_FEEDBACK_BUFFER_SIZE },
+};
+
+static GLboolean
+check_integer(const struct test_desc *test, GLenum param,
+	      const char *param_string, GLint expected)
+{
+	GLint get_result;
+
+	if (test->mode == MAIN && test->param == param) {
+		glGetIntegerv(param, &get_result);
+		if (get_result != expected) {
+			printf("%s == %i, expected %i\n", param_string,
+			       get_result, expected);
+			return GL_FALSE;
+		}
+	}
+	return GL_TRUE;
+}
+
+#define CHECK_INTEGER(param, expected) \
+	pass = check_integer(test, param, #param, expected) && pass
+
+static GLboolean
+check_indexed(const struct test_desc *test, GLenum param,
+	      const char *param_string, GLuint index, GLint expected)
+{
+	GLint get_result;
+
+	if (test->mode == INDEXED && test->param == param) {
+		piglit_GetIntegeri_v(param, index, &get_result);
+		if (get_result != expected) {
+			printf("%s[%u] == %i, expected %i\n", param_string,
+			       index, get_result, expected);
+			return GL_FALSE;
+		}
+	}
+	return GL_TRUE;
+}
+
+#define CHECK_INDEXED(param, index, expected) \
+	pass = check_indexed(test, param, #param, index, expected) && pass
+
+static GLboolean
+do_test(const struct test_desc *test)
+{
+	GLuint *bufs;
+	GLboolean pass = GL_TRUE;
+	GLint max_separate_attribs;
+	float initial_xfb_buffer_contents[XFB_BUFFER_SIZE];
+	int i;
+
+	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
+		      &max_separate_attribs);
+	printf("MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTIBS=%i\n",
+	       max_separate_attribs);
+
+	bufs = malloc(max_separate_attribs * sizeof(GLuint));
+	glGenBuffers(max_separate_attribs, bufs);
+	memset(initial_xfb_buffer_contents, 0,
+	       sizeof(initial_xfb_buffer_contents));
+
+	/* Main GL_TRANSFORM_FEEDBACK_BUFFER_BINDING should still be
+	 * set to its default value.
+	 */
+	CHECK_INTEGER(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, 0);
+
+	/* Set up buffers. */
+	for (i = 0; i < max_separate_attribs; ++i) {
+		printf("BindBuffer(TRANSFORM_FEEDBACK_BUFFER, %u)\n", bufs[i]);
+		glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, bufs[i]);
+		CHECK_INTEGER(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, bufs[i]);
+		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,
+			     sizeof(initial_xfb_buffer_contents),
+			     initial_xfb_buffer_contents, GL_STREAM_READ);
+	}
+
+	/* Indexed bindings should still be set to their default values. */
+	for (i = 0; i < max_separate_attribs; ++i) {
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i, 0);
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_START, i, 0);
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i, 0);
+	}
+
+	/* Bind buffers, setting various offsets and sizes. */
+	for (i = 0; i < max_separate_attribs; ++i) {
+		int offset = 4 * (i % 4);
+		int size = 4 * ((i % 3) + 1);
+		printf("BindBufferRange(TRANSFORM_FEEDBACK_BUFFER, %i, %u, %i, %i)\n",
+		       i, bufs[i], offset, size);
+		piglit_BindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i,
+				       bufs[i], offset, size);
+		CHECK_INTEGER(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, bufs[i]);
+	}
+
+	/* Check indexed bindings. */
+	for (i = 0; i < max_separate_attribs; ++i) {
+		int offset = 4 * (i % 4);
+		int size = 4 * ((i % 3) + 1);
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, i, bufs[i]);
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_START, i, offset);
+		CHECK_INDEXED(GL_TRANSFORM_FEEDBACK_BUFFER_SIZE, i, size);
+	}
+
+	return pass;
+}
+
+void
+print_usage_and_exit(const char *prog_name)
+{
+	int i;
+
+	printf("Usage: %s <test_name>\n"
+	       "  where <test_name> is one of:\n", prog_name);
+	for (i = 0; i < ARRAY_SIZE(tests); ++i)
+		printf("    %s\n", tests[i].name);
+	exit(0);
+}
+
+const struct test_desc *
+find_matching_test(const char *prog_name, const char *test_name)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(tests); ++i) {
+		if (strcmp(tests[i].name, test_name) == 0)
+			return &tests[i];
+	}
+	print_usage_and_exit(prog_name);
+	return NULL; /* won't actually be reached */
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	const struct test_desc *test;
+
+	/* Parse params. */
+	if (argc != 2)
+		print_usage_and_exit(argv[0]);
+	test = find_matching_test(argv[0], argv[1]);
+
+	piglit_require_GLSL();
+	piglit_require_transform_feedback();
+
+	piglit_report_result(do_test(test) ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
+}
-- 
1.7.6.5



More information about the Piglit mailing list