venus: workaround a blob_mem mappable size check issue
authorYiwei Zhang <zzyiwei@chromium.org>
Wed, 1 Sep 2021 21:30:36 +0000 (21:30 +0000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 1 Sep 2021 22:38:48 +0000 (22:38 +0000)
For blob_mem allocated from virtgpu_virgl backend, the guest mappable
size queried can be smaller than the size returned from image memory
requirement query from the host side. Here we temporarily workaround
until we switch to use cross-domain backend in minigbm.

Cc: 21.2.3 mesa-stable
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12687>

src/virtio/vulkan/vn_android.c
src/virtio/vulkan/vn_device_memory.c
src/virtio/vulkan/vn_device_memory.h

index 121f124..52901e7 100644 (file)
@@ -918,6 +918,7 @@ vn_android_device_import_ahb(struct vn_device *dev,
    int dup_fd = -1;
    uint64_t alloc_size = 0;
    uint32_t mem_type_bits = 0;
+   bool force_unmappable = false;
    VkResult result = VK_SUCCESS;
 
    handle = AHardwareBuffer_getNativeHandle(ahb);
@@ -960,6 +961,12 @@ vn_android_device_import_ahb(struct vn_device *dev,
       }
 
       alloc_size = mem_req.size;
+
+      /* XXX Workaround before we use cross-domain backend in minigbm. The
+       * blob_mem allocated from virgl backend can have a queried guest mappable
+       * size smaller than the size returned from image memory requirement.
+       */
+      force_unmappable = true;
    }
 
    if (dedicated_info && dedicated_info->buffer != VK_NULL_HANDLE) {
@@ -999,8 +1006,8 @@ vn_android_device_import_ahb(struct vn_device *dev,
       .allocationSize = alloc_size,
       .memoryTypeIndex = alloc_info->memoryTypeIndex,
    };
-   result =
-      vn_device_memory_import_dma_buf(dev, mem, &local_alloc_info, dup_fd);
+   result = vn_device_memory_import_dma_buf(dev, mem, &local_alloc_info,
+                                            force_unmappable, dup_fd);
    if (result != VK_SUCCESS) {
       close(dup_fd);
       return result;
index 89226dd..5a38cb4 100644 (file)
@@ -224,20 +224,23 @@ VkResult
 vn_device_memory_import_dma_buf(struct vn_device *dev,
                                 struct vn_device_memory *mem,
                                 const VkMemoryAllocateInfo *alloc_info,
+                                bool force_unmappable,
                                 int fd)
 {
    VkDevice device = vn_device_to_handle(dev);
    VkDeviceMemory memory = vn_device_memory_to_handle(mem);
    const VkPhysicalDeviceMemoryProperties *mem_props =
       &dev->physical_device->memory_properties.memoryProperties;
-   const VkMemoryType *mem_type =
-      &mem_props->memoryTypes[alloc_info->memoryTypeIndex];
+   VkMemoryPropertyFlags mem_flags =
+      mem_props->memoryTypes[alloc_info->memoryTypeIndex].propertyFlags;
    struct vn_renderer_bo *bo;
    VkResult result = VK_SUCCESS;
 
-   result = vn_renderer_bo_create_from_dma_buf(dev->renderer,
-                                               alloc_info->allocationSize, fd,
-                                               mem_type->propertyFlags, &bo);
+   if (force_unmappable)
+      mem_flags &= ~VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+
+   result = vn_renderer_bo_create_from_dma_buf(
+      dev->renderer, alloc_info->allocationSize, fd, mem_flags, &bo);
    if (result != VK_SUCCESS)
       return result;
 
@@ -355,7 +358,7 @@ vn_AllocateMemory(VkDevice device,
    } else if (export_ahb) {
       result = vn_android_device_allocate_ahb(dev, mem, pAllocateInfo, alloc);
    } else if (import_fd_info) {
-      result = vn_device_memory_import_dma_buf(dev, mem, pAllocateInfo,
+      result = vn_device_memory_import_dma_buf(dev, mem, pAllocateInfo, false,
                                                import_fd_info->fd);
    } else if (export_info) {
       result = vn_device_memory_alloc(dev, mem, pAllocateInfo, true,
index f480ad8..04f23d1 100644 (file)
@@ -47,6 +47,7 @@ VkResult
 vn_device_memory_import_dma_buf(struct vn_device *dev,
                                 struct vn_device_memory *mem,
                                 const VkMemoryAllocateInfo *alloc_info,
+                                bool force_unmappable,
                                 int fd);
 
 VkResult