Search Unity

Is it possible to calculate batch count of each material ?

Discussion in 'General Graphics' started by whiteforst, Apr 27, 2019.

  1. whiteforst

    whiteforst

    Joined:
    Jan 30, 2017
    Posts:
    1
    Spent long time in searching on a way to calculate or get the material batch cost .
    a way to access material data related to batch and passcalls from c# script .
    Is it possible ?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    What do you mean by batch cost? Materials don't themselves have anything to do with the process of determining batches, they're simply another data point for the batching system to compare.

    Imagine a grocer has a big bag of different apples who has to sort them into their different varieties. The grocer looks at each apple, figures out if it's a Fiji, Gala, or Delicious, and puts it in the appropriate crate. The apple itself doesn't know how it's being sorted, it's an apple.

    A batched mesh is a mix of multiple meshes that all use the same material combined into a single mesh on the CPU before rendering it on the GPU. The material has no knowledge of this, nor really does the GPU. It just knows it's been told to render a specific mesh with a specific material.

    Similarly pass calls are determined by counting the number of times it has to set the pass while rendering. It's not really "known" until after the frame is finished rendering, though Unity does employ some systems to reduce the number of SetPass calls required (which includes batching, but also render order sorting).

    I do not know of any way to get this data before hand though. I guess it could be possible using the new SRP related calls that you could iterate over all the renderers in the scene, pass them to the sorting function, and count the times the material changes, but those systems don't really understand multi-pass shaders so you wouldn't get an accurate count for how the built in rendering path works.