[Piglit] [PATCH 1/3] hiz: Add utility functions for creating HiZ tests

Ian Romanick idr at freedesktop.org
Thu Apr 28 11:55:22 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/27/2011 01:00 PM, chad at chad-versace.us wrote:
> From: Chad Versace <chad.versace at intel.com>
> 
> Eventually there will be over a dozen HiZ tests, so placing common
> functionality in a library will reduce a good hunk of code.
> 
> Signed-off-by: Chad Versace <chad.versace at intel.com>
> ---
>  tests/CMakeLists.txt        |    1 +
>  tests/hiz/CMakeLists.gl.txt |   14 +++
>  tests/hiz/CMakeLists.txt    |    1 +
>  tests/hiz/hiz-util.c        |  273 +++++++++++++++++++++++++++++++++++++++++++
>  tests/hiz/hiz-util.h        |   93 +++++++++++++++
>  5 files changed, 382 insertions(+), 0 deletions(-)
>  create mode 100644 tests/hiz/CMakeLists.gl.txt
>  create mode 100644 tests/hiz/CMakeLists.txt
>  create mode 100644 tests/hiz/hiz-util.c
>  create mode 100644 tests/hiz/hiz-util.h
> 
> diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
> index 521fcef..dce4022 100644
> --- a/tests/CMakeLists.txt
> +++ b/tests/CMakeLists.txt
> @@ -6,6 +6,7 @@ add_subdirectory (glean)
>  add_subdirectory (gles2)
>  add_subdirectory (glx)
>  add_subdirectory (glslparsertest)
> +add_subdirectory (hiz)
>  add_subdirectory (asmparsertest)
>  add_subdirectory (shaders)
>  add_subdirectory (texturing)
> diff --git a/tests/hiz/CMakeLists.gl.txt b/tests/hiz/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..5db8fb9
> --- /dev/null
> +++ b/tests/hiz/CMakeLists.gl.txt
> @@ -0,0 +1,14 @@
> +include_directories(
> +	${piglit_SOURCE_DIR}/tests
> +	${piglit_SOURCE_DIR}/tests/util
> +
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +	${GLUT_INCLUDE_DIR}
> +	)
> +
> +add_library(hiz-util
> +	hiz-util.c
> +	)
> +
> +# vim: ft=cmake:
> diff --git a/tests/hiz/CMakeLists.txt b/tests/hiz/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/hiz/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/hiz/hiz-util.c b/tests/hiz/hiz-util.c
> new file mode 100644
> index 0000000..b9ec8b3
> --- /dev/null
> +++ b/tests/hiz/hiz-util.c
> @@ -0,0 +1,273 @@
> +/*
> + * Copyright © 2011 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.
> + *
> + * Authors:
> + *     Chad Versace <chad.versace at intel.com>
> + */
> +
> +/**
> + * \file hiz-util.c
> + * \copybrief hiz-util.h
> + * \author Chad Versace <chad.versace at intel.com>
> + */
> +
> +#include <assert.h>
> +#include <getopt.h>
> +#include "piglit-util.h"
> +#include "hiz/hiz-util.h"
> +
> +void
> +hiz_draw_rects()
> +{
> +	const float width_3 = piglit_width / 3.0;
> +	const float height_3 = piglit_height / 3.0;
> +
> +	glEnable(GL_DEPTH_TEST);
> +	glDepthFunc(GL_LESS);
> +	glClearDepth(hiz_clear_z);
> +	glClearColor(hiz_grey[0], hiz_grey[1], hiz_grey[2], hiz_grey[3]);
> +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
> +
> +	glViewport(0, 0, piglit_width, piglit_height);
> +	piglit_ortho_projection(piglit_width, piglit_height, false);
> +
> +	glColor4fv(hiz_green);
> +	glDepthRange(hiz_green_z, hiz_green_z);
> +	piglit_draw_rect(0 * width_3, 0 * width_3,   /* x, y */
> +		         2 * width_3, 2 * height_3); /* width, height */
> +
> +	glColor4fv(hiz_blue);
> +	glDepthRange(hiz_blue_z, hiz_blue_z);
> +	piglit_draw_rect(1 * width_3, 1 * height_3,   /* x, y */
> +		         2 * width_3, 2 * height_3); /* width, height */
> +
> +	glClearDepth(1.0);
> +	glDepthRange(0, 1);
> +}
> +
> +bool
> +hiz_probe_rects()
> +{
> +	bool pass = true;
> +	const float width_9 = piglit_width / 9.0;
> +	const float height_9 = piglit_height / 9.0;
> +
> +	/*
> +	 * For the color and depth probing below, the read buffer is
> +	 * decomposed as follows: Let (w,h) be the read buffer's dimentions.
> +	 * Divide the read buffer into 9 large rectangles of dimension (w/3,
> +	 * h/3). Subdivide each large rectangle into 9 small rectangles of
> +	 * dimension (w/9, h/9).
> +	 */
> +
> +	/*
> +	 * Probe the color of the center small rectangle of each large
> +	 * rectangle. The large rectangles are traversed in column major
> +	 * order, bottom to top and left to right.
> +	 *
> +	 * Such exhaustive probing is necessary because HiZ corruption may
> +	 * cause global artifacts in the scene.
> +	 */
> +	pass &= piglit_probe_rect_rgba(1 * width_9, 1 * height_9,
> +	                                   width_9,     height_9, hiz_green);
> +	pass &= piglit_probe_rect_rgba(1 * width_9, 4 * height_9,
> +	                                   width_9,     height_9, hiz_green);
> +	pass &= piglit_probe_rect_rgba(1 * width_9, 7 * height_9,
> +	                                   width_9,     height_9, hiz_grey);
> +	pass &= piglit_probe_rect_rgba(4 * width_9, 1 * height_9,
> +	                                   width_9,     height_9, hiz_green);
> +	pass &= piglit_probe_rect_rgba(4 * width_9, 4 * height_9,
> +	                                   width_9,     height_9, hiz_green);
> +	pass &= piglit_probe_rect_rgba(4 * width_9, 7 * height_9,
> +	                                   width_9,     height_9, hiz_blue);
> +	pass &= piglit_probe_rect_rgba(7 * width_9, 1 * height_9,
> +	                                   width_9,     height_9, hiz_grey);
> +	pass &= piglit_probe_rect_rgba(7 * width_9, 4 * height_9,
> +	                                   width_9,     height_9, hiz_blue);
> +	pass &= piglit_probe_rect_rgba(7 * width_9, 7 * height_9,
> +	                                   width_9,     height_9, hiz_blue);
> +
> +	/* Now probe the depths. */
> +	pass &= piglit_probe_rect_depth(1 * width_9, 1 * height_9,
> +	                                    width_9,     height_9, hiz_green_z);
> +	pass &= piglit_probe_rect_depth(1 * width_9, 4 * height_9,
> +	                                    width_9,     height_9, hiz_green_z);
> +	pass &= piglit_probe_rect_depth(1 * width_9, 7 * height_9,
> +	                                    width_9,     height_9, hiz_clear_z);
> +	pass &= piglit_probe_rect_depth(4 * width_9, 1 * height_9,
> +	                                    width_9,     height_9, hiz_green_z);
> +	pass &= piglit_probe_rect_depth(4 * width_9, 4 * height_9,
> +	                                    width_9,     height_9, hiz_green_z);
> +	pass &= piglit_probe_rect_depth(4 * width_9, 7 * height_9,
> +	                                    width_9,     height_9, hiz_blue_z);
> +	pass &= piglit_probe_rect_depth(7 * width_9, 1 * height_9,
> +	                                    width_9,     height_9, hiz_clear_z);
> +	pass &= piglit_probe_rect_depth(7 * width_9, 4 * height_9,
> +	                                    width_9,     height_9, hiz_blue_z);
> +	pass &= piglit_probe_rect_depth(7 * width_9, 7 * height_9,
> +	                                    width_9,     height_9, hiz_blue_z);
> +
> +	return pass;
> +}
> +
> +
> +GLuint
> +hiz_make_fbo(const struct hiz_fbo_options *options)
> +{
> +	GLuint fb = 0;
> +	GLenum fb_status;
> +	GLuint color_rb = 0;
> +	GLuint depth_rb = 0;
> +	GLuint stencil_rb = 0;
> +	GLuint depth_stencil_rb = 0;
> +
> +	glGenFramebuffers(1, &fb);
> +	glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb);
> +
> +	/* Bind color attachment. */
> +	if (options->color_format != 0) {
> +		glGenRenderbuffers(1, &color_rb);
> +		glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_rb);
> +		glRenderbufferStorage(GL_RENDERBUFFER_EXT,
> +		                      options->color_format,
> +		                      piglit_width, piglit_height);
> +		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
> +		                          GL_COLOR_ATTACHMENT0_EXT,
> +		                          GL_RENDERBUFFER_EXT,
> +		                          color_rb);
> +		assert(glGetError() == 0);
> +	}
> +
> +	/* Bind depth attachment. */
> +	if (options->depth_format != 0) {
> +		glGenRenderbuffers(1, &depth_rb);
> +		glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_rb);
> +		glRenderbufferStorage(GL_RENDERBUFFER_EXT,
> +		                      options->depth_format,
> +		                      piglit_width, piglit_height);
> +		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
> +		                          GL_DEPTH_ATTACHMENT_EXT,
> +		                          GL_RENDERBUFFER_EXT,
> +		                          depth_rb);
> +		assert(glGetError() == 0);
> +	}
> +
> +	/* Bind stencil attachment. */
> +	if (options->stencil_format != 0) {
> +		glGenRenderbuffers(1, &stencil_rb);
> +		glBindRenderbuffer(GL_RENDERBUFFER_EXT, stencil_rb);
> +		glRenderbufferStorage(GL_RENDERBUFFER_EXT,
> +		                      options->stencil_format,
> +		                      piglit_width, piglit_height);
> +		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
> +		                          GL_STENCIL_ATTACHMENT_EXT,
> +		                          GL_RENDERBUFFER_EXT,
> +		                          stencil_rb);
> +		assert(glGetError() == 0);
> +	}
> +
> +	/* Bind depth/stencil attachment. */
> +	if (options->depth_stencil_format != 0) {
> +		glGenRenderbuffers(1, &depth_stencil_rb);
> +		glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_stencil_rb);
> +		glRenderbufferStorage(GL_RENDERBUFFER_EXT,
> +		                      options->depth_stencil_format,
> +		                      piglit_width, piglit_height);
> +		glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
> +		                          GL_DEPTH_STENCIL_ATTACHMENT,
> +		                          GL_RENDERBUFFER_EXT,
> +		                          depth_stencil_rb);
> +		assert(glGetError() == 0);
> +	}
> +
> +	fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
> +	if (fb_status != GL_FRAMEBUFFER_COMPLETE_EXT) {
> +		printf("error: FBO incomplete (status = 0x%04x)\n", fb_status);
> +		piglit_report_result(PIGLIT_SKIP);
> +	}
> +
> +	return fb;
> +}
> +
> +void
> +hiz_delete_fbo(GLuint fbo)
> +{
> +	const GLenum *i;
> +	const GLenum attachments[] = {
> +		GL_COLOR_ATTACHMENT0_EXT,
> +		GL_DEPTH_STENCIL_ATTACHMENT,
> +		GL_DEPTH_ATTACHMENT_EXT,
> +		GL_STENCIL_ATTACHMENT_EXT,
> +		0
> +	};
> +
> +	for (i = attachments; *i != 0; ++i) {
> +		GLuint name;
> +		glGetFramebufferAttachmentParameterivEXT(
> +			GL_DRAW_FRAMEBUFFER_EXT,
> +			GL_COLOR_ATTACHMENT0_EXT,
> +			GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT,
> +			(GLint*) &name);
> +		if (name != 0)
> +			glDeleteRenderbuffersEXT(1, &name);
> +	}
> +
> +	glDeleteFramebuffersEXT(1, &fbo);
> +
> +	glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
> +	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
> +
> +	assert(!glGetError());
> +}
> +
> +bool
> +hiz_check_fbo_depth_test(const struct hiz_fbo_options *fbo_options)
> +{
> +	bool pass = true;
> +	GLuint fbo = 0;
> +
> +	piglit_require_extension("GL_EXT_framebuffer_object");
> +	piglit_require_extension("GL_EXT_framebuffer_blit");

I think we could probably just use ARB_fbo now.  We mostly want to test
the on GEN6, and ARB_fbo is supported there.  I think it's also
supported on the Gallium Radeon drivers (perhaps Marek can confirm that).

> +
> +	/* Create and bind FBO. */
> +	fbo = hiz_make_fbo(fbo_options);
> +	assert(fbo != 0);
> +	glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo);
> +	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo);
> +
> +	hiz_draw_rects();
> +	pass = hiz_probe_rects();
> +
> +	if (!piglit_automatic) {
> +		/* Blit the FBO to the window FB so we can see the results. */
> +		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
> +		glBlitFramebufferEXT(0, 0, piglit_width, piglit_height,
> +			             0, 0, piglit_width, piglit_height,
> +			             GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +		glutSwapBuffers();
> +		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo);
> +	}
> +
> +	hiz_delete_fbo(fbo);
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> diff --git a/tests/hiz/hiz-util.h b/tests/hiz/hiz-util.h
> new file mode 100644
> index 0000000..8d0a9fa
> --- /dev/null
> +++ b/tests/hiz/hiz-util.h
> @@ -0,0 +1,93 @@
> +/*
> + * Copyright © 2011 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.
> + *
> + * Authors:
> + *     Chad Versace <chad.versace at intel.com>
> + */
> +
> +/**
> + * \file hiz-util.h
> + * \brief Utilities for HiZ tests
> + * \author Chad Versace <chad.versace at intel.com>
> + */
> +
> +#pragma once
> +
> +#include <stdbool.h>
> +
> +struct hiz_fbo_options {
> +	GLenum color_format;
> +	GLenum depth_format;
> +	GLenum stencil_format;
> +	GLenum depth_stencil_format;
> +};
> +
> +static const GLfloat hiz_green[4]  = { 0.0, 1.0, 0.0, 1.0 };
> +static const GLfloat hiz_blue[4]   = { 0.0, 0.0, 1.0, 1.0 };
> +static const GLfloat hiz_grey[4]   = { 0.5, 0.5, 0.5, 1.0 };
> +
> +static const GLfloat hiz_green_z  = 0.25;
> +static const GLfloat hiz_blue_z   = 0.50;
> +static const GLfloat hiz_clear_z  = 0.875;
> +
> +/**
> + * \brief Draw two overlapping rectangles.
> + *
> + * Draw a green rectangle, then a blue one behind it.
> + * This draw function should be sufficient for all HiZ tests.
> + *
> + * Let (w, h) be the window's dimensions. Then the scene is as follows:
> + *     - glClearDepth: hiz_clear_z
> + *     - glClearColor: hiz_grey
> + *     - glDepthFunc: GL_LESS
> + *     - rectangle 1
> + *         - color: hiz_green
> + *         - x range: [0, 2/3 * w]
> + *         - y range: [0, 2/3 * h]
> + *         - z: hiz_green_z
> + *     - rectangle 2
> + *         - color: hiz_blue
> + *         - x range: [1/3 * w, w]
> + *         - y range: [1/3 * h, h]
> + *         - z: hiz_blue_z
> + */
> +void hiz_draw_rects();
> +
> +/**
> + * \brief Probe the scene drawn by hiz_draw_rects().
> + * \return True if all probes passed.
> + */
> +bool hiz_probe_rects();
> +
> +GLuint hiz_make_fbo(const struct hiz_fbo_options *options);
> +
> +/**
> + * \brief For Valgrind's sake, delete the FBO and all attached renderbuffers.
> + */
> +void hiz_delete_fbo(GLuint fbo);
> +
> +/**
> + * \brief Check that depth tests work correctly when rendering to an FBO.
> + * \param options Perform the test with an FBO with the given formats.
> + * \return True if test passed.
> + */
> +bool hiz_check_fbo_depth_test(const struct hiz_fbo_options *options);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk25uBoACgkQX1gOwKyEAw+KTgCfcEJ/CAL+rRHP3VoKluUj/Lxq
HdUAniYPNXNI3qtTNNFMaziHahSGMbj7
=M5BH
-----END PGP SIGNATURE-----


More information about the Piglit mailing list