Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Integers faster than floats in shader?

2,452 views
Skip to first unread message

VelociChicken

unread,
Mar 12, 2012, 12:13:10 PM3/12/12
to
Hello, I'm about to do some lengthy algorithm in GLSL, and it can be
done using integers.
I just wanted to know whether it's actually worth using floats instead
(mainly because of int to float conversions in texture2D during the
loop). Or is it worth sticking to integers because they could be a lot
faster?
No fixed point maths are involved, just additions in loops.

Basically, which is fastest, int or float?

Thanks,
Dave.


Andy V

unread,
Mar 12, 2012, 7:03:22 PM3/12/12
to
Depends on the graphics board, just as any other question
involving performance.

--
Andy V

fungus

unread,
Mar 13, 2012, 10:09:36 AM3/13/12
to
On Monday, March 12, 2012 5:13:10 PM UTC+1, VelociChicken wrote:
>
> Basically, which is fastest, int or float?
>

Graphics cards are designed to use floats,
most graphics cards don't even have support
for ints.

Even if they do, there's no magic reason
why ints should be faster than floats.
I'd be surprised if you can find a graphics
card where ints are faster than floats.

> (mainly because of int to float conversions
> in texture2D during the loop).

That conversion will be free.

VelociChicken

unread,
Mar 13, 2012, 3:09:57 PM3/13/12
to
Thanks for the replies guys.
So I can lookup into a texture using integer numbers in pixels?

fungus

unread,
Mar 13, 2012, 5:00:51 PM3/13/12
to
On Tuesday, March 13, 2012 8:09:57 PM UTC+1, VelociChicken wrote:
> Thanks for the replies guys.
> So I can lookup into a texture using integer numbers in pixels?
>

Sure...but why? There's really no point
in using integers in shaders.

If you want the lookup to discard the
fractional part of the coordinate it's
probably better to set the texture filter.
I can't imagine the texture unit will
use ints internally so you're converting
to int and back again for no good reason.

VelociChicken

unread,
Mar 13, 2012, 5:10:40 PM3/13/12
to
Right, ok thanks for that. I must keep thinking 'floats' all the way. :)

D.

Nobody

unread,
Mar 15, 2012, 12:16:27 AM3/15/12
to
On Tue, 13 Mar 2012 19:09:57 +0000, VelociChicken wrote:

> So I can lookup into a texture using integer numbers in pixels?

Yes. The GLSL texelFetch() function retrieves a texel using integer
coordinates and an explicit mipmap level. No filtering or wrapping is
performed.

But, in general, you should use the appropriate data type. Integers are
unlikely to be faster than floats, and there are reasons why they may be
slower. In particular, integer calculations must be exact, whereas
floating-point calculations can be approximated based upon the usage of
the result (e.g. a float which is stored in the framebuffer only needs to
be accurate to within the precision of the framebuffer).


0 new messages