Mesa (main): venus: let device track queue families used for device creation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 16 19:06:12 UTC 2022


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

Author: Yiwei Zhang <zzyiwei at chromium.org>
Date:   Thu May 19 22:23:32 2022 +0000

venus: let device track queue families used for device creation

Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Ryan Neph <ryanneph at google.com>
Reviewed-by: Chad Versace <chadversary at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16731>

---

 src/virtio/vulkan/vn_device.c | 51 +++++++++++++++++++++++++++++++++++++++++++
 src/virtio/vulkan/vn_device.h |  4 ++++
 2 files changed, 55 insertions(+)

diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c
index f1ffe2ed296..28b64bb1ce5 100644
--- a/src/virtio/vulkan/vn_device.c
+++ b/src/virtio/vulkan/vn_device.c
@@ -115,6 +115,47 @@ vn_device_init_queues(struct vn_device *dev,
    return VK_SUCCESS;
 }
 
+static bool
+vn_device_queue_family_init(struct vn_device *dev,
+                            const VkDeviceCreateInfo *create_info)
+{
+   const VkAllocationCallbacks *alloc = &dev->base.base.alloc;
+   uint32_t *queue_families = NULL;
+   uint32_t count = 0;
+
+   queue_families = vk_zalloc(
+      alloc, sizeof(*queue_families) * create_info->queueCreateInfoCount,
+      VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+   if (!queue_families)
+      return false;
+
+   for (uint32_t i = 0; i < create_info->queueCreateInfoCount; i++) {
+      const uint32_t index =
+         create_info->pQueueCreateInfos[i].queueFamilyIndex;
+      bool new_index = true;
+
+      for (uint32_t j = 0; j < count; j++) {
+         if (queue_families[j] == index) {
+            new_index = false;
+            break;
+         }
+      }
+      if (new_index)
+         queue_families[count++] = index;
+   }
+
+   dev->queue_families = queue_families;
+   dev->queue_family_count = count;
+
+   return true;
+}
+
+static inline void
+vn_device_queue_family_fini(struct vn_device *dev)
+{
+   vk_free(&dev->base.base.alloc, dev->queue_families);
+}
+
 static bool
 find_extension_names(const char *const *exts,
                      uint32_t ext_count,
@@ -291,6 +332,11 @@ vn_device_init(struct vn_device *dev,
    if (result != VK_SUCCESS)
       return result;
 
+   if (!vn_device_queue_family_init(dev, create_info)) {
+      result = VK_ERROR_OUT_OF_HOST_MEMORY;
+      goto out_destroy_device;
+   }
+
    for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++) {
       struct vn_device_memory_pool *pool = &dev->memory_pools[i];
       mtx_init(&pool->mutex, mtx_plain);
@@ -313,6 +359,9 @@ out_memory_pool_fini:
    for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++)
       vn_device_memory_pool_fini(dev, i);
 
+   vn_device_queue_family_fini(dev);
+
+out_destroy_device:
    vn_call_vkDestroyDevice(instance, dev_handle, NULL);
 
    return result;
@@ -379,6 +428,8 @@ vn_DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator)
    for (uint32_t i = 0; i < ARRAY_SIZE(dev->memory_pools); i++)
       vn_device_memory_pool_fini(dev, i);
 
+   vn_device_queue_family_fini(dev);
+
    /* We must emit vkDestroyDevice before freeing dev->queues.  Otherwise,
     * another thread might reuse their object ids while they still refer to
     * the queues in the renderer.
diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h
index 2a070630aa3..d85cf088b92 100644
--- a/src/virtio/vulkan/vn_device.h
+++ b/src/virtio/vulkan/vn_device.h
@@ -23,6 +23,10 @@ struct vn_device {
    struct vn_physical_device *physical_device;
    struct vn_renderer *renderer;
 
+   /* unique queue family indices in which to create the device queues */
+   uint32_t *queue_families;
+   uint32_t queue_family_count;
+
    struct vn_device_memory_pool memory_pools[VK_MAX_MEMORY_TYPES];
 
    struct vn_buffer_cache buffer_cache;



More information about the mesa-commit mailing list