When we are using the PSO bundle feature, we will try to wait for the precompiled shaders to complete when the game is launched for the first time. This process usually takes a long time. There will be a waiting UI displayed in the game. Once the precompilation is completed, the game will start very quickly and this UI will not be displayed. However, when I change the graphics card, or modify the name of the game’s exe file, or manually delete the dxcache, the original shader cache seems to become invalid (dxcache). At this time, when the game is started, we have to wait for the precompiled shaders to complete again. We now need a way to determine this situation and display the waiting UI again. Is there a way in UE5 to determine whether the shaders have become invalid and need to be recompiled?
Hi,
thanks for reaching out. I asked my colleagues about this issue and it seems that the conditions that trigger shader recompilation (shader cache invalidation due to e.g. driver update, OS update, GPU upgrade etc.) are detected by the driver which stores the precompiled PSOs in a driver cache.
A potential way to mitigate long shader recompilation times is to migrate to the newer PSO precaching system (if possible) or combine the PSO bundling with PSO pre-caching. In that regard, the information in these topics may be useful:
[Content removed]
[Content removed]
Let me know if this is helpful. If you have more questions, I can pass it on to someone with more knowledge of this engine part at Epic.
Thanks,
Sam
Hi,
thanks for your reply. I consulted a colleague of mine and in 5.1, there is a way to determine if shaders are being compiled by using FShaderPipelineCache::NumPrecompilesRemaining() to check the number of outstanding PSO compiles as mentioned here (this works for both the bundled cache and PSO precaching) . You can modify your loading screen logic to check for this number and keep the loading screen up until it reaches zero. A similar comment with at the top of ShaderPipelineCache.h.
Please let me know if that helps.
Thanks,
Sam
Hi,
thanks for getting back. Using -nostablepipelinecache will disable the bundled PSO cache, and in that case only the GPU driver cache will be used. This will cause hitches during the first run of a game, as the GPU driver cache will need to compile every new shader it encounters on the fly. On subsequent runs, shader compilation will only occur if the driver has not seen the shader yet (so there may still be hitches/stutters), otherwise it will just return the cached shader. This is just to say that passing -nostablepipelinecache in the command line will bypass the PSO cache completely and should only be used for testing/debugging purposes. The GPU driver cache can be cleared with the -clearPSOdrivercache command, which may be useful to see if the PSO bundle has missed some shaders as explained in this article.
Apart from the PSO cache, there is also a user cache file which caches all the shaders not captured by the PSO cache (more info at this link).
Hopefully this helps. Please let me know if you have more questions.
Best,
Sam
Hello,
Thank you very much for your support.
As for the shader recompilation due to system update (such as driver update, OS update, GPU upgrade, etc.), we have referred to the method specified in FD3D12PipelineStateCache in UE5, namely:
const FString UniqueDeviceCachePath = FString::Printf(TEXT(“V%d_D%d_S%d_R%d.ushaderprecache”), Desc.Desc.VendorId, Desc.Desc.DeviceId, Desc.Desc.SubSysId, Desc.Desc.Revision).
We have not directly use the feature related to r.D3D12.PSO.DiskCache as the feature may seem to lead crash issues in 5.1.1.
Now, we just want to know that if we manually clear the dxcache in the GPU drive after the shader precompilation is complete or rename the .exe files, can we still see the UI that detects the failure of the dxcache in the next game launch and the UI that indicates “Waiting for shader precompilation”?
Thank you.
Hi,
Really thank you for your support.
We just want to learn further about the issue. Do we still have to conduct shader precompilation again after shader precompilation is completed and we ensured that there would be no change in systems and GPU drive for the last time we launched the game? Can we just skip over the loading of pipelinecache files via -nostablepipelinecache? Will anything happen if we skip over that?
Thank you.
Regards,