News for hackers. Stuff that matters.
Re:Don't "optimize" conditional moves in shaders with mix()+... by SpaghettiCthulu on Sunday February 09, 2025 @11:11AM (#42991517)
> A lot of our options do change how shaders work though, like forcing a shader to use double precision floats instead of the single it was compiled with.

What benefit would that give? Is double precision faster than single on modern hardware?

Re:Don't "optimize" conditional moves in shaders with mix()+... by kevingadd on Sunday February 09, 2025 @12:23PM (#42991991)
I would guess it's done for compatibility or quality reasons
Re:Don't "optimize" conditional moves in shaders with mix()+... by dahart on Sunday February 09, 2025 @06:46PM (#42995352)
Only more precision. But no, doubles are not faster. At best they’re the same instruction latency & throughput as singles, and that’s only on a few expensive pro/datacenter GPUs. Even if they are technically the same instruction speed, they’re still 2x the memory & register usage, which can compromise perf in other ways. Doubles on consumer GPUs are typically anywhere from 16 to 64 times slower than singles.

FWIW, I’ve never heard of shader replacement to force doubles. It’d be interesting to hear when that’s been used and why, and surprising to me if it was ever done for a popular game.

Re:Don't "optimize" conditional moves in shaders with mix()+... by Cieric on Sunday February 09, 2025 @07:41PM (#42995697)
That's specifically because gpus aren't IEEE compliant, and calculations will drift differently on different gpus. Double precision can help avoid divide by zero errors in some shaders because most don't guard against that and NANs propagate easily and show up as visual corruption.
Re:Don't "optimize" conditional moves in shaders with mix()+... by dahart on Monday February 10, 2025 @02:11PM (#43003985)
What GPUs aren’t IEEE compliant? I don’t think that’s been true for more than a decade.
Re:Don't "optimize" conditional moves in shaders with mix()+... by Cieric on Tuesday February 11, 2025 @11:23AM (#43014706)
After a bunch of testing and looking around I think I should actually change my statement. GPUs do offer IEEE floating point compliance by default, but don't strictly adhere to it. Multiple optimizations that can be applied by the driver developers can massively effect the floating point accuracy.

This is all kind of on the assumption that the accuracy of floating point multiplication and division is in the IEEE spec, I was told before that it was but searching now I can't seem to find it one way or the other.

I believe one of the optimizations done by nvidia is to drop f32 variables down to f16 in a shader. Which would technically break the accuracy requirement (as before if it exists). I don't have anything I can offer as proof of that due to NDA sadly though. I will note that most of my testing and work is done in PIX for Windows, and most don't have anti-cheat so they're easy to capture.

Re:Don't "optimize" conditional moves in shaders with mix()+... by dahart on Tuesday February 11, 2025 @08:27PM (#43020708)
What shaders (presumably GLSL & HLSL) do precision wise isn’t an IEEE compliance issue, it’s either a DX/Vulkan spec issue, OR a user compiler settings issue. Dropping compliance is and should be allowed when the code asks for it. This is why GLSL has lowp, mediump, and highp settings. I think all GPUs are IEEE compliant and have been for a long time.
Re:Don't "optimize" conditional moves in shaders with mix()+... by Cieric on Thursday February 13, 2025 @11:10AM (#43037387)
I agree on the dropping compliance when asked for aspect, the problem I'm referring to more is the driver dropping compliance without the game asking for it. If the underlying system can randomly drop compliance when ever it thinks it's fine without telling the user and without the user asking, I would not consider that compliant.
Re:Don't "optimize" conditional moves in shaders with mix()+... by dahart on Friday February 14, 2025 @10:24AM (#43049249)
That is fair, if true. But I’m very skeptical any modern drivers are dropping compliance without being asked. The one possibility I could buy is that you ran into a case of someone having dropped precision intentionally in a specific game in order to “optimize” a shader. Otherwise, precision and IEEE compliance is the prerogative of the compiler. The compiler is sometimes in the driver, but it never decides on it’s own what precision to use, it uses either default or explicit precision settings. The only reason it would not produce IEEE compliant code is if it was being asked to.