ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_copy_buffer / overlap.c
blob9f87025ed5fd5dde993a55f8915e35a0e295840d
1 /*
2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** @file overlap.c
26 * Tests the following piece of the GL_ARB_copy_buffer spec:
28 * "An INVALID_VALUE error is generated if the same buffer object
29 * is bound to both readtarget and writetarget, and the ranges
30 * [readoffset, readoffset+size) and [writeoffset,
31 * writeoffset+size) overlap."
33 * And it also tests that copying works correctly if there isn't
34 * overlap, but with one buffer being both src and dst.
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_compat_version = 10;
43 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
44 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 static void
49 test_copy(GLenum usage, int data_size, int src, int dst, int size)
51 uint8_t *data;
52 uint8_t *expected;
53 uint8_t *ptr;
54 int i;
56 data = (uint8_t *)malloc(data_size);
57 expected = (uint8_t *)malloc(data_size);
59 for (i = 0; i < data_size; i++) {
60 data[i] = i;
63 glBufferData(GL_COPY_READ_BUFFER, data_size, data, usage);
65 glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
66 src, dst, size);
68 if (src > dst - size &&
69 src < dst + size) {
70 if (!piglit_check_gl_error(GL_INVALID_VALUE)) {
71 fprintf(stderr,
72 "No error reported for overlapping "
73 "glCopyBufferSubData() from %d to %d, "
74 "size %d\n",
75 src, dst, size);
76 piglit_report_result(PIGLIT_FAIL);
77 } else {
78 free(expected);
79 free(data);
80 return;
82 } else {
83 if (!piglit_check_gl_error(0)) {
84 fprintf(stderr,
85 "Error reported for non-overlapping "
86 "glCopyBufferSubData() from %d to %d, "
87 "size %d\n",
88 src, dst, size);
89 piglit_report_result(PIGLIT_FAIL);
92 //piglit_reset_gl_error();
94 /* Now compute what the result should be and check that it matches. */
95 memcpy(expected, data, data_size);
96 memcpy(expected + dst, expected + src, size);
97 ptr = glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
98 if (memcmp(expected, ptr, data_size)) {
99 fprintf(stderr,
100 "Data not copied correctly for non-overlapping "
101 "glCopyBufferSubData().\n"
102 "from offset %d to offset %d, size %d\n",
103 src, dst, size);
105 fprintf(stderr, "original: expected: found:\n");
106 for (i = 0; i < data_size; i++) {
107 fprintf(stderr, "0x%02x 0x%02x 0x%02x\n",
108 i, expected[i], ptr[i]);
110 piglit_report_result(PIGLIT_FAIL);
112 glUnmapBuffer(GL_COPY_READ_BUFFER);
114 free(expected);
115 free(data);
118 enum piglit_result
119 piglit_display(void)
121 /* uncreached */
122 return PIGLIT_FAIL;
125 void
126 piglit_init(int argc, char **argv)
128 GLuint buf;
129 int src, dst, i;
130 int size = 6;
131 static const GLenum bo_modes[] = {
132 GL_STREAM_DRAW,
133 GL_STREAM_READ,
134 GL_STREAM_COPY,
135 GL_STATIC_DRAW,
136 GL_STATIC_READ,
137 GL_STATIC_COPY,
138 GL_DYNAMIC_DRAW,
139 GL_DYNAMIC_READ,
140 GL_DYNAMIC_COPY,
143 piglit_require_extension("GL_ARB_copy_buffer");
145 glGenBuffers(1, &buf);
147 glBindBufferARB(GL_COPY_READ_BUFFER, buf);
148 glBindBufferARB(GL_COPY_WRITE_BUFFER, buf);
150 for (i = 0; i < ARRAY_SIZE(bo_modes); i++) {
151 GLenum usage = bo_modes[i];
153 for (src = 0; src < size; src++) {
154 int max_src_size = size - src;
155 for (dst = 0; dst < size; dst++) {
156 int max_dst_size = size - dst;
157 int max_size = ((max_src_size < max_dst_size) ?
158 max_src_size :
159 max_dst_size);
160 int copy_size;
162 for (copy_size = 1; copy_size <= max_size;
163 copy_size++) {
164 test_copy(usage, size,
165 src, dst, copy_size);
171 glDeleteBuffers(1, &buf);
173 piglit_report_result(PIGLIT_PASS);