0003-VMA-add-vmaCalculateLazilyAllocatedBytes.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h
  2. index ecb84094b9..c436209896 100644
  3. --- a/thirdparty/vulkan/vk_mem_alloc.h
  4. +++ b/thirdparty/vulkan/vk_mem_alloc.h
  5. @@ -1713,6 +1713,19 @@ VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStatistics(
  6. VmaAllocator VMA_NOT_NULL allocator,
  7. VmaTotalStatistics* VMA_NOT_NULL pStats);
  8. +/** \brief Retrieves lazily allocated bytes
  9. +
  10. +This function is called "calculate" not "get" because it has to traverse all
  11. +internal data structures, so it may be quite slow. Use it for debugging purposes.
  12. +For faster but more brief statistics suitable to be called every frame or every allocation,
  13. +use vmaGetHeapBudgets().
  14. +
  15. +Note that when using allocator from multiple threads, returned information may immediately
  16. +become outdated.
  17. +*/
  18. +VMA_CALL_PRE uint64_t VMA_CALL_POST vmaCalculateLazilyAllocatedBytes(
  19. + VmaAllocator VMA_NOT_NULL allocator);
  20. +
  21. /** \brief Retrieves information about current memory usage and budget for all memory heaps.
  22. \param allocator
  23. @@ -14912,6 +14925,26 @@ VMA_CALL_PRE void VMA_CALL_POST vmaCalculateStatistics(
  24. allocator->CalculateStatistics(pStats);
  25. }
  26. +VMA_CALL_PRE uint64_t VMA_CALL_POST vmaCalculateLazilyAllocatedBytes(
  27. + VmaAllocator allocator)
  28. +{
  29. + VMA_ASSERT(allocator);
  30. + VMA_DEBUG_GLOBAL_MUTEX_LOCK
  31. + VmaTotalStatistics stats;
  32. + allocator->CalculateStatistics(&stats);
  33. + uint64_t total_lazilily_allocated_bytes = 0;
  34. + for (uint32_t heapIndex = 0; heapIndex < allocator->GetMemoryHeapCount(); ++heapIndex) {
  35. + for (uint32_t typeIndex = 0; typeIndex < allocator->GetMemoryTypeCount(); ++typeIndex) {
  36. + if (allocator->MemoryTypeIndexToHeapIndex(typeIndex) == heapIndex) {
  37. + VkMemoryPropertyFlags flags = allocator->m_MemProps.memoryTypes[typeIndex].propertyFlags;
  38. + if (flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)
  39. + total_lazilily_allocated_bytes += stats.memoryType[typeIndex].statistics.allocationBytes;
  40. + }
  41. + }
  42. + }
  43. + return total_lazilily_allocated_bytes;
  44. +}
  45. +
  46. VMA_CALL_PRE void VMA_CALL_POST vmaGetHeapBudgets(
  47. VmaAllocator allocator,
  48. VmaBudget* pBudgets)