@@ -5578,6 +5578,7 @@ class BlockVector
5578
5578
UINT64 size,
5579
5579
UINT64 alignment,
5580
5580
const ALLOCATION_DESC& allocDesc,
5581
+ bool committedAllowed,
5581
5582
size_t allocationCount,
5582
5583
Allocation** pAllocations);
5583
5584
@@ -5588,6 +5589,7 @@ class BlockVector
5588
5589
UINT64 alignment,
5589
5590
const ALLOCATION_DESC& allocDesc,
5590
5591
const CREATE_RESOURCE_PARAMS& createParams,
5592
+ bool committedAllowed,
5591
5593
Allocation** ppAllocation,
5592
5594
REFIID riidResource,
5593
5595
void ** ppvResource);
@@ -5638,6 +5640,7 @@ class BlockVector
5638
5640
UINT64 size,
5639
5641
UINT64 alignment,
5640
5642
const ALLOCATION_DESC& allocDesc,
5643
+ bool committedAllowed,
5641
5644
Allocation** pAllocation);
5642
5645
5643
5646
HRESULT AllocateFromBlock (
@@ -6516,7 +6519,7 @@ HRESULT AllocatorPimpl::CreateResource(
6516
6519
if (blockVector != NULL )
6517
6520
{
6518
6521
hr = blockVector->CreateResource (resAllocInfo.SizeInBytes , resAllocInfo.Alignment ,
6519
- *pAllocDesc, finalCreateParams,
6522
+ *pAllocDesc, finalCreateParams, committedAllocationParams. IsValid (),
6520
6523
ppAllocation, riidResource, ppvResource);
6521
6524
if (SUCCEEDED (hr))
6522
6525
return hr;
@@ -6559,7 +6562,7 @@ HRESULT AllocatorPimpl::AllocateMemory(
6559
6562
if (blockVector != NULL )
6560
6563
{
6561
6564
hr = blockVector->Allocate (pAllocInfo->SizeInBytes , pAllocInfo->Alignment ,
6562
- *pAllocDesc, 1 , (Allocation**)ppAllocation);
6565
+ *pAllocDesc, committedAllocationParams. IsValid (), 1 , (Allocation**)ppAllocation);
6563
6566
if (SUCCEEDED (hr))
6564
6567
return hr;
6565
6568
}
@@ -6873,17 +6876,15 @@ void AllocatorPimpl::GetBudget(Budget* outLocalBudget, Budget* outNonLocalBudget
6873
6876
6874
6877
void AllocatorPimpl::GetBudgetForHeapType (Budget& outBudget, D3D12_HEAP_TYPE heapType)
6875
6878
{
6876
- switch (heapType)
6879
+ const bool isLocal = StandardHeapTypeToMemorySegmentGroup (heapType) ==
6880
+ DXGI_MEMORY_SEGMENT_GROUP_LOCAL_COPY;
6881
+ if (isLocal)
6877
6882
{
6878
- case D3D12_HEAP_TYPE_DEFAULT:
6879
- case D3D12_HEAP_TYPE_GPU_UPLOAD_COPY:
6880
6883
GetBudget (&outBudget, NULL );
6881
- break ;
6882
- case D3D12_HEAP_TYPE_UPLOAD:
6883
- case D3D12_HEAP_TYPE_READBACK:
6884
+ }
6885
+ else
6886
+ {
6884
6887
GetBudget (NULL , &outBudget);
6885
- break ;
6886
- default : D3D12MA_ASSERT (0 );
6887
6888
}
6888
6889
}
6889
6890
@@ -8124,6 +8125,7 @@ HRESULT BlockVector::Allocate(
8124
8125
UINT64 size,
8125
8126
UINT64 alignment,
8126
8127
const ALLOCATION_DESC& allocDesc,
8128
+ bool committedAllowed,
8127
8129
size_t allocationCount,
8128
8130
Allocation** pAllocations)
8129
8131
{
@@ -8138,6 +8140,7 @@ HRESULT BlockVector::Allocate(
8138
8140
size,
8139
8141
alignment,
8140
8142
allocDesc,
8143
+ committedAllowed,
8141
8144
pAllocations + allocIndex);
8142
8145
if (FAILED (hr))
8143
8146
{
@@ -8226,40 +8229,43 @@ HRESULT BlockVector::CreateResource(
8226
8229
UINT64 alignment,
8227
8230
const ALLOCATION_DESC& allocDesc,
8228
8231
const CREATE_RESOURCE_PARAMS& createParams,
8232
+ bool committedAllowed,
8229
8233
Allocation** ppAllocation,
8230
8234
REFIID riidResource,
8231
8235
void ** ppvResource)
8232
8236
{
8233
- HRESULT hr = Allocate (size, alignment, allocDesc, 1 , ppAllocation);
8237
+ HRESULT hr = Allocate (size, alignment, allocDesc, committedAllowed, 1 , ppAllocation);
8238
+ if (FAILED (hr))
8239
+ {
8240
+ return hr;
8241
+ }
8242
+
8243
+ ID3D12Resource* res = NULL ;
8244
+ hr = m_hAllocator->CreatePlacedResourceWrap (
8245
+ (*ppAllocation)->m_Placed .block ->GetHeap (),
8246
+ (*ppAllocation)->GetOffset (),
8247
+ createParams,
8248
+ D3D12MA_IID_PPV_ARGS (&res));
8234
8249
if (SUCCEEDED (hr))
8235
8250
{
8236
- ID3D12Resource* res = NULL ;
8237
- hr = m_hAllocator->CreatePlacedResourceWrap (
8238
- (*ppAllocation)->m_Placed .block ->GetHeap (),
8239
- (*ppAllocation)->GetOffset (),
8240
- createParams,
8241
- D3D12MA_IID_PPV_ARGS (&res));
8251
+ if (ppvResource != NULL )
8252
+ {
8253
+ hr = res->QueryInterface (riidResource, ppvResource);
8254
+ }
8242
8255
if (SUCCEEDED (hr))
8243
8256
{
8244
- if (ppvResource != NULL )
8245
- {
8246
- hr = res->QueryInterface (riidResource, ppvResource);
8247
- }
8248
- if (SUCCEEDED (hr))
8249
- {
8250
- (*ppAllocation)->SetResourcePointer (res, createParams.GetBaseResourceDesc ());
8251
- }
8252
- else
8253
- {
8254
- res->Release ();
8255
- SAFE_RELEASE (*ppAllocation);
8256
- }
8257
+ (*ppAllocation)->SetResourcePointer (res, createParams.GetBaseResourceDesc ());
8257
8258
}
8258
8259
else
8259
8260
{
8261
+ res->Release ();
8260
8262
SAFE_RELEASE (*ppAllocation);
8261
8263
}
8262
8264
}
8265
+ else
8266
+ {
8267
+ SAFE_RELEASE (*ppAllocation);
8268
+ }
8263
8269
return hr;
8264
8270
}
8265
8271
@@ -8377,6 +8383,7 @@ HRESULT BlockVector::AllocatePage(
8377
8383
UINT64 size,
8378
8384
UINT64 alignment,
8379
8385
const ALLOCATION_DESC& allocDesc,
8386
+ bool committedAllowed,
8380
8387
Allocation** pAllocation)
8381
8388
{
8382
8389
// Early reject: requested allocation size is larger that maximum block size for this block vector.
@@ -8393,13 +8400,19 @@ HRESULT BlockVector::AllocatePage(
8393
8400
freeMemory = (budget.UsageBytes < budget.BudgetBytes ) ? (budget.BudgetBytes - budget.UsageBytes ) : 0 ;
8394
8401
}
8395
8402
8396
- const bool canCreateNewBlock =
8403
+ const bool canExceedFreeMemory = !committedAllowed;
8404
+
8405
+ bool canCreateNewBlock =
8397
8406
((allocDesc.Flags & ALLOCATION_FLAG_NEVER_ALLOCATE) == 0 ) &&
8398
- (m_Blocks.size () < m_MaxBlockCount) &&
8399
- // Even if we don't have to stay within budget with this allocation, when the
8400
- // budget would be exceeded, we don't want to allocate new blocks, but always
8401
- // create resources as committed.
8402
- freeMemory >= size;
8407
+ (m_Blocks.size () < m_MaxBlockCount);
8408
+
8409
+ // Even if we don't have to stay within budget with this allocation, when the
8410
+ // budget would be exceeded, we don't want to allocate new blocks, but always
8411
+ // create resources as committed.
8412
+ if (freeMemory < size && !canExceedFreeMemory)
8413
+ {
8414
+ canCreateNewBlock = false ;
8415
+ }
8403
8416
8404
8417
// 1. Search existing allocations
8405
8418
{
@@ -8449,25 +8462,28 @@ HRESULT BlockVector::AllocatePage(
8449
8462
}
8450
8463
}
8451
8464
8452
- size_t newBlockIndex = 0 ;
8453
- HRESULT hr = newBlockSize <= freeMemory ?
8454
- CreateBlock (newBlockSize, &newBlockIndex) : E_OUTOFMEMORY;
8465
+ size_t newBlockIndex = SIZE_MAX;
8466
+ HRESULT hr = E_OUTOFMEMORY;
8467
+ if (newBlockSize <= freeMemory || canExceedFreeMemory)
8468
+ {
8469
+ hr = CreateBlock (newBlockSize, &newBlockIndex);
8470
+ }
8455
8471
// Allocation of this size failed? Try 1/2, 1/4, 1/8 of m_PreferredBlockSize.
8456
8472
if (!m_ExplicitBlockSize)
8457
8473
{
8458
8474
while (FAILED (hr) && newBlockSizeShift < NEW_BLOCK_SIZE_SHIFT_MAX)
8459
8475
{
8460
8476
const UINT64 smallerNewBlockSize = newBlockSize / 2 ;
8461
- if (smallerNewBlockSize >= size)
8477
+ if (smallerNewBlockSize < size)
8462
8478
{
8463
- newBlockSize = smallerNewBlockSize;
8464
- ++newBlockSizeShift;
8465
- hr = newBlockSize <= freeMemory ?
8466
- CreateBlock (newBlockSize, &newBlockIndex) : E_OUTOFMEMORY;
8479
+ break ;
8467
8480
}
8468
- else
8481
+
8482
+ newBlockSize = smallerNewBlockSize;
8483
+ ++newBlockSizeShift;
8484
+ if (newBlockSize <= freeMemory || canExceedFreeMemory)
8469
8485
{
8470
- break ;
8486
+ hr = CreateBlock (newBlockSize, &newBlockIndex) ;
8471
8487
}
8472
8488
}
8473
8489
}
0 commit comments