[PATCH] early-z: add test to check for early depth testing bugs
Christoph Bumiller
e0425955 at student.tuwien.ac.at
Thu Mar 10 13:26:16 PST 2011
If early fragment tests cause the depth buffer to be also updated
before the fragment shader is run, it has to be disabled whenever
alpha testing is enabled or discard is used.
---
tests/all.tests | 1 +
tests/general/CMakeLists.gl.txt | 1 +
tests/general/early-z.c | 148 +++++++++++++++++++++++++++++++++++++++
3 files changed, 150 insertions(+), 0 deletions(-)
create mode 100644 tests/general/early-z.c
diff --git a/tests/all.tests b/tests/all.tests
index a3ec4f1..b285b1e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -187,6 +187,7 @@ add_plain_test(general, 'framebuffer-srgb')
add_plain_test(general, 'geterror-invalid-enum')
add_plain_test(general, 'geterror-inside-begin')
add_plain_test(general, 'hiz')
+add_plain_test(general, 'early-z')
add_plain_test(general, 'isbufferobj')
add_plain_test(general, 'line-aa-width')
add_plain_test(general, 'linestipple')
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index be8097a..55075c7 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -53,6 +53,7 @@ add_executable (hiz hiz.c)
if (UNIX)
target_link_libraries (hiz m)
endif (UNIX)
+add_executable (early-z early-z.c)
add_executable (isbufferobj isbufferobj.c)
add_executable (linestipple linestipple.c)
add_executable (line-aa-width line-aa-width.c)
diff --git a/tests/general/early-z.c b/tests/general/early-z.c
new file mode 100644
index 0000000..b4f6720
--- /dev/null
+++ b/tests/general/early-z.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2011 Christoph Bumiller
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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
+ * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
+ * 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
+ * Test for bugs with early depth testing and early depth update.
+ */
+
+#include "piglit-util.h"
+
+
+int piglit_width = 128;
+int piglit_height = 128;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH;
+
+static const char *fpFragDepthText =
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 1.0); \n"
+ " gl_FragDepth = 0.9; \n"
+ "} \n";
+
+static const char *fpDiscardText =
+ "void main() \n"
+ "{ \n"
+ " if (gl_Color.r > 0.25) \n"
+ " discard; \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 1.0); \n"
+ "} \n";
+
+static const char *fpAlphaText =
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 0.0); \n"
+ "} \n";
+
+
+static GLuint shader[3];
+static GLuint program[3];
+
+static void quad(const GLfloat z, uint32_t colour)
+{
+ glColor3ub(colour & 0xff, (colour >> 8) & 0xff, (colour >> 16) & 0xff);
+ glBegin(GL_QUADS);
+ glVertex3f(-1.0f, -1.0f, z);
+ glVertex3f(-1.0f, 1.0f, z);
+ glVertex3f( 1.0f, 1.0f, z);
+ glVertex3f( 1.0f, -1.0f, z);
+ glEnd();
+}
+
+static GLboolean
+test_early_depth(void)
+{
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearDepth(1.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LESS);
+
+ /* 1. (blue) depth should be adjusted to 0.9 by the FP */
+ glUseProgram(program[0]);
+ quad(0.3, 0xff0000);
+
+ /* 2. (red) should be discarded, no depth value written */
+ glUseProgram(program[1]);
+ quad(0.2, 0x0000ff);
+
+ /* 3. (white) should be discarded by the alpha test, no depth written */
+ glUseProgram(program[2]);
+ glEnable(GL_ALPHA_TEST);
+ glAlphaFunc(GL_GREATER, 0.5f);
+ quad(0.1, 0xffffff);
+ glDisable(GL_ALPHA_TEST);
+
+ /* 4. (green) should be drawn because depth is still 0.9 */
+ quad(0.7, 0x00ff00);
+
+ {
+ const GLfloat color[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
+ GLint pos[4];
+
+ /* use glRasterPos to determine where to read a sample pixel */
+ glRasterPos2f(0.0f, 0.0f);
+ glGetIntegerv(GL_CURRENT_RASTER_POSITION, pos);
+
+ if (!piglit_probe_pixel_rgba(pos[0], pos[1], color)) {
+ glutSwapBuffers();
+ return GL_FALSE;
+ }
+ }
+
+ glutSwapBuffers();
+
+ return GL_TRUE;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ if (!test_early_depth())
+ return PIGLIT_FAILURE;
+
+ return PIGLIT_SUCCESS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ int i;
+
+ shader[0] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpFragDepthText);
+ assert(shader[0]);
+
+ shader[1] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpDiscardText);
+ assert(shader[1]);
+
+ shader[2] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpAlphaText);
+ assert(shader[2]);
+
+ for (i = 0; i < 3; ++i)
+ program[i] = piglit_link_simple_program(shader[i], 0);
+}
--
1.7.3.4
--------------020802000208060107030202--
More information about the mesa-dev
mailing list