views:

35

answers:

1

In a vertex shader, I calculate a vector using only uniforms. Therefore, the outcome of this calculation is the same for all instantiations of the vertex shader. Should I just do this calculation on the CPU and upload it as a uniform? What if I have ten such calculations? If I upload a lot of uniforms in this way, does CPU-GPU communication ever get so slow that recomputing such values in the vertex shader is actually faster?

A: 

I actually depends on the uniforms/vertex count ratio. In the case vertices are more than the uniform variables, it's probably better to compute uniforms on CPU, which is the most frequent scenario.

In the case uniforms values are many and their computation is complex (i.e. inverse matrix), while vertices count is low, it may be better to off load the CPU and perform computation on GPU.

The ratio threshold value is difficoult to determine, since many factor influence the shader execution. Normally its better to compute most of uniforms on CPU, to offload the shader execution.

A note: once you set the uniform variables, the shader program mantains their values untill its relinked again.

Luca