Cost of updating (many) uniforms

Hey folks, had a performance intuition question.

I have ~20 animation parameters that I want to interpolate based on some function of the elapsed time, ideally at 60fps.

I could either:

  • calculate the updated interpolated value in JS, and then update the uniform for each parameter separately (this would be 1200 uniform updates per second);

  • update a single parameter on the uniform, time, and calculate the interpolated values for each of these other animation parameters in GLSL (this would be about 60 uniform updates per second).

What are the performance characteristics of each approach? Is one meaningfully more expensive than the other?

What if there were 200 animation parameters instead of just 20?

What if each update was to a nested value, e.g. uniform.animationParameter.time?

Appreciate any advice!

If you first have to recalculate 1200 uniforms on the CPU side in every frame before you pass them on to the GPU, then the CPU will suffer. The GPU can do this much better because it has several hundred cores.
The CPU is the manager and the GPU is the worker. A nice example of how valuable the executive workforce (GPU) is :smile:
But both are indispensable CPU and GPU. But the CPU is excellent at managing work and the GPU is excellent at executing work. Your numerous calculations are better in the GPU

Just to clarify, it wouldn’t be 1200 every frame.

It would be 20 every frame, at 60fps, so 1200 every second.

I wouldn’t get too caught up in the calculations themselves, we know how to measure that. But I’m much more curious about the uniform updates themselves – are those expensive to do at scale?

These updates happen regardless. If you switch to a different mesh, same material the uniforms are updated. If you switch to a different mesh, different material this is orders of magnitude more expensive.

If you had say a million objects or values that say need interpolation, then you could get mileage out of uploading some values first and interpolating later (like you said using just the time uniform).