2 * Copyright © 2014 Intel Corporation
3 * Copyright © 2015 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * Test R8 copying with non-dword alignment.
31 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 15;
37 config
.supports_gl_core_version
= 31;
38 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
42 #define SIZE (1 << 20)
47 clear_buffer(int i
, unsigned offset
, unsigned size
, unsigned char value
, char *cpu
)
49 glClearBufferSubData(GL_ARRAY_BUFFER
, GL_R8
, offset
, size
,
50 GL_RED
, GL_UNSIGNED_BYTE
, &value
);
51 memset(cpu
+offset
, value
, size
);
53 if (debug
&& !check_array_buffer_data(SIZE
, cpu
)) {
54 printf("Clear %i failed: offset=%i (%%4 = %i), size=%i (%%4 = %i)\n",
55 i
, offset
, offset
% 4, size
, size
% 4);
56 piglit_report_result(PIGLIT_FAIL
);
61 piglit_init(int argc
, char **argv
)
66 unsigned offset
, size
;
67 char *cpu
= malloc(SIZE
);
70 piglit_report_result(PIGLIT_FAIL
);
72 for (i
= 1; i
< argc
; i
++)
73 if (!strcmp(argv
[i
], "-debug"))
76 piglit_require_extension("GL_ARB_clear_buffer_object");
77 glGenBuffers(1, &buffer
);
78 glBindBuffer(GL_ARRAY_BUFFER
, buffer
);
79 glBufferData(GL_ARRAY_BUFFER
, SIZE
, NULL
, GL_STREAM_READ
);
81 clear_buffer(0, 0, SIZE
, 0, cpu
);
84 for (i
= 1; i
<= 200; i
++) {
85 offset
= rand() % SIZE
;
86 size
= 1 + (rand() % (SIZE
- offset
));
88 clear_buffer(i
, offset
, size
, rand(), cpu
);
91 /* and some small unaligned copies within one dword */
92 for (; i
< 230; i
++) {
93 offset
= (rand() % (SIZE
/4)) * 4 + 1 + (rand() % 2);
96 clear_buffer(i
, offset
, size
, rand(), cpu
);
99 pass
= piglit_check_gl_error(GL_NO_ERROR
) &&
100 check_array_buffer_data(SIZE
, cpu
);
101 glDeleteBuffers(1, &buffer
);
103 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);