From 4570dd918604c0cea8c7f44aef1b8e5538448f9a Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 30 Mar 2023 09:27:01 -0700 Subject: [PATCH] Minor improvements to alignment mismatch logging. --- src/gpgmm/common/DedicatedMemoryAllocator.cpp | 7 +++++++ src/gpgmm/d3d12/BufferAllocatorD3D12.cpp | 17 ++++++++--------- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 6 ++++++ src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.cpp b/src/gpgmm/common/DedicatedMemoryAllocator.cpp index 3e238b9e7..3e9d9b883 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.cpp +++ b/src/gpgmm/common/DedicatedMemoryAllocator.cpp @@ -36,10 +36,17 @@ namespace gpgmm { MemoryAllocationRequest memoryRequest = request; memoryRequest.Alignment = mMemoryAlignment; + memoryRequest.SizeInBytes = AlignTo(request.SizeInBytes, request.Alignment); std::unique_ptr allocation; GPGMM_TRY_ASSIGN(GetNextInChain()->TryAllocateMemory(memoryRequest), allocation); + if (memoryRequest.SizeInBytes > request.SizeInBytes) { + DebugLog(MessageId::kAlignmentMismatch) + << "Memory allocation was larger then the requested size: " + << memoryRequest.SizeInBytes << " vs " << request.SizeInBytes << " bytes."; + } + mStats.UsedBlockCount++; mStats.UsedBlockUsage += allocation->GetSize(); diff --git a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp index e1f082f63..e8014660c 100644 --- a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp @@ -46,16 +46,8 @@ namespace gpgmm::d3d12 { return {}; } - const uint64_t heapSize = AlignTo(request.SizeInBytes, request.Alignment); - if (heapSize > request.SizeInBytes) { - DebugEvent(this, MessageId::kAlignmentMismatch) - << "Resource heap size is larger then the requested size (" + - std::to_string(heapSize) + " vs " + std::to_string(request.SizeInBytes) + - " bytes)."; - } - D3D12_RESOURCE_ALLOCATION_INFO info = {}; - info.SizeInBytes = heapSize; + info.SizeInBytes = AlignTo(request.SizeInBytes, request.Alignment); info.Alignment = request.Alignment; D3D12_RESOURCE_DESC resourceDescriptor; @@ -77,10 +69,17 @@ namespace gpgmm::d3d12 { mHeapProperties, mHeapFlags, info, &resourceDescriptor, /*pOptimizedClearValue*/ nullptr, mInitialResourceState, /*resourceOut*/ nullptr, &resourceHeap); + if (FAILED(hr)) { return {static_cast(hr)}; } + if (info.SizeInBytes > request.SizeInBytes) { + DebugLog(MessageId::kAlignmentMismatch) + << "Memory allocation size was larger then the requested size: " << info.SizeInBytes + << " vs " << request.SizeInBytes << " bytes."; + } + mStats.UsedMemoryUsage += resourceHeap->GetSize(); mStats.UsedMemoryCount++; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 134e956e2..ca3be966e 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1295,6 +1295,12 @@ namespace gpgmm::d3d12 { &newResourceDesc, clearValue, initialResourceState, &committedResource, &resourceHeap)); + if (resourceInfo.SizeInBytes > request.SizeInBytes) { + DebugLog(MessageId::kAlignmentMismatch) + << "Resource heap size is larger then the requested size: " + << resourceInfo.SizeInBytes << " vs " << request.SizeInBytes << " bytes."; + } + // Using committed resources will create a tightly allocated resource allocations. // This means the block and heap size should be equal (modulo driver padding). const uint64_t& allocationSize = resourceHeap->GetSize(); diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index 6a335bdbf..cb8d5d5fd 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -82,7 +82,7 @@ namespace gpgmm::d3d12 { } if (resourceHeapDesc.SizeInBytes > request.SizeInBytes) { - DebugEvent(this, MessageId::kAlignmentMismatch) + DebugLog(MessageId::kAlignmentMismatch) << "Resource heap was larger then the requested size: " << resourceHeapDesc.SizeInBytes << " vs " << request.SizeInBytes << " bytes."; }