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
13 changes: 13 additions & 0 deletions src/gpgmm/d3d12/ResidencyHeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ namespace gpgmm::d3d12 {

const bool isResidencyDisabled = (pResidencyManager == nullptr);

// Validate residency resource heap flags must also have a residency manager.
if (isResidencyDisabled && descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET) {
ErrorLog(MessageId::kInvalidArgument, true)
<< "Creating a heap always in budget requires a residency manager to exist.";
return E_INVALIDARG;
}

if (isResidencyDisabled && descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT) {
ErrorLog(MessageId::kInvalidArgument, true)
<< "Creating a heap always residency requires a residency manager to exist.";
return E_INVALIDARG;
}

ResidencyManager* residencyManager = static_cast<ResidencyManager*>(pResidencyManager);

// Ensure enough budget exists before creating the heap to avoid an out-of-memory error.
Expand Down
18 changes: 18 additions & 0 deletions src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) {
CreateResourceHeapCallbackContext::CreateHeap,
&createHeapContext, &resourceHeap));

{
RESIDENCY_HEAP_DESC invalidResourceHeapDesc = resourceHeapDesc;
invalidResourceHeapDesc.Flags |= RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT;

ASSERT_FAILED(CreateResidencyHeap(invalidResourceHeapDesc, nullptr,
CreateResourceHeapCallbackContext::CreateHeap,
&createHeapContext, nullptr));
}

{
RESIDENCY_HEAP_DESC invalidResourceHeapDesc = resourceHeapDesc;
invalidResourceHeapDesc.Flags |= RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET;

ASSERT_FAILED(CreateResidencyHeap(invalidResourceHeapDesc, nullptr,
CreateResourceHeapCallbackContext::CreateHeap,
&createHeapContext, nullptr));
}

// Ensure the unmanaged resource heap state is always unknown. Even though D3D12 implicitly
// creates heaps as resident, untrack resource heaps would never transition out from
// RESIDENCY_HEAP_STATUS_CURRENT and must be left RESIDENCY_HEAP_STATUS_UNKNOWN.
Expand Down