Commit Graph

25 Commits

Author SHA1 Message Date
Philip Langdale 085f3e31a0 vo: hwdec: Pass the ra_ctx to hwdecs instead of just the ra
We will need the full ra_ctx to be able to look up all the state
required to initialise an ffmpeg vulkan hwcontext, so pass let's
pass the ra_ctx instead of just the ra.
2023-05-28 15:46:05 -07:00
Dudemanguy c1de4bb745 vo_dmabuf_wayland: rewrite around wl_list
vo_dmabuf_wayland worked by allocating entries to a pool and then having
a lot of complex logic dealing with releasing buffers, pending entries,
etc. along with some other not so nice things. Instead, we can rewrite
this logic so that the wl_buffers created by the imported dmabuf is
instead stored in a linked list, wl_list. We can simply append our
buffers to the list when needed and destroy everything at the end. On
every frame, we can check the ids of our surfaces and reuse existing
buffers, so in practice there will only ever be a handful at a time.
Some other small changes were made in an attempt to organize the
vaapi/drmprime code a little better as well.

An important change is to always enforce at least a minimum number of
buffers. Certain formats would not make enough unique buffers, and this
results in flickering/artifacts occuring. The old way to attempt to deal
with this was to clear out all the existing buffers and remake them, but
this gets complicated and also didn't always work. An easy solution to
this is just create more buffers which appears to solve this problem.
The actual number needed is not really based on anything solid, but 8
is a reasonable number to create for the lifetime of a file and it seems
to do the trick.

Additionally, seeking/loading new files can result in flicker artificts
due to buffers being reused when they shouldn't. When that happens, we
flip a bool so all the buffers get destroyed in draw_frame to avoid any
visual glitches.
2023-05-24 21:53:17 +00:00
Harri Nieminen 292a5868cb various: fix typos
Found by codespell
2023-03-28 19:29:44 +00:00
Ray Smith 8a43fc0e9a wayland: use bool type for alpha framebuffer tracking
ra_ctx_opts.want_alpha and vo_wayland_set_opaque_region's alpha
argument are only used as bool but both are ints. Particularly for the
function argument, passing a 0 or 1 is confusing - at first glance it
looks like you're specifying an alpha value of 0 or 1.

Since they're only used as bools, make them bools.
2023-02-28 14:53:32 +00:00
Dudemanguy e2cdc23af0 Revert "vo_dmabuf_wayland: drop support for linux-dmabuf-v2"
This was originally dropped because it was thought to be unneeded at the
time, but at least some devices (rockchip) apparently are still on old
compositors that use linux-dmabuf v2. It's not much code, and for
testing purposes it's good to have around since it's hard to test
drmprime otherwise. Some minor additions are here to support the newly
added vaapi-format mapping in v2 of the protocol.

This reverts commit a5b9d529ee.
2023-02-18 02:21:54 +00:00
Aaron Boxer 49fd6caa43 vo_dmabuf_wayland: reject hw formats not supported by compositor 2023-02-11 00:46:46 +00:00
Aaron Boxer a3340645be vo_dmabuf_wayland: add purgatory list to buffer pool to avoid memory leaks 2023-02-05 23:27:08 +00:00
Aaron Boxer 6803903e0c vo_dmabuf_wayland: ensure buffer pool is cleaned at start of uninit 2023-02-05 23:27:08 +00:00
Aaron Boxer ce6efc782f vo_dmabuf_wayland: simplify buffer pool reset 2023-02-05 23:27:08 +00:00
Aaron Boxer f1f6eaa3de vo_dmabuf_wayland: only resize when a new frame is about to be drawn 2023-02-05 23:27:08 +00:00
Aaron Boxer 881f820fdf vo_dmabuf_wayland: close file handles when surface export fails
file handles may still be opened despite failure
2023-01-28 16:54:48 +01:00
Aaron Boxer e3618002e3 vo_dmabuf_wayland: plug leaking file descriptor from solid buffer pool 2023-01-28 16:54:48 +01:00
Dudemanguy 006ec9ce43 wayland: rewrite geometry and scaling handling
This is in preparation for fractional scaling support. Basically, redo
all the coordinates in wayland so that wl->geometry is equal exactly to
what is being put out to the screen (no extra wl->scaling multiplication
required). The wl->vdparams variable is also eliminated for simplicity.
This changes mpv's behavior on wayland with hidpi scaling but that will
be addressed in more detail with the next commit.
2023-01-24 00:04:39 +00:00
Dudemanguy a5b9d529ee vo_dmabuf_wayland: drop support for linux-dmabuf-v2
The only real reason this was ever supported is because it was
dramatically simpler than v4, so it was put in as an initial
implementation. Later, v4 support was added and we left v2 for
compatibility, but let's just drop it. Compositors all use v4 nowadays,
and v2 is significantly limited (no modifier support for example). It's
better to just remove this dead code for simplicity.
2023-01-12 17:42:35 +00:00
Aaron Boxer 865a159244 vo_dmabuf_wayland: support panscan and panning 2023-01-11 18:10:40 +00:00
Dudemanguy c5af54eb35 vo_dmabuf_wayland: goto err instead of returning
Returning early is clearly wrong. It should use to goto to cleanup after
itself. Also renamed from error_out to err for purely comestic reasons.
2023-01-08 12:19:14 -06: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
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
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
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
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
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 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