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 ?
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. …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.
Cheers!
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...
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!