Synchronized buffer swapping in multi window application

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Synchronized buffer swapping in multi window application

Marc@56K
Hi,

I'm using JOGL 2.0 Beta 10 in a VR environment. It consists of two projectors an one pc with two grafic boards. The application creates two NEWT windows (com.sun.javafx.newt.opengl.GLWindow), one for each gpu. Every window runs in a separate render thread. So the application consists of two render threads an one main thread. The rendering is synchronized after each frame with a wait-notifyall structure.
My problem is to swap the buffers in all render threads at the same time. I deactivated the auto swapping and swap before i start to render the next frame (GLWindow.swapBuffers()). But the swapping isn't realy synchronized. Is there an easy way to swap all buffers at the same time?

thx
Reply | Threaded
Open this post in threaded view
|

Re: Synchronized buffer swapping in multi window application

Demoscene Passivist
Administrator
One problem is that OpenGL commands are buffered before execution. When using a software swap synchronization (like u seem to do with ur wait-notifyall structure), call glFinish before entering the swap barrier to complete all outstanding OpenGL commands. But beware, glFinish is bad for the performance especially in SLI/Crossfire environments.

Also if the synchronization has to be perfect at least to my knowledge the is no way around a hardware solution like nVidia GSync to synchronize the video signal and buffer swap. Take a look here: http://www.nvidia.com/page/quadrofx_gsync.html

But don't panic normally a software synchronization is often good enough in most cases ... :)

Another common approach when it comes to synchronized rendering over multiple monitors/devices is to simply use SLI/Crossfire and make the two GPUs one rendering device. To do the mutlimonitor rendering simply make a window wich spans across 2 monitors and render 2 different projections side-by-side in one thread (e.g. using FBOs). This eases u from all synchronization stuff and if u program carefully u get the full power of both GPUs.


Reply | Threaded
Open this post in threaded view
|

Re: Synchronized buffer swapping in multi window application

Marc@56K
Thanks for the reply.
Our system uses geforce cards and so GSync is no option for us. I tryed the glFinish approach but it didn't become better. To use SLI with one big window is a good idea but the performance benefit of SLI systems is far away from 100%. The framerate with two NEWT-Windows in two thread excelent on linux (nearly 100% faster than one card).

If i run both windows on the same thread e.g.:
window1.render()
window2.render()
window1.swap()
window2.swap()

Than the swapping seams to be absolute synchronized. This is strange because I didn't call both swap commands at the same time.
Reply | Threaded
Open this post in threaded view
|

Re: Synchronized buffer swapping in multi window application

Demoscene Passivist
Administrator
Ok, then ur problem (even if u seem to have solved it now) is probably related to OpenGLs really "confusing" multithreading model.

First u should take a look here regarding NEWT: http://jogamp.org/wiki/index.php/Jogl_FAQ#What_is_Newt.27s_Threading_Model_for_native_window_events_.3F

Also u should note that OpenGL is only threadsafe when u use one context per thread. So with two windows u should create two contexts. Two threads rendering in one context usually gives "strange" results. So u could say that OpenGL is more "thread-specific" rather than "thread-safe".

Other than that I would not recommend using multithreading and OpenGL together at all coz in my experience most driver implementations are really fucked up regarding multithreading.

Anyway, as the single thread swap()² method works for u now I would recommend: "Never change a running system!" :)
Reply | Threaded
Open this post in threaded view
|

Re: Synchronized buffer swapping in multi window application

Marc@56K
I think I have solved my problem. Today I tried the java.util.concurrent.CyclicBarrier to synchronize the render threads before swapping, and it works very well.