Is there a way to make indirect rendering and pass textures to a uniform buffer and access to them with an index like in opengl ? Rather than making a drawcall by texture which can slow the gpu if I have a lot of textures
The link contains the long version, but the short version is pretty simple. In Vulkan, a uniform of sampler type can be an array. Unlike OpneGL, an array of a uniform is a single descriptor. A single Vulkan descriptor can be arrayed.
Note that I’m not talking about an array texture; I mean an array of textures.
The limits on an arrayed sampler has limitations defined by the implementation, but it can be quite large. Such arrays can be indexed with dynamically uniform, or even completely non-uniform expressions, depending on hardware support. Given such support, you can get an index to your shader, index this array of textures, and proceed as you like.
The principle limitation here is that the textures in the array have to be of the same sampler type (2D, 3D, etc). But actually… you can have that too.
See, you can declare multiple
uniform arrays in your shader to use the same descriptor set, despite having different sampler types. And you’ll note that the descriptor type in Vulkan doesn’t actually say what kind of texture it is; they’re all just “storage images” or “sampled images” or whatever. There is a runtime check that the descriptor bound at that array index must match the shader variable type.
But that’s just a matter of picking the right array, which should be an integral part of your shader logic.
One of the challenges with supporting a more pure-GL-like bindless texturing approach, even in OpenGL, is missing SPIR-V IR support. Related:
See the last post for a 2022 update, including SPV_NV_bindless_texture . The last time we looked into this though, the tooling to make use of this was lacking. So AFAIK bindless texture via SPIR-V isn’t an option for either OpenGL or Vulkan.
And on Vulkan specifically, if you’re interested in some context on why the pure-Vulkan approach is what it is, think “lowest common denominator”. For details, see:
- Vulkan “But WHY?” FAQ (Yosoygames, 2023)
** ← Specifically the last section: “Why resource binding is done through VkPipelineLayout & VkDescriptorSetLayout and all that madness”
- Descriptors are hard (Ekstrand, 2022)
So, you may be able to choose a different tech approach depending on what your target set of GPUs is.