diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c index 121f124853f..52901e75bd0 100644 --- a/src/virtio/vulkan/vn_android.c +++ b/src/virtio/vulkan/vn_android.c @@ -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; diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c index 89226dde332..5a38cb416f9 100644 --- a/src/virtio/vulkan/vn_device_memory.c +++ b/src/virtio/vulkan/vn_device_memory.c @@ -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, diff --git a/src/virtio/vulkan/vn_device_memory.h b/src/virtio/vulkan/vn_device_memory.h index f480ad811bc..04f23d10541 100644 --- a/src/virtio/vulkan/vn_device_memory.h +++ b/src/virtio/vulkan/vn_device_memory.h @@ -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