venus: remember the memory bound to a swapchain image

It will be needed for VkBindImageMemorySwapchainInfoKHR.

Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14550>
This commit is contained in:
Chia-I Wu
2022-01-13 12:02:46 -08:00
committed by Marge Bot
parent 350dfb8c3c
commit 127263dc4a
5 changed files with 42 additions and 14 deletions
+3 -2
View File
@@ -515,9 +515,10 @@ vn_android_image_from_anb(struct vn_device *dev,
if (result != VK_SUCCESS)
goto fail;
img->is_wsi = true;
img->wsi.is_wsi = true;
/* Android WSI image owns the memory */
img->private_memory = memory;
img->wsi.memory = vn_device_memory_from_handle(memory);
img->wsi.memory_owned = true;
*out_img = img;
return VK_SUCCESS;
+3 -3
View File
@@ -126,13 +126,13 @@ vn_cmd_fix_image_memory_barrier(const struct vn_command_buffer *cmd,
out_barrier->newLayout != VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
return;
assert(img->is_wsi);
assert(img->wsi.is_wsi);
if (VN_PRESENT_SRC_INTERNAL_LAYOUT == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
return;
/* prime blit src or no layout transition */
if (img->is_prime_blit_src ||
if (img->wsi.is_prime_blit_src ||
out_barrier->oldLayout == out_barrier->newLayout) {
if (out_barrier->oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
out_barrier->oldLayout = VN_PRESENT_SRC_INTERNAL_LAYOUT;
@@ -1251,7 +1251,7 @@ vn_CmdCopyImageToBuffer(VkCommandBuffer commandBuffer,
/* sanity check */
const struct vn_image *img = vn_image_from_handle(srcImage);
prime_blit = img->is_wsi && img->is_prime_blit_src;
prime_blit = img->wsi.is_wsi && img->wsi.is_prime_blit_src;
assert(prime_blit);
}
+20 -2
View File
@@ -295,8 +295,10 @@ vn_DestroyImage(VkDevice device,
if (!img)
return;
if (img->private_memory != VK_NULL_HANDLE)
vn_FreeMemory(device, img->private_memory, pAllocator);
if (img->wsi.memory && img->wsi.memory_owned) {
VkDeviceMemory mem_handle = vn_device_memory_to_handle(img->wsi.memory);
vn_FreeMemory(device, mem_handle, pAllocator);
}
vn_async_vkDestroyImage(dev->instance, device, image, NULL);
@@ -396,6 +398,13 @@ vn_GetImageSparseMemoryRequirements2(
pSparseMemoryRequirements);
}
static void
vn_image_bind_wsi_memory(struct vn_image *img, struct vn_device_memory *mem)
{
assert(img->wsi.is_wsi && !img->wsi.memory);
img->wsi.memory = mem;
}
VkResult
vn_BindImageMemory(VkDevice device,
VkImage image,
@@ -403,8 +412,12 @@ vn_BindImageMemory(VkDevice device,
VkDeviceSize memoryOffset)
{
struct vn_device *dev = vn_device_from_handle(device);
struct vn_image *img = vn_image_from_handle(image);
struct vn_device_memory *mem = vn_device_memory_from_handle(memory);
if (img->wsi.is_wsi)
vn_image_bind_wsi_memory(img, mem);
if (mem->base_memory) {
memory = vn_device_memory_to_handle(mem->base_memory);
memoryOffset += mem->base_offset;
@@ -427,8 +440,13 @@ vn_BindImageMemory2(VkDevice device,
VkBindImageMemoryInfo *local_infos = NULL;
for (uint32_t i = 0; i < bindInfoCount; i++) {
const VkBindImageMemoryInfo *info = &pBindInfos[i];
struct vn_image *img = vn_image_from_handle(info->image);
struct vn_device_memory *mem =
vn_device_memory_from_handle(info->memory);
if (img->wsi.is_wsi)
vn_image_bind_wsi_memory(img, mem);
/* TODO handle VkBindImageMemorySwapchainInfoKHR */
if (!mem || !mem->base_memory)
continue;
+14 -5
View File
@@ -36,15 +36,24 @@ struct vn_image {
struct vn_image_memory_requirements requirements[4];
bool is_wsi;
bool is_prime_blit_src;
/* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
VkDeviceMemory private_memory;
/* For VK_ANDROID_external_memory_android_hardware_buffer, real image
* creation is deferred until bind image memory.
*/
struct vn_image_create_deferred_info *deferred_info;
struct {
/* True if this is a swapchain image and VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
* is a valid layout. A swapchain image can be created internally
* (wsi_image_create_info) or externally (VkNativeBufferANDROID).
*/
bool is_wsi;
bool is_prime_blit_src;
struct vn_device_memory *memory;
/* For VK_ANDROID_native_buffer, the WSI image owns the memory. */
bool memory_owned;
} wsi;
};
VK_DEFINE_NONDISP_HANDLE_CASTS(vn_image,
base.base,
+2 -2
View File
@@ -132,8 +132,8 @@ vn_wsi_create_image(struct vn_device *dev,
if (result != VK_SUCCESS)
return result;
img->is_wsi = true;
img->is_prime_blit_src = wsi_info->prime_blit_src;
img->wsi.is_wsi = true;
img->wsi.is_prime_blit_src = wsi_info->prime_blit_src;
*out_img = img;
return VK_SUCCESS;