Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Estimate number of registers required in GLSL shader

Lately I'm getting some

error C6020: Constant register limit exceeded at variable; more than 1024 registers needed to compile program

errors during compilation of a GLSL vertex shader, probably because of the number of uniform variables and I'm trying to figure out a way of estimating/calculating the number of registers required in the shader based on the uniforms that I have defined. Is there any guide or rule for that?

For example, am I correct to assume that variables up to vec4 in size require 1 register and mat4 require 4 registers? Are there any rules for this purpose?

like image 224
Greg K. Avatar asked Oct 28 '22 07:10

Greg K.


1 Answers

Graphics hardware is simply too diverse for any such estimation. Even your seemingly simple assumption:

variables up to vec4 in size require 1 register and mat4 require 4 registers?

That's not correct on a lot of modern hardware. It used to be, but that was years ago. Especially if you're talking about individual uniform variables; compilers can play all kinds of games with them.

There is no even remotely accurate way of estimating the number of such resources consumed by a piece of GLSL code. You can count the number of uniform components your code uses, but that's because OpenGL tells you how to do it. Beyond that, there's nothing you can do.

like image 69
Nicol Bolas Avatar answered Nov 02 '22 09:11

Nicol Bolas