mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git
synced 2024-11-24 21:10:11 +00:00
Enabled committed allocations in custom pools!
Added test: TestStandardCustomCommittedPlaced.
This commit is contained in:
parent
47bedc01ff
commit
d647ce1202
@ -4985,7 +4985,9 @@ HRESULT AllocatorPimpl::AllocateCommittedResource(
|
|||||||
|
|
||||||
ID3D12Resource* res = NULL;
|
ID3D12Resource* res = NULL;
|
||||||
HRESULT hr = m_Device->CreateCommittedResource(
|
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));
|
pOptimizedClearValue, IID_PPV_ARGS(&res));
|
||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
@ -5039,7 +5041,9 @@ HRESULT AllocatorPimpl::AllocateCommittedResource1(
|
|||||||
|
|
||||||
ID3D12Resource* res = NULL;
|
ID3D12Resource* res = NULL;
|
||||||
HRESULT hr = m_Device4->CreateCommittedResource1(
|
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));
|
pOptimizedClearValue, pProtectedSession, IID_PPV_ARGS(&res));
|
||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
@ -5094,7 +5098,9 @@ HRESULT AllocatorPimpl::AllocateCommittedResource2(
|
|||||||
|
|
||||||
ID3D12Resource* res = NULL;
|
ID3D12Resource* res = NULL;
|
||||||
HRESULT hr = m_Device8->CreateCommittedResource2(
|
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));
|
pOptimizedClearValue, pProtectedSession, IID_PPV_ARGS(&res));
|
||||||
if(SUCCEEDED(hr))
|
if(SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
@ -5222,7 +5228,7 @@ HRESULT AllocatorPimpl::CalcAllocationParams(const ALLOCATION_DESC& allocDesc, U
|
|||||||
|
|
||||||
outCommittedAllocationParams.m_HeapProperties = pool->GetDesc().HeapProperties;
|
outCommittedAllocationParams.m_HeapProperties = pool->GetDesc().HeapProperties;
|
||||||
outCommittedAllocationParams.m_HeapFlags = pool->GetDesc().HeapFlags;
|
outCommittedAllocationParams.m_HeapFlags = pool->GetDesc().HeapFlags;
|
||||||
//outCommittedAllocationParams.m_List = pool->GetCommittedAllocationList(); // TODO
|
outCommittedAllocationParams.m_List = pool->GetCommittedAllocationList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -602,6 +602,7 @@ static void TestCustomPools(const TestContext& ctx)
|
|||||||
CHECK_BOOL( poolStats.UnusedBytes == poolStats.BlockCount * poolDesc.BlockSize );
|
CHECK_BOOL( poolStats.UnusedBytes == poolStats.BlockCount * poolDesc.BlockSize );
|
||||||
|
|
||||||
// # SetName and GetName
|
// # SetName and GetName
|
||||||
|
|
||||||
static const wchar_t* NAME = L"Custom pool name 1";
|
static const wchar_t* NAME = L"Custom pool name 1";
|
||||||
pool->SetName(NAME);
|
pool->SetName(NAME);
|
||||||
CHECK_BOOL( wcscmp(pool->GetName(), NAME) == 0 );
|
CHECK_BOOL( wcscmp(pool->GetName(), NAME) == 0 );
|
||||||
@ -646,6 +647,7 @@ static void TestCustomPools(const TestContext& ctx)
|
|||||||
CHECK_BOOL( globalStatsCurr.Total.UsedBytes == globalStatsBeg.Total.UsedBytes + poolStats.UsedBytes );
|
CHECK_BOOL( globalStatsCurr.Total.UsedBytes == globalStatsBeg.Total.UsedBytes + poolStats.UsedBytes );
|
||||||
|
|
||||||
// # NEVER_ALLOCATE and COMMITTED should fail
|
// # NEVER_ALLOCATE and COMMITTED should fail
|
||||||
|
// (Committed allocations not allowed in this pool because BlockSize != 0.)
|
||||||
|
|
||||||
for(uint32_t i = 0; i < 2; ++i)
|
for(uint32_t i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
@ -790,6 +792,62 @@ static void TestCustomHeaps(const TestContext& ctx)
|
|||||||
CHECK_HR(hr);
|
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)
|
static void TestAliasingMemory(const TestContext& ctx)
|
||||||
{
|
{
|
||||||
wprintf(L"Test aliasing memory\n");
|
wprintf(L"Test aliasing memory\n");
|
||||||
@ -1490,6 +1548,7 @@ static void TestGroupBasics(const TestContext& ctx)
|
|||||||
TestOtherComInterface(ctx);
|
TestOtherComInterface(ctx);
|
||||||
TestCustomPools(ctx);
|
TestCustomPools(ctx);
|
||||||
TestCustomHeaps(ctx);
|
TestCustomHeaps(ctx);
|
||||||
|
TestStandardCustomCommittedPlaced(ctx);
|
||||||
TestAliasingMemory(ctx);
|
TestAliasingMemory(ctx);
|
||||||
TestMapping(ctx);
|
TestMapping(ctx);
|
||||||
TestStats(ctx);
|
TestStats(ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user