1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

vk: Refactor descriptors a bit

This commit is contained in:
kd-11 2021-09-22 23:06:44 +03:00 committed by kd-11
parent 62979c7bd9
commit 24642a4c18
10 changed files with 96 additions and 80 deletions

View File

@ -458,6 +458,7 @@ if(TARGET 3rdparty_vulkan)
RSX/VK/vkutils/chip_class.cpp
RSX/VK/vkutils/commands.cpp
RSX/VK/vkutils/data_heap.cpp
RSX/VK/vkutils/descriptors.cpp
RSX/VK/vkutils/image.cpp
RSX/VK/vkutils/image_helpers.cpp
RSX/VK/vkutils/scratch.cpp

View File

@ -1,6 +1,6 @@
#pragma once
#include "VKPipelineCompiler.h"
#include "vkutils/descriptors.hpp"
#include "vkutils/descriptors.h"
#include "vkutils/buffer_object.h"
#include "Emu/IdManager.h"

View File

@ -4,7 +4,7 @@
#include "upscalers/upscaling.h"
#include "vkutils/descriptors.hpp"
#include "vkutils/descriptors.h"
#include "vkutils/data_heap.h"
#include "vkutils/instance.hpp"
#include "vkutils/sync.h"

View File

@ -7,7 +7,7 @@
#include "VKHelpers.h"
#include "vkutils/data_heap.h"
#include "vkutils/descriptors.hpp"
#include "vkutils/descriptors.h"
#include "vkutils/graphics_pipeline_state.hpp"
#include "Emu/IdManager.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include "VKProgramBuffer.h"
#include "vkutils/descriptors.hpp"
#include "vkutils/descriptors.h"
#include <unordered_map>
namespace vk

View File

@ -0,0 +1,56 @@
#include "descriptors.h"
namespace vk
{
void descriptor_pool::create(const vk::render_device& dev, VkDescriptorPoolSize* sizes, u32 size_descriptors_count, u32 max_sets, u8 subpool_count)
{
ensure(subpool_count);
VkDescriptorPoolCreateInfo infos = {};
infos.flags = 0;
infos.maxSets = max_sets;
infos.poolSizeCount = size_descriptors_count;
infos.pPoolSizes = sizes;
infos.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
m_owner = &dev;
m_device_pools.resize(subpool_count);
for (auto& pool : m_device_pools)
{
CHECK_RESULT(vkCreateDescriptorPool(dev, &infos, nullptr, &pool));
}
m_current_pool_handle = m_device_pools[0];
}
void descriptor_pool::destroy()
{
if (m_device_pools.empty()) return;
for (auto& pool : m_device_pools)
{
vkDestroyDescriptorPool((*m_owner), pool, nullptr);
pool = VK_NULL_HANDLE;
}
m_owner = nullptr;
}
bool descriptor_pool::valid() const
{
return (!m_device_pools.empty());
}
descriptor_pool::operator VkDescriptorPool()
{
return m_current_pool_handle;
}
void descriptor_pool::reset(VkDescriptorPoolResetFlags flags)
{
m_current_pool_index = (m_current_pool_index + 1) % u32(m_device_pools.size());
m_current_pool_handle = m_device_pools[m_current_pool_index];
CHECK_RESULT(vkResetDescriptorPool(*m_owner, m_current_pool_handle, flags));
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#include "../VulkanAPI.h"
#include "device.h"
#include <vector>
namespace vk
{
class descriptor_pool
{
const vk::render_device* m_owner = nullptr;
std::vector<VkDescriptorPool> m_device_pools;
VkDescriptorPool m_current_pool_handle = VK_NULL_HANDLE;
u32 m_current_pool_index = 0;
public:
descriptor_pool() = default;
~descriptor_pool() = default;
void create(const vk::render_device& dev, VkDescriptorPoolSize* sizes, u32 size_descriptors_count, u32 max_sets, u8 subpool_count);
void destroy();
void reset(VkDescriptorPoolResetFlags flags);
bool valid() const;
operator VkDescriptorPool();
};
}

View File

@ -1,74 +0,0 @@
#pragma once
#include "../VulkanAPI.h"
#include "device.h"
#include <vector>
namespace vk
{
class descriptor_pool
{
const vk::render_device* m_owner = nullptr;
std::vector<VkDescriptorPool> m_device_pools;
VkDescriptorPool m_current_pool_handle = VK_NULL_HANDLE;
u32 m_current_pool_index = 0;
public:
descriptor_pool() = default;
~descriptor_pool() = default;
void create(const vk::render_device& dev, VkDescriptorPoolSize* sizes, u32 size_descriptors_count, u32 max_sets, u8 subpool_count)
{
ensure(subpool_count);
VkDescriptorPoolCreateInfo infos = {};
infos.flags = 0;
infos.maxSets = max_sets;
infos.poolSizeCount = size_descriptors_count;
infos.pPoolSizes = sizes;
infos.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
m_owner = &dev;
m_device_pools.resize(subpool_count);
for (auto& pool : m_device_pools)
{
CHECK_RESULT(vkCreateDescriptorPool(dev, &infos, nullptr, &pool));
}
m_current_pool_handle = m_device_pools[0];
}
void destroy()
{
if (m_device_pools.empty()) return;
for (auto& pool : m_device_pools)
{
vkDestroyDescriptorPool((*m_owner), pool, nullptr);
pool = VK_NULL_HANDLE;
}
m_owner = nullptr;
}
bool valid()
{
return (!m_device_pools.empty());
}
operator VkDescriptorPool()
{
return m_current_pool_handle;
}
void reset(VkDescriptorPoolResetFlags flags)
{
m_current_pool_index = (m_current_pool_index + 1) % u32(m_device_pools.size());
m_current_pool_handle = m_device_pools[m_current_pool_index];
CHECK_RESULT(vkResetDescriptorPool(*m_owner, m_current_pool_handle, flags));
}
};
}

View File

@ -40,7 +40,7 @@
<ClInclude Include="Emu\RSX\VK\vkutils\chip_class.h" />
<ClInclude Include="Emu\RSX\VK\vkutils\commands.h" />
<ClInclude Include="Emu\RSX\VK\vkutils\data_heap.h" />
<ClInclude Include="Emu\RSX\VK\vkutils\descriptors.hpp" />
<ClInclude Include="Emu\RSX\VK\vkutils\descriptors.h" />
<ClInclude Include="Emu\RSX\VK\vkutils\barriers.h" />
<ClInclude Include="Emu\RSX\VK\vkutils\framebuffer_object.hpp" />
<ClInclude Include="Emu\RSX\VK\vkutils\image.h" />
@ -93,6 +93,7 @@
<ClCompile Include="Emu\RSX\VK\vkutils\scratch.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\sync.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\memory.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\descriptors.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\device.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\sampler.cpp" />
<ClCompile Include="Emu\RSX\VK\vkutils\shared.cpp" />

View File

@ -44,6 +44,9 @@
<ClCompile Include="Emu\RSX\VK\vkutils\memory.cpp">
<Filter>vkutils</Filter>
</ClCompile>
<ClCompile Include="Emu\RSX\VK\vkutils\descriptors.cpp">
<Filter>vkutils</Filter>
</ClCompile>
<ClCompile Include="Emu\RSX\VK\vkutils\device.cpp">
<Filter>vkutils</Filter>
</ClCompile>
@ -139,7 +142,7 @@
<ClInclude Include="Emu\RSX\VK\vkutils\swapchain.hpp">
<Filter>vkutils</Filter>
</ClInclude>
<ClInclude Include="Emu\RSX\VK\vkutils\descriptors.hpp">
<ClInclude Include="Emu\RSX\VK\vkutils\descriptors.h">
<Filter>vkutils</Filter>
</ClInclude>
<ClInclude Include="Emu\RSX\VK\vkutils\data_heap.h">