ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_invalidate_subdata / buffer.c
blobdedb93735a751a279f7c91f416586a9e2b17cfff
1 /*
2 * Copyright 2016 Advanced Micro Devices, Inc.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Nicolai Hähnle <nicolai.haehnle@amd.com>
28 * No-op is a conforming implementation of glInvalidateBuffer(Sub)Data, so
29 * this test only checks error conditions.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_core_version = 31;
37 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
38 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
43 * Section 6.5 (Invalidating Buffer Data) of the OpenGL 4.5 (Compatibility
44 * Profile) spec:
46 * * An INVALID_VALUE error is generated if buffer is zero or is not the
47 * name of an existing buffer object.
48 * * An INVALID_VALUE error is generated if offset or length is negative,
49 * or if offset + length is greater than the value of BUFFER_SIZE for
50 * buffer.
51 * * An INVALID_OPERATION error is generated if buffer is currently mapped
52 * by MapBuffer or if the invalidate range intersects the range currently
53 * mapped by MapBufferRange, unless it was mapped with MAP_PERSISTENT_BIT
54 * set in the MapBufferRange access flags.
56 static bool
57 check_errors_subdata()
59 GLuint buffer;
60 bool pass = true;
62 glGenBuffers(1, &buffer);
64 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
65 glInvalidateBufferSubData(buffer, 0, 0);
66 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
68 glBindBuffer(GL_ARRAY_BUFFER, buffer);
69 glInvalidateBufferSubData(buffer, 0, 0);
70 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
72 glBufferData(GL_ARRAY_BUFFER, 1024, NULL, GL_STREAM_DRAW);
73 glInvalidateBufferSubData(buffer, 0, 1024);
74 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
76 glInvalidateBufferSubData(buffer, -1, 0);
77 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
79 glInvalidateBufferSubData(buffer, 0, -1);
80 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
82 glInvalidateBufferSubData(buffer, 1023, 2);
83 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
85 glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
87 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
88 glInvalidateBufferSubData(buffer, 0, 1);
89 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
91 glUnmapBuffer(GL_ARRAY_BUFFER);
93 glMapBufferRange(GL_ARRAY_BUFFER, 256, 256, GL_MAP_WRITE_BIT);
95 glInvalidateBufferSubData(buffer, 0, 256);
96 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
98 glInvalidateBufferSubData(buffer, 512, 512);
99 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
101 glInvalidateBufferSubData(buffer, 240, 100);
102 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
104 glUnmapBuffer(GL_ARRAY_BUFFER);
106 if (piglit_is_extension_supported("GL_ARB_buffer_storage")) {
107 glBufferStorage(GL_ARRAY_BUFFER, 1024, NULL,
108 GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
110 glMapBufferRange(GL_ARRAY_BUFFER, 256, 256,
111 GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
113 glInvalidateBufferSubData(buffer, 240, 100);
114 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
116 glUnmapBuffer(GL_ARRAY_BUFFER);
119 glDeleteBuffers(1, &buffer);
121 return pass;
124 static bool
125 check_errors_data()
127 GLuint buffer;
128 bool pass = true;
130 glGenBuffers(1, &buffer);
132 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
133 glInvalidateBufferData(buffer);
134 pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
136 glBindBuffer(GL_ARRAY_BUFFER, buffer);
137 glInvalidateBufferData(buffer);
138 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
140 glBufferData(GL_ARRAY_BUFFER, 1024, NULL, GL_STREAM_DRAW);
141 glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
143 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
144 glInvalidateBufferData(buffer);
145 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
147 glUnmapBuffer(GL_ARRAY_BUFFER);
149 if (piglit_is_extension_supported("GL_ARB_buffer_storage")) {
150 glBufferStorage(GL_ARRAY_BUFFER, 1024, NULL,
151 GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
153 glMapBufferRange(GL_ARRAY_BUFFER, 256, 256, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
154 glInvalidateBufferData(buffer);
155 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
157 glUnmapBuffer(GL_ARRAY_BUFFER);
160 glDeleteBuffers(1, &buffer);
162 return pass;
165 enum piglit_result
166 piglit_display(void)
168 bool pass = true;
170 pass = check_errors_subdata() && pass;
171 pass = check_errors_data() && pass;
173 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
176 void
177 piglit_init(int argc, char **argv)
179 piglit_require_extension("GL_ARB_invalidate_subdata");