Are sets / bindings unique per stage or per program?

I’m asking because VkWriteDescriptorSet seems to have a set and binding but not a stage mask.
Regards

A descriptor set can be used with any program that is compatible with its set layout. So they are not “unique” to any program. The layout of a descriptor set specifies which shader stages access which descriptors (specifically VkDescriptorSetLayoutBinding::stageFlags) Different descriptors in the same set can be used by different stages. So a set is not “unique” to a stage.

Descriptor sets live outside of programs and stages. They feed these things, but they do not belong to them.

I mean set / binding configurations as part of the layout qualifier. I want to know if each combination is unique per program.

What does that mean, “per program”? If you mean “pipeline”, Vulkan doesn’t care; each pipeline is separate from each other, so it doesn’t matter if two different pipelines use the same set/binding location. Each pipeline is built against a descriptor set layout, and any set/binding locations in shaders in that pipeline are relative to sets that match that layout.

And if you mean within a pipeline, then all that means is that you have multiple stages that are reading the same descriptor. Which is fine, so long as your descriptor set layout makes it clear that those stages will read from the same descriptor (again, see VkDescriptorSetLayoutBinding::stageFlags).

Ok, let’s try again:

I have a shader program that has a vertex and a fragment stage. There are variables in it with a layout qualifier:
https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)
This layout qualifier can have a set and binding parameter.
My question is: Can two variables with different names have the same set/binding combination? If one is in fragment and the other one in vertex? Or differently: Is every set/binding combination unique?

No, you have two shader modules which you want to assemble into a pipeline. Vulkan has no concept of a “shader program” distinct from a pipeline.

Vulkan is based on SPIR-V, and SPIR-V definitions do not have names. Yes, the SPIR-V binary has string decorations which can be applied to its definitions, but these are optional and ignored as far as the functional behavior of a SPIR-V binary is concerned.

The only thing SPIR-V cares about are the set/bindings associated with a definition.

A particular resource specified by a pipeline’s layout is defined by a set and binding index. A shader module’s set/binding indices, when used to build a pipeline, will match its set/binding indices to those in the pipeline layout. So if two shader stages in the same pipeline are using the same set/binding indices, they are talking about the same resource.

It is OK to have two stages in the same pipeline use the same resource, so long as both stages agree on what that resource is (and the pipeline layout says that those stages are accessing it). If it’s a UBO resource, then both stages must use matching UBO definitions (along with the offset/alignment on each member of the UBO). If it’s a sampler, then the samplers must be of the same type. And so forth.

What do you mean by “unique”? Within a pipeline, every set/binding index is indicative of a particular resource with a particular structure (as defined in the pipeline layout).

2 Likes

That’s what I needed to know. Thank you!

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.