What is the underlying implementation of normalize() and length() in GLSL? I am trying to gauge the performance of my code and what to know what instructions are being executed for certain built in functions in GLSL. Where can I get more information on the underlying implementation of other built in functions?
The OpenGL Shading Language spec generally doesn't require a particular implementation of its functions, as long as they give the results it specifies. In GLSL 4.5, for example, see the correctness requirements on page 84, and the functions length()
and normalize()
on page 150.
Moreover, GLSL doesn't define a binary format for compiled shader code; that format is accordingly implementation dependent.
However, in general, I presume the length
function would be implemented using a dot product and a square root, and the normalize
function would be implemented by calling the length
function and also doing three divisions, or one division and a vector multiplication.