I'm trying to use an uniform array of matrices in my compute shader. However, it's really slow. I've narrowed it down to this lines of code:
uniform mat4 someMatrixArray[64];
...
vec4 result = vec4(0);
for (int i = 0; i < 2048; i++) {
result += someMatrixArray[i%64][0] * 0.01;
}
When not accessing someMatrixArray I get 700+ fps. When accessing it, I have 10 fps. Anybody has an idea what could cause this? Could it be a driver issue?
I already tried to unroll the loops (via #pragma optionNV (unroll all)
) but that didn't help. I'm using a GTX670 with the latest drivers on windows 7.
Edit:
The generated assembly for the inner loop is:
MAD.F R0.xyz, c[196], {0.0099999998, 0, 0, 0}.x, R0;
result
can be determined statically without needing to be evaluated in the shader. Why not calculate it on the CPU and pass in the final value ofresult
to the shader as a uniform? \$\endgroup\$result += someMatrixArray[i%64][0] / 100;
\$\endgroup\$