From 8ed849e416efcb9221f2b09f2b7497ace5c1d33c Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 16 Feb 2026 17:13:06 +0300 Subject: [PATCH] Optimize get_total_memory_used in D3D12 and Vulkan. --- drivers/d3d12/rendering_device_driver_d3d12.cpp | 8 +++++--- drivers/vulkan/rendering_device_driver_vulkan.cpp | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/d3d12/rendering_device_driver_d3d12.cpp b/drivers/d3d12/rendering_device_driver_d3d12.cpp index 66a624221c..e51c0d7edf 100644 --- a/drivers/d3d12/rendering_device_driver_d3d12.cpp +++ b/drivers/d3d12/rendering_device_driver_d3d12.cpp @@ -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() { diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index dc8a909d83..5c999af94b 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -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() {