Search Unity

What does "SRP: Node material requires device state change" mean?

Discussion in 'Universal Render Pipeline' started by zhutianlun810, Jun 11, 2021.

  1. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    172
    Hello,

    I am testing somthing on SRP Batching. I am wondering what can cause "SRP: Node material requires device state change"? What does it mean?
     
  2. modar

    modar

    Joined:
    Jul 18, 2013
    Posts:
    27
    We are experiencing the same issue. Some clarification about this issue would be very much appreciated.
    Thaka you!
     
  3. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Seeing the same thing in the Frame Debugger. Can we get more clarification about what this means?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    This means the fixed-function state differs from the previous draw call. Stencil, depth, blending - any of these.
     
  5. Kogamma

    Kogamma

    Joined:
    Feb 19, 2018
    Posts:
    19
    I got the same issue as OP, everything batches correctly until I do "material.color = otherColor" in my code. Isn't this still supposed to work via SRP batching? I'm using the default URP unlit shader
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    I don't think assigning a different color should result in a different fixed-function state.
     
  7. Kogamma

    Kogamma

    Joined:
    Feb 19, 2018
    Posts:
    19
    I think I found the solution for my problem. I had my scene set up where pretty much the only 2 materials used were using URP unlit as shader, but one of them had render face set to "Front" and the other one to "Back".

    Would this result in a different fixed-function state?
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Yes
     
    Kogamma likes this.
  9. Kogamma

    Kogamma

    Joined:
    Feb 19, 2018
    Posts:
    19
    Ok, thanks. I used RenderFace "Front" on both materials and they batched correctly.

    What I'm actually using in the scene is 1 material for my floor tiles and 1 material for my wall segments.
    The wall segments are the ones using the RenderFace "Back" material. I tried instead of turning of RenderFace "Back" to just switch shaders and temporarily use URP Lit Shader for the Wall Material.
    Now that of course breaks the SRP batching with the floor material, but instead of having something like 96 batches when using same shader and different RenderFace options, I get something like 3-4 batches when having different shaders AND different RenderFace options.

    The solution to my problem right now seems to be to make a perfect duplicate of the URP unlit shader to have the 2 materials use the "same" shader.
    Is there any better solution to this?
     
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Why do you need to render using the different winding order (RenderFace) in the first place?
     
    forestrf likes this.
  11. Kogamma

    Kogamma

    Joined:
    Feb 19, 2018
    Posts:
    19
    The reason is not important, I am planning to change to not using RenderFace "Back" for my walls. But I do wonder why the winding order breaks batching more than using completely different shaders?

    I'm mostly interested in the inner workings of the SRP batcher
     
  12. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,028
    Because it's just one of the factors in batching. A different shader is also a state change. Most likely the batcher doesn't take the winding order into account when sorting things in the first place. Or it does, but it's considered less important than other things.
     
    forestrf likes this.
  13. Kogamma

    Kogamma

    Joined:
    Feb 19, 2018
    Posts:
    19
    Okay, thanks for the quick answers!
     
    aleksandrk likes this.