You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UniformBlock.setUniforms() appears to mark needsRedraw unconditionally
#2599
Hi! I've been profiling a deck.gl application and noticed what appears to be unnecessary GPU buffer writes on every frame. I'd like to verify this before opening an issue or PR since I'm not familiar with the luma.gl internals.
What I'm seeing
UniformBlock.setUniforms() calls setNeedsRedraw() after every _setUniform() call, regardless of whether the uniform value actually changed:
_setUniform() correctly short-circuits via arrayEqual when values haven't changed, but it returns void, so the caller has no way to know whether a change occurred.
Since needsRedraw gates the uniformBuffer.write() call in UniformStore.updateUniformBuffer(), this seems to result in CPU-to-GPU buffer uploads every frame for every uniform block, even during steady-state rendering where no uniforms are actually changing.
In our application this adds up to a meaningful amount of per-frame overhead. We applied this fix locally in our application and saw a significant improvement in rendering performance.
This is a minimal change. _setUniform returns a boolean, and setUniforms only marks needsRedraw when something actually changed.
Context
Note that prior to the arrayEqual fix in #2538, this was compounded further, arrayEqual always returned false for array-typed uniforms, so _setUniform never short-circuited for those. This also means the setUniforms issue had no observable effect before #2538. Now that arrayEqual works correctly, _setUniform properly detects unchanged values, but setUniforms still marks needsRedraw unconditionally, negating the benefit of the fix.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hi! I've been profiling a deck.gl application and noticed what appears to be unnecessary GPU buffer writes on every frame. I'd like to verify this before opening an issue or PR since I'm not familiar with the luma.gl internals.
What I'm seeing
UniformBlock.setUniforms()callssetNeedsRedraw()after every_setUniform()call, regardless of whether the uniform value actually changed:luma.gl/modules/core/src/portable/uniform-block.ts
Lines 54 to 61 in 92abf5f
_setUniform()correctly short-circuits viaarrayEqualwhen values haven't changed, but it returns void, so the caller has no way to know whether a change occurred.Since
needsRedrawgates theuniformBuffer.write()call inUniformStore.updateUniformBuffer(), this seems to result in CPU-to-GPU buffer uploads every frame for every uniform block, even during steady-state rendering where no uniforms are actually changing.In our application this adds up to a meaningful amount of per-frame overhead. We applied this fix locally in our application and saw a significant improvement in rendering performance.
Possible fix
Would something like this be the right approach?
This is a minimal change.
_setUniformreturns a boolean, andsetUniformsonly marksneedsRedrawwhen something actually changed.Context
Note that prior to the arrayEqual fix in #2538, this was compounded further,
arrayEqualalways returnedfalsefor array-typed uniforms, so_setUniformnever short-circuited for those. This also means thesetUniformsissue had no observable effect before #2538. Now thatarrayEqualworks correctly,_setUniformproperly detects unchanged values, butsetUniformsstill marksneedsRedrawunconditionally, negating the benefit of the fix.All reactions