2

Let me say the scenario, we have several meshes with the same shader (material type, e.g. PBR material), but the difference between meshes materials are the uniform buffer and textures for rendering them.

For uniform buffer we have a dynamic uniform buffer technique that uniform buffer offsets can be specify for each draw in the command buffer, but for the image till here I didn't find a way of specifying image view in command buffer for descriptor set. In all the sample codes I have seen till now, for every mesh and every material of that mesh they have a new pipeline, descriptor sets and etc.

I think it is not the best way, there must be a way to only have one pipeline and descriptor set and etc for a material type and only change the uniform buffer offset and texture image-view and sampler, am I right?

If I'm wrong, are these samples doing the best way?

How should I specify the VkDescriptorPoolCreateInfo.maxSets (or other limits like that) for dynamic scene that every minute meshes will add and remove?

Update:

I think it is possible to have a same pipeline and descriptor set layout for all of the objects but problem with VkDescriptorPoolCreateInfo.maxSets (or other limits like that) and the best practice still exist.

It is not duplicate

I was seeking for a way of specifying textures like what we can do with dynamic uniform buffer (to reduce number of descriptor sets) and along with this question there were complementary questions mostly to find best practices for the way that's gonna be suggested with an answer.

Community
  • 1
  • 1
Hossein Noroozpour
  • 1,091
  • 1
  • 13
  • 26
  • 1
    what's wrong with having the descriptor for that imageview in a higher numbered set and rebinding as needed? – ratchet freak Jun 22 '18 at 11:19
  • You can use the same pipeline, but either You need to change descriptor sets during rendering (they can e created from the same layout) or You need to store Your texture data through texture atlases or texture arrays. – Ekzuzy Jun 22 '18 at 12:38
  • Possible duplicate of [Vulkan texture rendering on multiple meshes](https://stackoverflow.com/questions/36772607/vulkan-texture-rendering-on-multiple-meshes) – Nicol Bolas Jun 22 '18 at 13:28
  • Also possibly a duplicate of [Is this understanding of VkDescriptorPoolCreateInfo.pPoolSizes correct?](https://stackoverflow.com/q/40660497/734069) – Nicol Bolas Jun 22 '18 at 13:52

1 Answers1

3

You have many options.

The simplest mechanism is to divide your descriptor set layout into sets based on the frequency of changes. Things that change per-scene would be in set 0, things that change per-kind-of-object (character, static mesh, etc), would be in set 1, and things that change per-object would be in set 2. Or whatever. The point is that the things that change with greater frequency go in higher numbered sets.

This texture is per-object, so it would be in the highest numbered set. So you would give each object its own descriptor set containing that texture, then apply that descriptor set when you go to render.

As for VkDescriptorPoolCreateInfo.maxSets, you set that to whatever you feel is appropriate for your system. And if you run out, you can always create another pool; nobody's forcing you to use just one.

However, this is only one option. You can also employ array textures or arrays of textures (depending on your hardware capabilities). In either method, you have an array of different images (either as a single image view or multiple views bound to the same arrayed descriptor). Your per-object uniform data would have that object's texture index, so that it can fetch the index from the array texture/array of textures.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • So I can create several pool and it is not a bad practice(?), I can think of creating pool for for every N set. – Hossein Noroozpour Jun 22 '18 at 14:50
  • My plan was to predefine all the set layouts and pipelines because number of my material-types are limited. And for set I'm gonna create a map ( texture(s) -> set ) I think this is gonna reduce number of set as much as possible, am I right? – Hossein Noroozpour Jun 22 '18 at 15:09