Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RawImage breaks batching?

Discussion in 'UGUI & TextMesh Pro' started by ortin, Sep 4, 2014.

  1. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Here is the scene with 3 objects which renders in 2 draw calls (text + atlas) 2.png
    Now I add RawImage to prefab and expect 3 draw calls, but I get 9(!)
    9.png

    Does anyone see the same behavior?
     
    Last edited: Sep 5, 2014
  2. mh114

    mh114

    Joined:
    Nov 17, 2013
    Posts:
    295
    RawImage does break batching since it has to switch texture, and I would hazard a guess that you have those raw images interleved with the other components, so it has to switch back and forth, thus creating those extra draw calls. Have you tried grouping the raw images separately, moving them after the other objects in hierarchy (and thus in draw order)? (I may be wrong though -- not sure if Unity can sort them by material in this case but I'd guess the problem is that you have defined a draw order that forces Unity to switch materials.)
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    We look at material / texture / CanvasRenderer overlapping for batching. I'd love to know what each draw call was and the order that is happening, the drawcall debugger in Unity 5 is really good for this :( silly 4.6!

    Do you have visual studios 2013? or Intel GPA (assuming you are on windows). You can connect and see what is in each draw call.
     
  4. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I'll grab Unity 5 and try to find out.
    Should I continue here after or go to the beta list?
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    Feel free to continue here.
     
  6. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Ok, here is the how it's rendered.
    frames.gif
     
    Last edited: Sep 5, 2014
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    The batching looks at Rect overlaps, so if there are overlaps between non batchable elements then it will break batching.
     
  8. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    But how can I then implement player list with avatars which are loaded from web? Even if I write all avatars in one cache texture it will still break batching...
     
  9. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    If they use the same texture it won't. It will only break if they overlap, and their material / textures are different.
     
  10. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Ah, thanks. I'll give it a try then.
     
  11. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    @Tim C
    But wait, now that image with "star" (in 1st post) is the same for all 3 rows and it does break batching.
    I meant that 2nd screenshot "represents" player list where RawImage is avatar which is loaded from web. And that avatar is obviously placed in player row so it overlaps other images.
     
  12. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,221
    I think the best way to look into this is for you to raise a bug with the project you are using here so I can take a proper look.
     
  13. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    This thing becomes weirder and weirder or the other way clearer. While I was making repro project I discovered that if add spacing between rows (before it was Vertical layout with 0 spacing) or make that RawImage less than row height (Stretch and 1/1 Top/Bottom offsets instead of 0/0) batching works as expected. Not sure if you still need that bug report :)
     
    Last edited: Sep 10, 2014
  14. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Also I have related question as well: is Mask supposed to influence batching? Coz as soon as I add mask to my row prefab it will add 2 draw calls per row.
    Disabled mask:
    disabled_mask.png
    Enabled mask: enabled_mask.png
     
  15. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yea that what i was thinking. i'm 95% sure that out over lap rect checks would detect if the boarders are even just slightly touching. Although not the best I dont think a bug is required (hoping to fix the batching code more later).

    Also i'm pretty sure adding a mask forces that system to create a new draw call as the mask needs to be its own (set and remove)