[Piglit] [PATCH 1/3] hiz: Add tests for stencil testing

Chad Versace chad at chad-versace.us
Thu May 19 07:55:13 PDT 2011


Add the following tests:
    hiz-stencil-test-fbo-d0-s8
    hiz-stencil-test-fbo-d24-s8
    hiz-stencil-test-fbo-d24s8
    hiz-stencil-test-window-depth0
    hiz-stencil-test-window-depth1

These tests check that stencil testing works correctly when rendering to
an FBO.  They probe only the color buffer; they do not probe the stencil
buffer.

These tests does not probe the stencil buffer because correct operation of
1) stencil testing and stencil writes (via glDraw*) and of 2) stencil
buffer reads (via glRead*) are independent. It is possible for 1 to work
while 2 to fail. These tests cover only case 1.

Signed-off-by: Chad Versace <chad.versace at intel.com>
---
 tests/all.tests                            |    5 +
 tests/hiz/CMakeLists.gl.txt                |    5 +
 tests/hiz/hiz-stencil-test-fbo-d0-s8.c     |   65 ++++++++++++++++
 tests/hiz/hiz-stencil-test-fbo-d24-s8.c    |   66 ++++++++++++++++
 tests/hiz/hiz-stencil-test-fbo-d24s8.c     |   65 ++++++++++++++++
 tests/hiz/hiz-stencil-test-window-depth0.c |   55 +++++++++++++
 tests/hiz/hiz-stencil-test-window-depth1.c |   55 +++++++++++++
 tests/hiz/hiz-util.c                       |  114 ++++++++++++++++++++++++++++
 tests/hiz/hiz-util.h                       |   26 ++++++
 9 files changed, 456 insertions(+), 0 deletions(-)
 create mode 100644 tests/hiz/hiz-stencil-test-fbo-d0-s8.c
 create mode 100644 tests/hiz/hiz-stencil-test-fbo-d24-s8.c
 create mode 100644 tests/hiz/hiz-stencil-test-fbo-d24s8.c
 create mode 100644 tests/hiz/hiz-stencil-test-window-depth0.c
 create mode 100644 tests/hiz/hiz-stencil-test-window-depth1.c

diff --git a/tests/all.tests b/tests/all.tests
index a18cbfe..927e7cc 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1043,6 +1043,11 @@ add_plain_test(hiz, 'hiz-depth-test-fbo-d24-s8')
 add_plain_test(hiz, 'hiz-depth-test-fbo-d24s8')
 add_plain_test(hiz, 'hiz-depth-test-window-stencil0')
 add_plain_test(hiz, 'hiz-depth-test-window-stencil1')
+add_plain_test(hiz, 'hiz-stencil-test-fbo-d0-s8')
+add_plain_test(hiz, 'hiz-stencil-test-fbo-d24-s8')
+add_plain_test(hiz, 'hiz-stencil-test-fbo-d24s8')
+add_plain_test(hiz, 'hiz-stencil-test-window-depth0')
+add_plain_test(hiz, 'hiz-stencil-test-window-depth1')
 
 asmparsertest = Group()
 def add_asmparsertest(group, shader):
diff --git a/tests/hiz/CMakeLists.gl.txt b/tests/hiz/CMakeLists.gl.txt
index 05e02da..d9ba5b2 100644
--- a/tests/hiz/CMakeLists.gl.txt
+++ b/tests/hiz/CMakeLists.gl.txt
@@ -29,5 +29,10 @@ add_executable(hiz-depth-test-fbo-d24-s8 hiz-depth-test-fbo-d24-s8.c)
 add_executable(hiz-depth-test-fbo-d24s8 hiz-depth-test-fbo-d24s8.c)
 add_executable(hiz-depth-test-window-stencil0 hiz-depth-test-window-stencil0.c)
 add_executable(hiz-depth-test-window-stencil1 hiz-depth-test-window-stencil1.c)
+add_executable(hiz-stencil-test-fbo-d0-s8 hiz-stencil-test-fbo-d0-s8.c)
+add_executable(hiz-stencil-test-fbo-d24-s8 hiz-stencil-test-fbo-d24-s8.c)
+add_executable(hiz-stencil-test-fbo-d24s8 hiz-stencil-test-fbo-d24s8.c)
+add_executable(hiz-stencil-test-window-depth0 hiz-stencil-test-window-depth0.c)
+add_executable(hiz-stencil-test-window-depth1 hiz-stencil-test-window-depth1.c)
 
 # vim: ft=cmake:
diff --git a/tests/hiz/hiz-stencil-test-fbo-d0-s8.c b/tests/hiz/hiz-stencil-test-fbo-d0-s8.c
new file mode 100644
index 0000000..1deade3
--- /dev/null
+++ b/tests/hiz/hiz-stencil-test-fbo-d0-s8.c
@@ -0,0 +1,65 @@
+/*
+ * 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-stencil-test-fbo-d0-s8.c
+ *
+ * Check that stencil testing works correctly when rendering to an FBO with the
+ * following attachments:
+ *     - GL_COLOR_ATTACHMENT0: GL_RGBA
+ *     - GL_STENCIL_ATTACHMENT: GL_STENCIL_INDEX8
+ *
+ * \author Chad Versace <chad.versace at intel.com>
+ */
+
+#include "piglit-util.h"
+#include "hiz/hiz-util.h"
+
+int piglit_width = 400;
+int piglit_height = 400;
+int piglit_window_mode = GLUT_RGB;
+
+struct hiz_fbo_options fbo_options = {
+	GL_RGBA,
+	0,
+	GL_STENCIL_INDEX8,
+	0,
+};
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* empty */
+}
+
+enum piglit_result
+piglit_display()
+{
+	if (hiz_run_test_stencil_test_fbo(&fbo_options))
+		return PIGLIT_PASS;
+	else
+		return PIGLIT_FAIL;
+}
diff --git a/tests/hiz/hiz-stencil-test-fbo-d24-s8.c b/tests/hiz/hiz-stencil-test-fbo-d24-s8.c
new file mode 100644
index 0000000..1767ab7
--- /dev/null
+++ b/tests/hiz/hiz-stencil-test-fbo-d24-s8.c
@@ -0,0 +1,66 @@
+/*
+ * 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-stencil-test-fbo-d24-s8.c
+ *
+ * Check that stencil testing works correctly when rendering to an FBO with the
+ * following attachments:
+ *     - GL_COLOR_ATTACHMENT0: GL_RGBA
+ *     - GL_DEPTH_ATTACHMENT: GL_DEPTH_COMPONENT24
+ *     - GL_STENCIL_ATTACHMENT: GL_STENCIL_INDEX8
+ *
+ * \author Chad Versace <chad.versace at intel.com>
+ */
+
+#include "piglit-util.h"
+#include "hiz/hiz-util.h"
+
+int piglit_width = 400;
+int piglit_height = 400;
+int piglit_window_mode = GLUT_RGB;
+
+struct hiz_fbo_options fbo_options = {
+	GL_RGBA,
+	GL_DEPTH_COMPONENT24,
+	GL_STENCIL_INDEX8,
+	0,
+};
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* empty */
+}
+
+enum piglit_result
+piglit_display()
+{
+	if (hiz_run_test_stencil_test_fbo(&fbo_options))
+		return PIGLIT_PASS;
+	else
+		return PIGLIT_FAIL;
+}
diff --git a/tests/hiz/hiz-stencil-test-fbo-d24s8.c b/tests/hiz/hiz-stencil-test-fbo-d24s8.c
new file mode 100644
index 0000000..09a3007
--- /dev/null
+++ b/tests/hiz/hiz-stencil-test-fbo-d24s8.c
@@ -0,0 +1,65 @@
+/*
+ * 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-stencil-test-fbo-d24s8.c
+ *
+ * Check that stencil testing works correctly when rendering to an FBO with the
+ * following attachments:
+ *     - GL_COLOR_ATTACHMENT0: GL_RGBA
+ *     - GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH24_STENCIL8
+ *
+ * \author Chad Versace <chad.versace at intel.com>
+ */
+
+#include "piglit-util.h"
+#include "hiz/hiz-util.h"
+
+int piglit_width = 400;
+int piglit_height = 400;
+int piglit_window_mode = GLUT_RGB;
+
+struct hiz_fbo_options fbo_options = {
+	GL_RGBA,
+	0,
+	0,
+	GL_DEPTH24_STENCIL8,
+};
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* empty */
+}
+
+enum piglit_result
+piglit_display()
+{
+	if (hiz_run_test_stencil_test_fbo(&fbo_options))
+		return PIGLIT_PASS;
+	else
+		return PIGLIT_FAIL;
+}
diff --git a/tests/hiz/hiz-stencil-test-window-depth0.c b/tests/hiz/hiz-stencil-test-window-depth0.c
new file mode 100644
index 0000000..9555af5
--- /dev/null
+++ b/tests/hiz/hiz-stencil-test-window-depth0.c
@@ -0,0 +1,55 @@
+/*
+ * 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-stencil-test-window-depth0.c
+ * \author Chad Versace <chad.versace at intel.com>
+ *
+ * Check that stencil testing works correctly when rendering to a window
+ * framebuffer for which no depth buffer was requested.
+ */
+
+#include "piglit-util.h"
+#include "hiz/hiz-util.h"
+
+int piglit_width = 400;
+int piglit_height = 400;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_STENCIL;
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* empty */
+}
+
+enum piglit_result
+piglit_display()
+{
+	if (hiz_run_test_stencil_test_window())
+		return PIGLIT_PASS;
+	else
+		return PIGLIT_FAIL;
+}
diff --git a/tests/hiz/hiz-stencil-test-window-depth1.c b/tests/hiz/hiz-stencil-test-window-depth1.c
new file mode 100644
index 0000000..d04e136
--- /dev/null
+++ b/tests/hiz/hiz-stencil-test-window-depth1.c
@@ -0,0 +1,55 @@
+/*
+ * 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-stencil-test-window-depth1.c
+ * \author Chad Versace <chad.versace at intel.com>
+ *
+ * Check that stencil testing works correctly when rendering to a window
+ * framebuffer with a depth buffer.
+ */
+
+#include "piglit-util.h"
+#include "hiz/hiz-util.h"
+
+int piglit_width = 400;
+int piglit_height = 400;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_STENCIL | GLUT_DEPTH;
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* empty */
+}
+
+enum piglit_result
+piglit_display()
+{
+	if (hiz_run_test_stencil_test_window())
+		return PIGLIT_PASS;
+	else
+		return PIGLIT_FAIL;
+}
diff --git a/tests/hiz/hiz-util.c b/tests/hiz/hiz-util.c
index 13ce8c7..60df8c9 100644
--- a/tests/hiz/hiz-util.c
+++ b/tests/hiz/hiz-util.c
@@ -292,3 +292,117 @@ hiz_run_test_depth_test_window()
 }
 
 /** \} */
+
+/* ------------------------------------------------------------------------ */
+
+/**
+ * \name hiz_run_stencil_test utilties
+ *
+ * Utilities for testing stencil testing.
+ *
+ * \{
+ */
+
+/**
+ * Common functionality needed by hiz_run_test_stencil_test_fbo() and
+ * hiz_run_test_stencil_test_window().
+ */
+static bool
+hiz_run_test_stencil_test_common()
+{
+	static const float *expected_colors[9] = {
+		hiz_green,
+		hiz_green,
+		hiz_grey,
+
+		hiz_green,
+		hiz_blue,
+		hiz_grey,
+
+		hiz_grey,
+		hiz_blue,
+		hiz_grey,
+	};
+
+	const float dx = piglit_width / 3.0;
+	const float dy = piglit_height / 3.0;
+
+	/* Set up depth state. */
+	glDisable(GL_DEPTH_TEST);
+	glClearDepth(hiz_clear_z);
+
+	/* Set up stencil state. */
+	glEnable(GL_STENCIL_TEST);
+	glClearStencil(3); /* 3 is a good canary. */
+	glStencilFunc(GL_LESS, 3, ~0);
+	glStencilOp(GL_INCR, GL_INCR, GL_INCR);
+
+	glClearColor(hiz_grey[0], hiz_grey[1], hiz_grey[2], hiz_grey[3]);
+	glClear(GL_COLOR_BUFFER_BIT
+		| GL_DEPTH_BUFFER_BIT
+		| GL_STENCIL_BUFFER_BIT);
+
+	glViewport(0, 0, piglit_width, piglit_height);
+	piglit_ortho_projection(piglit_width, piglit_height, false);
+
+	/* Draw rect 1. */
+	glColor4fv(hiz_grey);
+	piglit_draw_rect(0 * dx, 0 * dy, /* x, y */
+			 2 * dx, 3 * dy); /* w, h */
+
+	/* Draw rect 2. */
+	glColor4fv(hiz_green);
+	piglit_draw_rect(0 * dx, 0 * dy,  /* x, y */
+			 2 * dx, 2 * dy); /* w, h */
+
+	/* Draw rect 3. */
+	glColor4fv(hiz_blue);
+	piglit_draw_rect(1 * dx, 1 * dy,   /* x, y */
+		         2 * dx, 2 * dy);  /* w, h */
+
+	assert(!glGetError());
+
+	return hiz_probe_color_buffer(expected_colors);
+}
+
+bool
+hiz_run_test_stencil_test_fbo(const struct hiz_fbo_options *fbo_options)
+{
+	bool pass = true;
+	GLuint fbo = 0;
+
+	piglit_require_extension("GL_ARB_framebuffer_object");
+
+	/* Create and bind FBO. */
+	fbo = hiz_make_fbo(fbo_options);
+	assert(fbo != 0);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+
+	pass = hiz_run_test_stencil_test_common();
+
+	if (!piglit_automatic) {
+		/* Blit the FBO to the window FB so we can see the results. */
+		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+		glBlitFramebuffer(0, 0, piglit_width, piglit_height,
+			          0, 0, piglit_width, piglit_height,
+			          GL_COLOR_BUFFER_BIT, GL_NEAREST);
+		glutSwapBuffers();
+		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	}
+
+	hiz_delete_fbo(fbo);
+
+	return pass;
+}
+
+bool
+hiz_run_test_stencil_test_window()
+{
+	bool pass = hiz_run_test_stencil_test_common();
+	if (!piglit_automatic)
+		glutSwapBuffers();
+	return pass;
+}
+
+/** \} */
diff --git a/tests/hiz/hiz-util.h b/tests/hiz/hiz-util.h
index 55747b2..7b95f1f 100644
--- a/tests/hiz/hiz-util.h
+++ b/tests/hiz/hiz-util.h
@@ -93,3 +93,29 @@ bool hiz_run_test_depth_test_fbo(const struct hiz_fbo_options *options);
  * \return True if test passed.
  */
 bool hiz_run_test_depth_test_window();
+
+/**
+ * \brief Check that stencil testing works correctly when rendering to an FBO.
+ *
+ * This test probes only the color buffer; it does not probe the stencil
+ * buffer.
+ *
+ * This test does not probe the stencil buffer because correct operation of 1)
+ * stencil testing and stencil writes (via glDraw*) and of 2) stencil buffer
+ * reads (via glRead*) are independent. It is possible for 1 to work while
+ * 2 to fail. This test covers only case 1.
+ *
+ * \param options Perform the test with an FBO with the given formats.
+ * \return True if test passed.
+ */
+bool hiz_run_test_stencil_test_fbo(const struct hiz_fbo_options *options);
+
+/**
+ * Check that stencil tests work correctly when rendering to the window
+ * framebuffer.
+ *
+ * \param options Perform the test with an FBO with the given formats.
+ * \return True if test passed.
+ * \see hiz_run_test_stencil_test_fbo()
+ */
+bool hiz_run_test_stencil_test_window();
-- 
1.7.5.1



More information about the Piglit mailing list