Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Shader.CreateGPUProgram takes a long time on first startup (iOS)

Discussion in 'iOS and tvOS' started by Johannski, Feb 13, 2018.

  1. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    486
    We're having this problem of very long loading times on the very first startup of our game (or when restarting the phone, but not when killing the app and reopening it or when reinstalling it).

    A check with the profiler shows that Shader.CreateGPUProgram is the problem:
    Fresh install: 6053ms
    Reinstall: 253ms
    Shader.CreateGPUProgram.png
    Can I control when this happens? We disabled loading shader variants and the shaders used at that stage (first scene) are very few.
    We do use quite a lot of shaders. I guess reducing the amount of shaders would help. I'm wondering however:
    - Are shaders included in the Resource folder also affected for Shader.CreateGPUProgram
    - Will shaders with shader variants create a smaller overhead than the shaders as separate files
    - What actually happens at Shader.CreateGPUProgram? And why does it take so much more time at the first run? Is this a bug, or does it make sense?

    btw. running Unity 5.6.4p4 and XCode 9.3 if that is important.
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    486
    Quick update: Shader.CreateGPUProgram compiles the shaders for the specific gpu. This happens whenever an app is freshly installes or the phone is restarted. Here is a simple test I made to show the impact:

    This is only for creating the shaders. Warming up the shaders takes about the same amount of time. Interestingly enough this seems to behave rather similar as Shader.CreateGPUProgram. It is normally only necessary at fresh install or when the phone is restarted.
    Can someone explain to me why shaders won't need warmup when I kill the app and restart it? Is the shader actually still on the GPU? And is there a faster way to flush the GPU buffer other than restarting the phone?

    TLDR: When implementing shaders, don't only look at performance but also loading times, they have a huge impact on the first start of your app.
     
    Last edited: Feb 23, 2018
  3. KristoferBoman

    KristoferBoman

    Joined:
    Feb 16, 2016
    Posts:
    35
    Hi,

    Did you ever solve this problem. We have it in our game as well. Our "Fresh Install" time for an iPhone 7 is around 20 seconds and "Reopening" time is 2 seconds.

    We have been blaiming the Resource folder up until i saw this post. We will try to fix this as well and i'll post back if we come to any conclusion on how to get rid of the problem.

    If someone from Unity could comment on this that would be even better.

    Thanks,
    Kristofer
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    486
    Well, as pointed out in the second post: The shaders get compiled on the device, that's taking a S***load of time. Additionally the shaders also need to be warmed up, this is also mostly only necessary for fresh installs.
    So in the end, try reducing the amount of shaders (and shader variants) you are using. A unity team member commented on it in this thread: https://forum.unity.com/threads/profiling-shader-creategpuprogram.249362/
     
  5. Nokola

    Nokola

    Joined:
    Jul 25, 2015
    Posts:
    4
    I have the same issue with Unity 2017.4.0 and blank project. 7-12 seconds startup on iOS. 1-2 seconds on Android. Just opened a bug in the issue tracker but haven't heard from Unity yet.