[Piglit] [PATCH 1/7] ARB_copy_buffer/overlap: New test for a section of the spec.
Eric Anholt
eric at anholt.net
Wed Jan 25 17:36:09 PST 2012
Caught a bug each in swrast and in i965.
---
tests/all.tests | 1 +
tests/spec/arb_copy_buffer/CMakeLists.gl.txt | 1 +
tests/spec/arb_copy_buffer/overlap.c | 160 ++++++++++++++++++++++++++
3 files changed, 162 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/arb_copy_buffer/overlap.c
diff --git a/tests/all.tests b/tests/all.tests
index c445b81..222747d 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1607,6 +1607,7 @@ arb_copy_buffer = Group()
spec['ARB_copy_buffer'] = arb_copy_buffer
add_plain_test(arb_copy_buffer, 'copy_buffer_coherency')
add_plain_test(arb_copy_buffer, 'copybuffersubdata')
+arb_copy_buffer['overlap'] = concurrent_test('arb_copy_buffer-overlap')
arb_vertex_type_2_10_10_10_rev = Group()
spec['ARB_vertex_type_2_10_10_10_rev'] = arb_vertex_type_2_10_10_10_rev
diff --git a/tests/spec/arb_copy_buffer/CMakeLists.gl.txt b/tests/spec/arb_copy_buffer/CMakeLists.gl.txt
index 6494b1d..563fca1 100644
--- a/tests/spec/arb_copy_buffer/CMakeLists.gl.txt
+++ b/tests/spec/arb_copy_buffer/CMakeLists.gl.txt
@@ -13,5 +13,6 @@ link_libraries (
add_executable (copy_buffer_coherency copy_buffer_coherency.c)
add_executable (copybuffersubdata copybuffersubdata.c)
+add_executable (arb_copy_buffer-overlap overlap.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_copy_buffer/overlap.c b/tests/spec/arb_copy_buffer/overlap.c
new file mode 100644
index 0000000..2e9f2de
--- /dev/null
+++ b/tests/spec/arb_copy_buffer/overlap.c
@@ -0,0 +1,160 @@
+/*
+ * 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 overlap.c
+ *
+ * Tests the following piece of the GL_ARB_copy_buffer spec:
+ *
+ * "An INVALID_VALUE error is generated if the same buffer object
+ * is bound to both readtarget and writetarget, and the ranges
+ * [readoffset, readoffset+size) and [writeoffset,
+ * writeoffset+size) overlap."
+ *
+ * And it also tests that copying works correctly if there isn't
+ * overlap, but with one buffer being both src and dst.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static void
+test_copy(GLenum usage, int data_size, int src, int dst, int size)
+{
+ uint8_t data[data_size];
+ uint8_t expected[data_size];
+ uint8_t *ptr;
+ int i;
+
+ for (i = 0; i < data_size; i++) {
+ data[i] = i;
+ }
+
+ glBufferData(GL_COPY_READ_BUFFER, data_size, data, usage);
+
+ glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
+ src, dst, size);
+
+ if (src > dst - size &&
+ src < dst + size) {
+ if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
+ fprintf(stderr,
+ "No error reported for overlapping "
+ "glCopyBufferSubData() from %d to %d, "
+ "size %d\n",
+ src, dst, size);
+ piglit_report_result(PIGLIT_FAIL);
+ } else {
+ return;
+ }
+ } else {
+ if (!piglit_check_gl_error(0)) {
+ fprintf(stderr,
+ "Error reported for non-overlapping "
+ "glCopyBufferSubData() from %d to %d, "
+ "size %d\n",
+ src, dst, size);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ }
+ //piglit_reset_gl_error();
+
+ /* Now compute what the result should be and check that it matches. */
+ memcpy(expected, data, data_size);
+ memcpy(expected + dst, expected + src, size);
+ ptr = glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
+ if (memcmp(expected, ptr, data_size)) {
+ fprintf(stderr,
+ "Data not copied correctly for non-overlapping "
+ "glCopyBufferSubData().\n"
+ "from offset %d to offset %d, size %d\n",
+ src, dst, size);
+
+ fprintf(stderr, "original: expected: found:\n");
+ for (i = 0; i < data_size; i++) {
+ fprintf(stderr, "0x%02x 0x%02x 0x%02x\n",
+ i, expected[i], ptr[i]);
+ }
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ glUnmapBuffer(GL_COPY_READ_BUFFER);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ /* uncreached */
+ return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint buf;
+ int src, dst, i;
+ int size = 6;
+ static const GLenum bo_modes[] = {
+ GL_STREAM_DRAW,
+ GL_STREAM_READ,
+ GL_STREAM_COPY,
+ GL_STATIC_DRAW,
+ GL_STATIC_READ,
+ GL_STATIC_COPY,
+ GL_DYNAMIC_DRAW,
+ GL_DYNAMIC_READ,
+ GL_DYNAMIC_COPY,
+ };
+
+ piglit_require_extension("GL_ARB_copy_buffer");
+
+ glGenBuffers(1, &buf);
+
+ glBindBufferARB(GL_COPY_READ_BUFFER, buf);
+ glBindBufferARB(GL_COPY_WRITE_BUFFER, buf);
+
+ for (i = 0; i < ARRAY_SIZE(bo_modes); i++) {
+ GLenum usage = bo_modes[i];
+
+ for (src = 0; src < size; src++) {
+ int max_src_size = size - src;
+ for (dst = 0; dst < size; dst++) {
+ int max_dst_size = size - dst;
+ int max_size = ((max_src_size < max_dst_size) ?
+ max_src_size :
+ max_dst_size);
+ int copy_size;
+
+ for (copy_size = 1; copy_size <= max_size;
+ copy_size++) {
+ test_copy(usage, size,
+ src, dst, copy_size);
+ }
+ }
+ }
+ }
+
+ glDeleteBuffers(1, &buf);
+
+ piglit_report_result(PIGLIT_PASS);
+}
--
1.7.7.3
More information about the Piglit
mailing list