Android (OpenGL) compiles shaders at runtime first spawn actor?
I am trying to some optimization to the gameplay in my project. So I was never quiet sure what is the suggested way of spawning gameplay relevant things.
So when I first spawn an Actor with a StaticMesh or SplineMeshComponent on Android I get some FPS spikes caused by the render thread as seen in the FrontEnd stats picture below taken from a GalaxyS5:
ShaderLinkTime and ShaderCompileTime take enough time to stop the flow of the gameplay.
Considering that this only happens at the first spawn of the actor, I so far spawned gameplay relevant things once before gameplay begins to keep this FPS Spike from happening. After that I destroy them and spawn them again when needed. Even tough those actors get garbage collected the SharderLinkTime and ShaderCompileTime don't seem to be influenced by this.
The Actor I spawn here has following CD0 and the FishMesh is the SplineMeshComponent example mesh from the content example project.
Is there any other workaround for avoiding the FPS spike on first spawn on mobile? Or what is the suggested way to spawn actors with PrimitiveComponents to avoid FPS spike?
AFAIK this is mostly an OpenGL problem. OpenGL doesn't support precompiled shaders so the driver has to actually compile the high level GLSL file the first time it's loaded. Since the compiler is implemented in the device's OpenGL driver, compilation time can vary from device to device or even between different driver versions. The GPU driver will (usually) re-use the compiled result when the same shader is loaded again by the same application while it's running, that's why you don't see the lag spike even after UE4 performs garbage collection.
My suggestion to avoid such spikes is to create a preload actor that contains one instance of each mesh you intend to load in your level and spawn one of those at a moment where the spike won't be noticed, like during the level loading screen.
answered Jan 21 '16 at 01:54 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here