URP Shader Variant Build Times

Hey devs! This topic again. :smile:

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)

5 Likes

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.

4 Likes

Thanks for replying. Iā€™m looking for more answer for this related question: https://discussions.unity.com/t/895602

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.

6 Likes

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.

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.

I agree this will be useful to share. We should definitely share more info about build time improvements and known issues in upcoming releases.

1 Like

Thank you for the info! Very helpful. :slight_smile:

Not sure why the thread has been marked as resolved. The issue of crazy long shader variant times still persists.

1 Like

Resolved just means answered, I believe, since itā€™s a Q&A session

1 Like