Generating Shader Combinations

Using the remote shader compiler

The Remote Shader Compiler is the perfect tool to generate a list of shader combinations for a game, as it logs every request that is made from instances of the game being run.

Firstly, make sure that a Remote Shader Compiler has been setup successfully. The remote shader compiler should be reached by everyone playing the game, especially QA, so that all necessary shader requests are triggered and logged on the server. Try to have everyone who is working on a certain game project share the same remote shader compiler.

How the engine loads shaders

Normal game builds should contain shader cache pak files generated by the shader cache generation phase, called global shader cache. At the beginning of a project this could be either totally missing (because no shaders requests have been submitted yet) or the pak files could still be missing a lot of shaders.

Chapters:

Related Pages:

When the engine tries to render an object it will check if the compiled shader is available. When the shader is not available, it will try to load it from the global cache. This can either be loaded directly or through the streaming engine. The direct loading will cause direct disc access from the render thread and this could cause severe stalls due to the streaming thread trying to access the disc at the same time.

By default, when shader compiling is disabled, the engine will stream the shaders from the global cache. The object won't be rendered when shader data is being streamed in. This default behavior can be modified with the following CVar (please note that streaming of shaders is not allowed when shader compiling is enabled, and the engine will automatically disable this CVar then):

r_shadersAsyncActivation = 0

When the shader is missing from the global cache, a "request line" to store this missing shader is directly sent to the remote shader compiler to be sure that this shader will be available in the next shader cache generation. This happens even when shader compiling is disabled, but the remote shader compiler needs to be active.


When no shader compiler is defined or disabled then the request line will be ignored. It is highly recommended to play as much as you can with the remote shader compiler to collect as many shader combinations as possible. The remote shader compiling can be disabled with the following CVar (disabled by default in release builds, else always enabled):

r_shadersRemoteCompiler = 0

The submission of the shader request lines can be disabled as well:

r_shadersSubmitRequestLine = 0

When shader compiling is disabled and the shader is missing in the global cache, the object won't be rendered at all. When shader compiling is enabled, and the remote shader compiler is active, an asynchronous request to compile the shader will be requested to the remote shader compiler. If the remote shader compiler is disabled, then the shader will be compiled locally on PC. Other platforms do not support local compilation.

Collecting global shader cache requests

As explained above, every time a shader is missing in the global cache a request will be send to the remote shader compiler to store information on the missing shader.

How to keep track of the current shader cache state in game

Extra debug information can be enabled using the following CVar:

r_displayinfo = 2

A shader cache information line can be found on the top right of the screen which reports the amount of Global Cache Misses (GCM) which have been found so far. It also reports if shader compiling is currently enabled or not.

All the shader cache misses also get dumped to a txt file at the following location: <user>\Shaders\ShaderCacheMisses.txt. This information is only used for debugging the current state of the shader cache, and should ideally be empty.