2

Is there a way of taking an array of ID3D11Texture2D* objects and putting them together in a single ID3D11Texture2D* (with an appropriate ArraySize value) that will allow me to use a Texture2DArray in HLSL with them?

At the very least, how do you pass in the individual textures when creating a new ID3D11Texture2D object after you have set ArraySize to greater than 1? Do you need to pass in an array of SUBRESOURCE_DATA structs with each pointing to a texture to the CreateTexture2D function? I've been looking around for an answer to this, but the documentation seems severely lacking.

Thanks for any help you can provide.

1 Answer 1

4

To copy existing textures to a texture array, you can use CopySubresourceRegion using the destination subresource index described below.

To create a new texture array with initial data, you specify multiple subresources (array slices / mip levels) using an array of SUBRESOURCE_DATA structures. Subresource index is defined as mip slice + array slice * mip leves. So for a 2-slice 3-MIP texture array, you would have the following subresources:

[0]: slice 0 mip 0
[1]: slice 0 mip 1
[2]: slice 0 mip 2
[3]: slice 1 mip 0
[4]: slice 1 mip 1
[5]: slice 1 mip 2

This is described in more detail at the following page: https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-subresources

Sign up to request clarification or add additional context in comments.

2 Comments

That looks like just what I'm looking for! But just to be clear, do you need to copy each individual mip level from a texture into the array texture, one at a time (making sure to add 1 to each destination index)
If you're going with the CopySubresourceRegion approach, then yes, you need to copy one subresource at a time. But in that case you should consider just using the array resource to begin with so you can avoid a copy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.