Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    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,630
    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:
    2,864
    Can you please report this bug? :)
    Thanks!
     
  3. Katerpilet

    Katerpilet

    Joined:
    Aug 2, 2015
    Posts:
    87
    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:
    35
    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:
    97
    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
     
    JmprDev, kaiyum, jq911 and 1 other person like this.
  6. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    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:
    208
    It took me a while to find what was making SRP Batcher not like my shader. It was using
    _Cutoff
    inside the fragment shader. 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.
     
    Last edited: Nov 19, 2021
  8. mdm2233

    mdm2233

    Joined:
    May 9, 2018
    Posts:
    10
    but we need to update the whole cb data even if only one property has been changed. am I right?I think we merely dont need to setup and bind cb to pipeline but we still need to upload data to it.correct me if i am wrong please!
     
    Vanimalsdev likes this.
  9. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    949
    I have a number of shadergraphs.
    All they display correct in 2020.1.1 and URP 8.2. with SRP batcher - compatible

    After importing to 202.2.2 and URP 10.2.2 they show as SRP batcher - not compatible, then Not initialized () or
    UnityPerMaterial CBuffer inconsistent size inside a SubShader (Universal Forward).

    After importing to 202.2.2 and HDRP 10.2.2 they still show as SRP batcher compatible.
     
    Chmyke likes this.
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,864
    @tomekkie2 please report this - sounds like a bug