Optimal solution ?


I’m rewriting a game with Vulkan and I face a problem.
There is maps with different sizes which are composed of a checkerboard of textures.
Example :

|GGG |


So here my thought :
Common ideas

  • Keep the preview images (AttachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD).
  • Use vkCmdClearAttachments to clear the screen on new map.
  • Use shaders to translate the map on player mouvement.

Idea 1
forEach texture in texturesArray [
vkCreateSampler(…, texture);
forEach tile in tilesIn(texture) {
Is this correct ? Can we call shaders to update only parts of image.

Idea 2
Pass an array of {texture, position} to the shaders but I can’t predict the array size.

Thank you.

Ok since I get no answer I think my question is not clear.
-> Thread 0 (Network) : It get the local map
-> Thread 1 (Ressources) : Use a dictionary to reverse tiles types to texture and position
If not found launch a new network thread which download the image and make it a texture
-> Thread 2 (Render) : Get the texture to the right position (the screen is divised in squares)
The problem is that the number of textures is variable how I do that in Vulkan ?

Still not very clear, is it 2d top-down view?

I think I forgot to include an image of the game Im rewriting here one :

I have include some text to better understand in it.
What I call a tile is the fact that each texture are on a chessboard.
How can I do that in Vulkan since the number of texture is unknown and loaded at runtime.

When you originally wrote this in OpenGL, you presumably didn’t give each tile a separate texture. You had each tile use the same texture. But there was always just one texture, which you redrew into different places.

Vulkan would work the exact same way.

I’m not the one who wrote the game It is actually a reverse, the game doesn’t use OpenGL (it use the CPU that is why it can be pretty slow) and there is really multiples textures.

Simplest solution (depending on your target hardware) would be to use a texture array, load tiles into the arrays when they’re required and index dynamically in the FS (if the implementation supports it). Other options are texture atlas, sparse texture or just rebuild CBs and descriptors dynamically using a background thread? Lots of possibilities to do this in Vulkan.

Any example for the texture array (Im pretty new to shaders).
I can’t do an atlas (the texture would be too large).
Doesn’t rebuild descriptor set would be not very optimal.

The thing you’re not understanding is that the texture is not the picture on the screen. It’s a picture in memory; it’s just data. You can display the same data in multiple places without having multiple textures. You just render two quads with the same descriptors.

I don’t see hundreds of textures in the tilemap of the screenshot you showed. I see 5 textures (probably using a texture atlas), which are used in different places.

Yes I know that but the size of a texture is limited and so I can’t fit all data in one.
Does texture array woul have better performance ?

You are not limited to one atlas texture, so if texture size is a limiting factor, split textures into multiple atlases and draw using the different atlases.

No, they’re just another way of storing textures that allow you to have multiple layers you can directly address within the shader. So if a tile is going to use “texture data” from layer 8 from the array, then you can directly sample from that slice in the shader but you only need one descriptor and binding point for the array texture.