DEBUG Mode doesn't work in D3D11CreateDeviceAndSwapChain

tyty Exs 20 Reputation points
2025-07-08T03:23:32.6133333+00:00

i use (windows-rs)[https://github.com/microsoft/windows-rs] to develop an app using DirectAPI, but i found that it can not get debug information, eventhough i enable D3D11_CREATE_DEVICE_DEBUG in when using D3D11CreateDeviceAndSwapChain, I don't see the debug message in the terminal where the program running. I use vscode, rust, windows-rs, here some sample code:


```rust
pub fn from_handle(hwnd: HWND) -> Self {
        let mut p_device = None;
        let mut p_swap = None;
        let mut p_context = None;
        let mut sd = DXGI_SWAP_CHAIN_DESC::default();
        sd.OutputWindow = hwnd;
        sd.Windowed = true.into();
        sd.BufferDesc.Width = 0;
        sd.BufferDesc.Height = 0;
        sd.BufferDesc.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
        sd.SampleDesc.Count = 1;
        sd.SampleDesc.Quality = 0;
        sd.BufferUsage = windows::Win32::Graphics::Dxgi::DXGI_USAGE_RENDER_TARGET_OUTPUT;
        sd.BufferCount = 2;
        sd.SwapEffect = windows::Win32::Graphics::Dxgi::DXGI_SWAP_EFFECT_FLIP_DISCARD;

        unsafe {
            D3D11CreateDeviceAndSwapChain(
                None,
                D3D_DRIVER_TYPE_HARDWARE,
                HMODULE::default(),
                D3D11_CREATE_DEVICE_DEBUG,   // !! here i use DEBUG MODE
                None,
                D3D11_SDK_VERSION,
                Some(&sd),
                Some(&mut p_swap),
                Some(&mut p_device),
                None,
                Some(&mut p_context),
            )
            .expect("D3D11CreateDeviceAndSwapChain failed");
        }
        let mut p_render_target: Option<ID3D11RenderTargetView> = None;
        unsafe {
            // Get the back buffer
            let p_back_buffer: Option<ID3D11Resource> = Some(p_swap.as_ref().unwrap().GetBuffer(0).expect("GetBuffer failed"));
            // Create the render target view
            p_device
                .as_ref()
                .unwrap()
                .CreateRenderTargetView(p_back_buffer.as_ref(), None, Some(&mut p_render_target as *mut _))
                .expect("CreateRenderTargetView failed");
        }
        Graphics {
            p_device,
            p_swap,
            p_context,
            p_target: p_render_target,
        }
    }

Is DEBUG mode an exclusive feature of VS Studio?

Developer technologies | Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. Varsha Dundigalla(INFOSYS LIMITED) 795 Reputation points Microsoft External Staff
    2025-07-08T06:40:39.63+00:00

    Thank you for reaching out. Please find the answer below.

    Debug mode is not exclusive to Visual Studio. Direct3D debug messages don’t appear in the terminal because they’re sent through OutputDebugString, not standard output. To see them, you need the Direct3D debug layer and a tool that captures debug output.

    First, install the “Graphics Tools” optional feature in Windows. Go to Settings → Apps → Optional Features → Add a feature, search for “Graphics Tools,” and install it. This provides the required D3D11SDKLayers.dll for debug mode to work.

    Next, use a debugger that listens for OutputDebugString. Visual Studio does this by default. In VSCode, you need to use the MSVC debugger (cppvsdbg) to capture these messages. You can also use DebugView, a free tool from Microsoft’s Sysinternals suite, which shows debug output in real time. It’s available at https://learn.microsoft.com/sysinternals/downloads/debugview.

    With the debug layer installed and a proper viewer running, you’ll be able to see Direct3D debug messages when using D3D11_CREATE_DEVICE_DEBUG.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.