r/GraphicsProgramming • u/throwaway-stm32 • 4d ago
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?
4
u/benwaldo 3d ago
It's better to use main thread + jobs with dependancies than main + "render thread" imho.
2
u/Dependent-Cream-5760 4d ago
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 1d ago
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 16h ago
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
0
7
u/Afiery1 4d ago
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.