Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved URP Shader Variant Build Times

Discussion in 'SRP Dev Blitz Day 2022 - Q&A' started by Andy-Touch, Sep 29, 2022.

  1. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,445
    Hey devs! This topic again. :D

    Using URP by default generates millions of shader variants. This results in default usage resulting in very long build times of many hours. Check this thread.

    I have a set of questions related to this:
    • What long terms plans, at a foundational level, are there to address this problem?
    • What short term plans, for tooling and documentation, can be built to help the community identify and solve these problems with their projects today?

    (I know this was raised by Gigaya team internally, but im raising it again publicly now as someone who will have to go through the exact same problem :p)
     
    Last edited: Sep 29, 2022
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    Hey, that's is very hot question and thanks for asking.
    For long term, we have plan to have better shader variant prefiltering. Also we have many more ideas in the loop.
    For short term, we are adding more information about shader stripping that would help keep variant count at minimum.
     
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Thanks for replying. I'm looking for more answer for this related question: https://forum.unity.com/threads/super-long-build-time-for-urp-hdrp-project.1342040/
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,195
    Hi!

    As far as I understand it, the fundamental problem is that the standard über-shaders are built with a lot of multi-compile keywords, which causes a extreme combinatoric growth of the number of shaders that has to be considered. Filtering out which ones are included or not helps, but you're still in theory having to crunch through billions of data points.

    Problem is, for a lot of projects, there's very few instances of actually taking advantage of the keywords being multi-compile rather than shader_feature. As in, for most of the things I've made, you could look at exactly the shaders variants that are on the materials in the build, and then compile those, idk, 100 shaders in total including variants?

    Would it be possible for me to enable some kind of "grownup mode" where I tell you explicitly which variants I want, and you're free to not even consider the other ones and give me magenta instead? It might be that there's this huge caveat I'm missing, but right now it seems absurd to me that this work "has to" happen at all.
     
  5. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    It's great to see some of the questions about shade variants, and that's a complex topic!
    I will link to a more complete answer I added in one of the threads here, but also let me take opportunity to call out some of the parts on that answer to your questions here.

    There are currently discussions about exposing API that could allow users to find the balance between runtime cost vs memory/build time cost, by f.ex turn keywords into dynamic branch.

    Several things happening. Shader Prefiltering is on PR review stage for 2023 and that brings massive improvements in shader stripping time. There is some work that recently landed to evict shaders from memory and improve shader memory footprint. Every release in URP we do a pass to find potential stripping improvements we might have missed, f.ex here.

    We have added more documentation on shader stripping [1][2][3][4]. We currently have documentation in progress to document shader keyword in URP.
     
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Awesome. I would like to see the latest build time for Gigaya project. Hopefully can shorten the build time to less than 1 hour for the first time build.
     
  7. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    I agree this will be useful to share. We should definitely share more info about build time improvements and known issues in upcoming releases.
     
    optimise likes this.
  8. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,445
    Thank you for the info! Very helpful. :)
     
  9. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,445
    Not sure why the thread has been marked as resolved. The issue of crazy long shader variant times still persists.
     
  10. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,268
    Resolved just means answered, I believe, since it's a Q&A session
     
    AljoshaD likes this.