Module: Mesa
Branch: main
Commit: f14e2ca099cbc1c732020b6e1c30aaff4f652d1b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f14e2ca099cbc1c732020b6e1c30aaff4f652d1b

Author: Iago Toral Quiroga <[email protected]>
Date:   Fri Nov 11 12:58:10 2022 +0100

v3dv: ignore imported BOs when tracking BO memory usage

Imported BOs are not allocated by the device so we don't
update BO stats when they are imported. Therefore, we should
not be updating them when they are freed either.

Reviewed-by: Alejandro PiƱeiro <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19675>

---

 src/broadcom/vulkan/v3dv_bo.c     | 32 +++++++++++++++++++++++---------
 src/broadcom/vulkan/v3dv_bo.h     |  4 ++++
 src/broadcom/vulkan/v3dv_device.c |  2 +-
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/broadcom/vulkan/v3dv_bo.c b/src/broadcom/vulkan/v3dv_bo.c
index f3c819fffc4..c51b1924560 100644
--- a/src/broadcom/vulkan/v3dv_bo.c
+++ b/src/broadcom/vulkan/v3dv_bo.c
@@ -142,15 +142,17 @@ bo_free(struct v3dv_device *device,
    if (ret != 0)
       fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno));
 
-   device->bo_count--;
-   device->bo_size -= bo->size;
-
-   if (dump_stats) {
-      fprintf(stderr, "Freed %s%s%dkb:\n",
-              bo->name ? bo->name : "",
-              bo->name ? " " : "",
-              bo->size / 1024);
-      bo_dump_stats(device);
+   if (!bo->is_import) {
+      device->bo_count--;
+      device->bo_size -= bo->size;
+
+      if (dump_stats) {
+         fprintf(stderr, "Freed %s%s%dkb:\n",
+                 bo->name ? bo->name : "",
+                 bo->name ? " " : "",
+                 bo->size / 1024);
+         bo_dump_stats(device);
+      }
    }
 
    /* Our BO structs are stored in a sparse array in the physical device,
@@ -198,9 +200,21 @@ v3dv_bo_init(struct v3dv_bo *bo,
    bo->name = name;
    bo->private = private;
    bo->dumb_handle = -1;
+   bo->is_import = false;
    list_inithead(&bo->list_link);
 }
 
+void
+v3dv_bo_init_import(struct v3dv_bo *bo,
+                    uint32_t handle,
+                    uint32_t size,
+                    uint32_t offset,
+                    bool private)
+{
+   v3dv_bo_init(bo, handle, size, offset, "import", private);
+   bo->is_import = true;
+}
+
 struct v3dv_bo *
 v3dv_bo_alloc(struct v3dv_device *device,
               uint32_t size,
diff --git a/src/broadcom/vulkan/v3dv_bo.h b/src/broadcom/vulkan/v3dv_bo.h
index 191c087dfb4..d7a48234677 100644
--- a/src/broadcom/vulkan/v3dv_bo.h
+++ b/src/broadcom/vulkan/v3dv_bo.h
@@ -52,6 +52,9 @@ struct v3dv_bo {
     */
    bool private;
 
+   /** If this BO has been imported */
+   bool is_import;
+
    /**
     * If this BO was allocated for a swapchain on the display device, the
     * handle of the dumb BO on that device.
@@ -62,6 +65,7 @@ struct v3dv_bo {
 };
 
 void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t 
offset, const char *name, bool private);
+void v3dv_bo_init_import(struct v3dv_bo *bo, uint32_t handle, uint32_t size, 
uint32_t offset, bool private);
 
 struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const 
char *name, bool private);
 
diff --git a/src/broadcom/vulkan/v3dv_device.c 
b/src/broadcom/vulkan/v3dv_device.c
index 4f3e2dae7b7..b86239d66ec 100644
--- a/src/broadcom/vulkan/v3dv_device.c
+++ b/src/broadcom/vulkan/v3dv_device.c
@@ -2278,7 +2278,7 @@ device_import_bo(struct v3dv_device *device,
    assert(*bo);
 
    if ((*bo)->refcnt == 0)
-      v3dv_bo_init(*bo, handle, size, get_offset.offset, "import", false);
+      v3dv_bo_init_import(*bo, handle, size, get_offset.offset, false);
    else
       p_atomic_inc(&(*bo)->refcnt);
 

Reply via email to