ValveSoftware / gamescope

SteamOS session compositing window manager
Other
3.03k stars 198 forks source link

Xwayland is delaying commits for vsynced clients #25

Closed Plagman closed 3 years ago

Plagman commented 4 years ago

Looking at gpuvis captures for vsynced games running is xwayland, unwanted things are happening. Xwayland is decoupled from the thing actually handling the output, so I'm not sure it ought having a say. Ideally Xwayland would just forward whether the client wants vsync to the compositor, and the compositor could pass back enough information to have the right behavior instead.

subdiff commented 4 years ago

Currently XWayland works like this for vsynced games:

  1. Flips get marked with sync_flip.
  2. On frame callback the MSC is bumped.
  3. The flip gets marked as done.

This has the following issue: The frame callback is not received by XWayland when the actual frame was presented but potentially later on when the compositor informs clients when there is "a good time to start drawing the next one".

I'm currently looking into replacing this with presentation-time protocol: Task, WIP-branch

My current approach is in a first step to decouple XWayland frame stepping from the frame-callback completely and instead directly use the timing values received through presentation-time to drive with an internal timer the presentation (and realign the timer later on).

Second step would then be to maybe reintroduce the frame callback to throttle presenting when the surface is not visible (battery saving). But that depends on how much a difference this actually would make.

Do you have specific games where you noticed this delay?

emersion commented 4 years ago

The frame callback is not received by XWayland when the actual frame was presented but potentially later on when the compositor informs clients when there is "a good time to start drawing the next one".

We send a frame callback as soon as we've received a commit, so this shouldn't be an issue.

Would still be nice to have presentation-time support in Xwayland ofc :)

Plagman commented 4 years ago

It's not quite as soon as, so it would still incur a delay for us. I think in general, what I stated back in January is still reasonable: a vsynced commit should be sent ASAP to the compositor without any more delay than a non-vsynced one, and knowledge that this commit/client is currently vsynced should come through another channel.

Has the current situation changed in any way? As a short-term workaround, can we force Xwayland to always act as if vsync is off? gamescope always acts as if vsync is on, so it would be the most efficient path.

emersion commented 3 years ago

Hmm. I've added instrumentation to the Vulkan WSI and I don't see any significant delay with Sekiro (~0.2ms). Can you elaborate how you reproduced the delays? Which games were you using?

emersion commented 3 years ago

Adding more trace points, it seems like Xwayland is committing a buffer right after we request it:

emersion commented 3 years ago

OK, it turns out there is some delay, because we actually don't send frame callbacks when the client commits, we send frame callbacks after painting.

Opened an upstream issue: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1150

emersion commented 3 years ago

Ref https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11290

Plagman commented 3 years ago

Sounds like discussion is mostly unblocked on that MR and we could proceed forward with disabling the mesa-side waiting based on a driconf setting.

emersion commented 3 years ago

The upstream MR has been merged.