Helion-Engine / Helion

A modern fast paced Doom FPS engine
GNU General Public License v3.0
86 stars 9 forks source link

Disabling VSync causes massive fluctuations / inconsistencies with frametimes #560

Closed SharlLegreg closed 5 months ago

SharlLegreg commented 5 months ago

OS: Windows 11 23H2 Version Tested On: https://github.com/Helion-Engine/Helion/commit/9641031c8470d6843b37516e8807494062f617f0

Disabling VSync either via the in-game options or GPU Software ( in this case AMD Adrenalin Software ) causes massive fluctuations and inconsistencies with frametimes. Capping the framerate does not seem to fix this frametime issue

This issue is further exacerbated on complex maps ( MAP26 of Eviternity and MAP29 of Hellbound ), making the gameplay feels jittery / stuttery . This is something not observed in other sourceports / games in general.

I'm not sure if this an engine issue or an issue on my side, but I've given relevant hardware information at the very end.

Helion https://github.com/Helion-Engine/Helion/commit/9641031c8470d6843b37516e8807494062f617f0, VSync ON Helion_2024_03_21_02_42_34_813

Helion https://github.com/Helion-Engine/Helion/commit/9641031c8470d6843b37516e8807494062f617f0, VSync OFF Helion_2024_03_21_02_42_42_424

GZDoom 4.11.3a, VSync OFF gzdoom_2024_03_21_02_46_23_129

GZDoom 4.11.3a VSync ON gzdoom_2024_03_21_02_46_40_222

DSDA-Doom 0.27.5 VSync OFF dsda-doom_2024_03_21_02_48_55_870

DSDA-Doom 0.27.5, VSync ON dsda-doom_2024_03_21_02_49_11_835

Hardware Information:

Lenovo Ideapad 3 15ALC6 82KU CPU: Ryzen 5 5500u with Vega 7 integrated GPU RAM: Dual Channel 8GB DDR4 Storage: 512GB SSD AMD Driver Version: 23.19.10-240104a-399660C-AMD-Software-Adrenalin-Edition

nstlaurent commented 5 months ago

The problem you are seeing is the processing happening for the world simulation every 28 milliseconds (35 times a second). This processing is a delay in sending commands to the GPU so it's going to be lower for that instant. Because Helion has comparatively no processing on the other frames compared to GZDoom/dsda the difference between the min and max framerates is going to be much higher.

I suspect if you use the chasecam command in the console the problem will go away when the burden of the world simulation is lifted off the CPU.

nstlaurent commented 5 months ago

So I played with this some more. My laptop has a 5900HS with a Vega 8. I force switched to my Vega 8 and noticed the same issue. In Helion you can use hud.showminmaxfps 1. This shows the min/max frames rendered.

My Vega 8 looks like this: FPS: 80 Min: 20 Max: 6000

I think what is happening is that the world simulation is allowing the card to play catch up and it blasts out too many frames and basically exhausts itself. Usually there is an internal limit but I don't know what AMD is doing here.

I used RivaTuner and set the framerate limit to be 100 and then I got much more stable numbers. I did the cap here because setting the cap in the AMD software does not appear to work.

nstlaurent commented 5 months ago

This one was a little tricky but it appears to be that the nvidia implementation has a baked in optimization where glMappedBuffer will return the same address so it doesn't have to synchronize the CPU and GPU memory every call. The apparent fix seems to be using GL_MAP_PERSISTENT_BIT with glBufferStorage to the call but that is a 4.4 feature.

@SharlLegreg since you appear to be building from source can you let me know if this branch fixes the problem you? I will have to test later that setting GL_MAP_PERSISTENT_BIT on cards that don't support it doesn't crash.

SharlLegreg commented 5 months ago

The branch majorly fixed the problem. Minor fluctuations is still there, and the fluctuations increases the more enemies are awake / pursuing the player.

The Min Max FPS are more stable and closer, with the max around 160-200 FPS, and min around 90-130 fps, compared to max of 3000 and min of 40.

Helion MPB Branch, many monsters awake Helion_2024_03_23_23_31_38_206

Ditto, no monsters awake Helion_2024_03_23_23_30_46_019

nstlaurent commented 5 months ago

The minor fluctuations are normal. The more monsters that are awake puts more processing time on the CPU and will make that frame take longer to render.

nstlaurent commented 5 months ago

Fixed with 0.9.2.8 release