From f5745b4ab6eb3fb175ac19e7661b978e49217e92 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 10 Nov 2022 14:56:18 -0500 Subject: [PATCH] Support window resize and fullscreen changes on Windows and Linux without validation errors --- neo/sys/DeviceManager_DX12.cpp | 4 +++- neo/sys/DeviceManager_VK.cpp | 4 ++-- neo/sys/sdl/sdl_vkimp.cpp | 4 ++++ neo/sys/win32/win_glimp.cpp | 28 ++++++++++++++-------------- neo/sys/win32/win_wndproc.cpp | 11 ++++++----- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/neo/sys/DeviceManager_DX12.cpp b/neo/sys/DeviceManager_DX12.cpp index 16c39674..581a7c46 100644 --- a/neo/sys/DeviceManager_DX12.cpp +++ b/neo/sys/DeviceManager_DX12.cpp @@ -539,6 +539,8 @@ void DeviceManager_DX12::ResizeSwapChain() void DeviceManager_DX12::BeginFrame() { +/* SRS - This code not needed: framebuffer/swapchain resizing & fullscreen are handled by idRenderBackend::ResizeImages() and DeviceManager::UpdateWindowSize() + DXGI_SWAP_CHAIN_DESC1 newSwapChainDesc; DXGI_SWAP_CHAIN_FULLSCREEN_DESC newFullScreenDesc; if( SUCCEEDED( m_SwapChain->GetDesc1( &newSwapChainDesc ) ) && SUCCEEDED( m_SwapChain->GetFullscreenDesc( &newFullScreenDesc ) ) ) @@ -561,7 +563,7 @@ void DeviceManager_DX12::BeginFrame() BackBufferResized(); } } - +*/ auto bufferIndex = m_SwapChain->GetCurrentBackBufferIndex(); WaitForSingleObject( m_FrameFenceEvents[bufferIndex], INFINITE ); diff --git a/neo/sys/DeviceManager_VK.cpp b/neo/sys/DeviceManager_VK.cpp index 58249ff4..483e4657 100644 --- a/neo/sys/DeviceManager_VK.cpp +++ b/neo/sys/DeviceManager_VK.cpp @@ -1165,7 +1165,7 @@ void DeviceManager_VK::BeginFrame() vk::Fence(), &m_SwapChainIndex ); - assert( res == vk::Result::eSuccess ); + assert( res == vk::Result::eSuccess || res == vk::Result::eSuboptimalKHR ); m_NvrhiDevice->queueWaitForSemaphore( nvrhi::CommandQueue::Graphics, m_PresentSemaphore, 0 ); } @@ -1189,7 +1189,7 @@ void DeviceManager_VK::Present() .setPImageIndices( &m_SwapChainIndex ); const vk::Result res = m_PresentQueue.presentKHR( &info ); - assert( res == vk::Result::eSuccess || res == vk::Result::eErrorOutOfDateKHR ); + assert( res == vk::Result::eSuccess || res == vk::Result::eErrorOutOfDateKHR || res == vk::Result::eSuboptimalKHR ); if( deviceParms.enableDebugRuntime ) { diff --git a/neo/sys/sdl/sdl_vkimp.cpp b/neo/sys/sdl/sdl_vkimp.cpp index b689cc0a..76d1a981 100644 --- a/neo/sys/sdl/sdl_vkimp.cpp +++ b/neo/sys/sdl/sdl_vkimp.cpp @@ -163,6 +163,10 @@ void DeviceManager::UpdateWindowSize( const glimpParms_t& parms ) ResizeSwapChain(); BackBufferResized(); } + else + { + deviceParms.vsyncEnabled = requestedVSync; + } } #endif diff --git a/neo/sys/win32/win_glimp.cpp b/neo/sys/win32/win_glimp.cpp index c3e69b65..181fdb68 100644 --- a/neo/sys/win32/win_glimp.cpp +++ b/neo/sys/win32/win_glimp.cpp @@ -1138,19 +1138,17 @@ bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, c glConfig.isFullscreen = parms.fullScreen; - UpdateWindowSize( parms ); - return true; } -void DeviceManager::UpdateWindowSize( const glimpParms_t& params ) +void DeviceManager::UpdateWindowSize( const glimpParms_t& parms ) { windowVisible = true; - if( int( deviceParms.backBufferWidth ) != params.width || - int( deviceParms.backBufferHeight ) != params.height || + if( int( deviceParms.backBufferWidth ) != parms.width || + int( deviceParms.backBufferHeight ) != parms.height || #if ID_MSAA - int( deviceParms.backBufferSampleCount ) != params.multiSamples || + int( deviceParms.backBufferSampleCount ) != parms.multiSamples || #endif ( deviceParms.vsyncEnabled != requestedVSync && GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) ) { @@ -1158,16 +1156,18 @@ void DeviceManager::UpdateWindowSize( const glimpParms_t& params ) BackBufferResizing(); - deviceParms.backBufferWidth = params.width; - deviceParms.backBufferHeight = params.height; - deviceParms.backBufferSampleCount = params.multiSamples; + deviceParms.backBufferWidth = parms.width; + deviceParms.backBufferHeight = parms.height; + deviceParms.backBufferSampleCount = parms.multiSamples; deviceParms.vsyncEnabled = requestedVSync; ResizeSwapChain(); BackBufferResized(); } - - deviceParms.vsyncEnabled = requestedVSync; + else + { + deviceParms.vsyncEnabled = requestedVSync; + } } /* @@ -1538,11 +1538,11 @@ bool GLimp_SetScreenParms( glimpParms_t parms ) glConfig.isFullscreen = parms.fullScreen; glConfig.pixelAspect = 1.0f; // FIXME: some monitor modes may be distorted - glConfig.isFullscreen = parms.fullScreen; + glConfig.isStereoPixelFormat = parms.stereo; glConfig.nativeScreenWidth = parms.width; glConfig.nativeScreenHeight = parms.height; - - deviceManager->UpdateWindowSize( parms ); + glConfig.displayFrequency = parms.displayHz; + glConfig.multisamples = parms.multiSamples; return true; } diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp index 31ebaa75..2bf10304 100644 --- a/neo/sys/win32/win_wndproc.cpp +++ b/neo/sys/win32/win_wndproc.cpp @@ -180,14 +180,13 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { case WM_WINDOWPOSCHANGED: // RB: FIXME this messes with with the window size in a really bad way -#if 0 - if( renderSystem->IsInitialized() )//&& win32.hDC != NULL ) + // SRS - Needed by ResizeImages() to resize before the start of a frame + // SRS - Aspect ratio constraints are controlled by WIN_Sizing() above + if( renderSystem->IsInitialized() && win32.hDC != NULL ) { RECT rect; if( ::GetClientRect( win32.hWnd, &rect ) ) { - auto originalWidth = glConfig.nativeScreenWidth; - auto originalHeight = glConfig.nativeScreenHeight; if( rect.right > rect.left && rect.bottom > rect.top ) { glConfig.nativeScreenWidth = rect.right - rect.left; @@ -200,10 +199,12 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) r_windowWidth.SetInteger( glConfig.nativeScreenWidth ); r_windowHeight.SetInteger( glConfig.nativeScreenHeight ); } + + // SRS - Inform ImGui that the window size has changed + ImGuiHook::NotifyDisplaySizeChanged( glConfig.nativeScreenWidth, glConfig.nativeScreenHeight ); } } } -#endif break; case WM_MOVE: {