platform/windows: change dwmflush default, add autodetection
On each re/init, query the active monitor refresh rate via DwmGetCompositionTimingInfo. If the client requested framerate exceeds the host monitor refresh, automatically disable DwmFlush. This avoids the problem by which DwmFlush would constrain the client FPS if the host monitor runs at a lower refresh rate, thus allowing the feature to be enabled by default. If there are other issues caused by DwmFlush for certain systems, it can still be disabled via configuration.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Created by loki on 1/12/20.
|
||||
//
|
||||
|
||||
#include <cmath>
|
||||
#include <codecvt>
|
||||
|
||||
#include "display.h"
|
||||
@@ -20,7 +21,7 @@ capture_e duplication_t::next_frame(DXGI_OUTDUPL_FRAME_INFO &frame_info, std::ch
|
||||
return capture_status;
|
||||
}
|
||||
|
||||
if(config::video.dwmflush) {
|
||||
if(use_dwmflush) {
|
||||
DwmFlush();
|
||||
}
|
||||
|
||||
@@ -217,6 +218,21 @@ int display_base_t::init(int framerate, const std::string &display_name) {
|
||||
<< "Offset : "sv << offset_x << 'x' << offset_y << std::endl
|
||||
<< "Virtual Desktop : "sv << env_width << 'x' << env_height;
|
||||
|
||||
// Enable DwmFlush() only if the current refresh rate can match the client framerate.
|
||||
auto refresh_rate = framerate;
|
||||
DWM_TIMING_INFO timing_info;
|
||||
timing_info.cbSize = sizeof(timing_info);
|
||||
|
||||
status = DwmGetCompositionTimingInfo(NULL, &timing_info);
|
||||
if(FAILED(status)) {
|
||||
BOOST_LOG(warning) << "Failed to detect active refresh rate.";
|
||||
}
|
||||
else {
|
||||
refresh_rate = std::round((double)timing_info.rateRefresh.uiNumerator / (double)timing_info.rateRefresh.uiDenominator);
|
||||
}
|
||||
|
||||
dup.use_dwmflush = config::video.dwmflush && !(framerate > refresh_rate) ? true : false;
|
||||
|
||||
// Bump up thread priority
|
||||
{
|
||||
const DWORD flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY;
|
||||
|
||||
Reference in New Issue
Block a user