Sign in to follow this  
w162

[D3D11] Superb strange problem with CreateDepthStencilState

Recommended Posts

w162    100
Hi Everyone,

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:

[code]
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;
}
[/code]

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:
[quote]
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 :)

Share this post


Link to post
Share on other sites
inovae_keith    102
Ok I have discovered that even though ID3D11DepthStencilState::GetDesc() is returning incorrect values rendering still behaves as expected per the values passed in at creation. It should be noted that PIX will also report incorrect values, presumably because it's calling ID3D11DepthStencilState::GetDesc().

Share this post


Link to post
Share on other sites
w162    100
[quote name='DirectX Sebastian' timestamp='1311791831' post='4841211']
Do you have depth enable set to false? If so, that would explain what you are seeing.
[/quote]

Yes, that was exactly the problem.

Actually, I think it's a bug in D3D 11 documentation which mixed the conception of "enable depth testing" and "enable depth buffering". The real meaning of D3D11_DEPTH_STENCIL_DESC::DepthEnable is the same as D3D9's D3DRS_ZENABLE.

I have already submitted a bug to Microsoft and hope they will fix that in the future DX releases.

Share this post


Link to post
Share on other sites
clb    2147
I am also seeing this, when I was using nVidia Parallel Nsight to debug my application. Seems that D3D11_DEPTH_STENCIL_DESC::DepthEnable and D3D11_DEPTH_STENCIL_DESC::StencilEnable are "short-circuiting". I also commented on the bug report "[D3D11] Documentation problem in D3D11_DEPTH_STENCIL_DESC.DepthEnable" at [url="https://connect.microsoft.com/site1102/feedback/details/670019/d3d11-documentation-problem-in-d3d11-depth-stencil-desc-depthenable"]Microsoft Connect[/url] (requires live account to view... duh MS!)

Note that PIX, Parallel Nsight and manually calling ID3D11DepthStencilState::GetDesc will all return the same data that is "inconsistent" to the states you set, if you had specified DepthEnable = FALSE or StencilEnable = FALSE, but as far as I can understand, it is ok, since those states don't have any effect.

Since there probably doesn't exist a Direct3D team anymore (nobody's been active at MS since December 2010!) to work on fixing the bugs, I have also added a comment to the documentation of [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476110(v=vs.85).aspx"]D3D11_DEPTH_STENCIL_DESC[/url] itself, so people won't waste time scratching their heads on this one, like I did.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this