ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_draw_indirect / api-errors.c
blobcac1a49ff427e8944b4f3d957e2c81625e466eb4
1 /*
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
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.
25 /* Test error behavior for GL_ARB_draw_indirect */
27 #include "piglit-util-gl.h"
29 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config.supports_gl_core_version = 31;
33 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
34 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
36 PIGLIT_GL_TEST_CONFIG_END
38 enum piglit_result
39 piglit_display(void)
41 return PIGLIT_FAIL;
45 static bool
46 check_binding_point(void)
48 /* Check that the binding point exists, and the default
49 * binding must be zero
52 GLint obj;
53 glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING, &obj);
55 if (!piglit_check_gl_error(GL_NO_ERROR))
56 return false;
58 if (obj != 0)
59 return false;
61 return true;
65 static bool
66 check_can_bind(void)
68 /* Check that a buffer can be bound to the binding point.
69 * Does not *use* the buffer for anything.
71 GLuint buf;
72 GLint obj;
73 glGenBuffers(1, &buf);
75 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
77 if (!piglit_check_gl_error(GL_NO_ERROR))
78 return false;
80 glBufferData(GL_DRAW_INDIRECT_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
82 if (!piglit_check_gl_error(GL_NO_ERROR))
83 return false;
85 glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING, &obj);
87 if (!piglit_check_gl_error(GL_NO_ERROR))
88 return false;
90 if (buf != obj)
91 return false;
93 return true;
97 static bool
98 check_draw_no_buffer_bound(void)
100 /* In the core profile, an INVALID_OPERATION error is generated
101 * if zero is bound to DRAW_INDIRECT_BUFFER and DrawArraysIndirect
102 * or DrawElementsIndirect is called.
105 /* Bind a buffer of indices; ensure we're hitting the correct
106 * error path with DrawElementsIndirect.
108 GLuint ib;
109 glGenBuffers(1, &ib);
110 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib);
111 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
113 /* no indirect buffer */
114 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
116 glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)0);
118 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
119 return false;
121 glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)0);
123 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
124 return false;
126 return true;
130 static bool
131 check_draw_beyond_end(void)
133 /* An INVALID_OPERATION error is generated if the commands source
134 * data beyond the end of the buffer object ..
137 GLuint buf;
138 glGenBuffers(1, &buf);
139 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
140 glBufferData(GL_DRAW_INDIRECT_BUFFER, 5 * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);
142 /* command is 4 * sizeof(GLuint); would read one GLuint beyond the end of the BO. */
143 glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)(2 * sizeof(GLuint)));
145 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
146 return false;
148 /* DrawElementsIndirect requires index buffer; bind the indirect buffer there too
149 * since it's handy; just to make sure we hit the right case. */
150 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
152 /* command is 5 * sizeof(GLuint); would read one GLuint beyond the end. */
153 glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)(1 * sizeof(GLuint)));
155 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
156 return false;
158 return true;
162 static bool
163 check_draw_misaligned(void)
165 /* An INVALID_VALUE error is generated
166 * .. or if <indirect> is not word aligned.
169 GLuint buf;
170 glGenBuffers(1, &buf);
171 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
172 glBufferData(GL_DRAW_INDIRECT_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
174 glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)1); /* misaligned */
176 if (!piglit_check_gl_error(GL_INVALID_VALUE))
177 return false;
179 return true;
183 static bool
184 check_draw_elements_no_indices(void)
186 /* If no element array buffer is bound, an INVALID_OPERATION
187 * error is generated.
190 GLuint buf;
191 glGenBuffers(1, &buf);
192 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
193 glBufferData(GL_DRAW_INDIRECT_BUFFER, 5 * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);
195 /* unbind indices */
196 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
198 glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)0);
200 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
201 return false;
203 return true;
207 static bool
208 report(bool result, char const *name)
210 piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL, "%s", name);
211 return result;
215 void
216 piglit_init(int argc, char **argv)
218 bool pass = true;
219 GLuint vao;
220 piglit_require_extension("GL_ARB_draw_indirect");
222 /* VAO is required since we're in core profile.
223 * Most of the subtests don't care about it.
225 glGenVertexArrays(1, &vao);
226 glBindVertexArray(vao);
228 pass = report(check_binding_point(), "binding-point") && pass;
229 pass = report(check_can_bind(), "can-bind") && pass;
230 pass = report(check_draw_no_buffer_bound(), "draw-no-buffer-bound") && pass;
231 pass = report(check_draw_beyond_end(), "draw-beyond-end") && pass;
232 pass = report(check_draw_misaligned(), "draw-misaligned") && pass;
233 pass = report(check_draw_elements_no_indices(), "draw-elements-no-indices") && pass;
235 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);