Jump to content
  • Advertisement
Sign in to follow this  

DX11 How to debug in DirectX11

This topic is 2181 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I have wrt an game using DX11.
I want display a trangle, but only background color displayed.

And I use the InfoQueue to catch the error message
[source lang="cpp"] HRESULT hr=S_OK;
EXCEPTION("Device not created")

EXCEPTION("Create ID3D11Debug failed")

EXCEPTION("Set ReportLiveDeviceObjects failed")

EXCEPTION("Create ID3D11InfoQueue failed")


ZeroMemory(&filter, sizeof(D3D11_INFO_QUEUE_FILTER));

In the log file:

Create RenderTargetView: Name="unnamed", Addr=0x00FDB034, ExtRef=1, IntRef=0
Create Texture2D: Name="unnamed", Addr=0x00FDB15C, ExtRef=1, IntRef=0
Create DepthStencilState: Name="unnamed", Addr=0x00FDB334, ExtRef=1, IntRef=0
Create DepthStencilView: Name="unnamed", Addr=0x00FDB42C, ExtRef=1, IntRef=0
But I don't know what's the meaning of it.
Because when I create the RenderTargetView,Texture2D,DepthStencilState and DepthStencilView, ther are all return S_OK.

How can I detect the bug?

And here is an other question.

Every function in ID3D11Device interface will return the HRESULT. so I can know the function run success or failed.
But the function in ID3D11DeviceContext interface have no return value.
How can I know the result?

Share this post

Link to post
Share on other sites
You can debug direct3d shaders directly from Visual Studio 2012.


Share this post

Link to post
Share on other sites
Hi, all

I found the problem. Because of i use the ID3D11DepthStencilView.

If I use the code:
[source lang="cpp"]deviceContext->OMSetRenderTargets(1, &defaultRenderTargetView, NULL);[/source]
everything is ok.

What's wrong with ID3D11DepthStencilView in my code?

[source lang="cpp"]
// Initialize the description of the depth buffer.
ZeroMemory(&depthBufferDesc, sizeof(depthBufferDesc));

// Set up the description of the depth buffer.

depthBufferDesc.Width = m_screenWidth;
depthBufferDesc.Height = m_screenHeight;
depthBufferDesc.MipLevels = 1;
depthBufferDesc.ArraySize = 1;
depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthBufferDesc.SampleDesc.Count = 1;
depthBufferDesc.SampleDesc.Quality = 0;
depthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthBufferDesc.CPUAccessFlags = 0;
depthBufferDesc.MiscFlags = 0;

// Create the texture for the depth buffer using the filled out description.
hr = m_device->CreateTexture2D(&depthBufferDesc, NULL, &defaultDepthStencilBuffer);

// Initialize the description of the stencil state.
ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc));

// Set up the description of the stencil state.
depthStencilDesc.DepthEnable = true;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;

depthStencilDesc.StencilEnable = true;
depthStencilDesc.StencilReadMask = 0xFF;
depthStencilDesc.StencilWriteMask = 0xFF;

// Stencil operations if pixel is front-facing.
depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

// Stencil operations if pixel is back-facing.
depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

// Create the depth stencil state.
hr = m_device->CreateDepthStencilState(&depthStencilDesc, &defaultDepthStencilState);

deviceContext->OMSetDepthStencilState(defaultDepthStencilState, 1);

// Initialize the depth stencil view.
ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc));

// Set up the depth stencil view description.
depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
depthStencilViewDesc.Texture2D.MipSlice = 0;

// Create the depth stencil view.
hr = m_device->CreateDepthStencilView(defaultDepthStencilBuffer, &depthStencilViewDesc, &defaultDepthStencilView);

deviceContext->OMSetRenderTargets(1, &defaultRenderTargetView, defaultDepthStencilView);[/source]

Share this post

Link to post
Share on other sites
I don't see anything obvious, though I wonder if you really want stencil enabled. Also, as BCullis noted, provide the shader source, and, since you now want to use depth test/write other relevant info (vertices, rasterizer state, transformations, especially the projection).

And I use the InfoQueue to catch the error message...[/quote]

I haven't dabbled with the info queue much, but I think by clearing the filters and adding D3D11_MESSAGE_SEVERITY_ERROR to the DenyList you actually disabled error reporting altogether. Rather leave it as is, creating the device in debug mode is probably enough.

And: Yeah, PIX (or the graphics debugger from VS 2012) is your friend. Get familiar with it now. To get a feeling, PIX-debug a working applications (e.g. Tutorial #5 of the SDK samples is a good start, since it uses depth).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!