nvk: Track and reference all device memory objects
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Tue, 31 Jan 2023 02:11:53 +0000 (20:11 -0600)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:57 +0000 (21:31 +0000)
This way bindless will work properly

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/nvk_device.c
src/nouveau/vulkan/nvk_device.h
src/nouveau/vulkan/nvk_device_memory.c
src/nouveau/vulkan/nvk_device_memory.h

index 9b5d738..8f45332 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "nvk_bo_sync.h"
 #include "nvk_cmd_buffer.h"
+#include "nvk_device_memory.h"
 #include "nvk_instance.h"
 #include "nvk_physical_device.h"
 
@@ -157,6 +158,13 @@ nvk_queue_submit(struct vk_queue *vkqueue, struct vk_queue_submit *submission)
          nouveau_ws_push_ref(cmd->push, bo_sync->bo, NOUVEAU_WS_BO_RDWR);
       }
 
+      simple_mtx_lock(&device->memory_objects_lock);
+      list_for_each_entry(struct nvk_device_memory, mem,
+                          &device->memory_objects, link) {
+         nouveau_ws_push_ref(cmd->push, mem->bo, NOUVEAU_WS_BO_RDWR);
+      }
+      simple_mtx_unlock(&device->memory_objects_lock);
+
       nouveau_ws_push_submit(cmd->push, device->pdev->dev, device->ctx);
       nouveau_ws_push_reset_refs(cmd->push, real_refs);
       if (cmd->reset_on_submit)
@@ -211,11 +219,14 @@ nvk_CreateDevice(VkPhysicalDevice physicalDevice,
       goto fail_init;
    }
 
+   list_inithead(&device->memory_objects);
+   simple_mtx_init(&device->memory_objects_lock, mtx_plain);
+
    result = nvk_descriptor_table_init(device, &device->images,
                                       8 * 4 /* tic entry size */,
                                       1024, 1024);
    if (result != VK_SUCCESS)
-      goto fail_ctx;
+      goto fail_memory_objects;
 
    /* Reserve the descriptor at offset 0 to be the null descriptor */
    ASSERTED uint32_t null_image_index;
@@ -278,7 +289,8 @@ fail_samplers:
    nvk_descriptor_table_finish(device, &device->samplers);
 fail_images:
    nvk_descriptor_table_finish(device, &device->images);
-fail_ctx:
+fail_memory_objects:
+   simple_mtx_destroy(&device->memory_objects_lock);
    nouveau_ws_context_destroy(device->ctx);
 fail_init:
    vk_device_finish(&device->vk);
@@ -309,6 +321,8 @@ nvk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator)
    vk_device_finish(&device->vk);
    nvk_descriptor_table_finish(device, &device->samplers);
    nvk_descriptor_table_finish(device, &device->images);
+   assert(list_is_empty(&device->memory_objects));
+   simple_mtx_destroy(&device->memory_objects_lock);
    nouveau_ws_context_destroy(device->ctx);
    vk_free(&device->vk.alloc, device);
 }
index 788dd54..01b085e 100644 (file)
@@ -36,6 +36,9 @@ struct nvk_device {
 
    struct nouveau_ws_context *ctx;
 
+   simple_mtx_t memory_objects_lock;
+   struct list_head memory_objects;
+
    struct nvk_descriptor_table images;
    struct nvk_descriptor_table samplers;
 
index 94797a7..184031d 100644 (file)
@@ -118,6 +118,10 @@ nvk_AllocateMemory(
       }
    }
 
+   simple_mtx_lock(&device->memory_objects_lock);
+   list_addtail(&mem->link, &device->memory_objects);
+   simple_mtx_unlock(&device->memory_objects_lock);
+
    *pMem = nvk_device_memory_to_handle(mem);
 
    return VK_SUCCESS;
@@ -143,6 +147,10 @@ nvk_FreeMemory(
    if (mem->map)
       nvk_UnmapMemory(_device, _mem);
 
+   simple_mtx_lock(&device->memory_objects_lock);
+   list_del(&mem->link);
+   simple_mtx_unlock(&device->memory_objects_lock);
+
    nouveau_ws_bo_destroy(mem->bo);
 
    vk_object_free(&device->vk, pAllocator, mem);
index 29cfb0c..d24947e 100644 (file)
@@ -3,9 +3,13 @@
 
 #include "nvk_private.h"
 
+#include "util/list.h"
+
 struct nvk_device_memory {
    struct vk_object_base base;
 
+   struct list_head link;
+
    struct nouveau_ws_bo *bo;
 
    void *map;