Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dynamic Texture Array

Started by Hassanbasil Jun 13, 2014 at 2:20 PM 4 replies 6.4k views
Original Post
Hassanbasil
Hassanbasil

Hello,

I'm trying to create a texture array that I want to update per frame. So I want to use D3D11_USAGE_DYNAMIC and ArraySize>1. but I get this error: D3D11 ERROR: ID3D11Device::CreateTexture2D: A D3D11_USAGE_DYNAMIC Resource must have ArraySize equal to 1. [ STATE_CREATION ERROR #101: CREATETEXTURE2D_INVALIDDIMENSIONS]

Why is that even a thing? Is there anything wrong with a dynamic texture array?

EDIT: I also tried 3D textures, there seems to be a minimum for the size of a row (128 in my case)? creating a 1x1x1 3D texture and then using Map gives RowPitch=128 (although format is 4 bytes per texel). Is this documented anywhere? there is not even a warning, using small textures messes up everything.

Regards,

Hasan Al-Jawaheri

MJP
MJP

D3D11 doesn't support dynamic textures with mipmaps or multiple array slices, which is why CreateTexture2D is failing. This is what you can do instead:

  • Create your Texture2D Array using D3D11_USAGE_DEFAULT
  • Create an identical Texture2D using D3D11_USAGE_STAGING
  • When you want to update the texture array, call Map with the STAGING texture and fill the memory
  • Use CopyResource to copy the contents from the STAGING texture to the DEFAULT texture

If you only want to update one slice at a time, you can do that as well by using CopySubresourceRegion.

Hassanbasil
Hassanbasil

D3D11 doesn't support dynamic textures with mipmaps or multiple array slices, which is why CreateTexture2D is failing. This is what you can do instead:

  • Create your Texture2D Array using D3D11_USAGE_DEFAULT
  • Create an identical Texture2D using D3D11_USAGE_STAGING
  • When you want to update the texture array, call Map with the STAGING texture and fill the memory
  • Use CopyResource to copy the contents from the STAGING texture to the DEFAULT texture

If you only want to update one slice at a time, you can do that as well by using CopySubresourceRegion.

I see. Would it be more efficient (performance and memory wise) to use a 3D texture instead?

kauna
kauna

Texture2DArray and 3D texture aren't same thing. The OP didn't specify the exact purpose for the texture array.

Cheers!

MJP
MJP

You probably don't want to use a 3D texture unless you need to filter between the different slices.

Hassanbasil
Hassanbasil

I'm using the texture to implement geometric clipmap based terrain. Basically, the texture is used by a Load call in the vertex shader. I thought, ignoring the "intuitive usage" of the texture, one ID3D11DeviceContext::Map for a 3D texture would be faster than a Map on a staging texture and a CopyResource. Plus it's probably using less memory.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.