Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

CBuffer inconsistent size inside a subshader

Discussion in 'Shaders' started by sebas77, Nov 28, 2019.

  1. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,220
    Hello,

    shaderlab is still full of mysteries for me. One thing it still not clear to me is why the subshader and passes features are so flexible/confusing.

    Now I get this message:

    UnityPerMaterial Cbuffer inconsistent inside a Subshader.

    this because I have two passes inside the same subshader, but they are used for totally different purpose (normal rendering and depth pass). Why am I supposed to have the same Cbuffer inside?
     
    Last edited: Mar 11, 2020
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    1,606
    Can you please report this bug? :)
    Thanks!
     
  3. Katerpilet

    Katerpilet

    Joined:
    Aug 2, 2015
    Posts:
    57
    I am hitting the same issue for the same reason. Was this fixed and if so in what version of Unity/LWRP?
     
  4. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    25
    I, too, get this with a shader that contains 2 sub-shaders (used for LOD-ing). Can it be confirmed this is a bug, and not something that I/we are doing wrong?
     
    Last edited: Apr 16, 2020
  5. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    61
    Hi,

    "UnityPerMaterial Cbuffer inconsistent inside a Subshader"

    In order to be SRP Batcher compatible, the "UnityPerMaterial" cbuffer has to have the exact same size and layout across all variants of one subshader. Because in SRP Batcher, UnityPerMaterial data are persistent in GPU memory (so we don't want to have tons of different layout to update in GPU memory ).
    Just use the same declaration for this cbuffer. It won't hurt performance because we won't upload the data to GPU per drawcall
     
    jq911 and jawad_ahmad like this.
  6. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    25
    Ah, makes sense! I'm using Amplify for generating my shaders, and so I'll have to talk to the team about fixing this up there (and/or making changes to the Shader Editor myself). Thank you for clearing this up!
     
  7. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    99
    It took me a while to find what was making SRP Batcher not like my shader, and using
    _Cutoff
    inside the fragment shader at all, not related to using
    clip()
    . By using a different variable, for example
    Cutoff
    the shader becomes SRP Batcher friendly.

    It would be good if we could know the variable that makes the SRP batcher no like a shader, or a more specified reason than "Not Initialized" or "Inconsistent size inside a SubShader (PASS_NAME)" as it does not help, there's no documentation anywhere on what those errors mean and how could they be solved.
     
unityunity