diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.cpp b/src/gpgmm/common/DedicatedMemoryAllocator.cpp index 9dcfc7c6..5541f404 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.cpp +++ b/src/gpgmm/common/DedicatedMemoryAllocator.cpp @@ -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."; } diff --git a/src/gpgmm/common/MemoryAllocator.cpp b/src/gpgmm/common/MemoryAllocator.cpp index 65a133ca..e0481ccb 100644 --- a/src/gpgmm/common/MemoryAllocator.cpp +++ b/src/gpgmm/common/MemoryAllocator.cpp @@ -161,7 +161,7 @@ namespace gpgmm { // Check request size cannot overflow. if (request.SizeInBytes > std::numeric_limits::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)); @@ -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)); @@ -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)."; @@ -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)."; diff --git a/src/gpgmm/common/MemoryAllocator.h b/src/gpgmm/common/MemoryAllocator.h index a837bd9a..5f17583a 100644 --- a/src/gpgmm/common/MemoryAllocator.h +++ b/src/gpgmm/common/MemoryAllocator.h @@ -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 - static ResultOrError> TrySubAllocateMemory( + ResultOrError> TrySubAllocateMemory( BlockAllocator* allocator, uint64_t requestSize, uint64_t alignment, @@ -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) << ")."; diff --git a/src/gpgmm/common/SlabMemoryAllocator.cpp b/src/gpgmm/common/SlabMemoryAllocator.cpp index b0e11bde..3b789f9b 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.cpp +++ b/src/gpgmm/common/SlabMemoryAllocator.cpp @@ -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; @@ -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) @@ -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()) diff --git a/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp b/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp index 3c078b53..428482d0 100644 --- a/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp +++ b/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp @@ -58,7 +58,7 @@ namespace gpgmm::d3d12 { break; } - DebugLog(mResidencyManager, MessageId::kBudgetUpdated) + DebugLog(MessageId::kBudgetUpdated, mResidencyManager) << "Updated budget from OS notification."; break; } @@ -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); } diff --git a/src/gpgmm/d3d12/LogD3D12.h b/src/gpgmm/d3d12/LogD3D12.h index 56a4c398..486d8815 100644 --- a/src/gpgmm/d3d12/LogD3D12.h +++ b/src/gpgmm/d3d12/LogD3D12.h @@ -21,23 +21,35 @@ namespace gpgmm::d3d12 { template - 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 - 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 - 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 - 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 diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp index 76ac26a6..8c3ecb03 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp @@ -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; } @@ -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; } @@ -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; @@ -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."; } @@ -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()); @@ -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; } @@ -257,7 +256,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO currentVideoInfo = {}; if (SUCCEEDED(residencyManager->QueryVideoMemoryInfo(descriptor.HeapSegment, ¤tVideoInfo))) { - 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( diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index a3bdb1ee..88d0aae8 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -64,13 +64,13 @@ namespace gpgmm::d3d12 { if ((descriptor.Flags & RESIDENCY_MANAGER_FLAG_NEVER_USE_UNIFIED_MEMORY) && caps->IsAdapterUMA()) { - WarnLog(MessageId::kInvalidArgument, true) + WarnLog(MessageId::kInvalidArgument) << "RESIDENCY_MANAGER_FLAG_NEVER_USE_UNIFIED_MEMORY flag was specified but " "did not match the architecture of the adapter."; } if (descriptor.MaxPctOfVideoMemoryToBudget != 0 && descriptor.MaxBudgetInBytes != 0) { - ErrorLog(MessageId::kInvalidArgument, true) + ErrorLog(MessageId::kInvalidArgument) << "Both the OS based memory budget and restricted budget were " "specified but cannot be used at the same time."; return E_UNEXPECTED; @@ -91,10 +91,9 @@ namespace gpgmm::d3d12 { // Enable automatic video memory budget updates. if (descriptor.Flags & RESIDENCY_MANAGER_FLAG_ALLOW_BACKGROUND_BUDGET_UPDATES) { if (FAILED(residencyManager->StartBudgetNotificationUpdates())) { - WarnLog(residencyManager.get(), MessageId::kBudgetUpdated) + WarnLog(MessageId::kBudgetUpdated, residencyManager.get()) << "RESIDENCY_MANAGER_FLAG_ALLOW_BACKGROUND_BUDGET_UPDATES was requested but " - "failed to " - "start."; + "failed to start."; } } @@ -122,13 +121,13 @@ namespace gpgmm::d3d12 { // Emit a warning if the budget was initialized to zero. // This means nothing will be ever evicted, which will lead to device lost. if (localVideoMemorySegmentInfo->Budget == 0) { - WarnLog(residencyManager.get(), MessageId::kBudgetInvalid) + WarnLog(MessageId::kBudgetInvalid, residencyManager.get()) << "GPU memory segment (" << GetMemorySegmentName(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, residencyManager->mIsUMA) << ") did not initialize a budget. This means either a restricted budget was not " "used or the first OS budget update hasn't occured."; if (!residencyManager->mIsUMA && nonLocalVideoMemorySegmentInfo->Budget == 0) { - WarnLog(residencyManager.get(), MessageId::kBudgetInvalid) + WarnLog(MessageId::kBudgetInvalid, residencyManager.get()) << "GPU memory segment (" << GetMemorySegmentName(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, residencyManager->mIsUMA) @@ -146,7 +145,7 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(residencyManager.get(), descriptor); - DebugLog(residencyManager.get(), MessageId::kObjectCreated) << "Created residency manager"; + DebugLog(MessageId::kObjectCreated, residencyManager.get()) << "Created residency manager"; if (ppResidencyManagerOut != nullptr) { *ppResidencyManagerOut = residencyManager.release(); @@ -246,7 +245,7 @@ namespace gpgmm::d3d12 { } if (heap->IsInList()) { - ErrorLog(this, MessageId::kBadOperation) + ErrorLog(MessageId::kBadOperation, this) << "Heap was never being tracked for residency. This usually occurs when a " "non-resource heap was created by the developer and never made resident at " "creation or failure to call LockHeap beforehand."; @@ -381,16 +380,16 @@ namespace gpgmm::d3d12 { if (previousUsage > pVideoMemoryInfo->CurrentUsage && GPGMM_BYTES_TO_MB(previousUsage - pVideoMemoryInfo->CurrentUsage) > 0) { - DebugLog(this, MessageId::kMemoryUsageUpdated) + DebugLog(MessageId::kMemoryUsageUpdated, this) << GetMemorySegmentName(heapSegment, mIsUMA) << " GPU memory usage went down by " << GPGMM_BYTES_TO_MB(previousUsage - pVideoMemoryInfo->CurrentUsage) << " MBs."; } else if (previousUsage < pVideoMemoryInfo->CurrentUsage && GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage - previousUsage) > 0) { - DebugLog(this, MessageId::kMemoryUsageUpdated) + DebugLog(MessageId::kMemoryUsageUpdated, this) << GetMemorySegmentName(heapSegment, mIsUMA) << " GPU memory usage went up by " << GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage - previousUsage) << " MBs."; } else if (previousUsage < pVideoMemoryInfo->CurrentUsage) { - DebugLog(this, MessageId::kMemoryUsageUpdated) + DebugLog(MessageId::kMemoryUsageUpdated, this) << GetMemorySegmentName(heapSegment, mIsUMA) << " GPU memory usage went up by " << GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage) << " MBs."; } @@ -404,13 +403,13 @@ namespace gpgmm::d3d12 { if (previousBudget > pVideoMemoryInfo->Budget && GPGMM_BYTES_TO_MB(previousBudget - pVideoMemoryInfo->Budget) > 0) { - DebugLog(this, MessageId::kMemoryUsageUpdated) + DebugLog(MessageId::kMemoryUsageUpdated, this) << GetMemorySegmentName(heapSegment, mIsUMA) << " GPU memory budget went down by " << GPGMM_BYTES_TO_MB(previousBudget - pVideoMemoryInfo->Budget) << " MBs."; } else if (previousBudget < pVideoMemoryInfo->Budget && GPGMM_BYTES_TO_MB(pVideoMemoryInfo->Budget - previousBudget) > 0) { - DebugLog(this, MessageId::kMemoryUsageUpdated) + DebugLog(MessageId::kMemoryUsageUpdated, this) << GetMemorySegmentName(heapSegment, mIsUMA) << " GPU memory budget went up by " << GPGMM_BYTES_TO_MB(pVideoMemoryInfo->Budget - previousBudget) << " MBs."; } @@ -606,7 +605,7 @@ namespace gpgmm::d3d12 { std::lock_guard lock(mMutex); if (count == 0) { - ErrorLog(this, MessageId::kInvalidArgument) + ErrorLog(MessageId::kInvalidArgument, this) << "ExecuteCommandLists is required to have at-least one residency " "list to be called."; return E_INVALIDARG; @@ -614,7 +613,7 @@ namespace gpgmm::d3d12 { // TODO: support multiple command lists. if (count > 1) { - ErrorLog(this, MessageId::kInvalidArgument) + ErrorLog(MessageId::kInvalidArgument, this) << "ExecuteCommandLists does not support multiple residency lists at this time. " "Please call ExecuteCommandLists per residency list as a workaround, if needed."; return E_NOTIMPL; @@ -675,7 +674,7 @@ namespace gpgmm::d3d12 { // If the heap should be already resident, calling MakeResident again will be redundant. // Tell the developer the heap wasn't properly tracked by the residency manager. if (heap->GetInfo().Status == RESIDENCY_HEAP_STATUS_UNKNOWN) { - DebugLog(this, MessageId::kBadOperation) + DebugLog(MessageId::kBadOperation, this) << "Residency state could not be determined for the heap (Heap=" << ToHexStr(heap) << "). This likely means the developer was attempting to make a " @@ -774,7 +773,7 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_FAILED( EvictInternal(mEvictSizeInBytes, heapSegment, &evictedSizeInBytes), mDevice); if (evictedSizeInBytes == 0) { - ErrorLog(this, MessageId::kBudgetInvalid) + ErrorLog(MessageId::kBudgetInvalid, this) << "Unable to evict enough heaps to stay within budget. This " "usually occurs when there is not enough available memory. " "Please reduce consumption by checking allocation sizes and " @@ -867,14 +866,16 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO* info = GetVideoMemoryInfo(segmentGroup); ASSERT(info != nullptr); - DebugLog(this) << GetMemorySegmentName(segmentGroup, IsUMA()) << " GPU memory segment:"; - DebugLog(this) << "\tBudget: " << GPGMM_BYTES_TO_MB(info->Budget) << " MBs (" - << GPGMM_BYTES_TO_MB(info->CurrentUsage) << " used)."; + DebugLog(MessageId::kBudgetUpdated, this) + << GetMemorySegmentName(segmentGroup, IsUMA()) << " GPU memory segment:"; + DebugLog(MessageId::kBudgetUpdated, this) + << "\tBudget: " << GPGMM_BYTES_TO_MB(info->Budget) << " MBs (" + << GPGMM_BYTES_TO_MB(info->CurrentUsage) << " used)."; if (info->CurrentReservation == 0) { - DebugLog(this) << "\tReserved: " << GPGMM_BYTES_TO_MB(info->CurrentReservation) - << " MBs (" << GPGMM_BYTES_TO_MB(info->AvailableForReservation) - << " available)."; + DebugLog(MessageId::kBudgetUpdated, this) + << "\tReserved: " << GPGMM_BYTES_TO_MB(info->CurrentReservation) << " MBs (" + << GPGMM_BYTES_TO_MB(info->AvailableForReservation) << " available)."; } } @@ -884,7 +885,7 @@ namespace gpgmm::d3d12 { ResidencyHeap* heap = static_cast(pHeap); if (heap->GetInfo().IsLocked) { - ErrorLog(this, MessageId::kBadOperation) + ErrorLog(MessageId::kBadOperation, this) << "Heap residency cannot be updated because it was locked. " "Please unlock the heap before updating."; return E_FAIL; @@ -892,9 +893,9 @@ namespace gpgmm::d3d12 { if (newStatus == RESIDENCY_HEAP_STATUS_UNKNOWN && heap->GetInfo().Status != RESIDENCY_HEAP_STATUS_UNKNOWN) { - ErrorLog(this, MessageId::kBadOperation) + ErrorLog(MessageId::kBadOperation, this) << "Heap residency cannot be unknown when previously known by the " - "residency manager. Please check the status before updating."; + "residency manager. Check the status before updating the state."; return E_FAIL; } diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 9102d84b..1d9b9da3 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -79,7 +79,7 @@ namespace gpgmm::d3d12 { // Allocation coordinates relative to the resource cannot be used when specifying // subresource-relative coordinates. if (subresource > 0 && GetInfo().Type == ALLOCATION_TYPE_SUBALLOCATED_WITHIN) { - ErrorLog(this, MessageId::kBadOperation) + ErrorLog(MessageId::kBadOperation, this) << "Mapping a sub-allocation within a resource cannot use " "non-zero subresource-relative coordinates."; return E_INVALIDARG; @@ -116,7 +116,7 @@ namespace gpgmm::d3d12 { // Allocation coordinates relative to the resource cannot be used when specifying // subresource-relative coordinates. if (subresource > 0 && GetInfo().Type == ALLOCATION_TYPE_SUBALLOCATED_WITHIN) { - ErrorLog(this, MessageId::kBadOperation) + ErrorLog(MessageId::kBadOperation, this) << "Unmapping a sub-allocation within a resource cannot use " "non-zero subresource-relative coordinates."; return; diff --git a/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp index 12007aa5..9ed405e3 100644 --- a/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp @@ -52,8 +52,9 @@ namespace gpgmm::d3d12 { std::lock_guard lock(mMutex); for (auto allocationEntry : mLiveAllocations) { const ResourceAllocation* allocation = allocationEntry->GetValue().GetAllocation(); - WarnLog() << "Live ResourceAllocation at " << ToHexStr(allocation) << ", " - << JSONSerializer::Serialize(allocation->GetInfo()).ToString(); + WarnLog(MessageId::kUnknown, this) + << "Live ResourceAllocation at " << ToHexStr(allocation) << ", " + << JSONSerializer::Serialize(allocation->GetInfo()).ToString(); } } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 10ebb1d5..c638a602 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -432,7 +432,7 @@ namespace gpgmm::d3d12 { } if (allocatorDescriptor.ResourceHeapTier > caps->GetMaxResourceHeapTierSupported()) { - ErrorLog(MessageId::kInvalidArgument, true) + ErrorLog(MessageId::kInvalidArgument) << "Resource heap tier exceeds the capabilities of the device " "(ResourceHeapTier:" << allocatorDescriptor.ResourceHeapTier << " vs " @@ -443,7 +443,7 @@ namespace gpgmm::d3d12 { if (allocatorDescriptor.ResourceHeapTier != 0 && allocatorDescriptor.ResourceHeapTier < caps->GetMaxResourceHeapTierSupported()) { - DebugLog(MessageId::kInvalidArgument, true) + DebugLog(MessageId::kInvalidArgument) << "Resource heap tier requested was lower than what the device " "supports. This is allowed but not recommended because it prevents " "resources of different categories from sharing the same heap."; @@ -451,7 +451,7 @@ namespace gpgmm::d3d12 { if (allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET && !pResidencyManager) { - WarnLog(MessageId::kInvalidArgument, true) + WarnLog(MessageId::kInvalidArgument) << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET has no effect when residency " "management does not exist. This is probably not what the " "developer intended to do. Please consider creating a residency " @@ -477,7 +477,7 @@ namespace gpgmm::d3d12 { // unsupported by the device. if ((allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY) && !caps->IsAdapterCacheCoherentUMA()) { - WarnLog(MessageId::kPerformanceWarning, true) + WarnLog(MessageId::kPerformanceWarning) << "RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY requested but disallowed " "because the device did not support cache-coherent UMA."; newDescriptor.Flags ^= RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY; @@ -485,7 +485,7 @@ namespace gpgmm::d3d12 { if ((allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT) && !caps->IsCreateHeapNotResidentSupported()) { - DebugLog(MessageId::kInvalidArgument, true) + DebugLog(MessageId::kInvalidArgument) << "RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT was requested but disallowed " "because the device did not support creation of non-resident heaps."; newDescriptor.Flags ^= RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT; @@ -513,7 +513,7 @@ namespace gpgmm::d3d12 { : kDefaultMemoryFragmentationLimit; if (newDescriptor.PreferredResourceHeapSize > newDescriptor.MaxResourceHeapSize) { - ErrorLog(MessageId::kInvalidArgument, true) + ErrorLog(MessageId::kInvalidArgument) << "Requested preferred resource heap size exceeded the capabilities " "of the device. This is probably not what the developer intended " "to do. Please consider using a smaller resource heap size."; @@ -537,7 +537,7 @@ namespace gpgmm::d3d12 { D3D12_INFO_QUEUE_FILTER emptyFilter{}; GPGMM_RETURN_IF_FAILED(leakMessageQueue->PushRetrievalFilter(&emptyFilter), mDevice); } else { - WarnLog(MessageId::kInvalidArgument, true) + WarnLog(MessageId::kInvalidArgument) << "GPGMM_ENABLE_DEVICE_LEAK_CHECKS has no effect because the D3D12 debug " "layer was either not installed or enabled. Please call " "ID3D12Debug::EnableDebugLayer before using this flag."; @@ -551,7 +551,7 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(resourceAllocator.get(), newDescriptor); - DebugLog(resourceAllocator.get(), MessageId::kObjectCreated) + DebugLog(MessageId::kObjectCreated, resourceAllocator.get()) << "Created resource allocator."; if (ppResourceAllocatorOut != nullptr) { @@ -913,7 +913,7 @@ namespace gpgmm::d3d12 { // required alignment is for this resource. if (resourceDescriptor.Alignment != 0 && resourceDescriptor.Alignment != resourceInfo.Alignment) { - DebugLog(this, MessageId::kPerformanceWarning) + DebugLog(MessageId::kPerformanceWarning, this) << "Re-aligned: " << resourceDescriptor.Alignment << " vs " << resourceInfo.Alignment << " bytes."; @@ -1015,7 +1015,7 @@ namespace gpgmm::d3d12 { const D3D12_RESOURCE_ALLOCATION_INFO resourceInfo = GetResourceAllocationInfo(newResourceDesc); if (resourceInfo.SizeInBytes > mMaxResourceHeapSize) { - ErrorLog(this, MessageId::kSizeExceeded) + ErrorLog(MessageId::kSizeExceeded, this) << "Unable to create resource allocation because the resource size exceeded " "the capabilities of the device: " << GPGMM_BYTES_TO_GB(resourceInfo.SizeInBytes) << " vs " @@ -1046,7 +1046,7 @@ namespace gpgmm::d3d12 { if (allocationDescriptor.HeapType != D3D12_HEAP_TYPE_READBACK) { heapType = D3D12_HEAP_TYPE_UPLOAD; } else { - DebugLog(this, MessageId::kPerformanceWarning) + DebugLog(MessageId::kPerformanceWarning, this) << "Unable to optimize resource allocation for supported UMA adapter " "due to D3D12_HEAP_TYPE_READBACK being specified. Please consider " "using an unspecified heap type if CPU read-back efficency is " @@ -1057,7 +1057,7 @@ namespace gpgmm::d3d12 { const RESOURCE_HEAP_TYPE resourceHeapType = GetResourceHeapType( newResourceDesc.Dimension, heapType, newResourceDesc.Flags, mResourceHeapTier); if (resourceHeapType == RESOURCE_HEAP_TYPE_INVALID) { - ErrorLog(this, MessageId::kInvalidArgument) + ErrorLog(MessageId::kInvalidArgument, this) << "Unable to create resource allocation because the resource type was invalid due " "to the combination of resource flags, descriptor, and resource heap tier."; return E_INVALIDARG; @@ -1071,7 +1071,7 @@ namespace gpgmm::d3d12 { D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(resourceHeapType, IsCreateHeapNotResidentEnabled()); if (!HasAllFlags(heapFlags, allocationDescriptor.ExtraRequiredHeapFlags)) { - WarnLog(this, MessageId::kPerformanceWarning) + WarnLog(MessageId::kPerformanceWarning, this) << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED was not requested but enabled anyway " "because " "the required heap flags were incompatible with resource heap type (" @@ -1115,7 +1115,7 @@ namespace gpgmm::d3d12 { if (GPGMM_UNLIKELY(requiresPadding)) { request.SizeInBytes += allocationDescriptor.ExtraRequiredResourcePadding; if (!neverSubAllocate) { - WarnLog(this, MessageId::kInvalidArgument) + WarnLog(MessageId::kInvalidArgument, this) << "Sub-allocation was enabled but has no effect when padding is requested: " << allocationDescriptor.ExtraRequiredResourcePadding << " bytes."; neverSubAllocate = true; @@ -1138,7 +1138,7 @@ namespace gpgmm::d3d12 { const uint64_t maxSegmentSize = mCaps->GetMaxSegmentSize(heapSegment); if (request.SizeInBytes > maxSegmentSize) { - ErrorLog(this, MessageId::kSizeExceeded) + ErrorLog(MessageId::kSizeExceeded, this) << "Unable to create resource allocation because the resource size exceeded " "the capabilities of the adapter: " << GPGMM_BYTES_TO_GB(request.SizeInBytes) << " vs " @@ -1162,7 +1162,7 @@ namespace gpgmm::d3d12 { request.AvailableForAllocation = allocationStats.FreeHeapUsage; - DebugLog(this, MessageId::kBudgetExceeded) + DebugLog(MessageId::kBudgetExceeded, this) << "Current usage exceeded budget: " << GPGMM_BYTES_TO_MB(currentVideoInfo->CurrentUsage) << " vs " << GPGMM_BYTES_TO_MB(currentVideoInfo->Budget) << " MBs (" @@ -1318,7 +1318,7 @@ namespace gpgmm::d3d12 { // allocations where sub-allocation or pooling is otherwise ineffective. // The time and space complexity of committed resource is driver-defined. if (request.NeverAllocate) { - ErrorLog(this, MessageId::kAllocatorFailed) + ErrorLog(MessageId::kAllocatorFailed, this) << "Unable to allocate memory for resource because no memory was allowed to " "be created."; return E_OUTOFMEMORY; @@ -1326,7 +1326,7 @@ namespace gpgmm::d3d12 { // Committed resources cannot specify resource heap size. if (GPGMM_UNLIKELY(requiresPadding)) { - ErrorLog(this, MessageId::kAllocatorFailed) + ErrorLog(MessageId::kAllocatorFailed, this) << "Unable to allocate memory for resource because a padding was specified " "but no resource allocator could be used."; return E_INVALIDARG; @@ -1334,15 +1334,11 @@ namespace gpgmm::d3d12 { if (!isAlwaysCommitted) { if (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_FALLBACK) { - ErrorLog(this, MessageId::kAllocatorFailed) + ErrorLog(MessageId::kAllocatorFailed, this) << "Unable to allocate memory for resource because no memory was could " "be created and fall-back was disabled."; return E_OUTOFMEMORY; } - - InfoEvent(this, MessageId::kAllocatorFailed) - << "Unable to allocate memory for a resource by using a heap, falling back to a " - "committed resource."; } ComPtr committedResource; @@ -1354,7 +1350,7 @@ namespace gpgmm::d3d12 { mDevice); if (resourceInfo.SizeInBytes > request.SizeInBytes) { - DebugLog(this, MessageId::kAlignmentMismatch) + DebugLog(MessageId::kAlignmentMismatch, this) << "Resource heap size is larger then the requested size: " << resourceInfo.SizeInBytes << " vs " << request.SizeInBytes << " bytes."; } @@ -1656,7 +1652,7 @@ namespace gpgmm::d3d12 { switch (message->ID) { case D3D12_MESSAGE_ID_LIVE_HEAP: case D3D12_MESSAGE_ID_LIVE_RESOURCE: { - WarnLog(this, MessageId::kPerformanceWarning) + WarnLog(MessageId::kPerformanceWarning, this) << "Device leak detected: " + std::string(message->pDescription); } break; default: @@ -1707,7 +1703,7 @@ namespace gpgmm::d3d12 { return S_OK; } default: { - WarnLog(this, MessageId::kBadOperation) + WarnLog(MessageId::kBadOperation, this) << "CheckFeatureSupport does not support feature (" + std::to_string(feature) + ")."; return E_INVALIDARG; diff --git a/src/gpgmm/utils/Log.cpp b/src/gpgmm/utils/Log.cpp index bfa6c813..c0915531 100644 --- a/src/gpgmm/utils/Log.cpp +++ b/src/gpgmm/utils/Log.cpp @@ -215,6 +215,26 @@ namespace gpgmm { return message; } + LogMessage DebugLog(MessageId messageId, const ObjectBase* object) { + return DebugLog(messageId, /*isExternal*/ false, + (object != nullptr) ? object->GetTypename() : "", object); + } + + LogMessage InfoLog(MessageId messageId, const ObjectBase* object) { + return InfoLog(messageId, /*isExternal*/ false, + (object != nullptr) ? object->GetTypename() : "", object); + } + + LogMessage WarnLog(MessageId messageId, const ObjectBase* object) { + return WarnLog(messageId, /*isExternal*/ false, + (object != nullptr) ? object->GetTypename() : "", object); + } + + LogMessage ErrorLog(MessageId messageId, const ObjectBase* object) { + return ErrorLog(messageId, /*isExternal*/ false, + (object != nullptr) ? object->GetTypename() : "", object); + } + LogMessage Log(MessageSeverity severity, MessageId messageId, bool isExternal, diff --git a/src/gpgmm/utils/Log.h b/src/gpgmm/utils/Log.h index 78dc7965..f7fd98cb 100644 --- a/src/gpgmm/utils/Log.h +++ b/src/gpgmm/utils/Log.h @@ -86,30 +86,39 @@ namespace gpgmm { std::ostringstream mStream; }; - // Short-hands to create a LogMessage with the respective severity. + LogMessage DebugLog(MessageId messageId, + bool isExternal, + const std::string& name, + const ObjectBase* object); + LogMessage InfoLog(MessageId messageId, + bool isExternal, + const std::string& name, + const ObjectBase* object); + LogMessage WarnLog(MessageId messageId, + bool isExternal, + const std::string& name, + const ObjectBase* object); + LogMessage ErrorLog(MessageId messageId, + bool isExternal, + const std::string& name, + const ObjectBase* object); + + // Short-hands to create a LogMessage internally. LogMessage DebugLog(MessageId messageId = MessageId::kUnknown, - bool isExternal = false, - const std::string& name = "", - const ObjectBase* mObject = nullptr); + const ObjectBase* object = nullptr); LogMessage InfoLog(MessageId messageId = MessageId::kUnknown, - bool isExternal = false, - const std::string& name = "", - const ObjectBase* mObject = nullptr); + const ObjectBase* object = nullptr); LogMessage WarnLog(MessageId messageId = MessageId::kUnknown, - bool isExternal = false, - const std::string& name = "", - const ObjectBase* mObject = nullptr); + const ObjectBase* object = nullptr); LogMessage ErrorLog(MessageId messageId = MessageId::kUnknown, - bool isExternal = false, - const std::string& name = "", - const ObjectBase* mObject = nullptr); + const ObjectBase* object = nullptr); // Create a LogMessage based on severity. LogMessage Log(MessageSeverity severity, MessageId messageId = MessageId::kUnknown, bool isExternal = false, const std::string& name = "", - const ObjectBase* mObject = nullptr); + const ObjectBase* object = nullptr); // GPGMM_DEBUG is a helper macro that creates a DebugLog and outputs file/line/function // information