Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions include/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,13 @@ namespace gpgmm::d3d12 {
*/
ALLOCATOR_FLAG_ALWAYS_ON_DEMAND = 0x8,

/** \brief Disables use of D3D12_HEAP_TYPE_CUSTOM.
/** \brief Disables using D3D12_HEAP_TYPE_CUSTOM-equivalent upload heap everywhere on UMA
GPUs.

Used to workaround issues when a custom-equivalent heap is not considered equal to
the corresponding heap type.
Used to workaround issues when custom heaps are not being recongized as expected or driver
bugs related to using a single memory pool.
*/
ALLOCATOR_FLAG_DISABLE_CUSTOM_HEAPS = 0x10,
ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY = 0x10,

/** \brief Report leaks of resource allocations.

Expand Down Expand Up @@ -974,7 +975,7 @@ namespace gpgmm::d3d12 {
as well as frequent CPU reads would beneifit from D3D12_HEAP_TYPE_READBACK since the CPU
properties are always write-combined.

If ALLOCATOR_FLAG_DISABLE_CUSTOM_HEAPS was specified, heap type was
If ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was specified, heap type was
D3D12_HEAP_TYPE_READBACK, or the adapter is not cache-coherent UMA, this flag has no effect.
*/
ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS = 0x20,
Expand Down
14 changes: 12 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ namespace gpgmm::d3d12 {
newDescriptor.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB;
}

// By default, UMA is allowed to use a single heap type. Unless it is explicitly disabled or
// unsupported by the device.
if (!(allocatorDescriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY) &&
!caps->IsAdapterCacheCoherentUMA()) {
gpgmm::DebugLog()
<< "ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was not requested but enabled "
"anyway because the device did not support cache-coherent UMA.";
newDescriptor.Flags |= ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY;
}

// Resource heap tier is required but user didn't specify one.
if (newDescriptor.ResourceHeapTier == 0) {
newDescriptor.ResourceHeapTier = caps->GetMaxResourceHeapTierSupported();
Expand Down Expand Up @@ -569,7 +579,7 @@ namespace gpgmm::d3d12 {
mFlushEventBuffersOnDestruct(descriptor.RecordOptions.EventScope &
EVENT_RECORD_SCOPE_PER_INSTANCE),
mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents),
mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_CUSTOM_HEAPS) {
mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);

if (descriptor.Flags & ALLOCATOR_FLAG_NEVER_LEAK_MEMORY) {
Expand Down Expand Up @@ -938,7 +948,7 @@ namespace gpgmm::d3d12 {
// read-back would be inefficent since upload heaps on UMA adapters are usually
// write-combined (vs write-back) so leave read back heaps alone.
if (!(allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS) &&
mCaps->IsAdapterCacheCoherentUMA() && !mIsCustomHeapsDisabled) {
!mIsCustomHeapsDisabled) {
if (allocationDescriptor.HeapType != D3D12_HEAP_TYPE_READBACK) {
heapType = D3D12_HEAP_TYPE_UPLOAD;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) {
EXPECT_EQ(resourceAllocator->GetStats().FreeMemoryUsage, kBufferOf4MBAllocationSize * 2);
}

TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableCustomHeaps) {
TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableUMA) {
ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc();
allocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_CUSTOM_HEAPS;
allocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY;

ComPtr<IResourceAllocator> resourceAllocator;
ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, &resourceAllocator, nullptr));
Expand Down