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

(Needs Testing) Improve V-Sync and frame-rate synchronization #234

Closed
wants to merge 3 commits into from
Closed

(Needs Testing) Improve V-Sync and frame-rate synchronization #234

wants to merge 3 commits into from

Conversation

HeavenVolkoff
Copy link
Contributor

Hello,

This is a proposed fix for #168 and some improvements for v-sync detection in setups with multiple monitors of heterogeneous refresh-rate.

The changes included are:

  • Automatic detection of current display refresh-rate¹
  • Automatic update of swap-interval to match ratio of display's refresh-rate to game's fixed frame-rate
  • Minor improvement to the precision of frame-rate synchronization (enabled when v-sync is off)
  • Improvement on error handling for environments where SDL can't detect the display frame-rate and/or enable v-sync

¹ This has a know bug due to SDL caching the display's current_mode at initialization and only updating it on explicit SDL mode change calls. Therefore, if any external change happens it starts reporting wrong values.

src/pc/gfx/gfx_sdl2.c Outdated Show resolved Hide resolved
@porcino
Copy link
Contributor

porcino commented May 20, 2020

Amazing! For me (w7 x64 nvidia) the vsync option is working for the first time with this.

src/game/options_menu.c Outdated Show resolved Hide resolved
@HeavenVolkoff
Copy link
Contributor Author

Amazing! For me (w7 x64 nvidia) the vsync option is working for the first time with this.

@porcino What is the refresh rate of your display? Because I was just reviewing the code and I realized that in displays with an refresh rate that are not multiple of 30, I actually am disabling the vsync in the logic, but leaving the option enabled in the menu. (will push a fix for that soon)

@porcino
Copy link
Contributor

porcino commented May 20, 2020

@porcino What is the refresh rate of your display?

60hz
I just played for a bit, in fullscreen works, in windows mode I know is tied to windows aero theme, so vsync is always on (that's fine happens in every game), but when I change to basic windows theme, only with vsync enabled in game, I get variable framerate, or speedups.

@HeavenVolkoff
Copy link
Contributor Author

60hz

Nice, so it should be working properly

I get variable framerate, or speedups

Even with this PR? Or are you talking about the current master/nightly?

@porcino
Copy link
Contributor

porcino commented May 20, 2020

Even with this PR? Or are you talking about the current master/nightly?

Yes with this PR, in windowed mode, with basic windows theme and vsync enabled in game

@HeavenVolkoff
Copy link
Contributor Author

Yes with this PR, in windowed mode, with basic windows theme and vsync enabled in game

Hun... I will setup a Windows VM to test this. Just a question though, are you changing the windows theme while the game is open? If so, could you test starting the game after enabling the basic windows theme to check if the issue persists.

@porcino
Copy link
Contributor

porcino commented May 20, 2020

could you test starting the game after enabling the basic windows theme to check if the issue persists.

Same result 31-35 fps with vsync on, stable 30fps without vsync. Since you can't enable vsync in windows mode, why not just ignore the setting?

@HeavenVolkoff
Copy link
Contributor Author

Same result 31-35 fps with vsync on, stable 30fps without vsync.

Seems like something isn't working properly, will need to debug this on a Windows machine

Since you can't enable vsync in windows mode, why not just ignore the setting?

You should be able to use vsync whether in fullscreen or windowed mode. The only requirement is that the display refresh rate must be a multiple of 30

@porcino
Copy link
Contributor

porcino commented May 20, 2020

You should be able to use vsync whether in fullscreen or windowed mode.

Not really, only Desktop Window Manager can disable or enable vsync in a game in windows mode, you can't have half of the screen synchronized. Is like that for every game

@HeavenVolkoff
Copy link
Contributor Author

Not really, only Desktop Window Manager can disable or enable vsync in a game in windows mode, you can't have half of the screen synchronized. Is like that for every game

I think I am misunderstanding something. When using windows basic theme, that results in the WM disabling vsync? If that is so, you are rigth. In windowed mode there is no way for the program to enable vsync afaik, it needs exclusive mode for this. What I meant was that vsync should work in windowed mode, if it's enabled in the WM, so there should be no need for the code to handle synchronization by itself... But I really did forgot to add some check for windowed mode with vsync off, that should default to the synchronization logic...

@porcino
Copy link
Contributor

porcino commented May 21, 2020

When using windows basic theme, that results in the WM disabling vsync?

Exactly, just like when you change the windows manager in linux to another without gpu acceleration example

@Emill
Copy link

Emill commented May 23, 2020

Just pull in the glx and d3d backends instead from https://github.com/Emill/n64-fast3d-engine, which already fixes all these issues. Except for >120 Hz monitors on d3d which I'm working on. SDL's API is not rich enough to correctly deal with vsync timing and deterministic latency.

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.

None yet

4 participants