[Mesa-dev] [PATCH] glx-multi-context-ib-1: New test for a regression in the i965 driver.

Eric Anholt eric at anholt.net
Fri Jul 22 11:15:15 PDT 2011


---
 tests/all.tests                    |    1 +
 tests/glx/CMakeLists.gl.txt        |    1 +
 tests/glx/glx-multi-context-ib-1.c |  206 ++++++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+), 0 deletions(-)
 create mode 100644 tests/glx/glx-multi-context-ib-1.c

diff --git a/tests/all.tests b/tests/all.tests
index fcee3e2..0168ae9 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -533,6 +533,7 @@ glx['glx-fbconfig-sanity'].runConcurrent = True
 add_plain_test(glx, 'glx-fbconfig-compliance')
 glx['glx-fbconfig-compliance'].runConcurrent = True
 add_plain_test(glx, 'glx-fbo-binding')
+add_plain_test(glx, 'glx-multi-context-ib-1')
 add_plain_test(glx, 'glx-multithread')
 add_plain_test(glx, 'glx-multithread-makecurrent-1')
 add_plain_test(glx, 'glx-multithread-makecurrent-2')
diff --git a/tests/glx/CMakeLists.gl.txt b/tests/glx/CMakeLists.gl.txt
index 16a178a..4560ef0 100644
--- a/tests/glx/CMakeLists.gl.txt
+++ b/tests/glx/CMakeLists.gl.txt
@@ -22,6 +22,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	add_executable (glx-close-display glx-close-display.c)
 	add_executable (glx-destroycontext-1 glx-destroycontext-1.c)
 	add_executable (glx-destroycontext-2 glx-destroycontext-2.c)
+	add_executable (glx-multi-context-ib-1 glx-multi-context-ib-1.c)
 	add_executable (glx-multithread glx-multithread.c)
 	target_link_libraries(glx-multithread pthread)
 	add_executable (glx-multithread-makecurrent-1 glx-multithread-makecurrent-1.c)
diff --git a/tests/glx/glx-multi-context-ib-1.c b/tests/glx/glx-multi-context-ib-1.c
new file mode 100644
index 0000000..6161145
--- /dev/null
+++ b/tests/glx/glx-multi-context-ib-1.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright © 2009-2011 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 glx-multi-context-ib.c
+ *
+ * Tests that multiple contexts drawing using index buffers work correctly.
+ *
+ * Catches a bug in the i965 driver in which index buffer state was
+ * not reemitted across batchbuffer boundaries, if the first draw
+ * after the batch didn't use the IB.
+ */
+
+#include <unistd.h>
+#include "piglit-util.h"
+#include "piglit-glx-util.h"
+#include "pthread.h"
+
+int piglit_width = 50, piglit_height = 50;
+static Display *dpy;
+static Window win;
+static GLXContext ctx0, ctx1;
+
+GLuint vb_c0, vb_c1, ib_c0, ib_c1;
+static float green[] = {0, 1, 0, 0};
+static float red[]   = {1, 0, 0, 0};
+
+/* c0 sets up an IB that will mess up c1's drawing, by only indexing
+ * outside of c0's VBO.
+ */
+static void
+context0_init()
+{
+	float vb_data[] = {
+		0, 0,
+		0, 0,
+		0, 0,
+		0, 0,
+		-1, -1,
+		 1, -1,
+		 1,  1,
+		-1,  1,
+	};
+	uint32_t ib_data[] = {
+		4, 5, 6, 7,
+	};
+
+	glGenBuffersARB(1, &vb_c0);
+	glGenBuffersARB(1, &ib_c0);
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb_c0);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib_c0);
+
+	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vb_data), vb_data,
+			GL_STATIC_DRAW);
+	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(ib_data), ib_data,
+			GL_STATIC_DRAW);
+}
+
+static void
+context1_init()
+{
+	float vb_data[] = {
+		-1, -1,
+		 1, -1,
+		 1,  1,
+		-1,  1,
+	};
+	uint32_t ib_data[] = {
+		0, 1, 2, 3,
+	};
+
+	glGenBuffersARB(1, &vb_c1);
+	glGenBuffersARB(1, &ib_c1);
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb_c1);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib_c1);
+
+	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vb_data), vb_data,
+			GL_STATIC_DRAW);
+	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(ib_data), ib_data,
+			GL_STATIC_DRAW);
+}
+
+static void
+context0_frame(void)
+{
+	glXMakeCurrent(dpy, win, ctx0);
+
+	glColor4fv(red);
+
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb_c0);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib_c0);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(2, GL_FLOAT, 0, (void *)0);
+
+	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, (void *)0);
+}
+
+static void
+context1_frame(int iter)
+{
+	glXMakeCurrent(dpy, win, ctx1);
+
+	/* This is the drawing without an IB that triggered the driver
+	 * not reemitting IB state in the next draw call.
+	 *
+	 * The other context just exists to ensure that the race for
+	 * the IB getting smashed is lost, and is also the thing that
+	 * produces the glFlush()-based batchbuffer emits we rely on.
+	 */
+	glColor4fv(red);
+	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+	/* Failing draw call. */
+	if (iter == 1)
+		glColor4fv(green);
+	else
+		glColor4fv(red);
+
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vb_c0);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib_c0);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(2, GL_FLOAT, 0, (void *)0);
+
+	glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_INT, (void *)0);
+}
+
+enum piglit_result
+draw(Display *dpy)
+{
+	bool pass;
+
+	context0_frame();
+	context1_frame(0);
+	/* The issue was that on the second frame, failure occurred. */
+	context0_frame();
+	context1_frame(1);
+
+	pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green);
+
+	glXSwapBuffers(dpy, win);
+
+	glXMakeCurrent(dpy, None, None);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+int
+main(int argc, char **argv)
+{
+	XVisualInfo *visinfo;
+	int i;
+
+	for(i = 1; i < argc; ++i) {
+		if (!strcmp(argv[i], "-auto"))
+			piglit_automatic = 1;
+		else
+			fprintf(stderr, "Unknown option: %s\n", argv[i]);
+	}
+
+	dpy = XOpenDisplay(NULL);
+	if (dpy == NULL) {
+		fprintf(stderr, "couldn't open display\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+	visinfo = piglit_get_glx_visual(dpy);
+	win = piglit_get_glx_window(dpy, visinfo);
+
+	XMapWindow(dpy, win);
+
+	ctx0 = piglit_get_glx_context(dpy, visinfo);
+	ctx1 = piglit_get_glx_context(dpy, visinfo);
+
+	glXMakeCurrent(dpy, win, ctx0);
+	glewInit();
+	piglit_require_extension("GL_ARB_vertex_buffer_object");
+	context0_init();
+	glXMakeCurrent(dpy, win, ctx1);
+	context1_init();
+
+	piglit_glx_event_loop(dpy, draw);
+
+	XFree(visinfo);
+	glXDestroyContext(dpy, ctx0);
+	glXDestroyContext(dpy, ctx1);
+
+	return 0;
+}
-- 
1.7.5.4



More information about the mesa-dev mailing list