[Mesa-dev] [PATCH 2/9] i915: take ownership rather than adding reference for new renderbuffers

Timothy Arceri tarceri at itsqueeze.com
Sat Apr 8 01:04:33 UTC 2017


This avoids locking in the reference calls and fixes a leak after the
RefCount initialisation was change from 0 to 1.

Fixes: 32141e53d1520 (mesa: tidy up renderbuffer RefCount initialisation)
---
 src/mesa/drivers/dri/i915/intel_screen.c | 9 +++++----
 src/mesa/main/renderbuffer.c             | 6 +++---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c
index fe86179..7e17e95 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -868,47 +868,48 @@ intelCreateBuffer(__DRIscreen * driScrnPriv,
       rgbFormat = MESA_FORMAT_B5G6R5_UNORM;
    else if (mesaVis->sRGBCapable)
       rgbFormat = MESA_FORMAT_B8G8R8A8_SRGB;
    else if (mesaVis->alphaBits == 0)
       rgbFormat = MESA_FORMAT_B8G8R8X8_UNORM;
    else
       rgbFormat = MESA_FORMAT_B8G8R8A8_UNORM;
 
    /* setup the hardware-based renderbuffers */
    rb = intel_create_renderbuffer(rgbFormat);
-   _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
 
    if (mesaVis->doubleBufferMode) {
       rb = intel_create_renderbuffer(rgbFormat);
-      _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
+      _mesa_add_renderbuffer_without_ref(fb, BUFFER_BACK_LEFT,
+                                            &rb->Base.Base);
    }
 
    /*
     * Assert here that the gl_config has an expected depth/stencil bit
     * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
     * which constructs the advertised configs.)
     */
    if (mesaVis->depthBits == 24) {
       assert(mesaVis->stencilBits == 8);
 
       /*
        * Use combined depth/stencil. Note that the renderbuffer is
        * attached to two attachment points.
        */
       rb = intel_create_private_renderbuffer(MESA_FORMAT_Z24_UNORM_S8_UINT);
-      _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
+      _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, &rb->Base.Base);
       _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
    }
    else if (mesaVis->depthBits == 16) {
       assert(mesaVis->stencilBits == 0);
       rb = intel_create_private_renderbuffer(MESA_FORMAT_Z_UNORM16);
-      _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
+      _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, &rb->Base.Base);
    }
    else {
       assert(mesaVis->depthBits == 0);
       assert(mesaVis->stencilBits == 0);
    }
 
    /* now add any/all software-based renderbuffers we may need */
    _swrast_add_soft_renderbuffers(fb,
                                   false, /* never sw color */
                                   false, /* never sw depth */
diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 6fcff35..6bf33de 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -106,23 +106,23 @@ _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 
 
 /**
  * Attach a renderbuffer to a framebuffer.
  * \param bufferName  one of the BUFFER_x tokens
  *
  * This function avoids adding a reference and is therefore intended to be
  * used with a freashly created renderbuffer.
  */
 void
-_mesa_attach_renderbuffer_without_ref(struct gl_framebuffer *fb,
-                                      gl_buffer_index bufferName,
-                                      struct gl_renderbuffer *rb)
+_mesa_add_renderbuffer_without_ref(struct gl_framebuffer *fb,
+                                   gl_buffer_index bufferName,
+                                   struct gl_renderbuffer *rb)
 {
    assert(fb);
    assert(rb);
    assert(bufferName < BUFFER_COUNT);
 
    /* There should be no previous renderbuffer on this attachment point,
     * with the exception of depth/stencil since the same renderbuffer may
     * be used for both.
     */
    assert(bufferName == BUFFER_DEPTH ||
-- 
2.9.3



More information about the mesa-dev mailing list