2 * Copyright © 2013 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
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
24 /** @file subdata-sync.c
26 * Tests that glBufferSubData() synchronizes correctly with
27 * glCopyBufferSubData().
29 * We make sure that a subdata over the read buffer after the copy has
30 * no effect, while a subdata over the write buffer after the copy
31 * does have an effect.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 15;
39 config
.supports_gl_core_version
= 31;
41 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
47 piglit_init(int argc
, char *argv
[])
50 uint32_t dummy_data_1
[4], dummy_data_2
[4];
51 uint32_t good_data
[4] = {0, 1, 2, 3};
52 uint32_t result_data
[4];
54 size_t size
= sizeof(good_data
);
55 GLuint buffer_handles
[2];
57 memset(dummy_data_1
, 0xaa, size
);
58 memset(dummy_data_2
, 0xbb, size
);
60 piglit_require_extension("GL_ARB_copy_buffer");
62 glGenBuffers(2, buffer_handles
);
63 glBindBuffer(GL_COPY_READ_BUFFER
, buffer_handles
[0]);
64 glBindBuffer(GL_COPY_WRITE_BUFFER
, buffer_handles
[1]);
66 glBufferData(GL_COPY_READ_BUFFER
, 4096, NULL
, GL_STREAM_COPY
);
67 glBufferData(GL_COPY_WRITE_BUFFER
, 4096, NULL
, GL_STREAM_COPY
);
68 glBufferSubData(GL_COPY_READ_BUFFER
, 0, size
, good_data
);
69 glBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, dummy_data_1
);
71 glCopyBufferSubData(GL_COPY_READ_BUFFER
, GL_COPY_WRITE_BUFFER
,
73 glBufferSubData(GL_COPY_READ_BUFFER
, 0, size
, dummy_data_2
);
74 memset(result_data
, 0xd0, size
);
75 glGetBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, result_data
);
76 subtest_pass
= memcmp(good_data
, result_data
, size
) == 0;
78 fprintf(stderr
, "found 0x%08x 0x%08x 0x%08x 0x%08x\n",
79 result_data
[0], result_data
[1],
80 result_data
[2], result_data
[3]);
81 fprintf(stderr
, "expected 0x%08x 0x%08x 0x%08x 0x%08x\n",
82 good_data
[0], good_data
[1],
83 good_data
[2], good_data
[3]);
86 piglit_report_subtest_result(subtest_pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
87 "overwrite source data");
90 glBufferData(GL_COPY_READ_BUFFER
, 4096, NULL
, GL_STREAM_COPY
);
91 glBufferData(GL_COPY_WRITE_BUFFER
, 4096, NULL
, GL_STREAM_COPY
);
92 glBufferSubData(GL_COPY_READ_BUFFER
, 0, size
, dummy_data_1
);
93 glBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, dummy_data_2
);
94 glCopyBufferSubData(GL_COPY_READ_BUFFER
, GL_COPY_WRITE_BUFFER
,
96 glBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, good_data
);
97 memset(result_data
, 0xd0, size
);
98 glGetBufferSubData(GL_COPY_WRITE_BUFFER
, 0, size
, result_data
);
99 subtest_pass
= memcmp(good_data
, result_data
, size
) == 0;
101 fprintf(stderr
, "found 0x%08x 0x%08x 0x%08x 0x%08x\n",
102 result_data
[0], result_data
[1],
103 result_data
[2], result_data
[3]);
104 fprintf(stderr
, "expected 0x%08x 0x%08x 0x%08x 0x%08x\n",
105 good_data
[0], good_data
[1],
106 good_data
[2], good_data
[3]);
109 piglit_report_subtest_result(subtest_pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
110 "overwrite destination data");
112 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);