Mesa (main): venus: add vn_device_memory_alloc as a helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 3 06:02:46 UTC 2021


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

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Wed Jun  2 20:16:24 2021 -0700

venus: add vn_device_memory_alloc as a helper

It is used for the most common case (non-ahb, non-import, and
non-suballocate).

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

---

 src/virtio/vulkan/vn_device_memory.c | 45 +++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c
index 8b4feb62595..a92e24f87ce 100644
--- a/src/virtio/vulkan/vn_device_memory.c
+++ b/src/virtio/vulkan/vn_device_memory.c
@@ -220,6 +220,34 @@ vn_device_memory_import_dma_buf(struct vn_device *dev,
    return VK_SUCCESS;
 }
 
+static VkResult
+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);
+   VkDeviceMemory mem_handle = vn_device_memory_to_handle(mem);
+   VkResult result = vn_call_vkAllocateMemory(dev->instance, dev_handle,
+                                              alloc_info, NULL, &mem_handle);
+   if (result != VK_SUCCESS || !need_bo)
+      return result;
+
+   result = vn_renderer_bo_create_from_device_memory(
+      dev->renderer, mem->size, mem->base.id, flags, external_handles,
+      &mem->base_bo);
+   if (result != VK_SUCCESS) {
+      vn_async_vkFreeMemory(dev->instance, dev_handle, mem_handle, NULL);
+      return result;
+   }
+
+   vn_instance_roundtrip(dev->instance);
+
+   return VK_SUCCESS;
+}
+
 VkResult
 vn_AllocateMemory(VkDevice device,
                   const VkMemoryAllocateInfo *pAllocateInfo,
@@ -296,26 +324,15 @@ vn_AllocateMemory(VkDevice device,
          dev, pAllocateInfo->memoryTypeIndex, mem->size, &mem->base_memory,
          &mem->base_bo, &mem->base_offset);
    } else {
-      result = vn_call_vkAllocateMemory(dev->instance, device, pAllocateInfo,
-                                        NULL, &mem_handle);
+      result = vn_device_memory_alloc(
+         dev, mem, pAllocateInfo, need_bo, mem_type->propertyFlags,
+         export_info ? export_info->handleTypes : 0);
    }
    if (result != VK_SUCCESS) {
       vk_free(alloc, mem);
       return vn_error(dev->instance, result);
    }
 
-   if (need_bo && !mem->base_bo) {
-      result = vn_renderer_bo_create_from_device_memory(
-         dev->renderer, mem->size, mem->base.id, mem_type->propertyFlags,
-         export_info ? export_info->handleTypes : 0, &mem->base_bo);
-      if (result != VK_SUCCESS) {
-         vn_async_vkFreeMemory(dev->instance, device, mem_handle, NULL);
-         vk_free(alloc, mem);
-         return vn_error(dev->instance, result);
-      }
-      vn_instance_roundtrip(dev->instance);
-   }
-
    *pMemory = mem_handle;
 
    return VK_SUCCESS;



More information about the mesa-commit mailing list