[Mesa-dev] i965: glClearBuffer() should only clear a single buffer.

Submitted by Iago Toral Quiroga on March 31, 2014, 12:17 p.m.

Details

Message ID 1396268228-20859-1-git-send-email-itoral@igalia.com
State Accepted
Commit a5957f7bc5e3618243f03cf9459394f9a83e5971
Headers show

Not browsing as part of any series.

Commit Message

Iago Toral Quiroga March 31, 2014, 12:17 p.m.
glClearBuffer() is currently clearing all active draw color buffers (all
buffers that have not been set to GL_NONE when calling glDrawBuffers) instead
of only clearing the one it receives as parameter. Altough brw_clear()
receives a bit mask indicating the color buffers that should be cleared,
this mask is ignored when calling brw_blorp_clear_color().

This was breaking the 'fbo-drawbuffers-none glClearBuffer' piglit test.

The patch provides the bit mask to brw_blorp_clear_color() so it can limit
clearing to the color buffers present in the mask.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76832
---
 src/mesa/drivers/dri/i965/brw_blorp.h         | 2 +-
 src/mesa/drivers/dri/i965/brw_blorp_clear.cpp | 6 +++++-
 src/mesa/drivers/dri/i965/brw_clear.c         | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h b/src/mesa/drivers/dri/i965/brw_blorp.h
index db41497..15a7a0b 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.h
+++ b/src/mesa/drivers/dri/i965/brw_blorp.h
@@ -48,7 +48,7 @@  brw_blorp_blit_miptrees(struct brw_context *brw,
 
 bool
 brw_blorp_clear_color(struct brw_context *brw, struct gl_framebuffer *fb,
-                      bool partial_clear);
+                      GLbitfield mask, bool partial_clear);
 
 void
 brw_blorp_resolve_color(struct brw_context *brw,
diff --git a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
index d16da97..9b3cc72 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
+++ b/src/mesa/drivers/dri/i965/brw_blorp_clear.cpp
@@ -569,12 +569,16 @@  do_single_blorp_clear(struct brw_context *brw, struct gl_framebuffer *fb,
 extern "C" {
 bool
 brw_blorp_clear_color(struct brw_context *brw, struct gl_framebuffer *fb,
-                      bool partial_clear)
+                      GLbitfield mask, bool partial_clear)
 {
    for (unsigned buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
       struct gl_renderbuffer *rb = fb->_ColorDrawBuffers[buf];
       struct intel_renderbuffer *irb = intel_renderbuffer(rb);
 
+      /* Only clear the buffers present in the provided mask */
+      if (((1 << fb->_ColorDrawBufferIndexes[buf]) & mask) == 0)
+         continue;
+
       /* If this is an ES2 context or GL_ARB_ES2_compatibility is supported,
        * the framebuffer can be complete with some attachments missing.  In
        * this case the _ColorDrawBuffers pointer will be NULL.
diff --git a/src/mesa/drivers/dri/i965/brw_clear.c b/src/mesa/drivers/dri/i965/brw_clear.c
index 6571e84..e9ba4d9 100644
--- a/src/mesa/drivers/dri/i965/brw_clear.c
+++ b/src/mesa/drivers/dri/i965/brw_clear.c
@@ -245,7 +245,7 @@  brw_clear(struct gl_context *ctx, GLbitfield mask)
    /* BLORP is currently only supported on Gen6+. */
    if (brw->gen >= 6 && brw->gen < 8) {
       if (mask & BUFFER_BITS_COLOR) {
-         if (brw_blorp_clear_color(brw, fb, partial_clear)) {
+         if (brw_blorp_clear_color(brw, fb, mask, partial_clear)) {
             debug_mask("blorp color", mask & BUFFER_BITS_COLOR);
             mask &= ~BUFFER_BITS_COLOR;
          }

Comments

Iago Toral Quiroga <itoral@igalia.com> writes:

> glClearBuffer() is currently clearing all active draw color buffers (all
> buffers that have not been set to GL_NONE when calling glDrawBuffers) instead
> of only clearing the one it receives as parameter. Altough brw_clear()
> receives a bit mask indicating the color buffers that should be cleared,
> this mask is ignored when calling brw_blorp_clear_color().
>
> This was breaking the 'fbo-drawbuffers-none glClearBuffer' piglit test.
>
> The patch provides the bit mask to brw_blorp_clear_color() so it can limit
> clearing to the color buffers present in the mask.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76832

Reviewed-by: Eric Anholt <eric@anholt.net>