From d1bf6ccb70088cc3a1448ed7316f48e1d674d0c8 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 2 Mar 2023 09:04:29 -0800 Subject: [PATCH] Move alignment mismatch behind flag. --- include/gpgmm_d3d12.h | 10 ++++++++++ src/gpgmm/common/MemoryAllocator.cpp | 4 ++-- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index 6600f293c..5b086457d 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -988,6 +988,16 @@ namespace gpgmm::d3d12 { Mostly used when external resources are residency managed elsewhere. */ ALLOCATION_FLAG_DISABLE_RESIDENCY = 0x80, + + /** \brief Report alignment mismatches upon successful resource creation. + + Flag is used to report when requested size does not match the allocation size due to + resource or allocation alignment requirements. + + Must compile with GPGMM_ENABLE_MEMORY_ALIGN_CHECKS to use as the request size + is normally not tracked. + */ + ALLOCATION_FLAG_WARN_ON_ALIGNMENT_MISMATCH = 0x100, }; DEFINE_ENUM_FLAG_OPERATORS(ALLOCATION_FLAGS) diff --git a/src/gpgmm/common/MemoryAllocator.cpp b/src/gpgmm/common/MemoryAllocator.cpp index c893a4915..b7edd830a 100644 --- a/src/gpgmm/common/MemoryAllocator.cpp +++ b/src/gpgmm/common/MemoryAllocator.cpp @@ -210,8 +210,8 @@ namespace gpgmm { void MemoryAllocator::CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation) { if (allocation.GetSize() > allocation.GetRequestSize()) { - DebugEvent(this, MessageId::kAlignmentMismatch) - << "Resource allocation is larger then the requested size (" + + WarningLog(MessageId::kAlignmentMismatch) + << "Allocation is larger then the requested size (" + std::to_string(allocation.GetSize()) + " vs " + std::to_string(allocation.GetRequestSize()) + " bytes)."; } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 4fc27ad7d..184c12ee5 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -949,10 +949,10 @@ namespace gpgmm::d3d12 { ReturnIfFailed(QueryStatsInternal(nullptr)); } -#if defined(GPGMM_ENABLE_MEMORY_ALIGN_CHECKS) - // Allocation is subject to alignment requirements per allocator or allocation method. - CheckAndReportAllocationMisalignment(*static_cast(allocation.Get())); -#endif + if (allocationDescriptor.Flags & ALLOCATION_FLAG_WARN_ON_ALIGNMENT_MISMATCH) { + CheckAndReportAllocationMisalignment( + *static_cast(allocation.Get())); + } if (ppResourceAllocationOut != nullptr) { *ppResourceAllocationOut = allocation.Detach();