Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question What is Not Initialized() for SRP Batcher? & Random Behavior of SRP Batcher's Compatibility

Discussion in 'General Graphics' started by GuardHei, Mar 15, 2022.

  1. GuardHei


    Feb 10, 2018
    I'm writing my own SRP based render pipeline and trying to implement SRP batcher to reduce the cost of binding cbuffer. However, I'm noticing a very weird problem here: A shader may be displayed as "SRP Batcher not compatible: Not Initialized()" at first. Then once I change any line of code in the shader (e.g. create a newline with nothing in it), save it to refresh, then revert the change and refresh, the shader will become SRP Batcher compatible without any error. But once I reimport the shader, it goes back to "SRP Batcher not compatible: Not Initialized()". During the process, there is nothing else has been changed, including the direction and position of the camera.

    I've checked the frame debugger, and it does follow what the shader compatibility says for SRP Batching, so no display error here.

    My "UnityPerDraw CBuffer" has a consistent layout (no #if xxx thing). My "UnityPerMaterial CBuffer" is at least consistent within the same shader. I've reused some codes, but that will only be changed from other shader (like #define a constant in another shader, so it shouldn't matter).

    I've heard about the conflict between instancing and srp batcher (though according to docs, it says it works with auto instancing at least), so I've also commented out "#pragma multi_compile_instancing". However, the issue still happens randomly like I've described above (all the passes in FrameDebugger don't have the keyword INSTANCING_ON.)

    One of my other shader weirdly doesn't encounter the same issue, even though sharing one main pass (but different in other passes). Now you may think that maybe this is due to the other passes. However, in this case the scenario is even stranger.

    Suppose the shader that has the issue is Shader A, which has 3 passes: pass_A1, pass_A2, pass_common. And there's the other shader Shader B, which has 4 passes: pass_B1, pass_B2, pass_B3, pass_common.

    I tried to comment out pass_A1, A2, and pass_common (or all of them) for Shader A, and this random compatibility issue still happens.

    But the strange thing is that, if I comment pass_common in Shader A, the original compatible Shader B will become incompatible even though I don't change anything with the same error: "SRP Batcher not compatible: Not Initialized()". And the implementation of this shared pass is implemented in Shader B, not Shader A.


    I'm so confused right now, and I'd like to ask two questions.
    First, what does "SRP Batcher not compatible: Not Initialized()" even mean? Originally if I have a problem with the CBuffer, they will just display something like "Inconsistent CBuffer Layout". Yet in this case, there is not any useful hint to help me debug. I tried to search on google, but found no explanation on "Not Initialized()". Thus, could I get an explanation from any Unity insider?

    Second, is there any solution to this strange random compatibility issue? Ty!