Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

"SRP Batcher" in 2018.2

Discussion in 'Graphics Experimental Previews' started by PhilSA, Apr 18, 2018.

  1. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    SRP Batcher enabled in edit mode is in 2019.1. Sorry 2018.3 didn't have that feature, and you have to click PLAY as you described.
     
    esc_marcin likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,850
    I'm just getting around to realizing that the SRP batcher exists, and so far simply enabling it has seem framerates jump from around 60fps to around 75fps in my project in the editor. However, in a build, there doesn't seem to be any improvement when enabling this. Is there anything I can do to dig into this further?

    Also, when using SRP batching, should/must I disable the Static and Dynamic batching options in Player settings? What if all three are enabled?
     
  3. Tartiflette

    Tartiflette

    Joined:
    Apr 10, 2015
    Posts:
    42
    If it doesn't change anything in the build it probably means you are only CPU-limited in the editor (which is fine). I think dynamic batching is generally considered to be a bit 'meh' or oven counter productive, but static batching is fine and can be used with SRP batching.
     
    dgoyette likes this.
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    You are probably using graphics jobs in your standalone player, so rendering part is not the CPU bottleneck. Graphics jobs are not running in editor, that's why you probably see a speedup in editor. The speedup is really there in standalone, but does not impact global framerate because rendering is not CPU bottleneck in your scene. ( you may find details in that blog post https://blogs.unity3d.com/2019/02/28/srp-batcher-speed-up-your-rendering/ )

    Dynamic batching is automatically disabled for all object going to SRP Batcher code path. Static batching is still effective. ( you should always keep static batching option, can't make things run slower so keep it)
     
    dgoyette likes this.
  5. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    709
    Hi arnaud-carre

    1) On SRP Batching does Unity send the same textures in 2 different materials twice in the same frame?
    2) And does unity generally transfer all textures meshes and materials in one frame to the gpu?

    + And also interesting is the project from the first video. SRP Batcher Benchmark. Would it possible to share this small one please? I'm interesting how many objects and what texture size is used in this case. I think other uses found this small project useful as well.
     
    Last edited: Apr 25, 2019
  6. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    115
    Does SRP batcher work with meshes referenced from .asset files (This is how Houdini stores it's baked meshes)? It seems to work fine for me in editor but in builds those objects don't render. If I disable SRP batcher then those objects render in builds correctly.
     
  7. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,894
    This sounds like a bug.

    Please submit a bug-report as described in this document:
    https://unity3d.com/unity/qa/bug-reporting

    It's important that you report these issues together with a reproduction project if you want them to get fixed. If you don't do it, it might be a long time until someone else reports them or until Unity Technologies find them.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. Please post the Case number (number only, not the link) in this forum thread for Unity staff to pick up.
     
  8. Fran0212

    Fran0212

    Joined:
    Oct 22, 2014
    Posts:
    1
    Hi arnaud-carre
    SRP Batcher is very awesome, but I have some question about sprite renderer

    1. What is the reason for SpriteRenderer not supporting by SRPBatcher? (is it because SpriteRenderer uses MaterialPropertyBlock?)
    2. Will SRP batcher support SpriteRenderer in the future?
     
    Terean and msorokinmycom like this.
  9. teutonicus

    teutonicus

    Joined:
    Jul 4, 2012
    Posts:
    37
    I've got issues with missing meshes in builds too. Haven't had a chance to figure out what the issue is or file a bug report but IIRC a lot of them are just regular old .fbx instances/variants existing in the scene and not necessarily referenced in another .asset file. Have to disable SRP batcher for now.
     
  10. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,073
    Are those meshes bigger than 65k vertices? I discovered today that 2019.2.0a14 at least doesn't render my high poly mesh on standalone again, at least not on development build. There used to be a bug for this that was fixed and it does work now on editor but wondering if it has somehow creeped back in to standalone player as it does only affect the highpoly mesh on my build (yet again).
     
  11. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,363
    Did you set Index Format to 32bit? (4 billion verticies limit instead of 65535 for 16bit)
     
  12. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,073
    Actually I double checked and it's was on 16bit mode when it failed. This is a large mesh, it gets split into 3 chunks with 16 bit setting. There used to be an issue with 32bit indexing with multiple materials in past for bigger meshes but that was fixed.

    I remembered I had returned the mesh to 32 bit index format so I assumed it was the same old bug returning, but it's indeed now using 16 bit indices and it still doesn't show the mesh in standalone (it still has multiple materials so maybe that's still related to the issue). I will investigate this more next week if it's still relevant then.
     
  13. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    538
    The old method for toggling SRP batcher for 2018.3, aka "GraphicsSettings.useScriptableRenderPipelineBatching", no longer works in 2019.1, only LWRP asset seems to be able to control it.

    Not sure if it's a bug or not.
     
  14. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,073
    I finally did some simple repro for my recent SRP Batcher issue. It happens on some meshes, for example all test meshes I've exported from Modo fail but batcher still keeps working on default Unity cube.

    So to make this more clear: SRP Batcher works in editor but fails on standalone but only for some meshes (haven't found a pattern yet).

    I tried both 2019.2 with HDRP 6.5+ and 2019.1 with HDRP 5.13 combos. 2019.1 + HDRP 5.13 is fine, it works as it should in standalone, only 2019.2 + HDRP 6.5+ fails there. I forgot to try 2019.2 + HDRP 5.13 combo though.

    Case ID 1153573.
     
    Peter77 likes this.
  15. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    88
    Hello, I just learned about SRP Batcher. I see that 2019.2b Beta release notes says that

    My question is ... so does 2019.1 have any support for SRP Batcher for mobile? Or is it only 2019.2b that can support it?

    Also is the LWRP and SRP Batcher beneficial for 2D games?
     
  16. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    30
    SRP Batcher does not support SpriteRenderer? Shader has marker "SRP batcher compatible", but in sprites in Frame Debugger has "SRP: Node is not compatible with SRP batcher". I've seen the previous question, but there is no answer. Standard batching is disabled in RP and in shader, and enabling it does not change anything btw.
     
  17. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    Hi,
    Textures data are persistent in GPU memory. During the batch, texture binding can happen right before each drawcall if needed. Same for meshes. ( ie mesh data is in GPU memory, and some vertex or index buffer binding could occur right before drawcall command if needed). ( more technical details in this blogpost https://blogs.unity3d.com/2019/02/28/srp-batcher-speed-up-your-rendering/ )

    Regarding benchmark scene, you can get it from here: https://github.com/Unity-Technologies/SRPBatcherBenchmark
     
  18. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    This bug has been fixed recently and backport to 2019.2 and 2019.1 are in flight. Till backport are released, you can use that work around: for meshes that aren't displayed, just check the "Read/Write enable" checkbox in the mesh inspector.
     
    rizu likes this.
  19. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    GraphicsSettings.useScriptableRenderPipelineBatching is still working. But recently LWRP changed a bit and set the GraphicsSettings.useScriptableRenderPipelineBatching flag each frame using its own value located in LWRP asset ( so even if you change GraphicsSettings.useScriptableRenderPipelineBatching, it will be re-forced by LWRP main loop )
    As a workaround you can look in to LWRP source code where GraphicsSettings.useScriptableRenderPipelineBatching is set and comment the line ( so you can modify GraphicsSettings.useScriptableRenderPipelineBatching yourself at any time )
     
  20. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    You're right, shader is compatible but render-node type isn't. ( currrently SRP Batcher only support meshes ). We may investigate to add sprite support in the future.
     
  21. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    SRP Batcher works on mobile using Vulkan and iOS Metal for a while. It also supports OpenGL since 2019.1. So yes you should have benefit of SRP Batcher on mobile ( 2019.1 for OpenGL )

    Regarding 2D games, if you're using "mesh" you should also benefit of SRP Batcher. If you're using Sprites, currently we don't support it. We may investigate to add 2D sprite support in SRP Batcher
     
    chanon81 likes this.
  22. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    30
    That would be great, thank you. Because for now I'm doing very strange things, like building meshes and materials from sprites. It is working, but like voodoo magic. Storing meshes in scene file for static and in ScriptableObject for dynamic things not a best way.
     
  23. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    709
    Cool, Thanks for the link!

    An interesting aspect of the SRP batcher would be also to mark materials optional as static generally. (Also for standard default rendering.) Properties of static materials can not changed at runtime/play for sure and displayed disabled in inspector.

    The SRP batcher and standard renderer can benefit from as well, in order to know exactly what material can be definitely persistent in GPU.

    The biggest issue are multi tillable materials in both axis, (eg ground or wall textures spread over larger surfaces) where texture atlases not work. Or slicing mesh into several repeating UV rectangles not work as well.
     
  24. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    538
    A follow-up question on this: is there currently any way to disable SRP batcher per material with shader keyword? I see SRP Batcher always takes precedence over GPU Instancing when using MeshRenderer.

    (We know manually calling DrawMeshInstanced / Indirect method is still the fastest way to render; but SRP batcher taking precedence over GPU instancing suggests it is just as fast?)
     
  25. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    No there is no way of disable SRP batcher per material. If the material use a custom shader, you could make the shader "non SRP batcher" compatible on purpose. ( for instance by declaring a material var outside of UnityPerMaterial CBUFFER. It's a bit tricky but could be done.

    I admit it's a bit confusing. SRP Batcher is faster than our "generic GPU instancing". ( the one that try to GPU instance any mesh in the scene). But SRP Batcher isn't faster than "explicit GPU instancing". ( But this one require a dedicated shader, and you have to explicitly build and provide the GPU instancing data buffer)
     
    ekakiya and bitinn like this.
  26. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    531
    Will the GPU instancing option be removed from the SRP materials or HDRP specifically? Since SRP Batcher is on by default and GPU instancing isn't overriding it, it's doing nothing unless you turn SRP Batcher off by code then the GPU instancing kicks in. This is why I'm wondering if it will be removed in the future or changed some how.
     
  27. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    512
    This is not what I call tricky but rather annoying... Declaring var outside per material constant buffer itself is not enough. The property needs to be declared too so that shader can be flagged as non SRP Batcher compatible.
    IMHO, this is a very hacky way...

    Does Unity forgot the purpose of "DisableBatching" tag ?
    Please allow us to disable shader compatibility with SRP Batcher using "DisableBatching" tag!
     
  28. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,336
    The SRP Batcher might be disabled in the SRP, or the specific rendering you're doing isn't supported by the SRP batcher, so it still has some use and requires a documentation entry more than any other action, I think.

    What is the use case for ever disabling SRP batcher per material? Why would you want to be slowing your project down by forcing it to take a less efficient path?

    SRP batcher is always faster than not having it.

    Using DrawMeshInstancedIndirect doesn't use it so it is irrelivant as you supply your own details for that...
     
  29. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    512
    Dear @hippocoder, I haven't asked for advice, you don't know about any of my requirements. I'm not concerned by performances but just by this tricky way of disabling material from being SRP batched.
     
  30. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,336
    Why disable material from being SRP batched? There is no reason to.
     
  31. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    512
    I have 3 different materials using the same shader, they require a procedural generated texture to be updated each frame which is different for each materials.
    This won't work (all materials using same procedural texture) unless I disable SRP Batcher for these materials.

    EDIT: Forget it, it works fine.
    As with the tricky way of declaring a uniform outside per material constant buffer it is required have the corresponding for it to work fine.
     
    Last edited: Aug 15, 2019 at 3:35 PM
  32. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,336
    I see, so is this something likely to become more common? The reason I am asking is because Unity is happy to change things if there is a good common use case for it, ie it's logical to invest work into it.

    So when people are asking for things, the use-cases are really important.
     
  33. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    512
    Not sure this is common... I use compute shaders to generate texture arrays for some tiles, those were set correctly but without the corresponding shader property inlined with texture array declaration the SRP Batcher was having strange behavior, it was switching from one tile's array to another.

    That said, getting a DisableBatching shader tag that is useless for SRP Batcher is a bit strange, that was my initial rant. Avoiding tricks to disable something is really important yes.
     
    hippocoder likes this.
  34. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    63
    Will SRP batcher support skinned mesh renderer in future?
     
  35. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    47
    I have a good news for you: skinned mesh will be SRP Batcher compatible in 2019.3
     
    hippocoder and rizu like this.