From 9e9fe2a2cf5105c84d2f082342b78b03b87769a4 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 20 Aug 2018 21:17:25 -0700 Subject: [PATCH] Work around DWM bug on Windows 7 causing horrible performance --- .../video/ffmpeg-renderers/dxva2.cpp | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index 07c539c3..e38ed503 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -4,6 +4,10 @@ #include #include + +#define WIN32_LEAN_AND_MEAN +#include +#include #include #include @@ -481,8 +485,22 @@ bool DXVA2Renderer::initializeDevice(SDL_Window* window, bool enableVsync) // to reduce latency by avoiding double v-syncing. d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - // Use FlipEx mode if DWM is running to increase efficiency - d3dpp.SwapEffect = D3DSWAPEFFECT_FLIPEX; + // 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"); + } SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Windowed mode with DWM running");