Optimize get_total_memory_used in D3D12 and Vulkan.

This commit is contained in:
Skyth 2026-02-16 17:13:06 +03:00
parent bf95b62586
commit 8ed849e416
2 changed files with 17 additions and 6 deletions

View file

@ -5799,9 +5799,11 @@ uint64_t RenderingDeviceDriverD3D12::get_resource_native_handle(DriverResource p
}
uint64_t RenderingDeviceDriverD3D12::get_total_memory_used() {
D3D12MA::TotalStatistics stats;
allocator->CalculateStatistics(&stats);
return stats.Total.Stats.BlockBytes;
D3D12MA::Budget local_budget;
D3D12MA::Budget non_local_budget;
allocator->GetBudget(&local_budget, &non_local_budget);
return local_budget.Stats.AllocationBytes + non_local_budget.Stats.AllocationBytes;
}
uint64_t RenderingDeviceDriverD3D12::get_lazily_memory_used() {

View file

@ -7166,9 +7166,18 @@ uint64_t RenderingDeviceDriverVulkan::get_resource_native_handle(DriverResource
}
uint64_t RenderingDeviceDriverVulkan::get_total_memory_used() {
VmaTotalStatistics stats = {};
vmaCalculateStatistics(allocator, &stats);
return stats.total.statistics.allocationBytes;
const VkPhysicalDeviceMemoryProperties *memory_properties = nullptr;
vmaGetMemoryProperties(allocator, &memory_properties);
VmaBudget *budgets = ALLOCA_ARRAY(VmaBudget, memory_properties->memoryHeapCount);
vmaGetHeapBudgets(allocator, budgets);
uint64_t total_memory_used = 0;
for (uint32_t i = 0; i < memory_properties->memoryHeapCount; i++) {
total_memory_used += budgets[i].statistics.allocationBytes;
}
return total_memory_used;
}
uint64_t RenderingDeviceDriverVulkan::get_lazily_memory_used() {