[Piglit] [PATCH 1/8] arb_draw_indirect: add test for api errors
Chris Forbes
chrisf at ijw.co.nz
Thu Nov 7 11:00:51 PST 2013
This initial test covers the new buffer binding point and expected API errors only;
no successful Draw*Indirect calls are made.
Future tests will exercise positive cases.
Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
tests/all.tests | 5 +
tests/spec/CMakeLists.txt | 1 +
tests/spec/arb_draw_indirect/CMakeLists.gl.txt | 14 ++
tests/spec/arb_draw_indirect/CMakeLists.txt | 1 +
tests/spec/arb_draw_indirect/api-errors.c | 235 +++++++++++++++++++++++++
5 files changed, 256 insertions(+)
create mode 100644 tests/spec/arb_draw_indirect/CMakeLists.gl.txt
create mode 100644 tests/spec/arb_draw_indirect/CMakeLists.txt
create mode 100644 tests/spec/arb_draw_indirect/api-errors.c
diff --git a/tests/all.tests b/tests/all.tests
index 2e88de4..1ad230e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1215,6 +1215,11 @@ arb_draw_instanced['negative-elements-type'] = concurrent_test('arb_draw_instanc
add_plain_test(arb_draw_instanced, 'draw-instanced')
add_plain_test(arb_draw_instanced, 'draw-instanced-divisor')
+# Group ARB_draw_indirect
+arb_draw_indirect = Group()
+spec['ARB_draw_indirect'] = arb_draw_indirect
+add_concurrent_test(arb_draw_indirect, 'arb_draw_indirect-api-errors')
+
# Group ARB_fragment_program
arb_fragment_program = Group()
spec['ARB_fragment_program'] = arb_fragment_program
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 18b846d..07721b5 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -3,6 +3,7 @@ add_subdirectory (arb_color_buffer_float)
add_subdirectory (arb_debug_output)
add_subdirectory (khr_debug)
add_subdirectory (arb_depth_clamp)
+add_subdirectory (arb_draw_indirect)
add_subdirectory (arb_draw_instanced)
add_subdirectory (arb_es2_compatibility)
add_subdirectory (arb_framebuffer_object)
diff --git a/tests/spec/arb_draw_indirect/CMakeLists.gl.txt b/tests/spec/arb_draw_indirect/CMakeLists.gl.txt
new file mode 100644
index 0000000..1447610
--- /dev/null
+++ b/tests/spec/arb_draw_indirect/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+ piglitutil_${piglit_target_api}
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (arb_draw_indirect-api-errors api-errors.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_draw_indirect/CMakeLists.txt b/tests/spec/arb_draw_indirect/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_draw_indirect/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_draw_indirect/api-errors.c b/tests/spec/arb_draw_indirect/api-errors.c
new file mode 100644
index 0000000..acd7f6c
--- /dev/null
+++ b/tests/spec/arb_draw_indirect/api-errors.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+/* Test error behavior for GL_ARB_draw_indirect */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_core_version = 31;
+
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+
+static bool
+check_binding_point(void)
+{
+ /* Check that the binding point exists, and the default
+ * binding must be zero
+ */
+
+ GLint obj;
+ glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING, &obj);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ return false;
+
+ if (obj != 0)
+ return false;
+
+ return true;
+}
+
+
+static bool
+check_can_bind(void)
+{
+ /* Check that a buffer can be bound to the binding point.
+ * Does not *use* the buffer for anything.
+ */
+ GLuint buf;
+ GLint obj;
+ glGenBuffers(1, &buf);
+
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ return false;
+
+ glBufferData(GL_DRAW_INDIRECT_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ return false;
+
+ glGetIntegerv(GL_DRAW_INDIRECT_BUFFER_BINDING, &obj);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ return false;
+
+ if (buf != obj)
+ return false;
+
+ return true;
+}
+
+
+static bool
+check_draw_no_buffer_bound(void)
+{
+ /* In the core profile, an INVALID_OPERATION error is generated
+ * if zero is bound to DRAW_INDIRECT_BUFFER and DrawArraysIndirect
+ * or DrawElementsIndirect is called.
+ */
+
+ /* Bind a buffer of indices; ensure we're hitting the correct
+ * error path with DrawElementsIndirect.
+ */
+ GLuint ib;
+ glGenBuffers(1, &ib);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
+
+ /* no indirect buffer */
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
+
+ glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)0);
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)0);
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ return true;
+}
+
+
+static bool
+check_draw_beyond_end(void)
+{
+ /* An INVALID_OPERATION error is generated if the commands source
+ * data beyond the end of the buffer object ..
+ */
+
+ GLuint buf;
+ glGenBuffers(1, &buf);
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
+ glBufferData(GL_DRAW_INDIRECT_BUFFER, 5 * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);
+
+ /* command is 4 * sizeof(GLuint); would read one GLuint beyond the end of the BO. */
+ glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)(2 * sizeof(GLuint)));
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ /* DrawElementsIndirect requires index buffer; bind the indirect buffer there too
+ * since it's handy; just to make sure we hit the right case. */
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
+
+ /* command is 5 * sizeof(GLuint); would read one GLuint beyond the end. */
+ glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)(1 * sizeof(GLuint)));
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ return true;
+}
+
+
+static bool
+check_draw_misaligned(void)
+{
+ /* An INVALID_OPERATION error is generated
+ * .. or if <indirect> is not word aligned.
+ */
+
+ GLuint buf;
+ glGenBuffers(1, &buf);
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
+ glBufferData(GL_DRAW_INDIRECT_BUFFER, 32, NULL, GL_DYNAMIC_DRAW);
+
+ glDrawArraysIndirect(GL_TRIANGLES, (GLvoid const *)1); /* misaligned */
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ return true;
+}
+
+
+static bool
+check_draw_elements_no_indices(void)
+{
+ /* If no element array buffer is bound, an INVALID_OPERATION
+ * error is generated.
+ */
+
+ GLuint buf;
+ glGenBuffers(1, &buf);
+ glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buf);
+ glBufferData(GL_DRAW_INDIRECT_BUFFER, 5 * sizeof(GLuint), NULL, GL_DYNAMIC_DRAW);
+
+ /* unbind indices */
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+ glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_SHORT, (GLvoid const *)0);
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+ return false;
+
+ return true;
+}
+
+
+static bool
+report(bool result, char const *name)
+{
+ piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL, name);
+ return result;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ GLuint vao;
+ piglit_require_extension("GL_ARB_draw_indirect");
+
+ /* VAO is required since we're in core profile.
+ * Most of the subtests don't care about it.
+ */
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ pass = report(check_binding_point(), "binding-point") && pass;
+ pass = report(check_can_bind(), "can-bind") && pass;
+ pass = report(check_draw_no_buffer_bound(), "draw-no-buffer-bound") && pass;
+ pass = report(check_draw_beyond_end(), "draw-beyond-end") && pass;
+ pass = report(check_draw_misaligned(), "draw-misaligned") && pass;
+ pass = report(check_draw_elements_no_indices(), "draw-elements-no-indices") && pass;
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
1.8.4.2
More information about the Piglit
mailing list