From df3d007e0a83c31d9e1738993684cb7806f5d8df Mon Sep 17 00:00:00 2001 From: David Maas Date: Wed, 21 Jul 2021 16:59:34 -0500 Subject: [PATCH 1/2] Disabled DXGI window management features for swap chains owned by the backend. --- backends/imgui_impl_dx10.cpp | 1 + backends/imgui_impl_dx11.cpp | 1 + backends/imgui_impl_dx12.cpp | 2 ++ docs/CHANGELOG.txt | 1 + examples/example_sdl_directx11/main.cpp | 6 ++++++ examples/example_win32_directx10/main.cpp | 6 ++++++ examples/example_win32_directx11/main.cpp | 6 ++++++ 7 files changed, 23 insertions(+) diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp index 671e400524f3..a031d4a600fe 100644 --- a/backends/imgui_impl_dx10.cpp +++ b/backends/imgui_impl_dx10.cpp @@ -624,6 +624,7 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport) IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL); bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain); + bd->pFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); // Create the render target if (vd->SwapChain) diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp index e14b0ce3a955..b369d33d2507 100644 --- a/backends/imgui_impl_dx11.cpp +++ b/backends/imgui_impl_dx11.cpp @@ -641,6 +641,7 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL); bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain); + bd->pFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); // Create the render target if (vd->SwapChain) diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index e16f82b21e17..17e3300bbbaa 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -898,6 +898,8 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport) IDXGISwapChain1* swap_chain = NULL; res = dxgi_factory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain); IM_ASSERT(res == S_OK); + res = dxgi_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + IM_ASSERT(res == S_OK); dxgi_factory->Release(); diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c2d3484ab657..5869da08d281 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -181,6 +181,7 @@ Docking+Viewports Branch: - Viewports: Fix popup/tooltip created without a parent window from being given a ParentViewportId value from the implicit/fallback window. (#4236, #2409) - Backends: Vulkan: Fix the use of the incorrect fence for secondary viewports. (#4208) [@FunMiles] +- Examples: Disabled DXGI window management features (such as Alt+Enter fullscreen) for DirectX 10/11 samples. (#4350) [@PathogenDavid] ----------------------------------------------------------------------- diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index ac45b32dc55c..ff083dc2ca50 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -223,6 +223,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) return false; + // Disable DXGI's window management features + // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + IDXGIFactory* pSwapChainFactory; + if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + CreateRenderTarget(); return true; } diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index 33bad3872d8b..fd2abb94204b 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -206,6 +206,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK) return false; + // Disable DXGI's window management features + // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + IDXGIFactory* pSwapChainFactory; + if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + CreateRenderTarget(); return true; } diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index d6378d804101..9d35adf59157 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -214,6 +214,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) return false; + // Disable DXGI's window management features + // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + IDXGIFactory* pSwapChainFactory; + if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + CreateRenderTarget(); return true; } From 6f2450d95253d7ea70cc3bacd76e1ddedafe4767 Mon Sep 17 00:00:00 2001 From: David Maas Date: Thu, 22 Jul 2021 14:14:13 -0500 Subject: [PATCH 2/2] Tweaked comments and changelog entry to clarify why DXGI window transitions are disabled. Simplified MakeWindowAssociation calls in examples. --- docs/CHANGELOG.txt | 3 ++- examples/example_sdl_directx11/main.cpp | 7 ++++--- examples/example_win32_directx10/main.cpp | 7 ++++--- examples/example_win32_directx11/main.cpp | 7 ++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5869da08d281..c085d7e6e894 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -181,7 +181,8 @@ Docking+Viewports Branch: - Viewports: Fix popup/tooltip created without a parent window from being given a ParentViewportId value from the implicit/fallback window. (#4236, #2409) - Backends: Vulkan: Fix the use of the incorrect fence for secondary viewports. (#4208) [@FunMiles] -- Examples: Disabled DXGI window management features (such as Alt+Enter fullscreen) for DirectX 10/11 samples. (#4350) [@PathogenDavid] +- Examples: Disabled DXGI's automatic alt+enter fullscreen for DirectX 10/11 samples. Applications are free to + leave this enabled, but it does not work properly with multiple viewports. (#4350) [@PathogenDavid] ----------------------------------------------------------------------- diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index ff083dc2ca50..451500e6ed05 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -223,11 +223,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) return false; - // Disable DXGI's window management features - // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + // Disable DXGI's automatic alt+enter fullscreen + // You are free to leave this enabled, but it will not work properly with multiple viewports + // For DirectX 11, this must be done for all windows associated with the device IDXGIFactory* pSwapChainFactory; if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) - pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER); CreateRenderTarget(); return true; diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index fd2abb94204b..d234cc3e7161 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -206,11 +206,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK) return false; - // Disable DXGI's window management features - // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + // Disable DXGI's window management features (namely automatic alt+enter fullscreen) + // You are free to leave this enabled, but it will not work properly with multiple viewports + // For DirectX 10, this must be done for all windows associated with the device IDXGIFactory* pSwapChainFactory; if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) - pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES); CreateRenderTarget(); return true; diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 9d35adf59157..10dc0e204f5c 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -214,11 +214,12 @@ bool CreateDeviceD3D(HWND hWnd) if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) return false; - // Disable DXGI's window management features - // (This doesn't play nice with multiple viewports and must be done on all windows associated with the device.) + // Disable DXGI's automatic alt+enter fullscreen + // You are free to leave this enabled, but it will not work properly with multiple viewports + // For DirectX 11, this must be done for all windows associated with the device IDXGIFactory* pSwapChainFactory; if (SUCCEEDED(g_pSwapChain->GetParent(IID_PPV_ARGS(&pSwapChainFactory)))) - pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_PRINT_SCREEN | DXGI_MWA_NO_WINDOW_CHANGES); + pSwapChainFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER); CreateRenderTarget(); return true;