Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cost of Branching on uniforms on modern GPUs

Tags:

opengl

glsl

When using GLSL on modern (GL3.3+) GPUs, what is the likely cost of branching on a uniform?

In my engine I'm getting to the point where I have a lot of shaders. And I have several different quality presets for a lot of those. As it stands, I'm using uniforms with if() in the shaders to choose different quality presets. I'm however worried that I might achieve better performance by recompiling the shaders and using #ifdef. The problem with that is the need to worry about tracking and resetting other uniforms when I recompile a shader.

Basically what I want to know is if my fears are unfounded. Is branching on a uniform cheap on modern GPUs? I have done a few tests myself and found very little difference either way, but I've only tested on an nVidia 680.

like image 433
Jagoly Avatar asked Mar 17 '15 04:03

Jagoly


1 Answers

I will admit that I'm not an expert, but perhaps my speculation is better than nothing.

I would think that branching on uniforms is indeed fairly cheap. It's clearly much different from branching on texture or attribute data, since all the ALUs in the SIMD will follow the same code path from the shader, so it is a "real" branch rather than an execution mask. I'm not too sure how shader processors suffer from branch bubbles in their pipeline, but the pipeline is certainly bound to be more shallow than in general-purpose CPUs (particularly given the much lower clock-speeds they typically run at).

I wish I could be more helpful and I'd also appreciate if someone else can answer more authoritatively. I, for one, wouldn't worry too much about branching on uniforms, however. But as always, if you have the possibility, do profile your shader and see if it makes any noticeable difference.

like image 172
Dolda2000 Avatar answered Oct 29 '22 16:10

Dolda2000