Search Unity

Question BatchRendererGroup on mobile

Discussion in 'Graphics for ECS' started by Epineurien, Apr 3, 2023.

  1. Epineurien

    Epineurien

    Joined:
    Mar 9, 2013
    Posts:
    45
    Anyone know if there are particular settings/functions/etc to use so BatchRendererGroup work on Android?
    I pretty much copy-pasted "BRGSetup" from Unity's own repository, and it work perfectly fine in Editor (or build for PC). However on actual mobiles nothing is displayed - outside of the regular meshrenderer'ed ground.

    Tried with an OPPO A16s, a Samsung Galaxy S6, even with Bluestack and Nox just in case.
    Scenes with regular MeshRenderer and DrawMeshInstanced both work fine, but not the BatchRendererGroup one.

    It's Unity 2022.2.12, so it "should" be compatible - but it doesn't even raise an error.
     
    Last edited: Apr 3, 2023
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Make sure to set the "BatchRendererGroup Variants" setting in Project Settings > Graphics to "Keep All" when using BatchRendererGroup, otherwise player builds will be missing the required shader variants.

    If this doesn't help, please try to run the application using both Vulkan and OpenGL to see if one of them works.
     
  3. Epineurien

    Epineurien

    Joined:
    Mar 9, 2013
    Posts:
    45
    Thanks, but "Keep All" was already on, since it wouldn't work when Built for PC otherwise.

    The fix was to use the second overload of BatchRendererGroup.AddBatch; the one that take an additional offset and length.
    Both must be set to 0 for regular platforms (when "BatchRendererGroup.BufferTarget" equal "RawBuffer"), and settings them to 0 & 16384 respectively made my scene work on all the aforementioned phones except the OPPO.
    16384 was picked for being the lowest "SystemInfo.maxConstantBufferSize" among all tested phones (the Samsung).

    I still have no idea what those values actually do (outside of the obvious "being an offset and size for some buffer somewhere"). I guess it's neither the GraphicsBuffer nor the Metadata array since they are already arguments, but Googling only return info about shaders that I'm not really sure are the same things.

    At least it's working now, and working much faster than MeshRenderers&DrawMeshInstanced, so I guess the arcane of "why" it's working can wait.
     
    Last edited: Apr 5, 2023
  4. arnaud-carre

    arnaud-carre

    Unity Technologies

    Joined:
    Jun 23, 2016
    Posts:
    97
    BRG is compatible with GLES3.1 where SSBO can't be used as main GPU buffer. When running on GLES3.1, you should use UBO buffer to store BRG main GPU data. There is no size limit to UBO, just a "visibile window size" limit. that's why we added offset & window size parameter. For instance, you can create a 64MiB UBO and sub-allocate. In this case you will specify the start offset (this offset should always be an interger multiple of BatchRendererGroup.GetConstantBufferOffsetAlignment )

    Also, instead of using hardcoded 16384 value, you can use BatchRendererGroup.GetConstantBufferMaxWindowSize as a second argument and it should work on all your GLES3.1 devices.
     
  5. jiang19910003

    jiang19910003

    Joined:
    Jul 16, 2019
    Posts:
    2
    In the Unity2022.3 version, BRG will have the problem of being unable to render on some devices. This problem will occur when I use the official Demo (brg-shooter) to package my own code. The device with the problem is Samsung Galaxy S5, which is a Old equipment, but it should support GLES3. I tested 2022.3.14f1 and 2022.3.18f1 respectively, and this problem will occur. When BatchRendererGroup.AddBatch is called, an error will be thrown: BatchRendererGroup.AddBatch windowSize parameter (16384) is over the limit allowed by the Graphics API (maxConstantBufferSize: 0)
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Last edited: Jan 25, 2024
  7. jiang19910003

    jiang19910003

    Joined:
    Jul 16, 2019
    Posts:
    2
    Thanks for your enthusiastic answer, my problem was successfully solved. I can determine the device platform to bypass this problem.