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)
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.
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.
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.