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.

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();
this.depthStencilShaderResourceVariable.SetResource(this.depthTextureShaderResourceView);
share|improve this question
1  
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
1  
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

1 Answer 1

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
1  
Actually, if you want to write a bound texture, D3D11 will unbind it for you while generating a warning: gamedev.stackexchange.com/questions/88373/… –  János Turánszki yesterday
    
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 yesterday

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.