Hi,
I want to see if I can get better performance with GPU instancing instead of SRP batching. Per comment here, HDRP - Batching does not work I need to make a copy of the HDRP Lit shader and replace the “UnityPerMaterial” with “BypassUnityPerMaterial” CBuffer.
However, there is no “UnityPerMaterial” in the default HDRP Lit shader. I tried adding some CBuffer blocks in the middle of the shader code and SRP batching is still “compatible”. Is there some magic word I can add to the shader code so that it will become incompatible?
To make a Unity shader incompatible with the SRP Batcher, you need to make changes to the shader source file:
For hand-written shaders, open the shader source file. For Shader Graph shaders, copy the Shader Graph’s compiled shader source code into a new shader source file. Use the new shader source file in your application instead of the Shader Graph.
Add a new material property declaration into the shader’s Properties block. Don’t declare the new material property in the UnityPerMaterial constant buffer.
The material property doesn’t need to do anything; just having a material property that doesn’t exist in the UnityPerMaterial constant buffer makes the shader incompatible with the SRP Batcher.
But, the property must be used to take effect, or it will be optimized out.
This info isn’t correct. I have followed this to the T with Shader Graph shader, added new property, but not in CBUFFER UnityPerMaterial. Shader compiles and shows SRP Compatible…
So Frustrated.
I don’t know how it works, but srp batcher doesn’t work anymore.
Unity must add something like “DisableSRPBatching” = “True”, because right now it has “DisableBatching” = “True”
You are right. So I tried another way. If the properites are per instance, just wrap them in the instancing marcos, if they are per material, just remove the CBuffer, because GPU instancing just works on the same material for different meshes, so per material properites is useless and put them in global let the shader incompatialbe with the SRP Batcher