I'm interested in information about the speed of sin()
and cos()
in Open GL Shader Language.
The GLSL Specification Document indicates that:
The built-in functions basically fall into three categories:
- ...
- ...
- They represent an operation graphics hardware is likely to accelerate at some point. The trigonometry functions fall into this category.
EDIT:
As has been pointed out, counting clock cycles of individual operations like sin()
and cos()
doesn't really tell the whole performance story.
So to clarify my question, what I'm really interested in is whether it's worthwhile to optimize away sin()
and cos()
calls for common cases.
For example, in my application it'll be very common for the argument to be 0
. So does something like this make sense:
float sina, cosa;
if ( rotation == 0 )
{
sina = 0;
cosa = 1;
}
else
{
sina = sin( rotation );
cosa = cos( rotation );
}
Or will the GLSL
compiler or the sin()
and cos()
implementations take care of optimizations like that for me?
sin()
andcos()
?" If it's running on the GPU it can be said to be hardware accelerated. In any event your best bet is to try it out and profile it, as clock cycles on a GPU are somewhat meaningless without more context as to what you're doing. Even between different cards from the same vendor, there can be differences in number of execution units, so cycles only tells you part of the story. – Vicereinesin
might cost nothing, depending on where you use it and the hardware. – Woodwarduniform
vars. Doesn't make sense forin/attribute
vars, though. – Goa