9 ms·
I don't work on the nvidia side of things but it's likely to be the same. Shader replacement is only one of a whole host of things we can do to make games run f
by Cieric 2y ago
I don't work on the nvidia side of things but it's likely to be the same. Shader replacement is only one of a whole host of things we can do to make games run faster. It's actually kind of rare for use to do them since it boats the size of the driver so much. 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.
- SpaghettiCthulu 2y ago> 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?
- kevingadd 2y agoI would guess it's done for compatibility or quality reasons
- dahart 2y agoOnly 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.
- Cieric 2y agoThat'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.
- dahart 2y agoWhat GPUs aren’t IEEE compliant? I don’t think that’s been true for more than a decade.
- Cieric 2y agoAfter 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.
- dahart 2y agoWhat 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.
- Cieric 2y agoI 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.
- 2y ago
- chrisjj 2y ago> > 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. That will break code sufficienly reliant on the behaviour of sungle precision, though.
- david-gpu 2y agoObviously, which is the reason you don't do something like that without appropriate amounts of testing.
- chrisjj 2y agoTesting on platforms that perverts the precision is outside appropriate, I would say.
- Dylan16807 2y agoCode depending on specific low precision is very likely to be so fragile it won't make it anywhere near release.
- chrisjj 2y agoConsider an RNG.
- Dylan16807 2y agoI consider a floating point RNG in a shader that is seeded for reproducibility to be a bad idea.
- chrisjj 2y agoWhy, pray?
- Dylan16807 2y agoGPUs often have weird sizes for optimal behavior and you have to depend on math-based optimizations never being applied to your code. In my opinion, floating point shaders should be treated as a land of approximations. You asked in another comment why /width*width isn't optimized out by the compiler. But it's changes just like that that will break an RNG!