async glXSwapBuffers()

Hi
I have two-threading programm, where one thread for drawing, second for calculation on shaders. Both threads has own context, second was created like that:

	GLint attributes[] = { 	GLX_RGBA,
				GLX_DEPTH_SIZE, 24,
				None };
	XVisualInfo *xVisualInfo = glXChooseVisual(_xDisplay, 0, attributes);
	GLXContext newContext = glXCreateContext(_xDisplay, xVisualInfo, _glxContext, GL_TRUE);
	if ( newContext == NULL ) {
		throw runtime_error ( _ExceptionString "Can not create new context.");
	}
	glXMakeCurrent(_xDisplay, _xWindow, newContext );

The problem is thet glXSwapBuffers is sync, so its wait for shaders in second thread to be done. How make It async or what have I to put in attributes array?

glXSwapBuffers is very much async as far as CPU/GPU execution in my experience (on NVidia at least). Driver/GPU can queue it and CPU can happily run on and start queuing GL calls for the next frame. This is actually something I don’t want, so I do a glFinish() after glXSwapBuffers so that I get to decide when the next frame starts on the CPU (common technique).

I think your question is more what happens when rendering with 2 contexts in 2 different threads both targetting the same GPU. AFAIK, the GPU can only be processing the commands for one of those contexts at a time. So yeah, you’re probably seeing one “stalled” while the other is “working”.

So its mean, theat GPU can’t process more then one glDraw* call at once, so its mean thet I can’t do smth to make CPU-like multithreading, using shaders in both threads?

Not a guru here. But my understanding is that with 2 GPUs, no sweat. But with 1 GPU, they have to share.

Check this out:

I found the solution. Its simple and very evident I’m stupid because I don’t think aboth that before. Simple syncronisation via condition variable: second thread (with gpgpu) waits for thirst to drow thre results of 2nd.