Mesa (main): venus: track memory type property flags in vn_device_memory

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Dec 4 01:59:42 UTC 2021


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

Author: Yiwei Zhang <zzyiwei at chromium.org>
Date:   Fri Nov 19 06:27:13 2021 +0000

venus: track memory type property flags in vn_device_memory

Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13874>

---

 src/virtio/vulkan/vn_device_memory.c | 24 +++++++++++-------------
 src/virtio/vulkan/vn_device_memory.h |  1 +
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c
index 82f95e9bebc..0a65eae56d6 100644
--- a/src/virtio/vulkan/vn_device_memory.c
+++ b/src/virtio/vulkan/vn_device_memory.c
@@ -44,6 +44,7 @@ vn_device_memory_pool_grow_alloc(struct vn_device *dev,
 
    vn_object_base_init(&mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY, &dev->base);
    mem->size = size;
+   mem->flags = mem_flags;
 
    mem_handle = vn_device_memory_to_handle(mem);
    result = vn_call_vkAllocateMemory(
@@ -60,7 +61,7 @@ vn_device_memory_pool_grow_alloc(struct vn_device *dev,
    }
 
    result = vn_renderer_bo_create_from_device_memory(
-      dev->renderer, mem->size, mem->base.id, mem_flags, 0, &mem->base_bo);
+      dev->renderer, mem->size, mem->base.id, mem->flags, 0, &mem->base_bo);
    if (result != VK_SUCCESS) {
       assert(!mem->base_bo);
       goto fail;
@@ -187,7 +188,7 @@ vn_device_memory_pool_suballocate(struct vn_device *dev,
 
 static bool
 vn_device_memory_should_suballocate(const VkMemoryAllocateInfo *alloc_info,
-                                    const VkMemoryType *mem_type)
+                                    const VkMemoryPropertyFlags flags)
 {
    /* We should not support suballocations because apps can do better.  But
     * each BO takes up a KVM memslot currently and some CTS tests exhausts
@@ -196,7 +197,7 @@ vn_device_memory_should_suballocate(const VkMemoryAllocateInfo *alloc_info,
     */
 
    /* consider host-visible memory only */
-   if (!(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
+   if (!(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
       return false;
 
    /* reject larger allocations */
@@ -286,7 +287,6 @@ vn_device_memory_alloc(struct vn_device *dev,
                        struct vn_device_memory *mem,
                        const VkMemoryAllocateInfo *alloc_info,
                        bool need_bo,
-                       VkMemoryPropertyFlags flags,
                        VkExternalMemoryHandleTypeFlags external_handles)
 {
    VkDevice dev_handle = vn_device_to_handle(dev);
@@ -297,7 +297,7 @@ vn_device_memory_alloc(struct vn_device *dev,
       return result;
 
    result = vn_renderer_bo_create_from_device_memory(
-      dev->renderer, mem->size, mem->base.id, flags, external_handles,
+      dev->renderer, mem->size, mem->base.id, mem->flags, external_handles,
       &mem->base_bo);
    if (result != VK_SUCCESS) {
       vn_async_vkFreeMemory(dev->instance, dev_handle, mem_handle, NULL);
@@ -329,8 +329,8 @@ vn_AllocateMemory(VkDevice device,
 
    const VkPhysicalDeviceMemoryProperties *mem_props =
       &dev->physical_device->memory_properties.memoryProperties;
-   const VkMemoryType *mem_type =
-      &mem_props->memoryTypes[pAllocateInfo->memoryTypeIndex];
+   const VkMemoryPropertyFlags mem_flags =
+      mem_props->memoryTypes[pAllocateInfo->memoryTypeIndex].propertyFlags;
 
    const VkExportMemoryAllocateInfo *export_info = NULL;
    const VkImportAndroidHardwareBufferInfoANDROID *import_ahb_info = NULL;
@@ -366,6 +366,7 @@ vn_AllocateMemory(VkDevice device,
 
    vn_object_base_init(&mem->base, VK_OBJECT_TYPE_DEVICE_MEMORY, &dev->base);
    mem->size = pAllocateInfo->allocationSize;
+   mem->flags = mem_flags;
 
    VkDeviceMemory mem_handle = vn_device_memory_to_handle(mem);
    VkResult result;
@@ -379,16 +380,13 @@ vn_AllocateMemory(VkDevice device,
                                                import_fd_info->fd);
    } else if (export_info) {
       result = vn_device_memory_alloc(dev, mem, pAllocateInfo, true,
-                                      mem_type->propertyFlags,
                                       export_info->handleTypes);
-   } else if (vn_device_memory_should_suballocate(pAllocateInfo, mem_type)) {
+   } else if (vn_device_memory_should_suballocate(pAllocateInfo, mem_flags)) {
       result = vn_device_memory_pool_suballocate(
          dev, mem, pAllocateInfo->memoryTypeIndex);
    } else {
-      const bool need_bo =
-         mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
-      result = vn_device_memory_alloc(dev, mem, pAllocateInfo, need_bo,
-                                      mem_type->propertyFlags, 0);
+      const bool need_bo = mem_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+      result = vn_device_memory_alloc(dev, mem, pAllocateInfo, need_bo, 0);
    }
    if (result != VK_SUCCESS) {
       vn_object_base_fini(&mem->base);
diff --git a/src/virtio/vulkan/vn_device_memory.h b/src/virtio/vulkan/vn_device_memory.h
index aedd8465e68..88a602cdd29 100644
--- a/src/virtio/vulkan/vn_device_memory.h
+++ b/src/virtio/vulkan/vn_device_memory.h
@@ -23,6 +23,7 @@ struct vn_device_memory {
    struct vn_object_base base;
 
    VkDeviceSize size;
+   VkMemoryPropertyFlags flags;
 
    /* non-NULL when suballocated */
    struct vn_device_memory *base_memory;



More information about the mesa-commit mailing list