Thanks for the reply!
Yes, some sync issue seems to be at the heart of this. This explanation seems plausible (AI-generated):
"Before adding the query, your rendering loop might have been implicitly synchronizing with the GPU in a way that caused sudden stalls.
When the GPU gets overloaded, certain OpenGL calls (like glBufferSubData, glMapBuffer, or even glDrawElements) can block the CPU until the GPU catches up.
GL_TIME_ELAPSED queries introduce a form of implicit pipelining by allowing the GPU to finish rendering asynchronously before retrieving the result in a later frame.
This reduces the chance of a hard sync point where the CPU waits for the GPU, leading to a more gradual degradation of performance instead of sudden hitches."
Perhaps this points to something which could be improved within JUCE’s OpenGL implementation?
I’m working on a general-purpose GPU class, which I want to be able to handle anything the user throws at it. I know exactly what is causing the huge pileup of GPU commands – I am causing it intentionally!
I’m impressed by how much of a positive difference the function makes. OpenGL went from potentially slowing the entire system to being completely robust, and I can’t notice any negative effects under normal circumstances. Also, the function lets me measure the GPU load quite precisely, which is the reason I put it in there to begin with.
Without it, not only might the system suddenly get clogged up, I also don’t have a reliable way to know when that is about to happen.
I will try to test on more hardware. For now I have just tested on an (old) Intel MacbookPro. Whether on battery or plugged makes no difference. GL_TIME_ELAPSED is not supported on OpenGL ES, so I can’t test on mobile devices.