Skip to content

Commit 9b8303f

Browse files
Merge pull request #249 from JustSid/master
Fixed two issues with the new defragmenter
2 parents 46776a4 + 7b9c21f commit 9b8303f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/vk_mem_alloc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10909,6 +10909,7 @@ class VmaBlockVector
1090910909
size_t GetBlockCount() const { return m_Blocks.size(); }
1091010910
// To be used only while the m_Mutex is locked. Used during defragmentation.
1091110911
VmaDeviceMemoryBlock* GetBlock(size_t index) const { return m_Blocks[index]; }
10912+
VMA_RW_MUTEX &GetMutex() { return m_Mutex; }
1091210913

1091310914
VkResult CreateMinBlocks();
1091410915
void AddStatistics(VmaStatistics& inoutStats);
@@ -13064,6 +13065,8 @@ VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPass
1306413065
{
1306513066
if (m_PoolBlockVector != VMA_NULL)
1306613067
{
13068+
VmaMutexLockWrite lock(m_PoolBlockVector->GetMutex(), m_PoolBlockVector->GetAllocator()->m_UseMutex);
13069+
1306713070
if (m_PoolBlockVector->GetBlockCount() > 1)
1306813071
ComputeDefragmentation(*m_PoolBlockVector, 0);
1306913072
else if (m_PoolBlockVector->GetBlockCount() == 1)
@@ -13075,6 +13078,8 @@ VkResult VmaDefragmentationContext_T::DefragmentPassBegin(VmaDefragmentationPass
1307513078
{
1307613079
if (m_pBlockVectors[i] != VMA_NULL)
1307713080
{
13081+
VmaMutexLockWrite lock(m_pBlockVectors[i]->GetMutex(), m_pBlockVectors[i]->GetAllocator()->m_UseMutex);
13082+
1307813083
if (m_pBlockVectors[i]->GetBlockCount() > 1)
1307913084
{
1308013085
if (ComputeDefragmentation(*m_pBlockVectors[i], i))
@@ -13276,7 +13281,7 @@ VkResult VmaDefragmentationContext_T::DefragmentPassEnd(VmaDefragmentationPassMo
1327613281
for (const FragmentedBlock& block : immovableBlocks)
1327713282
{
1327813283
VmaBlockVector* vector = m_pBlockVectors[block.data];
13279-
for (size_t i = m_ImmovableBlockCount; vector->GetBlockCount(); ++i)
13284+
for (size_t i = m_ImmovableBlockCount; i < vector->GetBlockCount(); ++i)
1328013285
{
1328113286
if (vector->GetBlock(i) == block.block)
1328213287
{

0 commit comments

Comments
 (0)