[Piglit] [PATCH 2/2] arb_es2_compatibility: Verify FBO blits with missing color doesn't crash
Ian Romanick
idr at freedesktop.org
Thu Jun 2 14:13:04 PDT 2011
From: Ian Romanick <ian.d.romanick at intel.com>
There are four ways this test can be run.
- Color/depth blit to an FBO w/o color with draw buffer = NONE
- Color/depth blit to an FBO w/o color with draw buffer != NONE (ES2
FBO completeness rules).
- Color/depth blit from an FBO w/o color with draw buffer = NONE
- Color/depth blit from an FBO w/o color with draw buffer != NONE
(ES2 FBO completeness rules).
In addition, after the blit the values in the depth buffer are probed
to make sure that part of the blit happened.
---
tests/all.tests | 4 +
tests/spec/arb_es2_compatibility/CMakeLists.gl.txt | 1 +
.../fbo-missing-attachment-blit.c | 216 ++++++++++++++++++++
3 files changed, 221 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/arb_es2_compatibility/fbo-missing-attachment-blit.c
diff --git a/tests/all.tests b/tests/all.tests
index a723ada..3dd3127 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -174,6 +174,8 @@ add_fbo_rg(fbo, 'GL_R16')
add_fbo_rg(fbo, 'GL_RG')
add_fbo_rg(fbo, 'GL_RG8')
add_fbo_rg(fbo, 'GL_RG16')
+fbo['FBO blit to missing attachment'] = PlainExecTest(['fbo-missing-attachment-blit', '-auto', 'to'])
+fbo['FBO blit from missing attachment'] = PlainExecTest(['fbo-missing-attachment-blit', '-auto', 'from'])
general = Group()
add_plain_test(general, 'bgra-sec-color-pointer')
@@ -715,6 +717,8 @@ add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-shadercompiler')
add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-releaseshadercompiler')
add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-fixed-type')
add_plain_test(arb_es2_compatibility, 'fbo-missing-attachment-clear')
+arb_es2_compatibility['FBO blit to missing attachment (ES2 completeness rules)'] = PlainExecTest(['fbo-missing-attachment-blit', '-auto', 'es2', 'to'])
+arb_es2_compatibility['FBO blit from missing attachment (ES2 completeness rules)'] = PlainExecTest(['fbo-missing-attachment-blit', '-auto', 'es2', 'from'])
# Group ARB_draw_instanced
arb_draw_instanced = Group()
diff --git a/tests/spec/arb_es2_compatibility/CMakeLists.gl.txt b/tests/spec/arb_es2_compatibility/CMakeLists.gl.txt
index e8c3d5c..7215134 100644
--- a/tests/spec/arb_es2_compatibility/CMakeLists.gl.txt
+++ b/tests/spec/arb_es2_compatibility/CMakeLists.gl.txt
@@ -22,4 +22,5 @@ add_executable (arb_es2_compatibility-shadercompiler arb_es2_compatibility-shade
add_executable (arb_es2_compatibility-getshaderprecisionformat arb_es2_compatibility-getshaderprecisionformat.c)
add_executable (arb_es2_compatibility-fixed-type arb_es2_compatibility-fixed-type.c)
add_executable (fbo-missing-attachment-clear fbo-missing-attachment-clear.c)
+add_executable (fbo-missing-attachment-blit fbo-missing-attachment-blit.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_es2_compatibility/fbo-missing-attachment-blit.c b/tests/spec/arb_es2_compatibility/fbo-missing-attachment-blit.c
new file mode 100644
index 0000000..5356505
--- /dev/null
+++ b/tests/spec/arb_es2_compatibility/fbo-missing-attachment-blit.c
@@ -0,0 +1,216 @@
+/*
+ * 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 fbo-missing-attachment-blit.c
+ * Verify that a color blit to a depth-only FBO doesn't crash
+ *
+ * From the ARB_ES2_compatibility spec:
+ *
+ * "(8) How should we handle draw buffer completeness?
+ *
+ * RESOLVED: Remove draw/readbuffer completeness checks, and treat
+ * drawbuffers referring to missing attachments as if they were NONE."
+ *
+ * From the ARB_framebuffer_object spec:
+ *
+ * "If a buffer is specified in <mask> and does not exist in both the
+ * read and draw framebuffers, the corresponding bit is silently
+ * ignored."
+ *
+ * It is valid to have a depth-only FBO that has the draw buffer set to values
+ * other than \c GL_NONE. However, doing operations that would read from or
+ * draw to these missing attachments should treat them as though they were
+ * \c GL_NONE (i.e., don't crash).
+ *
+ * This test can run in four modes:
+ *
+ * - From an FBO missing the color attachment with the ES2 rules.
+ * - From an FBO missing the color attachment without the ES2 rules.
+ * - To an FBO missing the color attachment with the ES2 rules.
+ * - To an FBO missing the color attachment without the ES2 rules.
+ *
+ * See also https://bugs.freedesktop.org/show_bug.cgi?id=37739.
+ *
+ * \author Ian Romanick <ian.d.romanick at intel.com>
+ */
+#include "piglit-util.h"
+
+int piglit_width = 32;
+int piglit_height = 32;
+int piglit_window_mode = GLUT_RGB;
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+bool
+do_blit_test(bool use_es2, bool from_missing_to_complete)
+{
+ GLuint rb[3];
+ GLuint fb[2];
+ GLenum status;
+ GLenum err;
+ const unsigned src = from_missing_to_complete ? 0 : 1;
+ const unsigned dst = 1 - src;
+ const char *const names[] = {
+ "buffer with missing attachment",
+ "complete buffer"
+ };
+ bool pass = true;
+
+ printf("Testing blit from %s to %s...\n", names[src], names[dst]);
+
+ /* Create a depth-only FBO and a depth/color FBO.
+ */
+ glGenRenderbuffers(ARRAY_SIZE(rb), rb);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, rb[0]);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
+ piglit_width, piglit_height);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb[1]);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
+ piglit_width, piglit_height);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb[2]);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
+ piglit_width, piglit_height);
+
+ glGenFramebuffers(ARRAY_SIZE(fb), fb);
+ glBindFramebuffer(GL_FRAMEBUFFER, fb[0]);
+ glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+ GL_RENDERBUFFER, rb[0]);
+ if (!use_es2) {
+ glDrawBuffer(GL_NONE);
+ glReadBuffer(GL_NONE);
+ }
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[1]);
+ glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+ GL_RENDERBUFFER, rb[1]);
+ glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_RENDERBUFFER, rb[2]);
+
+ err = glGetError();
+ if (err != 0) {
+ fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
+ return false;
+ }
+
+ /* Check completeness of the source surface.
+ */
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[src]);
+ status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "Read FBO erroneously incomplete: 0x%04x\n",
+ status);
+ return false;
+ }
+
+ /* In the source surface, clear the depth buffer and draw a single
+ * rectangle with a constant depth value. The depth test setting here
+ * is correct.
+ */
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[src]);
+ glClearDepth(0.0);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_ALWAYS);
+
+ piglit_draw_rect_z(0.5, -0.5, -0.5, 1.0, 1.0);
+
+ /* Check completeness of the destination surface.
+ */
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[dst]);
+ status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "Draw FBO erroneously incomplete: 0x%04x\n",
+ status);
+ return false;
+ }
+
+ glBlitFramebuffer(0, 0, piglit_width, piglit_height,
+ 0, 0, piglit_width, piglit_height,
+ GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
+ GL_NEAREST);
+ err = glGetError();
+ if (err != 0) {
+ fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
+ return false;
+ }
+
+ /* Probe depth values from the destination buffer to make sure the
+ * depth part of the blit actually happened.
+ */
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[dst]);
+ pass = piglit_probe_rect_depth(0.25 * piglit_width,
+ 0.25 * piglit_height,
+ 0.4 * piglit_width,
+ 0.4 * piglit_height,
+ 0.75);
+ pass = piglit_probe_rect_depth(0,
+ 0,
+ piglit_width,
+ 0.2 * piglit_height,
+ 0.0)
+ && pass;
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+ glDeleteFramebuffers(ARRAY_SIZE(fb), fb);
+ glDeleteRenderbuffers(ARRAY_SIZE(rb), rb);
+
+ return pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass;
+ bool use_es2 = false;
+ unsigned arg;
+
+ if (argc > 1 && strcmp(argv[1], "es2") == 0) {
+ use_es2 = true;
+ arg = 2;
+ } else {
+ arg = 1;
+ }
+
+ piglit_require_extension("GL_ARB_framebuffer_object");
+
+ if (use_es2)
+ piglit_require_extension("GL_ARB_ES2_compatibility");
+
+ if (argc > arg) {
+ pass = do_blit_test(use_es2,
+ strcmp(argv[arg], "from") == 0);
+ } else {
+ pass = do_blit_test(use_es2, true);
+ pass = do_blit_test(use_es2, false) && pass;
+ }
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
1.7.4
More information about the Piglit
mailing list