3 ms·
The problem is with the tool he's using. It doesn't seem to show the "idle" time when calling the OpenGL method. He's very likely hitting a CPU/GPU stall while
by speps 11y ago
The problem is with the tool he's using. It doesn't seem to show the "idle" time when calling the OpenGL method. He's very likely hitting a CPU/GPU stall while the data is uploaded to VRAM.
As mentioned by Scott in the comments section of the article, the solution is usually like this (D3D12 has removed dynamic resources for example [0]) :
So this means if you glBufferSubData into the same
address between every drawcall, the opengl driver is
forced to execute the command then sync before copying
the new data over the old data, which is really slow.
What you are meant to do instead is create a buffer
with glBufferData that is large enough to hold at least
one frame worth of uniforms. Then use glBufferSubData
with a **different offset** for each drawcall’s uniforms,
so they end up next to each other in GPU memory. Treat
it as a circular buffer.
[0] https://msdn.microsoft.com/en-us/library/windows/desktop/dn899125%28v=vs.85%29.aspx https://msdn.microsoft.com/en-us/library/windows/desktop/dn8...
- fulafel 11y agoOr maybe not the solution, Scott has posted a "never mind" followup to his own comment. Edit: also I think the blog author had no problem getting to the waiting diagnosis despite the tools not splitting the time into idle and working parts, since he zeroed in early on the option 3, "The GPU is waiting on the CPU (or vice versa) for something"
- speps 11y agoBut his conclusion was wrong in my opinion. Updating many many sub parts of an array in random order will always be slower than updating it all at once. He also didn't reach the usual solution to double or triple buffer everything that is uploaded to the GPU.
- kllrnohj 11y agoDid you not bother reading the article? At least half of it is talking about it being a stall and trying to figure out why it's stalling.
- speps 11y agoMy point was that his conclusion seems wrong but I didn't make that clear. He didn't fix the stalling, he just found a work around which seems more like a hack.