Shader Compilation and Why It Causes Stuttering, Explained

What you need to explain is how games from a short time ago did not require pre-compilation of shaders, yet still ran well and had graphics that were not considerably worse than today's games.

My theory is that having powerful GPUs and consoles, plus FSR and DLSS has made devs lazy about optimization.
 
Great article, thank you for it. I think that it is worth mentioning that, many great console games, which could be good, have stutters mainly because of a lame port to PC.

After some spectacular failures of AAA game launches, I stopped buying games 1st day launch, or pre-order them. Instead, I chose to buy them after 1 year or when they are on-sale discounts. So, I give game devs time to patch the bugs and optimize their game. If they don't do it, I do not buy their games.

Most recent examples - Atomic Heart and Wo-Long.
Most (in)famous - Fallout 76 and Cyberpunk 2077.

Though, Cyberpunk 2077 devs redeemed themselves with numerous patches, optimizations and free small DLCs. IMHO, in 2023 Cyberpunk 2077 became one of the greatest game to play.
Oh, and even nowadays when unfinished and unoptimized games became the 'norm', there are still great studio games which deliver polished and quality games: Elden Ring, GOW series, Returnal etc. PC port of Returnal is one of the best and optimized one.
 
Last edited:
For an example of how NOT to manage shaders, one need look no further than Borderlands 3. That game stutters so badly that it is unplayable in either DX11 or DX12. There are countless "fixes" online. None of them work, even an a PC with a 5800X, 32 GB, RX6600-XT, and NVMe.
 
What I don’t understand is why the compiled shaders aren’t cached on disk immediately after compilation. When the compilation environment changes, for example a new gpu is detected, or a more optimal driver or whatever, just delete the whole cache. My guess is that it has more to do with the management seeing it as unimportant as it doesn’t reflect the average fps, so I applaud you bringing this to attention. Maybe besides average and low 1% frame rate stats in benchmarks we should include some measurement of stuttering, for example how many times a minute there’s a frame which took 10 times the average (stutter).
 
What I don’t understand is why the compiled shaders aren’t cached on disk immediately after compilation. When the compilation environment changes, for example a new gpu is detected, or a more optimal driver or whatever, just delete the whole cache. My guess is that it has more to do with the management seeing it as unimportant as it doesn’t reflect the average fps, so I applaud you bringing this to attention. Maybe besides average and low 1% frame rate stats in benchmarks we should include some measurement of stuttering, for example how many times a minute there’s a frame which took 10 times the average (stutter).
The best measurement of stuttering is frametime analysis. Most reviews include frametime graphs, and they are available in MSI Afterburner. A consistent frametime is far more important than FPS when it comes to game smoothness. Stutters show up as sharp spikes in a frametime graph.
 
What you need to explain is how games from a short time ago did not require pre-compilation of shaders, yet still ran well and had graphics that were not considerably worse than today's games.
There's really no such thing as pre-compilation, as all shaders have to be compiled before use. Just because a game isn't actively showing this taking place doesn't mean it's not happening - older games simply had fewer and less complex shaders, so they could more easily be compiled during the main menu or level-loading.
What I don’t understand is why the compiled shaders aren’t cached on disk immediately after compilation.
They are by the GPU drivers and some games do it too. For example, if you have an Nvidia graphics card, the compiled shaders are stored in these locations:

C:\users\[account name]\AppData\Local\NVIDIA\DXCache
C:\users\[account name]\AppData\Local\NVIDIA\GLCache

On my PC, that first folder is 1.92GB in size and looks like this:

nvidia_DXcache.png

I've played one game today and used Chrome to web browse, and you can see that this generated 10 files, accumulating 20.5 MB of compiled shaders.
 
My theory is that having powerful GPUs and consoles, plus FSR and DLSS has made devs lazy about optimization.

That is pretty much my take away from the whole thing. I've been playing Quake 4 all day with a 4K Texture pack and a decent shader pack. I remember this gsme running good on my mind rsnged hardware when it came out. Now here I am playing it on my 2 year old hardware and it still plays good. Something happened... We have all these games that the physics break if it goes over 60FPS. We have games that aren't optimized for any hardware and seem to just be waiting on hardware powerful enough to run their janky software.

I had hoped that when Doom Eternal came out it would kick off a new trend but nope... Still not even there. You're right, it's lazy developers wanting to push a game that barely plays on top end modern day hardware with the hops that next gen hardware will run it better. Well we have seen how that works. There is a whole site dedicated to fixes for games both old and new just to get them playable.

I brought up Quake 4 because a lot of gsmes from that era or right after seem to have problems playing on modern hardware.
 
My theory is that having powerful GPUs and consoles, plus FSR and DLSS has made devs lazy about optimization.

I think reviewers need to move 4k dlss/FSR out of the 4k charts and to the appropriate render resolution at 1440p or 1080p. Who cares what its up scaling to, what is it rendering at?
 
There's really no such thing as pre-compilation, as all shaders have to be compiled before use. Just because a game isn't actively showing this taking place doesn't mean it's not happening - older games simply had fewer and less complex shaders, so they could more easily be compiled during the main menu or level-loading.

That's fair, but honestly I think it needs to be addressed how this situation is on a whole other level these days. Like, even as little as three years ago, "compiling shaders" wasn't even in my gaming vocabulary, and now suddenly it's EVERYWHERE. It feels excessive, and to be blunt, I think games today 1) are starting to rely on shaders more than is necessary, and 2) need to find better solutions to the way they employ them.
 
Like, even as little as three years ago, "compiling shaders" wasn't even in my gaming vocabulary, and now suddenly it's EVERYWHERE.
It's been a problem with UE4 for quite some time now, and Epic has done a lot of work in trying to address it. The simple truth is that the graphics level of the 'big' games has ballooned in complexity in just a few years -- take Elden Ring, as a perfect example. FromSoftware uses a proprietary engine for all its games, but it's only the last few titles that have really grown in scope and complexity.

It feels excessive, and to be blunt, I think games today 1) are starting to rely on shaders more than is necessary, and 2) need to find better solutions to the way they employ them.
Unfortunately, the point of relying on shaders more than is necessary or finding better solutions isn't really addressable, as games have no other way of generating graphics. Modern rendering engines used in titles with cutting-edge graphics, especially those using D3D12 or Vulkan, are incredibly complex and difficult to work with.

The real problem for developers is where management wants the focus to be -- chase the 'easy' money in the world of consoles, delve into the immensely broad world of PCs, or attempt to do both. The more work any team is given, with a set timeframe and budget, the more things have to be pushed down the priority chain. The lead rendering programmer may want to spend a couple of weeks honing the shader compilation to perfection, but there will be a whole stack of other tasks that will have a higher priority.
 
Thanks for the informative article !

What I don’t understand is why the compiled shaders aren’t cached on disk immediately after compilation. When the compilation environment changes, for example a new gpu is detected, or a more optimal driver or whatever, just delete the whole cache.
Yes, was wondering the same ... this should need to be done only once (until a system/GPU/driver/... change would warrant a recompilation)

From the article:
"Hogwarts Legacy does this every time you launch the game"
Is there a reason or limitation why this needs to be done each time ?

It would be nice to have this shader compiling just as a part of the installation process: download, install + compile shaders
That would have very little impact and no negative side effects ?
 
What you need to explain is how games from a short time ago did not require pre-compilation of shaders, yet still ran well and had graphics that were not considerably worse than today's games.

My theory is that having powerful GPUs and consoles, plus FSR and DLSS has made devs lazy about optimization.
It's a side effect of using newer versions of graphics APIs (such as directx 12) to their fullest. Ironically enough, the shader compiling is actually an optimization that ensures the game runs as fast as possible on your particular hardware configuration, at the cost of compiling each shader individually on your system.
Doing this though allows much more complex graphic effects for the same amount of processing power as opposed to shaders that are universally compiled and run immediately on every system.
Correct me if I'm wrong.
 
Thanks for the informative article !


Yes, was wondering the same ... this should need to be done only once (until a system/GPU/driver/... change would warrant a recompilation)

From the article:
"Hogwarts Legacy does this every time you launch the game"
Is there a reason or limitation why this needs to be done each time ?

It would be nice to have this shader compiling just as a part of the installation process: download, install + compile shaders
That would have very little impact and no negative side effects ?

Storage space. Plus you have to recompile them every time the GPU driver changes anyways, so why bother when the majority of people who play the game are going to update their drivers bi-weekly or so?

Also consider that not all shaders are used every time; some are quite large/specialized and may only run in specific portions of the game, so those are typically compiled "as needed".

What's happening is the graphical detail in games has gotten so complex that shader compilation is actually becoming a performance bottleneck; prior to the last few years this was rarely a significant problem, but as devs chase smaller and smaller image quality gains, the ever more complex shaders are going to be a problem on certain systems.
 
From the article:
"Hogwarts Legacy does this every time you launch the game"
Is there a reason or limitation why this needs to be done each time ?
The developers, like many others, chose it to be this way; others do it at the main menu or in loading screens. It's the best way to ensure that the shaders are properly compiled before running the main graphics engine, as it can't tell if any changes to drivers, hardware, or other system files have taken place since the last time the game was played.

It would be better if developers gave the end user a little more control over when they would prefer shader compilation to take place, in my opinion.

Does having a faster cpu or nvme drive accelerate the speed of shader compilation process?
A faster CPU would help, as compilation time is likely to be proportional to clock speed and IPC. But it would need to be a serious increase in performance to make a big difference.

If a game is running at 60 fps, that's 17 milliseconds for every frame to be rendered and then presented. So if one CPU manages to do it all in, say, 20 milliseconds, and it's being done during gameplay, that would increase the frame time to 47 milliseconds, dropping the instantaneous frame rate down to 21 fps. Halving that compilation time would only result in the drop being 37 fps, which would be just as noticeable, albeit not as dramatic.

Storage performance wouldn't affect this, unless the number of shader files ran into the hundreds of thousands.
 
Why not have an intermediate solution, compile all the shaders needed for your particular hardware, O/S and driver setup on game installation, and do a quick check to see if anything has changed when the game is run, and if it has say "xxx has changed, recompiling shaders for optimum performance".
 
There's really no such thing as pre-compilation, as all shaders have to be compiled before use. Just because a game isn't actively showing this taking place doesn't mean it's not happening - older games simply had fewer and less complex shaders, so they could more easily be compiled during the main menu or level-loading.

They are by the GPU drivers and some games do it too. For example, if you have an Nvidia graphics card, the compiled shaders are stored in these locations:

C:\users\[account name]\AppData\Local\NVIDIA\DXCache
C:\users\[account name]\AppData\Local\NVIDIA\GLCache

On my PC, that first folder is 1.92GB in size and looks like this:

View attachment 88886

I've played one game today and used Chrome to web browse, and you can see that this generated 10 files, accumulating 20.5 MB of compiled shaders.
Not really, Old games typically used fixed-function pipelines where the graphics hardware had a limited set of operations it could perform. These operations were hard-coded into the GPU and executed in real-time during the game. There was no need to compile shaders as they were not used in these fixed-function pipelines.

However, modern games use programmable pipelines where the graphics hardware can execute custom shaders. These shaders need to be compiled before the game can use them. Pre-compiling the shaders allows the game to optimize the code and reduce the overhead of compiling the shader during gameplay.
 
There needs to be launch options for every game that will allow users to pre compile the shaders before being able to play the game. I'll gladly wait 15-20 minutes for smoother if not completely smooth gameplay. spending $1000 or more on a rig to play video games just to experience stuttering on basically every game feels demeaning at best. I shouldn't need to invest in a 4090 or something in order to avoid stuttering. if my computer meets the recommend specs to run the game I shouldn't experience a single stutter ever. devs are lazy children now who don't know what they're doing.
 
Bring back the elevator ( loading scenes ) - obviously that would be a cut scene now

Just better tools AI etc needed for the seamless transitions gamers expect

How big will GPU onboard memory get ??- going forward - imagine them coming with a"m3" drive in the future and it's own CPU - Nvidia RTX 7090 for 256 GB , 1TB NVME drive top specs , an a ARM CPU like Apples
 
Bring back the elevator ( loading scenes ) - obviously that would be a cut scene now

Just better tools AI etc needed for the seamless transitions gamers expect

How big will GPU onboard memory get ??- going forward - imagine them coming with a"m3" drive in the future and it's own CPU - Nvidia RTX 7090 for 256 GB , 1TB NVME drive top specs , an a ARM CPU like Apples

They will likely have AI-powered memory to reduce consumption and data movement, as well as stacked cache
 
Probably a dumb question but why not just install the compiled the shaders as part of the initial install? I mean if you can download a cache online, why can't it just be downloaded and installed as part of the game?
 
'At this point, you might also be thinking that some kind of online service'

No. Games should not require an Internet connection.
 
I shouldn't need to invest in a 4090 or something in order to avoid stuttering.
But that's the biggest kick in the teeeth, poorly shading compilation will absolutely mean stuttering with the beefiest/costliest card you can buy
 
Back