Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a V-Sync editor setting #48364

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented May 1, 2021

master version of #48366.

The editor setting makes it possible to tweak V-Sync status independently of the project setting.

Use cases:

  • Decrease input lag and increase editor responsiveness when editing a project that has V-Sync enabled.
  • Avoid tearing when editing a project that has V-Sync disabled.

Inspired by #20916, but the default behavior is now to have V-Sync enabled.

@Calinou Calinou requested a review from a team as a code owner May 1, 2021 23:22
@Calinou Calinou added cherrypick:3.x Considered for cherry-picking into a future 3.x release enhancement topic:editor labels May 1, 2021
@Calinou Calinou added this to the 4.0 milestone May 1, 2021
@Calinou Calinou force-pushed the add-vsync-editor-setting branch from 2f26170 to aa114c0 Compare May 1, 2021 23:26
@Calinou Calinou removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 1, 2021
@Chaosus
Copy link
Member

Chaosus commented Jul 10, 2021

@Calinou Does this look actual after #48622?

@Calinou
Copy link
Member Author

Calinou commented Jul 10, 2021

@Calinou Does this look actual after #48622?

Rebased and tested again, it works successfully.

@bjorn
Copy link

bjorn commented Jun 8, 2023

What's holding this up? I just spent a while trying to find a way to turn off V-Sync in the editor, until I found this PR. I'd love to get rid of the annoying input lag on Linux caused by the V-Sync!

After browsing the related issues, I noticed a comment about --disable-vsync, which actually does the trick for me. But an option in the Editor Settings would have been much easier to find. :-)

(And after trying this option, I have no idea why one would default vsync to on... the compositor seems to be already taking care of any tearing and the vsync seems to be just adding a huge unnecessary lag. Running X11 without compositor should be rather rare today, but maybe the behavior isn't the same everywhere...)

@Calinou
Copy link
Member Author

Calinou commented Jun 8, 2023

What's holding this up?

It needs a review from a contributor who is knowledgeable in the area 🙂

I'd love to get rid of the annoying input lag on Linux caused by the V-Sync!

Right now, V-Sync in the editor is controlled by the V-Sync project setting. Since 4.0, you can also use the --disable-vsync command line argument when opening the editor directly on the project.

If you have a variable refresh rate monitor (and VRR is enabled on windowed applications1), remember that you can leave V-Sync enabled and set a framerate cap by changing Low Processor Mode Sleep Usec in the editor settings to ceil(1.0 / vrr_fps_cap * 1000000), where vrr_fps_cap is determined by the formula refresh_rate - (int(refresh_rate / 60.0) + 1).

For instance, on a 60 Hz display, this is 58 FPS (17242 usec). On a 120 Hz display, this is 117 FPS (8548 usec), and on a 144 Hz display, this is 141 FPS (6945 usec). This allows you to get the best of both worlds (no tearing, low input lag).

See https://blurbusters.com/howto-low-lag-vsync-on/ for more information, and godotengine/godot-proposals#5451 which provides an automatic VRR-friendly framerate cap that can be selected by the user. (There's unfortunately no standard API to detect whether the user is currently using VRR, so this cannot be enabled automatically.)

(And after trying this option, I have no idea why one would default vsync to on...

I'd also prefer to have V-Sync off by default in the editor, but this should be discussed separately. reduz was against it last time I brought this up, since it results in noticeable tearing when panning in the 2D/3D editor viewports.

the compositor seems to be already taking care of any tearing and the vsync seems to be just adding a huge unnecessary lag

See also #71795. We don't know why this is occurring yet – input lag should not be higher than in 3.x in apples-to-apples comparisons. While disabling V-Sync will help a lot, we should still aim to resolve the original issue.

Edit: Input lag will be decreased once #80566 is merged too. This PR is still relevant nonetheless.

Footnotes

  1. VRR is always enabled on windowed applications on X11 (if VRR is enabled in general), but VRR only affects fullscreen apps by default on Windows.

@akien-mga
Copy link
Member

akien-mga commented Jun 8, 2023

Disabling V-Sync in the editor means burning CPU needlessly to render UI and the 2D/3D viewport, so this seems quite wasteful as a default setting. A lot of people use Godot on laptops and don't want to have fans spinning and the battery draining while organizing their scene nodes or writing scripts.

But adding an option to disable V-Sync is fine with me.

@Calinou This PR also needs an update to add the documentation, see CI checks.

@Calinou
Copy link
Member Author

Calinou commented Jun 8, 2023

Disabling V-Sync in the editor means burning CPU needlessly to render UI and the 2D/3D viewport,

There's already a FPS cap in place in the form of low-processor mode, although it does not cater to the monitor refresh rate currently (it's roughly 145 FPS by default). See godotengine/godot-proposals#5451. In the long term, we should unify the low-processor mode sleep duration and max FPS project settings into a single setting, as they're redundant since 3.2 when the low processor mode sleeping was reworked to be smoother.

@bjorn
Copy link

bjorn commented Jun 8, 2023

Right now, V-Sync in the editor is controlled by the V-Sync project setting.

I had tried changing that setting but it had no effect, so I assumed it would only affect a running game or something. Now I realize the setting just needs a restart to apply.

Disabling V-Sync in the editor means burning CPU needlessly to render UI and the 2D/3D viewport, so this seems quite wasteful as a default setting.

I just compared CPU usage on my system and it's 1% regardless of V-Sync being on or off. Anyway, I can understand if the behavior is different elsewhere. (though, if we're really worried about CPU usage, then I would expect 0% usage when I'm not doing anything - and no animation is playing)

@Calinou
Copy link
Member Author

Calinou commented Jun 8, 2023

@Calinou This PR also needs an update to add the documentation, see CI checks.

Done 🙂

(though, if we're really worried about CPU usage, then I would expect 0% usage when I'm not doing anything - and no animation is playing)

This is likely caused by the AudioServer running in the background when no sound is playing. See #63458.

@Calinou Calinou force-pushed the add-vsync-editor-setting branch from e382de0 to d07c210 Compare June 8, 2023 20:02
@Calinou Calinou requested a review from a team as a code owner June 8, 2023 20:02
@Calinou Calinou force-pushed the add-vsync-editor-setting branch 2 times, most recently from 0ec10fd to 825fff1 Compare June 8, 2023 20:18
@Calinou Calinou force-pushed the add-vsync-editor-setting branch from 825fff1 to 50f9d7f Compare September 25, 2023 23:43
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good overall.

How does this handle multiple windows? Do new windows spawned in the editor (e.g. dialogs) respect this setting too?

@Calinou
Copy link
Member Author

Calinou commented Sep 26, 2023

How does this handle multiple windows? Do new windows spawned in the editor (e.g. dialogs) respect this setting too?

I'm not sure how to test this, as I don't have a working way of having a FPS overlay on individual Godot windows (MangoHud doesn't play well with self-compiled builds).

The editor setting makes it possible to tweak V-Sync status
independently of the project setting.

Use cases:

- Decrease input lag and increase editor responsiveness when editing
  a project that has V-Sync enabled.
- Avoid tearing when editing a project that has V-Sync disabled.
@Calinou Calinou force-pushed the add-vsync-editor-setting branch from 977f28f to 6f95864 Compare February 5, 2024 21:14
@akien-mga akien-mga merged commit b98c2f2 into godotengine:master Feb 8, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stutter on Linux X11 when using multiple monitors
5 participants