Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sorry if this has been answered elsewhere - I'm rather new to DX. My question concerns conservation of resources - specifically textures in VRAM. I assume that upon returning from a call to CreateTexture2D, a copy of any textures data supplied has been copied elsewhere, likely VRAM. Does DX11 have any facility for having multiple ID3D11Texture2D objects which point to the same data?

This might at first seem silly, but imagine a ID3D11Texture2D which is an array of textures. In one material, an artist has chosen to blend three identically sized maps, saved on disk as A.dds, B.dds, and C.dds. Then imagine they have another material which also uses three maps, but this time A.dds, B.dds, and D.dds.

The shader code knows the diffuse texture is a texture array, and also has the number of layers baked (three in each case). I would essentially like to set up just two ID3D11Texture2D objects, one for each material, but I don't want to waste VRAM for two identical copies of A.dds and B.dds.

I could use explicit texture arrays, of course, but this reduces the number of resources available to the shader and can complicate code somewhat more than would otherwise be needed.

share|improve this question
add comment

2 Answers

I don't think that this is possible. What I would do in this case is have either 4 different textures sourced from A, B, C and D, or else a single array with 4 slices (A, B, C and D again) and include the array slices to use in the material definition.

share|improve this answer
add comment

I'm pretty sure D3D11 does not allow multiple ID3D11Texture2D objects to point to the same pixel data in memory. However, you can certainly have multiple ID3D11ShaderResourceView objects point to the same ID3D11Texture2D object, which addresses the same core concern. Using your example above, you could have six unique ShaderResourceView objects and four unique Textures set up as follows:

  • Material1.pSRV1 points to Texture A
  • Material1.pSRV2 points to Texture B
  • Material1.pSRV3 points to Texture C
  • Material2.pSRV1 points to Texture A
  • Material2.pSRV2 points to Texture B
  • Material2.pSRV3 points to Texture D

Memory-wise, SRVs are relatively lightweight objects compared to the Textures they refer to.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.