Creating the Descriptor Sets

Descriptor sets provide shaders with a means of accessing data stored in buffers

By this point, the application has buffers which store data, like the transformation matrix and the texture image, and also shaders which use this data to perform some kind of calculation. Resource descriptors provide the means with which shaders gain access to this buffer data.

What are descriptors and descriptor sets?

Descriptors (as the name implies) are used to describe the data that is going to be passed. They hold information that helps with binding data to shaders and describe any information Vulkan requires before executing the shader. Descriptors are not passed individually (and are opaque to the application) but are instead bundled in sets, known as descriptor sets. Descriptor sets hold pointers to the actual resources which are going to be accessed. Much like command buffers, descriptor sets must be allocated out of descriptor pools.

Example: initDescriptorPoolAndSet()

The example code demonstrates the process of creating a descriptor pool and then allocating descriptor sets out of it. Two descriptor sets are needed for this application:
  • A dynamic descriptor set which will point to the dynamic uniform buffer containing multiple transformation matrices.
  • A static descriptor set which will point to the buffer containing the texture data.
Before a descriptor set can be allocated, a descriptor set layout must be created. This object describes what type of resources the descriptor is pointing to and which shader stages can access the resource.
  • For the dynamic descriptor set, this will be a dynamic uniform buffer and the vertex shader stage.
  • For the static descriptor set, this will be a combined image sampler and the fragment shader stage.