venus: track prime blit dst buffer memory in the wsi image

This is to prepare for handling implicit fence from the compositor.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34516>
This commit is contained in:
Yiwei Zhang 2025-05-17 01:19:02 -07:00 committed by Marge Bot
parent fef64b7e7d
commit 5535184539
4 changed files with 36 additions and 1 deletions

View file

@ -48,6 +48,11 @@ struct vn_buffer {
struct vn_object_base base;
struct vn_buffer_memory_requirements requirements;
struct {
/* buffer is prime blit dst */
struct vn_device_memory *mem;
} wsi;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(vn_buffer,
base.vk,

View file

@ -1481,6 +1481,19 @@ vn_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
uint32_t regionCount,
const VkBufferImageCopy *pRegions)
{
struct vn_image *img = vn_image_from_handle(srcImage);
struct vn_buffer *buf = vn_buffer_from_handle(dstBuffer);
/* The prime blit dst buffer is internal to common wsi layer. Only the
* corresponding wsi image can blit to it.
*/
if (buf->wsi.mem) {
assert(img->wsi.is_wsi);
assert(img->wsi.is_prime_blit_src);
assert(!img->wsi.blit_mem);
img->wsi.blit_mem = buf->wsi.mem;
}
VN_CMD_ENQUEUE(vkCmdCopyImageToBuffer, commandBuffer, srcImage,
srcImageLayout, dstBuffer, regionCount, pRegions);
}

View file

@ -363,14 +363,18 @@ vn_AllocateMemory(VkDevice device,
const VkImportMemoryFdInfoKHR *import_fd_info = NULL;
const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL;
const struct wsi_memory_allocate_info *wsi_info = NULL;
vk_foreach_struct_const(pnext, pAllocateInfo->pNext) {
switch (pnext->sType) {
switch ((uint32_t)pnext->sType) {
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
import_fd_info = (const void *)pnext;
break;
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO:
dedicated_info = (const void *)pnext;
break;
case VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA:
wsi_info = (const void *)pnext;
break;
default:
break;
}
@ -391,6 +395,16 @@ vn_AllocateMemory(VkDevice device,
import_fd_info->fd);
} else {
result = vn_device_memory_alloc(dev, mem, pAllocateInfo);
/* track prime blit dst buffer memory */
if (wsi_info && result == VK_SUCCESS) {
assert(dedicated_info);
if (dedicated_info->buffer != VK_NULL_HANDLE) {
struct vn_buffer *buf =
vn_buffer_from_handle(dedicated_info->buffer);
buf->wsi.mem = mem;
}
}
}
vn_device_memory_emit_report(dev, mem, /* is_alloc */ true, result);

View file

@ -79,6 +79,9 @@ struct vn_image {
struct vn_device_memory *memory;
/* memory backing the prime blit dst buffer */
struct vn_device_memory *blit_mem;
/* For VK_ANDROID_native_buffer, the WSI image owns the memory. */
bool memory_owned;
} wsi;