Gregor Sattel
Gregor Sattel

Reputation: 400

How to resize TextureArray in directx 11

I'm using a Texture2DArray to store the shadow maps of my directional lights. When a new directional light is added I want to resize the texture array to be able to hold the new shadow map. How can I achieve this? I need this, because it's very convenient to pass texture array to my shader and just index the correct texture based on the light index.

One possibility I see is to instead keep multiple Texture2Ds, create a Texture2DArray before rendering with the required shader and copy to the corresponding subresource. This does not sound very convenient and efficient to me, though.

Upvotes: 1

Views: 427

Answers (1)

mrvux
mrvux

Reputation: 8963

Recreating resource every frame is certainly wasteful, so creating a texture array and copy is definitely not very efficient.

If your light count doesn't really change on a per scene basis, you can still totally create a new resource at the beginning of the scene (during load).

In case you want it fully dynamic, you will indeed have to pick a maximum number of light, in case you go over that number you can either decide to create a new resource, or issue an error stating that you are over the maximum allowed.

Also if you don't want to over commit memory (if you create a an array with 128 slices for example, but use only 5 lights you waste tons of vram), you can consider using Tiled Resources.

The idea is that you create a large resource up front, but with no memory assigned to it. On top of it you create a buffer with the Tile pool flag (note that in this case you are allowed to set a zero size, and size is always a multiple of 65536).

When you need to increase size, you can use ResizeTilePool on your buffer.

To assign blocks of memory from your tile pool to your texture, you use UpdateTileMappings

As a side note since you actually can use those tile memory on several resources at once you also might need to issue TiledResourceBarrier on your context (this is normally only needed if your tiles are used by several resources at once).

I used that technique for many use cases in my renderer, and had some very good memory usage improvements.

Upvotes: 2

Related Questions