Search Unity

Bug Shader Variant Compilation

Discussion in 'Shaders' started by Dneubern, May 26, 2023.

  1. Dneubern

    Dneubern

    Joined:
    Mar 2, 2019
    Posts:
    24
    I know this has been posted before, but Shader Compilation is a NIGHTMARE!

    I'm making a small game, use only three shaders with small variations. Not using most keywords. Building it? Seems like Unity enters a n^n^n^n^n loop. A dog trying to eat its own tail. That's unity shader compilation....

    What really makes my blood boil, is that all these shader variants have been built before.
    I change the X Y Position of one element in the screen, and to build it takes again 30 minutes recompiling these already compiled shaders?

    I have no problem with one compile taking a long time. But changing the X Y position of ONE element doesn't make it necessary for all other elements be rebuilt, specially the shader variants.

    BTW: I compile using the Append method, which should be faster, right?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    Which Unity version do you use? The latest 2021LTS or newer versions have incremental build support and shader prefiltering, which helps a lot. For me the first build takes long and after that it's really fast.
    And what do you mean with append builds? I haven't heard of this yet
     
  3. Dneubern

    Dneubern

    Joined:
    Mar 2, 2019
    Posts:
    24
    2021.3.19f
    The 2020 was horrible on this, the 2021 is better, but it's still not good enough.

    Append builds are available in iOS systems. When you build for iOS, Unity creates an XCODE project, which you then build. This Xcode project can be appended, so builds are faster.


    My builds for three mini games are going over 2 hours. That's insane!!!
    Someone sent me an Asset called shader control to test. Builds now take 50 seconds, but are not working (taking out some #pragma in the UI shaders).
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    1. Update Unity, might help
    2. Maybe check this: https://forum.unity.com/threads/optimizing-ios-and-macos-build-times-using-ccache.974190/
    3. Are builds actually faster with append? (did you measure this?)
    4. You can log shader compilation etc, or hook into the build process and manage the shaders yourself
     
  5. Dneubern

    Dneubern

    Joined:
    Mar 2, 2019
    Posts:
    24
    I've tried this script from the page you've shared, but I'm getting some errors when building.
    Me IDE though shows me no errors whatsoever.

    Code (CSharp):
    1. The type or namespace name 'Callbacks' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    2. The type or namespace name 'iOS' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    3. The type or namespace name 'BuildTarget' could not be found (are you missing a using directive or an assembly reference?)
    4. 'PostProcessBuild' is not an attribute class
    5.  
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,023
    We rebuild the player data each time something that affects it changes.
    We improved the build times in 2021.3.15f1 and later by moving a large part of URP's C# variant stripping to an earlier stage in the build.

    Do you use custom shaders? Do they have a keywords that are not present in URP?
     
    DevDunk likes this.
  7. Dneubern

    Dneubern

    Joined:
    Mar 2, 2019
    Posts:
    24
    I use both MK Glow and MK Toon.
    The only Renderer Feature currently on is MK Glow (necessary for it to work).
    It seems my build times dropped considerably after I've turned off some iOS Settings in Player and disabled Lightmaps.
     
    aleksandrk and DevDunk like this.