So the VBO extension document suggests an interesting usage for doing multi-threaded data transfers to/fro GL server.
Say you have two threads, each with their own GL context. They share namespaces, so they have access to each other’s texture, display lists, buffer objects, etc.
Producer Thread:
get buffer object from pool
fill buffer with data
notify Thread 2 of buffer object name
Consumer Thread:
map buffer object
read data, do stuff
unmap buffer object
return buffer object to pool
Thread 2 can also just getData instead of mapping.
Basically, Thread 1 has no blocking calls so it can still issue calls to GL without waiting for the map to complete. I think you can do a similar thing to write data to GL asynchronously.
The bad news is that it doesn’t work on my 6800GT with PBOs. The ~60 drivers crash, and the ~65 drivers crashes when you getData and gives you garbage when you map.
Question 1:
Did I interpret the spec correctly? Is there some reason why I shouldn’t expect this to work?
Question 2:
Has anyone done anything like this or gotten it to work?
Thanks all.
-Won
–EDIT–
It DOES work! Turns out we had a problem with wglShareLists… Yay.
Using the pointer from glMapBuffer I am filling the VBO from another thread that has no GL context. It seems to work well on ATI and NVIDIA drivers. Am I violating any rules?
As long as the context that mapped does not unmap while you are filling, it should be ok. If it does unmap, you’re in trouble; there’s no guarantee that the buffer won’t be moved somewhere else at any moment.
loop checking for producer thread completion,
use the previous buffer for GL drawing until
producer completes
For good performance using a VBO pointer, the buffer must be filled sequentially. There are special cases to handle if a buffer is lost. Use VSYNC and avoid the use glFinish to allow plenty of CPU time for the low priority thread to run.