Search every partition, and document the split gate
Browse files at this commit338bd3fa5b21b28b4eff2f240762147ff413cfa0Parent: 0723a49- perf
- search every partition, and document the split gate
2 changed files +44 -5
- crates/ec-h264/src/enc/mb.rs +14 -5
- lanes/h264x264-r2.report.md +30 -0
crates/ec-h264/src/enc/mb.rsmodified+14 -5
| @@ -735,11 +735,15 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter | |||
| 735 | best = (cand, c); | 735 | best = (cand, c); |
| 736 | } | 736 | } |
| 737 | } | 737 | } |
| 738 | - // A partition the prediction already fits within half a level a sample | 738 | + // Every partition is searched. This used to stop at a seed whose cost |
| 739 | - // is not searched further: on real content most of them are, and the | 739 | + // was already under half a level a sample, on the reasoning that the |
| 740 | - // search is the encoder's hot loop. | 740 | + // prediction fit and the search is the encoder's hot loop. Swept on |
| 741 | - let good_enough = (w * h / 2) as i32; | 741 | + // consecutive pictures (BD-PSNR against x264, GOP 10) the threshold is |
| 742 | - if best.1 > good_enough { | 742 | + // monotonically harmful: 0/0.25/0.5/1.0 levels a sample read |
| 743 | + // -0.586/-0.587/-0.593/-0.617 dB on the film clip and | ||
| 744 | + // -0.466/-0.470/-0.468/-0.476 on the screen capture. A seed that fits | ||
| 745 | + // is exactly where a little more refinement is cheap. | ||
| 746 | + { | ||
| 743 | let mut step = 4i16 * 4; // four whole samples, in quarter units | 747 | let mut step = 4i16 * 4; // four whole samples, in quarter units |
| 744 | while step >= 4 { | 748 | while step >= 4 { |
| 745 | let mut improved = true; | 749 | let mut improved = true; |
| @@ -828,6 +832,11 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter | |||
| 828 | // Measured: two more searches per macroblock buy 0.1-0.2 dB on screen | 832 | // Measured: two more searches per macroblock buy 0.1-0.2 dB on screen |
| 829 | // capture and nothing on camera content, for roughly twice the search | 833 | // capture and nothing on camera content, for roughly twice the search |
| 830 | // time. That is a Balanced trade, not a Fast one. | 834 | // time. That is a Balanced trade, not a Fast one. |
| 835 | + // The threshold is a floor that real content clears everywhere: swept at | ||
| 836 | + // 0, 0.5, 1 and 2 levels a sample it moves neither clip's BD-PSNR by a | ||
| 837 | + // thousandth of a decibel, so on these sources the halves are always | ||
| 838 | + // searched. It stays as a guard for content flat enough to make the two | ||
| 839 | + // extra searches pure cost. | ||
| 831 | if e.preset == Preset::Balanced && cost16 > 16 * 16 { | 840 | if e.preset == Preset::Balanced && cost16 > 16 * 16 { |
| 832 | for shape in [PShape::Horizontal, PShape::Vertical] { | 841 | for shape in [PShape::Horizontal, PShape::Vertical] { |
| 833 | let mut total = motion_rate(e, 6.0); // the partition's own signalling | 842 | let mut total = motion_rate(e, 6.0); // the partition's own signalling |
lanes/h264x264-r2.report.mdmodified+30 -0
| @@ -490,3 +490,33 @@ That is a prediction result, not an entropy-coding one. The residual coder is no | |||
| 490 | priced exactly and quantised against that price; the next thing to look at is what | 490 | priced exactly and quantised against that price; the next thing to look at is what |
| 491 | we hand it -- how the motion search chooses, and how the partition and mode decision | 491 | we hand it -- how the motion search chooses, and how the partition and mode decision |
| 492 | weighs a more expensive motion field against the residual it saves. | 492 | weighs a more expensive motion field against the residual it saves. |
| 493 | + | ||
| 494 | +## The two gates on the motion search, swept | ||
| 495 | + | ||
| 496 | +The bit account says the residual is where we overspend and the motion field is | ||
| 497 | +where we underspend, so the first thing to check is whether the search is being | ||
| 498 | +stopped early. Two constants decided that, and neither had been measured. | ||
| 499 | + | ||
| 500 | +The early exit: a partition whose best seed already cost less than half a level | ||
| 501 | +a sample was accepted without refinement. Swept, in levels a sample: | ||
| 502 | + | ||
| 503 | +| threshold | film | screen capture | | ||
| 504 | +| --- | --- | --- | | ||
| 505 | +| 0 (no exit) | **-0.586** | **-0.466** | | ||
| 506 | +| 0.25 | -0.587 | -0.470 | | ||
| 507 | +| 0.5 (was) | -0.593 | -0.468 | | ||
| 508 | +| 1.0 | -0.617 | -0.476 | | ||
| 509 | + | ||
| 510 | +Monotone in the direction of searching more, and the encode-side suite does not | ||
| 511 | +measure the extra work (71.7 s against 71.8 s), so the exit is gone. A seed that | ||
| 512 | +already fits is exactly the case where one more refinement step is cheap. | ||
| 513 | + | ||
| 514 | +The split gate, which decides whether the 16x8 and 8x16 halves are searched at | ||
| 515 | +all, reads identically at 0, 0.5, 1 and 2 levels a sample on both clips -- real | ||
| 516 | +content clears it everywhere, so the halves are always searched today. It stays | ||
| 517 | +as a guard for flat content, now documented as one rather than as a tuned value. | ||
| 518 | + | ||
| 519 | +Small numbers, and that is the finding: the search's stopping rules are not what | ||
| 520 | +holds the motion field back. What we do not have is the shape -- the encoder | ||
| 521 | +codes 16x16, 16x8 and 8x16 and nothing smaller, while x264 has the 8x8 sub- | ||
| 522 | +partitions. That is the next slice. | ||