[Piglit] [PATCH] invalidate: test GL_MAP_INVALIDATE_* flags between draw calls in a loop
Marek Olšák
maraeo at gmail.com
Thu Nov 22 16:17:24 PST 2012
---
tests/all.tests | 6 +
tests/spec/arb_map_buffer_range/CMakeLists.gl.txt | 1 +
tests/spec/arb_map_buffer_range/invalidate.c | 206 +++++++++++++++++++++
3 files changed, 213 insertions(+)
create mode 100644 tests/spec/arb_map_buffer_range/invalidate.c
diff --git a/tests/all.tests b/tests/all.tests
index 4a5c35e..ec4d980 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1997,6 +1997,12 @@ arb_map_buffer_range = Group()
spec['ARB_map_buffer_range'] = arb_map_buffer_range
add_plain_test(arb_map_buffer_range, 'map_buffer_range_error_check')
add_plain_test(arb_map_buffer_range, 'map_buffer_range_test')
+arb_map_buffer_range['MAP_INVALIDATE_RANGE_BIT offset=0'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_RANGE_BIT offset=0')
+arb_map_buffer_range['MAP_INVALIDATE_RANGE_BIT increment-offset'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_RANGE_BIT increment-offset')
+arb_map_buffer_range['MAP_INVALIDATE_RANGE_BIT decrement-offset'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_RANGE_BIT decrement-offset')
+arb_map_buffer_range['MAP_INVALIDATE_BUFFER_BIT offset=0'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_BUFFER_BIT offset=0')
+arb_map_buffer_range['MAP_INVALIDATE_BUFFER_BIT increment-offset'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_BUFFER_BIT increment-offset')
+arb_map_buffer_range['MAP_INVALIDATE_BUFFER_BIT decrement-offset'] = concurrent_test('map_buffer_range-invalidate MAP_INVALIDATE_BUFFER_BIT decrement-offset')
arb_multisample = Group()
spec['ARB_multisample'] = arb_multisample
diff --git a/tests/spec/arb_map_buffer_range/CMakeLists.gl.txt b/tests/spec/arb_map_buffer_range/CMakeLists.gl.txt
index 4c61018..df8570e 100644
--- a/tests/spec/arb_map_buffer_range/CMakeLists.gl.txt
+++ b/tests/spec/arb_map_buffer_range/CMakeLists.gl.txt
@@ -11,5 +11,6 @@ link_libraries (
piglit_add_executable (map_buffer_range_error_check map_buffer_range_error_check.c)
piglit_add_executable (map_buffer_range_test map_buffer_range_test.c)
+piglit_add_executable (map_buffer_range-invalidate invalidate.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_map_buffer_range/invalidate.c b/tests/spec/arb_map_buffer_range/invalidate.c
new file mode 100644
index 0000000..84230c2
--- /dev/null
+++ b/tests/spec/arb_map_buffer_range/invalidate.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright © 2010 Marek Olšák <maraeo at gmail.com>
+ *
+ * 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.
+ *
+ */
+
+/* This tests whether the invalidate map flags work as expected with rendering
+ * between map calls.
+ *
+ * The alignment of returned pointers is also checked
+ * if ARB_map_buffer_alignment is supported.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+
+ config.window_width = 600;
+ config.window_height = 480;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum {
+ TEST_MAP_INVALIDATE_RANGE_BIT,
+ TEST_MAP_INVALIDATE_BUFFER_BIT,
+} test_flag;
+
+enum {
+ TEST_OFFSET_0,
+ TEST_OFFSET_INCR,
+ TEST_OFFSET_DECR,
+} test_offset;
+
+int alignment = 1;
+
+void piglit_init(int argc, char **argv)
+{
+ unsigned i;
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "MAP_INVALIDATE_BUFFER_BIT")) {
+ test_flag = TEST_MAP_INVALIDATE_BUFFER_BIT;
+ } else if (!strcmp(argv[i], "MAP_INVALIDATE_RANGE_BIT")) {
+ test_flag = TEST_MAP_INVALIDATE_RANGE_BIT;
+ } else if (!strcmp(argv[i], "offset=0")) {
+ test_offset = TEST_OFFSET_0;
+ } else if (!strcmp(argv[i], "increment-offset")) {
+ test_offset = TEST_OFFSET_INCR;
+ } else if (!strcmp(argv[i], "decrement-offset")) {
+ test_offset = TEST_OFFSET_DECR;
+ } else {
+ printf("Unknown parameter %s\n", argv[i]);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ }
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+ piglit_require_gl_version(15);
+ piglit_require_extension("GL_ARB_map_buffer_range");
+
+ if (piglit_is_extension_supported("GL_ARB_map_buffer_alignment")) {
+ glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &alignment);
+ }
+
+ switch (test_flag) {
+ case TEST_MAP_INVALIDATE_RANGE_BIT:
+ puts("Testing GL_MAP_INVALIDATE_RANGE_BIT.");
+ break;
+ case TEST_MAP_INVALIDATE_BUFFER_BIT:
+ puts("Testing GL_MAP_INVALIDATE_BUFFER_BIT.");
+ break;
+ default:
+ assert(0);
+ }
+
+ switch (test_offset) {
+ case TEST_OFFSET_0:
+ puts("Offset = 0.");
+ break;
+ case TEST_OFFSET_INCR:
+ puts("Offset is incremented.");
+ break;
+ case TEST_OFFSET_DECR:
+ puts("Offset is decremented.");
+ break;
+ default:
+ assert(0);
+ }
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.2, 0.2, 0.2, 1.0);
+}
+
+static void upload(unsigned slot, float x1, float y1, float x2, float y2)
+{
+ unsigned offset = slot * 6*4;
+ float *v = glMapBufferRange(GL_ARRAY_BUFFER, offset, 6*4,
+ GL_MAP_WRITE_BIT |
+ (test_flag == TEST_MAP_INVALIDATE_BUFFER_BIT ? GL_MAP_INVALIDATE_BUFFER_BIT : 0) |
+ (test_flag == TEST_MAP_INVALIDATE_RANGE_BIT ? GL_MAP_INVALIDATE_RANGE_BIT : 0));
+ if (!v) {
+ printf("glMapBufferRange returned NULL.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ if (((uintptr_t)v - offset) % alignment != 0) {
+ printf("glMapBufferRange returned a pointer not aligned to GL_MIN_MAP_BUFFER_ALIGNMENT.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ *v++ = x1;
+ *v++ = y1;
+ *v++ = x1;
+ *v++ = y2;
+ *v++ = x2;
+ *v++ = y1;
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+}
+
+#define NUM_PRIMS 700
+
+enum piglit_result piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+ float white[] = {1, 1, 1, 1};
+ unsigned i, vbo;
+ float x, y;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glGenBuffers(1, &vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glBufferData(GL_ARRAY_BUFFER, NUM_PRIMS * 6*4, NULL, GL_STATIC_DRAW);
+
+ /* just make the GPU busy, render a degenerated triangle */
+ upload(0, 0, 0, 0, 0);
+ glVertexPointer(2, GL_FLOAT, 0, 0);
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+
+ x = 0, y = 0;
+ for (i = 0; i < NUM_PRIMS; i++) {
+ unsigned slot = 0;
+
+ switch (test_offset) {
+ case TEST_OFFSET_0:
+ break;
+ case TEST_OFFSET_INCR:
+ slot = i;
+ break;
+ case TEST_OFFSET_DECR:
+ slot = NUM_PRIMS - 1 - i;
+ break;
+ default:
+ assert(0);
+ }
+
+ upload(slot, x, y, x+20, y+20);
+ glDrawArrays(GL_TRIANGLES, slot*3, 3);
+
+ x += 20;
+ if (x >= piglit_width) {
+ x = 0;
+ y += 20;
+ }
+ }
+
+ x = 0, y = 0;
+ for (i = 0; i < NUM_PRIMS; i++) {
+ GLboolean result = piglit_probe_pixel_rgb(x+5, y+5, white);
+ if (!result)
+ printf(" ... FAIL with primitive %i:\n", i+1);
+ pass = result && pass;
+
+ x += 20;
+ if (x >= piglit_width) {
+ x = 0;
+ y += 20;
+ }
+ }
+
+ glDeleteBuffers(1, &vbo);
+ assert(glGetError() == 0);
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.7.10.4
More information about the Piglit
mailing list