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
16 changes: 16 additions & 0 deletions src/gpgmm/common/EventMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,20 @@ namespace gpgmm {
}
}

EventMessage DebugEvent(const ObjectBase* object, EventMessageId messageId) {
return {LogSeverity::Debug, object->GetTypename(), object, messageId};
}

EventMessage InfoEvent(const ObjectBase* object, EventMessageId messageId) {
return {LogSeverity::Info, object->GetTypename(), object, messageId};
}

EventMessage WarnEvent(const ObjectBase* object, EventMessageId messageId) {
return {LogSeverity::Warning, object->GetTypename(), object, messageId};
}

EventMessage ErrorEvent(const ObjectBase* object, EventMessageId messageId) {
return {LogSeverity::Error, object->GetTypename(), object, messageId};
}

} // namespace gpgmm
39 changes: 12 additions & 27 deletions src/gpgmm/common/EventMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef GPGMM_COMMON_EVENT_MESSAGE_H_
#define GPGMM_COMMON_EVENT_MESSAGE_H_

#include "gpgmm/common/Object.h"
#include "gpgmm/common/TraceEvent.h"
#include "gpgmm/utils/Log.h"

Expand Down Expand Up @@ -65,33 +66,17 @@ namespace gpgmm {
std::ostringstream mStream;
};

template <typename T>
EventMessage DebugEvent(const char* name,
const T* object,
EventMessageId messageId = EventMessageId::kUnknown) {
return {LogSeverity::Debug, name, object, messageId};
}

template <typename T>
EventMessage InfoEvent(const char* name,
const T* object,
EventMessageId messageId = EventMessageId::kUnknown) {
return {LogSeverity::Info, name, object, messageId};
}

template <typename T>
EventMessage WarnEvent(const char* name,
const T* object,
EventMessageId messageId = EventMessageId::kUnknown) {
return {LogSeverity::Warning, name, object, messageId};
}

template <typename T>
EventMessage ErrorEvent(const char* name,
T* object,
EventMessageId messageId = EventMessageId::kUnknown) {
return {LogSeverity::Error, name, object, messageId};
}
EventMessage DebugEvent(const ObjectBase* object,
EventMessageId messageId = EventMessageId::kUnknown);

EventMessage InfoEvent(const ObjectBase* object,
EventMessageId messageId = EventMessageId::kUnknown);

EventMessage WarnEvent(const ObjectBase* object,
EventMessageId messageId = EventMessageId::kUnknown);

EventMessage ErrorEvent(const ObjectBase* object,
EventMessageId messageId = EventMessageId::kUnknown);

// Messages of a given severity to be recorded.
void SetEventMessageLevel(const LogSeverity& level);
Expand Down
8 changes: 4 additions & 4 deletions src/gpgmm/common/MemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace gpgmm {

// Check request size cannot overflow.
if (request.SizeInBytes > std::numeric_limits<uint64_t>::max() - (request.Alignment - 1)) {
DebugEvent(GetTypename(), this, EventMessageId::kSizeExceeded)
DebugEvent(this, EventMessageId::kSizeExceeded)
<< "Requested size rejected due to overflow: " + std::to_string(request.SizeInBytes)
<< " bytes.";
return false;
Expand All @@ -165,7 +165,7 @@ namespace gpgmm {
// Check request size cannot overflow |this| memory allocator.
const uint64_t alignedSize = AlignTo(request.SizeInBytes, request.Alignment);
if (GetMemorySize() != kInvalidSize && alignedSize > GetMemorySize()) {
DebugEvent(GetTypename(), this, EventMessageId::kSizeExceeded)
DebugEvent(this, EventMessageId::kSizeExceeded)
<< "Requested size exceeds memory size (" + std::to_string(alignedSize) + " vs " +
std::to_string(GetMemorySize()) + " bytes).";
return false;
Expand All @@ -175,7 +175,7 @@ namespace gpgmm {
// Alignment value of 1 means no alignment required.
if (GetMemoryAlignment() == 0 ||
(GetMemoryAlignment() > 1 && !IsAligned(GetMemoryAlignment(), request.Alignment))) {
DebugEvent(GetTypename(), this, EventMessageId::kAlignmentMismatch)
DebugEvent(this, EventMessageId::kAlignmentMismatch)
<< "Requested alignment exceeds memory alignment (" +
std::to_string(request.Alignment) + " vs " +
std::to_string(GetMemoryAlignment()) + " bytes).";
Expand All @@ -201,7 +201,7 @@ namespace gpgmm {

void MemoryAllocator::CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation) {
if (allocation.GetSize() > allocation.GetRequestSize()) {
DebugEvent(GetTypename(), this, EventMessageId::kAlignmentMismatch)
DebugEvent(this, EventMessageId::kAlignmentMismatch)
<< "Resource allocation is larger then the requested size (" +
std::to_string(allocation.GetSize()) + " vs " +
std::to_string(allocation.GetRequestSize()) + " bytes).";
Expand Down
12 changes: 5 additions & 7 deletions src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ namespace gpgmm {
if (availableForAllocation < slabSize) {
const uint64_t slabSizeUnderBudget = FindNextFreeSlabOfSize(requestSize);
if (slabSizeUnderBudget == kInvalidSize) {
DebugEvent(GetTypename(), this)
<< "Slab size exceeds available memory: " << slabSize << " vs "
<< availableForAllocation << " bytes.";
DebugEvent(this) << "Slab size exceeds available memory: " << slabSize << " vs "
<< availableForAllocation << " bytes.";
return kInvalidSize;
}

Expand Down Expand Up @@ -205,8 +204,7 @@ namespace gpgmm {

// Slab cannot exceed memory size.
if (slabSize > mMaxSlabSize) {
gpgmm::DebugEvent(GetTypename(), this)
<< "Slab allocation was disabled because the size was invalid.";
gpgmm::DebugEvent(this) << "Slab allocation was disabled because the size was invalid.";
return {};
}

Expand Down Expand Up @@ -282,7 +280,7 @@ namespace gpgmm {
}

if (prefetchedSlabAllocation != nullptr) {
DebugEvent(GetTypename(), this, EventMessageId::kPrefetchFailed)
DebugEvent(this, EventMessageId::kPrefetchFailed)
<< "Pre-fetch slab memory is incompatible (" << slabSize << " vs "
<< prefetchedSlabAllocation->GetSize() << " bytes.";
}
Expand Down Expand Up @@ -459,7 +457,7 @@ namespace gpgmm {
SafeDivide(mStats.PrefetchedMemoryMissesEliminated,
mStats.PrefetchedMemoryMissesEliminated + mStats.PrefetchedMemoryMisses);
if (currentCoverage < kPrefetchCoverageWarnMinThreshold) {
WarnEvent(GetTypename(), this, EventMessageId::kPrefetchFailed)
WarnEvent(this, EventMessageId::kPrefetchFailed)
<< "Prefetch coverage is below threshold (%): " << currentCoverage * 100 << " vs "
<< kPrefetchCoverageWarnMinThreshold * 100;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/BufferAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace gpgmm::d3d12 {

const uint64_t heapSize = AlignTo(request.SizeInBytes, request.Alignment);
if (heapSize > request.SizeInBytes) {
DebugEvent(GetTypename(), this, EventMessageId::kAlignmentMismatch)
DebugEvent(this, EventMessageId::kAlignmentMismatch)
<< "Resource heap size is larger then the requested size (" +
std::to_string(heapSize) + " vs " + std::to_string(request.SizeInBytes) +
" bytes).";
Expand Down
11 changes: 5 additions & 6 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ namespace gpgmm::d3d12 {
break;
}

gpgmm::DebugEvent(mResidencyManager->GetTypename(), mResidencyManager,
EventMessageId::kBudgetUpdated)
gpgmm::DebugEvent(mResidencyManager, EventMessageId::kBudgetUpdated)
<< "Updated budget from OS budget notification.";
break;
}
Expand Down Expand Up @@ -521,7 +520,7 @@ namespace gpgmm::d3d12 {
// Ignore when no budget was specified.
if (pVideoMemoryInfo->Budget > 0 &&
pVideoMemoryInfo->CurrentUsage > pVideoMemoryInfo->Budget) {
WarnEvent(GetTypename(), this, EventMessageId::kBudgetExceeded)
WarnEvent(this, EventMessageId::kBudgetExceeded)
<< GetMemorySegmentName(memorySegmentGroup, mIsUMA)
<< " GPU memory exceeds budget: "
<< GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage) << " vs "
Expand Down Expand Up @@ -591,7 +590,7 @@ namespace gpgmm::d3d12 {
// If a budget wasn't provided, it not possible to evict. This is because either the budget
// update event has not happened yet or was invalid.
if (pVideoMemoryInfo->Budget == 0) {
WarnEvent(GetTypename(), this, EventMessageId::kBudgetInvalid)
WarnEvent(this, EventMessageId::kBudgetInvalid)
<< "GPU memory segment ("
<< GetMemorySegmentName(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, IsUMA())
<< ") was unable to evict memory because a budget was not specified.";
Expand Down Expand Up @@ -662,7 +661,7 @@ namespace gpgmm::d3d12 {
const uint32_t objectEvictCount = static_cast<uint32_t>(objectsToEvict.size());
ReturnIfFailed(mDevice->Evict(objectEvictCount, objectsToEvict.data()));

DebugEvent(GetTypename(), this, EventMessageId::kBudgetExceeded)
DebugEvent(this, EventMessageId::kBudgetExceeded)
<< "GPU page-out. Number of allocations: " << objectsToEvict.size() << " ("
<< bytesEvicted << " bytes).";
}
Expand Down Expand Up @@ -797,7 +796,7 @@ namespace gpgmm::d3d12 {

ReturnIfFailed(EvictInternal(sizeToMakeResident, memorySegmentGroup, nullptr));

DebugEvent(GetTypename(), this, EventMessageId::kBudgetExceeded)
DebugEvent(this, EventMessageId::kBudgetExceeded)
<< "GPU page-in. Number of allocations: " << numberOfObjectsToMakeResident << " ("
<< sizeToMakeResident << " bytes).";

Expand Down
5 changes: 3 additions & 2 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef GPGMM_D3D12_RESIDENCYMANAGERD3D12_H_
#define GPGMM_D3D12_RESIDENCYMANAGERD3D12_H_

#include "gpgmm/common/Object.h"
#include "gpgmm/d3d12/IUnknownImplD3D12.h"
#include "gpgmm/utils/EnumFlags.h"
#include "gpgmm/utils/LinkedList.h"
Expand All @@ -38,7 +39,7 @@ namespace gpgmm::d3d12 {
class ResourceAllocator;
class ResourceHeapAllocator;

class ResidencyManager final : public IUnknownImpl, public IResidencyManager {
class ResidencyManager final : public IUnknownImpl, public IResidencyManager, ObjectBase {
public:
static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor,
IResidencyManager** ppResidencyManagerOut);
Expand Down Expand Up @@ -87,7 +88,7 @@ namespace gpgmm::d3d12 {

bool IsUMA() const;

const char* GetTypename() const;
const char* GetTypename() const override;

using LRUCache = LinkedList<Heap>;

Expand Down
25 changes: 11 additions & 14 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,15 @@ namespace gpgmm::d3d12 {
if (allocation == nullptr) {
// NeverAllocate always fails, so suppress it.
if (!request.NeverAllocate) {
DebugEvent(allocator->GetTypename(), allocator,
EventMessageId::kAllocatorFailed)
DebugEvent(allocator, EventMessageId::kAllocatorFailed)
<< "Unable to allocate memory for request.";
}
return E_FAIL;
}

HRESULT hr = createResourceFn(*allocation);
if (FAILED(hr)) {
InfoEvent(allocator->GetTypename(), allocator, EventMessageId::kAllocatorFailed)
InfoEvent(allocator, EventMessageId::kAllocatorFailed)
<< "Failed to create resource using allocation: " +
GetDeviceErrorMessage(device, hr);
allocator->DeallocateMemory(std::move(allocation));
Expand Down Expand Up @@ -960,10 +959,9 @@ namespace gpgmm::d3d12 {
// Check memory requirements.
D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(resourceHeapType, IsCreateHeapNotResident());
if (!HasAllFlags(heapFlags, allocationDescriptor.ExtraRequiredHeapFlags)) {
DebugEvent(GetTypename(), this)
<< "Required heap flags are incompatible with resource heap type ("
<< std::to_string(allocationDescriptor.ExtraRequiredHeapFlags) << " vs "
<< std::to_string(heapFlags) + ").";
DebugEvent(this) << "Required heap flags are incompatible with resource heap type ("
<< std::to_string(allocationDescriptor.ExtraRequiredHeapFlags)
<< " vs " << std::to_string(heapFlags) + ").";

heapFlags |= allocationDescriptor.ExtraRequiredHeapFlags;

Expand Down Expand Up @@ -1036,10 +1034,9 @@ namespace gpgmm::d3d12 {
if (currentVideoInfo->CurrentUsage > currentVideoInfo->Budget) {
request.AvailableForAllocation = GetInfoInternal().FreeMemoryUsage;

DebugEvent(GetTypename(), this)
<< "Current usage exceeded budget ("
<< std::to_string(currentVideoInfo->CurrentUsage) << " vs "
<< std::to_string(currentVideoInfo->Budget) + " bytes).";
DebugEvent(this) << "Current usage exceeded budget ("
<< std::to_string(currentVideoInfo->CurrentUsage) << " vs "
<< std::to_string(currentVideoInfo->Budget) + " bytes).";

} else {
request.AvailableForAllocation =
Expand Down Expand Up @@ -1196,7 +1193,7 @@ namespace gpgmm::d3d12 {
if (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_FALLBACK) {
return E_FAIL;
}
InfoEvent(GetTypename(), this, EventMessageId::kAllocatorFailed)
InfoEvent(this, EventMessageId::kAllocatorFailed)
<< "Unable to allocate by using a heap, falling back to a committed resource.";
}

Expand Down Expand Up @@ -1416,8 +1413,8 @@ namespace gpgmm::d3d12 {
switch (message->ID) {
case D3D12_MESSAGE_ID_LIVE_HEAP:
case D3D12_MESSAGE_ID_LIVE_RESOURCE: {
gpgmm::WarnEvent("Device", device.Get())
<< "Leak detected: " + std::string(message->pDescription);
gpgmm::WarningLog()
<< "Device leak detected: " + std::string(message->pDescription);
} break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace gpgmm::d3d12 {
}

if (resourceHeapDesc.SizeInBytes > request.SizeInBytes) {
DebugEvent(GetTypename(), this, EventMessageId::kAlignmentMismatch)
DebugEvent(this, EventMessageId::kAlignmentMismatch)
<< "Resource heap was larger then the requested size (" +
std::to_string(resourceHeapDesc.SizeInBytes) + " vs " +
std::to_string(request.SizeInBytes) + " bytes).";
Expand Down
3 changes: 1 addition & 2 deletions src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace gpgmm::vk {
const uint64_t maxDeviceMemoryAllocationCount =
mResourceAllocator->GetCaps()->GetMaxDeviceAllocationCount();
if (mStats.UsedMemoryCount + 1 >= maxDeviceMemoryAllocationCount) {
DebugEvent("DeviceMemoryAllocator.TryAllocateMemory", this,
EventMessageId::kAllocatorFailed)
DebugEvent(this, EventMessageId::kAllocatorFailed)
<< "Device exceeded max number of device memory allocations (" +
std::to_string(mStats.UsedMemoryCount) + " vs " +
std::to_string(maxDeviceMemoryAllocationCount) + ").";
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/vk/ResourceAllocatorVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "gpgmm/common/BuddyMemoryAllocator.h"
#include "gpgmm/common/Defaults.h"
#include "gpgmm/common/EventMessage.h"
#include "gpgmm/common/Object.h"
#include "gpgmm/common/PooledMemoryAllocator.h"
#include "gpgmm/common/SegmentedMemoryAllocator.h"
#include "gpgmm/common/SizeClass.h"
Expand Down Expand Up @@ -352,8 +353,7 @@ namespace gpgmm::vk {
}

if (memoryAllocation == nullptr) {
ErrorEvent("GpResourceAllocator.TryAllocateResource", this,
EventMessageId::kAllocatorFailed)
ErrorEvent(allocator, EventMessageId::kAllocatorFailed)
<< "Unable to allocate memory for resource.";

return VK_ERROR_UNKNOWN;
Expand Down