Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 17 Aug 2007
Offline Last Active Apr 21 2011 10:45 PM

#588324 OMSetRenderTargets Warnings

Posted by simotix on 20 November 2010 - 03:53 PM

I am getting the following two warnings, and honestly, I am not too sure why, and not too sure how to fix them. The warnings are

D3D11: WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD ]
D3D11: WARNING: ID3D11DeviceContext::OMSetRenderTargets[AndUnorderedAccessViews]: Forcing PS shader resource slot 0 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD ]

I have tracked it down to the line that is printing this warning, and the line that is causing this to happen.

I am trying to achieve rendering to a texture, then to display the texture. While I do know how to do this, I do not know how to prevent these warnings. The warning will display after I the second time this line will get called.

m_pD3D11DeviceContext->OMSetRenderTargets(1, &m_renderTargetView,

It is a result of inside TextureShaderClass::SetShaderParameters where this line is called

deviceContext->PSSetShaderResources(0, 1, &texture);

My main rendering loop looks like this, and yes, there is no actual contents being rendered, I am trying to break this bug down to the smallest bit possible.

void Render()
// Render to texture initialize
// Set the Render Target to be the render to texture.
m_pD3D11DeviceContext->OMSetRenderTargets(1, &m_renderTargetView,

float color[4];
color[0] = 0.0f;
color[1] = 0.0f;
color[2] = 1.0f;
color[3] = 1.0f;

// Clear the render to texture
m_pD3D11DeviceContext->ClearRenderTargetView(m_renderTargetView, color);
D3D11_CLEAR_DEPTH, 1.0f, 0);

// Reset the render target back to the original back buffer and not the render to texture anymore.
m_pD3D11DeviceContext->OMSetRenderTargets(1, &m_pD3D11RenderTargetView, m_pDepthStencilView );

// Clear the buffers to begin the scene
float color[4];
color[0] = 0.0f;
color[1] = 1.0f;
color[2] = 0.0f;
color[3] = 1.0f;
m_pD3D11DeviceContext->ClearRenderTargetView( m_pD3D11RenderTargetView, color );
m_pD3D11DeviceContext->ClearDepthStencilView( m_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );

// Turn off the Z buffer to begin all 2D rendering.
m_pD3D11DeviceContext->OMSetDepthStencilState(m_depthDisabledStencilState, 1);

// Render the texture at 50, 50
m_DebugWindow->Render(m_pD3D11DeviceContext, 50, 50);

D3DXMATRIX worldMatrix;

D3DXMATRIX viewMatrix;

m_TextureShader->Render(m_pD3D11DeviceContext, m_DebugWindow->GetIndexCount(),
worldMatrix, viewMatrix, m_orthoMatrix, m_shaderResourceView);

m_pD3D11DeviceContext->OMSetDepthStencilState(m_depthStencilState, 1);

m_pSwapChain->Present(0, 0);

There is two functions that get called in that, m_DebugWindow->Render and m_TextureShader->Render. I will first show the contents of m_TextureShader->Render as I do not believe m_DebugWindow->Render is causing the error.

bool TextureShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, D3DXMATRIX worldMatrix, D3DXMATRIX viewMatrix,
D3DXMATRIX projectionMatrix, ID3D11ShaderResourceView* texture)
bool result;

// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture);
return false;

// Now render the prepared buffers with the shader.
RenderShader(deviceContext, indexCount);

return true;

Which calls these two functions

bool TextureShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, D3DXMATRIX worldMatrix, D3DXMATRIX viewMatrix,
D3DXMATRIX projectionMatrix, ID3D11ShaderResourceView* texture)
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
ConstantBufferType* dataPtr;
unsigned int bufferNumber;

// Lock the constant buffer so it can be written to.
result = deviceContext->Map(m_constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
return false;

// Get a pointer to the data in the constant buffer.
dataPtr = (ConstantBufferType*)mappedResource.pData;

// Transpose the matrices to prepare them for the shader.
D3DXMatrixTranspose(&worldMatrix, &worldMatrix);
D3DXMatrixTranspose(&viewMatrix, &viewMatrix);
D3DXMatrixTranspose(&projectionMatrix, &projectionMatrix);

// Copy the matrices into the constant buffer.
dataPtr->world = worldMatrix;
dataPtr->view = viewMatrix;
dataPtr->projection = projectionMatrix;

// Unlock the constant buffer.
deviceContext->Unmap(m_constantBuffer, 0);

// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;

// Now set the constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_constantBuffer);

// Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture);

return true;

void TextureShaderClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
// Set the vertex input layout.

// Set the vertex and pixel shaders that will be used to render this triangle.
deviceContext->VSSetShader(m_vertexShader, NULL, 0);
deviceContext->PSSetShader(m_pixelShader, NULL, 0);

// Set the sampler state in the pixel shader.
deviceContext->PSSetSamplers(0, 1, &m_sampleState);

// Render the triangle.
deviceContext->DrawIndexed(indexCount, 0, 0);


If any more code is needed, please let me know. I have read the warnings, and the documentation for them, but I do not know how to prevent them. Does anyone know?