Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: async glXSwapBuffers()

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13

    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:
    Code :
    	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?
    Sorry for my english.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,190
    Quote Originally Posted by ein_shved View Post
    The problem is thet glXSwapBuffers is sync, so its wait for shaders in second thread to be done.
    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".
    Last edited by Dark Photon; 12-04-2012 at 06:05 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13
    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?
    Sorry for my english.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,190
    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:
    * Parallel OpenGL FAQ

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13
    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.
    Sorry for my english.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •