Search Unity

Prewarming shaders on modern graphics APIs + Always Included Shader = ?

Discussion in 'General Graphics' started by CyrilGhys, Sep 2, 2021.

  1. CyrilGhys

    CyrilGhys

    Joined:
    Nov 1, 2018
    Posts:
    29
    Hello graphics people,

    I am currently learning basics of Unity's rendering system so this might a noobie question, but I'm just curious :p :

    While reading Unity's documentation, I stumbled on this line about Prewarming shader variants :
    "On modern graphics APIs such as DX12, Vulkan, and Metal, only the experimental ShaderWarmup API is fully supported, because it lets you specify a vertex format. Using the other methods can result in wasted work and GPU memory, without fixing the stalls." (from this page https://docs.unity3d.com/Manual/shader-loading.html)

    However, the thing is, even in a newly created project, there are 10 Always Included Shaders (Legacy Shader Diffuse, UI Default, ...). So, assuming I want to target modern graphics APIs, should I remove them from here and prewarm them using the previously cited ShaderWarmup API? Or am I guaranteed to not have the "wasted work and GPU memory" as the doc states? With these 10 shaders only or is this still fine if I add some more?

    Thank you for reading!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    That list has nothing to do with prewarming. It exists to ensure shader files are included with the built project files. If there are shaders that are used by internal Unity rendering systems (as are the shaders in the default list), referenced in code (like using
    Shader.Find()
    ), or only used by assets in an asset bundle, then Unity's asset referencing system won't know to add them to the built project files. So adding them there ensures Unity knows to include them even if the asset referencing system doesn't "see" them.

    Just below that it lists the 4 ways to preload shaders. Note that the Always Included Shaders list is not mentioned at all. It's totally fine to have shaders exist in both the Always Include Shaders list and in a Shader Variant Collection used for prewarming / preloading.
     
  3. CyrilGhys

    CyrilGhys

    Joined:
    Nov 1, 2018
    Posts:
    29
    Ohh I see, thanks for clearing up my mind
    I thought the 'Always Included Shaders' list was the thing the documentation was talking about (the second way), but there is actually another list just below this one, my bad!