Skip to content

Commit 619c795

Browse files
Removed macros D3D12MA_OPTIONS16_SUPPORTED, D3D12MA_TIGHT_ALIGNMENT_SUPPORTED from the public interface
Also removed them from the Cmake script. They are now automatically determined based on D3D12_PREVIEW_SDK_VERSION, D3D12_SDK_VERSION macro. Also made fixes in tests.
1 parent 42bfb6b commit 619c795

5 files changed

Lines changed: 45 additions & 34 deletions

File tree

include/D3D12MemAlloc.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,17 +1130,13 @@ class D3D12MA_API Allocator : public IUnknownImpl
11301130
When true, you can use `D3D12_HEAP_TYPE_GPU_UPLOAD`.
11311131
11321132
This flag is fetched from `D3D12_FEATURE_D3D12_OPTIONS16::GPUUploadHeapSupported`.
1133-
1134-
`#define D3D12MA_OPTIONS16_SUPPORTED 1` is needed for the compilation of this library. Otherwise the flag is always false.
11351133
*/
11361134
BOOL IsGPUUploadHeapSupported() const;
11371135
/** \brief Returns true if resource tight alignment is supported on the current system.
11381136
When supported, it is automatically used by the library, unless
11391137
#ALLOCATOR_FLAG_DONT_USE_TIGHT_ALIGNMENT flag was specified on allocator creation.
11401138
11411139
This flag is fetched from `D3D12_FEATURE_DATA_TIGHT_ALIGNMENT::SupportTier`.
1142-
1143-
`#define D3D12MA_TIGHT_ALIGNMENT_SUPPORTED 1` is needed for the compilation of this library. Otherwise the flag is always false.
11441140
*/
11451141
BOOL IsTightAlignmentSupported() const;
11461142
/** \brief Returns total amount of memory of specific segment group, in bytes.

src/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,3 @@ if(D3D12MA_AGILITY_SDK_DIRECTORY)
190190
else()
191191
message(STATUS "DX12 Agility SDK not used.")
192192
endif()
193-
194-
option(D3D12MA_OPTIONS16_SUPPORTED "Set if using Agility SDK 1.710.0-preview or newer that defines D3D12_FEATURE_DATA_D3D12_OPTIONS16." OFF)
195-
if(D3D12MA_OPTIONS16_SUPPORTED)
196-
target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_OPTIONS16_SUPPORTED=1)
197-
if(${D3D12MA_BUILD_SAMPLE} AND ${WIN32})
198-
target_compile_definitions(D3D12Sample PRIVATE D3D12MA_OPTIONS16_SUPPORTED=1)
199-
endif()
200-
endif()
201-
202-
option(D3D12MA_TIGHT_ALIGNMENT_SUPPORTED "Set if using Agility SDK 1.716.0-preview or newer that defines D3D12_FEATURE_DATA_TIGHT_ALIGNMENT." OFF)
203-
if(D3D12MA_TIGHT_ALIGNMENT_SUPPORTED)
204-
target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_TIGHT_ALIGNMENT_SUPPORTED=1)
205-
if(${D3D12MA_BUILD_SAMPLE} AND ${WIN32})
206-
target_compile_definitions(D3D12Sample PRIVATE D3D12MA_TIGHT_ALIGNMENT_SUPPORTED=1)
207-
endif()
208-
endif()

src/D3D12MemAlloc.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ especially to test compatibility with D3D12_RESOURCE_HEAP_TIER_1 on modern GPUs.
107107
#define D3D12MA_DEFAULT_BLOCK_SIZE (64ull * 1024 * 1024)
108108
#endif
109109

110+
#ifndef D3D12MA_TIGHT_ALIGNMENT_SUPPORTED
111+
#if D3D12_PREVIEW_SDK_VERSION >= 716
112+
#define D3D12MA_TIGHT_ALIGNMENT_SUPPORTED 1
113+
#else
114+
#define D3D12MA_TIGHT_ALIGNMENT_SUPPORTED 0
115+
#endif
116+
#endif
117+
118+
#ifndef D3D12MA_OPTIONS16_SUPPORTED
119+
#if D3D12_SDK_VERSION >= 610
120+
#define D3D12MA_OPTIONS16_SUPPORTED 1
121+
#else
122+
#define D3D12MA_OPTIONS16_SUPPORTED 0
123+
#endif
124+
#endif
125+
110126
#ifndef D3D12MA_DEBUG_LOG
111127
#define D3D12MA_DEBUG_LOG(format, ...)
112128
/*
@@ -6168,9 +6184,6 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc)
61686184
m_D3D12Options.ResourceHeapTier = (D3D12MA_FORCE_RESOURCE_HEAP_TIER);
61696185
#endif
61706186

6171-
// You must define this macro to like `#define D3D12MA_OPTIONS16_SUPPORTED 1` to enable GPU Upload Heaps!
6172-
// Unfortunately there is no way to programmatically check if the included <d3d12.h> defines D3D12_FEATURE_DATA_D3D12_OPTIONS16 or not.
6173-
// Main interfaces have respective macros like __ID3D12Device4_INTERFACE_DEFINED__, but structures like this do not.
61746187
#if D3D12MA_OPTIONS16_SUPPORTED
61756188
{
61766189
D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16 = {};
@@ -6180,11 +6193,8 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc)
61806193
m_GPUUploadHeapSupported = options16.GPUUploadHeapSupported;
61816194
}
61826195
}
6183-
#endif
6196+
#endif // #if D3D12MA_OPTIONS16_SUPPORTED
61846197

6185-
// You must define macro `#define D3D12MA_TIGHT_ALIGNMENT_SUPPORTED 1` to enable resource tight alignment!
6186-
// Unfortunately there is no way to programmatically check if the included <d3d12.h> defines D3D12_FEATURE_DATA_TIGHT_ALIGNMENT or not.
6187-
// Main interfaces have respective macros like __ID3D12Device4_INTERFACE_DEFINED__, but structures like this do not.
61886198
#if D3D12MA_TIGHT_ALIGNMENT_SUPPORTED
61896199
{
61906200
D3D12_FEATURE_DATA_TIGHT_ALIGNMENT tightAlignment = {};
@@ -6202,7 +6212,7 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc)
62026212
}
62036213
}
62046214
}
6205-
#endif
6215+
#endif // #if D3D12MA_TIGHT_ALIGNMENT_SUPPORTED
62066216

62076217
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &m_D3D12Architecture, sizeof(m_D3D12Architecture));
62086218
if (FAILED(hr))
@@ -7427,7 +7437,7 @@ HRESULT AllocatorPimpl::CalcAllocationParams(const ALLOCATION_DESC& allocDesc, U
74277437
outPreferCommitted = false;
74287438

74297439
D3D12MA_ASSERT((allocDesc.HeapType != D3D12_HEAP_TYPE_GPU_UPLOAD_COPY || IsGPUUploadHeapSupported()) &&
7430-
"Trying to allocate from D3D12_HEAP_TYPE_GPU_UPLOAD while GPUUploadHeapSupported == FALSE or D3D12MA_OPTIONS16_SUPPORTED macro was not defined when compiling D3D12MA library.");
7440+
"Trying to allocate from D3D12_HEAP_TYPE_GPU_UPLOAD while GPUUploadHeapSupported == FALSE.");
74317441

74327442
bool msaaAlwaysCommitted;
74337443
if (allocDesc.CustomPool != NULL)

src/Doxyfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8
4242
# title of most generated pages and in a few other places.
4343
# The default value is: My Project.
4444

45-
PROJECT_NAME = "Direct3D 12 Memory Allocator"
45+
PROJECT_NAME = "D3D12 Memory Allocator"
4646

4747
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
4848
# could be handy for archiving the generated documentation or if some version
@@ -2372,6 +2372,8 @@ PREDEFINED = __ID3D12Device1_INTERFACE_DEFINED__ \
23722372
__ID3D12Device4_INTERFACE_DEFINED__ \
23732373
__ID3D12Device8_INTERFACE_DEFINED__ \
23742374
__ID3D12Device10_INTERFACE_DEFINED__ \
2375+
D3D12_PREVIEW_SDK_VERSION=716 \
2376+
D3D12_SDK_VERSION=716 \
23752377
protected=private
23762378

23772379
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this

src/Tests.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static constexpr UINT64 MEGABYTE = 1024 * KILOBYTE;
5151
static constexpr CONFIG_TYPE ConfigType = CONFIG_TYPE_AVERAGE;
5252
static const char* FREE_ORDER_NAMES[] = { "FORWARD", "BACKWARD", "RANDOM", };
5353

54+
constexpr D3D12_RESOURCE_FLAGS D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY = (D3D12_RESOURCE_FLAGS)0x400;
55+
5456
// Indexes match enum D3D12_HEAP_TYPE.
5557
static const WCHAR* const HEAP_TYPE_NAMES[] =
5658
{
@@ -204,6 +206,10 @@ static void FillAllocationsDataGPU(const TestContext& ctx, const ComPtr<D3D12MA:
204206
D3D12_RESOURCE_DESC resDesc = alloc->GetResource()->GetDesc();
205207
if (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
206208
{
209+
// Fix for D3D12 ERROR: ID3D12Device::CreatePlacedResource: D3D12_RESOURCE_DESC::Alignment is invalid. The value is 8. When D3D12_RESOURCE_DESC::Flag bit for D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT is set, Alignment must be 0. [ STATE_CREATION ERROR #721: CREATERESOURCE_INVALIDALIGNMENT]
210+
if ((resDesc.Flags & D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY) != 0)
211+
resDesc.Alignment = 0;
212+
207213
ComPtr<D3D12MA::Allocation> uploadAlloc;
208214
CHECK_HR(ctx.allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_GENERIC_READ,
209215
nullptr, &uploadAlloc, IID_NULL, nullptr));
@@ -296,6 +302,10 @@ static void ValidateAllocationsDataGPU(const TestContext& ctx, const ComPtr<D3D1
296302
D3D12_RESOURCE_DESC resDesc = alloc->GetResource()->GetDesc();
297303
if (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
298304
{
305+
// Fix for D3D12 ERROR: ID3D12Device::CreatePlacedResource: D3D12_RESOURCE_DESC::Alignment is invalid. The value is 8. When D3D12_RESOURCE_DESC::Flag bit for D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT is set, Alignment must be 0. [ STATE_CREATION ERROR #721: CREATERESOURCE_INVALIDALIGNMENT]
306+
if ((resDesc.Flags & D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY) != 0)
307+
resDesc.Alignment = 0;
308+
299309
ComPtr<D3D12MA::Allocation> downloadAlloc;
300310
CHECK_HR(ctx.allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COPY_DEST,
301311
nullptr, &downloadAlloc, IID_NULL, nullptr));
@@ -762,7 +772,13 @@ static void TestSmallBuffers(const TestContext& ctx)
762772
CHECK_HR(ctx.allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON,
763773
nullptr, &resWithAlloc.allocation, IID_PPV_ARGS(&resWithAlloc.resource)));
764774
CHECK_BOOL(resWithAlloc.allocation && resWithAlloc.allocation->GetResource());
765-
CHECK_BOOL(!resWithAlloc.allocation->GetHeap()); // Expected to be committed.
775+
// May or may not be committed, depending on the PREFER_SMALL_BUFFERS_COMMITTED
776+
// and TIGHT_ALIGNMENT settings.
777+
const bool isCommitted = resWithAlloc.allocation->GetHeap() == NULL;
778+
if (isCommitted)
779+
wprintf(L" Small buffer %llu B inside a custom pool was created as committed.\n", resDesc.Width);
780+
else
781+
wprintf(L" Small buffer %llu B inside a custom pool was created as placed.\n", resDesc.Width);
766782
}
767783

768784
// Test 3: NEVER_ALLOCATE.
@@ -2857,7 +2873,7 @@ static void TestDevice10(const TestContext& ctx)
28572873

28582874
static void TestGPUUploadHeap(const TestContext& ctx)
28592875
{
2860-
#if D3D12MA_OPTIONS16_SUPPORTED
2876+
#if D3D12_SDK_VERSION >= 610
28612877
using namespace D3D12MA;
28622878

28632879
wprintf(L"Test GPU Upload Heap\n");
@@ -3003,7 +3019,6 @@ static void TestGPUUploadHeap(const TestContext& ctx)
30033019

30043020
static void TestTightAlignment(const TestContext& ctx)
30053021
{
3006-
#if D3D12MA_TIGHT_ALIGNMENT_SUPPORTED
30073022
using namespace D3D12MA;
30083023

30093024
wprintf(L"Test resource tight alignment\n");
@@ -3047,7 +3062,6 @@ static void TestTightAlignment(const TestContext& ctx)
30473062
resDesc.Width,
30483063
allocs[1]->GetOffset());
30493064
}
3050-
#endif
30513065
}
30523066

30533067
static void TestVirtualBlocks(const TestContext& ctx)
@@ -3418,6 +3432,11 @@ static void ProcessDefragmentationPass(const TestContext& ctx, D3D12MA::DEFRAGME
34183432
const bool isDefaultHeap = stepInfo.pMoves[i].pSrcAllocation->GetHeap()->GetDesc().Properties.Type == D3D12_HEAP_TYPE_DEFAULT;
34193433
// Create new resource
34203434
D3D12_RESOURCE_DESC desc = stepInfo.pMoves[i].pSrcAllocation->GetResource()->GetDesc();
3435+
3436+
// Fix for D3D12 ERROR: ID3D12Device::CreatePlacedResource: D3D12_RESOURCE_DESC::Alignment is invalid. The value is 8. When D3D12_RESOURCE_DESC::Flag bit for D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT is set, Alignment must be 0. [ STATE_CREATION ERROR #721: CREATERESOURCE_INVALIDALIGNMENT]
3437+
if ((desc.Flags & D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT_COPY) != 0)
3438+
desc.Alignment = 0;
3439+
34213440
ComPtr<ID3D12Resource> dstRes;
34223441
CHECK_HR(ctx.device->CreatePlacedResource(stepInfo.pMoves[i].pDstTmpAllocation->GetHeap(),
34233442
stepInfo.pMoves[i].pDstTmpAllocation->GetOffset(), &desc,

0 commit comments

Comments
 (0)