From 2e2b88e63c6b342ebc7ffb2159775dd8babd92c4 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Fri, 4 Aug 2023 18:02:10 -0700 Subject: [PATCH] Default the creation of resources to being resident. --- include/gpgmm_d3d12.h | 9 ++++----- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 22 ++++++++++++---------- src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index afde9037a..bce4edbc4 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -814,14 +814,13 @@ namespace gpgmm::d3d12 { */ RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK = 0x20, - /** \brief Requires resource allocation to be created resident. + /** \brief Create resource allocation to be NOT created resident. - With this flag, resource heaps created by this resource allocator will never specify + With this flag, resource heaps created by this resource allocator will specify D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT, when supported, to avoid unnecessary GPU paging - operations at resource creation, and instead, reverts back to the default behavior of D3D12 - of always making heaps implicitly resident on creation. + operations at resource creation. */ - RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT = 0x40, + RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT = 0x40, }; DEFINE_ENUM_FLAG_OPERATORS(RESOURCE_ALLOCATOR_FLAGS) diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 51174b382..10ebb1d5f 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -483,12 +483,12 @@ namespace gpgmm::d3d12 { newDescriptor.Flags ^= RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY; } - if (!(allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT) && + if ((allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT) && !caps->IsCreateHeapNotResidentSupported()) { DebugLog(MessageId::kInvalidArgument, true) - << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT was not requested but enabled " - "anyway because the device did not support creation of non-resident heaps."; - newDescriptor.Flags |= RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT; + << "RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT was requested but disallowed " + "because the device did not support creation of non-resident heaps."; + newDescriptor.Flags ^= RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT; } // Resource heap tier is required but user didn't specify one. @@ -575,7 +575,8 @@ namespace gpgmm::d3d12 { RECORD_SCOPE_PER_INSTANCE), mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents), mIsCustomHeapsEnabled(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY), - mIsAlwaysCreateResident(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT), + mIsCreateNotResidentEnabled(descriptor.Flags & + RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT), mMaxResourceHeapSize(descriptor.MaxResourceHeapSize) { ASSERT(mDevice != nullptr); @@ -594,7 +595,7 @@ namespace gpgmm::d3d12 { static_cast(resourceHeapTypeIndex); const D3D12_HEAP_FLAGS& heapFlags = - GetHeapFlags(resourceHeapType, IsCreateHeapNotResident()); + GetHeapFlags(resourceHeapType, IsCreateHeapNotResidentEnabled()); const D3D12_HEAP_TYPE heapType = GetHeapType(resourceHeapType); const uint64_t msaaHeapAlignment = GetHeapAlignment(heapFlags, true); @@ -1067,7 +1068,8 @@ namespace gpgmm::d3d12 { bool isAlwaysCommitted = mIsAlwaysCommitted; // Check memory requirements. - D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(resourceHeapType, IsCreateHeapNotResident()); + D3D12_HEAP_FLAGS heapFlags = + GetHeapFlags(resourceHeapType, IsCreateHeapNotResidentEnabled()); if (!HasAllFlags(heapFlags, allocationDescriptor.ExtraRequiredHeapFlags)) { WarnLog(this, MessageId::kPerformanceWarning) << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED was not requested but enabled anyway " @@ -1148,7 +1150,7 @@ namespace gpgmm::d3d12 { // to prevent OOM to free memory only or to the amount of budget left. The allocator // checks this amount to determine if its appropriate to pre-allocate more memory or // not. - if (IsResidencyEnabled() && !IsCreateHeapNotResident()) { + if (IsResidencyEnabled() && !IsCreateHeapNotResidentEnabled()) { DXGI_QUERY_VIDEO_MEMORY_INFO* currentVideoInfo = mResidencyManager->GetVideoMemoryInfo(heapSegment); @@ -1680,8 +1682,8 @@ namespace gpgmm::d3d12 { SafeRelease(allocation); } - bool ResourceAllocator::IsCreateHeapNotResident() const { - return IsResidencyEnabled() && !mIsAlwaysCreateResident; + bool ResourceAllocator::IsCreateHeapNotResidentEnabled() const { + return IsResidencyEnabled() && mIsCreateNotResidentEnabled; } bool ResourceAllocator::IsResidencyEnabled() const { diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 723b81b0b..c443227c4 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -141,7 +141,7 @@ namespace gpgmm::d3d12 { HRESULT ReportLiveDeviceObjects() const; - bool IsCreateHeapNotResident() const; + bool IsCreateHeapNotResidentEnabled() const; bool IsResidencyEnabled() const; D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo( @@ -166,7 +166,7 @@ namespace gpgmm::d3d12 { const bool mFlushEventBuffersOnDestruct; const bool mUseDetailedTimingEvents; const bool mIsCustomHeapsEnabled; - const bool mIsAlwaysCreateResident; + const bool mIsCreateNotResidentEnabled; const uint64_t mMaxResourceHeapSize; static constexpr uint64_t kNumOfResourceHeapTypes = 12u;