The FShaderCache provides mechanisms for reducing shader hitching in-game. It supports the OpenGLDrv RHI, and works on Mac, Linux, and Windows platforms.
There are a number of console commands that can be used to enable or disable FShaderCache functionality.
||Tracking of RHI draw states so that each bound-shader-state can be predrawn.|
||Predrawing of tracked RHI draw states to eliminate first-use hitches.|
||Control over time spent predrawing each frame to distribute over many frames if required. Use -1 for all.|
The cache should be populated by enabling
r.UseShaderDrawLog on a development machine.
Users/players should then consume the cache by enabling
Draw logging (
r.UseShaderDrawLog) adds noticeable fixed overhead so avoid enabling it in shipped products if possible.
Since the caching is done via shader hashes, it is also advisable to only use this as a final optimization tool when content is largely complete
as changes to shader hashes will result in unused entries accumulating in the cache, increasing cache size without reducing hitches.
The code will first try and load the writable cache, then fall back to the distribution cache if needed.
|Cache Type||Cache Location|
When the cache needs to be updated and writable caches invalidated the game should specify a new GameVersion.
FShaderCache::SetGameVersion before initializing the RHI (which initializes the cache). This will cause the contents of a cache generated by a previous version to be ignored. At present you cannot carry over cache entries from a previous version.
For streaming games, or where the cache becomes very large, calls to
FShaderCache::SetStreamingKey should be added with unique values for the currently relevant game regions/streaming levels (as required). Logged draw states will be linked to the active streaming key. This limits predrawing to only those draw states required by the active streaming key on subsequent runs.