Enabled committed allocations in custom pools!
Added test: TestStandardCustomCommittedPlaced.
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index 2a0ccc4..9fc000a 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -4985,7 +4985,9 @@
ID3D12Resource* res = NULL;
HRESULT hr = m_Device->CreateCommittedResource(
- &committedAllocParams.m_HeapProperties, committedAllocParams.m_HeapFlags, pResourceDesc, InitialResourceState,
+ &committedAllocParams.m_HeapProperties,
+ committedAllocParams.m_HeapFlags & ~RESOURCE_CLASS_HEAP_FLAGS, // D3D12 ERROR: ID3D12Device::CreateCommittedResource: When creating a committed resource, D3D12_HEAP_FLAGS must not have either D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES, D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES, nor D3D12_HEAP_FLAG_DENY_BUFFERS set. These flags will be set automatically to correspond with the committed resource type. [ STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS]
+ pResourceDesc, InitialResourceState,
pOptimizedClearValue, IID_PPV_ARGS(&res));
if(SUCCEEDED(hr))
{
@@ -5039,7 +5041,9 @@
ID3D12Resource* res = NULL;
HRESULT hr = m_Device4->CreateCommittedResource1(
- &committedAllocParams.m_HeapProperties, committedAllocParams.m_HeapFlags, pResourceDesc, InitialResourceState,
+ &committedAllocParams.m_HeapProperties,
+ committedAllocParams.m_HeapFlags & ~RESOURCE_CLASS_HEAP_FLAGS, // D3D12 ERROR: ID3D12Device::CreateCommittedResource: When creating a committed resource, D3D12_HEAP_FLAGS must not have either D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES, D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES, nor D3D12_HEAP_FLAG_DENY_BUFFERS set. These flags will be set automatically to correspond with the committed resource type. [ STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS]
+ pResourceDesc, InitialResourceState,
pOptimizedClearValue, pProtectedSession, IID_PPV_ARGS(&res));
if(SUCCEEDED(hr))
{
@@ -5094,7 +5098,9 @@
ID3D12Resource* res = NULL;
HRESULT hr = m_Device8->CreateCommittedResource2(
- &committedAllocParams.m_HeapProperties, committedAllocParams.m_HeapFlags, pResourceDesc, InitialResourceState,
+ &committedAllocParams.m_HeapProperties,
+ committedAllocParams.m_HeapFlags & ~RESOURCE_CLASS_HEAP_FLAGS, // D3D12 ERROR: ID3D12Device::CreateCommittedResource: When creating a committed resource, D3D12_HEAP_FLAGS must not have either D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES, D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES, nor D3D12_HEAP_FLAG_DENY_BUFFERS set. These flags will be set automatically to correspond with the committed resource type. [ STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS]
+ pResourceDesc, InitialResourceState,
pOptimizedClearValue, pProtectedSession, IID_PPV_ARGS(&res));
if(SUCCEEDED(hr))
{
@@ -5222,7 +5228,7 @@
outCommittedAllocationParams.m_HeapProperties = pool->GetDesc().HeapProperties;
outCommittedAllocationParams.m_HeapFlags = pool->GetDesc().HeapFlags;
- //outCommittedAllocationParams.m_List = pool->GetCommittedAllocationList(); // TODO
+ outCommittedAllocationParams.m_List = pool->GetCommittedAllocationList();
}
else
{
diff --git a/src/Tests.cpp b/src/Tests.cpp
index 3c3bed1..fbca62a 100644
--- a/src/Tests.cpp
+++ b/src/Tests.cpp
@@ -602,6 +602,7 @@
CHECK_BOOL( poolStats.UnusedBytes == poolStats.BlockCount * poolDesc.BlockSize );
// # SetName and GetName
+
static const wchar_t* NAME = L"Custom pool name 1";
pool->SetName(NAME);
CHECK_BOOL( wcscmp(pool->GetName(), NAME) == 0 );
@@ -646,6 +647,7 @@
CHECK_BOOL( globalStatsCurr.Total.UsedBytes == globalStatsBeg.Total.UsedBytes + poolStats.UsedBytes );
// # NEVER_ALLOCATE and COMMITTED should fail
+ // (Committed allocations not allowed in this pool because BlockSize != 0.)
for(uint32_t i = 0; i < 2; ++i)
{
@@ -790,6 +792,62 @@
CHECK_HR(hr);
}
+static void TestStandardCustomCommittedPlaced(const TestContext& ctx)
+{
+ wprintf(L"Test standard, custom, committed, placed\n");
+
+ static const D3D12_HEAP_TYPE heapType = D3D12_HEAP_TYPE_DEFAULT;
+ static const UINT64 bufferSize = 1024;
+
+ D3D12MA::POOL_DESC poolDesc = {};
+ poolDesc.HeapProperties.Type = heapType;
+ poolDesc.HeapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
+
+ D3D12MA::Pool* poolPtr;
+ CHECK_HR(ctx.allocator->CreatePool(&poolDesc, &poolPtr));
+ PoolUniquePtr pool{poolPtr};
+
+ std::vector<AllocationUniquePtr> allocations;
+
+ D3D12_RESOURCE_DESC resDesc = {};
+ FillResourceDescForBuffer(resDesc, bufferSize);
+
+ for(uint32_t standardCustomI = 0; standardCustomI < 2; ++standardCustomI)
+ {
+ const bool useCustomPool = standardCustomI > 0;
+ for(uint32_t flagsI = 0; flagsI < 3; ++flagsI)
+ {
+ const bool useCommitted = flagsI > 0;
+ const bool neverAllocate = flagsI > 1;
+
+ D3D12MA::ALLOCATION_DESC allocDesc = {};
+ if(useCustomPool)
+ {
+ allocDesc.CustomPool = pool.get();
+ allocDesc.HeapType = (D3D12_HEAP_TYPE)0xCDCDCDCD; // Should be ignored.
+ allocDesc.ExtraHeapFlags = (D3D12_HEAP_FLAGS)0xCDCDCDCD; // Should be ignored.
+ }
+ else
+ allocDesc.HeapType = heapType;
+ if(useCommitted)
+ allocDesc.Flags |= D3D12MA::ALLOCATION_FLAG_COMMITTED;
+ if(neverAllocate)
+ allocDesc.Flags |= D3D12MA::ALLOCATION_FLAG_NEVER_ALLOCATE;
+
+ D3D12MA::Allocation* allocPtr = NULL;
+ HRESULT hr = ctx.allocator->CreateResource(&allocDesc, &resDesc,
+ D3D12_RESOURCE_STATE_COMMON,
+ NULL, // pOptimizedClearValue
+ &allocPtr, IID_NULL, NULL);
+ if(allocPtr)
+ allocations.push_back(AllocationUniquePtr{allocPtr});
+
+ bool expectSuccess = !neverAllocate; // NEVER_ALLOCATE should always fail with COMMITTED.
+ CHECK_BOOL(expectSuccess == SUCCEEDED(hr));
+ }
+ }
+}
+
static void TestAliasingMemory(const TestContext& ctx)
{
wprintf(L"Test aliasing memory\n");
@@ -1490,6 +1548,7 @@
TestOtherComInterface(ctx);
TestCustomPools(ctx);
TestCustomHeaps(ctx);
+ TestStandardCustomCommittedPlaced(ctx);
TestAliasingMemory(ctx);
TestMapping(ctx);
TestStats(ctx);