shaveenk
shaveenk

Reputation: 2083

Underlying implementation of normalize() and length() in GLSL

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?

Upvotes: 1

Views: 3326

Answers (2)

Peter O.
Peter O.

Reputation: 32898

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.

Upvotes: 4

rotoglup
rotoglup

Reputation: 5273

The answer is wildly GPU/vendor dependent ; but it may give you a clue to look at the output provided by AMD Shader Analyser or take a peek into 'binary' dumps of compiled shaders on NVidia - last time I checked (long time ago), they were containing assembly code in text form.

Upvotes: 2

Related Questions