Module vulkano::descriptor_set

source ·
Expand description

Bindings between shaders and the resources they access.

Overview

In order to access a buffer or an image from a shader, that buffer or image must be put in a descriptor. Each descriptor contains one buffer or one image alongside with the way that it can be accessed. A descriptor can also be an array, in which case it contains multiple buffers or images that all have the same layout.

Descriptors are grouped in what is called descriptor sets. In Vulkan you don’t bind individual descriptors one by one, but you create then bind descriptor sets one by one. As binding a descriptor set has (small but non-null) a cost, you are encouraged to put descriptors that are often used together in the same set so that you can keep the same set binding through multiple draws.

Examples

Note: This section describes the simple way to bind resources. There are more optimized ways.

There are two steps to give access to a resource in a shader: creating the descriptor set, and passing the descriptor sets when drawing.

Creating a descriptor set

TODO: write example for: PersistentDescriptorSet::start(layout.clone()).add_buffer(data_buffer.clone())

Passing the descriptor set when drawing

TODO: write

When drawing

When you call a function that adds a draw command to a command buffer, one of the parameters corresponds to the list of descriptor sets to use. Vulkano will check that what you passed is compatible with the layout of the pipeline.

TODO: talk about perfs of changing sets

Descriptor sets creation and management

There are three concepts in Vulkan related to descriptor sets:

  • A DescriptorSetLayout is a Vulkan object that describes to the Vulkan implementation the layout of a future descriptor set. When you allocate a descriptor set, you have to pass an instance of this object. This is represented with the DescriptorSetLayout type in vulkano.
  • A DescriptorPool is a Vulkan object that holds the memory of descriptor sets and that can be used to allocate and free individual descriptor sets. This is represented with the DescriptorPool type in vulkano.
  • A DescriptorSet contains the bindings to resources and is allocated from a pool. This is represented with the [UnsafeDescriptorSet] type in vulkano.

In addition to this, vulkano defines the following:

Re-exports

Modules

  • In the Vulkan API, descriptor sets must be allocated from descriptor pools.
  • Describes the layout of all descriptors within a descriptor set.
  • A simple, immutable descriptor set that is expected to be long-lived.
  • Low-level descriptor set.

Structs

Enums

Traits