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
2 changes: 1 addition & 1 deletion src/gpgmm/common/DedicatedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace gpgmm {
GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(memoryRequest), allocation);

if (memoryRequest.SizeInBytes > request.SizeInBytes) {
DebugLog(MessageId::kAlignmentMismatch, false, GetTypename(), this)
DebugLog(MessageId::kAlignmentMismatch, this)
<< "Memory allocation was larger then the requested size: "
<< memoryRequest.SizeInBytes << " vs " << request.SizeInBytes << " bytes.";
}
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 @@ -161,7 +161,7 @@ namespace gpgmm {

// Check request size cannot overflow.
if (request.SizeInBytes > std::numeric_limits<uint64_t>::max() - (request.Alignment - 1)) {
DebugLog(MessageId::kSizeExceeded, false, GetTypename(), this)
DebugLog(MessageId::kSizeExceeded, this)
<< "Requested size rejected due to overflow: " + std::to_string(request.SizeInBytes)
<< " bytes.";
return std::move(ErrorCodeType(kInternalFailureResult));
Expand All @@ -170,7 +170,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()) {
DebugLog(MessageId::kSizeExceeded, false, GetTypename(), this)
DebugLog(MessageId::kSizeExceeded, this)
<< "Requested size exceeds memory size (" + std::to_string(alignedSize) + " vs " +
std::to_string(GetMemorySize()) + " bytes).";
return std::move(ErrorCodeType(kInternalFailureResult));
Expand All @@ -180,7 +180,7 @@ namespace gpgmm {
// Alignment value of 1 means no alignment required.
if (GetMemoryAlignment() == 0 ||
(GetMemoryAlignment() > 1 && !IsAligned(GetMemoryAlignment(), request.Alignment))) {
DebugLog(MessageId::kAlignmentMismatch, false, GetTypename(), this)
DebugLog(MessageId::kAlignmentMismatch, this)
<< "Requested alignment exceeds memory alignment (" +
std::to_string(request.Alignment) + " vs " +
std::to_string(GetMemoryAlignment()) + " bytes).";
Expand All @@ -207,7 +207,7 @@ namespace gpgmm {
void MemoryAllocatorBase::CheckAndReportAllocationMisalignment(
const MemoryAllocationBase& allocation) {
if (allocation.GetSize() > allocation.GetRequestSize()) {
WarnLog(MessageId::kAlignmentMismatch)
WarnLog(MessageId::kAlignmentMismatch, this)
<< "Allocation is larger then the requested size (" +
std::to_string(allocation.GetSize()) + " vs " +
std::to_string(allocation.GetRequestSize()) + " bytes).";
Expand Down
5 changes: 2 additions & 3 deletions src/gpgmm/common/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace gpgmm {
// or uninitalized memory allocation cannot be created. If memory cannot be allocated for
// the block, the block will be deallocated instead of allowing it to leak.
template <typename GetOrCreateMemoryFn>
static ResultOrError<std::unique_ptr<MemoryAllocationBase>> TrySubAllocateMemory(
ResultOrError<std::unique_ptr<MemoryAllocationBase>> TrySubAllocateMemory(
BlockAllocator* allocator,
uint64_t requestSize,
uint64_t alignment,
Expand All @@ -222,8 +222,7 @@ namespace gpgmm {
if (!result.IsSuccess()) {
// NeverAllocate always fails, so suppress it.
if (!neverAllocate) {
DebugLog(MessageId::kAllocatorFailed, false, allocator->GetTypename(),
allocator)
DebugLog(MessageId::kAllocatorFailed, this)
<< "Failed to sub-allocate memory range = ["
<< std::to_string(block->Offset) << ", "
<< std::to_string(block->Offset + block->Size) << ").";
Expand Down
6 changes: 3 additions & 3 deletions src/gpgmm/common/SlabMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace gpgmm {
if (availableForAllocation < slabSize) {
const uint64_t slabSizeUnderBudget = FindNextFreeSlabOfSize(requestSize);
if (slabSizeUnderBudget == kInvalidSize) {
DebugLog(MessageId::kSizeExceeded, false, GetTypename(), this)
DebugLog(MessageId::kSizeExceeded, this)
<< "Slab size exceeded available memory: " << GPGMM_BYTES_TO_MB(slabSize)
<< " vs " << GPGMM_BYTES_TO_MB(availableForAllocation) << " MBs.";
return kInvalidSize;
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace gpgmm {

// Slab cannot exceed memory size.
if (slabSize > mMaxSlabSize) {
DebugLog(MessageId::kSizeExceeded, false, GetTypename(), this)
DebugLog(MessageId::kSizeExceeded, this)
<< "Slab allocation was disabled because the slab size exceeded the max slab size "
"allowed: "
<< GPGMM_BYTES_TO_MB(slabSize) << " vs " << GPGMM_BYTES_TO_MB(mMaxSlabSize)
Expand Down Expand Up @@ -296,7 +296,7 @@ namespace gpgmm {
}

if (prefetchedSlabAllocation != nullptr) {
DebugLog(MessageId::kPrefetchFailed, false, GetTypename(), this)
DebugLog(MessageId::kPrefetchFailed, this)
<< "Pre-fetching failed because the slab size did not match: "
<< GPGMM_BYTES_TO_MB(slabSize) << " vs "
<< GPGMM_BYTES_TO_MB(prefetchedSlabAllocation->GetSize())
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/d3d12/BudgetUpdateD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace gpgmm::d3d12 {
break;
}

DebugLog(mResidencyManager, MessageId::kBudgetUpdated)
DebugLog(MessageId::kBudgetUpdated, mResidencyManager)
<< "Updated budget from OS notification.";
break;
}
Expand All @@ -75,7 +75,7 @@ namespace gpgmm::d3d12 {
}

if (FAILED(hr)) {
ErrorLog(mResidencyManager, MessageId::kBudgetInvalid)
ErrorLog(MessageId::kBudgetInvalid, mResidencyManager)
<< "Unable to update budget: " +
GetDeviceErrorMessage(mResidencyManager->mDevice, hr);
}
Expand Down
28 changes: 20 additions & 8 deletions src/gpgmm/d3d12/LogD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,35 @@
namespace gpgmm::d3d12 {

template <typename BackendT>
LogMessage DebugLog(const BackendT* object, MessageId messageId = MessageId::kUnknown) {
return gpgmm::DebugLog(messageId, true, gpgmm::WCharToUTF8(object->GetDebugName()), object);
LogMessage DebugLog(MessageId messageId = MessageId::kUnknown,
const BackendT* object = nullptr) {
return gpgmm::DebugLog(
messageId, true, (object != nullptr) ? gpgmm::WCharToUTF8(object->GetDebugName()) : "",
object);
}

template <typename BackendT>
LogMessage InfoLog(const BackendT* object, MessageId messageId = MessageId::kUnknown) {
return gpgmm::InfoLog(messageId, true, gpgmm::WCharToUTF8(object->GetDebugName()), object);
LogMessage InfoLog(MessageId messageId = MessageId::kUnknown,
const BackendT* object = nullptr) {
return gpgmm::InfoLog(messageId, true,
(object != nullptr) ? gpgmm::WCharToUTF8(object->GetDebugName()) : "",
object);
}

template <typename BackendT>
LogMessage WarnLog(const BackendT* object, MessageId messageId = MessageId::kUnknown) {
return gpgmm::WarnLog(messageId, true, gpgmm::WCharToUTF8(object->GetDebugName()), object);
LogMessage WarnLog(MessageId messageId = MessageId::kUnknown,
const BackendT* object = nullptr) {
return gpgmm::WarnLog(messageId, true,
(object != nullptr) ? gpgmm::WCharToUTF8(object->GetDebugName()) : "",
object);
}

template <typename BackendT>
LogMessage ErrorLog(const BackendT* object, MessageId messageId = MessageId::kUnknown) {
return gpgmm::ErrorLog(messageId, true, gpgmm::WCharToUTF8(object->GetDebugName()), object);
LogMessage ErrorLog(MessageId messageId = MessageId::kUnknown,
const BackendT* object = nullptr) {
return gpgmm::ErrorLog(
messageId, true, (object != nullptr) ? gpgmm::WCharToUTF8(object->GetDebugName()) : "",
object);
}

} // namespace gpgmm::d3d12
Expand Down
21 changes: 10 additions & 11 deletions src/gpgmm/d3d12/ResidencyHeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace gpgmm::d3d12 {
}

if (newDescriptor.SizeInBytes == kInvalidSize) {
ErrorLog(MessageId::kInvalidArgument, true) << "Heap size for residency was invalid";
ErrorLog(MessageId::kInvalidArgument) << "Heap size for residency was invalid";
return E_INVALIDARG;
}

Expand All @@ -152,8 +152,7 @@ namespace gpgmm::d3d12 {
}

if (newDescriptor.Alignment == kInvalidSize) {
ErrorLog(MessageId::kInvalidArgument, true)
<< "Heap alignment for residency was invalid.";
ErrorLog(MessageId::kInvalidArgument) << "Heap alignment for residency was invalid.";
return E_INVALIDARG;
}

Expand All @@ -175,8 +174,8 @@ namespace gpgmm::d3d12 {

// Heap created not resident requires no budget to be created.
if (heap->GetInfo().Status == RESIDENCY_HEAP_STATUS_EVICTED &&
(newDescriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET)) {
ErrorLog(heap.get(), MessageId::kInvalidArgument)
(descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET)) {
ErrorLog(MessageId::kInvalidArgument, heap.get())
<< "Creating a heap always in budget cannot be used with "
"D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT.";
return E_INVALIDARG;
Expand All @@ -199,8 +198,8 @@ namespace gpgmm::d3d12 {
}
}
} else {
if (newDescriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_RESIDENT) {
WarnLog(heap.get(), MessageId::kInvalidArgument)
if (descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_RESIDENT) {
WarnLog(MessageId::kInvalidArgument, heap.get())
<< "RESIDENCY_HEAP_FLAG_CREATE_RESIDENT was specified but had no effect "
"becauase residency management is not being used.";
}
Expand All @@ -209,7 +208,7 @@ namespace gpgmm::d3d12 {
GPGMM_RETURN_IF_FAILED(heap->SetDebugName(newDescriptor.DebugName), GetDevice(pPageable));
GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(heap.get(), newDescriptor);

DebugLog(heap.get(), MessageId::kObjectCreated)
DebugLog(MessageId::kObjectCreated, heap.get())
<< "Created heap, Size=" << heap->GetInfo().SizeInBytes
<< ", ID3D12Pageable=" << ToHexStr(heap->mPageable.Get());

Expand All @@ -232,13 +231,13 @@ namespace gpgmm::d3d12 {

// Validate residency resource heap flags must also have a residency manager.
if (isResidencyDisabled && descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET) {
ErrorLog(MessageId::kInvalidArgument, true)
ErrorLog(MessageId::kInvalidArgument)
<< "Creating a heap always in budget requires a residency manager to exist.";
return E_INVALIDARG;
}

if (isResidencyDisabled && descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_RESIDENT) {
ErrorLog(MessageId::kInvalidArgument, true)
ErrorLog(MessageId::kInvalidArgument)
<< "Creating a heap always residency requires a residency manager to exist.";
return E_INVALIDARG;
}
Expand All @@ -257,7 +256,7 @@ namespace gpgmm::d3d12 {
DXGI_QUERY_VIDEO_MEMORY_INFO currentVideoInfo = {};
if (SUCCEEDED(residencyManager->QueryVideoMemoryInfo(descriptor.HeapSegment,
&currentVideoInfo))) {
ErrorLog(MessageId::kBudgetExceeded, true)
ErrorLog(MessageId::kBudgetExceeded)
<< "Unable to create heap because not enough budget exists ("
<< GPGMM_BYTES_TO_MB(descriptor.SizeInBytes) << " vs "
<< GPGMM_BYTES_TO_MB(
Expand Down
Loading