Search Unity

Question URP shaders have big size

Discussion in 'Universal Render Pipeline' started by tazerg, May 16, 2022.

  1. tazerg

    tazerg

    Joined:
    Oct 21, 2017
    Posts:
    15
    Hi all!
    We transfer our project from Unity 2020.3.21 to Unity 2021.3.2 (URP 10.7.0 -> 12.1.6).
    And after build Addressables groups and recompile shader variants, we have increased bundle size.
    After investigating the problem, we saw that the size of compiled shaders in the bundle increased several times!
    Unity 2020 shader size:
    2020_1.PNG 2020_2.PNG
    Unity 2021 shader size:
    2021_1.PNG 2021_2.PNG
    Why is this happening and how to solve this problem?
     
  2. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    My guess (and it is very much a guess) is that the increase in size comes as a side effect of the URP 12 change in shader stripping. As in, in URP 10 lots of helpful stripping of keywords and variants was happening for your shaders and the size was smaller, but when you upgraded to URP 12 it's no longer automatically reducing the size and number of shaders and you might need to check the shader stripping Project settings and see what you've got set up there.
     
  3. tazerg

    tazerg

    Joined:
    Oct 21, 2017
    Posts:
    15
    Thnx for reply!
    This is our Graphic Project Settings. We have set the value Strip Unused in the Shader Stripping category. settings.PNG
    Where else are the settings related to stripping?
     
  4. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    What does changing Instancing Variants to 'Strip All' get you in terms of a decrease of shader size? I had to set my project to 'Strip All' to control the exponential increase of compile times when building my project.

    Also, in the 'Player' tab of the Project Settings, what Graphics APIs are you generating? If you're generating for DirectX, OpenGL and Vulkan then that's multiplying the number of shaders required for each of those platforms.

    Unity's blog post on Shader Stripping is the best explanation of how keywords, variants and platforms can cause a ballooning in file size or compile time.
     
  5. tazerg

    tazerg

    Joined:
    Oct 21, 2017
    Posts:
    15
    Thank you for your answers. It helped us a lot. If we have any more questions, I'll be sure to ask them here.

    Can we expect a shader build fix from Unity in the future?
     
  6. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Who knows! I'm don't work for Unity and have no secret info.

    I think the changes in URP 12.0 improved things for a lot of people, there's a forum post here that talks about some of that. Before I was having a lot of build times that stretched on for hours and made regular builds a huge pain, but things have been a lot better for me in in 2021.2. I'd certainly welcome some further improvements to the speed of shader compilation though.