Vulkan Sampler Array

Started by
2 comments, last by acerskyline 4 years, 9 months ago

I have 10 samplers as an uniform array in a fragment shader. When rendering, I only used 3 of them. So the descriptor set layout and descriptor set only have 3 combined image samplers. That's why I am getting this validation layer warning:


validation layer: Shader expects at least 10 descriptors for binding 0.1 but only 3 provided

Is there any way to get rid of this other than changing 


layout(set = 0, binding = 1) uniform sampler2D lightTextureArray[10];

to


layout(set = 0, binding = 1) uniform sampler2D lightTextureArray[3];

If I fill up remaining descriptors with default image info (use null handle for view and sampler), the validation layer will complain about invalid combined image sampler/view or something like that. The only way I can think of now is to repeat the existing descriptors. Is there any other way to get around this? What is the standard way to solve this problem?
 

Advertisement

The descriptor layout must have the same number of bindings that you specify in the shader, and have valid descriptors bound to them, according to the spec. Apparently, most implementations are fine with invalid descriptors if they are not dynamically used, but the validation layers will warn you regardless.
To get rid of the warning, you can use the approach you mentioned and fill the remaining ones with whatever compatible samplers you have. Personally, I create dummy objects for these cases (e.g. a simple generic sampler, a 1x1 image, etc.) that I reuse everywhere necessary.
Another way is to use VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT, if supported, which allows bindings to not contain valid descriptors if they are not dynamically used.

Thanks so much!

This topic is closed to new replies.

Advertisement