synchronization issues
Posted by
ac on
May 08, 2013; 11:10pm
URL: https://forum.jogamp.org/synchronization-issues-tp4029115.html
Hi guys,
I have encountered some performance issues in Processing that seem to be related to how the drawing thread in Processing synchronizes with JOGL. The problem manifests with choppy rendering, and it is most noticeable with programs that are GPU-bound. It is discussed at length in this thread:
https://github.com/processing/processing/issues/1714
My current understanding of the problem is as follows: Processing calls GLCanvas.display() from its main drawing thread. This thread also calculates how long the rendering of the last frame took, in order to sleep for the right amount of time so to satisfy the target framerate. GLCanvas.display() doesn't call the rendering code right away, but it triggers a callback to GLEventListener.display() (am I correct?). So one immediate problem is that the time interval calculated in the drawing thread for a single frame is most likely incorrect, since it only measures how long does it take to call GLCanvas.display(). Even the gl functions inside GLEventListener.display() could take a very short time to be called on the CPU, while they might take a much longer time to be executed on the CPU. An extreme example of this scenario would be a raymarching algorithm that runs entirely on the fragment shader. The CPU code simply consists in drawing one rectangle, so its execution time is negligible.
I have been trying to figure out how to properly synchronize the display requests from Processing so there is no stuttering, but haven't been successful so far. The only solution I found so far was to call glFinish() at the end of GLEventListener.display(), but the use of glFinish() is in general not recommended.
Any ideas or suggestions?
Andres