# CBuffer inconsistent size inside a subshader

**URL:** https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204
**Category:** Shaders & Materials
**Tags:** Shaders
**Created:** [November 28, 2019, 4:37pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204 "2019-11-28T16:37:27Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![sebas771](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sebas771/32/90842_2.png) [@sebas771](https://discussions.unity.com/u/sebas771)
#### Post date: [November 28, 2019, 4:37pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/1 "2019-11-28T16:37:27Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![aleksandrk](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@aleksandrk](https://discussions.unity.com/u/aleksandrk)
#### Post date: [November 30, 2019, 7:09pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/2 "2019-11-30T19:09:45Z")

</div>

Can you please report this bug? 🙂  
Thanks!

---

<div class="post-metadata">

### Author: ![Katerpilet](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/katerpilet/32/213809_2.png) [@Katerpilet](https://discussions.unity.com/u/Katerpilet)
#### Post date: [March 10, 2020, 5:27pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/3 "2020-03-10T17:27:01Z")

</div>

I am hitting the same issue for the same reason. Was this fixed and if so in what version of Unity/LWRP?

---

<div class="post-metadata">

### Author: ![jawad\_ahmad](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jawad\_ahmad](https://discussions.unity.com/u/jawad_ahmad)
#### Post date: [April 16, 2020, 6:31pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/4 "2020-04-16T18:31:36Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![arnaud-carre](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/arnaud-carre/32/899611_2.png) [@arnaud-carre](https://discussions.unity.com/u/arnaud-carre)
#### Post date: [April 17, 2020, 7:59am UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/5 "2020-04-17T07:59:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jawad\_ahmad](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jawad\_ahmad](https://discussions.unity.com/u/jawad_ahmad)
#### Post date: [April 17, 2020, 5:37pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/6 "2020-04-17T17:37:39Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![forestrf](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/forestrf/32/86391_2.png) [@forestrf](https://discussions.unity.com/u/forestrf)
#### Post date: [June 5, 2020, 10:29pm UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/7 "2020-06-05T22:29:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mdm2233](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@mdm2233](https://discussions.unity.com/u/mdm2233)
#### Post date: [October 22, 2020, 8:07am UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/8 "2020-10-22T08:07:39Z")

</div>

> [@arnaud-carre](#):
>
> 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

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!

---

<div class="post-metadata">

### Author: ![tomekkie2](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@tomekkie2](https://discussions.unity.com/u/tomekkie2)
#### Post date: [February 6, 2021, 8:54am UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/9 "2021-02-06T08:54:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aleksandrk](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@aleksandrk](https://discussions.unity.com/u/aleksandrk)
#### Post date: [February 6, 2021, 9:11am UTC](https://discussions.unity.com/t/cbuffer-inconsistent-size-inside-a-subshader/767204/10 "2021-02-06T09:11:50Z")

</div>

@tomekkie2 please report this - sounds like a bug
