libdrm-radeon: unreference buffer once cs stream is submited or on cs clean
authorJerome Glisse <glisse@freedesktop.org>
Fri, 14 Nov 2008 11:13:53 +0000 (12:13 +0100)
committerJerome Glisse <glisse@freedesktop.org>
Fri, 14 Nov 2008 11:16:10 +0000 (12:16 +0100)
BO are referenced once by reloc to make sure that they not destroyed
before we get a chance to flush the cmd stream, so we need to unreference
them once in cs submit or cs erase if cs i never submitted so bo can
be destructed.

libdrm/radeon/radeon_cs_gem.c

index f9c9fab..9488f81 100644 (file)
@@ -251,7 +251,7 @@ static int cs_gem_emit(struct radeon_cs *cs)
 {
     struct cs_gem *csg = (struct cs_gem*)cs;
     uint64_t chunk_array[2];
-    int r;
+    int r, i;
 
     chunk_array[0] = (uint64_t)(intptr_t)&csg->chunks[0];
     chunk_array[1] = (uint64_t)(intptr_t)&csg->chunks[1];
@@ -261,10 +261,11 @@ static int cs_gem_emit(struct radeon_cs *cs)
 
     r = drmCommandWriteRead(cs->csm->fd, DRM_RADEON_CS2,
                             &csg->cs, sizeof(struct drm_radeon_cs2));
-    if (r) {
-        return r;
+    for (i = 0; i < csg->base.crelocs; i++) {
+        radeon_bo_unref(csg->relocs_bo[i]);
+        csg->relocs_bo[i] = NULL;
     }
-    return 0;
+    return r;
 }
 
 static int cs_gem_destroy(struct radeon_cs *cs)
@@ -281,7 +282,16 @@ static int cs_gem_destroy(struct radeon_cs *cs)
 static int cs_gem_erase(struct radeon_cs *cs)
 {
     struct cs_gem *csg = (struct cs_gem*)cs;
+    int i;
 
+    if (csg->relocs_bo) {
+        for (i = 0; i < csg->base.crelocs; i++) {
+            if (csg->relocs_bo[i]) {
+                radeon_bo_unref(csg->relocs_bo[i]);
+                csg->relocs_bo[i] = NULL;
+            }
+        }
+    }
     cs->relocs_total_size = 0;
     cs->cdw = 0;
     cs->section = 0;