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
6 changes: 6 additions & 0 deletions src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace gpgmm { namespace d3d12 {
}

void DebugResourceAllocator::ReportLiveAllocations() const {
std::lock_guard<std::mutex> lock(mMutex);

for (auto allocationEntry : mLiveAllocations) {
const ResourceAllocation* allocation = allocationEntry->GetValue().GetAllocation();
gpgmm::WarningLog() << "Live ResourceAllocation: "
Expand All @@ -58,6 +60,8 @@ namespace gpgmm { namespace d3d12 {
}

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

mLiveAllocations.GetOrCreate(
ResourceAllocationEntry(allocation, allocation->GetAllocator()), true);

Expand All @@ -66,6 +70,8 @@ namespace gpgmm { namespace d3d12 {
}

void DebugResourceAllocator::DeallocateMemory(std::unique_ptr<MemoryAllocation> allocation) {
std::lock_guard<std::mutex> lock(mMutex);

// KeepAlive must be false so |mLiveAllocations| cache will shrink by 1 entry once |entry|
// falls out of scope below since AddLiveAllocation() adds one (and only one) ref.
auto entry = mLiveAllocations.GetOrCreate(
Expand Down
16 changes: 10 additions & 6 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ namespace gpgmm { namespace d3d12 {
mResourceHeapTier(descriptor.ResourceHeapTier),
mIsAlwaysCommitted(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_COMMITED),
mIsAlwaysInBudget(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET),
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize),
mAllocationTimer(gpgmm::CreatePlatformTime()) {
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);

#if defined(GPGMM_ENABLE_ALLOCATOR_CHECKS)
Expand Down Expand Up @@ -606,19 +605,20 @@ namespace gpgmm { namespace d3d12 {

TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.CreateResource");

std::lock_guard<std::mutex> lock(mMutex);
// Timer isn't thread safe so it cannot be shared between invocations of CreateResource.
std::unique_ptr<PlatformTime> timer(CreatePlatformTime());

mAllocationTimer->StartElapsedTime();
timer->StartElapsedTime();
ReturnIfFailed(CreateResourceInternal(allocationDescriptor, resourceDescriptor,
initialResourceState, clearValue,
resourceAllocationOut));
const double allocationLatency = mAllocationTimer->EndElapsedTime() * 1e6;
const double allocationLatency = timer->EndElapsedTime() * 1e6;
GPGMM_UNUSED(allocationLatency);

TRACE_COUNTER1(TraceEventCategory::Default, "GPU allocation latency (us)",
allocationLatency);

const RESOURCE_ALLOCATOR_INFO& info = GetInfo();
const RESOURCE_ALLOCATOR_INFO info = GetInfo();
GPGMM_UNUSED(info);

TRACE_COUNTER1(TraceEventCategory::Default, "GPU memory fragmentation (MB)",
Expand Down Expand Up @@ -649,6 +649,8 @@ namespace gpgmm { namespace d3d12 {
D3D12_RESOURCE_STATES initialResourceState,
const D3D12_CLEAR_VALUE* clearValue,
ResourceAllocation** resourceAllocationOut) {
std::lock_guard<std::mutex> lock(mMutex);

// If d3d tells us the resource size is invalid, treat the error as OOM.
// Otherwise, creating a very large resource could overflow the allocator.
D3D12_RESOURCE_DESC newResourceDesc = resourceDescriptor;
Expand Down Expand Up @@ -950,6 +952,8 @@ namespace gpgmm { namespace d3d12 {
}

RESOURCE_ALLOCATOR_INFO ResourceAllocator::GetInfo() const {
std::lock_guard<std::mutex> lock(mMutex);

// ResourceAllocator itself could call CreateCommittedResource directly.
RESOURCE_ALLOCATOR_INFO result = mInfo;

Expand Down
1 change: 0 additions & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ namespace gpgmm { namespace d3d12 {
mBufferAllocatorOfType;

std::unique_ptr<DebugResourceAllocator> mDebugAllocator;
std::unique_ptr<PlatformTime> mAllocationTimer;
};

}} // namespace gpgmm::d3d12
Expand Down