From e06c6b5ac805ab0588931ae001c574b6e62c8944 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 14 May 2023 23:37:50 +0300 Subject: [PATCH] vk: Refactor memory allocators to easily inspect device properties --- rpcs3/Emu/RSX/VK/vkutils/device.cpp | 4 ++-- rpcs3/Emu/RSX/VK/vkutils/memory.cpp | 11 ++++++++--- rpcs3/Emu/RSX/VK/vkutils/memory.h | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index cedc83ec56..b085e41b0e 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -679,11 +679,11 @@ namespace vk if (g_cfg.video.disable_vulkan_mem_allocator) { - m_allocator = std::make_unique(dev, pdev); + m_allocator = std::make_unique(*this, pdev); } else { - m_allocator = std::make_unique(dev, pdev); + m_allocator = std::make_unique(*this, pdev); } // Useful for debugging different VRAM configurations diff --git a/rpcs3/Emu/RSX/VK/vkutils/memory.cpp b/rpcs3/Emu/RSX/VK/vkutils/memory.cpp index 0c3213e4bf..45237853be 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/memory.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/memory.cpp @@ -153,7 +153,12 @@ namespace vk rsx_log.warning("Rebalanced memory types successfully"); } - mem_allocator_vma::mem_allocator_vma(VkDevice dev, VkPhysicalDevice pdev) : mem_allocator_base(dev, pdev) + mem_allocator_base::mem_allocator_base(const vk::render_device& dev, VkPhysicalDevice) + : m_device(dev), m_allocation_flags(0) + {} + + mem_allocator_vma::mem_allocator_vma(const vk::render_device& dev, VkPhysicalDevice pdev) + : mem_allocator_base(dev, pdev) { // Initialize stats pool std::fill(stats.begin(), stats.end(), VmaBudget{}); @@ -164,11 +169,11 @@ namespace vk std::vector heap_limits; const auto vram_allocation_limit = g_cfg.video.vk.vram_allocation_limit * 0x100000ull; - if (vram_allocation_limit < g_render_device->get_memory_mapping().device_local_total_bytes) + if (vram_allocation_limit < dev.get_memory_mapping().device_local_total_bytes) { VkPhysicalDeviceMemoryProperties memory_properties; vkGetPhysicalDeviceMemoryProperties(pdev, &memory_properties); - for (int i = 0; i < memory_properties.memoryHeapCount; ++i) + for (u32 i = 0; i < memory_properties.memoryHeapCount; ++i) { const u64 max_sz = (memory_properties.memoryHeaps[i].flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) ? vram_allocation_limit diff --git a/rpcs3/Emu/RSX/VK/vkutils/memory.h b/rpcs3/Emu/RSX/VK/vkutils/memory.h index 10c1a3c6f3..61509b2e47 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/memory.h +++ b/rpcs3/Emu/RSX/VK/vkutils/memory.h @@ -55,7 +55,7 @@ namespace vk public: using mem_handle_t = void*; - mem_allocator_base(VkDevice dev, VkPhysicalDevice /*pdev*/) : m_device(dev), m_allocation_flags(0) {} + mem_allocator_base(const vk::render_device& dev, VkPhysicalDevice /*pdev*/); virtual ~mem_allocator_base() = default; virtual void destroy() = 0; @@ -83,7 +83,7 @@ namespace vk class mem_allocator_vma : public mem_allocator_base { public: - mem_allocator_vma(VkDevice dev, VkPhysicalDevice pdev); + mem_allocator_vma(const vk::render_device& dev, VkPhysicalDevice pdev); ~mem_allocator_vma() override = default; void destroy() override; @@ -112,7 +112,7 @@ namespace vk class mem_allocator_vk : public mem_allocator_base { public: - mem_allocator_vk(VkDevice dev, VkPhysicalDevice pdev) : mem_allocator_base(dev, pdev) {} + mem_allocator_vk(const vk::render_device& dev, VkPhysicalDevice pdev) : mem_allocator_base(dev, pdev) {} ~mem_allocator_vk() override = default; void destroy() override {}