Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback [0.7.5] Clarify how shader stripping affect Addressable

Discussion in 'Addressables' started by bitinn, May 5, 2019.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    It appears shader stripping setting will affect how Addressable include shaders in the build.

    My question is, how exactly:

    - When I set it to "Strip All" then build, I expect Addressable is smart enough to know to look at "Shader preloading" and include those shaders in the shader variant collection.

    - But what actually happens is: the shaders are not loaded, or at least, not loaded correctly. So my DrawMeshInstanced doesn't render at all. No errors or warning were print by Unity, the Frame Debugger simply doesn't list these draw calls.

    - This issue only happens in Packed Play Mode / Player build, of course.

    - When I set shader stripping to following then build player content, issue doesn't take place:

    (A) "Strip unused" or "Keep All".
    (B) "Strip All" + but let a gameobject in scene directly reference said shader.

    - When these combination are used, build player content will result in no draw call issues:

    (C) "Strip All" + adding said shader to Addressable + load this shader before rendering.
    (D) "Strip All" + adding said shader variant collection to Addressable + load this collection before rendering.

    So my conclusion is:

    - Something is wrong with Addressable with regards to Shader stripping.
    - My understanding is, without Addressable, Shader stripping "Strip All" + Shader preloading set to a variant collection, will ensure shaders in the collection are loaded.
    - So I don't understand why adding Addressable in the mix cause my issue, thus I am not quite sure how best to fix my issue.

    TL;DR:

    Since I believe shaders must be compiled before adding to addressable build, my question is basically, how does Addressable know which shader variants we would use, when there isn't a direct reference in scene? If there is no way for Addressable to figure it out automatically, how do I tell it manually?

    (I ran into this issue while testing a bug report, case 1151889, so if you prefer to see a build, it's in there.)
     
    Last edited: May 5, 2019
    chrismarch likes this.
  2. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    FOLLOW UP

    I tried using AssetBundle Browser to inspect the bundle built by Addressables in the player build, and I saw this:

    Screen Shot 2019-05-07 at 1.17.40.png

    Compare to my actual ScriptableObject asset:

    Screen Shot 2019-05-07 at 1.23.52.png

    Can anyone tell me how to figure out if a shader variant is being included correctly?

    And is there anything special I have to do to make sure these shader are parsed and rendered properly with DrawMeshInstanced?
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Here is the expected behavior, which it sounds like you're seeing:

    1. "Keep all" - all variants are kept, so all should work. there was never a need/purpose for a shader variant collection if doing this
    2. "Strip all" - everything is stripped. don't do this.
    3. "strip unused" - only strips what's not used. This used to require a shader variant collection. With addressables, it does not. The scriptable build pipeline, which we use under the hood, handles variant calculations for us.
    See this for more info on shader stripping: https://docs.unity3d.com/Manual/class-GraphicsSettings.html
     
  4. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Thx, just to clarify, this issue is better summarize in my other thread, I consider this is a duplicate of it:

    https://forum.unity.com/threads/0-8...ails-to-render-with-drawmeshinstanced.676291/
     
  5. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    @unity_bill If shader variant collections aren't required in addressables, how can you warm them up on the start of a game to avoid lag spikes from compiling shaders later on?
     
  6. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Has anyone managed to figure this out? I'm still trying to figure out how to avoid those lag spikes
     
    mitaywalle likes this.
  7. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    40
    I hacked a bit around and split one collection into multiple ones. But the exposed data is broken for HDRP...
    I end up stripping all unused variants by hooking in the HDRP code... But this is very very fragile...
     
  8. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
    In short - you should make your ShaderVariantCollection Addressable, with dependency to Shader.

    Details:
    If you check ShaderVariantCollection-Asset Inspector in Debug mode you'll see direct reference to Shader
    upload_2022-5-27_18-33-8.png
     
  9. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    I think you misunderstood my question. @unity_bill was saying shader variant collections are not needed in Addressables for shader stripping. That means it should theoretically be possible to warmup all shader variants in Addressables without needing to manually maintain a shader variant collection.