From e53f57096bf3306c1eb07cda4d0379a325ca5a34 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Tue, 10 Oct 2023 21:01:22 -0300 Subject: [PATCH] [VK] Fix wrong heap chosen on fallback code path w/ high memory pressure VulkanVaoManager would fallback to using less-desired memory pools if it runs out of memory in the best pools. The code for that path was flawed and could potentially chose the wrong heap. --- .../Vulkan/src/Vao/OgreVulkanVaoManager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp b/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp index 2e5b73aecc7..7af8c7d8bef 100644 --- a/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp +++ b/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp @@ -982,9 +982,8 @@ namespace Ogre { // Found one! size_t defaultPoolSize = - std::min( mDefaultPoolSize[vboFlag], - memHeaps[memTypes[*itMemTypeIdx].heapIndex].size - - mUsedHeapMemory[heapIdx] ); + std::min( (VkDeviceSize)mDefaultPoolSize[vboFlag], + memHeaps[heapIdx].size - mUsedHeapMemory[heapIdx] ); poolSize = std::max( defaultPoolSize, sizeBytes ); break; } @@ -1010,14 +1009,13 @@ namespace Ogre { // We didn't try this memory type. Let's check if we can use it // TODO: See comment above about memHeaps[heapIdx].size - const size_t heapIdx = memTypes[memTypes[i].heapIndex].heapIndex; + const size_t heapIdx = memTypes[i].heapIndex; if( mUsedHeapMemory[heapIdx] + poolSize < memHeaps[heapIdx].size ) { // Found one! size_t defaultPoolSize = - std::min( mDefaultPoolSize[vboFlag], - memHeaps[memTypes[heapIdx].heapIndex].size - - mUsedHeapMemory[heapIdx] ); + std::min( (VkDeviceSize)mDefaultPoolSize[vboFlag], + memHeaps[heapIdx].size - mUsedHeapMemory[heapIdx] ); chosenMemoryTypeIdx = static_cast( i ); poolSize = std::max( defaultPoolSize, sizeBytes ); break;