3 ms·
This a great and concise writeup, thanks. But I was left wondering what the actual problem was. Why is glBufferMap slow? Is it just the impedance mismatch betw
by stefan_ 9y ago
This a great and concise writeup, thanks.
But I was left wondering what the actual problem was. Why is glBufferMap slow? Is it just the impedance mismatch between D3D and GL that don't have the same synchronization guarantees for that specific call? Why does Wine have it's own command handling thread when very likely, the underlying OpenGL driver has one, too?
- Jasper_ 9y agoglMapBuffer doesn't have any ability to declare that you won't overwrite data. All you can say is whether you want read/write access to the buffer. So the driver has to assume that the client might overwrite in-flight data, so synchronization is required. As for the command stream handling, it makes decent sense to do translation up-front and your drawing commands into a command stream so a separate thread can just hammer through it as fast as possible, rather than doing GL calls in-line with the translation. Partly so the game can return to doing its thing as fast as possible, and partly to fix issues with GL's threading model being horrible ( see e.g. https://bugs.winehq.org/show_bug.cgi?id=24684 https://bugs.winehq.org/show_bug.cgi?id=24684 )
- kllrnohj 9y ago> glMapBuffer doesn't have any ability to declare that you won't overwrite data. Well, yes and no. glMapBufferRange, which is basically a drop-in replacement for glMapBuffer, does have such a flag, it's GL_MAP_UNSYNCHRONIZED_BIT. glMapBufferRange requires OpenGL 3.0 whereas glMapBuffer exists all the way back to OpenGL 2.0 but this looks more like just an oversight in Wine than anything else.
- twtw 9y agoWine uses glMapBufferRange when available, and has logic to translate D3DLOCK_NOOVERWRITE to GL_MAP_UNSYNCHRONIZED_BIT. I don't understand what the current implementation is doing that is causing wined3d_resource_map to block. https://github.com/wine-mirror/wine/blob/538263d0efe725124df88ce1cce124bc3ad7e2af/dlls/wined3d/resource.c#L422 https://github.com/wine-mirror/wine/blob/538263d0efe725124df...
- twtw 9y agoThis is an excellent question. The current wine implementation using OpenGL should mirror the behaviour of D3D, since it is using glMapBufferRange and passing GL_MAP_UNSYNCHRONIZED_BIT when possible. I am also wondering what is actually going on that is hurting performance. EDIT: After further research and more thought, I suspect that the "pipeline stall" doesn't involve waiting for the GPU to complete work using the buffer, just waiting for the driver. The map/unmap with overwrite or discard is working as intended, but the persistent buffer heap he implemented outperforms it because it reduces the number of calls into the driver required. I initially had the impression that the existing wine implementation was somehow deficient, but really what the author did was find a way to use the new persistent buffers feature to optimize D3D code using the older per-frame map/unmap method. This is in fact what the post essentially said (after a re-read), I just misunderstood and thought the pipeline stall was actually waiting for the GPU. The note in the post about the "GPU" line really being the driver is important.
- acomminos 9y agoThere's two main parts to the stall, which aren't well illustrated by the diagram (I'll get on updating it): 1. Waiting for the resource to exit the command stream (wined3d_resource_wait_idle). 2. Waiting for the CS thread to finish after the map (occurs in wined3d_cs_map). It's a pipeline stall because the D3D thread has to wait for the CS thread to do things, and thus is unable to dispatch more commands to the CS (and thus the GPU) during this time. I don't consider the actual glMapBufferRange to be part of the stall. Edit: saw your edit :)
- twtw 9y agoThanks for clarifying, that makes sense. I'm glad you saw the edit. I initially wrote it based on my first interpretation of what you wrote, but after re-reading I realized that your description was totally accurate, I just misunderstood. Great work, and thanks for writing it up.