Jump to content

  • Log In with Google      Sign In   
  • Create Account

OMSetRenderTargets Warnings


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 simotix   Members   -  Reputation: 142

Like
1Likes
Like

Posted 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,
m_pDepthStencilView);

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,
m_pDepthStencilView);

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);
m_pD3D11DeviceContext->ClearDepthStencilView(m_pDepthStencilView,
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;
D3DXMatrixIdentity(&worldMatrix);

D3DXMATRIX viewMatrix;
D3DXMatrixIdentity(&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);
if(!result)
{
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);
if(FAILED(result))
{
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.
deviceContext->IASetInputLayout(m_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);

return;
}



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?

Sponsor:

#2 smasherprog   Members   -  Reputation: 432

Like
0Likes
Like

Posted 20 November 2010 - 05:42 PM

Well, I am not sure because I am to lazy to completely look over your code --yeah, I am lazy. However, I know that you will get warnings like that if you have a texture bound to a shader, and attempt to bind the same texture as a render target.

So, if you every have a texture bound in a shader, and then attempt to set that same texture as a rendertarget, you will get warnings, and visa versa. Remember, directx is a state machine, so if you have a texture bound as a render target, it will stay bound, the same for textures. You have to unbind one of them so there isnt a conflict by setting one of them to null.

//d3d10 code, but 11 is the same
ID3D10RenderTargetView* pNullRTV = NULL;
g_Device->OMSetRenderTargets( 1, &pNullRTV, NULL );//<--- THIS is needed because you cannot bind a texture and have it bound as a render target. Must release first


Try it out lemmi know how it goes

#3 simotix   Members   -  Reputation: 142

Like
0Likes
Like

Posted 20 November 2010 - 06:24 PM

Quote:
Original post by smasherprog
Well, I am not sure because I am to lazy to completely look over your code --yeah, I am lazy. However, I know that you will get warnings like that if you have a texture bound to a shader, and attempt to bind the same texture as a render target.

So, if you every have a texture bound in a shader, and then attempt to set that same texture as a rendertarget, you will get warnings, and visa versa. Remember, directx is a state machine, so if you have a texture bound as a render target, it will stay bound, the same for textures. You have to unbind one of them so there isnt a conflict by setting one of them to null.

//d3d10 code, but 11 is the same
ID3D10RenderTargetView* pNullRTV = NULL;
g_Device->OMSetRenderTargets( 1, &pNullRTV, NULL );//<--- THIS is needed because you cannot bind a texture and have it bound as a render target. Must release first


Try it out lemmi know how it goes


I would like to avoid a "hack" like that if possible. I do not see what I could be doing wrong, I basically followed the tutorial at http://rastertek.com/dx11tut22.html where there was no "hack" like that done. I have gone line by line, literally, line by line to make sure our code is EXACTLY the same. Nothing catches me eye, I can almost swear the code is 100% the same (started off a lot different, but when trying to track down this code ... I ended up writing it much like his.

#4 smasherprog   Members   -  Reputation: 432

Like
0Likes
Like

Posted 20 November 2010 - 07:06 PM

Its not a hack. You cannot read and write to a resource at the same time, which is why you cannot have a texture bound to a shader and bound as a render target. So, you should get warnings if you are attempting to do that.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS