From 90a230ac2b59d85f64b96d148707809b22e4be09 Mon Sep 17 00:00:00 2001 From: sawickiap Date: Thu, 13 Nov 2025 21:13:08 +0100 Subject: [PATCH 1/3] Disabled usage of small alignment when tight alignment is enabled in AllocatorPimpl::GetResourceAllocationInfo Hopefully fixes https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator/issues/83 - thanks @rtryan98 --- src/D3D12MemAlloc.cpp | 1 + src/D3D12Sample.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index 0666868..f01c85c 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp @@ -7849,6 +7849,7 @@ HRESULT AllocatorPimpl::GetResourceAllocationInfo( #if D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT if (inOutResourceDesc.Alignment == 0 && + !IsTightAlignmentEnabled() && (inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D || inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D || inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) && diff --git a/src/D3D12Sample.cpp b/src/D3D12Sample.cpp index 40b8185..32c5147 100644 --- a/src/D3D12Sample.cpp +++ b/src/D3D12Sample.cpp @@ -605,8 +605,8 @@ static void PrintAdapterInformation(IDXGIAdapter1* adapter) assert(0); } - wprintf(L"D3D12_FEATURE_DATA_D3D12_OPTIONS16:\n"); - wprintf(L" GPUUploadHeapSupported = %u\n", g_Allocator->IsGPUUploadHeapSupported() ? 1 : 0); + wprintf(L"GPUUploadHeapSupported = %u\n", g_Allocator->IsGPUUploadHeapSupported() ? 1 : 0); + wprintf(L"TightAlignmentSupported = %u\n", g_Allocator->IsTightAlignmentSupported() ? 1 : 0); ComPtr adapter3; if(SUCCEEDED(adapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) From cea8c63e82a7a3647b61af304cf481b5adf1d379 Mon Sep 17 00:00:00 2001 From: sawickiap Date: Fri, 14 Nov 2025 12:54:02 +0100 Subject: [PATCH 2/3] Improved logic in AllocatorPimpl::GetResourceAllocationInfo See https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator/issues/83 --- src/D3D12MemAlloc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index f01c85c..0b8d8fd 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp @@ -215,6 +215,7 @@ static const D3D12_HEAP_FLAGS RESOURCE_CLASS_HEAP_FLAGS = static const D3D12_RESIDENCY_PRIORITY D3D12_RESIDENCY_PRIORITY_NONE = D3D12_RESIDENCY_PRIORITY(0); static const D3D12_HEAP_TYPE D3D12_HEAP_TYPE_GPU_UPLOAD_COPY = (D3D12_HEAP_TYPE)5; +static const D3D12_RESOURCE_FLAGS D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY = (D3D12_RESOURCE_FLAGS)0x400; #ifndef _D3D12MA_ENUM_DECLARATIONS @@ -7849,7 +7850,7 @@ HRESULT AllocatorPimpl::GetResourceAllocationInfo( #if D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT if (inOutResourceDesc.Alignment == 0 && - !IsTightAlignmentEnabled() && + (inOutResourceDesc.Flags & D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY) == 0 && (inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE1D || inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D || inOutResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) && From 07f1e1e89735c6f44ea828b81b3bdb69e555a8cf Mon Sep 17 00:00:00 2001 From: sawickiap Date: Thu, 20 Nov 2025 09:37:27 +0100 Subject: [PATCH 3/3] Loosened restriction on alignment and size in ValidateAllocateMemoryParameters --- src/D3D12MemAlloc.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index 0b8d8fd..96243ef 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp @@ -817,11 +817,9 @@ static bool ValidateAllocateMemoryParameters( return pAllocDesc && pAllocInfo && ppAllocation && - (pAllocInfo->Alignment == 0 || - pAllocInfo->Alignment == D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT || - pAllocInfo->Alignment == D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT) && - pAllocInfo->SizeInBytes != 0 && - pAllocInfo->SizeInBytes % (64ull * 1024) == 0; + IsPow2(pAllocInfo->Alignment) && + pAllocInfo->SizeInBytes > 0 && + pAllocInfo->SizeInBytes % 4 == 0; } #endif // _D3D12MA_FUNCTIONS @@ -9880,7 +9878,7 @@ HRESULT Allocator::AllocateMemory( return E_INVALIDARG; } D3D12MA_DEBUG_GLOBAL_MUTEX_LOCK - return m_Pimpl->AllocateMemory(pAllocDesc, pAllocInfo, ppAllocation); + return m_Pimpl->AllocateMemory(pAllocDesc, pAllocInfo, ppAllocation); } HRESULT Allocator::CreateAliasingResource(