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
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace gpgmm::d3d12 {
resourceHeapDesc.IsExternal = false;
resourceHeapDesc.DebugName = "Resource heap";
resourceHeapDesc.Alignment = request.Alignment;
resourceHeapDesc.AlwaysInBudget = !(mHeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT);
resourceHeapDesc.HeapType = mHeapType;

Heap* resourceHeap = nullptr;
Expand Down
37 changes: 32 additions & 5 deletions src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,46 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) {

const D3D12_RESOURCE_DESC bufferDesc = CreateBasicBufferDesc(GPGMM_MB_TO_BYTES(1));

std::vector<ComPtr<ResourceAllocation>> allocations = {};
// Keep allocating until we reach the budget.
std::vector<ComPtr<ResourceAllocation>> allocationsBelowBudget = {};
while (!IsOverBudget(residencyManager.Get())) {
ComPtr<ResourceAllocation> allocation;
ASSERT_SUCCEEDED(resourceAllocator->CreateResource(
{}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation));
allocationsBelowBudget.push_back(std::move(allocation));

allocations.push_back(std::move(allocation));
// Prevent the first created resources from being evicted once over budget.
ASSERT_SUCCEEDED(residencyManager->UpdateVideoMemorySegments());
}

// All allocations should be created resident.
for (auto& allocation : allocations) {
// Created allocations below the budget should be resident.
for (auto& allocation : allocationsBelowBudget) {
EXPECT_TRUE(allocation->IsResident());
}

// Keep allocating |kMemoryOverBudget| over the budget.
constexpr uint64_t kMemoryOverBudget = GPGMM_MB_TO_BYTES(10);

// Allocating the same amount over budget, where older allocations will be evicted.
std::vector<ComPtr<ResourceAllocation>> allocationsAboveBudget = {};
const uint64_t currentMemoryUsage = resourceAllocator->GetInfo().UsedMemoryUsage;

while (currentMemoryUsage + kMemoryOverBudget > resourceAllocator->GetInfo().UsedMemoryUsage) {
ComPtr<ResourceAllocation> allocation;
ASSERT_SUCCEEDED(resourceAllocator->CreateResource(
{}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation));
allocationsAboveBudget.push_back(std::move(allocation));
}

// Created allocations above the budget should be resident.
for (auto& allocation : allocationsAboveBudget) {
EXPECT_TRUE(allocation->IsResident());
}

// Created allocations below the budget should NOT be resident.
for (auto& allocation : allocationsBelowBudget) {
EXPECT_FALSE(allocation->IsResident());
}
}

// Keeps allocating until it goes over the OS limited budget.
Expand Down Expand Up @@ -263,10 +289,11 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithGrowth) {
resourceHeaps.push_back(allocation->GetMemory());
allocations.push_back(std::move(allocation));

// Prevent the first created resources from being evicted once over budget.
ASSERT_SUCCEEDED(residencyManager->UpdateVideoMemorySegments());
}

// All allocations should be created resident.
// Created allocations above the budget should be resident.
for (auto& allocation : allocations) {
EXPECT_TRUE(allocation->IsResident());
}
Expand Down