Skip to content

Commit 8ed849e

Browse files
Optimize get_total_memory_used in D3D12 and Vulkan.
1 parent bf95b62 commit 8ed849e

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

drivers/d3d12/rendering_device_driver_d3d12.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5799,9 +5799,11 @@ uint64_t RenderingDeviceDriverD3D12::get_resource_native_handle(DriverResource p
57995799
}
58005800

58015801
uint64_t RenderingDeviceDriverD3D12::get_total_memory_used() {
5802-
D3D12MA::TotalStatistics stats;
5803-
allocator->CalculateStatistics(&stats);
5804-
return stats.Total.Stats.BlockBytes;
5802+
D3D12MA::Budget local_budget;
5803+
D3D12MA::Budget non_local_budget;
5804+
allocator->GetBudget(&local_budget, &non_local_budget);
5805+
5806+
return local_budget.Stats.AllocationBytes + non_local_budget.Stats.AllocationBytes;
58055807
}
58065808

58075809
uint64_t RenderingDeviceDriverD3D12::get_lazily_memory_used() {

drivers/vulkan/rendering_device_driver_vulkan.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7166,9 +7166,18 @@ uint64_t RenderingDeviceDriverVulkan::get_resource_native_handle(DriverResource
71667166
}
71677167

71687168
uint64_t RenderingDeviceDriverVulkan::get_total_memory_used() {
7169-
VmaTotalStatistics stats = {};
7170-
vmaCalculateStatistics(allocator, &stats);
7171-
return stats.total.statistics.allocationBytes;
7169+
const VkPhysicalDeviceMemoryProperties *memory_properties = nullptr;
7170+
vmaGetMemoryProperties(allocator, &memory_properties);
7171+
7172+
VmaBudget *budgets = ALLOCA_ARRAY(VmaBudget, memory_properties->memoryHeapCount);
7173+
vmaGetHeapBudgets(allocator, budgets);
7174+
7175+
uint64_t total_memory_used = 0;
7176+
for (uint32_t i = 0; i < memory_properties->memoryHeapCount; i++) {
7177+
total_memory_used += budgets[i].statistics.allocationBytes;
7178+
}
7179+
7180+
return total_memory_used;
71727181
}
71737182

71747183
uint64_t RenderingDeviceDriverVulkan::get_lazily_memory_used() {

0 commit comments

Comments
 (0)