What is shader compilation and why is it so prevalent now?

137 views

With the recent hubbub about The Calisto Protocol stuttering due to rampant “shader compilation”, I was recently reminded that other recent games (like Horizon Zero Dawn) were also known for shader compilation issues.

What is the game doing that makes it different from other games that just open and play without stutter or compilation?

I also don’t remember anyone making a fuss about this for titles 5 years ago.

In: 30

5 Answers

Anonymous 0 Comments

Shader compilation has become more prevalent in recent years because of the increasing complexity and realism of graphics in games and other applications. As graphics have become more detailed and realistic, the shaders used to render them have also become more complex, which means that they require more advanced GPU hardware to execute efficiently. This has led to a greater need for shader compilation, as it allows developers to take advantage of the capabilities of modern GPUs.

Anonymous 0 Comments

Your GPU isn’t just some fancy thing that makes pictures. It’s an wntire computer. A shader is a computer program designed to run on a specialized kind of computer, which has extra hardware that let’s it do certain matrix calculations faster than a regular general purpose computer.

Shader can be compiled at two different times. Before or during the time you want to draw an image. If you compile the shader, that is, convert the code into instruction the machine understands, ahead of time, then you don’t have to waste time doing that conversion whike you try to draw stuff.

Alternatively, you can wait until its time to run the program to compile it. This has the upside of being able to dynamically change what you want the program to do in order to be more efficient at the specific task it will be accomplishing.

So, there is an equilibrium point where being better able to plan and adjust for the current situation saves more time than is costs to do that adjustment.

Shader recompilation is an optimization technique used when an application thinks that by changing the program running on the GPU, it can make it run faster.

Anonymous 0 Comments

Let’s say you’re going hiking up the mountains for a few days. You know it’s going to be cold, so you definitely pack a jacket, a tent, and a sleeping bag, but you don’t necessarily know about all the other things you may need on the trip, so you bring a bunch of flexible essentials just in case: a knife, some kindling, flint and tinder, ready-to-eat snacks.

Shader compilation is deciding what to pack in your bags for that hike. If you do it right, you reach the peak, put on your sweater, set up your tent, prepare dinner. If you do it wrong, you’re on a cold mountain peak without a jacket so you go into a cave looking for a bear to kill so you can use its corpse to keep you warm while eating the remains. In both situations, you’re warm and fed, but one took longer and messier than if you’d known better and just packed some extra.

In a videogame, the right data (for photorealistic visuals) wasn’t properly prepared, so the game has to manually calculate that in real time, which locks up hardware and slows the game to a crawl.

Anonymous 0 Comments

A shader is a small program that is executed by a GPU. But before it can be executed it needs to be compiled, which means to turn it from a human readable text file into something the GPU can work with. And that takes some time.

The name shader goes back to when games were less complicated and mostly applied simple color shading to the faces of 3d meshes (the arrangement of polygons that make up a 3d object). Nowadays shader programs can do all kinds of other things but we still call them shaders.

Five years ago stuttering from shader compilation was still a problem but the shader programs were simpler so they took less time to compile, there were less of them to compile, and there were other limitations that sort of kept the problem in line.

One of those limitations was draw calls, which is basically the game telling the GPU driver “I have all this stuff figured out for this 3d mesh and I’m calling on you to tell the GPU to draw it on the screen”. Five years ago game devs had to pay more attention to draw calls than shader compilation. It was draw calls that was the bottleneck and the major cause of stutters.

One of the main goals of the modern graphical APIs (the software interface between the game and the GPU) was to reduce that bottleneck and games now can issue dozens of times more draw calls every frame. And within each of those draw calls more work can be done.

That has led to an explosion in 3d mesh complexity which is why games now have so much more geometric detail, which in turn requires more (and more complicated) shader programs to be executed for every frame. So essentially we’ve moved the bottleneck which is why shader compilation issues are more prevalent now.

But like everything else in computer science there are workarounds and clever ideas to mask the problem. But they don’t work well in all cases, they require careful planning and design of the game levels and 3d meshes, and all of that takes expertise, time, and money.

Anonymous 0 Comments

Shader compilation is a process that happens in some video games when the game is first run on a new device. It involves the game’s shaders, which are small programs that run on the graphics processing unit (GPU) and are responsible for rendering certain visual effects in the game. When a game is first run on a device, the shaders need to be compiled, or converted into a form that the GPU can understand and execute. This process can take some time and can cause stuttering or other performance issues during gameplay.

In the past, most games were released on a limited number of platforms, so developers could pre-compile the shaders for those specific platforms. This meant that the game would not have to do shader compilation when it was first run on a player’s device, which helped to avoid stuttering and other performance issues. However, in recent years, the number of different devices and platforms that games are released on has increased significantly. This means that developers can no longer pre-compile the shaders for every possible platform, so the game must do shader compilation when it is first run on a player’s device. This can cause stuttering and other performance issues, which has led to some players and reviewers calling attention to the problem.