3

I have been working with GL_MAP_PERSISTENT_BIT and glBufferStorage/glMapBufferRange. I am curious if there is an improvement in performance possible using GL_MAP_UNSYNCHRONIZED_BIT.

I already found Opengl Unsynchronized/Non-blocking Map

But the answer seems to be a bit contradictory to me. It's said there that you need to sync or block when using this flag. What is the point of setting it unsynchronized if I have to sync it later then anyway? Also I tried this combination and was not able to see any performance difference. Does it even make sense together with persistent mapped buffers? I found literally no examples about such a usage. The mentioned topic also says that you can

issue a barrier or flush that region of the buffer explicitly

But every attempt I made so far using these only resulted in garbage.

I am using currently triple buffering, but since I have to deal with very small chunks of data sometimes which I hardly can batch I had to find out that glBufferData is often faster in these cases and persistent buffers only of (huge) benefit if I can batch and reduce also the amount of drawcalls. Using GL_MAP_UNSYNCHRONIZED_BIT could be the key here.

Can anyone give me a working example, in case it even makes sense in this combination?

Christopher Oezbek
  • 17,629
  • 3
  • 48
  • 71
Gnampf
  • 875
  • 1
  • 12
  • 21

1 Answers1

4

What is the point of setting it unsynchronized if I have to sync it later then anyway?

The point, as stated by that answer, is that OpenGL isn't doing the synchronization for you. You control when the synchronization happens. This means that you can ensure that it doesn't happen at an inappropriate time. By using your own synchronization, you can also ask the question, "are you finished using the buffer?" which is not a question you could ask without your own sync system.

By using unsynchronized mapping, you stop the implementation from having to check its own internal sync in addition to your synchronization.

However, that answer you linked to applies primarily to non-persistent mapping (since that's what the question was about). Unsynchronized mapping only applies to the map call itself. It prevents GL from issuing internal synchronization due to you calling glMapBufferRange.

But unsynchronized mapping doesn't really affect persistent mapping because... well, it's persistent. The whole point of the feature is that you keep the buffer mapped, so you're only going to call glMapBufferRange once. And the unsynchronized bit only applies at the moment you call glMapBufferRange.

So whether you use unsynchronized or not with your persistent mapping call is essentially irrelevant.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829