IndieDoroid

Screenshot 2021-10-28 015912.jpg


Hi guys
I just installed URP a couple of weeks, so I'm going through the growing pains. :bigeye:

I tried to make a build today and noticed build times are getting bottlenecked on shaders.

I read on the Unity forum that we should remove any shaders that we don't need. For the Spine shaders, what are the bets practices for shader removal? Are they interconnected in some ways? :wounded:

Thanks
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
Avatar
IndieDoroid
  • Postovi: 246

Harald

Sorry to hear that!

While we didn't experience this ourselves yet, this has been reported once here on this forum thread:
Compiling URP Shader Variants Takes Hours
Since I need to fix a Unity 2021.2 related URP shaders issue, I will have a look at the shader variants and whether these could be reduced.
IndieDoroid je napisao/la:I read on the Unity forum that we should remove any shaders that we don't need. For the Spine shaders, what are the bets practices for shader removal? Are they interconnected in some ways?
While the URP .shader files are not interconnected (only shaders that have UsePass <other/shader/pass> in it need the other file), this will not help you much.

The best optimization for your case would be to open the Spine-Sprite-URP.shader file and reduce some variants by removing complete lines, or single keyword options. While #pragma shader_feature statements should only be compile when they are actually used, it would be worth a try removing or reducing those lines starting here:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader#L84

E.g. if you use the URP/Spine/Sprite shader and never use any of the Additive or Multiply shader Blend modes , you can reduce the line from:
#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY _ADDITIVEBLEND _ADDITIVEBLEND_SOFT _MULTIPLYBLEND _MULTIPLYBLEND_X2
to this:
#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY
Also you can remove the following lines if you don't use a diffuse ramp for lighting:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader#L90-L91

If this reduces the compile time and the number of compiled variants (from 39936 in your case above), you're on a good track. Note that a single binary shader_feature will double the number of variants, so it quickly sums up.
Avatar
Harald

Harri
  • Postovi: 3924

IndieDoroid

Harald je napisao/la:Sorry to hear that!

While we didn't experience this ourselves yet, this has been reported once here on this forum thread:
Compiling URP Shader Variants Takes Hours
Since I need to fix a Unity 2021.2 related URP shaders issue, I will have a look at the shader variants and whether these could be reduced.
IndieDoroid je napisao/la:I read on the Unity forum that we should remove any shaders that we don't need. For the Spine shaders, what are the bets practices for shader removal? Are they interconnected in some ways?
While the URP .shader files are not interconnected (only shaders that have UsePass <other/shader/pass> in it need the other file), this will not help you much.

The best optimization for your case would be to open the Spine-Sprite-URP.shader file and reduce some variants by removing complete lines, or single keyword options. While #pragma shader_feature statements should only be compile when they are actually used, it would be worth a try removing or reducing those lines starting here:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader#L84

E.g. if you use the URP/Spine/Sprite shader and never use any of the Additive or Multiply shader Blend modes , you can reduce the line from:
#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY _ADDITIVEBLEND _ADDITIVEBLEND_SOFT _MULTIPLYBLEND _MULTIPLYBLEND_X2
to this:
#pragma shader_feature _ _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAPREMULTIPLY_VERTEX_ONLY
Also you can remove the following lines if you don't use a diffuse ramp for lighting:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.0/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-Sprite-URP.shader#L90-L91

If this reduces the compile time and the number of compiled variants (from 39936 in your case above), you're on a good track. Note that a single binary shader_feature will double the number of variants, so it quickly sums up.
Update
Yep Unity has some fixing to do :wounded:
Do you happen to know why the numbers are so high? I don't think I have 80k assets using spine shaders :think:
compiule2.jpg



Hi Harald,

Ok sounds like there's some possible solutions! Thanks a lot! 8)

Please note this isn't a Spine related issue. Unity users in general have been talking about this since waaay back. I'm just trying to find out how to reduce the compile times since I'm using primarily Spine Shaders.

You can catch up with the discussion here.
https://forum.unity.com/threads/compiling-shader-variants-taking-ages.527724/page-5
Nemaš dopuštenje za pregledavanje privit(a)ka dodan(og)ih postu.
Avatar
IndieDoroid
  • Postovi: 246

Harald

IndieDoroid je napisao/la::wounded:
Do you happen to know why the numbers are so high? I don't think I have 80k assets using spine shaders
I assume that Unity also compiles more shader_feature variants here than necessary, not only the ones used by your assets. Anyway, the baseline of multi_compile variants was also too high, which was at 12.288 due to the lighting variants (due to every single FEATURE_ON/_OFF multi_compile statement doubling the count). We have just committed a fix for this high number of multi_compile shader variants and thus high compile time to the 4.0 branch. A new spine-unity 4.0 URP shaders UPM package is available for download here as usual:
Spine Unity Download

Please let us know if this improves the situation for your scenario.

Issue ticket URL for later reference:
https://github.com/EsotericSoftware/spine-runtimes/issues/1974
Avatar
Harald

Harri
  • Postovi: 3924

IndieDoroid

Harald je napisao/la:
IndieDoroid je napisao/la::wounded:
Do you happen to know why the numbers are so high? I don't think I have 80k assets using spine shaders
I assume that Unity also compiles more shader_feature variants here than necessary, not only the ones used by your assets. Anyway, the baseline of multi_compile variants was also too high, which was at 12.288 due to the lighting variants (due to every single FEATURE_ON/_OFF multi_compile statement doubling the count). We have just committed a fix for this high number of multi_compile shader variants and thus high compile time to the 4.0 branch. A new spine-unity 4.0 URP shaders UPM package is available for download here as usual:
Spine Unity Download

Please let us know if this improves the situation for your scenario.

Issue ticket URL for later reference:
https://github.com/EsotericSoftware/spine-runtimes/issues/1974
Ok thanks Harald. I installed the latest runtimes. I'll let you know how it goes the next time I try to build again. Thanks for the help! 8)
Avatar
IndieDoroid
  • Postovi: 246


Natrag na Unity