Skip to content

Performance issue when caching uniform arrays #16355

@fernandojsg

Description

@fernandojsg

When working on the Multiview PR #16316 I've noticed that updating array of matrices uniforms impact the performance quite a lot.
This is mainly because of the cache, checking both elements are the same and then copying the array if not, seems to be a hot spot.

I'll try to get some numbers to compare using cache vs not using for arrays. I believe it could be interesting to consider avoid caching arrays or maybe provide a way to define that you don't want to cache some uniforms if you already know they'll be changing per frame.

Looking at the Babylon's sourcecode it seems they just cache simple data https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/effect.ts#L1113-L1122 but not arrays https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/effect.ts#L1131-L1174.

So some ideas:

  • Avoid using cache for Array uniforms
  • Allow the user to define which uniforms must not use cache
  • Add a new boolean param to setValue to force non-cache update, eg: uniform.setValue(gl, 'name', [a,b], true)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions