Commit Graph

98 Commits

Author SHA1 Message Date
Ian Forbes e3bd318547 drm/backend: add support for cursor hotspots
Enables DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT and sets the cursor hotspots on the
cursor plane so virtualized drivers can accelerate mouse movement.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3776
2024-03-22 13:54:18 -05:00
Kirill Primak 71be993982 backend/drm: set adaptive_sync_status again
Fixes: d7d974ae30
2024-03-15 10:39:05 +03:00
Simon Ser d41b5efc65 backend/drm: fix adaptive sync no-op changes
When a compositors submits a wlr_output_state with
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED set and
adaptive_sync_enabled = false on an output which doesn't support
adaptive sync, we'd fail the commit. Fix this.

This bug was previously hidden because wlr_output_commit() drops
no-op changes from wlr_output_state.committed.
2024-03-14 22:03:10 +00:00
Simon Ser 805807fd5b backend/drm: add infrastructure for device-wide commits 2024-03-14 22:03:10 +00:00
Simon Ser 4636f8c407 backend/drm: track pending atomic state in wlr_drm_connector_state
This centralizes logic common for both the atomic and libliftoff
backends. Additionally, a struct will make it easier to implement
multi-connector commits (since it can be stored in an array).
2024-03-14 22:03:10 +00:00
Simon Ser d7d974ae30 backend/drm: drop VRR debug message
These weren't super helpful and will get in our way for
multi-connector commits.
2024-03-14 22:03:10 +00:00
Simon Ser 16b42bf65b backend/drm: track cursor FB in wlr_drm_connector_state
Use the same logic for cursor FBs as we currently use for primary
FBs. This also fixes the same bug as [1] but in a different, more
robust way.

The new logic integrates better with atomic and will be required
anyways in the future when set_cursor will be superseded by a better
API.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4577
2024-03-04 11:26:20 +01:00
Simon Ser 0d9ffef774 backend/drm: don't destroy previous DRM master blobs
On startup, we fetch the previous MODE_ID blob ID so that
compositors can keep using the previous mode if they want to.
However, that blob doesn't belong to us, it belongs to the
previous DRM master. As a result, we get an error when trying to
destroy it.

Fix this by tracking whether the blob belongs to us or not.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3811
2024-02-21 15:10:44 +00:00
Simon Ser 842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Simon Ser 505175e56f backend/drm: atomically reset state after VT switch
Allows the KMS driver to parallelize the modesets, so should be
faster than going through each CRTC one by one.
2024-02-14 19:13:23 +01:00
Simon Ser 9a685cefa9 backend/drm: add destroy_blob()
Centralizes the logic to destroy a DRM blob: check whether it's
zero, and print a nice error message.
2024-02-14 17:13:25 +01:00
Simon Ser 741aaa3f76 backend/drm: drop wlr_drm_backend arg from create_mode_blob()
No need for this, the backend can be grabbed from the connector.
2024-02-14 17:13:25 +01:00
Simon Ser 260dbdf704 backend/drm: split wlr_drm_fb related functions into separate file 2023-11-30 14:44:46 +00:00
Simon Ser 8c44e86077 backend/drm: add wlr_drm_connector_state.nonblock
Instead of having this condition checked in multiple places,
centralize it so that they don't go out-of-sync.
2023-11-19 15:32:30 +01:00
Simon Ser 3b53d1cbf1 backend/drm: introduce page-flip tracking struct
Introduce a per-page-flip tracking struct passed to the kernel
when we request a page-flip event for an atomic commit. The kernel
will pass us back this pointer when delivering the event.

This eliminates any risk of mixing up events together. In particular,
if two events are pending, or if the CRTC of a connector is swapped,
we no longer blow up in the page-flip event handler.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3753
2023-11-17 16:59:04 +00:00
Simon Ser b82a53a918 Revert "backend/drm: Automatic non-blocking commits"
This reverts commit 45ba35719e.

Sadly, this causes regressions on amdgpu [1] and even with these
fixed, there are fundamental issues with non-blocking modesets [2].

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3745
[2]: https://oftc.irclog.whitequark.org/dri-devel/2023-10-11#1697031838-1697036920;
2023-10-12 16:31:33 +00:00
Kenny Levinsen 45ba35719e backend/drm: Automatic non-blocking commits
We currently only perform non-blocking commits for non-modeset commits
with a buffer attached.

Perform non-blocking commits whenever there is no pending pageflip
event. If a non-blocking modeset commit fails, which can happen if the
driver implicitly added more CRTCs to the commit that we did not know we
had to wait for, retry with a blocking commit.

References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2239
2023-10-10 12:44:59 +00:00
Alexander Orzechowski 1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Simon Ser 7a9f8d8d6b Use struct initializers instead of memset()
This is a bit more type-safe.
2023-07-07 17:31:11 +02:00
Simon Ser aa1055134d backend/drm: handle output layer damage 2023-06-30 04:31:50 +00:00
Simon Ser 4339c37f99 backend/drm: clip FB damage
The kernel complains when the damage exceeds the FB bounds:

    [73850.448326] i915 0000:00:02.0: [drm:drm_atomic_check_only] [PLANE:31:plane 1A] invalid damage clip 0 0 2147483647 2147483647

Make the DRM backend behave like the Wayland one and allow compositors
to damage (0, 0, INT32_MAX, INT32_MAX) to repaint everything without
needing to know the exact buffer size.

Closes: https://github.com/swaywm/sway/issues/7632
2023-06-12 20:38:03 +00:00
Simon Ser 9d43e7e4d6 backend/drm: add libliftoff interface 2023-02-20 18:38:57 +01:00
Simon Ser d36dd96e8d backend/drm: set "max bpc" property based on pixel format
Since 1d581656c7 ("backend/drm: set "max bpc" to the max") we
set the "max bpc" property to the maximum value. The kernel driver
is supposed to clamp this value depending on hardware capabilities.

All kernel drivers lower the value depending on the GPU capabilities.
However, none of the drivers lower the value depending on the DP-MST
link capabilities. Thus, enabling a 4k@60Hz mode can fail on some
DP-MST setups due to the "max bpc" property.

Additionally, it's not a good idea to unconditionally set "max bpc"
to the max. A high bpc consumes more lanes and more clock speed,
which means higher power consumption and the busy lanes cannot be
used for something else (e.g. other data transfers on a USB-C cable).

For now, let's tie the "max bpc" to the pixel format of the buffer.
Introduce a heuristic to make "high bit-depth buffer" a synonym of
"I want the best quality".

This is not perfect: a "max bpc" higher than 8 might be desirable
for pixel formats with a color depth of 8 bits, for instance when
the color management KMS properties are used. But we don't really
support that yet, so let's leave this for later.

Closes: https://github.com/swaywm/sway/issues/7367
2023-01-31 09:32:11 +00:00
Simon Ser 037b21647b backend/drm: store pending FB in state
Instead of having a pending_fb field on the struct wlr_drm_plane,
move it to struct wlr_drm_connector_state. That way, there's no
risk having a stale pending FB around: the state doesn't survive
across tests and commits.

The cursor is a special case because it's disconnected from the
atomic state: the wlr_backend_impl.set_cursor hook sets the cursor
for the next commit. Move the field to
wlr_drm_connector.cursor_pending_fb.
2022-12-07 17:45:59 +01:00
Simon Ser ae61cd6bfb backend/drm: use separate field to store pending cursor FB
We'll move the pending primary FB into the connector state in the
next commit, dropping wlr_drm_plane.pending_fb in the process.
Introduce a dedicated field for the cursor, which has to be managed
in a special way due to our set_cursor API.
2022-12-07 17:44:51 +01:00
Simon Ser 602f0d3be5 backend/drm: pass fb as arg in set_plane_props()
plane_get_next_fb() will go away in subsequent commits. Primary and
cursor will differ with the new logic. Let's prepare for this.
2022-12-07 17:44:51 +01:00
Simon Ser bc2d2e853b backend/drm: stop using goto in set_plane_props()
We only have one error code-path, no need for goto here.
2022-12-07 17:44:51 +01:00
Simon Ser feb5691240 backend: remove const casts for pixman_region32_t
Pixman 0.42.0 has constified APIs for pixman_region32_t. We no longer
need the casts.
2022-11-11 23:11:17 +00:00
vanfanel 4ffc97d134 Only set max_bpc when full modesetting is being done. 2022-09-16 14:15:58 +00:00
Simon Ser 8c70245d5f output: fail commits if adaptive sync cannot be enabled
Previously, adaptive sync was just a hint and wouldn't make any
atomic commit fail if the backend didn't support it. The main reason
is wlr_output_test wasn't supported at the time.

Now that we have a way for compositors to test whether a change can
work, let's remove the exception for adaptive sync and convert it to
a regular output state field.
2022-08-30 17:53:50 +00:00
Simon Ser 1d581656c7 backend/drm: set "max bpc" to the max
"max bpc" is a maximum value, the driver is free to choose a
smaller value depending on the bandwidth available.

Some faulty monitors misbehave with higher bpc values. We'll add
a workaround if users get hit by these in practice.

References: https://gitlab.freedesktop.org/wayland/weston/-/issues/612
2022-06-19 16:55:36 +00:00
Simon Ser 1b27d537d1 backend/drm: unconditionally set "content type" to graphics
CTA-861-G says that "graphics" is used to indicate non-analog (ie,
digital) content. With that bit set, the sink should turn off analog
reconstruction and other related filtering.
2022-06-07 13:21:21 +00:00
Simon Ser acc6d94db0 backend/drm: make commits without a buffer blocking
The wlr_output API requires compositors to wait for wlr_output.frame
before submitting a new buffer. However, compositors can perform a
commit which doesn't involve a buffer anytime.

If the commit is a modeset, we set DRM_MODE_ATOMIC_ALLOW_MODESET and
block until the commit is done. If it isn't, we currently always
perform a non-blocking commit. This is an issue because a previous
page-flip might still be in flight kernel-side, returning EBUSY.

Fix this by using blocking commits when a buffer isn't submitted by
the compositor.

Closes: https://github.com/swaywm/sway/issues/6962
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/2239
2022-06-01 21:16:02 +02:00
Simon Ser 2563b79dc2 backend/drm: improve atomic commit flag logging
We weren't logging all of the flags, which made debugging more
difficult.
2022-05-31 09:31:16 +02:00
Simon Ser 83090de034 backend/drm: avoid creating empty FB_DAMAGE_CLIPS prop
drmModeCreatePropertyBlob cannot create zero-sized blobs, that
fails with EINVAL.

Closes: https://github.com/swaywm/wlroots/issues/3297
2021-10-29 15:03:17 +02:00
Simon Ser 3c74bd0c91 backend/drm: introduce wlr_drm_connector_state
Previously, we were copying wlr_output_state on the stack and
patching it up to be guaranteed to have a proper drmModeModeInfo
stored in it (and not a custom mode). Also, we had a bunch of
helpers deriving DRM-specific information from the generic
wlr_output_state.

Copying the wlr_output_state worked fine so far, but with output
layers we'll be getting a wl_list in there. An empty wl_list stores
two pointers to itself, copying it on the stack blindly results in
infinite loops in wl_list_for_each.

To fix this, rework our DRM backend to stop copying wlr_output_state,
instead add a new struct wlr_drm_connector_state which holds both
the wlr_output_state and additional DRM-specific information.
2021-09-07 11:18:18 +02:00
Simon Ser 5dfaf5ea9c backend/drm: introduce wlr_drm_bo_handle_table
Using GBM to import DRM dumb buffers tends to not work well. By
using GBM we're calling some driver-specific functions in Mesa.
These functions check whether Mesa can work with the buffer.
Sometimes Mesa has requirements which differ from DRM dumb buffers
and the GBM import will fail (e.g. on amdgpu).

Instead, drop GBM and use drmPrimeFDToHandle directly. But there's
a twist: BO handles are not ref'counted by the kernel and need to
be ref'counted in user-space [1]. libdrm usually performs this
bookkeeping and is used under-the-hood by Mesa.

We can't re-use libdrm for this task without using driver-specific
APIs. So let's just re-implement the ref'counting logic in wlroots.
The wlroots implementation is inspired from amdgpu's in libdrm [2].

Closes: https://github.com/swaywm/wlroots/issues/2916

[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
[2]: 1a4c0ec9ae/amdgpu/handle_table.c
2021-08-25 10:05:37 -04:00
Simon Ser 46c42e55c6 backend/drm: add support for FB_DAMAGE_CLIPS
This allows the kernel to access our buffer damage. Some drivers
can take advantage of this, e.g. for PSR2 panels (Panel Self
Refresh) or for transfer over USB.

Closes: https://github.com/swaywm/wlroots/issues/1267
2021-08-18 20:59:25 +02:00
Simon Ser f67cfb2ce2 backend/drm: remove backend arg from wlr_drm_interface.crtc_commit
The callee can just get it from the wlr_drm_connector.
2021-07-09 15:31:19 -04:00
Simon Ser 017555651b backend/drm: add test_only arg to wlr_drm_interface.crtc_commit
Right now callers of drm_crtc_commit need to check whether the
interface is legacy or atomic before passing the TEST_ONLY flag.
Additionally, the fallbacks for legacy are in-place in the common
code.

Add a test_only arg to the crtc_commit hook. This way, there's no
risk to pass atomic-only flags to the legacy function (add an assert
to ensure this) and all of the legacy-specific logic can be put back
into legacy.c (done in next commit).
2021-07-09 15:31:19 -04:00
Simon Ser 31082a0554 backend/drm: remove wlr_drm_crtc_state.mode
Replace it with drm_connector_state_mode, which computes the mode
from the wlr_output_state to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser dfea0ff31d backend/drm: remove wlr_drm_crtc_state.active
Replace it with drm_connector_state_active, which figures out
whether the connector is active depending on the wlr_output_state
to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser 485ecc11a6 backend/drm: remove wlr_drm_crtc.pending_modeset
Replace it with a new drm_connector_state_is_modeset function that
decides whether a modeset is necessary directly from the
wlr_output_state which is going to be applied.
2021-04-29 19:51:57 +02:00
Simon Ser 8f90d7f8f5 backend/drm: take wlr_output_state as arg in crtc_commit
Stop assuming that the state to be applied is in output->pending in
crtc_commit. This will allow us to remove ephemeral fields in
wlr_drm_crtc, which are used scratch fields to stash temporary
per-commit data.
2021-04-29 19:51:57 +02:00
Simon Ser 7efc2d05b7 backend/drm: downgrade test-only commit failure log level
Let's not clutter the logs with error messages when a test-only
atomic commit fails.
2021-04-06 20:35:15 +02:00
Simon Ser 5088e25eaf backend/drm: don't set NONBLOCK with TEST_ONLY
The kernel ignores NONBLOCK when TEST_ONLY is set. Let's just not
set it, to make it clear it's unused.
2021-04-06 20:35:15 +02:00
Simon Ser c94728b53a
backend/drm: stop using surface size for BO
Stop using wlr_drm_surface.{width,height} to figure out the size of a
gbm_bo. In the future we'll stop using wlr_drm_plane.surf, so these will
be zero. Instead, rely on gbm_bo_get_{width,height}.
2021-01-10 11:24:44 +01:00
Simon Ser 5b1b43c68c backend/drm: make wlr_drm_plane.{pending,queued,current}_fb pointers
This will be useful once we start re-using wlr_drm_fb.
2021-01-10 11:24:35 +01:00
Simon Ser 17dd4c9e9a
backend/drm: use connector log helpers in atomic backend 2020-12-24 17:55:45 +01:00
Simon Ser d3bcd63a40 backend/drm: remove drm_fb_acquire
Instead, import the buffer into GBM and KMS in drm_fb_import. Also move
the multi-GPU copy there if necessary.
2020-12-22 15:53:10 +01:00