[Piglit] [PATCH] vbo-map-unsync: test unsynchronized buffer mapping

Brian Paul brianp at vmware.com
Thu Nov 8 07:04:39 PST 2012


---
 tests/all.tests                 |    1 +
 tests/general/CMakeLists.gl.txt |    1 +
 tests/general/vbo-map-unsync.c  |  173 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+), 0 deletions(-)
 create mode 100644 tests/general/vbo-map-unsync.c

diff --git a/tests/all.tests b/tests/all.tests
index 09b0931..9db1038 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1245,6 +1245,7 @@ add_plain_test(arb_vertex_buffer_object, 'fdo31934')
 add_plain_test(arb_vertex_buffer_object, 'pos-array')
 add_plain_test(arb_vertex_buffer_object, 'vbo-bufferdata')
 add_plain_test(arb_vertex_buffer_object, 'vbo-map-remap')
+add_plain_test(arb_vertex_buffer_object, 'vbo-map-unsync')
 add_plain_test(arb_vertex_buffer_object, 'vbo-subdata-sync')
 add_plain_test(arb_vertex_buffer_object, 'vbo-subdata-zero')
 
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index 171b3f1..a9c2193 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -124,6 +124,7 @@ piglit_add_executable (vao-01 vao-01.c)
 piglit_add_executable (vao-02 vao-02.c)
 piglit_add_executable (vao-element-array-buffer vao-element-array-buffer.c)
 piglit_add_executable (vbo-map-remap vbo-map-remap.c)
+piglit_add_executable (vbo-map-unsync vbo-map-unsync.c)
 piglit_add_executable (vbo-bufferdata vbo-bufferdata.c)
 piglit_add_executable (vbo-subdata-zero vbo-subdata-zero.c)
 piglit_add_executable (vbo-subdata-sync vbo-subdata-sync.c)
diff --git a/tests/general/vbo-map-unsync.c b/tests/general/vbo-map-unsync.c
new file mode 100644
index 0000000..92dfe85
--- /dev/null
+++ b/tests/general/vbo-map-unsync.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright © 2012 VMware, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * Test mapping VBOs with GL_MAP_UNSYNCHRONIZED_BIT.
+ * This could cause a driver crash if there's a bug in the driver.
+ *
+ * Based on a test program by Keith Whitwell, modified by Thomas Hellstrom.
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const struct {
+	GLfloat pos[3];
+	GLubyte color[4];
+} verts[] =  
+{
+	{
+		{  1.0, -1.0, 0.0 },
+		{ 0x00, 0x00, 0xff, 0x00 } 
+	},
+
+	{
+		{  1.0,  1.0, 0.0 },
+		{ 0x00, 0xff, 0x00, 0x00 }
+	},
+
+	{
+		{ -1.0,  1.0, 0.0 },
+		{ 0xff, 0x00, 0x00, 0x00 } 
+	},
+
+	{
+		{ -1.0, -1.0, 0.0 },
+		{ 0xff, 0xff, 0xff, 0x00 }
+	},
+};
+
+static const GLuint indices[] = { 0, 1, 2, 3 };
+static const GLuint indices2[] = { 0, 2, 3 };
+
+static GLuint arrayObj, elementObj;
+
+static const float red[4] = {1, 0, 0, 0};
+static const float green[4] = {0, 1, 0, 0};
+static const float blue[4] = {0, 0, 1, 0};
+static const float white[4] = {1, 1, 1, 0};
+
+
+void
+piglit_init(int arg, char *argv[])
+{
+	glGenBuffersARB(1, &arrayObj);
+	glGenBuffersARB(1, &elementObj);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	int vstride = sizeof(verts[0]);
+	int voffset1 = 0;
+	int voffset2 = sizeof(verts);
+	int coffset1 = 3 * sizeof(float);
+	int coffset2 = voffset2 + coffset1;
+	bool pass = true;
+	void *verts_map;
+	void *elems_map;
+
+	glViewport(0, 0, piglit_width, piglit_height);
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(-1.0, 1.0, -1.0, 1.0, -0.1, 1.0);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_COLOR_ARRAY);
+
+	/* Create empty vertex, index buffers.  The vertex buffer is large
+	 * enough to store two of the vertex arrays defined above.
+	 */
+	glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
+	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, elementObj);
+	glBufferDataARB(GL_ARRAY_BUFFER_ARB, 2 * sizeof(verts),
+			NULL, GL_STATIC_DRAW_ARB);
+	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(indices),
+			NULL, GL_STATIC_DRAW_ARB);
+
+	/* Map first half of vertex buffer */
+	verts_map = glMapBufferRange(GL_ARRAY_BUFFER_ARB,
+				     0, sizeof(verts), 
+				     GL_MAP_WRITE_BIT |
+				     GL_MAP_INVALIDATE_BUFFER_BIT |
+				     GL_MAP_FLUSH_EXPLICIT_BIT);
+	elems_map = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+				   GL_WRITE_ONLY_ARB);
+
+	memcpy(verts_map, verts, sizeof(verts));
+	memcpy(elems_map, indices, sizeof(indices));
+	glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
+	glFlushMappedBufferRange(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts));
+	glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+
+	/* Draw first triangle: upper-right half of window */
+	glVertexPointer(3, GL_FLOAT, vstride, (void *) voffset1);
+	glColorPointer(4, GL_UNSIGNED_BYTE, vstride, (void *) coffset1);
+
+	glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, NULL);
+
+
+	/* Map second half of vertex buffer */
+	verts_map = glMapBufferRange(GL_ARRAY_BUFFER_ARB,
+				     sizeof(verts), sizeof(verts), 
+				     GL_MAP_WRITE_BIT |
+				     GL_MAP_INVALIDATE_RANGE_BIT |
+				     GL_MAP_UNSYNCHRONIZED_BIT |
+				     GL_MAP_FLUSH_EXPLICIT_BIT);
+	elems_map = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
+				   GL_WRITE_ONLY_ARB);
+	memcpy(verts_map, verts, sizeof(verts));
+	memcpy(elems_map, indices2, sizeof(indices2));
+	glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
+	glFlushMappedBufferRange(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts));
+	glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
+	
+	/* Draw second triangle: lower-left half of window */
+	glVertexPointer(3, GL_FLOAT, vstride, (void *) voffset2);
+	glColorPointer(4, GL_UNSIGNED_BYTE, vstride, (void *) coffset2);
+
+	glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, NULL);
+
+	/* check corner colors */
+	pass = piglit_probe_pixel_rgb(0, 0, white) && pass;
+	pass = piglit_probe_pixel_rgb(piglit_width-1, 0, blue) && pass;
+	pass = piglit_probe_pixel_rgb(piglit_width-1, piglit_height-1,
+				      green) && pass;
+	pass = piglit_probe_pixel_rgb(0, piglit_height-1, red) && pass;
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.7.3.4



More information about the Piglit mailing list