aboutsummaryrefslogtreecommitdiff
path: root/backend/drm/atomic.c
AgeCommit message (Collapse)Author
2023-07-07Use struct initializers instead of memset()Simon Ser
This is a bit more type-safe.
2023-06-30backend/drm: handle output layer damageSimon Ser
2023-06-12backend/drm: clip FB damageSimon Ser
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-02-20backend/drm: add libliftoff interfaceSimon Ser
2023-01-31backend/drm: set "max bpc" property based on pixel formatSimon Ser
Since 1d581656c756 ("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
2022-12-07backend/drm: store pending FB in stateSimon Ser
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-07backend/drm: use separate field to store pending cursor FBSimon Ser
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-07backend/drm: pass fb as arg in set_plane_props()Simon Ser
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-07backend/drm: stop using goto in set_plane_props()Simon Ser
We only have one error code-path, no need for goto here.
2022-11-11backend: remove const casts for pixman_region32_tSimon Ser
Pixman 0.42.0 has constified APIs for pixman_region32_t. We no longer need the casts.
2022-09-16Only set max_bpc when full modesetting is being done.vanfanel
2022-08-30output: fail commits if adaptive sync cannot be enabledSimon Ser
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-06-19backend/drm: set "max bpc" to the maxSimon Ser
"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-07backend/drm: unconditionally set "content type" to graphicsSimon Ser
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-01backend/drm: make commits without a buffer blockingSimon Ser
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-05-31backend/drm: improve atomic commit flag loggingSimon Ser
We weren't logging all of the flags, which made debugging more difficult.
2021-10-29backend/drm: avoid creating empty FB_DAMAGE_CLIPS propSimon Ser
drmModeCreatePropertyBlob cannot create zero-sized blobs, that fails with EINVAL. Closes: https://github.com/swaywm/wlroots/issues/3297
2021-09-07backend/drm: introduce wlr_drm_connector_stateSimon Ser
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-08-25backend/drm: introduce wlr_drm_bo_handle_tableSimon Ser
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]: https://gitlab.freedesktop.org/mesa/drm/-/blob/1a4c0ec9aea13211997f982715fe5ffcf19dd067/amdgpu/handle_table.c
2021-08-18backend/drm: add support for FB_DAMAGE_CLIPSSimon Ser
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-07-09backend/drm: remove backend arg from wlr_drm_interface.crtc_commitSimon Ser
The callee can just get it from the wlr_drm_connector.
2021-07-09backend/drm: add test_only arg to wlr_drm_interface.crtc_commitSimon Ser
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-04-29backend/drm: remove wlr_drm_crtc_state.modeSimon Ser
Replace it with drm_connector_state_mode, which computes the mode from the wlr_output_state to be applied.
2021-04-29backend/drm: remove wlr_drm_crtc_state.activeSimon Ser
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-29backend/drm: remove wlr_drm_crtc.pending_modesetSimon Ser
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-29backend/drm: take wlr_output_state as arg in crtc_commitSimon Ser
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-06backend/drm: downgrade test-only commit failure log levelSimon Ser
Let's not clutter the logs with error messages when a test-only atomic commit fails.
2021-04-06backend/drm: don't set NONBLOCK with TEST_ONLYSimon Ser
The kernel ignores NONBLOCK when TEST_ONLY is set. Let's just not set it, to make it clear it's unused.
2021-01-10backend/drm: stop using surface size for BOSimon Ser
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-10backend/drm: make wlr_drm_plane.{pending,queued,current}_fb pointersSimon Ser
This will be useful once we start re-using wlr_drm_fb.
2020-12-24backend/drm: use connector log helpers in atomic backendSimon Ser
2020-12-22backend/drm: remove drm_fb_acquireSimon Ser
Instead, import the buffer into GBM and KMS in drm_fb_import. Also move the multi-GPU copy there if necessary.
2020-12-22backend/drm: make drm_fb_acquire return a FB IDSimon Ser
2020-12-18backend/drm: introduce wlr_drm_connector.nameSimon Ser
The DRM backend is a little special when it comes to wlr_outputs: the wlr_drm_connectors are long-lived and are created even when no screen is connected. A wlr_drm_connector only advertises a wlr_output to the compositor when a screen is connected. As such, most of wlr_output's state is invalid when the connector is disconnected. We want to stop using wlr_output state on disconnected connectors. Introduce wlr_drm_connector.name which is always valid regardless of the connector status to avoid reading wlr_output.name when disconnected.
2020-12-15backend/drm: add wlr_drm_connector.backendSimon Ser
This allows the DRM code to have direct access to the wlr_drm_backend without having to go through an upcast via get_drm_backend_from_backend.
2020-06-01backend/drm: make adaptive_sync atomicSimon Ser
Stop using drmModeObjectSetProperty, set the property in the crtc_commit function instead.
2020-05-27backend/drm: don't set cursor if off-screenSimon Ser
Closes: https://github.com/swaywm/wlroots/issues/2216
2020-05-26backend/drm: introduce pending and current CRTC stateSimon Ser
Previously, we only had the pending state (crtc->pending, crtc->mode and crtc->active). This causes issues when a commit fails: the pending state is left as-is, and the next commit may read stale data from it. This will also cause issues when implementing test-only commits: we need to rollback the pending CRTC state after a test-only commit. Introduce separate pending and current CRTC states. Properly update the current state after a commit.
2020-05-26backend/drm: rollback atomic blobsSimon Ser
If the atomic commit fails or is test-only, rollback wlr_drm_crtc.{mode_id,gamma_lut} blob IDs to their previous value. This prevents the next commits from failing or applying test-only state.
2020-05-14backend/drm: fix atomic commits when the GAMMA_LUT prop is missingSimon Ser
We already have the logic to fallback to the legacy interface above. We just need to avoid calling atomic_add with a zero prop ID. Closes: https://github.com/swaywm/wlroots/issues/2187
2020-05-14output: make wlr_output_set_gamma atomicSimon Ser
wlr_output_set_gamma is now double-buffered and applies the gamma LUT on the next output commit.
2020-05-12backend/drm: print error in set_plane_propsSimon Ser
This makes it easier to understand which plane failed.
2020-05-10backend/drm: simplify atomic commit logicSimon Ser
We don't need a per-CRTC atomic request anymore. Let's make the request per-commit so that it's easier to debug. This is also groundwork for supporting wlr_output_test properly.
2020-05-10backend/drm: GAMMA_LUT_SIZE isn't atomicSimon Ser
GAMMA_LUT_SIZE isn't an atomic property. It can be used with the legacy interface too. So we can unify both codepaths and remove wlr_drm_interface.crtc_get_gamma_size. It's no guaranteed to exist though, so we still need to keep the fallback.
2020-05-09backend/drm: remove crtc_set_cursor from interfaceSimon Ser
2020-05-09backend/drm: remove conn_enable from interfaceSimon Ser
Use crtc_commit instead.
2020-05-09backend/drm: rename crtc_pageflip to crtc_commitSimon Ser
Also add a flags argument. The commit function will also be used for disabling the CRTC.
2020-05-09backend/drm: apply gamma LUT on page-flipSimon Ser
2020-05-09backend/drm: remove mode argument to crtc_pageflipSimon Ser
Add a new wlr_drm_crtc.pending bitfield which keeps track of pending output changes. More fields will be added in the future (e.g. active, gamma).
2020-05-09backend/drm: remove wlr_drm_interface.crtc_move_cursorSimon Ser
Instead, make the legacy backend call drmModeMoveCursor on page-flip.