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?
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?
“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
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!
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.
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!
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.