venus/virtgpu: drop mappable if blob size is smaller than requested

Instead of failing the import, drop the mappable bit if blob size is
smaller than the requested alloc size, which defers the error to the
intended vkMapMemory api call if the client app requests Vulkan mapping
from the imported external memory.

Normally this won't occur if the app obeys the spec with a properly
implemented blob mem allocator. However, legacy allocators like minigbm
virtgpu_virgl backend could allocate via virgl w/o knowing the real blob
size from the guest side. The unsatified cases are external gralloc
images, which won't be mapped in any meaningful way after being
imported. This is to prepare dropping the force_unmappable workaround,
and to further prepare adopting common Android runtime.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36128>
This commit is contained in:
Yiwei Zhang 2025-07-13 20:28:42 -07:00 committed by Marge Bot
parent a6bbf544cf
commit 6c8f075fb3

View file

@ -1187,10 +1187,14 @@ virtgpu_bo_create_from_dma_buf(struct vn_renderer *renderer,
/* mmap_size is only used when mappable */
mmap_size = 0;
if (blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE) {
/* If queried blob size is smaller than requested allocation size, we
* drop the mappable flag to defer the mapping failure till the app's
* vkMapMemory api call.
*/
if (info.size < size)
goto fail;
mmap_size = size;
blob_flags &= ~VIRTGPU_BLOB_FLAG_USE_MAPPABLE;
else
mmap_size = size;
}
}