This is just a curiosity for me. In Call of Duty Black Ops Cold War, whenever you change your graphics settings you need to recompile shaders. This is a rather long process, but is done in the game’s menu system, while the game is running. I’ve been wondering what the developers are really gaining by doing this? (I’m referring to the PC version, I don’t know if this is the case for consoles)
I’m no expert on shaders, but in Unity you compile shaders as part of the compile/build process. As far as I’m aware, the process is done at that point when they end up in the build. What functionality or benefit are we missing out on that COD is leveraging by doing it this way?
Yeah I guess, but why? Would this let them more finely tune the shaders for specific graphics settings or detected GPU’s for better quality or performance than the Unity way allows?
Call of Duty games have generally used a lot of unique, specially tuned shader variants, and aggressively chops apart meshes at the triangle level at run time to apply different variants to different parts of a mesh. For example, if an object is affected by multiple lights with and without shadows, that single mesh might be chopped up into separate parts based on if it’s affected by one light, or two, or three, or one non shadowing light and one shadowing light, and every other permutation you might think of. Unity devs often stress over having a few hundred set pass calls, but some CoD often runs with tens or even hundreds of thousands of the equivalent of set pass calls. Their whole rendering pipeline is designed around the idea of aggressively reducing the per pixel shader cost.
The side effect of that is if they were to ship all of their shader variants for every possible quality setting they’d probably have a few extra gigabytes of shaders. Especially as the newer CoD games probably have even more permutations. So they don’t. The silly thing of course being that today’s CoD games regularly take 250 GB, so an extra gigabyte or two of pre-compiled shaders wouldn’t even be noticeable, but they just probably didn’t bother spending the extra effort to modify a system that already worked. It’s also curious because the last few CoD games didn’t do it. But shrug who knows, maybe there were some problems with the pre-compiled setup they didn’t want to deal with.
Many of their graphics settings are probably implemented as shader keywords. Like bgolus said, they already use finely grained shader combinations based on all sorts of material and lighting situations.
If you consider each additional toggle roughly doubles the amount of shader permutations, enough of them could easily explode the number of shaders into the order of millions or even more. They could also have different shader paths for different GPUs, further inflating the number of combinations.
Maybe that number is so high that compiling them all at build time took far too long or something like that.
Napkin math: let’s say that for a single configuration they have 250MBs worth of shaders. If they have 7 keyword toggles for settings, that’d take 32 gigabytes of storage just for shaders.