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
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
46 check_binding_point(void)
48 /* Check that the binding point exists, and the default
49 * binding must be zero
53 glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING
, &obj
);
55 if (!piglit_check_gl_error(GL_NO_ERROR
))
68 /* Check that a buffer can be bound to the binding point.
69 * Does not *use* the buffer for anything.
73 glGenBuffers(1, &buf
);
75 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, buf
);
77 if (!piglit_check_gl_error(GL_NO_ERROR
))
80 glBufferData(GL_DRAW_INDIRECT_BUFFER
, 32, NULL
, GL_DYNAMIC_DRAW
);
82 if (!piglit_check_gl_error(GL_NO_ERROR
))
85 glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING
, &obj
);
87 if (!piglit_check_gl_error(GL_NO_ERROR
))
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.
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
))
121 glDrawElementsIndirect(GL_TRIANGLES
, GL_UNSIGNED_SHORT
, (GLvoid
const *)0);
123 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
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 ..
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
))
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
))
163 check_draw_misaligned(void)
165 /* An INVALID_VALUE error is generated
166 * .. or if <indirect> is not word aligned.
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
))
184 check_draw_elements_no_indices(void)
186 /* If no element array buffer is bound, an INVALID_OPERATION
187 * error is generated.
191 glGenBuffers(1, &buf
);
192 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, buf
);
193 glBufferData(GL_DRAW_INDIRECT_BUFFER
, 5 * sizeof(GLuint
), NULL
, GL_DYNAMIC_DRAW
);
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
))
208 report(bool result
, char const *name
)
210 piglit_report_subtest_result(result
? PIGLIT_PASS
: PIGLIT_FAIL
, "%s", name
);
216 piglit_init(int argc
, char **argv
)
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
);