vk: Refactor memory allocators to easily inspect device properties

This commit is contained in:
kd-11 2023-05-14 23:37:50 +03:00 committed by kd-11
parent a6dada6c36
commit e06c6b5ac8
3 changed files with 13 additions and 8 deletions

View File

@ -679,11 +679,11 @@ namespace vk
if (g_cfg.video.disable_vulkan_mem_allocator)
{
m_allocator = std::make_unique<vk::mem_allocator_vk>(dev, pdev);
m_allocator = std::make_unique<vk::mem_allocator_vk>(*this, pdev);
}
else
{
m_allocator = std::make_unique<vk::mem_allocator_vma>(dev, pdev);
m_allocator = std::make_unique<vk::mem_allocator_vma>(*this, pdev);
}
// Useful for debugging different VRAM configurations

View File

@ -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<VkDeviceSize> 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

View File

@ -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 {}