From 7d9478b774ba59c60c2931cc855007da536aa369 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Aug 2018 00:49:29 -0700 Subject: [PATCH] Fix FlipEx on Windows 7 --- .../video/ffmpeg-renderers/dxva2.cpp | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index bbf80f27..cda8366f 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -460,7 +460,6 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync) D3DPRESENT_PARAMETERS d3dpp = {}; d3dpp.hDeviceWindow = info.info.win.window; - d3dpp.BackBufferCount = 1; d3dpp.Flags = D3DPRESENTFLAG_VIDEO; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; @@ -485,22 +484,10 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync) // to reduce latency by avoiding double v-syncing. d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - // On Windows 7, DWM seems to have a nasty bug where using - // FlipEx causes rendering to be locked to 30 FPS. I'm not - // sure if Windows 8 is affected, but I confirmed Windows 8.1 - // is not. I'm erring on the side of caution and assuming - // Windows 8 is affected. - if (IsWindows8Point1OrGreater()) { - // Use FlipEx mode if DWM is running to increase efficiency - d3dpp.SwapEffect = D3DSWAPEFFECT_FLIPEX; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, - "Using FlipEx swapping with DWM"); - } - else { - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, - "Using discard swapping with DWM"); - } + // D3DSWAPEFFECT_FLIPEX requires at least 2 back buffers to allow us to + // continue while DWM is waiting to render the surface to the display. + d3dpp.SwapEffect = D3DSWAPEFFECT_FLIPEX; + d3dpp.BackBufferCount = 2; SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Windowed mode with DWM running"); @@ -509,6 +496,7 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync) // Uncomposited desktop or full-screen exclusive mode with V-sync enabled // We will enable V-sync in this scenario to avoid tearing. d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + d3dpp.BackBufferCount = 1; SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "V-Sync enabled"); @@ -517,6 +505,7 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync) // Uncomposited desktop or full-screen exclusive mode with V-sync disabled // We will allowing tearing for lowest latency. d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + d3dpp.BackBufferCount = 1; SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "V-Sync disabled in tearing mode");