From 1e977fe889d448dc84d360d6089b9db9d7e04e8d Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 6 Dec 2024 15:51:52 +0000 Subject: [PATCH] Use configurable overestimate to account for incorrect maxVertex * We do this already on D3D12, this applies the same change to Vulkan - maxVertex can't really be trusted but we hope it is approximately right or the VBs are small, we don't want to copy the whole VB since it may be massive. --- .../vulkan/vk_acceleration_structure.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_acceleration_structure.cpp b/renderdoc/driver/vulkan/vk_acceleration_structure.cpp index d6b41460e..c0d06287b 100644 --- a/renderdoc/driver/vulkan/vk_acceleration_structure.cpp +++ b/renderdoc/driver/vulkan/vk_acceleration_structure.cpp @@ -28,6 +28,13 @@ #include "vk_manager.h" RDOC_EXTERN_CONFIG(bool, Vulkan_Debug_SingleSubmitFlushing); +RDOC_CONFIG(uint32_t, Vulkan_Debug_RT_MaxVertexIncrement, 1000, + "Amount to add to the API-provided max vertex when building a BLAS with an index " + "buffer, to account for incorrectly set values by application."); +RDOC_CONFIG( + uint32_t, Vulkan_Debug_RT_MaxVertexPercentIncrease, 10, + "Percentage increase for the API-provided max vertex when building a BLAS with an index " + "buffer, to account for incorrectly set values by application."); namespace { @@ -323,9 +330,17 @@ RDResult VulkanAccelerationStructureManager::CopyInputBuffers( if(indexData) { - // If we're using an index buffer we don't know how much of the vertex buffer we need, - // and we can't trust the app to set maxVertex correctly, so we take the whole buffer - vertexData.size = vertexData.rao.record->memSize - vertexData.rao.offset; + // don't take maxVertex as perfect, applications have no reason to set it correctly for + // everything to work with drivers, and likely no validation. Add an overestimate factor + uint32_t untrustedVertexCount = triInfo.maxVertex; + uint32_t estimatedVertexCount = + untrustedVertexCount + + (untrustedVertexCount / 100) * Vulkan_Debug_RT_MaxVertexPercentIncrease() + + Vulkan_Debug_RT_MaxVertexIncrement(); + + // don't read more than what is left in the buffer + vertexData.size = RDCMIN(triInfo.vertexStride * estimatedVertexCount, + vertexData.rao.record->memSize - vertexData.rao.offset); vertexData.SetReadPosition(0); } else