radeon: dri2 don't forget to free buffer
authorJerome Glisse <glisse@freedesktop.org>
Fri, 14 Nov 2008 10:25:28 +0000 (11:25 +0100)
committerJerome Glisse <glisse@freedesktop.org>
Fri, 14 Nov 2008 10:26:17 +0000 (11:26 +0100)
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/r300/radeon_context.c
src/mesa/drivers/dri/radeon/radeon_screen.c

index bb2f0937c131022939d663d4aa18964a7b8da4d8..30efc0b6dbcd9b94dcf6aca080e80f88c6d91916 100644 (file)
@@ -486,6 +486,17 @@ void r300SetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
     }
 
     radeon_update_renderbuffers(pDRICtx, dPriv);
+    /* back & depth buffer are useless free them right away */
+    rb = (void*)fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+        rb->bo = NULL;
+    }
+    rb = (void*)fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+        rb->bo = NULL;
+    }
     rb = (void*)fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
     if (rb->bo == NULL) {
         /* Failed to BO for the buffer */
index 9bb95a5a32596c9bc043264fadeab87a75f6b3a7..3a1ab8d96ed706e4504656aaed498d2219a77b31 100644 (file)
@@ -191,6 +191,37 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
  */
 void radeonCleanupContext(radeonContextPtr radeon)
 {
+    FILE *track;
+       struct radeon_renderbuffer *rb;
+       GLframebuffer *fb;
+    
+    fb = (void*)radeon->dri.drawable->driverPrivate;
+    rb = (void *)fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    fb = (void*)radeon->dri.readable->driverPrivate;
+    rb = (void *)fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+
        /* _mesa_destroy_context() might result in calls to functions that
         * depend on the DriverCtx, so don't set it to NULL before.
         *
@@ -204,6 +235,11 @@ void radeonCleanupContext(radeonContextPtr radeon)
                FREE(radeon->state.scissor.pClipRects);
                radeon->state.scissor.pClipRects = 0;
        }
+    track = fopen("/tmp/tracklog", "w");
+    if (track) {
+        radeon_tracker_print(&radeon->radeonScreen->bom->tracker, track);
+        fclose(track);
+    }
 }
 
 
@@ -363,6 +399,10 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
         switch (buffers[i].attachment) {
         case __DRI_BUFFER_FRONT_LEFT:
             rb = (void *)draw->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+            if (rb->bo) {
+                radeon_bo_unref(rb->bo);
+                rb->bo = NULL;
+            }
             rb->cpp = buffers[i].cpp;
             rb->pitch = buffers[i].pitch;
             rb->width = drawable->w;
@@ -381,6 +421,10 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
             break;
         case __DRI_BUFFER_BACK_LEFT:
             rb = (void *)draw->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+            if (rb->bo) {
+                radeon_bo_unref(rb->bo);
+                rb->bo = NULL;
+            }
             rb->cpp = buffers[i].cpp;
             rb->pitch = buffers[i].pitch;
             rb->width = drawable->w;
@@ -395,6 +439,10 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
             break;
         case __DRI_BUFFER_DEPTH:
             rb = (void *)draw->Attachment[BUFFER_DEPTH].Renderbuffer;
+            if (rb->bo) {
+                radeon_bo_unref(rb->bo);
+                rb->bo = NULL;
+            }
             rb->cpp = buffers[i].cpp;
             rb->pitch = buffers[i].pitch;
             rb->width = drawable->w;
@@ -447,7 +495,7 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
         if (driDrawPriv != driReadPriv)
             radeon_update_renderbuffers(driContextPriv, driReadPriv);
         radeon->state.color.rrb =
-            (void *)dfb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+            (void *)dfb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
         radeon->state.depth_buffer =
             (void *)dfb->Attachment[BUFFER_DEPTH].Renderbuffer;
     }
index 9cc91ac197f9b306e4fbd199b403c2796a31a151..93131d269cd17744736c1f74f81b917806438da8 100644 (file)
@@ -1059,6 +1059,7 @@ radeonDestroyScreen( __DRIscreenPrivate *sPriv )
         return;
 
     if (sPriv->dri2.enabled) {
+        radeon_tracker_print(&screen->bom->tracker, stderr);
         radeon_bo_manager_gem_shutdown(screen->bom);
     } else {
         radeon_bo_manager_legacy_shutdown(screen->bom);
@@ -1357,6 +1358,22 @@ radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 radeonDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
+       struct radeon_renderbuffer *rb;
+       GLframebuffer *fb;
+    
+    fb = (void*)driDrawPriv->driverPrivate;
+    rb = (void *)fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
+    rb = (void *)fb->Attachment[BUFFER_DEPTH].Renderbuffer;
+    if (rb && rb->bo) {
+        radeon_bo_unref(rb->bo);
+    }
    _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }