Jump to content
  • Advertisement
Sign in to follow this  
Lolums

Async Upload of Meshes

This topic is 1012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites


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

Share this post


Link to post
Share on other sites

 


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!