Skip to main content

split_class_runs

Function split_class_runs 

Source
pub fn split_class_runs(
    instances: &[GpuStrip],
    min_run: u32,
    uber_only: bool,
    out: &mut Vec<ClassRun>,
)
Expand description

Splits instances — one pass segment, in painter order — into consecutive runs, each drawn with one class’s program, appending them to out.

Painter order is preserved by construction: the runs are contiguous, non-overlapping and cover the slice front to back, so drawing them in the order returned draws exactly the instances the unsplit segment did, in the same order. Only the program each instance is shaded by changes, and every program shades the instances it is handed exactly as the whole one would.

Three steps, each linear:

  1. maximal runs of equal PaintClass::of_instance;
  2. a solid run shorter than min_run is folded into a neighbouring non-solid run (the previous one, else the next) — every program draws solid, so this costs that neighbour nothing and saves a switch; runs of one class left adjacent by a fold are joined;
  3. a remaining non-solid run shorter than min_run is drawn with PaintClass::Uber, and adjacent Uber runs are joined — the short run is merged into its neighbours rather than paying for a pipeline switch of its own.

A solid run is never promoted to Uber: it only survives step 2 short when it has no non-solid neighbour at all, and then the solid program is the cheapest one that draws it. min_run 0 or 1 disables both merges.

uber_only is the kill switch (FRUST_ENGINE_UBER_PROGRAM): the whole slice becomes ONE Uber run, which is the unsplit segment exactly.