Skip to content

Commit

Permalink
Merge pull request #64 from blueskythlikesclouds/master
Browse files Browse the repository at this point in the history
Handle ALLOCATOR_FLAG_SINGLETHREADED flag in AllocationObjectAllocator.
  • Loading branch information
adam-sawicki-a authored Jun 3, 2024
2 parents 8991a63 + b901f4d commit 4d815ec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/D3D12MemAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2790,29 +2790,30 @@ class AllocationObjectAllocator
{
D3D12MA_CLASS_NO_COPY(AllocationObjectAllocator);
public:
AllocationObjectAllocator(const ALLOCATION_CALLBACKS& allocationCallbacks)
: m_Allocator(allocationCallbacks, 1024) {}
AllocationObjectAllocator(const ALLOCATION_CALLBACKS& allocationCallbacks, bool useMutex)
: m_Allocator(allocationCallbacks, 1024), m_UseMutex(useMutex) {}

template<typename... Types>
Allocation* Allocate(Types... args);
void Free(Allocation* alloc);

private:
D3D12MA_MUTEX m_Mutex;
bool m_UseMutex;
PoolAllocator<Allocation> m_Allocator;
};

#ifndef _D3D12MA_ALLOCATION_OBJECT_ALLOCATOR_FUNCTIONS
template<typename... Types>
Allocation* AllocationObjectAllocator::Allocate(Types... args)
{
MutexLock mutexLock(m_Mutex);
MutexLock mutexLock(m_Mutex, m_UseMutex);
return m_Allocator.Alloc(std::forward<Types>(args)...);
}

void AllocationObjectAllocator::Free(Allocation* alloc)
{
MutexLock mutexLock(m_Mutex);
MutexLock mutexLock(m_Mutex, m_UseMutex);
m_Allocator.Free(alloc);
}
#endif // _D3D12MA_ALLOCATION_OBJECT_ALLOCATOR_FUNCTIONS
Expand Down Expand Up @@ -6094,7 +6095,7 @@ AllocatorPimpl::AllocatorPimpl(const ALLOCATION_CALLBACKS& allocationCallbacks,
m_AllocationCallbacks(allocationCallbacks),
m_CurrentFrameIndex(0),
// Below this line don't use allocationCallbacks but m_AllocationCallbacks!!!
m_AllocationObjectAllocator(m_AllocationCallbacks)
m_AllocationObjectAllocator(m_AllocationCallbacks, m_UseMutex)
{
// desc.pAllocationCallbacks intentionally ignored here, preprocessed by CreateAllocator.
ZeroMemory(&m_D3D12Options, sizeof(m_D3D12Options));
Expand Down

0 comments on commit 4d815ec

Please sign in to comment.