Skip to content

Initial support for DRM async page flip#1335

Draft
PolyMeilex wants to merge 2 commits intoSmithay:masterfrom
PolyMeilex:drm-async-page-flip
Draft

Initial support for DRM async page flip#1335
PolyMeilex wants to merge 2 commits intoSmithay:masterfrom
PolyMeilex:drm-async-page-flip

Conversation

@PolyMeilex
Copy link
Member

@PolyMeilex PolyMeilex commented Feb 17, 2024

This allows users to select if frame should be presented with VSync or fully ASync.

blocked by: Smithay/drm-rs#190 (awaiting releasse)
blocked by: Smithay/gbm.rs#40
related: #1325

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes are missing coverage. Please review.

Project coverage is 21.23%. Comparing base (91e61f1) to head (a7e1c32).
Report is 16 commits behind head on master.

Files Patch % Lines
src/backend/renderer/element/mod.rs 0.00% 15 Missing ⚠️
src/backend/renderer/element/surface.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1335      +/-   ##
==========================================
- Coverage   21.32%   21.23%   -0.09%     
==========================================
  Files         156      156              
  Lines       25121    25042      -79     
==========================================
- Hits         5356     5317      -39     
+ Misses      19765    19725      -40     
Flag Coverage Δ
wlcs-buffer 18.37% <0.00%> (-0.05%) ⬇️
wlcs-core 18.03% <0.00%> (-0.07%) ⬇️
wlcs-output 7.78% <0.00%> (+0.02%) ⬆️
wlcs-pointer-input 20.05% <0.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@PolyMeilex PolyMeilex force-pushed the drm-async-page-flip branch 2 times, most recently from 1a8c49e to 0d62362 Compare February 17, 2024 04:08
@nferhat

This comment was marked as resolved.

@PolyMeilex
Copy link
Member Author

Well I'm no Smithay maintainer but still curious whether this will help with integrating tearing-control-v1 or not? Because it seems quite promising!

It actually does.

Yep, it's more or less the only use-case for this.

@PolyMeilex PolyMeilex requested a review from cmeissl February 23, 2024 00:52
@PolyMeilex PolyMeilex force-pushed the drm-async-page-flip branch 4 times, most recently from e141600 to fb65980 Compare April 19, 2024 18:00
@PolyMeilex PolyMeilex marked this pull request as ready for review April 19, 2024 18:07
@PolyMeilex
Copy link
Member Author

Ok, I belive this is ready.

Although I still can't test the atomic path, even tho my driver started to report AtomicASyncPageFlip as supported recently, any attempt to page flip results in Invalid argument (os error 22) (perhaps it's a code issue so any testing with presentation mode flipped to Async would be welcome, just flip VSync to Async in anvil's udev.rs)

Running with SMITHAY_USE_LEGACY=1 on the other hand works flawlesly for me already (if one can use flawless to describe tearing 😄).

fn presentation_mode(&self) -> Option<PresentationMode> {
// On Wayland assume VSync as default preference
Some(PresentationMode::VSync)
// TODO: Return Async in case wp_tearing is attatched to the surface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is waiting on the tearing control PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, or the other way around, I don't care. Although the protocol PR is probably more merge ready. We could also just merge the PRs into one.

@cmeissl
Copy link
Collaborator

cmeissl commented Apr 21, 2024

Okay, so this is not going to work this way unfortunately. Async page flips have some special limitations we need to account for. For an async page flip to succeed the atomic commit is only allowed to change the framebuffer on the primary plane. Every other change will result in the page flip request to be declined.

This unfortunately also includes IN_FENCE_FD required for explicit sync. But this is something that is being worked on, so imo we should not special case this and just wait for it to land. Currently we do not support explicit sync for direct scan-out anyway.

Not sure what to do about FB_DAMAGE_CLIPS, need to check what the plan for this is. (worst case is we disable it for async page flips).

There are also driver specific limitations like for example intel not supporting async page flips if the plane uses some compressed tiling format.

So imo the most sane way to handle this is to do best guessing in render_frame if an async page flip might work.
Then in queue_frame do trail and error with a retry without async flip and remember that it failed for this frame state.
render_frame would then use the state as a feedback loop to prevent endless retries. The failed state should reset in case the format or other stuff changes allowing to re-test.

I prototyped some parts of this and will post a patch when its ready.

@cmeissl
Copy link
Collaborator

cmeissl commented Apr 21, 2024

Okay, I put something together that should work (at least it seems to work on my system).
https://github.com/cmeissl/smithay/commits/drm_async_page_flip/ (@PolyMeilex PR branch rebased on top of current master + some small fixes)

Curious if this also works on AMD and Nvidia now @PolyMeilex @YaLTeR @Drakulix
Filtering for linear formats is probably not going to work on Nvidia and probably also not needed.
Intel also does support async page flips with some modifiers (probably only compressed one are not supported, which kind of makes sense), but I was too lazy to put together a list of working formats.

@PolyMeilex PolyMeilex force-pushed the drm-async-page-flip branch from fb65980 to c5d0073 Compare May 1, 2024 21:33
@PolyMeilex
Copy link
Member Author

@cmeissl Atomic backend now works on my AMD systems, looks promising.

Rebased on master, and cherrypicked the cmeissl's commit (with some minnor reverts of debug code edits)

@PolyMeilex PolyMeilex force-pushed the drm-async-page-flip branch from c5d0073 to e62c854 Compare May 31, 2024 17:43
@PolyMeilex
Copy link
Member Author

Confits resolved, everything seems to still work as expected on my AMD machines both with atomic and legacy

@Drakulix
Copy link
Member

Drakulix commented Jun 3, 2024

Feedback from the display next hackfest:

  • IN_FENCE_FD will be added as a supported property in some future kernel
  • FB_DAMAGE_CLIPS is unclear, but amd/intel are aware that their current set of properties is too restrictive
  • There was a proposal to have an additional IN_FORMATS_ASYNC (or similarly named) property to solve the format issue.
  • Other compositors currently seem to just fall back to non-tearing presentation, when the format doesn't work out or default to the legacy api. Just using linear was deemed to potentially have performance issues...

@andry-dev

This comment was marked as resolved.

@shibahaczix

This comment was marked as duplicate.

@cmeissl
Copy link
Collaborator

cmeissl commented Oct 26, 2025

I will try to find some time in the next two weeks to go over the PR

@PolyMeilex are you fine with me updating the PR?

@PolyMeilex
Copy link
Member Author

@PolyMeilex are you fine with me updating the PR?

For sure, go ahead

@relativemodder

This comment was marked as duplicate.

@shibahaczix

This comment was marked as duplicate.

@alexmozaidze

This comment was marked as duplicate.

@nferhat
Copy link
Contributor

nferhat commented Jan 7, 2026

Not to be that guy, but it's 2026 already. Gamers demand answers from the Niri gods. Will you bestow upon us the godly feature of tearing so we may dominate COD lobbies once more?

On a more serious note, what's missing as of now? What needs to be changed here or in the codebase so I could contribute? I know Rust and I want this feature badly enough to drop everything I do right now and try working on it.

  • Implement wayland side of tearing control #1325 To implement the protocol that lets clients choose for themselves if they want to have tearing presentation or not
  • Rebasing this branch onto main again (smithay moves really quickly, and as a side effect of this leaving some fork/branch for a little could make it a hellish nightmare to rebase)
  • Free time for smithay maintainers and compositors devs to write implementation in their respective compositors, test it, make sure there's nothing wrong, test it even more, point out flaws

And after that, if it doesn't require multiple rounds of such review, then it can potentially get merged. We all want lower latency in our games, me included, and I am avid to implement this and make use of it, but having a solid implementation backing it more important.

@shibahaczix

This comment was marked as off-topic.

@gabriele2000

This comment was marked as off-topic.

@PolyMeilex PolyMeilex force-pushed the drm-async-page-flip branch 2 times, most recently from d4e7ff1 to 1072da7 Compare February 16, 2026 20:24
@PolyMeilex
Copy link
Member Author

PolyMeilex commented Feb 16, 2026

Ok, it took a bit of patience, but I managed to rebase this.
The anvil implementation did not survive the rebase tho, I did a minimal reimpl instead.

It's still possible to test this by editing this line:

Some(PresentationMode::VSync)

It's also worth noting that I still don't have a full grasp of what's going on in the Cmeissl's commit that made the atomic backend work, that's why I'm keeping it as a separate WIP commit.

Open question: Would dropping the seemingly more problematic atomic backend implementation and merging just the legacy impl make sense? Just to get things rolling, or should I rather just focus on trying to grasp what's needed for less hacky atomic impl?

@cmeissl
Copy link
Collaborator

cmeissl commented Feb 16, 2026

Ok, it took a bit of patience, but I managed to rebase this. The anvil implementation did not survive the rebase tho.

It's still possible to test this by editing this line in anvil: https://github.com/PolyMeilex/smithay/blob/1072da79b699cbfb18ceac51541f847a4d907114/anvil/src/udev.rs#L1674 I will try to bring back RenderElement based presentation mode selection to Anvill soon'ish.

It's also worth noting that I still don't have a full grasp of what's going on in the Cmeissl's commit that made the atomic backend work, that's why I'm keeping it as a separate WIP commit.

Open question: Would dropping the seemingly more problematic atomic backend implementation and merging just the legacy impl make sense? Just to get things rolling, or should I rather just focus on trying to grasp what's needed for less hacky atomic impl?

Thanks again for taking the time to get this forward. imo it does not make sense without the atomic backend. Also some of the things of my commit should not longer be required as some of the limitations have been lifted in the kernel. But I need some time to look into this again :(

@PolyMeilex
Copy link
Member Author

Also some of the things of my commit should not longer be required as some of the limitations have been lifted in the kernel. But I need some time to look into this again :(

The one thing I noticed is that your Linear format filters did not survive the rebase, but the impl still seems to work fine, so perhaps that's one of the limitations lifted?

@cmeissl
Copy link
Collaborator

cmeissl commented Feb 16, 2026

Also some of the things of my commit should not longer be required as some of the limitations have been lifted in the kernel. But I need some time to look into this again :(

The one thing I noticed is that your Linear format filters did not survive the rebase, but the impl still seems to work fine, so perhaps that's one of the limitations lifted?

Possible, I don't remember all details. But one thing that should be lifted is the IN_FENCE_FD iirc.

@PolyMeilex PolyMeilex marked this pull request as draft February 16, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.