class new in Git master
#include <Magnum/Vk/DescriptorSet.h>
DescriptorSet Descriptor set.
Wraps a VkDescriptorSet. A descriptor set is allocated from a DescriptorPool for a particular DescriptorSetLayout and specifies what descriptors (such as uniform buffers or samplers) are bound to shaders.
Descriptor set allocation
Given a DescriptorSetLayout and a compatible DescriptorPool with enough free slots, asingle descriptor set for given layout can be allocated with DescriptorPool::
Vk::DescriptorSetLayout layout{…}; Vk::DescriptorPool pool{…}; Vk::DescriptorSet set = pool.allocate(layout);
When allocating more than what the pool has, the DescriptorPool::
Containers::Optional<Vk::DescriptorSet> set = pool.tryAllocate(layout); /* Oops, the pool is full (or fragmented). Hope the plan B doesn't fail too. */ if(!set) set = overflowPool.allocate(layout);
Freeing descriptor sets
By default, the DescriptorSet destructor is a no-op and descriptor sets are all freed together on a call to DescriptorPool::
Vk::DescriptorPool pool{device, Vk::DescriptorPoolCreateInfo{…, { … }, Vk::DescriptorPoolCreateInfo::Flag::FreeDescriptorSet}}; { Vk::DescriptorSet set = pool.allocate(layout); // the set gets automatically freed at the end of scope }
Variable descriptor count allocation
If the descriptor set layout contains a descriptor with variable count (there has to be at most one and it has to be the last binding), a concrete count is specified in the call to DescriptorPool::
Vk::Device device{instance, Vk::DeviceCreateInfo{…} … .addEnabledExtensions<Vk::Extensions::EXT::descriptor_indexing>() .setEnabledFeatures( Vk::DeviceFeature::DescriptorBindingVariableDescriptorCount| … ) }; Vk::DescriptorSetLayout layout{device, Vk::DescriptorSetLayoutCreateInfo{ {{…, Vk::DescriptorType::SampledImage, 8, Vk::ShaderStage::Fragment, Vk::DescriptorSetLayoutBinding::Flag::VariableDescriptorCount}}, … }}; Vk::DescriptorSet set = pool.allocate(layout, 4);
Public static functions
- static auto wrap(Device& device, VkDescriptorPool pool, VkDescriptorSet handle, HandleFlags flags = {}) -> DescriptorSet
- Wrap existing Vulkan handle.
Constructors, destructors, conversion operators
- DescriptorSet(NoCreateT) explicit
- Construct without creating the fence.
- DescriptorSet(const DescriptorSet&) deleted
- Copying is not allowed.
- DescriptorSet(DescriptorSet&& other) noexcept
- Move constructor.
- ~DescriptorSet()
- Destructor.
- operator VkDescriptorSet()
Public functions
- auto operator=(const DescriptorSet&) -> DescriptorSet& deleted
- Copying is not allowed.
- auto operator=(DescriptorSet&& other) -> DescriptorSet& noexcept
- Move assignment.
- auto handle() -> VkDescriptorSet
- Underlying VkDescriptorSet handle.
- auto handleFlags() const -> HandleFlags
- Handle flags.
- auto release() -> VkDescriptorSet
- Release the underlying Vulkan descriptor set.
Function documentation
static DescriptorSet Magnum:: Vk:: DescriptorSet:: wrap(Device& device,
VkDescriptorPool pool,
VkDescriptorSet handle,
HandleFlags flags = {})
Wrap existing Vulkan handle.
Parameters | |
---|---|
device | Vulkan device the descriptor pool is created on |
pool | Vulkan descriptor pool the set is allocated from |
handle | The VkDescriptorSet handle |
flags | Handle flags |
The handle
is expected to be originating from device
. The Vulkan descriptor set is by default not freed on destruction — if the handle comes from a pool with DescriptorPoolCreateInfo::flags
.
Magnum:: Vk:: DescriptorSet:: DescriptorSet(NoCreateT) explicit
Construct without creating the fence.
The constructed instance is equivalent to moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.
Magnum:: Vk:: DescriptorSet:: ~DescriptorSet()
Destructor.
Frees associated VkDescriptorSet handle if it was allocated from a pool with DescriptorPoolCreateInfo::
Magnum:: Vk:: DescriptorSet:: operator VkDescriptorSet()
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
VkDescriptorSet Magnum:: Vk:: DescriptorSet:: release()
Release the underlying Vulkan descriptor set.
Releases ownership of the Vulkan descriptor set and returns its handle so vkFreeDescriptorSets() is not called on destruction. The internal state is then equivalent to moved-from state.