Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ namespace gpgmm::d3d12 {
}
}

void DebugResourceAllocator::ReleaseLiveAllocationsForTesting() {
std::lock_guard<std::mutex> lock(mMutex);
for (auto allocationEntry : mLiveAllocations) {
allocationEntry->GetValue().GetAllocator()->DeallocateMemory(
std::unique_ptr<MemoryAllocation>(allocationEntry->GetValue().GetAllocation()));
}

mLiveAllocations.clear();
}

void DebugResourceAllocator::AddLiveAllocation(ResourceAllocation* allocation) {
std::lock_guard<std::mutex> lock(mMutex);

Expand Down
20 changes: 4 additions & 16 deletions src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,16 @@ namespace gpgmm::d3d12 {

class ResourceAllocation;

/** \brief DebugResourceAllocator tracks "live" allocations so they can be reported if leaked.

A "live" allocation means the allocation was created (allocated) but not released
(de-allocated).

Use `gpgmm_enable_allocator_leak_checks = true` to always report for leaks.
*/
// DebugResourceAllocator tracks "live" allocations so they can be reported if leaked.
// A "live" allocation means the allocation was created (allocated) but not released
// (de-allocated).
class DebugResourceAllocator final : public MemoryAllocator {
public:
DebugResourceAllocator() = default;

/** \brief Add a "live" allocation.

@param allocation A pointer to a ResourceAllocation to track.
*/
void AddLiveAllocation(ResourceAllocation* allocation);

/** \brief Report "live" allocations.

Dumps outstanding or "live" allocations.
*/
void ReportLiveAllocations() const;
void ReleaseLiveAllocationsForTesting();

private:
void DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) override;
Expand Down
5 changes: 4 additions & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,12 @@ namespace gpgmm::d3d12 {
ResourceAllocator::~ResourceAllocator() {
GPGMM_TRACE_EVENT_OBJECT_DESTROY(this);

// Give the debug allocator the first chance to report leaks.
// Give the debug allocator the first chance to report allocation leaks.
// If allocation leak exists, report then release them immediately to prevent another leak
// check from re-reporting the leaked allocation.
if (mDebugAllocator) {
mDebugAllocator->ReportLiveAllocations();
mDebugAllocator->ReleaseLiveAllocationsForTesting();
}

// Destroy allocators in the reverse order they were created so we can record delete events
Expand Down