aboutsummaryrefslogtreecommitdiff
path: root/backend/drm/backend.c
AgeCommit message (Collapse)Author
2023-05-11wlr_drm_format_set: Store formats on arrayAlexander Orzechowski
2023-01-18backend/drm: disable all CRTCs after VT switchSimon Ser
When the user switches away from the VT where wlroots is running, the new DRM master may mutate the KMS state in an arbitrary manner. For instance, let's say wlroots uses the following connector/CRTC mapping: - CRTC 42 drives connector DP-1 - CRTC 43 drives connector DP-2 Then the new DRM master may swap the mapping like so: - CRTC 42 drives connector DP-2 - CRTC 43 drives connector DP-1 wlroots needs to restore its own state when the user switches back. Some state is attached to wlr_drm_crtc (e.g. current FB), so reading back and adopting the CRTC/connector mapping left by the previous DRM master would be complicated (this was the source of other bugs in the past, see [1]). With the previous logic, wlroots merely tries to restore the state of each connector one after the other. This fails in the scenario described above: the kernel refuses to use CRTC 42 for DP-1, because that CRTC is already in-use for DP-2. Unfortunately with the legacy uAPI it's not possible to restore the state in one go. We need to support both legacy and atomic uAPIs, so let's fix the bug for the legacy uAPI first, and then improve the situation for the atomic uAPI as a second step [2]. We need to disable the CRTCs we're going to switch the connectors for. This sounds complicated, so let's just disable all CRTCs to simplify. This causes a black screen because of the on/off modesets, but makes VT switch much more reliable, so I'll take it. [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/commit/c6d8a11d2c438d514473b1cbe20e5550e7227472 [2]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3794 Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3342
2022-12-13backend/drm: rename wlr_drm_backend.outputs to connectorsSimon Ser
This list contains wlr_drm_connector entries, and there is no guarantee that the wlr_output fields are initialized.
2022-11-11backend/drm: ensure disconnected outputs are disabled after VT switchSimon Ser
The following situation can be dangerous: - Output DP-1 is plugged in, compositor enables it. - User VT switches away. - User unplugs DP-1. - User VT switches back. - scan_drm_connectors() figures out the output is now disconnected, uninitializes the struct wlr_output. - The loop restoring previous output state in handle_session_active() accesses the struct wlr_output to figure out what to restore. By chance, we zero out the struct wlr_output after uninitializing it, so enabled and current_mode will always be zero. But let's make sure we handle this case explicitly, to remind future readers that it exists and make the code less fragile.
2022-11-08Revert "backend/drm: fetch EDID manufacturer from udev_hwdb"Simon Ser
This reverts commit e646d882cf4949d290fff2ba3b7ae4c124f6f13d. This commit has added a dependency on udev_hwdb. This API isn't available on all platforms (e.g. FreeBSD), and further deepens our udev dependency. A better solution is being worked on in [1]. [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3638
2022-10-17backend/drm: log when restoring mode after VT switch failsSimon Ser
Can make it easier to track down issues.
2022-09-30backend/drm: fix missing wlr_output_state.allow_artifactsSimon Ser
Without allow_artifacts, applying the new state will fail because it requires ALLOW_MODESET. Fixes VT switch and disabling CRTCs.
2022-08-18Use wl_signal_emit_mutableAlexander Orzechowski
2022-05-24backend/drm: allow non-linear modifiers for multi-GPUSimon Ser
Prior to [1], if an entry in a DRM format set was different than a single LINEAR modifier, implicit modifiers were always allowed. This has changed and now implicit modifiers are only allowed if INVALID is in the list of modifiers. So now we can safely enable explicit modifiers for cross-GPU imports, without risking receiving buffers with an implicit modifier. This should improve perf a bit on setups where two GPUs from the same vendor are used. This fixes the first bullet point from [2]. [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3231 [2]: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3331
2022-05-11backend/drm: fetch EDID manufacturer from udev_hwdbSimon Ser
Maintaining our internal table up-to-date is tedious: one needs to manually go through the PnP ID registry [1] and check whether we're missing any entry. udev_hwdb already has an API to fetch a manufacturer name from its PnP ID. Use that instead. [1]: https://uefi.org/pnp_id_list
2021-11-19backend/drm: scan leases on ueventSimon Ser
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3181
2021-11-18backend/drm: stop initializing backend rendererSimon Zeni
2021-11-02backend/drm: handle per-connector hotplug eventsSimon Ser
When a connector ID is specified in a hotplug event, don't scan all connectors. Only scan the connector that has changed.
2021-10-29backend/drm: get rid of BO handle tableSimon Ser
The BO handle table exists to avoid double-closing a BO handle, which aren't reference-counted by the kernel. But if we can guarantee that there is only ever a single ref for each BO handle, then we don't need the BO handle table anymore. This is possible if we create the handle right before the ADDFB2 IOCTL, and close the handle right after. The handles are very short-lived and we don't need to track their lifetime. Because of multi-planar FBs, we need to be a bit careful: some FB planes might share the same handle. But with a small check, it's easy to avoid double-closing the same handle (which wouldn't be a big deal anyways). There's one gotcha though: drmModeSetCursor2 takes a BO handle as input. Saving the handles until drmModeSetCursor2 time would require us to track BO handle lifetimes, so we wouldn't be able to get rid of the BO handle table. As a workaround, use drmModeGetFB to turn the FB ID back to a BO handle, call drmModeSetCursor2 and then immediately close the BO handle. The overhead should be minimal since these IOCTLs are pretty cheap. Closes: https://github.com/swaywm/wlroots/issues/3164
2021-09-30backend: create renderer and allocator in wlr_backend_autocreateSimon Ser
Instead of ensuring the renderer and allocator are initialized in each backend, do it in wlr_backend_autocreate. This allows compositors to create backends without any renderer/allocator if they side-step wlr_backend_autocreate. Since the wlr_backend_get_renderer and backend_get_allocator end up calling wlr_renderer_autocreate and wlr_allocator_autocreate, it sounds like a good idea to centralize all of the opimionated bits in one place.
2021-09-07backend/drm: fix crash on VT switchSimon Ser
Don't set the MODE flag when disabling a CRTC. This fixes a NULL pointer dereference in drm_connector_state_init.
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-10backend/drm: add proper error handling to wlr_drm_backend_createSimon Ser
Some listeners weren't removed and caused a use-after-free with e.g. vkms when used as a secondary GPU.
2021-07-28backend/drm: stop initializing renderer for parent backendSimon Ser
Unless we're dealing with a multi-GPU setup and the backend being initialized is secondary, we don't need a renderer nor an allocator. Stop initializing these.
2021-07-28backend/drm: drop get_renderer implementationSimon Ser
We can now just rely on the common code for this.
2021-07-20backend/drm: stop restoring CRTCs on exitSimon Ser
This is the cause of the spurious "drmHandleEvent failed" messages at exit. restore_drm_outputs calls handle_drm_event in a loop without checking whether the FD is readable, so drmHandleEvent ends up with a short read (0 bytes) and returns an error. The loop's goal is to wait for all queued page-flip events to complete, to allow drmModeSetCrtc calls to succeed without EBUSY. The drmModeSetCrtc calls are supposed to restore whatever KMS state we were started with. But it's not clear from my PoV that restoring the KMS state on exit is desirable. KMS clients are supposed to save and restore the (full) KMS state on VT switch, but not on exit. Leaving our KMS state on exit avoids unnecessary modesets and allows flicker-free transitions between clients. See [1] for more details, and note that with Pekka we've concluded that a new flag to reset some KMS props to their default value on compositor start-up is the best way forward. As a side note, Weston doesn't restore the CRTC by does disable the cursor plane on exit (see drm_output_deinit_planes, I still think disabling the cursor plane shouldn't be necessary on exit). Additionally, restore_drm_outputs only a subset of the KMS state. Gamma and other atomic properties aren't accounted for. If the previous KMS client had some outputs disabled, restore_drm_outputs would restore a garbage mode. [1]: https://blog.ffwll.ch/2016/01/vt-switching-with-atomic-modeset.html
2021-07-19backend/drm: fix NULL data in handle_drm_eventSimon Ser
wl_event_loop_add_fd was called with a NULL data argument, but the function expects the data argument to be set to the wlr_drm_backend. Fixes: 053ebe7c278b ("backend/drm: terminate display on drmHandleEvent failure")
2021-07-08backend/drm: force linear layout for multi-GPU buffersSimon Ser
Some buffers need to be copied across GPUs. Such buffers need to be allocated with a format and modifier suitable for both the source and the destination. When explicit modifiers aren't supported, we were forcing the buffers to be allocated with a linear layout, because implicit modifiers aren't portable across GPUs. All is well with this case. When explicit modifiers are supported, we were advertising the whole list of destination modifiers, in the hope that the source might have some in common and might be able to allocate a buffer with a more optimized layout. This works well if the source supports explicit modifiers. However, if the source doesn't, then wlr_drm_format_intersect will fallback to implicit modifiers, and everything goes boom: the source uses a GPU-specific tiling and the destination interprets it as linear. To avoid this, just force linear unconditionally. We'll be able to revert this once we have a good way to indicate that an implicit modifier isn't supported in wlr_drm_format_set, see [1]. [1]: https://github.com/swaywm/wlroots/pull/2815 Closes: https://github.com/swaywm/wlroots/issues/3030
2021-07-01buffer: make enum wlr_buffer_cap publicSimon Ser
Custom backends and renderers need to implement wlr_backend_impl.get_buffer_caps and wlr_renderer_impl.get_render_buffer_caps. They can't if enum wlr_buffer_cap isn't made public.
2021-07-01Remove unused wlr_list.h includesSimon Ser
2021-06-02backend/drm: implement get_cursor_formats and get_cursor_sizeSimon Ser
2021-05-21backend: introduce wlr_backend_finishSimon Ser
This new functions cleans up the common backend state. While this currently only emits the destroy signal, this will also clean up the renderer and allocator in upcoming patches.
2021-04-29backend/drm: introduce drm_connector_commit_stateSimon Ser
Backend-initiated mode changes can use this function instead of going through drm_connector_set_mode. drm_connector_set_mode becomes a mere drm_connector_commit_state helper.
2021-04-29backend/drm: remove mode arg from drm_connector_set_modeSimon Ser
All of the information is in wlr_output_state.
2021-04-29backend/drm: fill scratch wlr_output_state for set_modeSimon Ser
Populate the wlr_output_state when setting a mode. This will allow drm_connector_set_mode to stop relying on ephemeral fields in wlr_drm_crtc. Also drm_connector_set_mode will be able to apply both a new buffer and a new mode atomically.
2021-04-29backend/drm: take wlr_output_state as arg in commit callersSimon Ser
Instead of relying on wlr_output.pending to be empty when performing backend-initiated CRTC commits, use a zero wlr_output_state.
2021-04-28backend: introduce backend_get_buffer_capsSimon Zeni
2021-04-27backend/drm: destroy backend on udev remove eventSimon Ser
Any use of the DRM FD after the remove event results in a "Permission denied" error.
2021-04-27backend/drm: destroy when parent is destroyedSimon Ser
2021-02-05Make implementation function lists static constManuel Stoeckl
This requires a change to the type of `struct wlr_tablet` and `wlr_tablet_init` signature, both of which are part of the unstable API.
2021-01-16backend/drm: implement get_drm_fdSimon Ser
2021-01-10backend/drm: re-use FBsSimon Ser
Instead of importing buffers to GBM and KMS at each frame, cache them and re-use them while the wlr_buffer is alive. This is the same as [1] and [2] but for the DRM backend. [1]: https://github.com/swaywm/wlroots/pull/2538 [2]: https://github.com/swaywm/wlroots/pull/2539
2021-01-07remove unnecessary egl includesSimon Zeni
2021-01-03backend/drm: ignore hotplug events while inactiveSimon Ser
When the session is inactive, we can't change the KMS state. Ignore hotplug events so that compositors don't try to perform a modeset when a connector is plugged in. We already re-scan connectors when the session becomes active. To test, run a wlroots compositor on VT 1, switch to VT 2, unplug a connector, re-plug it, switch back to VT 1. Without this patch the screen is black on VT 1. References: https://github.com/swaywm/wlroots/issues/2370
2020-12-30Remove wlr_create_renderer_func_tSimon Ser
This callback allowed compositors to customize the EGL config used by the renderer. However with renderer v6 EGL configs aren't used anymore. Instead, buffers are allocated via GBM and GL FBOs are rendered to. So customizing the EGL config is a no-op.
2020-12-25backend/drm: make listener names more idiomaticSimon Ser
Use the "<object>_<event>" notation for listeners, use "handle_<listener>" for handlers.
2020-12-18backend/drm: refactor wlr_output destructionSimon Ser
Instead of hand-rolling our own manual wlr_output cleanup function, rely on wlr_output_destroy to remove an output from the compositor's state.
2020-12-17backend/drm: add wlr_drm_backend.nameSimon Ser
Save the DRM device name in a wlr_drm_backend field, so that we can easily use it for logging purposes.
2020-11-19backend/session: replace session_signal with events.activeSimon Ser
This is more idiomatic wlroots API. The new name makes it clear that the signal is emitted when wlr_session.active changes.
2020-11-19backend/session: operate on wlr_deviceSimon Ser
Instead of operating on FDs in {open,close}_device, operate on wlr_devices. This avoids the device lookup in wlr_session and allows callers to have access to wlr_device fields. For now, we use it to remove wlr_session_signal_add and replace it with a more idiomatic wlr_session.events.change field. In the future, other events will be added.
2020-05-26backend/drm: make drm_connector_set_mode take a wlr_drm_connectorSimon Ser
Since this is an internal DRM backend function, there's no reason we need to take a generic wlr_output.
2020-05-26backend/drm: remove enable_drm_connectorSimon Ser
Merge enable_drm_connector into drm_connector_set_mode. This allows us to de-duplicate logic since enabling an output performs a modeset.
2020-05-10backend/drm: fix crash in session_signalSimon Ser
conn->crtc is NULL in case the output is disabled. However, the DRM backend will set the GAMMA_LUT property anyway. On each commit the whole state is sent to KMS. Adding WLR_DRM_CRTC_GAMMA_LUT to the pending state would just make the backend re-create the blob containing the gamma LUT.
2020-05-09backend/drm: remove crtc_set_cursor from interfaceSimon Ser
2020-05-09backend/drm: apply gamma LUT on page-flipSimon Ser