(reprint) (official) ue4--image programming----Fshadercache

Source: Internet
Author: User

Fshadercache Overview

Fshadercache provides a mechanism to reduce the lag of shaders in the game. It supports Opengldrv and Metalrhi rhis, which can be used on MAC, Linux, and Windows platforms.

The Fshadercache feature can be enabled or disabled through multiple console commands.

 

Console commands

Describe

r.UseShaderCaching [0/1]

  • The shader deserializes an early commit, not a request.

  • Trace the binding shader state so that they are pre-bound in the early submission.

r.UseShaderDrawLog [0/1]

Tracks the RHI drawing state so that each bound shader state can be pre-drawn.

r.UseShaderPredraw [0/1]

RHI Draw status of pre-drawn traces to eliminate the first-use lag.

r.PredrawBatchTime [Time in (ms)]

Controls the pre-draw time per frame. Distribute on multiple frames, if necessary. Use all-1.

r.UseShaderBinaryCache 0/1

Add all shader bytecode to a separate cache file

r.UseAsyncShaderPrecompilation 0/1

Asynchronous precompilation of shader code in game process

r.TargetPrecompileFrameTime [Time in (ms)]

When the maximum target frame is maintained when R.useasyncshaderprecompilation is enabled. Pre-compile all shaders with 11 times.

r.AccelPredrawBatchTime [Time in (ms)]

The option to temporarily accelerate pre-drawing when in non-interactive mode, such as loading a screen. Select 0 to use r.PredrawBatchTime .

r.AccelTargetPrecompileFrameTime [Time in (ms)]

The option to speed up asynchronous precompilation in non-interactive mode, such as loading the screen. Select 0 to use R.targetprecompileframetime.

r.InitialShaderLoadTime [Time in (ms)]

The maximum amount of time it takes to load a shader before entering asynchronous pre-compilation at startup. Use-1 for synchronous loading)

Use

Should be enabled on the development machine  r.useshadercaching   and   r.useshaderdrawlog   fills the cache. User/player should enable   r.useshadercaching   and   R.UseShaderPredraw   consumes the cache. Drawing the log ( R.useshaderdrawlog ) adds significant fixed overhead and should not be used in publishing products. The binary shader cache can be accumulated during the game process or during the packaging process (currently MAC-only), by specifying the shader platform in the Cachedshaderformats array (/script/in Engine.ini Mactargetplatform.mactargetsettings in the Settings group). For OpenGL, the binary cache contains enough shader pipeline data to construct the full-link GL program or the GL Program pipeline (depending on whether the gl_arb_separate_shader_objects is available), but the data used for pipeline construction on other RHI is insufficient. This helps to reduce the lag on OpenGL without first completing the game process. If it works best, it is still recommended to complete the game process first. Caching is done by shader hashing, which is recommended to be used only as a final optimization tool when most of the content is complete, because modifications to the shader hash will cause unused entries to accumulate in the cache, increasing the cache size, but will not reduce the value of the card.

The code will first try and load the writable cache, and then return to the distribution cache as needed.

Cache type

Cache location

Can write

<Game>/Saved/DrawCache.ushadercache, <Game>/Saved/ByteCodeCache.ushadercode

Distribution

<Game>/Content/DrawCache.ushadercache, <Game>/Content/ByteCodeCache.ushadercode

Integration steps

There are many console commands to reduce the lag in your project, and the recommended prioritization enables you to enable the option to maximize performance while avoiding additional project work.

    1. Enable and for all users in the project configuration r.UseShaderCaching r.UseShaderPredraw .

    2. Try to enable only on the build r.UseShaderDrawLog and ensure that the shader drawing state is recorded in the final QA for each version. When it cannot be implemented (such as great and/or streaming games), it is enabled for all users.

Testing this setting is sufficient to reduce the lag to an acceptable level, additional optimizations require more work and have a significant negative impact.

  1. If the above settings are insufficient to resolve the issue, enable r.UseShaderBinaryCache and configure Cachedshaderformats to ensure that the binary cache is populated (currently MAC only).

  2. Now all shader code will be loaded at startup, and all pre-draw operations will occur at the first frame. If the load time is too extreme, it will be r.PredrawBatchTime set to more than 0 ms to consume pre-drawing in each frame.

  3. You can also r.AccelPredrawBatchTime specify a larger value. This value can be applied when the loading screen or other non-interactive content is displayed.

  4. The call FShaderCache::BeginAcceleratedBatching tells the shader cache to speed up pre-drawing at the expense of the game frame rate, and it is necessary to return the lower-cost pre-drawn batches when called FShaderCache::EndAcceleratedBatching .

  5. FShaderCache::FlushOutstandingBatches The call will process all remaining shaders in the next frame.

  6. If the initial load of the project is still too long, it is enabled r.UseAsyncShaderPrecompilation and will be r.InitialShaderLoadTime set to a value greater than 0. As the initial load time of the shader increases, the work that must be handled during the game run is reduced.

  7. r.TargetPrecompileFrameTime Asynchronously precompile a shader by adjusting a value that can be modified at the desired target frame time.

  8. As with pre-drawn batches, you can specify a more aggressive value to precompile: It will be r.AccelTargetPrecompileFrameTime set to a larger value and then called FShaderCache::BeginAcceleratedBatching (called later FShaderCache::EndAcceleratedBatching ).

  9. r.UseAsyncShaderPrecompilation When enabled, the call will FShaderCache::FlushOutstandingBatches also empty all unresolved compilation requests.

Handling Updates/expirations

When the cache needs to be updated and the writable cache is invalidated, the game should specify a new gameversion. Called before initializing the RHI (which initializes the cache) FShaderCache::SetGameVersion . This will cause the cached content generated by the previous version to be ignored. The previous version of the cache entry cannot be inherited at this moment.

Area/Stream Delivery Batches

For streaming games or caching great content, you should add FShaderCache::SetStreamingKey a call to a unique value based on your needs for the current relevant game area/stream level. The drawing state of the entry will be connected to the used streaming key. This restricts pre-drawing to the drawing state required by the stream feed key used in the run.

Original address: https://docs.unrealengine.com/latest/CHN/Programming/Rendering/FShaderCache/index.html

(reprint) (official) ue4--image programming----Fshadercache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.