3
\$\begingroup\$

I have a ID3D11Texture2D (that I've created manually) inside a ID3D11ShaderResourceView. When I want to Release() the resource view, do I need to Release() the texture that it is inside too? Or is it not necessary to do so?

Msdn doc and Google couldn't help me on this one. :/

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

Yes. Any reference you have to a D3D object needs a Release() call when you're done with it. It doesn't matter whether another object might also have a reference to it. The object will not be deleted until all references to it are gone, so it's safe to Release() the texture as soon as you don't need the pointer to it anymore. If it's also referenced by an SRV, that reference will keep it alive until the SRV is also deleted.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for your answer. So this would be okay to do? HRESULT res = d3dDevice->CreateShaderResourceView(ret_texture, &desc, &SRV); ret_texture->Release(); // ... Do more stuff with SRV object \$\endgroup\$
    – Kaboose
    Apr 29, 2013 at 17:07
  • \$\begingroup\$ @Kaboose Yes, that should be fine. \$\endgroup\$ Apr 29, 2013 at 17:09
1
\$\begingroup\$

I would add to the prior answer a discussion about bound Shader Resource Views and a distinction between D3D10 and D3D11. Microsoft changed the behavior when binding resources such that the D3D11 runtime holds a reference to the resource until you bind something else to whatever slot it is on.

D3D10 did not do this and various swapchain operations that require you to release all resources will fail if you do not clear all SRV bindings first in D3D11 (but not D3D10). You may have implicit references floating around even if you have released every resource you ever created.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .