diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index e3681b45e..568ec36d1 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -134,7 +134,7 @@ namespace gpgmm::d3d12 { /** \brief Requires the heap to be created in budget. - This flags allows the heap to be tracked for residency but not made resident. + This flags ensures there is enough budget to exist for the heap or E_OUTOFMEMORY. */ HEAP_FLAG_ALWAYS_IN_BUDGET = 0x1, @@ -648,14 +648,9 @@ namespace gpgmm::d3d12 { */ ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x1, - /** \brief Creates resource within budget. + /** \brief Requires resource allocation to be created within budget. - By default (and when residency is used), resources will not be created resident unless an - operation is performed on the allocation that requires them to be (ex. Map). Otherwise, the - resource will become resident once ExecuteCommandList() is called. However, this flag can be - used to change this behavior by requiring resource heaps to be always resident at resource - creation. When residency is not used, ALLOCATOR_FLAG_ALWAYS_IN_BUDGET is implicitly enabled - through the GPU/driver instead of explicitly through GPGMM. + Always use HEAP_FLAG_ALWAYS_IN_BUDGET to resource heaps created by this resource allocator. */ ALLOCATOR_FLAG_ALWAYS_IN_BUDGET = 0x2, @@ -690,14 +685,6 @@ namespace gpgmm::d3d12 { to be released, it will report details on any leaked allocations as log messages. */ ALLOCATOR_FLAG_NEVER_LEAK_MEMORY = 0x20, - - /** \brief Allows resources to be created over budget. - - Used when GPGMM is unable to manage enough budget (external heaps, multiple GMMs per - process) and instead relies on the default OS/kernel behavior. This should be considered a - temporary measure and should not replace implementing good budget management. - */ - ALLOCATOR_FLAG_ALLOW_OVER_BUDGET = 0x40, }; DEFINE_ENUM_FLAG_OPERATORS(ALLOCATOR_FLAGS) diff --git a/src/gpgmm/d3d12/HeapD3D12.cpp b/src/gpgmm/d3d12/HeapD3D12.cpp index 5edd9b0b0..c606d1bc3 100644 --- a/src/gpgmm/d3d12/HeapD3D12.cpp +++ b/src/gpgmm/d3d12/HeapD3D12.cpp @@ -45,16 +45,12 @@ namespace gpgmm::d3d12 { } } // namespace - HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool isResidencyEnabled) { - if (heapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT) { - return HEAP_FLAG_NONE | HEAP_FLAG_ALWAYS_IN_RESIDENCY; - } - - if (isResidencyEnabled) { + HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget) { + if (alwaysCreatedInBudget) { return HEAP_FLAG_ALWAYS_IN_BUDGET | HEAP_FLAG_ALWAYS_IN_RESIDENCY; } - return HEAP_FLAG_NONE; + return HEAP_FLAG_ALWAYS_IN_RESIDENCY; } HRESULT CreateHeap(const HEAP_DESC& descriptor, diff --git a/src/gpgmm/d3d12/HeapD3D12.h b/src/gpgmm/d3d12/HeapD3D12.h index 2c41319ea..97588563f 100644 --- a/src/gpgmm/d3d12/HeapD3D12.h +++ b/src/gpgmm/d3d12/HeapD3D12.h @@ -27,7 +27,7 @@ namespace gpgmm::d3d12 { class ResidencyManager; - HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool isResidencyEnabled); + HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget); class Heap final : public MemoryBase, public DebugObject, public LinkNode, public IHeap { public: diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 3e5416f4c..623e15ad8 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -533,18 +533,6 @@ namespace gpgmm::d3d12 { newDescriptor.ResourceHeapTier = caps->GetMaxResourceHeapTierSupported(); } - // ID3D12Device::CreateCommittedResource and ID3D12Device::CreateHeap implicity - // call ID3D12Device::MakeResident, requiring resource heaps to be "created in budget". - // But this can be disabled if D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT is supported. - if (!(allocatorDescriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET) && - !caps->IsCreateHeapNotResidentSupported()) { - newDescriptor.Flags |= ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; - - DebugLog(MessageId::kInvalidArgument) - << "ALLOCATOR_FLAG_ALWAYS_IN_BUDGET was not requested but enabled " - "anyway because the device did not support creating non-resident heaps."; - } - newDescriptor.MaxResourceHeapSize = (allocatorDescriptor.MaxResourceHeapSize > 0) ? std::min(allocatorDescriptor.MaxResourceHeapSize, caps->GetMaxResourceHeapSize()) @@ -616,8 +604,7 @@ namespace gpgmm::d3d12 { mFlushEventBuffersOnDestruct(descriptor.RecordOptions.EventScope & EventRecordScope::kPerInstance), mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents), - mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY), - mIsOverBudgetEnabled(descriptor.Flags & ALLOCATOR_FLAG_ALLOW_OVER_BUDGET) { + mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY) { ASSERT(mDevice != nullptr); GPGMM_TRACE_EVENT_OBJECT_NEW(this); @@ -785,8 +772,9 @@ namespace gpgmm::d3d12 { const D3D12_HEAP_PROPERTIES& heapProperties, uint64_t heapAlignment) { std::unique_ptr resourceHeapAllocator = - std::make_unique( - mResidencyManager.Get(), mDevice, heapProperties, heapFlags, mIsOverBudgetEnabled); + std::make_unique(mResidencyManager.Get(), mDevice, + heapProperties, heapFlags, + mIsAlwaysCreatedInBudget); const uint64_t heapSize = std::max(heapAlignment, AlignTo(descriptor.PreferredResourceHeapSize, heapAlignment)); @@ -1451,13 +1439,9 @@ namespace gpgmm::d3d12 { resourceHeapDesc.SizeInBytes = info.SizeInBytes; resourceHeapDesc.Alignment = info.Alignment; resourceHeapDesc.DebugName = L"Resource heap (committed)"; - resourceHeapDesc.Flags |= GetHeapFlags(heapFlags, IsResidencyEnabled()); - - if (mIsOverBudgetEnabled) { - resourceHeapDesc.Flags &= ~(HEAP_FLAG_ALWAYS_IN_BUDGET); // clear - } if (IsResidencyEnabled()) { + resourceHeapDesc.Flags |= GetHeapFlags(heapFlags, mIsAlwaysCreatedInBudget); resourceHeapDesc.MemorySegmentGroup = GetMemorySegmentGroup( heapProperties.MemoryPoolPreference, mResidencyManager->IsUMA()); } @@ -1611,7 +1595,7 @@ namespace gpgmm::d3d12 { } bool ResourceAllocator::IsCreateHeapNotResident() const { - return IsResidencyEnabled() && !mIsAlwaysCreatedInBudget; + return IsResidencyEnabled() && mCaps->IsCreateHeapNotResidentSupported(); } bool ResourceAllocator::IsResidencyEnabled() const { diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 9931af15f..d9eb217c7 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -153,7 +153,6 @@ namespace gpgmm::d3d12 { const bool mFlushEventBuffersOnDestruct; const bool mUseDetailedTimingEvents; const bool mIsCustomHeapsDisabled; - const bool mIsOverBudgetEnabled; static constexpr uint64_t kNumOfResourceHeapTypes = 12u; diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index 6ff50233f..7c84ccf36 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -33,12 +33,12 @@ namespace gpgmm::d3d12 { ID3D12Device* device, D3D12_HEAP_PROPERTIES heapProperties, D3D12_HEAP_FLAGS heapFlags, - bool isOverBudgetEnabled) + bool alwaysCreatedInBudget) : mResidencyManager(residencyManager), mDevice(device), mHeapProperties(heapProperties), mHeapFlags(heapFlags), - mIsOverBudgetEnabled(isOverBudgetEnabled) { + mIsAlwaysCreatedInBudget(alwaysCreatedInBudget) { } ResultOrError> ResourceHeapAllocator::TryAllocateMemory( @@ -60,13 +60,8 @@ namespace gpgmm::d3d12 { resourceHeapDesc.DebugName = kResourceHeapDebugName; const bool isResidencyEnabled = (mResidencyManager != nullptr); - resourceHeapDesc.Flags |= GetHeapFlags(mHeapFlags, isResidencyEnabled); - - if (mIsOverBudgetEnabled) { - resourceHeapDesc.Flags &= ~(HEAP_FLAG_ALWAYS_IN_BUDGET); // clear - } - if (isResidencyEnabled) { + resourceHeapDesc.Flags |= GetHeapFlags(mHeapFlags, mIsAlwaysCreatedInBudget); resourceHeapDesc.MemorySegmentGroup = GetMemorySegmentGroup( mHeapProperties.MemoryPoolPreference, mResidencyManager->IsUMA()); } diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h index 4e831de2c..1e4c9dde9 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h @@ -58,7 +58,7 @@ namespace gpgmm::d3d12 { ID3D12Device* const mDevice; const D3D12_HEAP_PROPERTIES mHeapProperties; const D3D12_HEAP_FLAGS mHeapFlags; - const bool mIsOverBudgetEnabled; + const bool mIsAlwaysCreatedInBudget; }; } // namespace gpgmm::d3d12