Fix validation issue with ASs as memory can't be used without buffer

This commit is contained in:
baldurk
2025-04-16 12:37:23 +01:00
parent f9d03761b3
commit abb0b9d843
3 changed files with 17 additions and 3 deletions
@@ -173,6 +173,16 @@ VulkanAccelerationStructureManager::VulkanAccelerationStructureManager(WrappedVu
{
}
void VulkanAccelerationStructureManager::Cleanup()
{
if(!scratchBuffers.empty())
{
const VkDevice d = m_pDriver->GetDev();
for(VkBuffer buf : scratchBuffers)
ObjDisp(d)->DestroyBuffer(Unwrap(d), buf, NULL);
}
}
RDResult VulkanAccelerationStructureManager::CopyInputBuffers(
VkCommandBuffer commandBuffer, const VkAccelerationStructureBuildGeometryInfoKHR &info,
const VkAccelerationStructureBuildRangeInfoKHR *buildRange)
@@ -966,9 +976,7 @@ void VulkanAccelerationStructureManager::UpdateScratch(VkDeviceSize requiredSize
scratchAddressUnion.deviceAddress =
ObjDisp(d)->GetBufferDeviceAddressKHR(Unwrap(d), &scratchAddressInfo);
// We do not need the buffer object, only the mem address
m_pDriver->AddPendingObjectCleanup(
[d, buf = scratch.buf]() { ObjDisp(d)->DestroyBuffer(Unwrap(d), buf, NULL); });
scratchBuffers.push_back(scratch.buf);
}
}
@@ -94,6 +94,7 @@ class VulkanAccelerationStructureManager
{
public:
explicit VulkanAccelerationStructureManager(WrappedVulkan *driver);
void Cleanup();
// Allocates readback mem and injects commands into the command buffer so that the input buffers
// are copied.
@@ -148,4 +149,5 @@ private:
Allocation scratch;
VkDeviceOrHostAddressKHR scratchAddressUnion;
rdcarray<VkBuffer> scratchBuffers;
};
@@ -1044,6 +1044,8 @@ void WrappedVulkan::Shutdown()
for(size_t i = 0; i < m_ReplayPhysicalDevices.size(); i++)
GetResourceManager()->ReleaseWrappedResource(m_ReplayPhysicalDevices[i]);
m_ASManager->Cleanup();
m_Replay->DestroyResources();
m_IndirectBuffer.Destroy();
@@ -4840,6 +4842,8 @@ void WrappedVulkan::vkDestroyDevice(VkDevice device, const VkAllocationCallbacks
SAFE_DELETE(m_ShaderCache);
SAFE_DELETE(m_TextRenderer);
m_ASManager->Cleanup();
// since we didn't create proper registered resources for our command buffers,
// they won't be taken down properly with the pool. So we release them (just our
// data) here.