From 24f4582b6f7f57f566418551f9252b8578d2b602 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 19 Jun 2022 19:40:20 -0500 Subject: x11: add --x11-present option With the recent addition of the libxpresent, it should improve frame timings for most users. However, there were known cases of bad behavior (Nvidia) which lead to a construction of a whitelist instead of just enabling this all the time. Since there's no way to predict whatever combination of hardware/drivers/etc. may work correctly, just give users an option to switch the usage of xorg's presentation statistics on/off. The default value, auto, works like before (basically, Mesa drivers and no Nvidia are allowed), but now one can force it on/off if needed. --- DOCS/interface-changes.rst | 1 + DOCS/man/options.rst | 17 +++++++++++++++++ options/options.c | 3 +++ options/options.h | 1 + video/out/x11_common.c | 8 +++++--- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index 4cd93ab6ab..1c3e6496a9 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -42,6 +42,7 @@ Interface changes - `--sub-visibility` no longer has any effect on secondary subtitles - add `film-grain` sub-parameter to `format` video filter - add experimental `--vo=vaapi-wayland` video output driver + - add `--x11-present` for controlling whether to use xorg's present extension --- mpv 0.34.0 --- - deprecate selecting by card number with `--drm-connector`, add `--drm-device` which can be used instead diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index e3aeb4b5bb..59fc79c89e 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3354,6 +3354,23 @@ Window ``never`` asks the window manager to never disable the compositor. +``--x11-present=`` + Whether or not to use presentation statistics from X11's presentation + extension (default: ``auto``). + + mpv asks X11 for present events which it then may use for more accurate + frame presentation. This only has an effect if ``--video-sync=display-...`` + is being used. + + The auto option enumerates XRandr providers for autodetection. If amd, radeon, + intel, or nouveau (the standard x86 Mesa drivers) is found and nvidia is NOT + found, presentation feedback is enabled. Other drivers are not assumed to + work, so they are not enabled automatically. + + ``yes`` or ``no`` can still be passed regardless to enable/disable this + mechanism in case there is good/bad behavior with whatever your combination + of hardware/drivers/etc. happens to be. + Disc Devices ------------ diff --git a/options/options.c b/options/options.c index 6d38af53b4..0b1c58d9a6 100644 --- a/options/options.c +++ b/options/options.c @@ -175,6 +175,8 @@ static const m_option_t mp_vo_opt_list[] = { {"x11-netwm", OPT_CHOICE(x11_netwm, {"auto", 0}, {"no", -1}, {"yes", 1})}, {"x11-bypass-compositor", OPT_CHOICE(x11_bypass_compositor, {"no", 0}, {"yes", 1}, {"fs-only", 2}, {"never", 3})}, + {"x11-present", OPT_CHOICE(x11_present, + {"no", 0}, {"auto", 1}, {"yes", 2})}, #endif #if HAVE_WIN32_DESKTOP {"vo-mmcss-profile", OPT_STRING(mmcss_profile)}, @@ -212,6 +214,7 @@ const struct m_sub_options vo_sub_opts = { .WinID = -1, .window_scale = 1.0, .x11_bypass_compositor = 2, + .x11_present = 1, .mmcss_profile = "Playback", .ontop_level = -1, .timing_offset = 0.050, diff --git a/options/options.h b/options/options.h index 4eb5ef07c7..f38f3b6bfb 100644 --- a/options/options.h +++ b/options/options.h @@ -29,6 +29,7 @@ typedef struct mp_vo_opts { char *appid; int x11_netwm; int x11_bypass_compositor; + int x11_present; int native_keyrepeat; float panscan; diff --git a/video/out/x11_common.c b/video/out/x11_common.c index f041d594ec..054557189f 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -1286,11 +1286,13 @@ void vo_x11_check_events(struct vo *vo) break; case GenericEvent: { XGenericEventCookie *cookie = (XGenericEventCookie *)&Event.xcookie; - if (cookie->extension == x11->present_code && x11->have_present && - x11->has_mesa && !x11->has_nvidia) + if (cookie->extension == x11->present_code && x11->have_present) { + int present = x11->opts->x11_present; + bool use_present = (x11->has_mesa && !x11->has_nvidia && + present) || present == 2; XGetEventData(x11->display, cookie); - if (cookie->evtype == PresentCompleteNotify) { + if (cookie->evtype == PresentCompleteNotify && use_present) { XPresentCompleteNotifyEvent *present_event; present_event = (XPresentCompleteNotifyEvent *)cookie->data; present_update_sync_values(x11->present, present_event->ust, -- cgit v1.2.3