Async Upload of Meshes

Started by
4 comments, last by Lolums 8 years, 1 month ago
My game world is divided into chunks and spikes horribly every time I upload chunk meshes, as there is one mesh per chunk that contains a few thousand vertices and I upload a lot of them. Is there a way to do this on a different thread and use them once they're uploaded?
Advertisement
Yes, look into un-/map VBOs: https://www.opengl.org/sdk/docs/man/html/glUnmapBuffer.xhtml

You would approach this like this:
1. map VBO: this will give you a pointer to memory, which you can access from your CPU regardless of thread (just standard sync considerations, but independent of OGL context).
2. update the memory block
3. unmap VBO: this will result in an asynchronously upload if the memory is located in videomemory (DMA)
4. wait until VBO has been uploaded, then render it (else you will stall again).

The latter is important, don't try to use the VBO until the upload has been finished to avoid sync trouble. If you need to render something, either render a dummy or start uploading your mesh earlier and not just at the time of entering your vision.

Here are more readups:
https://www.opengl.org/wiki/Buffer_Object_Streaming
https://www.opengl.org/wiki/Buffer_Object

Thanks a bunch for these. It's really useful!

Yes, look into un-/map VBOs: https://www.opengl.org/sdk/docs/man/html/glUnmapBuffer.xhtml

You would approach this like this:
1. map VBO: this will give you a pointer to memory, which you can access from your CPU regardless of thread (just standard sync considerations, but independent of OGL context).
2. update the memory block
3. unmap VBO: this will result in an asynchronously upload if the memory is located in videomemory (DMA)
4. wait until VBO has been uploaded, then render it (else you will stall again).

The latter is important, don't try to use the VBO until the upload has been finished to avoid sync trouble. If you need to render something, either render a dummy or start uploading your mesh earlier and not just at the time of entering your vision.

Here are more readups:
https://www.opengl.org/wiki/Buffer_Object_Streaming
https://www.opengl.org/wiki/Buffer_Object

I've been playing around with this but found that glMapBuffer only returns a buffer after I call glBufferData. However, this is pretty useless because glBufferData uploads the data in the same thread.

How are we supposed to use this?


I've been playing around with this but found that glMapBuffer only returns a buffer after I call glBufferData. However, this is pretty useless because glBufferData uploads the data in the same thread.
You use glBufferData once to create the buffer, then use glMapBuffer many times to update it.

As for sync's - there's a lot of different kinds to look out for, many of which won't be fixed by simply using another CPU thread. e.g. If you attempt to update a resource that's currently in use by the GPU, then you're forcing the driver to block all CPU-side OpenGL calls until the GPU has finished consuming all previous commands, making that resource safe to access. The PDF below outlines the common strategies for "dynamic" (often updated) buffers:

https://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf


I've been playing around with this but found that glMapBuffer only returns a buffer after I call glBufferData. However, this is pretty useless because glBufferData uploads the data in the same thread.
You use glBufferData once to create the buffer, then use glMapBuffer many times to update it.

As for sync's - there's a lot of different kinds to look out for, many of which won't be fixed by simply using another CPU thread. e.g. If you attempt to update a resource that's currently in use by the GPU, then you're forcing the driver to block all CPU-side OpenGL calls until the GPU has finished consuming all previous commands, making that resource safe to access. The PDF below outlines the common strategies for "dynamic" (often updated) buffers:

https://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf

Thanks a bunch. That was useful and I see what I did wrong with glMapBuffer. It turns out that performance was slightly worse for me (the way I implemented it) and that my lag spikes weren't caused by mesh uploads. I did learn a lot though.

This topic is closed to new replies.

Advertisement