Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question What makes a shader SRP batcher incompatible?

Discussion in 'Shader Graph' started by mat108, May 20, 2022.

  1. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    From my experience and testing, the SRP batcher can give some insane performance boosts if a projects shaders are designed with this in mind. However while trying to optimise and clean up some old shaders of mine, it turned out that the 'improved' version is marked SRP batcher incompatible.

    And upon testing, the materials using this shader do in fact not get batched. When the prior materials using the 'unimproved' old version of that shadergraph, did indeed get batched.

    So I'm sitting there wondering how that is possible... the shadergraphs seem to me almost identical. Some new operations which I thought were an improvement, I subsequently removed, thinking this would make the shadergraph SRP batcher compatible again. But no such luck. So I'm sitting there with practically the same shadergraph... but it's srp batcher incompatible?

    Somebody please help me understand. Also somebody please help me understand this technical wuwu mumbojumbo big sleeve wizard technobabble:

     
  2. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    In before that one guy telling me that I 'need to make the PerMaterial CBuffer inside my SubShader consistent'. I don't know what any of that means, as far as I'm aware I'm not using any subshaders or CBuffers and casting shadows has not made any of my other shaders SRP batcher incompatible.
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,336
    You need to make the PerMaterial CBuffer inside your SubShader consistent ;)

    On more serious note, do you use any custom nodes? or something non standard, maybe strange keyword combinations or anything that might help to find the issue? Also is it URP or HDRP?
     
    hippocoder likes this.
  4. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    Nooo it's all stunningly boring and standard. That's why I'm so helpless... no custom nodes, not a single line of custom code, no subshaders, nothing. And it's URP (2020.3.0f1)
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,336
    It might be bug actually. Also did you try restart Unity? Sometimes I had info it's not and then after reload it was ok. Well, it is hard to say without any code or SS.
    If you know it worked before then can't you just find what's wrong in the part you added? or just disconnect some nodes and check if it's ok to locate the problem.
     
  6. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    At this point it's usually just safest to make something inside of shadergraph with custom function node if you need coded behaviour, as it'll be compatible with SRPs, XR, and also hybrid renderer. Unity keeps tinkering so I've basically accepted custom shaders without shadergraph are a bit of a rough ride.
     
  8. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    Okay so Unity being Unity once you realise something is fishy you cannot assume anything to not be riddled with bugs and so at some point everything just start stinking. After figuring using the texel size note causes Unity to poop itself and cower in a corner shaking frantically and foaming out of its mouth, I embarked on the journey to rebuild all my SRP incompatible shaders. Luckily there's copy paste, but alas, still everything is SRP incompatible, even basic elementary arithmetic seems too much to handle. So I figured some sort of 'under the hood' setting was being transfered along during the copy paste process. An obscure remnant of having used the dreaded texel size node.

    So I rebuild some of my shaders node by node, from scratch. And still, SRP INCOMPATIBLE.
    Bravo Unity, you win again.
     
  9. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    But I don't need coded behavior. My shadergraphs are elementary level arithmetic and some multiply by HDR color. My mom could put these shaders together after a 10 minute introduction to shadergraph.
     
  10. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    140
    Okay I think I figured it out Lord give me strength. Referencing 2d texture assets and not exposing them as a property makes Unity convulse, pee itself and cower in a corner. Was really too hard to point that out huh Unity devs???

    Instead we get this joke of valuable highly technical information:

    'UnItY CbUfFeR IncOntInent HurrDUrrr SiZe InSide a Duur SuBShAdeR Huhahuahua YoU FiGuRe OuT WhAt ThIS MeAns YoUrSelFHURRDURRR'

     
  11. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,336
    I can't reproduce. Unity 2021.3.1