minetest / minetest

Minetest is an open source voxel game-creation platform with easy modding and game creation
https://www.minetest.net/
Other
10.64k stars 2.01k forks source link

FPS limiter is inaccurate compared to other games (fixed on Linux) #13399

Open Calinou opened 1 year ago

Calinou commented 1 year ago
Minetest version
5.7.0
OS / Hardware

Operating system: Linux CPU: Intel Core i9-13900K

GPU model: GeForce RTX 4090 (NVIDIA 530.41.03) OpenGL version: OpenGL 4.6

Summary

Minetest's FPS limiter renders more frames than requested. This is a problem when attempting to reach a stable framerate below the V-Sync threshold for low input lag with V-Sync enabled when using a variable refresh rate monitor.

I've had decent success using fps_max = 110 to target 117 FPS on a 120 Hz display, but even then, it will occasionally go above 117 FPS (which causes temporarily increased input lag).

The screenshots below show both Minetest's own FPS counter and a MangoHUD overlay to prove that Minetest's FPS counter isn't the issue:

fps_max = 100

Expected time between frames: 10.0 ms

Screenshot_20230408_231239

fps_max = 150

Expected time between frames: ~6.7 ms

Screenshot_20230408_231336

fps_max = 30

Expected time between frames: ~33.3 ms

Screenshot_20230408_231435

Steps to reproduce

Set fps_max to any value and notice how the FPS cap is exceeded by the game. This can be verified both using Minetest's own FPS counter, but also external tools such as RTSS and MangoHUD.

Desour commented 1 year ago

We're only sleeping with ms resolution (very coarse): https://github.com/minetest/minetest/blob/9d736e8b8baeeacad9cfa94edd18adfcaf000029/src/client/game.cpp#L4252

sfan5 commented 1 year ago

That is a leftover from when the entire code operated with ms, feel free to test with higher accuracy.

srifqi commented 1 year ago

(EDIT: See below for testing with larger FPS limit)

Is this issue Linux-specific? I can not reproduce it on mine (Windows 10/10.0.19045, AMD Ryzen 5 4500U with Radeon Graphics). The FPS never goes above the limit.

FPS on Minetest vs on Xbox Game Bar

(setting fps_max = 30 and using Xbox Game Bar on Windows, Win+G)

Zughy commented 11 months ago

fps_max = 30, Pop!_OS. Is this wrong? Also, why FPS on MT always says 29?

https://github.com/minetest/minetest/assets/63455151/016a9bb4-e7d1-4315-a0b3-1379aaac71ab

sfan5 commented 11 months ago

Might be solved on Linux due to #13445

Calinou commented 11 months ago

Also, why FPS on MT always says 29?

It's likely a rounding error (perhaps it's floored in one way or another instead of using round()).

PS: While we're at it, we could make drawtime display one or two decimals, similar to RTT.

Zughy commented 9 months ago

So, to be clear, this is fixed? I didn't get it, sorry

Calinou commented 9 months ago

Seems to work great as of a98200bb4:

Screenshot_20231211_123208

Thanks!

Calinou commented 9 months ago

The issue still seems to be reproducible on Windows 11 with 5.8.0 on the same hardware:

image

Here, I use fps_max = 114 but I actually reach 120 FPS.

Should I open a new issue or reopen this one?

PS: The overlay in the corners is from Special K.

sfan5 commented 9 months ago

It's fundamentally the same issue, just a different platform.

srifqi commented 9 months ago

After further testing, it does seem like the FPS limiter is still broken on Windows (Windows 10/10.0.19045, AMD Ryzen 5 4500U with Radeon Graphics).

I tested it with fps_max = 114 using Xbox Game Bar on Windows (Win+G).

5.0.1 5.7.0 5.8.0
50 FPS 118 FPS 116 FPS
5.0.1 5.7.0 5.8.0
srifqi commented 9 months ago

I found another issue with FPS limiter. When I run Minetest by compiling at 5.8.0 tag using MSVC (Release configuration), my FPS is capped at around 35 FPS. This does not happen when I run Minetest from the official 5.8.0 release for Windows (compiled with MinGW, I assume): I can get much higher FPS using that. Is there any difference in calculating FPS limit between compilers?

grorp commented 9 months ago

I found another issue with FPS limiter. When I run Minetest by compiling at 5.8.0 tag using MSVC (Release configuration), my FPS is capped at around 35 FPS. This does not happen when I run Minetest from the official 5.8.0 release for Windows (compiled with MinGW, I assume): I can get much higher FPS using that. Is there any difference in calculating FPS limit between compilers?

I have the same problem. I usually get 25 FPS with MSVC ("Release" configuration) builds and 55-60 FPS with official Windows builds. All settings are set to their default values. Setting a high fps_max value doesn't make any difference for me, so I'm not sure if this problem is related to the FPS limiter.

sfan5 commented 9 months ago

Please test my PR. It might just happen to get fix that too.

srifqi commented 9 months ago

Please test my PR. It might just happen to get fix that too.

The PR does not fix my issue.

srifqi commented 9 months ago

After further checking, I found that the FPS is limited to around 35 FPS when the debug info is shown (F5). Again, this only happens in MSVC, not in MinGW.

Without debug info With debug info
5.8.0 MSVC without debug info 5.8.0 MSVC with debug info
sfan5 commented 9 months ago

Sounds like some weird (msvc-specific) inefficiency with text rendering. What happens if you put lots of text in chat?

srifqi commented 9 months ago

It has a lower FPS with lots of text in chat.

Slow MT with lots of text

Opening the chat console window lowers the FPS significantly.

Slow MT with lots of text