Merge pull request #116355 from blueskythlikesclouds/get-total-memory-optimization
Optimize `get_total_memory_used` in D3D12 and Vulkan.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user