GraphicsMemory fix for robustness during cleanup
This commit is contained in:
Родитель
12ddc4edf4
Коммит
4e524d1783
|
@ -96,6 +96,17 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
// Explicitly destroy LinearAllocators inside a critical section
|
||||
~DeviceAllocator()
|
||||
{
|
||||
ScopedLock lock(mMutex);
|
||||
|
||||
for (auto& allocator : mPools)
|
||||
{
|
||||
allocator.reset();
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsResource Alloc(_In_ size_t size, _In_ size_t alignment)
|
||||
{
|
||||
ScopedLock lock(mMutex);
|
||||
|
|
|
@ -49,7 +49,7 @@ LinearAllocatorPage::LinearAllocatorPage()
|
|||
, mGpuAddress {}
|
||||
, mOffset(0)
|
||||
, mSize(0)
|
||||
, mRefCount(0)
|
||||
, mRefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,17 @@ size_t LinearAllocatorPage::Suballocate(_In_ size_t size, _In_ size_t alignment)
|
|||
return offset;
|
||||
}
|
||||
|
||||
void LinearAllocatorPage::Release()
|
||||
{
|
||||
assert(mRefCount > 0);
|
||||
|
||||
if (mRefCount.fetch_sub(1) == 1)
|
||||
{
|
||||
mUploadResource->Unmap(0, nullptr);
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
LinearAllocator::LinearAllocator(
|
||||
_In_ ID3D12Device* pDevice,
|
||||
_In_ size_t pageSize,
|
||||
|
@ -439,8 +450,7 @@ void LinearAllocator::FreePages( LinearAllocatorPage* page )
|
|||
{
|
||||
LinearAllocatorPage* nextPage = page->pNextPage;
|
||||
|
||||
page->mUploadResource->Unmap( 0, nullptr );
|
||||
delete page;
|
||||
page->Release();
|
||||
|
||||
page = nextPage;
|
||||
m_totalPages--;
|
||||
|
|
|
@ -64,9 +64,9 @@ namespace DirectX
|
|||
size_t BytesUsed() const { return mOffset; }
|
||||
size_t Size() const { return mSize; }
|
||||
|
||||
int32_t AddRef() { return mRefCount.fetch_add(1); }
|
||||
int32_t Release() { assert(mRefCount > 0); return mRefCount.fetch_sub(1); }
|
||||
void AddRef() { mRefCount.fetch_add(1); }
|
||||
int32_t RefCount() const { return mRefCount.load(); }
|
||||
void Release();
|
||||
|
||||
protected:
|
||||
friend class LinearAllocator;
|
||||
|
|
Загрузка…
Ссылка в новой задаче