Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a very interesting article, it was fun to learn what shaders are and why I have to wait for them to compile every time I play Call of Duty.

What I'd like to know is why game developers can't provide a service / daemon that will perform shader compilation when shaders or drivers change so I don't need to waste 25 minutes of my precious gaming time when I load CoD and see they need compiling. My computer has been sitting there unused all week. Steam was smart enough to download game updates in that time, why isn't your game smart enough to recompile my shaders on an idle machine?



One alternative that many games choose is to do it on-demand which is felt as micro-stutters while you play but this is a poor choice for a competitive game like CoD.

We take a slightly different approach: we don't do any up-front in the launcher but do as much as possible on the level loading screen; it's not perfect though: due to the way some legacy code works we can't always anticipate all permutations ahead of time so you get the occasional micro-stutter as missing shaders are sent to the driver.

You can get away with being lazier with modern drivers because they will cache the compiled result for you (if you don't cache the pipeline state object yourself in DirectX 12) but on older DirectX drivers for Intel IGPs there wasn't a cache at all so the first 30 seconds after loading into a level would be very busy.


A better approach is to drastically reduce the number of individual shaders. Having tens of thousands of shader variants is an unfortunate side effect of treating shaders as asset data, and building them with visual noodle-graph tools by artists. No game actually needs tens of thousands of shaders.


GPUs suck at things like e.g. data driven branches. What looks like one shader at a high level ends up creating many separate compiled blobs, because you really want some of the parameters baked in at compile time to avoid the performance tanking, and this means you need to compile a version of the shader for every combination of values those parameters can take.


Uniform branches are free pretty much

The main issue is that gpr allocation is static and worse case. So on the majority of hardware you hose your occupancy.


Sometimes it pays off to have an ubershader with all the options though https://dolphin-emu.org/blog/2017/07/30/ubershaders/


Steam actually shares compiled shaders between users with the same hardware / driver version, but only for Vulkan I believe.


The shared compiled shaders are only for the Steam Deck I believe. Other hardware will require a background compile or will compile at launch.


Nope, it's been available in the Steam client beta since 2016, and somewhere around 2017 it went into the mainline client.


Yes, it'll share a shader cache that isn't precompiled is what I mean. As opposed to the Steam Deck which shares precompiled shader caches.


Imagine the outcry if every game came with a background process that just sits there in the background.

Also - and this may sound a little bonkers - some renderers are so complex and flexible that the actual set of required shaders is only discovered when it tries to render a frame and the full set of possible shader configuration permutations is so large that compiling them all in advance is pointless or borderline infeasible.


Lots of games come with background processes.


Can you name an example? I have a large library of games and can't name one that does.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: