Search Unity

Compiling Shader Variants Taking Ages

Discussion in 'Shaders' started by Nigey, Apr 20, 2018.

  1. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Hi Guys,

    I'm just building my project, and for some reason the 'compiling shader variants' is taking close to an hour to do. I mean fair play, it's a fairly large project, but for example for terrains I have a small park, with one grass texture and some of the built in unity trees.. That's it. It's compiling 6768 shader varients for 'Nature/SpeedTree'. Anyone have any idea why this is taking so long? Thanks!
     
  2. Norgg

    Norgg

    Joined:
    Aug 24, 2014
    Posts:
    2
    Are you by any chance compiling for mobile VR with single pass rendering enabled in Unity 2018.1? We were getting the same problem and it looks like having that enabled causes pretty much every possible shader variant to get compiled...
     
  3. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Hah, not quite. VR on desktop with single pass rendering in 2018.1 lol. So it looks like that's the culprit. Hopefully will be repaired in a few weeks when 2018.1 is officially released.
     
    tigerleapgorge likes this.
  4. Pryzmeister

    Pryzmeister

    Joined:
    Jan 21, 2015
    Posts:
    26
    Just trying with 2018.1 release.. same problem.
     
    tigerleapgorge and BrainSlugs83 like this.
  5. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    It's still there, a true and simple deal-breaker for me, probably will need to revert to 2017.1.
     
    tigerleapgorge likes this.
  6. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Still there for me too. I am just biting the bullet and doing other jobs while the project builds (about 10 minutes).
     
  7. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    it just started doing that with latest version. It's running for a while and then crash and exit completely.

    Help please Unity !!
     
    BrainSlugs83 likes this.
  8. Touchsurgery

    Touchsurgery

    Joined:
    Apr 6, 2017
    Posts:
    1
    I'm experiencing the same problem. Building for Oculus GO (Android target) is taking much longer on Unity 2018.1.4f1 than on 2017.4.1
     
    tigerleapgorge likes this.
  9. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Yeah I did find when it's built once, and you don't make changes to those shaders that same build is faster when re-done I 'think', but that's worth double checking. Either way when you have large projects it means walking away from the computer for a good hour. On company time it doesn't look good lol.
     
  10. kwcae

    kwcae

    Joined:
    May 26, 2017
    Posts:
    34
    We have a similar problem with 2018.2.0b2 building for WebGL. All of a sudden all builds (even empty 1 cube scenes) are compiling hundreds of thousands of shader variants. The best we can tell is that the editor gets stuck in WebGL1.0 emulation mode (or automatically switches to it upon build and then freaks out.

    No clue why it's happening but it's killed this project and it's delivery deadline.
     
    BrainSlugs83 likes this.
  11. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    experiencing the same issue today with Unity 2018.1.0f2
    building for android and get 6144 shader variants to compile, but it seems that the compiler is going back at 1024th shader... and restart compile from scratch to get stuck again athis 1024th shader..

    Also downloaded and tested with Unity 2018.1.5f1 got the exact same problem

    any help ?
     
    Last edited: Jun 19, 2018
  12. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    after more inspection i deleted a folder containing a serie of shaders that may be the probelm, the compiler is now going further . ;)
     
  13. kwcae

    kwcae

    Joined:
    May 26, 2017
    Posts:
    34
    For the interim i had to replace all lights in my scene with area lights to get it to generate a build in a timely (still twice as long as usual) manner. It seems that once lighting is baked, unity creates hundreds and thousands of shader variants for each light type, and material in the scene. So far it looks like the (back of napkin) math is close to #Materials * #light types * #shader variants per material 'visible to each light'
     
    TomTrottel and tigerleapgorge like this.
  14. millefoliumink

    millefoliumink

    Joined:
    Aug 28, 2014
    Posts:
    139
    Bump, does anyone know what is causing this problem?

    The most shader variants are coming out of the PostProcessing FX folder and I don't think it's even being used.
     
    tigerleapgorge likes this.
  15. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    Try to notice where and when the builder stops, it may be a clue to find what to remove.
    Another thing that may helps is to build your application using Build system Internal instead of Grable
     
  16. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    At this point I'm doing cloud builds. Yeah they take a while, but at least it doesn't mean at work I play about for 40 minutes.
     
  17. bgrz

    bgrz

    Joined:
    Mar 22, 2015
    Posts:
    59
    Is there a way to reuse the compilation output from the previous build? For most games this will rarely change.
     
    AlanMattano, rocky1138, r137 and 2 others like this.
  18. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Not that I'm aware of, however you may be able to get around it on 2018.2b. You may not want to use it for production code, but one of the main features is stripping the shader variants to decrease build time.. You know, create a problem to fix a problem lol. Link here: https://blogs.unity3d.com/2018/05/14/stripping-scriptable-shader-variants/
     
    BrainSlugs83 and candycat like this.
  19. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Take some time, get a coffee, did so and it only takes this "hours" once. You can also put your variants in a preset in the Project -> Graphics Settings on the bottom. That might help a bit :)
     
  20. TJD269

    TJD269

    Joined:
    Oct 17, 2017
    Posts:
    19
    Lol no it doesn't. Our issue is it happens every time like everyone is saying in this thread.
     
    BrainSlugs83 likes this.
  21. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Did you try to pack the variants like I said in my post?
     
  22. twin_digital

    twin_digital

    Joined:
    Jul 26, 2018
    Posts:
    6
    Any update about this ?

    Build times are just to big to work properly, like my project got 40 mat, including about 30 standard and 10 mat wich use 3 different custom shaders, got 22 shaders tracked with 67 variants but compiling its displaying numbers 250k, 75k , 35k , etc ...

    Thks
     
  23. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    There is a fix to this. Go to Edit->Project Settings->Graphics. Go to the very bottom. It will state the number of shaders and shader variants. Make sure that seems about right to you. There is a button called 'Save to asset...'. Use that to save a compiled shader variants file. In the graphics tab you're still in, drag that saved file from your Project window into the 'Preloaded Shaders' list. That will decrease the built time dramatically.
     
  24. twin_digital

    twin_digital

    Joined:
    Jul 26, 2018
    Posts:
    6
    Hi, thanks for your reply,

    well i didn't know what to do after hiting this save to assets button, so know i do thanks to you,

    sadly i'm trying this right and doesnt do sh** :( Still got huge amount of shader variants compiling even though i see a right to me number of shaders on this project : 21 shaders and 33 totals variants,

    to be more precise, it's building 25600 then 5120 then 4480 then some other random numbers, and then it strats again for about 30 minutes,in comparison on 2017.3 i got like 5 min build time ^^

    i'd be glad to know what do people think about unity 2018, i was realy hyped by it but right know all i try to do with it is just F***ing my brain up with no results (SRP, scriptable shader variants stripping), like it's all messy and nothing work as great as before (yh i needed to complain sry ^^)

    Thanks anyway :)


    EDIT : Just cleared the "always built in shader" list, u're solution indeed do the trick, thanks a lot again !
     
    Last edited: Jul 26, 2018
    Dance_M, Sprarage and Nigey like this.
  25. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Glad it's working. For reference I think there's teething problems with introducting the LRWP HDRP and custom RP. With that is this system, which normally works great alongside those pipelines. However there hasn't been clear documentation for these systems, and their relational changes in the editor itself (example A: This problem lol). I get the feeling as they continue those rendering pipelines and they come out their beta phase, problems like these will be better addressed. That's my gut instincts on it anyways.
     
    croixbk likes this.
  26. twin_digital

    twin_digital

    Joined:
    Jul 26, 2018
    Posts:
    6
    I hope so :)

    I'm an enthousiast supporter of Unity since if thinks the engine got a fairly high power right now !

    Having thoose things being as u said well documented and allowing us to use them in prod is a step i can't wait for :)

    best regards !
     
    Nigey likes this.
  27. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    I hope it will, as the LRWP pipeline killed my project :D Had to revert back to standard shader, as I got artefacts and crashes on devices and all that stuff.
     
    BrainSlugs83, ynaoto and twin_digital like this.
  28. bgrz

    bgrz

    Joined:
    Mar 22, 2015
    Posts:
    59
    Unity_2018-07-31_15-54-31.png This still doesn't work for me, the "Compiling shader variants" stage during build is still taking a long time and goes through thousands of variants. Tried on 2018.2.0f1 and 2018.2.0f2
     
    BrainSlugs83 likes this.
  29. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Set 'Instancing Variants' to strip all. Re-create that asset file, re-assign, and try then. You will find some instancing variants will happen, but they'll be about 80% of the way through already. It dropped the build time from 40 mins to about 5 mins for me. This is with me having assets like https://assetstore.unity.com/packages/3d/environments/urban/qa-office-and-security-room-114109 included.
     
  30. FastKillteam1

    FastKillteam1

    Joined:
    Sep 20, 2017
    Posts:
    50
    Are you ref
    Are you referring to the “Always Included Shaders” array? Or the dropdowns under “Built-in Shader Settings”?
     
    BrainSlugs83 likes this.
  31. Vtroxi

    Vtroxi

    Joined:
    Sep 21, 2017
    Posts:
    1
    Thank you so much. This works great for me, even with a HDRP projetct!
     
    Nigey likes this.
  32. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Preloaded Shaders list at the very bottom.
     
  33. FastKillteam1

    FastKillteam1

    Joined:
    Sep 20, 2017
    Posts:
    50
    I was actually referring to the edit at the bottom of the post where twin_digital stated they cleared the always built in shader list. Tried everything now anyway. I am not using the lwrp or hdrp. Builds take forever, and when you need to do three successive builds(win, Linux, mac)each update it’s terrible painful. yeah Unity 2018 has some nice features but Unity 2017 was far superior just for the build speed.
     
    Last edited: Aug 3, 2018
    flintcheeze and BrainSlugs83 like this.
  34. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    You can fix this. I had given up several times, but due to doing multiplayer I have to make a build multiple times a day to test any functionality I script. Strip all variants. Re-save and assign that asset. You'll find about 80% is gone. Sometimes the first build takes a little longer, but still saves time. They do need to address this. Asides the fact that people are running to the forums for advice on the worlds most common and simple thing on Unity (building it), but what I've suggested does make a big difference.
     
  35. FastKillteam1

    FastKillteam1

    Joined:
    Sep 20, 2017
    Posts:
    50
    I have tried everything suggested, everything and have been looking for a solution since the 2018 betas we’re rolling even. Nothing at all changes in the build time or number of shaders it compiles. I have tried your suggestion and cleared, resaved asset etc to no prevail, I really wish it would work for me
     
  36. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Strip all unused assets selected as well? It's worked for everyone else so far at least. Normally then goes to about 80% of the way through each shader variant upon building. Is there any scripts overriding Unity's default build process? Otherwise you might have to contact Unity with a bug request or depend on a cloud build solution. Though generally cloud building takes about 3x time to build than on your desktop, at least it frees up your desktop to do other things. A bit OTT for some, but possibly an option when you've really tried everything and filed a bug report.
     
  37. FastKillteam1

    FastKillteam1

    Joined:
    Sep 20, 2017
    Posts:
    50
    Yes strip all is selected also, I will file a bug report for sure, I really thought this issue would be fixed in the public version so I have been waiting it out.
     
  38. fiezi

    fiezi

    Joined:
    Jul 10, 2017
    Posts:
    3
    For me, unchecking "Optimize Meshes" did the trick.
     
  39. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Where do you find optimize Meshes?
     
  40. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Because this is a joke.. got a really basic simple scene and it takes fricken ages to build out on Android and windows.. What has unity done because this is a killa and will be rolling back to an earlier version..
     
    araz01 likes this.
  41. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Ok switching to lightweight rendering pipline has help slightly..
     
  42. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    You can still save the generated shader variants as an asset and put them in the preload thing, so it does noth ave to load all of them when building.
     
  43. FastKillteam1

    FastKillteam1

    Joined:
    Sep 20, 2017
    Posts:
    50
    That does not work. Nothing suggested here works. Unity just needs to fix it. It works perfectly in 2017
     
    BrainSlugs83 and shomz like this.
  44. Frima

    Frima

    Joined:
    Jan 26, 2016
    Posts:
    52
    Our Android/iOS project is using Vuforia 7.2.24 and we adopted the Lightweight rendering system a few weeks ago with Unity 2018.1.6f1. Since then, the build time exploded.

    The main blocker is that popup at build time saying "Compiling shader variants. LightweightPipeline/Standard (Physically Based): x of about 9600". On almost each scene... We can't go back because we need Vuforia 7.2. We can't iterate fast because of this brand new broken build system.

    As @asd234w4r5 suggested, I did save the generated shader variants as an asset + preload thing but it doesn't change a thing.

    Reading this page, I just updated to 2018.2.5f1 with the hopes that the new shader variants compiler would help but I don't see any difference. The build seem to spend most of its time infinite looping from 0 to 9600 in 3 seconds then reset to 0 and so on during at least 5 to 10 minutes.

    Does anyone has any kind of solution?
     
  45. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Try this:

    1) Edit->Project Settings->Graphics->Shader Stripping->Instancing Variants->Strip All
    2) Edit->Project Settings->Graphics->Shader Preloading->Save to asset...
    3) Edit->Project Settings->Graphics->Shader Preloading->Preloaded Shaders->Assign saved shader variants asset
    4) Check whether shader variants number changes between scenes, save multiple shader variant assets and assign when that's the case.
    5) Make sure unless specifically required by your project. You make sure the bool for 'Enable GPU Instancing' is not ticked in your shaders (default is not ticked. You would have specifically ticked them more than likely).

    It will compile slowly once I believe. Once that singular compile is done it won't need to re-compile for those options.
     
  46. Frima

    Frima

    Joined:
    Jan 26, 2016
    Posts:
    52
    My setup is already like that. It still takes about 8 minutes to build a pretty simple project.
     
  47. replay11

    replay11

    Joined:
    Dec 24, 2007
    Posts:
    168
    I also tried the above mentioned suggestions, but it still takes forever to build with "compiling shader assets"... literally thousands. I'm sure this has some benefits in the final build, but having a build take this long for each iteration for Android / Oculus Go is just not really workable. We need to be able to iterate fast and this ... along with the light map baking... just takes forever! Ugh! Wish there was a fix!
     
  48. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    476
    I'm just trying to build the Lightweight VR template on Android and it took a ridiculously long time, even with the suggestions above.
     
  49. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    This is an absolute joke, we are wasting cummalitive hours a week because of this sudden problem. Please will this be fixed soon, this is making using unity at work almost unbareable. We are now having to iterate less as fast iterating is not possible with unity because of this currently.

    EDIT: read my -possible- solution to this further down in the thread
     
    Last edited: Dec 11, 2018
  50. frankadoriv

    frankadoriv

    Joined:
    Jul 19, 2017
    Posts:
    14
    Im having this same issue is very annoying, there is not any issue reported on the tracker?

    Unity 2018.2.6f1
    Lightweight pipeline
    Android/OculusGo
    Mono
    .Net 4
    Only oculus sdk.
    Small scene with only two type of shadders (Physical), one directional light and everything baked and static
     
    BrainSlugs83 likes this.