Commit Graph

5294 Commits

Author SHA1 Message Date
Niklas Haas e97e0e4d92 vo_gpu_next: don't flush cache on OSD update
Flushing the cache is a hammer-for-a-screw operation, because it nukes
*all* renderer state, including the HDR peak detection state. When
enabling e.g. --hdr-compute-peak, or any other future methods of dynamic
tone mapping, this would lead to bad results (e.g. brightness
fluctuations) whenever the OSD state is updated.

Instead of flushing the cache to force an OSD re-render, instead just
update the frame signature directly whenever its osd_sync value changes.
This accomplishes effectively the same thing but without touching the
HDR state.

This is slightly violating the libplacebo abstraction in a way that
isn't publicly documented. To be on the safe side we could make a carbon
copy of the array before modifying it, but given that this is unlikely
to change upstream I'll probably just end up explicitly documenting it
instead of forcing the copy in mpv.
2022-11-25 02:15:05 +01:00
Niklas Haas e1a04cd8ac lcms: fix validate_3dlut_size_opt
Not only was this function needlessly convoluted, it was also broken -
since it returned a bool value where an error code was expected.
2022-11-21 17:39:37 +01:00
Niklas Haas b9b3342369 lcms: always parse lcms2-related options
Currently, the lcms-related options are only defined when lcms2 is
enabled at build time. However, this causes issues (e.g. segfault) for
vo_gpu_next, which relies on the presence of these options (to forward
them to libplacebo).

(That libplacebo internally depends on lcms2 as well is an
implementation detail - compiling mpv *without* lcms against libplacebo
*with* lcms should be possible in principle)

Fixes: #10891
Closes: #10856
2022-11-21 17:39:37 +01:00
LaserEyess a62f71bfbe vo_dmabuf_wayland: use single-pixel-buffer-v1
The new single-pixel-buffer protocol is designed to optimize the case
for using a solid color as an underlay wl_surface. It works the same as
the wl_shm 1x1 pixel trick currently used, but it allows the compositor
to make optimizations with more certainty than the wl_shm trick.
2022-11-20 19:13:59 +00:00
LaserEyess 303178e645 wlbuf_pool.h: add headers for forward declarations
This was previously implicitly included by the order of headers in
vo_dmabuf_wayland.c, but it is better to make it an explicit and reorder
the headers properly.
2022-11-20 19:13:59 +00:00
Niklas Haas 8327ac3e6d vo_gpu_next: fix undefined behavior on alpha-first formats
When the alpha channel is the first component, this code block gets
skipped by the continue, meaning the check for c==0 never passes.

Fix it by explicitly keeping track of whether bits have been set.
2022-11-19 14:12:24 +01:00
Dudemanguy d3a61cfe98 wayland: also log refresh rate on surface entrance
Never bothered to log this for some reason, but it's pretty convenient
when debugging.
2022-11-18 16:36:21 -06:00
LaserEyess ba20f60add drm: remove legacy API
The legacy DRM API adds some complexity to the DRM code. There
are only 4 drivers that do not support the DRM Atomic API:

1. radeon (early GCN amd cards)
2. gma500 (ancient intel GPUs)
3. ast (ASPEED SoCs)
4. nouveau

Going forward, new DRM drivers will be guaranteed to support the atomic
API so this is a safe removal.
2022-11-16 09:32:55 +01:00
Dudemanguy 6623efb142 wayland: add support for content-type protocol
The content-type protocol allows mpv to send compositor a hint about the
type of content being displayed on its surface so it could potentially
make some sort of optimization. Fundamentally, this is pretty simple but
since this requires a very new wayland-protocols version (1.27), we have
to mess with the build to add a new define and add a bunch of if's in
here. The protocol itself exposes 4 different types of content: none,
photo, video, and game.

To do that, let's add a new option (wayland-content-type) that lets
users control what hint to send to the compossitor. Since the previous
commit adds a VOCTRL that notifies us about the content being displayed,
we can also add an auto value to this option. As you'd expect, the
compositor hint would be set to photo if mpv's core detects an image,
video for other things, and it is set to none for the special case of
forcing a window when there is not a video track. For completion's sake,
game is also allowed as a value for this option, but in practice there
shouldn't be a reason to use that.
2022-11-15 23:18:55 +00:00
Dudemanguy bab85944df player/video: add VOCTRL_CONTENT_TYPE
mpv's core already keeps track of whether or not it thinks a track is an
image. Some VOs (i.e. wayland) would benefit from knowing if what is
currently being displayed is an image or not so add a new VOCTRL that
signals this anytime we load a new file with a VO. Additionally, let's
add a helper enum for signaling the kind of content that is being
displayed. There is now MP_CONTENT_NONE (strictly for force window being
used on a track with no image/video), MP_CONTENT_IMAGE, and
MP_CONTENT_VIDEO. See the next commit for the actual usage of this (with
wayland).
2022-11-15 23:18:55 +00:00
Philip Langdale 25fa52d237 vo: hwdec: remove legacy_names
These were introduced for configuration compatibility in 0.35 but we
don't want to retain them past that point.
2022-11-15 16:33:12 +01:00
Dudemanguy 38a626650a player: add --force-render option
mpv has an internal optimization on a couple of platforms where it will
not render any frames if the window is minimized or hidden. There's at
least once possible use case for wanting to force a render anyway
(screensharing with pipeware) so let's just add a simple switch for
this that always forces mpv to render. Closes #10846.
2022-11-15 15:31:21 +00:00
Dudemanguy 295ceab382 wayland: error out if essential protocol support is missing
Related issue: #10868. While most protocols are in theory optional, a
small amount of them are absolutely essential and nothing will work
without them. We should make sure to error out in those cases and not
try to actually do anything. For wayland support in general,
wl_compositor support is obviously required. If there is no wl_surface,
you can't do anything. Additionally, vo_wlshm quite obviously requires
wl_shm so mark that one as well. vo_dmabuf_wayland needs linux_dmabuf,
viewporter, wl_shm, and wl_subcompositor. In practice, these are all
very standard protocols and shouldn't be missing but the linked issue
above is at least one example where a compositor was stuck on an ancient
version of a wayland interface.
2022-11-15 14:42:02 +00:00
Niklas Haas 33136c276c vo_gpu_next: add tunable shader parameters
This is a very simple but easy way of doing it. Ideally, it would be
nice if we could also add some sort of introspection about shader
parameters at runtime, ideally exposing the entire list of parameters as
a custom property dict. But that is a lot of effort for dubious gain.

It's worth noting that, as currently implemented, re-setting
`glsl-shader-opts` to a new value doesn't reset back previously mutated
values to their defaults.
2022-11-11 13:58:35 +01:00
sfan5 ac3966184b vo_gpu: mark --gamma-factor and --gamma-auto with deprecation warnings
This was forgotten in commit 2207236aaa.
2022-11-10 16:19:37 +01:00
sfan5 175e250038 wayland, x11: fix possibly unsafe bstr usage
In practice this never led to any issues due to implementation
details of bstr_sanitize_utf8_latin1, but there's no guarantee that
a bstr is correctly null-terminated.
2022-11-10 16:19:37 +01:00
Aaron Boxer 00e3c90fb1 vo_dmabuf_wayland: improve error handling exporting VA surface
1. check for all error conditions when calling vaExportSurfaceHandle
2. only clean up valid descriptors
2022-11-07 16:42:01 +00:00
Aaron Boxer 259eda4e2f hwdec_vaapi: only set VADisplay resource if entire init process has succeeded
This resource is used by dmabuf_waland to decide if it should manage
vaapi buffers, so it should not be set if vaapi init has failed
2022-11-07 16:42:01 +00:00
Dudemanguy 2c53fb6a2b gpu/context: properly guard wldmabuf context
This should only be added if the build has dmabuf-wayland enabled. This
fixes #10828.
2022-11-03 17:24:09 -05:00
Niklas Haas 6acb7db9fa vo_gpu_next: set background transparency
Fixes: https://github.com/mpv-player/mpv/issues/10815
2022-11-01 19:09:40 +01:00
Lynne d555ae9571 wayland_common: always zero out presentation context when destroying it
A desync between the feedback and the feedback in the context
still happens when closing a hidden surface.
2022-10-31 20:46:29 -05:00
Dudemanguy 5fa3bca863 wayland: correct braindead comment (no-op)
I was confused in d3a28f12c9 why it
actually even worked, but after not being stupid, it's quite obviously
just a dangling pointer. The reason it only happens with
wp_presentation_feedback is because the object and listener actually
created in frame_callback not the presentation events itself (for vsync
timing reasons). So it is possible to free the object, but not
immediately recreate it again before quitting (unlike with the frame
callback). The actual comment is moved into feedback_presented (which is
first) but as of this commit it doesn't have the NULL setting logic
(that's the next one).
2022-10-31 20:45:56 -05:00
Dudemanguy d3a28f12c9 wayland: hack around presentation_feedback weirdness
964692ad4c added some code to destroy
presentation_feedback we get in the presentation_discarded event. This
is the correct thing to do since the compositor could send us this
instead of feedback_presented. Without that change, mutter could
potentially leak memory on every frame.

Unfortunately, life is not so simple and wlroots and weston act
differently. These compositors only send one presentation_discarded
event if the mpv window is hidden. Not on every single missed frame like
mutter. Now in theory this shouldn't matter, but it also turns out that
mpv attempts to free the presentation feedback twice if you quit it
while it is hidden away (on weston and wlroots compositors only). The
inital wp_presentation_feedback_destroy in feedback_discarded fires, but
then the function goes off again in vo_wayland_uninit because
wl->feedback is apparently not NULL for some reason. Possibly, this is
some race condition but we can't just get rid of what's in
feedback_discarded since mutter needs this line. Instead, just hack it
by explicitly setting wl->feedback to NULL in feedback_discarded after we
destroy the presentation feedback. Some valgrind testing in mutter,
sway, and weston shows that this works correctly on all of those
compositors with various combinations of mpv being visible or not while
quitting. feedback_presented doesn't appear to exhibit this behavior so
we just leave that as-is.
2022-10-30 14:23:55 +00:00
Dudemanguy 667222dffa wayland: free dmabuf_feedback object
666cb91cf1 added dmabuf_feedback, but it
was never actually free'd on uninit. Because this function requires
wayland protocols 1.24, we have to wrap it in an #if. Also throw in some
minor cosmetic changes in here.
2022-10-30 14:23:55 +00:00
Philip Langdale 48bb17549c filters/f_hwtransfer: remove VAAPI <-> Vulkan mapping for now
This mapping isn't actually relevant until we have the Vulkan interop
merged, and it requires a newer version of libavutil than our minimum
requirement. So I'm going to remove it from master and put it in the
interop PR.

Fixes #10813
2022-10-29 18:49:46 -07:00
Dudemanguy f594482451 build: add an additional check for wayland-protocols 1.24
666cb91cf1 added support for v4 of the
dmabuf protocol. This was meant to be optional and the fallback support
for the old v2 (dates back to 2017[0] well before the 1.15
wayland-protocol version we depend on) was maintained. However, v4 added
several new functions and structs that of course aren't defined in old
protocol versions so naturally this breaks the build on those systems.
Since this is just a niche feature and not really critical to overall
wayland support in mpv, just give in and add another check in the build
system and #if out the newer stuff in wayland_common. v4 of linux-dmabuf
depends on wayland protocols 1-24[1], so go ahead and make that our new
check. Fixes #10807.

[0]: a840b3634a
[1]: 8a5cd28a0e
2022-10-29 20:41:20 +00:00
Dudemanguy adb556bf15 vo_dmabuf_wayland: use special ra_ctx_create_by_name
vo_dmabuf_wayland has its own ra and context so it can handle all the
different hwdec correctly. Unfortunately, this API was pretty clearly
designed with vo_gpu/vo_gpu_next in mind and has a lot of concepts that
don't make sense for vo_dmabuf_wayland. We still want to bolt on a
ra_ctx, but instead let's rework the ra_ctx logic a little bit. First,
this introduces a hidden bool within the ra_ctx_fns that is used to hide
the wldmabuf context from users as an option (unlike the other usual
contexts). We also want to make sure that hidden contexts wouldn't be
autoprobed in the usual ra_ctx_create, so we be sure to skip those in
that function. Additionally, let's create a new ra_ctx_create_by_name
function which does exactly what says. It specifically selects a context
based on a passed string. This function has no probing or option logic
is simplified just for what vo_dmabuf_wayland needs. The api/context
validations functions are modified just a little bit to make sure hidden
contexts are skipped and the documentation is updated to remove this
entries. Fixes #10793.
2022-10-28 02:36:46 +00:00
Dudemanguy 31af37f877 vo_dmabuf_wayland: load all hwdecs in preinit
vo_gpu and vo_gpu_next typically load hwdec interops on demand and
vo_dmabuf_wayland naively copied this logic. This is actually wrong
however since draw_frame in the VO always inherently relies on hwdec
being fully loaded. This can lead to a race condition during startup
which happens with --force-window=immediate. Avoid this by simply always
loading all the interops. In the case of vo_dmabuf_wayland, this is not
really a big deal since there's only vaapi and drmprime to load. Also
fixes #10791 (the other half).
2022-10-28 02:36:46 +00:00
Dudemanguy 99699cd7ba wayland: always do a display_roundtrip at the end of init
We really need two roundtrips in the init function. The first one is for
running the registry and then second one is for ensuring the xdg_surface
and other potential wayland objects are configured at least once before
mpv does anything. We've been getting away with only doing the first for
a while via luck, but really we should do at least one more wait on the
compositor. Fixes #10791 (half of it).
2022-10-28 02:36:46 +00:00
Dave Craig 6e274dc8d8 vo_dmabuf_wayland: fix DRM builds with no VAAPI
Building on DRM platform without VAAPI broke because of misuse of
HAVE_VAAPI with #ifdef in place of #if. Also, the hwcontext_drm.h
header is not required for VAAPI builds, only DRM builds.
2022-10-27 18:41:37 +00:00
Jan Ekström bc3e96098d video/out/wayland_common: adjust decoration disagreement log level
Originally, I considered warning once to be useful for figuring
out whether the change in logic regarding resetting requested
mode actually fixed the reported issue or not, but alas not everyone
was happy with that decision. Thus the log level will always be
debug. This enables us to lose one level of indent as well as a
variable, which is always positive.

Additionally, make the message more explicit regarding what could
possibly be implied by the mismatch, as it seems like this was
not always clear.
2022-10-27 19:07:05 +03:00
Jan Ekström e0c4193ee5 video/out/wayland_common: clear decoration request even if compositor disagrees
Otherwise mpv and the compositor can end up in an eternal loop where
mpv requests one mode, and compositor tells that the mode is not
that (and will most likely not change).

Additionally, log these mismatches - first time as a warning, and
later as debug logging.
2022-10-26 22:20:31 +03:00
Jan Ekström f39e56bf5e video/out/wayland_common: don't pass a negative of border flag into ternary
Make it clear that we are passing the original requested border mode
on.
2022-10-26 22:20:31 +03:00
Jan Ekström 2c58ab481b video/out/wayland_common: make decoration state usage explicit
It is verbose, but makes it more explicit that requested_decoration
takes in three values:

* 0: no specific mode requested by mpv
* ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: (!border)
* ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: (border)
2022-10-26 22:20:31 +03:00
Emmanuel Gil Peyrot 666cb91cf1 wayland: bump dmabuf protocol to version 4
Pulled from https://github.com/mpv-player/mpv/pull/10382

The zwp_linux_dmabuf_v1 protocol version 4 provides a file descriptor
containing both formats and modifiers, which makes it possible for the
compositor to import the buffers onto planes using explicit modifiers.

This is an extremely important efficiency improvement, as the 3D
hardware can be left powered off altogether, the vaapi buffer being sent
directly from the video hardware to the display controller.

It could be possible to support zwp_linux_dmabuf_v1 version 3 as well,
but there is no reason beyond compatibility with old stacks.  I would
recommend to ditch version 2 as well, as modifier-less formats aren’t
very useful nowadays.
2022-10-26 18:41:47 +00:00
Aaron Boxer aeb4792cb6 vo_vaapi_wayland: remove, as it is superceded by vo_dmabuf_wayland 2022-10-26 18:41:47 +00:00
Aaron Boxer 7358b9d371 vo_dmabuf_wayland: wayland VO displaying dmabuf buffers
Wayland VO that can display images from either vaapi or drm hwdec

The PR adds the following changes:

1. a context_wldmabuf context with no gl dependencies
2. no-op ra_wldmabuf and dmabuf_interop_wldmabuf objects
   no-op because there is no need to map/unmap the drmprime buffer,
    and there is no need to manage any textures.

Tested on both x86_64 and rk3399 AArch64
2022-10-26 18:41:47 +00:00
Aaron Boxer 964692ad4c wayland: clean wp_presentation_feedback in discard callback to avoid leak 2022-10-26 18:41:47 +00:00
Aaron Boxer fbcd9c140f mp_imgfmt: move DRMPRIME format to end of enum
dmabuf-wayland vo supports both DRMPRIME and VAAPI formats.
If upload filter is needed, we want to try VAAPI hwdec first
since most users will be using VAAPI, and there is a several second
delay when DRMPRIME hwdec is tried and fails.
2022-10-26 18:41:47 +00:00
Philip Langdale 395b37b005 vo_gpu/hwdec: add NULL check for legacy_name 2022-10-22 12:56:18 -07:00
sfan5 42cfed002f hwdec_aimagereader: fix incorrect return values 2022-10-22 15:34:37 +02:00
Philip Langdale 345342f50a hwdec/dmabuf_interop_gl: work-around implicit rgba swizzling
This has been a long standing problem that I think was the root cause
for wm4's vaapi shitlist. As DRM explicit supports all possible rgba
orderings, but OpenGL only guarantees support for 'rgba8', something
has to happen to support import of dmabufs with non-native ordering.

Although undocumented, it appears that somewhere in the import on the
GL side, the ordering is swizzled to rgba - which makes sense as that's
the only way to be able to support importing all the different formats.

But we didn't know this, and we do our own swizzling based on the
original imgfmt - which matches the drm format. So we get double
swizzling and messed up colours.

As there is no way for us to express that the GL swizzle happened to
the rest of mpv, the easiest thing to do is fudge the format to the
natural ordering so the GL doesn't change anything, then our swizzling
will do the right thing in the end.

Note that this change doesn't handle 0rgb and 0bgr because they seem to
be affected by some additional feature/bug that is mangling the
ordering somewhere that equally affects Vulkan interop. That could be a
vaapi driver bug or something going on in ffmpeg.
2022-10-15 09:30:46 -07:00
Philip Langdale 66e30e7f2f hwdec/vaapi: improve probing of supported sw formats
The logic around trying to establish what formats are supported by
vaapi is confusing, and it turns out that we've been doing it wrong.

Up until now, we've been going through the list of decoding profile
endpoints and checking the formats declared in those profiles to build
our list.

However, the set of formats that the vaapi driver can actually support
is potentially a superset of those supported by any given profile
endpoint. This master list is exposed by libavutil via the
av_hwframe_transfer_get_formats() function, and so we should use that
list as our starting point.

Perhaps surprisingly, this change actually removes no code, because we
still want the logic that enumerates endpoints and finds supported
formats for endpoints. We need this because we must have at least one
known sw format to initialise the hwframe_ctx with.

Additionally, while in the general case,
av_hwframe_transfer_get_formats can return different formats depending
on what format you initialise the hwframe_ctx with, I happen to have
read the libavutil code, and it doesn't care, so we just need to call
it once, we know we'll get back all known formats.

In practice, with an Intel vaapi driver, this will result in us
supporting a handful of extra formats for hwuploads - particularly
yuv420p (so no need to convert to nv12 first) and various orderings
of rgb(a).
2022-10-15 09:30:46 -07:00
rcombs dfb5b0c55f vo_gpu_next: fix crash on uninit after startup failure 2022-10-14 15:37:49 +02:00
Philip Langdale 064059e6c3 vo_gpu/hwdec: rename and introduce legacy names for some interops
We've had some annoying names for interops, which we can't simply
rename because that would break config files and command lines. So we
need to put a little more effort in and add a concept of legacy names
that allow us to continue loading them, but with a warning.

The two I'm renaming here are:
* vaapi-egl -> vaapi (vaapi works with Vulkan too)
* drmprime-drm -> drmprime-overlay (actually describes what it does)
* cuda-nvdec -> cuda (cuda interop is not nvdec specific)
2022-10-11 10:07:48 -07:00
odnar-dev d050e350fe x11: fix --on-all-workspaces option
mpv set _NET_WM_DESKTOP to 0xFFFFFFFF, which behaves differently with each window manager.
Instead, set the window property to STICKY, and let the window managers deal with it.
2022-10-11 09:25:26 +02:00
Niklas Haas c96cee2940 vo_gpu_next: vulkan: libplacebo: unify log prefix
The new status quo is simple: all messages coming from libplacebo are
marked "vo/gpu{-next}/libplacebo", regardless of the backend API (vulkan
vs opengl/d3d11).

Messages coming from mpv's internal vulkan code will continue to come
from "vo/gpu{-next}/vulkan", and messages coming from the vo module
itself will be marked "vo/gpu{-next}".

This is significantly better than the old status quo of vulkan messages
coming from "vo/gpu{-next}/vulkan/libplacebo" whereas opengl/d3d11
messages simply came from "vo/gpu{-next}", even when those messages
originated from libplacebo.

(It's worth noting that the the destructor for the log is redundant
because it's attached to the ctx which is freed on uninit anyway)
2022-10-09 21:47:35 +02:00
Dudemanguy bb56554a62 x11: fix a couple of memory leaks
Managed to go completely unnoticed for months (who was the bad person
that introduced these*). Fairly self-explanatory. After getting
ProviderInfo from randr, we need to free it. The other one is pretty bad
because it leaked every frame (ouch). It turns out that you're supposed
to free any event data after you cast a generic event to an
XGenericEventCookie. Free that as well.

*: It was me.
2022-10-08 23:50:55 -05:00
Dudemanguy d2a0791fe8 wayland: correctly handle non-CLOCK_MONOTONIC clocks
The wayland presentation time code currently always assumes that only
CLOCK_MONOTONIC can be used. There is a naive attempt to ignore clocks
other than CLOCK_MONOTONIC, but the logic is actually totally wrong and
the timestamps would be used anyway. Fix this by checking a use_present
bool (similar to use_present in xorg) which is set to true if we receive
a valid clock in the clockid event. Additionally, allow
CLOCK_MONOTONIC_RAW as a valid clockid. In practice, it should be the
same as CLOCK_MONOTONIC for us (ntp/adjustime difference wouldn't
matter). Since this is a linux-specific clock, add a define for it if it
is not found.
2022-10-06 18:08:51 +00:00
Niklas Haas 7f5541fc3c vulkan: remove --vulkan-disable-events
This has had no effect since libplacebo v4.192.0, and was deprecated
upstream a year ago. No deprecation period in mpv is justified by this
being a debug / work-around option.
2022-10-05 16:35:14 +02:00