ShaderCache Generation

Overview

The creation of the ShaderCache.pak suppose that a Remote Shader Compiler is running on a server machine and that contains a set of compiled shader used by the game.

The creation of the ShaderCache.pak will not work if you don't use the Remote Shader Compiler to compile the shaders.

Chapters:

Related Pages:

ShaderCache Generation Process Description

To create the ShaderCache.pak you need to follow these instructions:

Step 1

Get the build for which you want to create the ShaderCache.pak. The set of files you really need in this step is:

  • The ShaderCacheGen.exe contained in the <root>\bin\win_x64 folder of the shipped CRYENGINE build the game is based on.
  • All the .dll and .pdb from the build, which should be built in the Profile configuration.
  • The <root>\Engine\Engine.pak and <root>\Engine\Shaders.pak (Shaders.pak can be created from the shader source code directly).

Please note, that if you are building from a workspace where you have used r_ShadersDebug before, you may have copies of shaders in the <root>\<GameName>\Shaders folder.
These must be deleted before building the ShaderCache.

Step 2

Copy one of the following files from the Remote Shaders Compiler cache folder and rename into <root>\USER\Shaders\shaderlist.txt. (note the casing on shaderlist)

The following platforms are supported:

  • ShaderList_PC.txt if you are building the ShaderCache.pak for the PC platform.
  • ShaderList_Orbis.txt if you are building the ShaderCache.pak for the Playstation 4 platform.
  • ShaderList_Durango.txt if you are building the ShaderCache.pak for the Xbox One platform.
  • ShaderList_GL4.txt if you are building the ShaderCache.pak for the OpenGL 4 platform

Please note that the ShaderList is typically generated by running the game in the appropriate configuration with RSC attached to the game.
For ShaderList_GL4.txt this means you should be using the CryRenderGL.dll as renderer at runtime (with r_driver=GL and running on the target platform)

Step 3

Write a system.cfg file into the <root> folder as following:

sys_no_crash_dialog=1
d3d9_NullRefDevice=1
sys_vr_support = 0
log_IncludeTime=3
log_Verbosity=3
log_FileVerbosity=3
e_profile_level_loading=0
r_driver=DX11
sys_game_folder=<GameName>
r_ShadersAsyncCompiling=3
r_ShadersAsyncMaxThreads=16
r_ShadersRemoteCompiler=1
r_ShaderCompilerServer=<ShaderCompilerIPAddressOrHostname>
r_ShaderCompilerPort=<ShaderCompilerPort>
r_ShadersUserFolder=1
r_ShadersUseInstanceLookUpTable=1
r_multithreaded=0
r_ShadersSubmitRequestline=0
r_ShadersDX11=0
r_ShadersDurango=0
r_ShadersOrbis=0
 
-- For the OpenGL renderer support
-- r_driver=GL
-- r_ShadersGL4=0


Then, depending on the platform, change exactly one of the following variables from 0 to 1 in the system.cfg file:

Target PlatformVariable to changeTarget Subfolder
PC, DirectX 11r_ShadersDX11D3D11
XBox Oner_ShadersDurangoDURANGO
Playstation 4r_ShadersOrbisORBIS
PC, OpenGL 4r_ShadersGL4GL4

Only one set of shaders can be compiled at one time. Therefore, only set one of the r_ShadersXXX variables to 1 at a time.

When using r_ShadersGL4=1 you must also set r_driver=GL and you must have the appropriate CryRenderGL.dll in your build.

Step 4

Generate the files needed for the ShaderCache.pak running the ShaderCacheGen tool with the following command line (The result of the process is logged into the file editor.log):

If a ShaderCache.pak for a PC, Playstation 4 or Xbox One platform is generated the command is:

<root>\bin\win_x64\ShaderCacheGen.exe -noprompt -anygpu /PrecacheShaderList

It is important to run those command lines from the root folder!
Step 5

Packing the shader cache together can be done manually or by using Tools\PakShaders.bat. It is required that you have gone through Step 1-4 before doing this. The command to invoke packing is:

<root>\Tools\PakShaders.bat <TargetSubfolder>

<TargetSubfolder> can be found in the table in Step 3

It is important to run this command line from the root folder!

The script will create the *.pak files inside the root folder. It processes in an accumulative way, which means when you run the command for different platforms after each other, they will all be merged into the same archives.
Typically, the generated *.pak are copied into the Engine folder in the final build.
For reference, take a look at the pre-built games shipped in the SDK, the shaders in them have been generated with the same method as the one here.

Currently, it only makes sense to pack multiple sets of shaders for the PC platform, specifically, the D3D10, D3D11 and GL4 sets can be combined.
For other platforms, there is no reason to pack any shaders other than for the single supported set on that specific hardware.

If you would rather pack your shader cache manually, please continue reading:

Pack the files into the different pak files. The folder mapping for the different platforms:

  • The PC platform should copy the data from the following folders:

    <root>\USER\Shaders\Cache\D3D9\

    <root>\USER\Shaders\Cache\D3D10\

    <root>\USER\Shaders\Cache\D3D11\

    <root>\USER\Shaders\Cache\GL4\

    ... into:

    Shaders\Cache\D3D9\

    Shaders\Cache\D3D10\

    Shaders\Cache\D3D11\

    Shaders\Cache\GL4\

  • The Xbox One platform should copy the data from the following folder:

    <root>\USER\Shaders\Cache\Durango\
    ... into:
    Shaders\Cache\Durango\
  • The Playstation 4 platform should copy the data from the following folder:

    <root>\USER\Shaders\Cache\Orbis\
    ... into:
    Shaders\Cache\Orbis\


  • ShaderCache.pak should contain everything from the above subfolders.
  • ShadersBin.pak should contain only the *.cfxb and *.cfib files.
  • ShaderCacheStartup.pak should contain the following files:
    • <root>\USER\Shaders\Cache\<platform>\lookupdata.bin -> Shadercache\<platform>\lookupdata.bin
    • <root>\USER\Shaders\Cache\<platform>\CGPShader\FixedPipelineEmu* -> Shadercache\<platform>\CGPShader\FixedPipelineEmu*
    • <root>\USER\Shaders\Cache\<platform>\CGPShader\Scaleform* -> Shadercache\<platform>\CGPShader\Scaleform*
    • <root>\USER\Shaders\Cache\<platform>\CGPShader\Stereo* -> Shadercache\<platform>\CGPShader\Stereo*
    • <root>\USER\Shaders\Cache\<platform>\CGVShader\FixedPipelineEmu* -> Shadercache\<platform>\CGVShader\FixedPipelineEmu*
    • <root>\USER\Shaders\Cache\<platform>\CGVShader\Scaleform* -> Shadercache\<platform>\CGVShader\Scaleform*
    • <root>\USER\Shaders\Cache\<platform>\CGVShader\Stereo* -> Shadercache\<platform>\CGVShader\Stereo*
    • <root>\USER\Shaders\Cache\<platform>\lookupdata.bin -> Shaders\Cache\<platform>\lookupdata.bin
    • <root>\USER\Shaders\Cache\<platform>\Common.cfib -> Shaders\Cache\<platform>\Common.cfib
    • <root>\USER\Shaders\Cache\<platform>\fallback.cfxb -> Shaders\Cache\<platform>\fallback.cfxb
    • <root>\USER\Shaders\Cache\<platform>\fixedpipelineemu.cfxb -> Shaders\Cache\<platform>\fixedpipelineemu.cfxb
    • <root>\USER\Shaders\Cache\<platform>\FXConstantDefs.cfib -> Shaders\Cache\<platform>\FXConstantDefs.cfib
    • <root>\USER\Shaders\Cache\<platform>\FXSamplerDefs.cfib -> Shaders\Cache\<platform>\FXSamplerDefs.cfib
    • <root>\USER\Shaders\Cache\<platform>\FXSetupEnvVars.cfib -> Shaders\Cache\<platform>\FXSetupEnvVars.cfib
    • <root>\USER\Shaders\Cache\<platform>\FXStreamDefs.cfib -> Shaders\Cache\<platform>\FXStreamDefs.cfib
    • <root>\USER\Shaders\Cache\<platform>\scaleform.cfxb -> Shaders\Cache\<platform>\scaleform.cfxb
    • <root>\USER\Shaders\Cache\<platform>\stereo.cfxb -> Shaders\Cache\<platform>\stereo.cfxb