Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a Direct3D 11 HLSL shader with SharpDX. What I want to do is write the depth to a texture in one pass and read it in the next one. After declaring the texture, do I have to set the depth texture and the shader resource view per frame, or just once when attaching?

this.depthStencilShaderResourceVariable = this.effect.GetVariableByName("DepthTexture").AsShaderResource();
share|improve this question
I'm not certain about DirectX, but in OpenGL you aren't allowed to render to a bound texture - so some rebinding is necessary each frame. – Polar Nov 26 '13 at 12:45
Ok, but what do you mean by bound texture? I thought the bindings I'm doing there were precisely to be able to read the texture. – c4sh Nov 26 '13 at 16:08
You can't read and write a texture simultaneously in the common case. So you have to bind the depth texture to write it, then unbind it for writing before you bind it for reading. There are ways around this for regular textures using newer hardware features, but not for depth textures to my knowledge. – Sean Middleditch Nov 26 '13 at 17:26
Thanks, so I guess the changes I have to do are per frame? – c4sh Nov 26 '13 at 17:50

D3D11 will prevent you from binding a shader view of a resource and a render view of a resource simultaneously.

Consequently you will need to bind and unbind the views every time you want to read or write to the depth texture; you can't just bind them and leave them that way for the lifetime of your program, because you can't have both views bound simultaneously.

share|improve this answer
Actually, if you want to write a bound texture, D3D11 will unbind it for you while generating a warning:… – János Turánszki Dec 18 '14 at 17:14
Huh, that's interesting, I'd never tried that since the documentation is littered with comments about the "conflict checker" that "prevents" this sort of thing. Good to know. – Josh Petrie Dec 18 '14 at 17:16

Your Answer


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.