diff --git a/renderdoc/driver/vulkan/vk_memory.cpp b/renderdoc/driver/vulkan/vk_memory.cpp index 4bd4616c2..e023faedc 100644 --- a/renderdoc/driver/vulkan/vk_memory.cpp +++ b/renderdoc/driver/vulkan/vk_memory.cpp @@ -42,10 +42,19 @@ GPUAddressRange WrappedVulkan::CreateAddressRange(VkDevice device, VkBuffer buff VkResourceRecord *record = GetRecord(buffer); VkResourceRecord *memrecord = GetResourceManager()->GetResourceRecord(record->baseResourceMem); - // Just in case this is called when a buffer is being destroyed without being bound - if(!memrecord) + const bool isSparse = record->resInfo && record->resInfo->IsSparse(); + + // If the buffer is not sparse and there's no baseResourceMem, then the buffer is being destroyed + // without being bound so exit early as there's nothing to do + if(!isSparse && !memrecord) return {}; + // Sparse buffers may not have a single device allocation so set the OOB size to the same as the + // buffer + VkDeviceSize oobSize = record->memSize; + if(!isSparse && memrecord) + oobSize = memrecord->memSize - record->memOffset; + const VkBufferDeviceAddressInfo addrInfo = { VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO, NULL, @@ -58,7 +67,7 @@ GPUAddressRange WrappedVulkan::CreateAddressRange(VkDevice device, VkBuffer buff return { address, address + record->memSize, - address + (memrecord->memSize - record->memOffset), + address + oobSize, record->GetResourceID(), }; } diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index 3c1e95361..3a808940d 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -1912,11 +1912,17 @@ VkResult WrappedVulkan::vkCreateBuffer(VkDevice device, const VkBufferCreateInfo ObjDisp(device)->GetBufferMemoryRequirements(Unwrap(device), Unwrap(*pBuffer), &record->resInfo->memreqs); - // initialise the sparse page table if(isSparse) + { + // initialise the sparse page table record->resInfo->sparseTable.Initialise(pCreateInfo->size, record->resInfo->memreqs.alignment & 0xFFFFFFFFU); + // Track the buffer address. We only do this here for sparse buffers as they aren't + // bound against a single allocation + TrackBufferAddress(device, *pBuffer); + } + // for external buffers, try creating a non-external version and take the worst case of // memory requirements, in case the non-external one (as we will replay it) needs more // memory or a stricter alignment