[Piglit] [PATCH 2/2] GL_ARB_occlusion_query2: Add tests for the API.

Ian Romanick idr at freedesktop.org
Fri Oct 19 15:11:14 PDT 2012


On 10/19/2012 11:13 AM, Eric Anholt wrote:
> Apparently I added Mesa support for it without adding tests, and
> shockingly the Mesa support was broken.

Of course. :)  Other than a small nit below, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> ---
>   tests/all.tests                                   |    6 +
>   tests/spec/CMakeLists.txt                         |    1 +
>   tests/spec/arb_occlusion_query2/CMakeLists.gl.txt |   13 ++
>   tests/spec/arb_occlusion_query2/CMakeLists.txt    |    1 +
>   tests/spec/arb_occlusion_query2/api.c             |  253 +++++++++++++++++++++
>   tests/spec/arb_occlusion_query2/render.c          |  103 +++++++++
>   6 files changed, 377 insertions(+)
>   create mode 100644 tests/spec/arb_occlusion_query2/CMakeLists.gl.txt
>   create mode 100644 tests/spec/arb_occlusion_query2/CMakeLists.txt
>   create mode 100644 tests/spec/arb_occlusion_query2/api.c
>   create mode 100644 tests/spec/arb_occlusion_query2/render.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 42fda51..37ebcbc 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1174,6 +1174,12 @@ arb_debug_output = Group()
>   spec['ARB_debug_output'] = arb_debug_output
>   add_plain_test(arb_debug_output, 'arb_debug_output-api_error')
>
> +# Group ARB_occlusion_query2
> +arb_occlusion_query2 = Group()
> +spec['ARB_occlusion_query2'] = arb_occlusion_query2
> +arb_occlusion_query2['api'] = concurrent_test('arb_occlusion_query2-api')
> +arb_occlusion_query2['render'] = concurrent_test('arb_occlusion_query2-render')
> +
>   # Group ARB_robustness
>   arb_robustness = Group()
>   spec['ARB_robustness'] = arb_robustness
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index 2895958..351b113 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -7,6 +7,7 @@ add_subdirectory (arb_framebuffer_srgb)
>   add_subdirectory (arb_instanced_arrays)
>   add_subdirectory (arb_map_buffer_range)
>   add_subdirectory (arb_multisample)
> +add_subdirectory (arb_occlusion_query2)
>   add_subdirectory (arb_robustness)
>   add_subdirectory (arb_sampler_objects)
>   add_subdirectory (arb_seamless_cube_map)
> diff --git a/tests/spec/arb_occlusion_query2/CMakeLists.gl.txt b/tests/spec/arb_occlusion_query2/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..f1cee6f
> --- /dev/null
> +++ b/tests/spec/arb_occlusion_query2/CMakeLists.gl.txt
> @@ -0,0 +1,13 @@
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +)
> +
> +link_libraries (
> +	piglitutil_${piglit_target_api}
> +	${OPENGL_gl_LIBRARY}
> +	${OPENGL_glu_LIBRARY}
> +)
> +
> +piglit_add_executable (arb_occlusion_query2-api api.c)
> +piglit_add_executable (arb_occlusion_query2-render render.c)
> diff --git a/tests/spec/arb_occlusion_query2/CMakeLists.txt b/tests/spec/arb_occlusion_query2/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/arb_occlusion_query2/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/spec/arb_occlusion_query2/api.c b/tests/spec/arb_occlusion_query2/api.c
> new file mode 100644
> index 0000000..5615481
> --- /dev/null
> +++ b/tests/spec/arb_occlusion_query2/api.c
> @@ -0,0 +1,253 @@
> +/*
> + * Copyright © 2012 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.
> + */
> +
> +/**
> + * \file api.c
> + *
> + * Test miscellaneous other entrypoints for GL_ARB_occlusion_query2.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;
> +
> +	config.window_width = 50;
> +	config.window_height = 50;
> +	config.window_visual = (PIGLIT_GL_VISUAL_RGB |
> +				PIGLIT_GL_VISUAL_DOUBLE |
> +				PIGLIT_GL_VISUAL_DEPTH);
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static bool
> +test_error_begin_while_other_active()
> +{
> +	GLuint oq[2];
> +	bool pass = true;
> +
> +	/* GL_ARB_occlusion_query2 specifies INVALID_OPERATION for
> +	 * starting either query type with the other one active.
> +	 */
> +	glGenQueries(2, oq);
> +
> +	glBeginQuery(GL_SAMPLES_PASSED, oq[0]);
> +	if (!piglit_check_gl_error(0))
> +		pass = false;
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]);
> +	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
> +		pass = false;
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +	glEndQuery(GL_SAMPLES_PASSED);
> +	/* Clear any error left over from the glEndQuery()s. */
> +	while (glGetError())
> +		;

piglit_reset_gl_error instead?

> +
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]);
> +	if (!piglit_check_gl_error(0))
> +		pass = false;
> +	glBeginQuery(GL_SAMPLES_PASSED, oq[1]);
> +	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
> +		pass = false;
> +	glEndQuery(GL_SAMPLES_PASSED);
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +	/* Clear any error left over from the glEndQuery()s. */
> +	while (glGetError())
> +		;

Ditto.

> +
> +	glDeleteQueries(2, oq);
> +
> +	return pass;
> +}
> +
> +static bool
> +test_counter_bits()
> +{
> +	GLint result = -1;
> +
> +	/* From the GL_ARB_occlusion_query2 spec:
> +	 *
> +	 *   "Modify the paragraph beginning with "For occlusion
> +	 *   queries (SAMPLES_PASSED)..."
> +	 *
> +	 *       For occlusion queries
> +	 *    |  (SAMPLES_PASSED and ANY_SAMPLES_PASSED), the number of bits
> +	 *    |  depends on the target.  For a target of ANY_SAMPLES_PASSED, if
> +	 *    |  the number of bits is non-zero,  the minimum number of bits
> +	 *    |  is 1.  For a target of SAMPLES_PASSED,
> +	 *       if the number of bits is non-zero, ..."
> +	 *
> +	 * So, the number of bits has to be either a zero or >= 1.
> +	 */
> +	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &result);
> +	if (result < 0) {
> +		fprintf(stderr, "GL_QUERY_COUNTER_BITS returned %d\n", result);
> +		return false;
> +	}
> +	return true;
> +}
> +
> +static bool
> +test_error_end_wrong_target()
> +{
> +	bool pass = true;
> +	GLuint oq;
> +
> +	glGenQueries(1, &oq);
> +
> +	/* From the GL_ARB_occlusion_query2 spec:
> +	 *
> +	 *     "If EndQueryARB is called while no query with the same
> +	 *      target is in progress, an INVALID_OPERATION error is
> +	 *      generated."
> +	 */
> +	glBeginQuery(GL_SAMPLES_PASSED, oq);
> +	if (!piglit_check_gl_error(0))
> +		pass = false;
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
> +		pass = false;
> +	glEndQuery(GL_SAMPLES_PASSED);
> +	/* Clear any error left over from the glEndQuery()s. */
> +	while (glGetError())
> +		;

Ditto.

> +
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
> +	if (!piglit_check_gl_error(0))
> +		pass = false;
> +	glEndQuery(GL_SAMPLES_PASSED);
> +	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
> +		pass = false;
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +	/* Clear any error left over from the glEndQuery()s. */
> +	while (glGetError())
> +		;

Ditto.

> +
> +	glDeleteQueries(1, &oq);
> +
> +	return pass;
> +}
> +
> +static bool
> +test_current_query()
> +{
> +	bool pass = true;
> +	GLint result = -1;
> +	GLuint oq;
> +
> +	glGenQueries(1, &oq);
> +
> +	/* Test that GL_CURRENT_QUERY returns our target and not the
> +	 * other one. First, check that we're inactive after the
> +	 * previous sequence of query code.
> +	 */
> +	result = -1;
> +	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != 0) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
> +			"while inactive\n",
> +			result);
> +		pass = false;
> +	}
> +	result = -1;
> +	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != 0) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
> +			"while inactive\n",
> +			result);
> +		pass = false;
> +	}
> +
> +	/* Test the result for GL_ANY_SAMPLES_PASSED active */
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
> +	result = -1;
> +	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != oq) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
> +			"while GL_ANY_SAMPLES_PASSED active\n",
> +			result);
> +		pass = false;
> +	}
> +	result = -1;
> +	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != 0) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d while "
> +			"GL_ANY_SAMPLES_PASSED active\n",
> +			result);
> +		pass = false;
> +	}
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +
> +	/* Test the result for GL_SAMPLES_PASSED active */
> +	glBeginQuery(GL_SAMPLES_PASSED, oq);
> +	result = -1;
> +	glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != 0) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
> +			"while GL_SAMPLES_PASSED active\n",
> +			result);
> +		pass = false;
> +	}
> +	result = -1;
> +	glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
> +	if (result != oq) {
> +		fprintf(stderr,
> +			"GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
> +			"while GL_SAMPLES_PASSED active\n",
> +			result);
> +		pass = false;
> +	}
> +	glEndQuery(GL_SAMPLES_PASSED);
> +
> +	glDeleteQueries(1, &oq);
> +
> +	return pass;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	bool pass = true;
> +
> +	pass = test_counter_bits() && pass;
> +	pass = test_current_query() && pass;
> +	pass = test_error_end_wrong_target() && pass;
> +	pass = test_error_begin_while_other_active() && pass;
> +
> +	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +
> +	/* UNREACHED */
> +	return PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_extension("GL_ARB_occlusion_query2");
> +}
> diff --git a/tests/spec/arb_occlusion_query2/render.c b/tests/spec/arb_occlusion_query2/render.c
> new file mode 100644
> index 0000000..1ad142e
> --- /dev/null
> +++ b/tests/spec/arb_occlusion_query2/render.c
> @@ -0,0 +1,103 @@
> +/*
> + * Copyright © 2012 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.
> + */
> +
> +/**
> + * \file render.c
> + *
> + * Simple test for getting query results with GL_ARB_occlusion_query2.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;
> +
> +	config.window_width = 50;
> +	config.window_height = 50;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	GLuint oq[3];
> +	GLint result[3] = {2, 2, 2};
> +	bool pass = true;
> +	int i;
> +
> +	glEnable(GL_DEPTH_TEST);
> +
> +	glClearDepth(1.0);
> +	glClearColor(0.5, 0.5, 0.5, 0.5);
> +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
> +
> +	glGenQueries(3, oq);
> +	glDeleteQueries(3, oq);
> +
> +	glColor4f(0.0, 1.0, 0.0, 0.0);
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]);
> +	piglit_draw_rect_z(0.5, -1, -1, 2, 2);
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]);
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +
> +	glColor4f(1.0, 0.0, 0.0, 0.0);
> +	glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[2]);
> +	piglit_draw_rect_z(0.75, -0.5, -0.5, 1.0, 1.0);
> +	glEndQuery(GL_ANY_SAMPLES_PASSED);
> +
> +	piglit_present_results();
> +
> +	for (i = 0; i < 3; i++) {
> +		glGetQueryObjectiv(oq[i], GL_QUERY_RESULT, &result[i]);
> +	}
> +
> +	if (result[0] != GL_TRUE) {
> +		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with passed fragments returned %d\n",
> +			result[0]);
> +		pass = false;
> +	}
> +
> +	if (result[1] != GL_FALSE) {
> +		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with no rendering returned %d\n",
> +			result[1]);
> +		pass = false;
> +	}
> +
> +	if (result[2] != GL_FALSE) {
> +		fprintf(stderr, "GL_ANY_SAMPLES_PASSED with occluded rendering returned %d\n",
> +			result[2]);
> +		pass = false;
> +	}
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_extension("GL_ARB_occlusion_query2");
> +}
>



More information about the Piglit mailing list