venus: fix re-export of imported classic 3d resources

When the guest driver is Virgl while Xwayland is on Zink, Virgl can
request virtgpu classic 3d resource allocations for swapchain images.
Zink will import when the image is shared with xserver and will export
for fd info of all 2d images later to be forwarded.

Cc: mesa-stable
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25579>
This commit is contained in:
Yiwei Zhang 2023-10-05 23:41:54 -07:00 committed by Marge Bot
parent 3c61fd029b
commit ca3095672f

View file

@ -1161,18 +1161,19 @@ virtgpu_bo_create_from_dma_buf(struct vn_renderer *renderer,
if (virtgpu_ioctl_resource_info(gpu, gem_handle, &info))
goto fail;
uint32_t blob_flags;
size_t mmap_size;
/* Upon import, blob_flags is not passed to the kernel and is only for
* internal use. Set it to what works best for us.
* - blob mem: SHAREABLE + conditional MAPPABLE per VkMemoryPropertyFlags
* - classic 3d: SHAREABLE only for export and to fail the map
*/
uint32_t blob_flags = VIRTGPU_BLOB_FLAG_USE_SHAREABLE;
size_t mmap_size = 0;
if (info.blob_mem) {
/* must be VIRTGPU_BLOB_MEM_HOST3D or VIRTGPU_BLOB_MEM_GUEST_VRAM */
if (info.blob_mem != gpu->bo_blob_mem)
goto fail;
/* blob_flags is not passed to the kernel and is only for internal use
* on imports. Set it to what works best for us.
*/
blob_flags = virtgpu_bo_blob_flags(flags, 0);
blob_flags |= VIRTGPU_BLOB_FLAG_USE_SHAREABLE;
blob_flags |= virtgpu_bo_blob_flags(flags, 0);
/* mmap_size is only used when mappable */
mmap_size = 0;
@ -1182,13 +1183,6 @@ virtgpu_bo_create_from_dma_buf(struct vn_renderer *renderer,
mmap_size = size;
}
} else {
/* must be classic resource here
* set blob_flags to 0 to fail virtgpu_bo_map
* set mmap_size to 0 since mapping is not allowed
*/
blob_flags = 0;
mmap_size = 0;
}
/* we check bo->gem_handle instead of bo->refcount because bo->refcount