I met a strange problem with ID3D11Device::CreateDepthStencilState(). The returned state object did not carry the correct states I set. So I got very abnormal rendering result.
I found the problem with PIX, and then wrote the following test code to verify it:
HRESULT hr = d3dDevice->CreateDepthStencilState( &desc, &d3d11DepthStencilState);
if( FAILED(hr) )
{
PopError( "Failed to create depth-stencil state object!" );
}
D3D11_DEPTH_STENCIL_DESC newDesc;
d3d11DepthStencilState->GetDesc(&newDesc);
static int errorCount = 0;
if (newDesc.DepthWriteMask != desc.DepthWriteMask)
{
++errorCount;
}
And the DepthWriteMask was different between the desc and newDesc sometimes. In my specific case, the desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ZERO and newDesc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL. It was the same behavior I saw with PIX.
The document just mentioned that:
4096 unique depth-stencil state objects can be created on a device at a time.
If an application attempts to create a depth-stencil-state interface with the same state as an existing interface, the same interface will be returned and the total number of unique depth-stencil state objects will stay the same.
[/quote]
But I could not believe that's the problem since the same depth-stencil-state object should only be reused when the state was the same. And hr == S_OK when the if() triggered.
How could this behavior be explained?
Thank you very much