Jump to content
  • Advertisement
Sign in to follow this  
Adaline

Unbind render targets and resource viewes

This topic is 2474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I regularly get this kind of warnings :

D3D10: WARNING: ID3D10Device::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]

As an example, I get this message from this code :

bool renderEmissiveBlur(UINT sizeOfVertexQuad,ID3D10Buffer * quadBuffer)
{
d3dDevice->IASetInputLayout(quadInputLayout); UINT offset=0;
UINT stride=sizeOfVertexQuad;
d3dDevice->IASetVertexBuffers(0,1,&quadBuffer,&stride,&offset);

d3dDevice->OMSetRenderTargets(1,&renderTargetView_WT,NULL);
if (!emissiveBlurEffect.setResourceVariable("g_Texture",shaderResourceViewes[2])) return false;
ID3D10EffectTechnique * technique=emissiveBlurEffect.getTechnique("EMISSIVEBLURH");
if (technique==NULL) return false;
if FAILED(technique->GetPassByIndex(0)->Apply(0)) return false; d3dDevice->Draw(6,0);
d3dDevice->OMSetRenderTargets(1,&renderTargetViewes[2],NULL); (triggers the warning message)
if (!emissiveBlurEffect.setResourceVariable("g_Texture",shaderResourceView_WT)) return false; technique=emissiveBlurEffect.getTechnique("EMISSIVEBLURV");
if (technique==NULL) return false;
if FAILED(technique->GetPassByIndex(0)->Apply(0)) return false;
d3dDevice->Draw(6,0); return true;
}


(it's used to blur the emissive layer in the G Buffer)

So what should I do to unbind properly my resources (renders targets and resource viewes) please ?

Thank you

Nico

Share this post


Link to post
Share on other sites
Advertisement
Seems that texture object related to renderTargetViewes[2] is bound as a texture somewhere? (PSSetShaderResources)

Simply call PSSetShaderResources again with the same Index and an array containing NULL pointer.

Best regards!

Share this post


Link to post
Share on other sites
Hello kauna and thank you it works fine with what you said.

So : after the first draw call, I added this (as a test) :

ID3D10ShaderResourceView * tab[1];
tab[0]=NULL;
d3dDevice->PSSetShaderResources(0,1,tab);

.... and the warning vanished !
I can now fix this at all the locations where this warning occurs smile.png

Nico

Share this post


Link to post
Share on other sites
When I’m coding, I sometimes realize that I need an additional shader resource view in a shader and then - of course - add it in the rendering loop. Unfortunately, I constantly keep forgetting to unbind the newly added SRV at the end of the function. smile.png …which can lead to such errors you had before, e.g.:
ID3D10ShaderResourceView* srvs[2] = {m_srv0, m_srv1};
d3dDevice->PSSetShaderResources(0, 2, srvs);
// some draw calls…
ID3D10ShaderResourceView* nosrvs[1] = {0}; // I forgot to unbind the second srv...
d3dDevice->PSSetShaderResources(0, 1, nosrvs);


To keep my mind from this, I’m sometimes lazy and just unbind everything.
ID3D10ShaderResourceView* srvs[D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0};
d3dDevice->PSSetShaderResources(0, D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srvs);


Maybe this helps you to prevent some errors. smile.png
Cheers!

Share this post


Link to post
Share on other sites
Or you can go one step further and create a simple layer between your engine and the API calls that monitors what is set and what isn't. Then you can unbind only the necessary views in between stages, and develop customized ways to handle when you are trying to write to a resource that is bound for input or vice versa. Hieroglyph 3 uses this concept, but only in a simple way...

Share this post


Link to post
Share on other sites
Jason, FWIW, I hope Microsoft addresses this in a future release. It would be nice if when you bound a resource, DX just automatically unbound it from whatever it was bound to before. If DX did this, we'd all benefit from it instead of each of us having to write that management layer!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!