vk: Add support for dynamic buffer offsets

This commit is contained in:
kd-11 2025-04-02 00:01:02 +03:00 committed by kd-11
parent b3bbd939e3
commit dad9a2b916
2 changed files with 20 additions and 1 deletions

View file

@ -430,6 +430,17 @@ namespace vk
} }
} }
void descriptor_set::push(const descriptor_set_dynamic_offset_t& offset)
{
ensure(offset.location >= 0 && offset.location <= 16);
while (m_dynamic_offsets.size() < (offset.location + 1))
{
m_dynamic_offsets.push_back(0);
}
m_dynamic_offsets[offset.location] = offset.value;
}
void descriptor_set::bind(const vk::command_buffer& cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout) void descriptor_set::bind(const vk::command_buffer& cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout)
{ {
if ((m_push_type_mask & ~m_update_after_bind_mask) || (m_pending_writes.size() >= max_cache_size)) if ((m_push_type_mask & ~m_update_after_bind_mask) || (m_pending_writes.size() >= max_cache_size))
@ -437,7 +448,7 @@ namespace vk
flush(); flush();
} }
vkCmdBindDescriptorSets(cmd, bind_point, layout, 0, 1, &m_handle, 0, nullptr); vkCmdBindDescriptorSets(cmd, bind_point, layout, 0, 1, &m_handle, ::size32(m_dynamic_offsets), m_dynamic_offsets.data());
} }
void descriptor_set::flush() void descriptor_set::flush()

View file

@ -27,6 +27,12 @@ namespace vk
} }
}; };
struct descriptor_set_dynamic_offset_t
{
int location;
u32 value;
};
class descriptor_pool class descriptor_pool
{ {
public: public:
@ -95,6 +101,7 @@ namespace vk
void push(const VkDescriptorImageInfo& image_info, VkDescriptorType type, u32 binding); void push(const VkDescriptorImageInfo& image_info, VkDescriptorType type, u32 binding);
void push(const VkDescriptorImageInfo* image_info, u32 count, VkDescriptorType type, u32 binding); void push(const VkDescriptorImageInfo* image_info, u32 count, VkDescriptorType type, u32 binding);
void push(rsx::simple_array<VkCopyDescriptorSet>& copy_cmd, u32 type_mask = umax); void push(rsx::simple_array<VkCopyDescriptorSet>& copy_cmd, u32 type_mask = umax);
void push(const descriptor_set_dynamic_offset_t& offset);
void bind(const vk::command_buffer& cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout); void bind(const vk::command_buffer& cmd, VkPipelineBindPoint bind_point, VkPipelineLayout layout);
@ -109,6 +116,7 @@ namespace vk
rsx::simple_array<VkBufferView> m_buffer_view_pool; rsx::simple_array<VkBufferView> m_buffer_view_pool;
rsx::simple_array<VkDescriptorBufferInfo> m_buffer_info_pool; rsx::simple_array<VkDescriptorBufferInfo> m_buffer_info_pool;
rsx::simple_array<VkDescriptorImageInfo> m_image_info_pool; rsx::simple_array<VkDescriptorImageInfo> m_image_info_pool;
rsx::simple_array<u32> m_dynamic_offsets;
#ifdef __clang__ #ifdef __clang__
// Clang (pre 16.x) does not support LWG 2089, std::construct_at for POD types // Clang (pre 16.x) does not support LWG 2089, std::construct_at for POD types