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
9 changes: 4 additions & 5 deletions include/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand All @@ -594,7 +595,7 @@ namespace gpgmm::d3d12 {
static_cast<RESOURCE_HEAP_TYPE>(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);
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace gpgmm::d3d12 {

HRESULT ReportLiveDeviceObjects() const;

bool IsCreateHeapNotResident() const;
bool IsCreateHeapNotResidentEnabled() const;
bool IsResidencyEnabled() const;

D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo(
Expand All @@ -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;
Expand Down