From 2eb028f31a1efe455d9e069ba669573c482958f3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 23 May 2025 14:23:31 +0100 Subject: [PATCH] Descriptor buffers must force on BDA for all memory * This is required for any images that will be bound to the memory --- renderdoc/driver/vulkan/vk_memory.cpp | 2 +- .../driver/vulkan/wrappers/vk_device_funcs.cpp | 5 +++-- .../driver/vulkan/wrappers/vk_resource_funcs.cpp | 15 ++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_memory.cpp b/renderdoc/driver/vulkan/vk_memory.cpp index 7d028b9e4..fc1699f48 100644 --- a/renderdoc/driver/vulkan/vk_memory.cpp +++ b/renderdoc/driver/vulkan/vk_memory.cpp @@ -395,7 +395,7 @@ MemoryAllocation WrappedVulkan::AllocateMemoryForResource(bool buffer, VkMemoryR }; VkMemoryAllocateInfo info = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - AccelerationStructures() ? &flagsInfo : NULL, + (DescriptorBuffers() || AccelerationStructures()) ? &flagsInfo : NULL, allocSize * 1024 * 1024, memoryTypeIndex, }; diff --git a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp index 1de93a240..c2a2a0e50 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_device_funcs.cpp @@ -4716,6 +4716,9 @@ VkResult WrappedVulkan::vkCreateDevice(VkPhysicalDevice physicalDevice, if(descBufFeatures && descBufFeatures->descriptorBuffer) { descBufFeatures->descriptorBufferCaptureReplay = VK_TRUE; + m_DescriptorBuffers = true; + + RDCLOG("descriptor buffers enabled, ALL MEMORY WILL BE MARKED AS BDA"); } VkResult ret; @@ -4923,8 +4926,6 @@ VkResult WrappedVulkan::vkCreateDevice(VkPhysicalDevice physicalDevice, if(m_EnabledExtensions.ext_EXT_descriptor_buffer && descBufFeatures && descBufFeatures->descriptorBuffer) { - m_DescriptorBuffers = true; - // if any update after bind feature is enabled, check robustBufferAccessUpdateAfterBind m_DescriptorBufferProperties = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT, diff --git a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp index c58bed248..b8d17492e 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_resource_funcs.cpp @@ -320,14 +320,15 @@ bool WrappedVulkan::Serialise_vkAllocateMemory(SerialiserType &ser, VkDevice dev { RDCDEBUG("Patching dedicated allocation for incompatible size"); - // if acceleration structures are used, we promote all non-dedicated memory to be BDA as - // we can't know if it will be used for an AS or not during capture. That means that - // during self-capture if we just remove the dedicated allocation structure here without - // any other changes the self-capture layer will promote it to BDA and potentially cause - // clashes with reserved addresses elsewhere. + // if acceleration structures or descriptor buffers are used, we promote all non-dedicated + // memory to be BDA as we can't know if it will be used for an AS or not during capture. + // That means that during self-capture if we just remove the dedicated allocation + // structure here without any other changes the self-capture layer will promote it to BDA + // and potentially cause clashes with reserved addresses elsewhere. + // // instead we do the more dangerous thing of adjusting the allocation size to match the // image's memory requirements and keep the dedicated allocation. - if(AccelerationStructures()) + if(AccelerationStructures() || DescriptorBuffers()) patched.allocationSize = mrq.size; else RemoveNextStruct(&patched, VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO); @@ -562,7 +563,7 @@ VkResult WrappedVulkan::vkAllocateMemory(VkDevice device, const VkMemoryAllocate // means that when RT is enabled ALL MEMORY IN THE ENTIRE PROGRAM must be marked as BDA just in // case. bool forceBDA = false; - if(IsCaptureMode(m_State) && AccelerationStructures()) + if(IsCaptureMode(m_State) && (AccelerationStructures() || DescriptorBuffers())) { // force BDA flag when creating, by adding the struct if needed forceBDA = true;