[Piglit] [PATCH 1/3] gl-3.0: Test clearing depth buffers with glClearBufferfv

Ian Romanick idr at freedesktop.org
Fri Nov 4 10:33:28 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This test passes on Mesa's swrast and Mesa's i965.  It fails on
NVIDIA's closed-source driver because they incorrectly generate a
GL_INVALID_ENUM error on the glClearBufferfv(GL_DEPTH) call when there
is no depth buffer.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/all.tests                            |    1 +
 tests/spec/gl-3.0/api/CMakeLists.gl.txt    |    1 +
 tests/spec/gl-3.0/api/clearbuffer-common.c |  180 ++++++++++++++++++++++++++++
 tests/spec/gl-3.0/api/clearbuffer-common.h |   33 +++++
 tests/spec/gl-3.0/api/clearbuffer-depth.c  |  158 ++++++++++++++++++++++++
 5 files changed, 373 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/gl-3.0/api/clearbuffer-common.c
 create mode 100644 tests/spec/gl-3.0/api/clearbuffer-common.h
 create mode 100644 tests/spec/gl-3.0/api/clearbuffer-depth.c

diff --git a/tests/all.tests b/tests/all.tests
index 6b18dda..13c8791 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -790,6 +790,7 @@ gl30 = Group()
 spec['!OpenGL 3.0'] = gl30
 add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')
 add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
+add_concurrent_test(gl30, 'clearbuffer-depth')
 
 # Group spec/glsl-1.00
 spec['glsl-1.00'] = Group()
diff --git a/tests/spec/gl-3.0/api/CMakeLists.gl.txt b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
index b90817f..8842884 100644
--- a/tests/spec/gl-3.0/api/CMakeLists.gl.txt
+++ b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
@@ -12,6 +12,7 @@ link_libraries (
 	${GLUT_glut_LIBRARY}
 )
 
+add_executable (clearbuffer-depth clearbuffer-common.c clearbuffer-depth.c)
 add_executable (clearbuffer-invalid-drawbuffer clearbuffer-invalid-drawbuffer.c)
 add_executable (clearbuffer-invalid-buffer clearbuffer-invalid-buffer.c)
 
diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.c b/tests/spec/gl-3.0/api/clearbuffer-common.c
new file mode 100644
index 0000000..0c1fc06
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.c
@@ -0,0 +1,180 @@
+/* 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.
+ */
+
+/**
+ * \file clearbuffer-common.c
+ * Common code and data for the basic glClearBuffer tests
+ */
+#include "piglit-util.h"
+
+const float default_color[4] = { 0.2, 0.4, 0.6, 1.0 };
+const float default_depth = 0.2;
+const int default_stencil = 0x7a;
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+GLuint
+generate_simple_fbo(bool color, bool stencil, bool depth, bool packed)
+{
+	GLuint fb;
+	GLuint rb[3];
+	GLenum status;
+
+	glGenFramebuffers(1, &fb);
+	glBindFramebuffer(GL_FRAMEBUFFER, fb);
+
+	glGenRenderbuffers(3, rb);
+
+	if (color) {
+		glBindRenderbuffer(GL_RENDERBUFFER, rb[0]);
+		glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
+				      piglit_width, piglit_height);
+
+		glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+					  GL_COLOR_ATTACHMENT0,
+					  GL_RENDERBUFFER,
+					  rb[0]);
+	} else {
+		/* If GL_ARB_ES2_compatibility is not supported, the GL
+		 * expects the draw buffer and read buffer be disabled if
+		 * there is no color buffer (to read or draw).
+		 */
+		glDrawBuffer(GL_NONE);
+		glReadBuffer(GL_NONE);
+	}
+
+	if (stencil) {
+		const GLenum format = (packed)
+			? GL_DEPTH24_STENCIL8
+			: GL_STENCIL_INDEX8;
+		const GLenum attachment = (packed)
+			? GL_DEPTH_STENCIL_ATTACHMENT
+			: GL_STENCIL_ATTACHMENT;
+
+		glBindRenderbuffer(GL_RENDERBUFFER, rb[1]);
+		glRenderbufferStorage(GL_RENDERBUFFER, format,
+				      piglit_width, piglit_height);
+
+		glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+					  attachment,
+					  GL_RENDERBUFFER,
+					  rb[1]);
+	}
+
+	if (!packed && depth) {
+		glBindRenderbuffer(GL_RENDERBUFFER, rb[2]);
+		glRenderbufferStorage(GL_RENDERBUFFER,
+				      GL_DEPTH_COMPONENT24,
+				      piglit_width, piglit_height);
+
+		glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+					  GL_DEPTH_ATTACHMENT,
+					  GL_RENDERBUFFER,
+					  rb[2]);
+	}
+
+	piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+
+	/* All of the possible combinations that we can generate are required
+	 * to be supported by all OpenGL 3.0 implementations, with one
+	 * exception.  As far as I can tell, implementations are not required
+	 * to support separate depth and stencil.  That one option is handled
+	 * specially.
+	 */
+	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if (status != GL_FRAMEBUFFER_COMPLETE
+	    && !(status == GL_FRAMEBUFFER_UNSUPPORTED && stencil && !packed)) {
+		fprintf(stderr,
+			"Framebuffer %s color, %s stencil (%s) was not "
+			"complete: 0x%04x\n",
+			color ? "with" : "without",
+			stencil ? "with" : "without",
+			packed ? "packed" : "separate",
+			status);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (status == GL_FRAMEBUFFER_UNSUPPORTED) {
+		glDeleteRenderbuffers(3, rb);
+		glDeleteFramebuffers(1, &fb);
+		return 0;
+	}
+
+	glClearColor(default_color[0],
+		     default_color[1],
+		     default_color[2],
+		     default_color[3]);
+	glClearDepth(default_depth);
+	glClearStencil(default_stencil);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
+		| GL_STENCIL_BUFFER_BIT);
+	glFinish();
+
+	piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+
+	return fb;
+}
+
+bool
+simple_probe(bool color, const float *color_value,
+	     bool stencil, int stencil_value,
+	     bool depth, float depth_value)
+{
+	bool pass = true;
+
+	if (color) {
+		if (!piglit_probe_rect_rgba(0, 0,
+					    piglit_width, piglit_height,
+					    color_value)) {
+			fprintf(stderr, "Bad color value.\n");
+			pass = false;
+		}
+	}
+
+	if (stencil) {
+		if (!piglit_probe_rect_stencil(0, 0,
+					       piglit_width, piglit_height,
+					       stencil_value)) {
+			fprintf(stderr, "Bad stencil value.\n");
+			pass = false;
+		}
+	}
+
+	if (depth) {
+		if (!piglit_probe_rect_depth(0, 0,
+					     piglit_width, piglit_height,
+					     depth_value)) {
+			fprintf(stderr, "Bad depth value.\n");
+			pass = false;
+		}
+	}
+
+	piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+	return pass;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.h b/tests/spec/gl-3.0/api/clearbuffer-common.h
new file mode 100644
index 0000000..e5afc51
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.h
@@ -0,0 +1,33 @@
+/* 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.
+ */
+
+extern const float default_color[4];
+extern const float default_depth;
+extern const int default_stencil;
+
+extern GLuint
+generate_simple_fbo(bool color, bool stencil, bool depth, bool packed);
+
+extern bool
+simple_probe(bool color, const float *color_value,
+	     bool stencil, int stencil_value,
+	     bool depth, float depth_value);
diff --git a/tests/spec/gl-3.0/api/clearbuffer-depth.c b/tests/spec/gl-3.0/api/clearbuffer-depth.c
new file mode 100644
index 0000000..02357a9
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-depth.c
@@ -0,0 +1,158 @@
+/* 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.
+ */
+
+/**
+ * \file clearbuffer-depth.c
+ * Verify clearing depth buffers with glClearBufferfv
+ *
+ * This test works by generating several framebuffer objects and attempting to
+ * clear the depth buffer of those FBOs by calling \c glClearBufferfv.
+ *
+ *     - An FBO with only a color attachment.  This should not generate an
+ *       error, but the color data should not be modified.
+ *
+ *     - An FBO with only a depth attachment.
+ *
+ *     - An FBO with a depth attachment and a color attachment.  The color
+ *       data should not be modified.
+ *
+ *     - An FBO with a depth attachment and a stencil attachment.  The stencil
+ *       data should not be modified.
+ *
+ *     - An FBO with a packed depth/stencil attachment.  The stencil data
+ *       should not be modified.
+ *
+ * In each case, \c glClearBufferfv is called twice.  Each call uses a
+ * different clear value.  This ensures that the test doesn't erroneously pass
+ * because the depth buffer was already filled with the clear color.
+ *
+ * \author Ian Romanick
+ */
+#include "piglit-util.h"
+#include "clearbuffer-common.h"
+
+void piglit_init(int argc, char **argv)
+{
+	static const struct {
+		bool color;
+		bool stencil;
+		bool depth;
+		bool packed;
+	} test_vectors[] = {
+		{ true,  false, false, false },
+		{ false, false, true,  false },
+		{ true,  false, true,  false },
+		{ false, true,  true,  false },
+		{ true,  true,  true,  false },
+		{ false, true,  true,  true },
+		{ true,  true,  true,  true },
+	};
+
+	static const float first[4]  = { 0.5, 1.0, 1.0, 1.0 };
+	static const float second[4] = { 0.8, 0.0, 0.0, 0.0 };
+
+	unsigned i;
+	bool pass = true;
+
+	piglit_require_gl_version(30);
+
+	for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
+		GLenum err;
+		GLuint fb = generate_simple_fbo(test_vectors[i].color,
+						test_vectors[i].stencil,
+						test_vectors[i].depth,
+						test_vectors[i].packed);
+
+		if (fb == 0) {
+			if (!piglit_automatic) {
+				printf("Skipping framebuffer %s color, "
+				       "%s depth, and "
+				       "%s stencil (%s).\n",
+				       test_vectors[i].color
+				       ? "with" : "without",
+				       test_vectors[i].depth
+				       ? "with" : "without",
+				       test_vectors[i].stencil
+				       ? "with" : "without",
+				       test_vectors[i].packed
+				       ? "packed" : "separate");
+			}
+
+			continue;
+		}
+
+		if (!piglit_automatic) {
+			printf("Trying framebuffer %s color, "
+			       "%s depth and "
+			       "%s stencil (%s)...\n",
+			       test_vectors[i].color ? "with" : "without",
+			       test_vectors[i].depth ? "with" : "without",
+			       test_vectors[i].stencil ? "with" : "without",
+			       test_vectors[i].packed ? "packed" : "separate");
+		}
+
+		/* The GL spec says nothing about generating an error for
+		 * clearing a buffer that does not exist.  Certainly glClear
+		 * does not.
+		 */
+		glClearBufferfv(GL_DEPTH, 0, first);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"First call to glClearBufferfv erroneously "
+				"generated a GL error (%s, 0x%04x)\n",
+				piglit_get_gl_error_name(err), err);
+			pass = false;
+		}
+
+		pass = simple_probe(test_vectors[i].color,
+				    default_color,
+				    test_vectors[i].stencil,
+				    default_stencil,
+				    test_vectors[i].depth,
+				    first[0])
+			&& pass;
+
+		glClearBufferfv(GL_DEPTH, 0, second);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"Second call to glClearBufferfv erroneously "
+				"generated a GL error (%s, 0x%04x)\n",
+				piglit_get_gl_error_name(err), err);
+			pass = false;
+		}
+
+		pass = simple_probe(test_vectors[i].color,
+				    default_color,
+				    test_vectors[i].stencil,
+				    default_stencil,
+				    test_vectors[i].depth,
+				    second[0])
+			&& pass;
+
+		glDeleteFramebuffers(1, &fb);
+		piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.6.4



More information about the Piglit mailing list