4 ms·
The glReadPixels is going to be your primary issue, since it means the CPU can't submit additional work since the glReadPixels will block on the GPU finishing i
by Jasper_ 8y ago
The glReadPixels is going to be your primary issue, since it means the CPU can't submit additional work since the glReadPixels will block on the GPU finishing its. The "proper" way to do this is to use a Pixel Buffer Object and a sync fence. That way, you can submit frames, have a thread dedicated to checking the fence + readback, and keep both the CPU and GPU busy.
In terms of actual scheduling, it's kind of complicated, but for the most part the APIs require that draws happen in-order. Don't really expect to get many savings out of multi-threading your render loop in OpenGL, so that means we move to more standard game optimizations. Memory bandwidth is likely to be your biggest bottleneck, so make sure to do any buffer transfers at the start of the frame or scene, and definitely don't touch them between draws. Do a clear at the start of a frame (GPUs can do "fast clears" which lets the ROP unit simply overwrite it instead of having to pull in the contents of the previous frame). Use modern GL best practices: that means uniform buffer objects, since the classic uniform setters will do transfers mid-frame. Use a good profiler for your platform to determine whether any bottlenecks or slowness is on the CPU in your code, on the CPU in the driver, or on the GPU. If it's on the CPU, consider moving to a modern API like D3D12, Metal or Vulkan, but expect that to take some work.