Search Unity

Question Exact same shader pass compile multiple times ?

Discussion in 'Shaders' started by Immu, Feb 9, 2023.

  1. Immu

    Immu

    Joined:
    Jun 18, 2013
    Posts:
    240
    Hello. I'm a bit confused by unity compiling multiple times the same shader. It's not normal, right ?
    I have a feeling that it might be due to the fact that I use addressables maybe ? My project is quite big, it's taking a long time to do separate tests to pinpoint the issue.
    I've eventually read that putting the said shader into an addressable group might help.
    But I didn't noticed any difference.
    Am I missing something ?

    Right now, clean builds takes 8-15+ hours dedicated to only do that shader compiling specifically. I'm worried.

    Again, even if I manage to strip more variants, which I'll surely do, my main point of concern is here to see
    "Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (vp)" being done twice for example.

    I'm using unity 2021.3.17f1

    Extracts from the editor build log:

    Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (vp)
    Full variant space: 1359101952
    After settings filtering: 28336128
    After built-in stripping: 885504
    After scriptable stripping: 28032
    Processed in 29.83 seconds

    Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (vp)
    Full variant space: 36864
    After settings filtering: 6144
    After built-in stripping: 384
    After scriptable stripping: 192
    Processed in 0.17 seconds


    Thanks for your help
     
    Last edited: Feb 9, 2023
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    It may be that different scenes reference different materials; the variants will be compiled independently for each. If you're using asset bundles (or addressables), the shader may be reference in each asset bundle and from the scenes that go into the build outside of those.