Do samplers that are not used at runtime in a Vulkan/GLSL shader need to be bound? [duplicate]

Until Vulkan 1.2, Vulkan did not recognize the possibility of a descriptor being "empty". When a descriptor set is created, the descriptors are (mostly) uninitialized. It's OK to have a set with an uninitialized descriptor, so long as the pipeline which consumes it does not statically use the descriptor. Since you are presumably trying to use the same pipeline for objects with diffuse maps and objects without them, your shader reads from the image based on a variable you provide. That represents static use of the descriptor, so you need an image there.

The typical way to deal with this is to create a tiny image of a reasonable format and stuff that into the descriptor. You can use the same image for essentially any "null" texture you want to use.

Vulkan 1.2, as part of the VK_EXT_descriptor_indexing extension promoted to core, allows for the possibility of partially bound descriptors. Basically, if the descriptorBindingPartiallyBound feature is available and requested, then you can allocate a descriptor set using the VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT bit. This means that it's OK to leave a descriptor undefined so long as it is not dynamically used.

So you simply wouldn't write a value for that descriptor.

Of course, this requires 1.2 (or the aforementioned extension), as well as requesting the feature.


You are not quite correct, a combined image sampler still requires a valid sampler for some reason, and not only that, a nullDescriptor functionality have to be enabled. I run into exactly the same problem. What noone ever tells is that partly bound descriptors is not the same as sparsly bound descriptors, so it basicaly means y can bind X descriptors out of N if X<N but all those X must be valid, the specs is realy thin on this and there is no good examples.