Commit Graph

331 Commits

Author SHA1 Message Date
Simon Ser b03eebf7d4 backend/drm: always perform a CRTC commit in drm_connector_commit
When the mode, status or buffer hasn't changed, drm_connector_commit was
a no-op. Because of this individual changes to the gamma LUT or adaptive
sync status were ignored (if committed without a buffer).

Instead, perform a commit to apply the changes.
2020-06-01 11:45:11 -06:00
Simon Ser 1a2e82e327 backend/drm: drop extra wlr_output_update_enabled call
drm_connector_set_mode already takes care of keeping this up-to-date.
2020-06-01 11:45:11 -06:00
Simon Ser 80467f6ae8 backend/drm: commit/rollback FBs in drm_crtc_commit
We need to perform the FB bookkeeping on all commits, not just on
page-flips.
2020-06-01 11:45:11 -06:00
Simon Ser 70f3a0bb27 backend/drm: make adaptive_sync atomic
Stop using drmModeObjectSetProperty, set the property in the crtc_commit
function instead.
2020-06-01 11:45:11 -06:00
Simon Ser 42126c2022 backend/drm: rollback pending CRTC state on test commit
A test commit doesn't apply the pending state.

The CRTC state will be populated again if the compositor decides to
perform a regular commit afterwards.
2020-06-01 11:45:11 -06:00
Simon Ser d66b9966e9 backend/drm: fix missing crtc->cursor NULL check
Fixes: cdb6fdbc6c ("backend/drm: remove missing cursor plane workaround")
2020-05-27 21:01:20 +02:00
Simon Ser e7a8ea84c3 backend/drm: don't set cursor if off-screen
Closes: https://github.com/swaywm/wlroots/issues/2216
2020-05-27 21:01:20 +02:00
Simon Ser 15d8f1806e backend/drm: introduce pending and current CRTC state
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-26 23:34:37 +02:00
Simon Ser d6cc718472 backend/drm: nuke retry_pageflip
retry_pageflip is now dead code, since drm_connector_start_renderer
isn't called anymore. It was previously called when enabling an output.
The name "retry_pageflip" was a little confusing because the function
retried a modeset and the timer wasn't set up while performing a simple
page-flip.

Let's just remove this altogether for now. We can discuss whether it's
worth it to bring it back. Should we only do it on failed page-flips?
Should we only do it on EBUSY?
2020-05-26 23:34:37 +02:00
Simon Ser 61095f4a12 backend/drm: make drm_connector_set_mode take a wlr_drm_connector
Since this is an internal DRM backend function, there's no reason we
need to take a generic wlr_output.
2020-05-26 23:34:37 +02:00
Simon Ser 445750aa9a backend/drm: remove enable_drm_connector
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-26 23:34:37 +02:00
Simon Ser c02e9c2bb1 backend/drm: remove drm_connector_set_custom_mode
Replace it with a function that returns the pending mode.
2020-05-26 23:34:37 +02:00
Simon Ser 21c6cc5e4c backend/drm: refuse to enable an output without a mode 2020-05-26 20:10:55 +02:00
Simon Ser af2f69e6c1 render/egl: unset current context after swapping buffers
After swapping buffers, it doesn't make sense to perform more rendering
operations. Unset the context to reflect this.

This commit makes it so the context is always only current between
wlr_egl_make_current and wlr_egl_swap_buffers.

This is an alternative to [1].

[1]: https://github.com/swaywm/wlroots/pull/2212
2020-05-20 17:39:34 +02:00
Simon Ser d28a7da95d backend/drm: add missing wlr_egl_unset_current 2020-05-19 21:32:38 +02:00
Simon Ser 1edc42157b render/egl: introduce wlr_egl_unset_current
This function can be called after wlr_egl_make_current to cleanup the
EGL context. This avoids having lingering EGL contexts that make things
work by chance.

Closes: https://github.com/swaywm/wlroots/issues/2197
2020-05-19 14:56:20 +02:00
Simon Ser 347bdb6d9a output: make wlr_output_set_gamma atomic
wlr_output_set_gamma is now double-buffered and applies the gamma LUT on
the next output commit.
2020-05-14 20:09:28 +02:00
Simon Ser 42e485dcc3 backend/drm: fix segfault in drm_crtc_page_flip
When no cursor plane is available, drm_crtc_page_flip would segfault.
2020-05-14 10:20:37 +02:00
Simon Ser 9412d34e2d backend/drm: disable cursor in dealloc_crtc
dealloc_crtc was destroying GBM surfaces, but the cursor_enabled flag
was left as-is. When re-enabling the output, atomic_crtc_pageflip would
try enabling the cursor plane, but would fail because no framebuffer is
available.

Closes: https://github.com/swaywm/wlroots/issues/2150
2020-05-12 15:12:22 +02:00
Simon Ser da4df82532 backend/drm: fix combined modeset+enable commits
When an output is enabled and modeset at the same time,
drm_connector_commit would first try to modeset then try to commit. This
won't work because both will trigger a page-flip. KMS will reject that.

Change the logic to only enable an output if no modeset has been
requested. The logic in wlr_output already checks that the user isn't
doing a modeset and disabling the output at the same time.
2020-05-12 15:12:06 +02:00
Simon Ser cdb6fdbc6c backend/drm: remove missing cursor plane workaround
We have a workaround for legacy drivers that support drmModeSetCursor
without exposing a cursor plane. It doesn't work anymore now that we've
moved to a more atomic interface.

Let's just remove this workaround and fallback to software cursors.

Closes: https://github.com/swaywm/wlroots/issues/2166
2020-05-12 08:57:13 +02:00
JonnyMako 1139234117
backend/drm: fix missing cursor on external monitors with multi-GPU setup and nouveau
We need to make the multi-GPU surface current before the glFinish call.

Closes: https://github.com/swaywm/sway/issues/5319
2020-05-11 08:51:41 +02:00
Simon Ser 2ca3bdc35e backend/drm: simplify atomic commit logic
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-10 09:21:04 +02:00
Simon Ser 06d5aa5780 backend/drm: GAMMA_LUT_SIZE isn't atomic
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-10 09:20:46 +02:00
Simon Ser da63d11d34 backend/drm: remove crtc_set_cursor from interface 2020-05-09 16:42:25 +02:00
Simon Ser f8e02db4bc backend/drm: remove conn_enable from interface
Use crtc_commit instead.
2020-05-09 16:42:25 +02:00
Simon Ser c608fc89d8 backend/drm: rename crtc_pageflip to crtc_commit
Also add a flags argument.

The commit function will also be used for disabling the CRTC.
2020-05-09 16:42:25 +02:00
Simon Ser 70883fd10b backend/drm: apply gamma LUT on page-flip 2020-05-09 16:42:25 +02:00
Simon Ser 69b2279092 backend/drm: remove mode argument to crtc_pageflip
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-09 16:42:25 +02:00
Simon Ser c9d6b18eef backend/drm: remove wlr_drm_interface.crtc_move_cursor
Instead, make the legacy backend call drmModeMoveCursor on page-flip.
2020-05-09 16:42:25 +02:00
Simon Ser 90ede7f838 backend/drm: make page-flip error scarier
The logs don't currently display the importance of a line. It's easy to
read "skipping page-flip" as a debug message instead of an error
message.

Change the error message to make it more explicit.

References: https://github.com/swaywm/wlroots/pull/2147
2020-05-01 16:48:42 +02:00
Will Daly 044a9f28d6 Fix error when reconnecting external display
Reconnecting an external display fails on initial
page-flip.  This occurs when the pageflip_pending flag
has been set on the connector at the time the monitor
is removed.  Once the connector's CRTC has been deallocated,
page_flip_handler cannot find the connector by its crtc_id,
so pageflip_pending will remain set.  This causes
initialization to fail when the monitor is reconnected
with the error messages:

    Skipping pageflip on output 'X'
    Failed to initialize renderer on connector 'X': initial page-flip failed

To fix this problem, clear the pageflip_pending flag
when cleaning up the connector.
2020-05-01 16:01:30 +02:00
Scott Anderson 321537ee92 backend/drm: don't allow legacy to use direct scanout 2020-04-28 09:54:52 +02:00
Scott Anderson 52281cb8ba backend/drm: move atomic cursor code into pageflip code
It makes sense to construct as much atomic state as possible in the same
place, so it doesn't get lost if we "reset" it.
2020-04-28 09:54:52 +02:00
Scott Anderson 8da9d9679e backend/drm: introduce wlr_drm_fb
This is a type which manages gbm_surfaces and imported dmabufs in the
same place, and makes the lifetime management between the two shared. It
should lead to easier to understand code, and fewer special cases.

This also contains a fair bit of refactoring to start using this new
type.

Co-authored-by: Simon Ser <contact@emersion.fr>
2020-04-28 09:54:52 +02:00
Simon Ser 50ade3671f output: check for buffer size compatibility in common code
Instead of checking for buffer size compatibility in each backend,
centralize the check in wlr_output itself.
2020-04-10 15:52:20 +02:00
Simon Ser 5f092c55d1 output: fix blurred hw cursors with fractional scaling
The scaling factor was being implicitly cast to an int.

Closes: https://github.com/swaywm/sway/issues/4927
2020-04-10 15:10:12 +02:00
Simon Ser 507d9bc19e Add wlr_output_impl.rollback
Most of the pending output state is not forwarded to the backend prior
to an output commit. For instance, wlr_output_set_mode just stashes the
mode without calling any wlr_output_impl function.
wlr_output_impl.commit is responsible for applying the pending mode.

However, there are exceptions to this rule. The first one is
wlr_output_attach_render. It won't go away before renderer v6 is
complete, because it needs to set the current EGL surface.

The second one is wlr_output_attach_buffer.
wlr_output_impl.attach_buffer is removed in [1].

When wlr_output_rollback is called, all pending state is supposed to be
cleared. This works for all the state except the two exceptions
mentionned above. To fix this, introduce wlr_output_impl.rollback.

Right now, the backend resets the current EGL surface. This prevents GL
commands from affecting the output after wlr_output_rollback.

This patch is required for FBO-based outputs to work properly. The
compositor might be using FBOs for its own purposes [2], having leftover
FBO state can have bad consequences.

[1]: https://github.com/swaywm/wlroots/pull/2097
[2]: https://github.com/swaywm/wlroots/pull/2063#issuecomment-597614312
2020-04-08 17:33:00 +02:00
Simon Ser d3bd5f2a7b backend: reset EGL surface after buffer swap
This prevents GL commands to affect a previously current EGL surface
after a buffer swap.
2020-04-08 17:33:00 +02:00
Simon Ser 6977f3a843 output: check buffer in wlr_output_test
Check that buffer can be scanned out in wlr_output_test instead of
wlr_output_attach_buffer. This allows the backend to have access to the
whole pending state when performing the check.

This brings the wlr_output API more in line with the KMS API.

This removes the need for wlr_output_attach_buffer to return a value,
and for wlr_output_impl.attach_buffer.
2020-04-08 16:31:21 +02:00
Simon Ser e041158988 output: introduce wlr_output_test 2020-04-08 16:31:21 +02:00
Simon Ser 6595db6409 buffer: add a release event
Consumers call wlr_buffer_lock. Once all consumers are done with the
buffer, only the producer should have a reference to the buffer. In this
case, we can release the buffer (and let the producer re-use it).
2020-04-02 15:03:43 +02:00
Filip Sandborg 5ee52a3ab9
Fix uint32 overflow in fill_empty_gamma_table on Icelake platform
Closes: https://github.com/swaywm/sway/issues/4826
2020-03-15 18:41:12 +01:00
Simon Ser 52c67284e2 backend/drm: add support for adaptive_sync_enabled
The vrr_capable and VRR_ENABLED properties are used.
2020-03-06 21:32:58 +01:00
Simon Ser 348f52b5fc output: remove wlr_output_impl.schedule_frame
This function allowed backends to provide a custom function for frame
scheduling. Before resuming the rendering loop, the DRM and Wayland
backends would wait for vsync.

There isn't a clear benefit of doing this. The only upside is that we
get more stable timings: the delay between two repaints doesn't change too
much and is close to a mutliple of the refresh rate.

However this introduces latency, especially when a client misses a
frame. For instance a fullscreen game missing vblank will need to wait
more than a whole frame before being able to display new content. This
worst case scenario happens as follows:

- Client is still rendering its frame and cannot submit it in time
- Deadline is reached
- Compositor decides to stop the rendering loop since nothing changed on
  screen
- Client finally manages to render its frame, submits it
- Compositor calls wlr_output_schedule_frame
- DRM backend waits for next vblank
- The wlr_output frame event is fired, compositor draws new content on screen
- On the second next vblank, the new content reaches the screen

With this patch, the wlr_output frame event is fired immediately when
the client submits its late frame.

This change also makes it easier to support variable refresh rate, since
VRR is all about being able to present too-late frames earlier.

References: https://github.com/swaywm/wlroots/issues/1925
2020-03-04 03:22:19 +01:00
Rouven Czerwinski 144d2041ad backend/drm: remove overzealous finish_drm_surface
The previous PR was overzealous in adding a finish_drm_surface call
which was also done by the caller. Remove the call and also move the
comment to the correct code location.
2020-01-24 19:57:09 +01:00
Rouven Czerwinski f0594fb732 backend/drm: add env variable to disable modifiers
In some cases modesets fail if the planes are initialized with
modifiers. Since in this case possibly all planes need to reinitialized,
which is not possible in the current wlroots design, add an environment
variable for affected users.
2020-01-24 19:43:51 +01:00
Simon Ser 7c05933e51 backend/drm: prevent outputs from being destroyed on commit
This would happen if initializing the renderer fails. Instead, we just
mark the output as disabled.

References: https://github.com/swaywm/sway/pull/4917
2020-01-17 06:49:31 -07:00
Simon Ser 21e1953b61 backend/drm: don't modeset with a NULL mode after TTY switch
This fixes a segfault in drm_connector_set_mode (mode = NULL).

This happens because we set wlr_output.enabled to true if the connector
is attached to the CRTC. When the user disables an output in the
wlroots-based compositor, switches to another VT (enabling the output),
then switches back, wlroots sets wlr_output.enabled to true but
wlr_output.current_mode is NULL.

We should consider not reading properties from KMS after a TTY switch,
disabling all connectors. However this may result in flickering (outputs
being disabled then re-enabled).

Closes: https://github.com/swaywm/wlroots/issues/1874
2019-12-30 14:32:37 -07:00
Simon Ser 8fc16890c7 output: refuse to commit a buffer or modeset a disabled output
References: https://github.com/swaywm/wlroots/issues/1780#issuecomment-518938390
2019-12-30 11:21:11 -07:00