Shader need 2 texture but only 1 was provided

Hello Community.
Here is my question:
My fragment shader looks like this:

layout(binding = 0) uniform sampler2D texture1;
layout(binding = 1) uniform sampler2D texture2;
if (condition1)
{
    only use texture1
}
else
{
    use texture1 and texture2
}

In condition1, only texture1’s vk::ImageView is provided from program, and I don’t have another vk::ImageView to bind to texture2. I tried to update my descriptor set with only one vk::WriteDescriptorSet and caused a validation error.
So What should I do to solve my problem in condition1? I’ve come up with some ideas, should I use one of them?
1.update descriptor set with two vk::WriteDescriptorSet, but both vk::WriteDescriptorSet use texutre1’s ImageView.
2.create a new vk::DescriptorSetLayout by only one vk::DescriptorSetLayoutbinding, and then create a new pipeline and a new descriptor set.
3.split this shader to two seperate shaders.
Thanks!

That’s not a thing; you cannot set a texture to null.

If you have descriptor indexing, you can choose to leave a binding uninitialized. But unless you’ve activated that feature, you must put something into all bindings of a descriptor set.

Thanks for your answer. ‘texture2 is nullptr’ means I don’t have another vk::ImageView to bind to texture2, I only have one vk::ImageView that can bind to texture1.Do you mean I should bind the only vk::ImageView to both texture1 and texture2 to solve this problem?

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