Advertisement
Guest User

map buffer

a guest
Jan 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. I personally think, that GL3 style of map buffer on alBuffer and
  2. my idea of dataBuffer do the same thing a non copy buffer data setting,
  3. but map buffer also provides general way to update data on already created
  4. buffer, whereas the sole purposes of dataBuffer is to initialize alBuffer.
  5.  
  6. I actually think, that map buffer should be used for my dataBuffer, because
  7. it will make dataBuffer as thread-safe as possible.
  8.  
  9. As of now you can access data in my dataBuffer with
  10. ALVoid *ALDataBufferGetData(ALdataBuffer buffer)
  11.  
  12. which means, that multiple threads can work with the data and more importantly,
  13. there is no grantee, that the work with the data is done by the time you are
  14. giving the dataBuffer to the alBuffer.
  15.  
  16. therefore replacing:
  17. ALVoid *ALDataBufferGetData(ALdataBuffer buffer);
  18. ALsizei alDataBufferGetSize(const ALdataBuffer buffer);
  19.  
  20. with:
  21.  
  22. ALVoid *ALDataBufferMapData(ALdataBuffer buffer, ALsizei *size)
  23. // size return size of the writable data
  24.  
  25. void ALDataBufferUnmapData(ALdataBuffer buffer)
  26.  
  27. this will make it as thread safe as possible, because ALDataBufferMapData
  28. will have to grantee that it's the only active mapping (most likely with
  29. spin-lock).
  30.  
  31. alBufferDataFromBuffer call will use ALDataBufferMapData
  32. during the buffer processing and dataBuffer will have its size set to 0 and
  33. data pointer returned by ALDataBufferMapData to NULL before unmapping, or
  34. destroying the dataBuffer all together, I personally tend to think, that
  35. destruction of the buffer itself is more desirable, because GiveData clearly
  36. states, that you will no longer hold the dataBuffer after its over and users
  37. will not have to make alDataBufferDelete() call, but thats up to debate.
  38.  
  39.  
  40. So imho dataBuffer with map/unmap is very robust way of initializing the
  41. alBuffer, whereas map/unmap directly on alBuffer will have either stop the
  42. buffer from playing or fail if the buffer is in use or count on users, to
  43. don't modify the currently accessed memory, which are all problems caused by
  44. the fact, that it is not a alBuffer data initialization method, but a method to
  45. directly manipulate alBuffer internal data, which will always make it tempting
  46. to misuse it for streaming.
  47.  
  48. Whereas streaming use of dataBuffer is absolutely safe, eg. if user for some
  49. reason wants to have a big 200mb buffer instead of using classical
  50. alSourceQueueBuffers and does not really care when the sound is ready for
  51. playing. It is possible to slowly write the data into the dataBuffer via
  52. map/unmap and some global offset, that is held by the app and once the
  53. dataBuffer is ready give it to alBuffer.
  54.  
  55.  
  56. I personally don't really see why would anyone wanted to do this, because play
  57. as soon as possible is usually what you want and for that very safe
  58. alSourceQueueBuffers or less safe alBufferSubDataSOFT (if I understand it
  59. correctly app has to make sure it does write into memory used by alSources).
  60.  
  61.  
  62.  
  63.  
  64. extra thoughts:
  65.  
  66.  
  67. map/unmap does not prohibit from multithreaded data loading:
  68.  
  69. ptr = ALDataBufferMapData(...)
  70. // give N threads N data segment from the ptr
  71. // join threads
  72. ALDataBufferUnmapData(...)
  73.  
  74. I am not sure what uses this has.
  75.  
  76.  
  77. dataBUffer with map/unmap can actually be used for memory transform to
  78. other memory than RAM, this would require some device flags for
  79. alDataBufferCreate and I don't see any real use for it as of now.
  80.  
  81.  
  82.  
  83. I looked up the mesa implementation of openCL and they also just return new
  84. object in clCreateBuffer.
  85.  
  86. https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/clover/api/memory.cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement