debonair
debonair

Reputation: 2593

does vulkan bindings have to be sequential in shaders

is it necessary that bindings for uniforms, varyings or the attributes have to be sequential in vulkan? Let say we have

layout (std140, set = 0, binding = 0) uniform ubo1 {}
layout (std140, set = 0, binding = 3) uniform ubo2 {}

is it allowed? same for the attribute bindings.?

Upvotes: 1

Views: 781

Answers (2)

Jesse Hall
Jesse Hall

Reputation: 6787

No, they don't have to be tightly packed. In the Descriptor Layout description (13.2.1), the spec says:

Bindings that are not specified have a descriptorCount and stageFlags of zero, and the descriptorType is treated as undefined. However, all binding numbers between 0 and the maximum binding number in the VkDescriptorSetLayoutCreateInfo::pBindings array may consume memory in the descriptor set layout even if not all descriptor bindings are used, though it should not consume additional memory from the descriptor pool.

Note: The maximum binding number specified should be as compact as possible to avoid wasted memory.

Upvotes: 0

InsertMemeNameHere
InsertMemeNameHere

Reputation: 2433

Yes, this is allowed in shader code. Not so certain about implementations.

You can take a look at the documentation for VkDescriptorSetLayoutCreateInfo to get an idea of what is involved in defining a descriptor set layout. You'll notice that VkDescriptorSetLayoutBinding allows the specification of a binding at an arbitrary index.

As a matter of personal preference (and that I didn't find any explicit wording on the matter), I simply do not trust implementations to handle this intuitively. So, I create empty bindings to "fill in the gaps".

Upvotes: 1

Related Questions