Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Draw call "separation" rules

Discussion in 'UGUI & TextMesh Pro' started by ortin, Dec 2, 2014.

  1. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I understand that overlapping UI materials create new draw call in unity, but I don't understand why you need at least 1 pixel between different elements for unity not to consider them overlapping.
    See example:
    1. Every cell have 3 different materials (white bg, ball image and text) and they're place in grid layout with 0 spacing. Though cells don't overlap, still every new cell create new draw call which leads to unhealthy 39 total.
    11.jpg
    2. I add 1 spacing to grid and get expected 3 draw calls.
    22.jpg
    So question basically is if it's intended that objects should be separated by at least 1 pixel and if yes what are reasons for it?
     
    rakkarage likes this.
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    atm the space is needed. when batching we do a overlap check on the rects for each graphic. even if its just touching by 1 pixel its "overlapping"
     
  3. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    But it makes things quite difficult for designers... Imagine these white backgrounds are gradients or something like that - it won't be easy to incorporate spacing into it.

    Btw, it's NOT touching by any pixels in my example - cells are just placed directly one after another.
     
    rakkarage likes this.
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yup I do understand your pain, it requires us to improve the batching code. This is planned just no set time as of yet.

    The first image looks like they boarder would be right along the same pixel so i assumed they were at least touching.
     
  5. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Some people seem a little too obsessed with draw calls, to the point where it can actually hurt performance, IMHO.

    Remember that if everything is batched into one draw call, then if you enable/disable a single UI element, it's going to have to rebuild that *entire* uber-draw-call, which can become a very expensive thing to do.

    Reducing draw calls primarily saves CPU time. But if you spend more time on clever batching and overlap tests than is saved by reducing the draw call count, it's a net loss of performance.

    Most good game UIs have at least a few elements in constant motion, so these rebuilds are happening a lot.

    One of the nice things about (some versions of) NGUI is that draw calls are created per UIPanel - if only elements within one panel are modified, it only has to update that panel, and the rest are left alone. At one point, there was an NGUI update that attempted to batch draw calls across panels. It caused great big performance spikes whenever anything changed on our HUD (e.g. enemy health bars being enabled/disabled), and that version was basically unusable for us...
     
  6. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yup and nested canvas's as almost the same as NGUI's UIPanel. a canvas will only batch elements that are below it and not part of a child canvas.
     
    bluescrn likes this.
  7. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Well, I'm not that obsessed, but in this specific case I was just surprised that I got so many draw calls for simple thing as I thought that overlap should be for at least 1 pixel into an object. But thanks to phil's answer I now know that mere touching leads to the same result and will try to avoid/workaround such cases ... and wait for improved batching in future :)
     
  8. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    628
    Ah, cool - that's good to know!

    (I've been trying out the new UI system, and was a little bit worried that we might not be able to organise/optimize things like that - I'd discovered canvas groups (which seemed to be the UIPanel equivalent), but not tried nesting canvases)