From 678312365476a0c40d71727d2fa2910cd7954af5 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 12 Mar 2023 13:16:57 +0100 Subject: [PATCH] [dxgi] Use heap size to determine reservable memory Budgets can change dynamically, so this should be more robust. --- src/dxgi/dxgi_adapter.cpp | 9 +++++---- src/dxvk/dxvk_adapter.cpp | 1 + src/dxvk/dxvk_adapter.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 71342b44..1badca8e 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -352,23 +352,24 @@ namespace dxvk { if (MemorySegmentGroup == DXGI_MEMORY_SEGMENT_GROUP_LOCAL) heapFlags |= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT; - pVideoMemoryInfo->Budget = 0; + pVideoMemoryInfo->Budget = 0; pVideoMemoryInfo->CurrentUsage = 0; + pVideoMemoryInfo->AvailableForReservation = 0; for (uint32_t i = 0; i < memInfo.heapCount; i++) { if ((memInfo.heaps[i].heapFlags & heapFlagMask) != heapFlags) continue; - pVideoMemoryInfo->Budget += memInfo.heaps[i].memoryBudget; + pVideoMemoryInfo->Budget += memInfo.heaps[i].memoryBudget; pVideoMemoryInfo->CurrentUsage += memInfo.heaps[i].memoryAllocated; + pVideoMemoryInfo->AvailableForReservation += memInfo.heaps[i].heapSize / 2; } // We don't implement reservation, but the observable // behaviour should match that of Windows drivers uint32_t segmentId = uint32_t(MemorySegmentGroup); - pVideoMemoryInfo->AvailableForReservation = pVideoMemoryInfo->Budget / 2; - pVideoMemoryInfo->CurrentReservation = m_memReservation[segmentId]; + pVideoMemoryInfo->CurrentReservation = m_memReservation[segmentId]; return S_OK; } diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index dc4c06bb..f18a4a36 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -39,6 +39,7 @@ namespace dxvk { for (uint32_t i = 0; i < info.heapCount; i++) { info.heaps[i].heapFlags = memProps.memoryProperties.memoryHeaps[i].flags; + info.heaps[i].heapSize = memProps.memoryProperties.memoryHeaps[i].size; if (m_hasMemoryBudget) { info.heaps[i].memoryBudget = memBudget.heapBudget[i]; diff --git a/src/dxvk/dxvk_adapter.h b/src/dxvk/dxvk_adapter.h index 56f15ffe..e70cecd6 100644 --- a/src/dxvk/dxvk_adapter.h +++ b/src/dxvk/dxvk_adapter.h @@ -30,6 +30,7 @@ namespace dxvk { */ struct DxvkAdapterMemoryHeapInfo { VkMemoryHeapFlags heapFlags; + VkDeviceSize heapSize; VkDeviceSize memoryBudget; VkDeviceSize memoryAllocated; };