Skip to content

tty: send a surface's dmabuf feedback only when it changes - #242

Open
sachahjkl wants to merge 2 commits into
bea4dev:mainfrom
sachahjkl:fix/dmabuf-feedback-unchanged
Open

sachahjkl wants to merge 2 commits into
bea4dev:mainfrom
sachahjkl:fix/dmabuf-feedback-unchanged

Conversation

@sachahjkl

Copy link
Copy Markdown
Contributor

Fixes #185.

Problem

On every frame, render_surface in backend/tty.rs gives each window, layer surface and lock surface its dmabuf feedback through smithay's send_dmabuf_feedback, which calls SurfaceDmabufFeedbackState::set_feedback. When the new feedback is a different Arc, set_feedback compares the format tables, and keeps the old Arc if they are equal. So an equal feedback, given again on every frame, makes the tables compared on every frame. In the profile of #185, this took about a tenth of the compositor's CPU. The feedback chosen for a surface rarely changes: a trace of one session logged 97 changes.

A second effect: the old calls passed |_, _| Some(output.clone()) as the primary-output function, so a surface on two outputs received each output's feedback in turn. Its kept feedback then changed on every frame, and the table comparison ran again for it.

Fix

All in src/shojiwm_lib/src/backend/tty.rs:

  • send_dmabuf_feedback_tree walks a surface tree as smithay's own walk does. It skips surfaces whose primary scan-out output (surface_primary_scanout_output) is not the output being rendered, as smithay's filter does.
  • Each surface keeps the feedback last sent to it in its data map (SentDmabufFeedback). set_feedback runs only when the chosen feedback differs from the kept one. The kept value is then the chosen Arc, so the next frame's comparison stops at the pointer.
  • send_dmabuf_feedback_with_popups walks a root surface and then its popups, as Window::send_dmabuf_feedback and LayerSurface::send_dmabuf_feedback do.
  • render_surface uses these for windows, mapped layer surfaces and the session lock surface. The selection (select_dmabuf_feedback, render or scan-out feedback) is unchanged.

Tests

No test is added. No new measurement is included in this PR; the numbers above come from #185 and from the trace in the commit message.

cargo test --workspace passes, except two tests that also fail on upstream main in our environment: evaluator::tests::embedded_runtime_ipc_does_not_leak_fds_across_reloads and input_method_keyboard_grab_gets_the_keymap_of_the_keys_it_is_sent.

This change has been running daily in the author's own session (a Windows-7-like desktop on ShojiWM).

ShojiWM gave every surface its dmabuf feedback on every frame, through
smithay's send_dmabuf_feedback, which calls set_feedback. set_feedback
compares the format tables whenever the feedback is another Arc, and
keeps its old Arc when they are equal: given an equal feedback on every
frame, it compared the tables on every frame, about a tenth of the
compositor's CPU in a profile (bea4dev#185). The feedback chosen for a surface
changes rarely: a trace of one session logged 97 changes.

ShojiWM now walks the surfaces itself, as smithay does (the surface
tree, then the popups), and keeps the feedback last sent in each
surface's data map. set_feedback runs only when the chosen feedback
differs from it; the kept one is then the chosen Arc, so the next
frame's comparison stops at the pointer.
A surface on two outputs was sent each output's feedback in turn, so
the kept feedback changed on every frame and the table comparison came
back for it. It now gets its primary scan-out output's feedback only,
the filter smithay's own walk applies.

This branch has not been deployed

No deployments
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.

TTY: dmabuf feedback compares whole format tables on every frame (~8 % of compositor CPU)

1 participant