Novum / vkQuake

Vulkan Quake port based on QuakeSpasm
GNU General Public License v2.0
1.72k stars 214 forks source link

MacOS+vsync: Game slows down to 5fps after taking 2-10 screenshots #661

Open Macil opened 1 year ago

Macil commented 1 year ago

If I take 2-10 screenshots, then after a random one of the screenshots the game suddenly slows down to 5 fps (at least that's what it says; feels more like 1 fps). This only happens for me with MacOS while vsync is on. The bug is dependably triggerable when I start the game with vsync on; it's not always triggerable if I've switched the setting while the game is running.

Once the issue happens, changing vsync to off does not fix it. Changing vsync to triple buffered does alleviate the issue, until I change it back to on or off.

I'm unable to reproduce this on Linux or Windows vkQuake, QS, or QSS. This is only slightly affected by the Max FPS setting (have tried with 60 and above 60 like 180): increasing the max fps slightly increases the framerate the game reports at during the slowdown (can get to 7-15 fps), though it oscillates and feels much more jank than what a consistent low framerate would be like.

While watching a scrolling sky texture during a slowdown, I think I figured out why it feels more like 1 fps: the game is consistently alternating between freezing for about a whole second and then quickly doing five frames. (Could some vsync timer be lowering its resolution to 1s somehow because of the quarter-second freeze during a screenshot, and so from then on for a whole second the game thinks it needs to wait more time before a frame, and then suddenly the timer ticks forward in one jump and a batch of frames all think it's time to go immediately until real time catches up to the vsync timer? I still need to actually look at the vsync code.)

Willing to debug this further over the next few days.

Novum commented 1 year ago

I bet this is some MoltenVK issue

Novum commented 1 year ago

I checked and this is definitely a MoltenVK bug. There is nothing in that code that could affect performance. It is very buggy in regards to vsync too (sometimes it syncs, sometimes it doesn't). Very frustrating, but nothing I can do on my side.

Novum commented 1 year ago

Guess I can keep this open for now.

temx commented 1 year ago

Maybe grabbing from somewhere else than the swapchain might help? That'd also allow hidding some HUD elements or notify strings in screenshots.

alexey-lysiuk commented 1 year ago

Setting MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS environment variable to 0 fixes the problem for me, i.e. launching with MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS=0 ./vkquake command line I was checking this on old Mac with Intel UHD Graphics 630.