Skip to content

Commit

Permalink
[VK] Fix wrong heap chosen on fallback code path w/ high memory pressure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darksylinc committed Oct 11, 2023
1 parent 4efe057 commit e53f570
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<uint32>( i );
poolSize = std::max( defaultPoolSize, sizeBytes );
break;
Expand Down

0 comments on commit e53f570

Please sign in to comment.