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
19 changes: 3 additions & 16 deletions include/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions src/gpgmm/d3d12/HeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/HeapD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Heap>, public IHeap {
public:
Expand Down
28 changes: 6 additions & 22 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -785,8 +772,9 @@ namespace gpgmm::d3d12 {
const D3D12_HEAP_PROPERTIES& heapProperties,
uint64_t heapAlignment) {
std::unique_ptr<MemoryAllocator> resourceHeapAllocator =
std::make_unique<ResourceHeapAllocator>(
mResidencyManager.Get(), mDevice, heapProperties, heapFlags, mIsOverBudgetEnabled);
std::make_unique<ResourceHeapAllocator>(mResidencyManager.Get(), mDevice,
heapProperties, heapFlags,
mIsAlwaysCreatedInBudget);

const uint64_t heapSize =
std::max(heapAlignment, AlignTo(descriptor.PreferredResourceHeapSize, heapAlignment));
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -1611,7 +1595,7 @@ namespace gpgmm::d3d12 {
}

bool ResourceAllocator::IsCreateHeapNotResident() const {
return IsResidencyEnabled() && !mIsAlwaysCreatedInBudget;
return IsResidencyEnabled() && mCaps->IsCreateHeapNotResidentSupported();
}

bool ResourceAllocator::IsResidencyEnabled() const {
Expand Down
1 change: 0 additions & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 3 additions & 8 deletions src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<MemoryAllocation>> ResourceHeapAllocator::TryAllocateMemory(
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down