ZDoom / gzdoom

GZDoom is a feature centric port for all Doom engine games, based on ZDoom, adding an OpenGL renderer and powerful scripting capabilities
http://zdoom.org
GNU General Public License v3.0
2.55k stars 552 forks source link

[BUG] Unable to disable VSync with Vulkan renderer: Game keeps rendering at 60 FPS even when told otherwise #2518

Open Eonfge opened 7 months ago

Eonfge commented 7 months ago

GZDoom version

GZDoom 4.12.1 Flathub

Which game are you running with GZDoom?

Doom 2

What Operating System are you using?

Linux x86_64

Please describe your specific OS version

Fedora Linux 39, Using Flathub

Relevant hardware info

AMD 6700, Using the MESA drivers with Linux 6.8

Have you checked that no other similar issue already exists?

A clear and concise description of what the bug is.

The Vulkan renderer does not allow you to unlock the FPS

Steps to reproduce the behaviour.

Your configuration

None. Best demonstrated with a clear config.

Provide a Log

[kevin@kevin-fedora-desktop ~/Projects/org.zdoom.GZDoom]$ MANGOHUD=0 flatpak run org.zdoom.GZDoom 
GZDoom g4.12.1-m - 2024-04-17 20:54:16 -0400 - SDL version
Compiled on Apr 21 2024

OS: Freedesktop SDK 23.08 (Flatpak runtime), Linux 6.8.6-200.fc39.x86_64 on x86_64
GZDoom version g4.12.1-m
W_Init: Init WADfiles.
adding /app/share/games/doom/gzdoom.pk3, 679 lumps
adding /app/share/games/doom/game_support.pk3, 3308 lumps
adding /home/kevin/.var/app/org.zdoom.GZDoom/.config/gzdoom/IWAD/DOOM2.WAD, 2919 lumps
adding /app/share/games/doom/lights.pk3, 7 lumps
adding /app/share/games/doom/brightmaps.pk3, 499 lumps
adding /app/share/games/doom/game_widescreen_gfx.pk3, 214 lumps
S_Init: Setting up sound.
I_InitSound: Initializing OpenAL
  Opened device Sirus Headset Analog Surround 4.0
  EFX enabled
Using video driver wayland
Number of detected displays 1 .
Creating window [2048x1152] on adapter 0
Vulkan device: AMD Radeon RX 6700 XT (RADV NAVI22)
Vulkan device type: discrete gpu
Vulkan version: 1.3.274 (api) 24.0.5 (driver)
Max. texture size: 16384
Max. uniform buffer range: -1
Min. uniform buffer offset alignment: 4
Resolution: 640 x 480
I_Init: Setting up machine state.
CPU Vendor ID: AuthenticAMD
  Name: AMD Ryzen 7 2700 Eight-Core Processor 
  Family 23 (23), Model 8, Stepping 2
  Features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2 F16C FMA3 BMI1 BMI2 HyperThreading
V_Init: allocate screen.
ST_Init: Init startup screen.
Checking cmd-line parameters...
S_InitData: Load sound definitions.
G_ParseMapInfo: Load map definitions.
Texman.Init: Init texture manager.
ParseTeamInfo: Load team definitions.
LoadActors: Load actor definitions.
script parsing took 520.66 ms
R_Init: Init Doom refresh subsystem.
DecalLibrary: Load decals.
M_Init: Init menus.
P_Init: Init Playloop state.
ParseSBarInfo: Loading custom status bar definition.
D_CheckNetGame: Checking network game status.
player 1 of 1 (1 nodes)

vid_fps 1

PS. My girlfriend was already fallen asleep on the couch, so I told her that I had to inform you of this bug... Now she's imagining a series of nerdy Christmas Elves sitting at a conveyor belt, maintaining projects like these.

RicardoLuis0 commented 7 months ago

can you double check for me if you have vid_maxfps at 60? it caps FPS separately from VSync (check "Max FPS" in settings, you can set it up to 500 in the menu, and you can disable completely in the console by running vid_maxfps 0) (same for cl_capfps ("Rendering Interpolation" in settings), disabling it disables all interpolation, so it forces the game to run at 35fps, regardless of vsync settings)

Eonfge commented 7 months ago

I did a quick check, and all are as they are supposed to be.

[kevin@kevin-fedora-desktop ~]$ MANGOHUD=0 flatpak run org.zdoom.GZDoom 
GZDoom g4.12.1-m - 2024-04-17 20:54:16 -0400 - SDL version
Compiled on Apr 21 2024

OS: Freedesktop SDK 23.08 (Flatpak runtime), Linux 6.8.6-200.fc39.x86_64 on x86_64
GZDoom version g4.12.1-m
W_Init: Init WADfiles.
adding /app/share/games/doom/gzdoom.pk3, 679 lumps
adding /app/share/games/doom/game_support.pk3, 3308 lumps
adding /home/kevin/.var/app/org.zdoom.GZDoom/.config/gzdoom/IWAD/DOOM2.WAD, 2919 lumps
adding /app/share/games/doom/lights.pk3, 7 lumps
adding /app/share/games/doom/brightmaps.pk3, 499 lumps
adding /app/share/games/doom/game_widescreen_gfx.pk3, 214 lumps
S_Init: Setting up sound.
I_InitSound: Initializing OpenAL
  Opened device Sirus Headset Analog Surround 4.0
  EFX enabled
Using video driver wayland
Number of detected displays 1 .
Creating window [2048x1152] on adapter 0
Vulkan device: AMD Radeon RX 6700 XT (RADV NAVI22)
Vulkan device type: discrete gpu
Vulkan version: 1.3.274 (api) 24.0.5 (driver)
Max. texture size: 16384
Max. uniform buffer range: -1
Min. uniform buffer offset alignment: 4
Resolution: 640 x 480
I_Init: Setting up machine state.
CPU Vendor ID: AuthenticAMD
  Name: AMD Ryzen 7 2700 Eight-Core Processor 
  Family 23 (23), Model 8, Stepping 2
  Features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2 F16C FMA3 BMI1 BMI2 HyperThreading
V_Init: allocate screen.
ST_Init: Init startup screen.
Checking cmd-line parameters...
S_InitData: Load sound definitions.
G_ParseMapInfo: Load map definitions.
Texman.Init: Init texture manager.
ParseTeamInfo: Load team definitions.
LoadActors: Load actor definitions.
script parsing took 516.65 ms
R_Init: Init Doom refresh subsystem.
DecalLibrary: Load decals.
M_Init: Init menus.
P_Init: Init Playloop state.
ParseSBarInfo: Loading custom status bar definition.
D_CheckNetGame: Checking network game status.
player 1 of 1 (1 nodes)

----------------------------------------

MAP01 - Entryway

]vid_fps
                     (default: "false")
]vid_fps 1
]vid_maxfps
                      (default: "500")
]cl_capfps
Rendering Interpolation
                       (default: "false")
]quit
Eonfge commented 7 months ago

Additional info: I now start GZDoom on my company laptop that has a 75 frame monitor... and the Vulkan renderer now caps itself at 75 fps.

RicardoLuis0 commented 7 months ago

does it also happen the same if you run it via wine? if not, it could be an SDL thing rather than a vulkan thing

Eonfge commented 7 months ago

That would be a bit harder for me to try.

But I did try something else: It's possible on Linux to translate OpenGL commands to Vulkan, and to use Vulkan to drive the GPU. When I do that... Vulkan does render at my configured fps target.

[kevin@kevin-fedora-desktop ~]$ MANGOHUD=0 MESA_LOADER_DRIVER_OVERRIDE=zink flatpak run org.zdoom.GZDoom
[...]
RicardoLuis0 commented 7 months ago

When I do that... Vulkan does render at my configured fps target.

hmm, could it be a vulkan driver issue then? does it happen with any other software running on vulkan?

Eonfge commented 7 months ago

Unlikely... it also doesn't happen to the previous version of GZDoom, 4.11.3

If I run Freedoom for example, who still uses the previous version of GZDoom, I have no trouble:

[kevin@kevin-fedora-desktop ~]$  MANGOHUD=0 flatpak run io.github.freedoom.Phase1
GZDoom g4.11.3-m - 2023-10-26 15:18:50 -0400 - SDL version
Compiled on Feb  1 2024

OS: Freedesktop SDK 23.08 (Flatpak runtime), Linux 6.8.6-200.fc39.x86_64 on x86_64
GZDoom version g4.11.3-m
W_Init: Init WADfiles.
adding /app/share/games/doom/gzdoom.pk3, 672 lumps
adding /app/share/games/doom/game_support.pk3, 3307 lumps
adding /app/share/games/doom/freedoom1.wad, 3163 lumps
adding /app/share/games/doom/game_widescreen_gfx.pk3, 214 lumps
adding /app/share/games/doom/lights.pk3, 7 lumps
adding /app/share/games/doom/brightmaps.pk3, 499 lumps
S_Init: Setting up sound.
I_InitSound: Initializing OpenAL
  Opened device Sirus Headset Analog Surround 4.0
  EFX enabled
I_Init: Setting up machine state.
CPU Vendor ID: AuthenticAMD
  Name: AMD Ryzen 7 2700 Eight-Core Processor 
  Family 23 (23), Model 8, Stepping 2
  Features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2 F16C FMA3 BMI1 BMI2 HyperThreading
V_Init: allocate screen.
ST_Init: Init startup screen.
Checking cmd-line parameters...
S_InitData: Load sound definitions.
G_ParseMapInfo: Load map definitions.
Texman.Init: Init texture manager.
ParseTeamInfo: Load team definitions.
LoadActors: Load actor definitions.
script parsing took 168.45 ms
R_Init: Init Doom refresh subsystem.
DecalLibrary: Load decals.
Adding dehacked patch freedoom1.wad:DEHACKED
Patch installed
M_Init: Init menus.
P_Init: Init Playloop state.
ParseSBarInfo: Loading custom status bar definition.
===========================================================================
This is Freedoom, the free content first person shooter.

Freedoom is freely redistributable under the terms of the modified BSD
license. Check out the Freedoom website for more information:

    https://freedoom.github.io/
============================================================================
D_CheckNetGame: Checking network game status.
player 1 of 1 (1 nodes)
Using video driver wayland
Vulkan device: AMD Radeon RX 6700 XT (RADV NAVI22)
Vulkan device type: discrete gpu
Vulkan version: 1.3.274 (api) 24.0.5 (driver)
Max. texture size: 16384
Max. uniform buffer range: -1
Min. uniform buffer offset alignment: 4
Resolution: 640 x 480

----------------------------------------

E1M1 - Outer Prison

]vid_fps 1
Eonfge commented 7 months ago

If I tried two another games:

Eonfge commented 6 months ago

Issue reproduced with 4.12.2

yum13241 commented 5 months ago

Turning off interpolation should lock your game at 35 FPS, I believe. Are you using Wayland by any chance? Depending on your desktop environment, Wayland could force VSync.

Eonfge commented 5 months ago

Turning off interpolation should lock your game at 35 FPS, I believe. Are you using Wayland by any chance? Depending on your desktop environment, Wayland could force VSync.

All these tests were done with Fedora Linux 40, using an AMD 6700, on Wayland. See the full application output for more details.

yum13241 commented 5 months ago

GNOME Wayland forces VSync, but there's been a new protocol in Wayland I believe, that allows forcing vsync off. Maybe GZDoom doesn't use it.

Eonfge commented 5 months ago

GNOME Wayland forces VSync on the output of the video streams, and there is a lot of talk about adaptive vsync or options to disable it. But that's not what is happening here.

In this case, it's not just about rendering at 60 FPS, but it's also simulating the game at 60 FPS. This is easy to notice when switching to the OpenGL ES renderen: Suddenly my mouse-inputs are buttery smooth and GZDoom reports 150+ frames... even when Wayland only shows the frames that sync up perfectly with the monitor.

For reference, this issue doesn't occur with older version of GZDoom or other games. Perhaps the Vulkan renderer incorrectly links the output frame-rate to the render/simulation-rate?

yum13241 commented 5 months ago

this case, it's not just about rendering at 60 FPS, but it's also simulating the game at 60 FPS.

Then you would shoot about twice as fast. I think you mean your inputs are being polled at 60 polls per second? The renderer doesn't do input, SDL does these days. Perhaps with the SDL-ification of input across platforms, this arises as a result?

RicardoLuis0 commented 5 months ago

simulating the game at 60 FPS

GZDoom only ever simulates at 35Hz, all that happens in higher framerates is inter-tic interpolation, you're probably just noticing the frame lag inherent to vsync

yum13241 commented 5 months ago

Which is what I was trying to say. Perhaps some modification of the input code added worsened V-Sync input lag or smth.

GZDoom probably doesn't know how to talk to `mutter, GNOME's compositor to force V-Sync off (yes, in the glorious world of Wayland the compositor is responsible for every single setting, maybe copying what Yamagi Quake 2 is doing would help?)

RicardoLuis0 commented 5 months ago

GZDoom probably doesn't know how to talk to `mutter, GNOME's compositor to force V-Sync off

that would be the responsibility of SDL, not GZDoom

yum13241 commented 5 months ago

And the reason this did not happen on older versions of GZDoom was that they only used SDL for input and not display, or smth like that, and only on Linux, since SDL sucked on Windows when Graf made that decision.

Calinou commented 3 months ago

On Windows 11, GZDoom 4.11.3 seems to respect the Max FPS setting when in-game V-Sync is enabled when using Vulkan, but 4.12.2 does not. This makes low-lag V-Sync on impossible without external tools on VRR displays.

When using OpenGL, the cap works with both versions when V-Sync is enabled.

My configuration: gzdoom_portable.txt (rename extension to .ini)