platform/windows: add optional DwmFlush() call to improve Windows capture

Invoke DwmFlush() before acquiring the next frame to alleviate visual stutter
during mouse movement at the cost of constraining the capture rate to the host's
monitor refresh.

Disabled by default; enable via "dwmflush" boolean configuration parameter.
This commit is contained in:
Conn O'Griofa 2022-05-18 18:20:33 +01:00
parent d051b58190
commit 211b25848f
7 changed files with 45 additions and 5 deletions

View File

@ -122,6 +122,7 @@ if(WIN32)
ws2_32
d3d11 dxgi D3DCompiler
setupapi
dwmapi
)
set_source_files_properties(third-party/ViGEmClient/src/ViGEmClient.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE=1;ERROR_INVALID_DEVICE_OBJECT_PARAMETER=650")

View File

@ -333,6 +333,25 @@ Example
3840x1600,
]
dwmflush
^^^^^^^^
Description
Invoke DwmFlush() to sync screen capture to the Windows presentation interval.
.. Caution:: Applies to Windows only. Alleviates visual stuttering during mouse movement, but causes the capture
rate to be limited to the host monitor's currently active refresh rate.
Default
``disabled``
Examples
Windows
.. code-block:: text
dwmflush = enabled
Audio
-----

View File

@ -400,7 +400,18 @@
You can select the video card you want to stream:<br />
The appropriate values can be found using the following command:<br />
tools\dxgi-info.exe<br />
<br />
</div>
</div>
<!--DwmFlush-->
<div class="mb-3" v-if="platform === 'windows'">
<label for="dwmflush" class="form-label">DwmFlush</label>
<select id="dwmflush" class="form-select" v-model="config.dwmflush">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled</option>
</select>
<div class="form-text">
Improves capture latency during mouse movement.<br />
Enabling this may prevent the client's FPS from exceeding the host monitor's active refresh rate.
</div>
</div>
<div class="mb-3" class="config-page" v-if="platform === 'linux'">
@ -832,6 +843,7 @@
this.config.key_rightalt_to_key_win || "disabled";
this.config.gamepad = this.config.gamepad || "x360";
this.config.upnp = this.config.upnp || "disabled";
this.config.dwmflush = this.config.dwmflush || "disabled";
this.config.min_log_level = this.config.min_log_level || 2;
this.config.origin_pin_allowed =
this.config.origin_pin_allowed || "pc";

View File

@ -226,9 +226,10 @@ video_t video {
1,
-1 }, // vt
{}, // encoder
{}, // adapter_name
{}, // output_name
{}, // encoder
{}, // adapter_name
{}, // output_name
false // dwmflush
};
audio_t audio {};
@ -735,6 +736,7 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
string_f(vars, "encoder", video.encoder);
string_f(vars, "adapter_name", video.adapter_name);
string_f(vars, "output_name", video.output_name);
bool_f(vars, "dwmflush", video.dwmflush);
path_f(vars, "pkey", nvhttp.pkey);
path_f(vars, "cert", nvhttp.cert);

View File

@ -44,6 +44,7 @@ struct video_t {
std::string encoder;
std::string adapter_name;
std::string output_name;
bool dwmflush;
};
struct audio_t {

View File

@ -8,6 +8,7 @@
#include <d3d11.h>
#include <d3d11_4.h>
#include <d3dcommon.h>
#include <dwmapi.h>
#include <dxgi.h>
#include <dxgi1_2.h>
@ -172,4 +173,4 @@ public:
};
} // namespace platf::dxgi
#endif
#endif

View File

@ -20,6 +20,10 @@ capture_e duplication_t::next_frame(DXGI_OUTDUPL_FRAME_INFO &frame_info, std::ch
return capture_status;
}
if(config::video.dwmflush) {
DwmFlush();
}
auto status = dup->AcquireNextFrame(timeout.count(), &frame_info, res_p);
switch(status) {