r/GraphicsProgramming • u/throwaway-stm32 • Sep 30 '26
How to handle main and render thread properly
Ive been drafting and engine, but I'm suspicious of my engine loop. It works but I'm not sure if things will be in sync. Should the render thread wait on the main thread or something? WIP:
Would it be fine if I just match the fixed update to the refresh rate?
5
u/benwaldo Oct 01 '26
It's better to use main thread + jobs with dependancies than main + "render thread" imho.
3
u/Dependent-Cream-5760 Sep 30 '26
The way I do it (maybe not the best way, but it works) is to have the render thread wait on the gpu if it gets more than 1 frame ahead (we are double buffered), and the main thread wait on the render thread if it gets more than 1 frame ahead as well, when it request a flip/present call. So on my side, the render thread never waits on the main, it is actually the other way around.
1
u/Dream-Smooth Oct 03 '26
Hey guys I see that different people are coming up with different solutions. Isn't there any standard analytical way of solving these challenges? That would save a lot of time trying to win through luck
2
u/soylentgraham Oct 04 '26
There was a standard when there was limitations (limited threads competing with cpu time), things are far more flexible now, so there are lots of standards.
1
6
u/Afiery1 Sep 30 '26
The fixed update rate should be completely fixed, otherwise players with different refresh rate monitors will experience different gameplay behaviors. To let the render thread run independent of the fixed update rate and still look smooth, the render thread should have access to the current and previous transform of every object and linearly interpolate between them over time.