ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.84k stars 10.18k forks source link

DirectX 11 Swap chain freezes on present when using viewports with mixed swap effects #5437

Open kudaba opened 2 years ago

kudaba commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.85 (Custom) Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp Compiler: MSVC Operating System: Windows 10

This is more of a PSA than an issue. I've been tracking an issue for months where the application would freeze when users drag a window out into it's own viewport. Sometimes it would happen right away, or it could take a while. When looking into the frozen application you would see this callstack:

    win32u.dll!NtGdiDdDDIPresent()
    d3d11.dll!CallAndLogImpl<long (*)(struct _D3DKMT_PRESENT *),struct _D3DKMT_PRESENT *>(long (*)(struct _D3DKMT_PRESENT *),char const *,struct _D3DKMT_PRESENT *)
    d3d11.dll!NDXGI::CDevice::PresentCB()
    igd10iumd64.dll!00007ffddff07467()
    igd10iumd64.dll!00007ffddff07646()
    d3d11.dll!NDXGI::CDevice::PresentImpl(struct DXGI_PRESENTSURFACE const *,unsigned int,struct IDXGIResource *,void *,unsigned int,unsigned int,unsigned int *)
    d3d11.dll!NDXGI::CDevice::Present()
    dxgi.dll!CDXGISwapChain::PresentImplCore()
    dxgi.dll!CDXGISwapChain::PresentImpl()
    dxgi.dll!CDXGISwapChain::Present()

To make matters worse this only happened on certain hardware configurations. The root cause of this was that we were creating our main application swap chain with DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL if support for HDR in windowed mode was detected. ImGui uses DXGI_SWAP_EFFECT_DISCARD. It seems that some hardware doesn't like having mixed swap chain effects. I tried changing the ImGui viewport swap effect to discard but DirectX didn't seem to like that so I just made it that our application reverts to discard if ImGui viewport support is enabled.

ocornut commented 2 years ago

Thanks for reporting this.

I wonder if we could come up with a way to allow the application to specify details for creating windows. In this backend it would be e.g. a DXGI_SWAP_CHAIN_DESC template (mostly for sd.BufferDesc.Format and sd.SwapEffect.. maybe others).

Vulkan has some of that via some of the fields in ImGui_ImplVulkan_InitInfo, maybe that can be standardized a little better.

ocornut commented 2 years ago

Adding to the above: it would be tempting to "query" info about the main viewport, but we are explicitly trying to steer toward allowing to make the concept of a "main viewport" completely optional so I think it is preferable we find a way to let user configure things.