Jittering in windowed mode

This question is perhaps not exclusively Defold related. Since I switched monitors from a 240Hz one to a 60Hz I’ve been noticing lots of jitter that can be seen by just animating a small sprite back and forth. After lots of testing I found out that this happens when v-sync is enabled and the application is in windowed mode. After testing several graphics drivers, monitors and machines I also tested SDL, SFML, my own GLFW/OpenGL application, Godot and Unity. It turns out Unity was the only engine that didn’t make the sprite jitter.

I have read about this being an issue in windowed application on Windows, but at first I couldn’t figure out why Unity didn’t have this problem. Then I switched from DirectX to OpenGL in Unity and experienced the exact same problem there too. Finally, I switched to Vulkan in Defold and got rid of the jitter altogether.

Do you know if this is something you have to live with when combining OpenGL, Windows, windowed mode and 60Hz v-sync? Does it have to do with Windows not recognizing the windowed OpenGL application as a game? I did notice the Windows “Game Bar / GeForce Experience” shows up when my game runs in full screen mode but not in windowed mode. However, after switching to Vulkan, it appears in windowed mode as well.

Sorry for a lengthy post, I was wondering if anyone has some insight here.

2 Likes

After switching to Vulkan I was happy for a while, but then I started noticing another kind of stutter/jitter – every time I call factory.create there’s a hickup. This hickup also occurs every time a game object enters or leaves the window. In the latter case the hickup can be avoided by not passing the frustum to render.draw in the render script. Weird bug if you ask me.

Finally, I switched back to OpenGL and found the magic option which solved all my (original) jittering issues. In the Nvidia control panel I switched the option ‘Vulkan/OpenGL present method’ from ‘Auto’ to ‘Prefer layered on DXGI Swapchain’. I don’t know why this works, but it seems to allow for some kind of optimization as displaying the frames is done via DXGI even if Vulkan or OpenGL is used.

No setting whatsoever seems to solve the Vulkan jittering issue though. This problem might be Defold related but I’m not sure. I’m just happy I found a solution for my own sake. Let me know if you want some testing done on the Vulkan thing.

2 Likes

It would be interesting for me to take a look at what’s going on with the vulkan jittering in your project, since we want to move away from OpenGL in general. I suspect it might be a side effect of having to create the render pipelines when a non-cached render state is seen in the engine, but it should only be happening the one time a new pipeline is created.

3 Likes

Is there anything I can extract from the logs? I built the engine using --with-vulkan and ran with -v. This prints only once just after running the program.

DEBUG:GRAPHICS: Created new VK Pipeline with hash 9433449058999663145

Yeah hm that means it’s not related to the pipeline creation, but it might be other resource creation calls, a bit hard to say without looking in a profiler

There’s no jittering if I remove the sprite from the game object spawned by the factory.

Ok, yeah I don’t think we can deduce anything with just that info. Does using the profiler give you any clues? Specifically something related to vertex buffers

I can’t really find anything out of the ordinary in the profiler. It looks very similar to when running with OpenGL. Also, dt is stable all the time.

But I just realized there is one setting I can change to make it smooth. That is using my 240Hz monitor set to 240Hz. When I use the 60Hz monitor or set the refresh rate to 60Hz on the 240Hz one it jitters on factory.create.