From 3a98f0e86f241b7682a95539b4fbd5369c737e5c Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 26 May 2025 14:12:12 +0200 Subject: [PATCH] radv: fix capture/replay with sparse images and descriptor buffer The sparse image VA needs to be returned to the application for replay. Reported by Baldur. VKCTS has coverage but it doesn't verify this yet. Cc: mesa-stable Signed-off-by: Samuel Pitoiset Part-of: (cherry picked from commit 63758bc093c69eef20500e843a9442e9e674241b) --- .pick_status.json | 2 +- src/amd/vulkan/radv_image.c | 26 ++++++++++++++++++++++++-- src/amd/vulkan/radv_physical_device.c | 6 ++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 94f3580df70..22d3ea150f9 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -584,7 +584,7 @@ "description": "radv: fix capture/replay with sparse images and descriptor buffer", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index 0e1367b7d0c..2aa76dfc5f4 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -1378,6 +1378,7 @@ radv_image_create(VkDevice _device, const struct radv_image_create_info *create_ assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO); const struct VkVideoProfileListInfoKHR *profile_list = vk_find_struct_const(pCreateInfo->pNext, VIDEO_PROFILE_LIST_INFO_KHR); + uint64_t replay_address = 0; unsigned plane_count = radv_get_internal_plane_count(pdev, format); @@ -1437,12 +1438,23 @@ radv_image_create(VkDevice _device, const struct radv_image_create_info *create_ } if (image->vk.create_flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) { + enum radeon_bo_flag flags = RADEON_FLAG_VIRTUAL; + + if (image->vk.create_flags & VK_IMAGE_CREATE_DESCRIPTOR_BUFFER_CAPTURE_REPLAY_BIT_EXT) { + flags |= RADEON_FLAG_REPLAYABLE; + + const VkOpaqueCaptureDescriptorDataCreateInfoEXT *opaque_info = + vk_find_struct_const(create_info->vk_info->pNext, OPAQUE_CAPTURE_DESCRIPTOR_DATA_CREATE_INFO_EXT); + if (opaque_info) + replay_address = *((const uint64_t *)opaque_info->opaqueCaptureDescriptorData); + } + image->alignment = MAX2(image->alignment, 4096); image->size = align64(image->size, image->alignment); image->bindings[0].offset = 0; - result = radv_bo_create(device, &image->vk.base, image->size, image->alignment, 0, RADEON_FLAG_VIRTUAL, - RADV_BO_PRIORITY_VIRTUAL, 0, true, &image->bindings[0].bo); + result = radv_bo_create(device, &image->vk.base, image->size, image->alignment, 0, flags, + RADV_BO_PRIORITY_VIRTUAL, replay_address, true, &image->bindings[0].bo); if (result != VK_SUCCESS) { radv_destroy_image(device, alloc, image); return vk_error(device, result); @@ -1907,3 +1919,13 @@ radv_GetImageDrmFormatModifierPropertiesEXT(VkDevice _device, VkImage _image, pProperties->drmFormatModifier = image->planes[0].surface.modifier; return VK_SUCCESS; } + +VKAPI_ATTR VkResult VKAPI_CALL +radv_GetImageOpaqueCaptureDescriptorDataEXT(VkDevice device, const VkImageCaptureDescriptorDataInfoEXT *pInfo, + void *pData) +{ + VK_FROM_HANDLE(radv_image, image, pInfo->image); + + *(uint64_t *)pData = image->bindings[0].bo_va; + return VK_SUCCESS; +} diff --git a/src/amd/vulkan/radv_physical_device.c b/src/amd/vulkan/radv_physical_device.c index bf0be2b35ad..be6cb596061 100644 --- a/src/amd/vulkan/radv_physical_device.c +++ b/src/amd/vulkan/radv_physical_device.c @@ -1815,9 +1815,11 @@ radv_get_physical_device_properties(struct radv_physical_device *pdev) .maxSamplerDescriptorBufferBindings = MAX_SETS, .maxEmbeddedImmutableSamplerBindings = MAX_SETS, .maxEmbeddedImmutableSamplers = radv_max_descriptor_set_size(), - /* No data required for capture/replay but these values need to be non-zero. */ + /* No data required for capture/replay (except for sparse images) but these values need to be + * non-zero. + */ .bufferCaptureReplayDescriptorDataSize = 1, - .imageCaptureReplayDescriptorDataSize = 1, + .imageCaptureReplayDescriptorDataSize = 8, .imageViewCaptureReplayDescriptorDataSize = 1, .samplerCaptureReplayDescriptorDataSize = 1, .accelerationStructureCaptureReplayDescriptorDataSize = 1,