[Piglit] [PATCH] Add test for NV_depth_buffer_float.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Sun Sep 14 07:09:01 PDT 2014


From: Mathias Froehlich <Mathias.Froehlich at web.de>

Add two tests for NV_depth_buffer_float.
depth-range-nv does a first croase test of negative ranges.
depth-range-nv-precision tests an application use case that
gained a lot of popular attention lately.

Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de
---
 tests/all.py                                       |   5 +
 tests/spec/CMakeLists.txt                          |   1 +
 tests/spec/nv_depth_buffer_float/CMakeLists.gl.txt |  15 ++
 tests/spec/nv_depth_buffer_float/CMakeLists.txt    |   1 +
 .../depth-range-nv-precision.c                     | 170 +++++++++++++++++++++
 tests/spec/nv_depth_buffer_float/depth-range-nv.c  | 127 +++++++++++++++
 6 files changed, 319 insertions(+)
 create mode 100644 tests/spec/nv_depth_buffer_float/CMakeLists.gl.txt
 create mode 100644 tests/spec/nv_depth_buffer_float/CMakeLists.txt
 create mode 100644 tests/spec/nv_depth_buffer_float/depth-range-nv-precision.c
 create mode 100644 tests/spec/nv_depth_buffer_float/depth-range-nv.c

diff --git a/tests/all.py b/tests/all.py
index 6f82f5b..db94f64 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2331,6 +2331,11 @@ add_depthstencil_render_miplevels_tests(
          'ds=z32f_s8'))
 arb_depth_buffer_float['fbo-clear-formats stencil'] = concurrent_test('fbo-clear-formats GL_ARB_depth_buffer_float stencil')
 
+nv_depth_buffer_float = {}
+spec['NV_depth_buffer_float'] = nv_depth_buffer_float
+add_plain_test(nv_depth_buffer_float, 'depth-range-nv')
+add_plain_test(nv_depth_buffer_float, 'depth-range-nv-precision')
+
 arb_texture_env_crossbar = {}
 spec['ARB_texture_env_crossbar'] = arb_texture_env_crossbar
 add_plain_test(arb_texture_env_crossbar, 'crossbar')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index c448fd4..76c11f9 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -69,6 +69,7 @@ add_subdirectory (ext_texture_swizzle)
 add_subdirectory (ext_timer_query)
 add_subdirectory (ext_transform_feedback)
 add_subdirectory (nv_conditional_render)
+add_subdirectory (nv_depth_buffer_float)
 add_subdirectory (nv_texture_barrier)
 add_subdirectory (oes_compressed_etc1_rgb8_texture)
 add_subdirectory (oes_compressed_paletted_texture)
diff --git a/tests/spec/nv_depth_buffer_float/CMakeLists.gl.txt b/tests/spec/nv_depth_buffer_float/CMakeLists.gl.txt
new file mode 100644
index 0000000..1920b1b
--- /dev/null
+++ b/tests/spec/nv_depth_buffer_float/CMakeLists.gl.txt
@@ -0,0 +1,15 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (depth-range-nv depth-range-nv.c)
+piglit_add_executable (depth-range-nv-precision depth-range-nv-precision.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/nv_depth_buffer_float/CMakeLists.txt b/tests/spec/nv_depth_buffer_float/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/nv_depth_buffer_float/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/nv_depth_buffer_float/depth-range-nv-precision.c b/tests/spec/nv_depth_buffer_float/depth-range-nv-precision.c
new file mode 100644
index 0000000..3b020a7
--- /dev/null
+++ b/tests/spec/nv_depth_buffer_float/depth-range-nv-precision.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright Mathias Fröhlich <Mathias.Froehlich at web.de>
+ *
+ * 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:
+ *    Mathias Fröhlich <Mathias.Froehlich at web.de>
+ */
+
+/** @file depth-range-nv-precision.c
+ *
+ * Test for NV_depth_buffer_float not clamping the near and far values.
+ * This is actually the application level use case setting up a
+ * projection matrix with and infinite far away far plane and a near plane
+ * at 1.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLdouble projection[16] = { 0.0, };
+
+	piglit_require_extension("GL_NV_depth_buffer_float");
+	piglit_require_extension("GL_EXT_framebuffer_object");
+	piglit_require_extension("GL_EXT_framebuffer_blit");
+
+	/* Set up a projection matrix ranging from -1 to -inf
+	 * and mapping this to [-1, 0] in projection space leaving
+	 * the [0, 1] range mostly unused.
+	 * The basic trick with this is that due to the symmetric
+	 * depth range we get the extended precition of the float
+	 * for model z values close to -inf.
+	 */
+	projection[0 + 4*0] = 1;
+	projection[1 + 4*1] = (GLdouble)piglit_width/piglit_height;
+	projection[2 + 4*3] = -1;
+	projection[3 + 4*2] = -1;
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadMatrixd(projection);
+
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+}
+
+void
+quad(double px, double py, double pz, double size)
+{
+	glBegin(GL_QUADS);
+	glVertex3d(px - 0.5*size, py - 0.5*size, pz);
+	glVertex3d(px + 0.5*size, py - 0.5*size, pz);
+	glVertex3d(px + 0.5*size, py + 0.5*size, pz);
+	glVertex3d(px - 0.5*size, py + 0.5*size, pz);
+	glEnd();
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLfloat red[3] = { 1, 0, 0 };
+	GLfloat green[3] = { 0, 1, 0 };
+	GLboolean pass = GL_TRUE;
+	GLuint fb, cb, db;
+	GLenum status;
+	int range10;
+
+	glGenRenderbuffers(1, &cb);
+	glBindRenderbuffer(GL_RENDERBUFFER, cb);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, piglit_width, piglit_height);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenRenderbuffers(1, &db);
+	glBindRenderbuffer(GL_RENDERBUFFER, db);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F_NV, piglit_width, piglit_height);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenFramebuffers(1, &fb);
+	glBindFramebuffer(GL_FRAMEBUFFER, fb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, db);
+
+	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if (status != GL_FRAMEBUFFER_COMPLETE) {
+		printf("FBO incomplete status 0x%X\n", status);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* This is to illustrate the effect of the usual clamped
+	 * near far values. If you uncomment the below define, you will
+	 * not reliably see the green surfaces before the red ones.
+	 */
+/* #define DESTROY_DEPTH_PRECISION */
+#ifndef DESTROY_DEPTH_PRECISION
+	glClearDepthdNV(0);
+	glDepthRangedNV(-1, 1);
+#endif
+	glClearColor(0, 0, 0, 1);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glEnable(GL_DEPTH_TEST);
+	glDepthFunc(GL_LESS);
+
+	for (range10 = 0; range10 < 16; ++range10) {
+		int width = piglit_width/4;
+		int height = piglit_height/4;
+		int tilex = range10 % 4;
+		int tiley = range10 / 4;
+		int x = tilex*width;
+		int y = tiley*height;
+		double z = pow(10, 1 + range10);
+
+		/* Set up a new viewport for each deoth we want to test */
+		glViewport(x, y, width, height);
+
+		/* Draw a red surface at given distance z */
+		glColor3fv(red);
+		quad(0, 0, -z, z);
+
+		pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, red) && pass;
+
+		/* And a green one just close in front of that red one */
+		glColor3fv(green);
+		quad(0, 0, (10*FLT_EPSILON - 1)*z, 0.5*z);
+		quad(0, 0, -z, 0.5*z);
+
+		pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, green) && pass;
+	}
+
+	/* copy the result to the back buffer */
+
+	/* set viewport to window size */
+	glViewport(0, 0, piglit_width, piglit_height);
+
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width, piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+	glDeleteFramebuffers(1, &fb);
+	glDeleteRenderbuffers(1, &cb);
+	glDeleteRenderbuffers(1, &db);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/nv_depth_buffer_float/depth-range-nv.c b/tests/spec/nv_depth_buffer_float/depth-range-nv.c
new file mode 100644
index 0000000..e6abc16
--- /dev/null
+++ b/tests/spec/nv_depth_buffer_float/depth-range-nv.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright Mathias Fröhlich <Mathias.Froehlich at web.de>
+ *
+ * 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:
+ *    Mathias Fröhlich <Mathias.Froehlich at web.de>
+ */
+
+/** @file depth-range-nv.c
+ *
+ * Basic test for NV_depth_buffer_float not clamping the near and far values.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_NV_depth_buffer_float");
+	piglit_require_extension("GL_EXT_framebuffer_object");
+	piglit_require_extension("GL_EXT_framebuffer_blit");
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
+
+void
+quad(float base_x, float base_y, float z)
+{
+	glBegin(GL_QUADS);
+	glVertex3f(base_x,	base_y,	     z);
+	glVertex3f(base_x + 10, base_y,	     z);
+	glVertex3f(base_x + 10, base_y + 10, z);
+	glVertex3f(base_x,	base_y + 10, z);
+	glEnd();
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+
+	GLuint fb, cb, db;
+	glGenRenderbuffers(1, &cb);
+	glBindRenderbuffer(GL_RENDERBUFFER, cb);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 256, 256);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenRenderbuffers(1, &db);
+	glBindRenderbuffer(GL_RENDERBUFFER, db);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F_NV, 256, 256);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenFramebuffers(1, &fb);
+	glBindFramebuffer(GL_FRAMEBUFFER, fb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, db);
+
+	GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if (status != GL_FRAMEBUFFER_COMPLETE) {
+		printf("FBO incomplete status 0x%X\n", status);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	glClearDepthdNV(-0.5);
+	glClear(GL_DEPTH_BUFFER_BIT);
+	glEnable(GL_DEPTH_TEST);
+	glDepthFunc(GL_ALWAYS);
+
+	glDepthRangedNV(-1, 1);
+	quad(10, 10, -1.0);
+	quad(10, 30, -0.5);
+	quad(10, 50, 0);
+	quad(10, 70, 0.5);
+	quad(10, 90, 1.0);
+
+	/* The clear value */
+	pass = piglit_probe_pixel_depth(5, 5, -0.5) && pass;
+
+	/* The few patches drawn above */
+	pass = piglit_probe_pixel_depth(15, 15, 1.0) && pass;
+	pass = piglit_probe_pixel_depth(15, 35, 0.5) && pass;
+	pass = piglit_probe_pixel_depth(15, 55, 0.0) && pass;
+	pass = piglit_probe_pixel_depth(15, 75, -0.5) && pass;
+	pass = piglit_probe_pixel_depth(15, 95, -1.0) && pass;
+
+	/* copy the result to the back buffer */
+
+	/* set viewport to window size */
+	glViewport(0, 0, piglit_width, piglit_height);
+
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width, piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+	glDeleteFramebuffers(1, &fb);
+	glDeleteRenderbuffers(1, &cb);
+	glDeleteRenderbuffers(1, &db);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.9.3



More information about the Piglit mailing list