uniforms and switching shader programs

Hi,

I guess when I switch to another shader using glUseProgram
and then back to the previous shader I have to upload all
required uniform data again?

Is that one of the reasons to use Uniform Buffer Objects?

Thanks

No, uniforms will be remembered. The driver will re-upload (sysram-vram) (or vram-vram copy) the necessary stuff.
UBOs are for large chunks of constants-data, accessible as arrays of structs, and being fast to bind (no upload or vram-vram copy).

Nope. Program object remembers them. Don’t set them again unless they change to save cycles.

Is that one of the reasons to use Uniform Buffer Objects?

No. Though I confess not to be an expert on the reasons “to” use UBOs. IIRC reading these forums, UBO reads can be more expensive to access, but you can set a bunch of uniforms in one call (since they’re all in one buffer).

Inferring a bit from other posts I get the feeling that UBOs are stored in device global memory and pulled by the shader, whereas plain ol’ uniforms are stored in device local memory and pushed to the shader (to use OpenCL memory space names). The latter being faster of course. Don’t put any stock in that though. I’m not a driver developer. Measure the perf yourself and see which you prefer.

Thanks a bunch! In this case I’ll add some logic to
my code to avoid unnecessary uniform data uploads :slight_smile: