gardenPre-allocated stock for shader resources
Vulkan descriptor pool
The concept
Like the Vulkan command pool, the descriptor pool is pre-allocated at startup, right after the Vulkan logical device — no allocation happens in the rendering loop. Where the command pool feeds the GPU its instructions, the descriptor pool feeds the shaders their data: it produces the descriptor sets that let us hand CPU-side resources (matrices, textures) to a shader.
In game engine
First we declare the stock levels — how many descriptors of each type the pool holds:
// cpp
// Resource Pools. A material set holds one sampler per texture slot, so
// the sampler budget must be a multiple of the set budget for the pool to
// reach 'maxSets' before it runs out of descriptors.
constexpr uint32_t maxSets = 1000;
constexpr uint32_t samplersPerMaterial = 8;
std::array poolSizes = {
vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, maxSets),
vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler,
maxSets * samplersPerMaterial)};UniformBuffer: mathematical matrices (camera position, projection, object transform).CombinedImageSampler: textures of 3D models (e.g. the texture of a brick wall). A material set holds one sampler per texture slot, so the sampler budget ismaxSets * samplersPerMaterial— otherwise the pool would run out of samplers before reaching its set budget.
Then we create the pool itself:
// cpp
vk::DescriptorPoolCreateInfo descriptorpoolInfo{};
descriptorpoolInfo.maxSets = maxSets;
descriptorpoolInfo.flags =
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet;
descriptorpoolInfo.setPoolSizes(poolSizes);
d_descriptorPool = vk::raii::DescriptorPool(d_device, descriptorpoolInfo);maxSets: the maximum number of "packs" (descriptor sets) this factory can produce in total, using the stock levels defined above.eFreeDescriptorSet: by default Vulkan does not allow destroying a single descriptor set, only the entire pool at once. This flag lets us free memory object by object.
Linked references 3
notes that point at this one
Bufferengine
Vulkan descriptor pool: a shader never reaches a uniform buffer directly.
Vulkan command poolvulkan
They are created right after the Vulkan logical device, alongside the Vulkan descriptor pool.
Architecturegamegine
Resource pools — the Vulkan descriptor pool and the Vulkan command pool, pre-allocated so the rendering loop never allocates.