[Mesa-dev] [PATCH 1/4] gallium/radeon/winsyses: fix counting mapped memory

Marek Olšák maraeo at gmail.com
Mon Sep 5 22:46:31 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

Not all buffers are unmapped explicitly.
---
 src/gallium/winsys/amdgpu/drm/amdgpu_bo.c     | 8 ++++++++
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
index a4bc474..32df0be 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
@@ -144,20 +144,28 @@ void amdgpu_bo_destroy(struct pb_buffer *_buf)
    amdgpu_va_range_free(bo->va_handle);
    amdgpu_bo_free(bo->bo);
 
    for (i = 0; i < RING_LAST; i++)
       amdgpu_fence_reference(&bo->fence[i], NULL);
 
    if (bo->initial_domain & RADEON_DOMAIN_VRAM)
       bo->ws->allocated_vram -= align64(bo->base.size, bo->ws->info.gart_page_size);
    else if (bo->initial_domain & RADEON_DOMAIN_GTT)
       bo->ws->allocated_gtt -= align64(bo->base.size, bo->ws->info.gart_page_size);
+
+   if (bo->map_count >= 1) {
+      if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+         bo->ws->mapped_vram -= bo->base.size;
+      else
+         bo->ws->mapped_gtt -= bo->base.size;
+   }
+
    FREE(bo);
 }
 
 static void amdgpu_bo_destroy_or_cache(struct pb_buffer *_buf)
 {
    struct amdgpu_winsys_bo *bo = amdgpu_winsys_bo(_buf);
 
    if (bo->use_reusable_pool)
       pb_cache_add_buffer(&bo->cache_entry);
    else
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
index 56aab48..5db2061 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
@@ -309,20 +309,28 @@ void radeon_bo_destroy(struct pb_buffer *_buf)
     /* Close object. */
     args.handle = bo->handle;
     drmIoctl(rws->fd, DRM_IOCTL_GEM_CLOSE, &args);
 
     pipe_mutex_destroy(bo->map_mutex);
 
     if (bo->initial_domain & RADEON_DOMAIN_VRAM)
         rws->allocated_vram -= align(bo->base.size, rws->info.gart_page_size);
     else if (bo->initial_domain & RADEON_DOMAIN_GTT)
         rws->allocated_gtt -= align(bo->base.size, rws->info.gart_page_size);
+
+    if (bo->map_count >= 1) {
+        if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+            bo->rws->mapped_vram -= bo->base.size;
+        else
+            bo->rws->mapped_gtt -= bo->base.size;
+    }
+
     FREE(bo);
 }
 
 static void radeon_bo_destroy_or_cache(struct pb_buffer *_buf)
 {
    struct radeon_bo *bo = radeon_bo(_buf);
 
    if (bo->use_reusable_pool)
       pb_cache_add_buffer(&bo->cache_entry);
    else
-- 
2.7.4



More information about the mesa-dev mailing list