From 75acc706f71bb3c1197ec28302b74f6530a78bc6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 11 Nov 2025 11:09:27 +0000 Subject: [PATCH] Try to create descriptor buffer buffer if failing to create wholeMemBuf * On some drivers such as radv there are memory types only accessible via descriptor buffer usage flags, and it's important to have a wholeMemBuf to readback both for maps (quite possible/likely) as well as initial contents. --- .../vulkan/wrappers/vk_resource_funcs.cpp | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index ff512a582..c238d3651 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -715,11 +715,38 @@ VkResult WrappedVulkan::vkAllocateMemory(VkDevice device, const VkMemoryAllocate } else { - // can't create a memory-spanning buffer for this allocation. Assume this is a case where - // this memory type is only available to images and is not mappable - in which case the - // whole memory buffer won't be needed so we can skip this. ObjDisp(device)->DestroyBuffer(Unwrap(device), wholeMemBuf, NULL); wholeMemBuf = VK_NULL_HANDLE; + + // can't create a memory-spanning buffer for this allocation. Try again with descriptor + // buffers if that is enabled as those memory types are sometimes unique. + if(DescriptorBuffers()) + { + bufInfo.usage |= VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT; + + ret = ObjDisp(device)->CreateBuffer(Unwrap(device), &bufInfo, NULL, &wholeMemBuf); + RDCASSERTEQUAL(ret, VK_SUCCESS); + + ObjDisp(device)->GetBufferMemoryRequirements(Unwrap(device), wholeMemBuf, &mrq); + + RDCASSERTEQUAL(mrq.size, info.allocationSize); + + if((mrq.memoryTypeBits & (1U << info.memoryTypeIndex)) != 0) + { + bufid = GetResourceManager()->WrapResource(Unwrap(device), wholeMemBuf); + + ObjDisp(device)->BindBufferMemory(Unwrap(device), Unwrap(wholeMemBuf), Unwrap(*pMemory), + 0); + } + else + { + ObjDisp(device)->DestroyBuffer(Unwrap(device), wholeMemBuf, NULL); + wholeMemBuf = VK_NULL_HANDLE; + } + } + + // Otherwise this could be a case where this memory type is only available to images and is + // not mappable - in which case the whole memory buffer shouldn't be needed so we can skip this. } }