3 ms·
I love crazy shader stories! My crazy shader story: 8 bit floats. Back in 2007-ish, I was having a hell of a time porting a shader from my desktop to my lapto
by jjoonathan 6y ago
I love crazy shader stories!
My crazy shader story: 8 bit floats.
Back in 2007-ish, I was having a hell of a time porting a shader from my desktop to my laptop. For the most part it seemed to work but the output was all one color. That isn't particularly strange for a bug in the shader world, so I went about bisecting it and narrowed the problem down to a critical statement. The input parameters were correct, as verified by color-mapping them, but whenever I performed a division the output would fix to a single color. I could get division to work by feeding it different parameters, though, so what could be the problem?
My big break happened when I noticed that a tiny zone around the edges was outputting a different color. The calculation was happening, it was just unexpectedly almost always producing a single value due to extreme rounding. With the problem identified, it was easy enough to work around by using a scaling factor. After paging through Intel documentation I finally found the cause: the integrated graphics card supported floating point all right, but with 8 bit floats. Implicit, mind you, and there was no compiler warning. I asked for a float and it gave me a float, what's the problem? ¯\_( ツ )_/¯
I'm guessing someone tasked the Intel Integrated graphics team with supporting floating point but didn't really give them the transistor or TDP budget for it, so some evil genius noted that they never specified the bit width and cheerfully squared that circle.
- valleyer 6y agoGreat story. Which Intel integrated GPU, if you remember? And what shader language? It looks like GLSL expects `float` to be a normal float32. https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Scalars https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Scalars
- kevingadd 6y ago"The specific sizes and formats for integers and floats in GLSL are only for GLSL 1.30 and above. Lower versions of GLSL may not use these exact specifications." Pre-1.3.0 was a truly dark era. Lots of really nasty driver and hardware issues lurking around.
- jjoonathan 6y agoIt was a Core 2 Duo white plastic macbook (or were they still iBooks?). I don't remember the exact GPU, but I do remember that it was the very early "wild west" days of GPGPU. Getting GPUs to do things other than draw textured polygons was a strange, crazy, cool idea. It would be years until transcoding and media editing tools managed to make it work. My PPC mac still absolutely smoked the new intel mac at those tasks, even with vector extensions, but of course the transition was underway and there would be no going back. The language was GLSL. I'm glad to see that sometime in the last decade and a half they decided to mandate float32. Pulling out the float8s to win a benchmark these days would be... something!
- formerly_proven 6y agoFunny how this turned around - until very recently low-precision (<32 bit floats) arithmetic was intentionally limited on consumer cards - iirc FP16 rate was limited to 1/100th or something crazy like that. Intel being the true pioneers they are not only made this available at full performance to their customers, but even the default!
- jhgb 6y ago> and this is what they came up with Programmers and insufficient specifications, name a more iconic duo?
- golergka 6y agoI had a very similar issue with mobile development: our QA dug up some weird chinese phone where some of our shader colors were way off. After spending 2 days on debugging, I found out it used 12 bit floats. Closed as "won't fix".
- jjoonathan 6y agoI love it! 37.5% precision float, this_is_fine.jpg
- kbelder 6y agoYou made me go looking. I don't think there's a universal standard, but an 8-bit float would probably be broken down as: 1 bit sign 4 bit exponent 3 bit mantissa This allows it to represent numbers in the range of 480 down to 0.0078 (and their negatives). Of course, it can only accurately represent 256 distinct numbers out of that range, so accuracy will be bit compromised. I wonder if they were ever legitimately used for a real-world program?