Search Unity

Warming up shader variant collection ignores certain variants

Discussion in 'Shaders' started by adamt, Sep 22, 2020.

  1. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I'm trying to warm up a number of shader variants during the loading scene of my game. In order to find out which shader variants are in use, I've checked the "Log Shader Compilation" checkbox in the "Graphics" tab of the "Project Settings" panel. Then, on-device (I'm using an Oculus Quest with Unity's own "Android Logcat" package to view the shader compilation logs), I play through my game and look for the shader compilation lines. For example, one variant that's getting compiled at runtime looks like this:

    Raygeas/Vegetation, pass: FORWARD, stage: all, keywords DIRECTIONAL FOG_LINEAR INSTANCING_ON LOD_FADE_CROSSFADE STEREO_MULTIVIEW_ON _COLOR2ENABLE_ON _COLOR2OVERLAYTYPE_VERTEX_POSITION_BASED _SNOWOVERLAYTYPE_WORLD_NORMAL_BASED _WIND_ON

    In order to pre-warm this variant in my loading scene, I created a script on a dummy GameObject and added a few lines to its Awake method:

    Code (CSharp):
    1. var preloadedShaderVariants = new ShaderVariantCollection();
    2. preloadedShaderVariants.Add(new ShaderVariantCollection.ShaderVariant(Shader.Find("Raygeas/Vegetation"), PassType.ForwardBase, "DIRECTIONAL", "FOG_LINEAR", "INSTANCING_ON", "LOD_FADE_CROSSFADE", "STEREO_MULTIVIEW_ON", "_COLOR2ENABLE_ON", "_COLOR2OVERLAYTYPE_VERTEX_POSITION_BASED", "_SNOWOVERLAYTYPE_WORLD_NORMAL_BASED", "_WIND_ON"));
    3. /* ...a number of other shader variants to be pre-warmed... */
    4.  
    5. Debug.Log("About to warm up shaders...");
    6. preloadedShaderVariants.WarmUp();
    7. Debug.Log("Finished warming up shaders.");
    However, at runtime, that shader variant is not pre-warmed during the call to WarmUp, and I incur the compilation overhead in the middle of my game scene, causing an unwanted hiccup. In fact, a number of variants I've added to the preloadedShaderVariants collection are not getting pre-warmed, and they're not limited to this "Raygeas/Vegetatian" shader. Other non-warmed variants include those in the Unity "Standard" shader as well.

    I'm using Unity 2019.3.15f1, if that helps.
     
  2. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I wanted to close the loop on this, as I believe the issue is now fixed. I upgraded to Unity 2019.4.10f1 and all of the shader variants I've added to my collection seem to be properly pre-warmed. I suspect -- though I'm not 100% sure -- that the fix was included in 2019.4.6, as a fix for issue 1244648. As most of the keywords for my previously non-warmed variants are local (defined using #pragma shader_feature_local), it looks suspect.

    Anyway, maybe this helps someone.
     
    Last edited: Sep 24, 2020