Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Buffer orphaning and multiple context

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Buffer orphaning and multiple context

    Hi,

    I would like to ask if anybody knows whether buffer orphaning works across thread boundary.
    More specifically, I'm interested whether the following would work:

    - Thread #1 orphans the buffer and uploads new data using BufferData
    - Thread #2 uses the buffer for drawing after thread #1 called BufferData
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  2. #2
    Member Regular Contributor
    Join Date
    Oct 2006
    Posts
    349

    Re: Buffer orphaning and multiple context

    When you say 'orphans', you mean BufferData(..., null) or something else entirely?

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Buffer orphaning and multiple context

    Actually orphaning happens no matter if you pass NULL as pointer or if you pass in an actual client side buffer to fill the buffer with.
    I mean orphaning by using BufferData. I don't think that the last argument matters.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  4. #4
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    41

    Re: Buffer orphaning and multiple context

    Correct me if I'm wrong but only one thread can access the OpenGL context at a time (at least with WGL) so, as long as you make sure BufferData returned before using the data in another thread, yes it should work because there's just one command queue.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Buffer orphaning and multiple context

    The two threads, of course, use their own rendering context. I thought it is obvious. Actually if I would render to the same context from two threads then it wouldn't work. I think it is not even supported anyway.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  6. #6
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: Buffer orphaning and multiple context


  7. #7
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    41

    Re: Buffer orphaning and multiple context

    From the spec of ARB_vertex_buffer_object:
    "Buffer objects may be shared by rendering contexts, as long as the server
    portion of the contexts share the same address space. (Like display lists
    and texture objects, buffer objects are part of the server context state.)
    OpenGL makes no attempt to synchronize access to buffer objects. If a
    buffer object is bound to more than one context, then it is up to the
    programmer to ensure that the contents of the object are not being changed
    via one context while another context is using the buffer object for
    rendering. The results of changing a buffer object while another context
    is using it are undefined."
    What is unclear to me is whether context #1 might still be writting to PBO once BufferData returned, so you might have to issue a glFinish in thread #1 before using the buffer in thread #2.
    My guess would be that it is not necessary.

  8. #8
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    41

    Re: Buffer orphaning and multiple context

    After some seach, it seems you should be using some fences for synchronization (better than glFinish): http://www.opengl.org/wiki/Sync_Object

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Buffer orphaning and multiple context

    Okay, to be more precise:

    I know that in order to ensure the correctness of the data I most probably have to use sync objects but I'm more concerned about that orphaning the buffer object will involve the allocation of a new memory range and this information is encapsulated in the client side data of the buffer object. I'm more concerned about whether thread #2 will be aware of the changed client side data of the buffer object which is actually up to the driver implementation as this is a CPU sync issue rather than a GPU one.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  10. #10
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    41

    Re: Buffer orphaning and multiple context

    Should the actual memory range be reallocated by a call to BufferData, the buffer OBJECT itself remains, so there is no orphaning here: the buffer handles in both threads will still refer to the same valid OpenGL object.

    As long as you're referencing buffer data with origin-relative adresses (no "bindless" rendering) and you're not mapping buffer data to client process memory, this should be OK. It's likely you don't even have to unbind buffer from context #1 before using it in context #2 as long as you properly ensure there's no concurrent accesses to the underying data.

    Buffer objects are server state. Only binding points and mappings are client-side.

Posting Permissions

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