3#include <vulkan/vulkan.hpp>
22 vk::DescriptorType type_,
23 vk::ShaderStageFlags stages_,
44 vk::ShaderStageFlags stages, uint32_t count = 1)
46 bindings.emplace_back(binding, type, stages, count);
49 void add_storage_buffer(uint32_t binding, vk::ShaderStageFlags stages = vk::ShaderStageFlagBits::eCompute)
51 add_binding(binding, vk::DescriptorType::eStorageBuffer, stages);
54 void add_uniform_buffer(uint32_t binding, vk::ShaderStageFlags stages = vk::ShaderStageFlagBits::eCompute)
56 add_binding(binding, vk::DescriptorType::eUniformBuffer, stages);
59 void add_storage_image(uint32_t binding, vk::ShaderStageFlags stages = vk::ShaderStageFlagBits::eCompute)
61 add_binding(binding, vk::DescriptorType::eStorageImage, stages);
64 void add_sampled_image(uint32_t binding, vk::ShaderStageFlags stages = vk::ShaderStageFlagBits::eCompute)
66 add_binding(binding, vk::DescriptorType::eCombinedImageSampler, stages);
86 vk::DeviceSize offset = 0,
87 vk::DeviceSize range = VK_WHOLE_SIZE);
90 vk::ImageView image_view,
91 vk::ImageLayout layout = vk::ImageLayout::eGeneral);
94 vk::ImageView image_view,
96 vk::ImageLayout layout = vk::ImageLayout::eShaderReadOnlyOptimal);
150 bool initialize(vk::Device device, uint32_t initial_pool_size = 1024);
158 void cleanup(vk::Device device);
192 vk::DescriptorSetLayout layout);
212 vk::DescriptorSet set,
215 vk::DeviceSize offset = 0,
216 vk::DeviceSize range = VK_WHOLE_SIZE);
233 vk::DescriptorSet set,
235 vk::ImageView image_view,
236 vk::Sampler sampler =
nullptr,
237 vk::ImageLayout layout = vk::ImageLayout::eGeneral);
250 vk::DescriptorSet set,
252 vk::Sampler sampler);
267 vk::DescriptorSet set,
269 vk::ImageView image_view,
271 vk::ImageLayout layout = vk::ImageLayout::eShaderReadOnlyOptimal);
285 vk::DescriptorSet set,
287 vk::ImageView image_view,
288 vk::ImageLayout layout = vk::ImageLayout::eShaderReadOnlyOptimal);
296 return { device, set };
308 vk::DescriptorSet src,
309 vk::DescriptorSet dst,
310 uint32_t copy_count = 0);
322 const std::vector<vk::DescriptorSetLayout>& layouts);
334 const std::vector<vk::WriteDescriptorSet>& writes);
380 vk::DescriptorPool
create_pool(vk::Device device, uint32_t max_sets);
DescriptorUpdateBatch & sampler(uint32_t binding, vk::Sampler sampler)
std::vector< vk::DescriptorBufferInfo > m_buffer_infos
std::vector< vk::WriteDescriptorSet > m_writes
DescriptorUpdateBatch & combined_image_sampler(uint32_t binding, vk::ImageView image_view, vk::Sampler sampler, vk::ImageLayout layout=vk::ImageLayout::eShaderReadOnlyOptimal)
DescriptorUpdateBatch & buffer(uint32_t binding, vk::Buffer buffer, vk::DeviceSize offset=0, vk::DeviceSize range=VK_WHOLE_SIZE)
DescriptorUpdateBatch & storage_image(uint32_t binding, vk::ImageView image_view, vk::ImageLayout layout=vk::ImageLayout::eGeneral)
std::vector< vk::DescriptorImageInfo > m_image_infos
Fluent interface for batching descriptor updates.
void reset_pools(vk::Device device)
Reset all descriptor pools.
uint32_t m_allocated_count
Total allocated sets.
vk::DescriptorSet allocate_set(vk::Device device, vk::DescriptorSetLayout layout)
Allocate a descriptor set from the pool.
void batch_update(vk::Device device, const std::vector< vk::WriteDescriptorSet > &writes)
Batch update multiple bindings at once.
std::unordered_map< size_t, size_t > m_layout_cache
vk::DescriptorSetLayout create_layout(vk::Device device, const DescriptorSetLayoutConfig &config)
Create descriptor set layout from configuration.
DescriptorUpdateBatch begin_batch(vk::Device device, vk::DescriptorSet set)
Begin a batch descriptor update.
std::pair< uint32_t, uint32_t > get_pool_stats() const
Get current pool utilization.
uint32_t m_pool_capacity
Total capacity across all pools.
void update_image(vk::Device device, vk::DescriptorSet set, uint32_t binding, vk::ImageView image_view, vk::Sampler sampler=nullptr, vk::ImageLayout layout=vk::ImageLayout::eGeneral)
Update descriptor set with image binding.
void update_combined_image_sampler(vk::Device device, vk::DescriptorSet set, uint32_t binding, vk::ImageView image_view, vk::Sampler sampler, vk::ImageLayout layout=vk::ImageLayout::eShaderReadOnlyOptimal)
Update descriptor set with combined image+sampler.
bool grow_pools(vk::Device device)
Grow pool capacity by allocating new pool.
void cleanup(vk::Device device)
Cleanup all descriptor resources.
std::vector< vk::DescriptorSet > allocate_sets(vk::Device device, const std::vector< vk::DescriptorSetLayout > &layouts)
Allocate multiple descriptor sets at once.
void update_buffer(vk::Device device, vk::DescriptorSet set, uint32_t binding, vk::Buffer buffer, vk::DeviceSize offset=0, vk::DeviceSize range=VK_WHOLE_SIZE)
Update descriptor set with buffer binding.
size_t m_current_pool_index
uint32_t m_pool_size
Sets per pool.
vk::DescriptorPool create_pool(vk::Device device, uint32_t max_sets)
Create a new descriptor pool.
void update_input_attachment(vk::Device device, vk::DescriptorSet set, uint32_t binding, vk::ImageView image_view, vk::ImageLayout layout=vk::ImageLayout::eShaderReadOnlyOptimal)
Update descriptor set with input attachment.
VKDescriptorManager(const VKDescriptorManager &)=delete
VKDescriptorManager()=default
VKDescriptorManager & operator=(const VKDescriptorManager &)=delete
void copy_descriptor_set(vk::Device device, vk::DescriptorSet src, vk::DescriptorSet dst, uint32_t copy_count=0)
Copy descriptor set contents.
void update_sampler(vk::Device device, vk::DescriptorSet set, uint32_t binding, vk::Sampler sampler)
Update descriptor set with sampler binding.
std::vector< vk::DescriptorPool > m_pools
size_t hash_layout_config(const DescriptorSetLayoutConfig &config) const
Compute hash of descriptor set layout config.
std::vector< vk::DescriptorSetLayout > m_layouts
Manages descriptor pools, layouts, and set allocation.
vk::DescriptorType type
Type (storage buffer, uniform, etc.)
vk::ShaderStageFlags stage_flags
Which shader stages access this.
uint32_t count
Array size (1 for non-arrays)
uint32_t binding
Binding index within set.
DescriptorBinding(uint32_t binding_, vk::DescriptorType type_, vk::ShaderStageFlags stages_, uint32_t count_=1)
Describes a single descriptor binding in a set.
std::vector< DescriptorBinding > bindings
void add_sampled_image(uint32_t binding, vk::ShaderStageFlags stages=vk::ShaderStageFlagBits::eCompute)
void add_storage_image(uint32_t binding, vk::ShaderStageFlags stages=vk::ShaderStageFlagBits::eCompute)
void add_storage_buffer(uint32_t binding, vk::ShaderStageFlags stages=vk::ShaderStageFlagBits::eCompute)
void add_uniform_buffer(uint32_t binding, vk::ShaderStageFlags stages=vk::ShaderStageFlagBits::eCompute)
void add_binding(uint32_t binding, vk::DescriptorType type, vk::ShaderStageFlags stages, uint32_t count=1)
Configuration for creating a descriptor set layout.