vk: Unify descriptor allocation

- Pool management should be a backend implementation detail.
This commit is contained in:
kd-11 2023-05-28 23:10:25 +03:00 committed by kd-11
commit 10171c19c3
10 changed files with 5 additions and 72 deletions

View file

@ -119,15 +119,6 @@ namespace vk
} }
} }
void compute_task::free_resources()
{
if (m_used_descriptors == 0)
return;
m_descriptor_pool.reset(0);
m_used_descriptors = 0;
}
void compute_task::load_program(const vk::command_buffer& cmd) void compute_task::load_program(const vk::command_buffer& cmd)
{ {
if (!m_program) if (!m_program)
@ -155,14 +146,7 @@ namespace vk
ensure(m_used_descriptors < VK_MAX_COMPUTE_TASKS); ensure(m_used_descriptors < VK_MAX_COMPUTE_TASKS);
VkDescriptorSetAllocateInfo alloc_info = {}; m_descriptor_set = m_descriptor_pool.allocate(m_descriptor_layout, VK_TRUE, m_used_descriptors++);
alloc_info.descriptorPool = m_descriptor_pool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &m_descriptor_layout;
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
CHECK_RESULT(vkAllocateDescriptorSets(*g_render_device, &alloc_info, m_descriptor_set.ptr()));
m_used_descriptors++;
bind_resources(); bind_resources();

View file

@ -44,8 +44,6 @@ namespace vk
void create(); void create();
void destroy(); void destroy();
void free_resources();
virtual void bind_resources() {} virtual void bind_resources() {}
virtual void declare_inputs() {} virtual void declare_inputs() {}

View file

@ -966,11 +966,6 @@ void VKGSRender::end()
m_aux_frame_context.grab_resources(*m_current_frame); m_aux_frame_context.grab_resources(*m_current_frame);
m_current_frame = &m_aux_frame_context; m_current_frame = &m_aux_frame_context;
} }
else if (m_current_frame->used_descriptors)
{
m_current_frame->descriptor_pool.reset(0);
m_current_frame->used_descriptors = 0;
}
ensure(!m_current_frame->swap_command_buffer); ensure(!m_current_frame->swap_command_buffer);

View file

@ -1322,13 +1322,10 @@ void VKGSRender::check_descriptors()
{ {
// Ease resource pressure if the number of draw calls becomes too high or we are running low on memory resources // Ease resource pressure if the number of draw calls becomes too high or we are running low on memory resources
const auto required_descriptors = rsx::method_registers.current_draw_clause.pass_count(); const auto required_descriptors = rsx::method_registers.current_draw_clause.pass_count();
if (!m_current_frame->descriptor_pool.can_allocate(required_descriptors, m_current_frame->used_descriptors)) if (!m_current_frame->descriptor_pool.can_allocate(required_descriptors, 0))
{ {
// Should hard sync before resetting descriptors for spec compliance // Should hard sync before resetting descriptors for spec compliance
flush_command_queue(true); flush_command_queue(true);
m_current_frame->descriptor_pool.reset(0);
m_current_frame->used_descriptors = 0;
} }
} }
@ -1336,7 +1333,7 @@ VkDescriptorSet VKGSRender::allocate_descriptor_set()
{ {
if (!m_shader_interpreter.is_interpreter(m_program)) [[likely]] if (!m_shader_interpreter.is_interpreter(m_program)) [[likely]]
{ {
return m_current_frame->descriptor_pool.allocate(descriptor_layouts, VK_TRUE, m_current_frame->used_descriptors++); return m_current_frame->descriptor_pool.allocate(descriptor_layouts, VK_TRUE, 0);
} }
else else
{ {

View file

@ -177,7 +177,6 @@ namespace vk
vk::descriptor_set descriptor_set; vk::descriptor_set descriptor_set;
vk::descriptor_pool descriptor_pool; vk::descriptor_pool descriptor_pool;
u32 used_descriptors = 0;
rsx::flags32_t flags = 0; rsx::flags32_t flags = 0;

View file

@ -288,12 +288,6 @@ namespace vk
void overlay_pass::free_resources() void overlay_pass::free_resources()
{ {
if (m_used_descriptors == 0)
return;
m_descriptor_pool.reset(0);
m_used_descriptors = 0;
m_vao.reset_allocation_stats(); m_vao.reset_allocation_stats();
m_ubo.reset_allocation_stats(); m_ubo.reset_allocation_stats();
} }

View file

@ -48,7 +48,6 @@ namespace vk
descriptor_set m_descriptor_set; descriptor_set m_descriptor_set;
VkDescriptorSetLayout m_descriptor_layout = nullptr; VkDescriptorSetLayout m_descriptor_layout = nullptr;
VkPipelineLayout m_pipeline_layout = nullptr; VkPipelineLayout m_pipeline_layout = nullptr;
u32 m_used_descriptors = 0;
VkFilter m_sampler_filter = VK_FILTER_LINEAR; VkFilter m_sampler_filter = VK_FILTER_LINEAR;
u32 m_num_usable_samplers = 1; u32 m_num_usable_samplers = 1;

View file

@ -518,23 +518,7 @@ namespace vk
VkDescriptorSet shader_interpreter::allocate_descriptor_set() VkDescriptorSet shader_interpreter::allocate_descriptor_set()
{ {
if (!m_descriptor_pool.can_allocate(1u, m_used_descriptors)) return m_descriptor_pool.allocate(m_shared_descriptor_layout, VK_TRUE, 0);
{
m_descriptor_pool.reset(0);
m_used_descriptors = 0;
}
VkDescriptorSetAllocateInfo alloc_info = {};
alloc_info.descriptorPool = m_descriptor_pool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &m_shared_descriptor_layout;
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
VkDescriptorSet new_descriptor_set;
CHECK_RESULT(vkAllocateDescriptorSets(m_device, &alloc_info, &new_descriptor_set));
m_used_descriptors++;
return new_descriptor_set;
} }
glsl::program* shader_interpreter::get(const vk::pipeline_props& properties, const program_hash_util::fragment_program_utils::fragment_program_metadata& metadata) glsl::program* shader_interpreter::get(const vk::pipeline_props& properties, const program_hash_util::fragment_program_utils::fragment_program_metadata& metadata)

View file

@ -42,7 +42,6 @@ namespace vk
std::unordered_map<pipeline_key, std::unique_ptr<glsl::program>, key_hasher> m_program_cache; std::unordered_map<pipeline_key, std::unique_ptr<glsl::program>, key_hasher> m_program_cache;
std::unordered_map<u64, std::unique_ptr<glsl::shader>> m_fs_cache; std::unordered_map<u64, std::unique_ptr<glsl::shader>> m_fs_cache;
vk::descriptor_pool m_descriptor_pool; vk::descriptor_pool m_descriptor_pool;
u32 m_used_descriptors = 0;
u32 m_vertex_instruction_start = 0; u32 m_vertex_instruction_start = 0;
u32 m_fragment_instruction_start = 0; u32 m_fragment_instruction_start = 0;

View file

@ -205,14 +205,7 @@ namespace vk
{ {
ensure(m_used_descriptors < 120); ensure(m_used_descriptors < 120);
VkDescriptorSetAllocateInfo alloc_info = {}; m_descriptor_set = m_descriptor_pool.allocate(m_descriptor_layout, VK_TRUE, m_used_descriptors++);
alloc_info.descriptorPool = m_descriptor_pool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &m_descriptor_layout;
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
CHECK_RESULT(vkAllocateDescriptorSets(device, &alloc_info, m_descriptor_set.ptr()));
m_used_descriptors++;
float scale[] = { scale_x, scale_y }; float scale[] = { scale_x, scale_y };
float colors[] = { color[0], color[1], color[2], color[3] }; float colors[] = { color[0], color[1], color[2], color[3] };
@ -360,15 +353,6 @@ namespace vk
} }
} }
void reset_descriptors()
{
if (m_used_descriptors == 0)
return;
m_descriptor_pool.reset(0);
m_used_descriptors = 0;
}
void set_scale(double scale) void set_scale(double scale)
{ {
// Restrict scale to 2. The dots are gonna be too sparse otherwise. // Restrict scale to 2. The dots are gonna be too sparse otherwise.