forge
Explore
Log in

Don't you dare go Hollow

A 16x4/4x16 pair's chroma edge-filter type came from the strip's own mi, not the pair's base mi

Browse files at this commit

6a9c6eb7240cc59ded7c80f924752b11b0e87cd6Ahmet Kaan GümüşParent: c6f22ad
  • fix
    • a 16x4/4x16 pair's chroma edge-filter type came from the strip's own mi, not the pair's base mi
Show full message
fix(av1): a 16x4/4x16 pair's chroma edge-filter type came from the strip's own mi, not the pair's base mi

libaom builds chroma_above_mbmi/chroma_left_mbmi from
mi[-((mi_row & ss_y) * mi_stride + (mi_col & ss_x))] (set_mi_offsets,
av1/common/blockd.h) and get_intra_edge_filter_type (reconintra.c:974)
reads THAT block's uv_mode. decode_leaf_rect4_16's chroma half asked
smooth_uv_neighbour at the odd strip mi instead, so the neighbour it saw
was the non-chroma-reference 4-row block directly above (uv_mode
UV_DC_PRED) rather than the chroma block above the pair. On the ReelB -ss 1200 key frame that lost a SMOOTH neighbour: filt_type 0
instead of 1 turned av1_use_intra_edge_upsample on (blk_wh 12 <= 16) for
an 8x4 H_PRED chroma strip at angle_delta -2 and moved 4 samples by 1.

Gate: a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact
now alternates in a chroma-carrying lavfi source (the gray one left both
chroma planes constant, so every uv_mode was DC and this shape could not
occur) and hard-asserts a new rect4_16_uv_pair_filt_hits counter -- pairs
whose filt type differs between the two mi. 8-bit: 13 flips, 10-bit: 8,
all pixel-exact; reverting the one-line fix reddens it at seed 43.

HG 1-frame key-frame census: -ss 1200 14 -> 0 bytes, -ss 1800 248 -> 0,
-ss 3600 1 -> 0, -ss 3300 44500 -> 39971; other segments unchanged.
crates/ec-av1/src/decode.rsmodified+27 -1
@@ -2193,6 +2193,17 @@ thread_local! {
2193 static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2193 static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2194 static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2194 static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2195 static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2195 static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2196+ /// lane-kf1200: pairs whose chroma edge-filter type read from the PAIR's
2197+ /// base mi differs from what the strip's own (odd) mi would have said --
2198+ /// the shape that made 4 chroma samples of the ReelB `-ss 1200`
2199+ /// key frame miss by 1. Zero here means a gate never exercised the fix.
2200+ static RECT4_16_UV_PAIR_FILT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2201+}
2202+
2203+/// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`
2204+/// from the pair's base mi than the strip's own mi would have given.
2205+pub fn rect4_16_uv_pair_filt_hits() -> usize {
2206+ RECT4_16_UV_PAIR_FILT_HITS.with(|c| c.get())
2196 }2207 }
2197 2208
2198 /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x162209 /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16
@@ -7680,7 +7691,22 @@ fn decode_rect4_16(
7680 let (cw, ch) = (pw / 2, ph / 2);7691 let (cw, ch) = (pw / 2, ph / 2);
7681 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };7692 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
7682 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height);7693 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height);
7683- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c);7694+ // lane-kf1200 r1: the chroma edge-filter type reads the neighbours
7695+ // of the CHROMA block, which for a 16x4/4x16 pair is `pair_mi`'s
7696+ // 16x8/8x16 region -- libaom builds `chroma_above_mbmi`/
7697+ // `chroma_left_mbmi` from `mi[-((mi_row & ss_y) * stride + (mi_col
7698+ // & ss_x))]` (`set_mi_offsets`, av1/common/blockd.h ~1050), i.e.
7699+ // the pair's top-left luma mi, never this leaf's odd row/column.
7700+ // Reading `lmi` here named the leaf directly above (a non-chroma
7701+ // -reference 4-row block, `uv_mode == UV_DC_PRED`) and so lost a
7702+ // SMOOTH neighbour: filt_type 0 instead of 1 turned
7703+ // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a
7704+ // directional chroma strip, moving 4 samples by 1.
7705+ let smooth_neighbor_uv =
7706+ neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);
7707+ if smooth_neighbor_uv != neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c) {
7708+ RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1));
7709+ }
7684 let (u_levels, v_levels) = if skip {7710 let (u_levels, v_levels) = if skip {
7685 let zeros = vec![0i32; cw * ch];7711 let zeros = vec![0i32; cw * ch];
7686 for (buf, _plane) in [(&mut *u, 1usize), (&mut *v, 2)] {7712 for (buf, _plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
crates/ec-av1/src/stream.rsmodified+32 -4
@@ -20503,6 +20503,11 @@ mod tests {
20503 let (mut horz_proved, mut vert_proved) = (0usize, 0usize);20503 let (mut horz_proved, mut vert_proved) = (0usize, 0usize);
20504 let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize);20504 let (mut chroma_proved, mut coeff_proved) = (0usize, 0usize);
20505 let mut split_proved = 0usize;20505 let mut split_proved = 0usize;
20506+ // lane-kf1200: chroma pairs whose intra-edge filter type comes out
20507+ // different when read from the PAIR's base mi (libaom's
20508+ // `chroma_above_mbmi`) rather than the odd strip mi -- the shape
20509+ // that was silently wrong by 1 on the ReelB key frames.
20510+ let mut pair_filt_proved = 0usize;
20506 let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32);20511 let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32);
20507 // The second half of the window turns `--enable-tx-size-search` on:20512 // The second half of the window turns `--enable-tx-size-search` on:
20508 // that is what makes a 16x4 strip SPLIT its transform (depth 1 =20513 // that is what makes a 16x4 strip SPLIT its transform (depth 1 =
@@ -20515,11 +20520,26 @@ mod tests {
20515 let axis = if attempt % 2 == 0 { "Y" } else { "X" };20520 let axis = if attempt % 2 == 0 { "Y" } else { "X" };
20516 let step = 67 + (attempt / 2) * 12;20521 let step = 67 + (attempt / 2) * 12;
20517 let noise = 6 + (attempt % 4) * 3;20522 let noise = 6 + (attempt % 4) * 3;
20518- let source = format!(20523+ // lane-kf1200: the odd attempts carry CHROMA content. The
20524+ // original gray source leaves both chroma planes constant, so
20525+ // every `uv_mode` is DC and a pair's edge-filter type can never
20526+ // differ from its strip's -- the shape that shipped wrong for
20527+ // months. A smooth chroma gradient makes aomenc pick SMOOTH /
20528+ // directional `uv_mode`s next to each other.
20529+ let source = if attempt % 2 == 0 {
20530+ format!(
20519 "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\20531 "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
20520 geq=lum='mod(floor({axis}/4)*{step},256)',\20532 geq=lum='mod(floor({axis}/4)*{step},256)',\
20521 noise=alls={noise}:all_seed={seed},format=yuv420p"20533 noise=alls={noise}:all_seed={seed},format=yuv420p"
20522- );20534+ )
20535+ } else {
20536+ format!(
20537+ "color=c=black:s={width}x{height}:d={duration}:r=25,format=yuv420p,\
20538+ geq=lum='mod(floor({axis}/4)*{step},256)'\
20539+ :cb='128+100*sin((X+Y)/23)':cr='128+100*cos(X/19)',\
20540+ noise=alls={noise}:all_seed={seed}"
20541+ )
20542+ };
20523 let cq_level = format!("--cq-level={}", 24 + (attempt % 4) * 8);20543 let cq_level = format!("--cq-level={}", 24 + (attempt % 4) * 8);
20524 let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };20544 let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
20525 let y4m = Command::new("ffmpeg")20545 let y4m = Command::new("ffmpeg")
@@ -20598,6 +20618,7 @@ mod tests {
20598 );20618 );
20599 let stream = out.stdout;20619 let stream = out.stdout;
20600 let before = crate::decode::rect4_16_counters();20620 let before = crate::decode::rect4_16_counters();
20621+ let pair_filt_before = crate::decode::rect4_16_uv_pair_filt_hits();
20601 let frames = match decode_stream(&stream) {20622 let frames = match decode_stream(&stream) {
20602 Err(e) => {20623 Err(e) => {
20603 let msg = e.to_string();20624 let msg = e.to_string();
@@ -20666,6 +20687,7 @@ mod tests {
20666 vert_proved += vert;20687 vert_proved += vert;
20667 chroma_proved += chroma;20688 chroma_proved += chroma;
20668 coeff_proved += coeff;20689 coeff_proved += coeff;
20690+ pair_filt_proved += crate::decode::rect4_16_uv_pair_filt_hits() - pair_filt_before;
20669 split_proved += split;20691 split_proved += split;
20670 matched += 1;20692 matched += 1;
20671 }20693 }
@@ -20698,11 +20720,17 @@ mod tests {
20698 "{NAME}: {bit_depth}-bit compared attempts never split a strip's transform -- \20720 "{NAME}: {bit_depth}-bit compared attempts never split a strip's transform -- \
20699 the `--enable-tx-size-search=1` half of the window proved nothing"20721 the `--enable-tx-size-search=1` half of the window proved nothing"
20700 );20722 );
20723+ assert!(
20724+ pair_filt_proved > 0,
20725+ "{NAME}: {bit_depth}-bit compared attempts never decoded a chroma pair whose \
20726+ edge-filter type differs between the pair's base mi and the strip's own mi -- \
20727+ the lane-kf1200 fix is unexercised, so this gate would pass with it reverted"
20728+ );
20701 eprintln!(20729 eprintln!(
20702 "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \20730 "{NAME}: {bit_depth}-bit {matched} compared attempts, {horz_proved} 16x4 / \
20703 {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \20731 {vert_proved} 4x16 strips, {chroma_proved} chroma pairs, {coeff_proved} coded \
20704- units, {split_proved} split-transform strips, {named_refusals} refusals, \20732+ units, {split_proved} split-transform strips, {pair_filt_proved} pair-base \
20705- {out_of_scope} out of scope"20733+ filt-type flips, {named_refusals} refusals, {out_of_scope} out of scope"
20706 );20734 );
20707 }20735 }
20708 }20736 }
lanes/kf1200-r1.report.mdadded+101 -0
@@ -0,0 +1,101 @@
1+# lane-kf1200 r1 — the 16x4/4x16 chroma pair read its edge-filter type from the wrong mi
2+
3+## Defect (census4 premise, re-measured on this branch)
4+
5+ReelB `-ss 1200` key frame (1 frame, `3840x1608 yuv420p10le`), our
6+`EC_PROBE_OUT16` vs `ffmpeg -pix_fmt yuv420p10le`: **12 U samples at ±1, Y and V exact**.
7+Stage bisect (`EC_AV1_PREFILT_DUMP16` ours vs aomdec's): **13 U samples already wrong
8+before the loop filter** — a reconstruction defect, not deblock/CDEF/LR/film grain, and
9+not an entropy desync (lane-kf900's shape).
10+
11+## Root cause
12+
13+Block: chroma `(x=352, y=356)`, `8x4`, `uv_mode = H_PRED`, `angle_delta_uv = -2`
14+(`p_angle = 174`), the chroma half of a `16x8` **`PARTITION_HORZ_4` pair** at
15+luma mi `(178,176)`, strip mi `(179,176)`.
16+Its prediction differed from aomdec's by 4 samples of the last row
17+(`OUR_PRED sum=16208` vs `EC_PREDOUT sum=16212`); row 0 and column 0 identical.
18+
19+`decode.rs:7683` asked for the chroma edge-filter type at the **strip's own mi**
20+(`lmi = (179,176)`). libaom builds `chroma_above_mbmi`/`chroma_left_mbmi` from
21+`mi[-((mi_row & ss_y) * mi_stride + (mi_col & ss_x))]` (`set_mi_offsets`,
22+`av1/common/blockd.h`), i.e. from the **pair's base mi** `(178,176)`, and
23+`get_intra_edge_filter_type` (`av1/common/reconintra.c:974`) reads that block's
24+`uv_mode`. The mi directly above the strip, `(178,176)`, is a non-chroma-reference
25+4-row block whose `uv_mode` is `UV_DC_PRED`; the mi above the PAIR, `(177,176)`,
26+coded `uv_mode = SMOOTH` (aomdec `EC_IMODE_VAL mi_row=177 mi_col=176 uv_mode=9`).
27+
28+So we computed `filt_type = 0` where libaom has `1` (aomdec `EC_PRED ... ft=1`).
29+With `filt_type = 0`, `av1_use_intra_edge_upsample(4, 8, -6, 0)` is TRUE
30+(`blk_wh = 12 <= 16`) instead of false — the left edge was upsampled before the
31+z2 walk, moving 4 samples by 1. The strength/upsample/z2 code itself is correct:
32+recomputing z2 by hand from the (identical) neighbour pixels reproduces aomdec's
33+row exactly (`scratchpad/kf1200`, brute force over dy/offsets).
34+
35+## Change
36+
37+- `crates/ec-av1/src/decode.rs:7683` — `smooth_uv_neighbour(pair_mi.0, pair_mi.1, ...)`
38+ instead of `(lmi.0, lmi.1, ...)`, with the libaom citation.
39+- `crates/ec-av1/src/decode.rs:2196` — new `RECT4_16_UV_PAIR_FILT_HITS` counter +
40+ `rect4_16_uv_pair_filt_hits()`: pairs where the pair-base answer DIFFERS from the
41+ strip-mi answer, i.e. the blocks the fix changes.
42+- `crates/ec-av1/src/stream.rs` gate
43+ `a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact` — the odd
44+ attempts now use a **chroma-carrying** source (smooth `cb`/`cr` gradients); the gray
45+ source left both chroma planes constant, so every `uv_mode` was DC and the shape was
46+ unreachable. New hard assert: `pair_filt_proved > 0` per bit-depth arm.
47+
48+No refusal lifted, so `refusal_inventory.rs`/`gate_coverage.rs` are unchanged.
49+
50+## EVIDENCE
51+
52+EVIDENCE: /tmp/.../scratchpad/kf1200/{ours16,ref.yuv} | ffmpeg -ss 1200 -t 0.4 -c:v copy -f obu, trunc.py to 1 frame (sha256 b4b92873d0329964 twice), decode_probe EC_PROBE_OUT16 vs ffmpeg yuv420p10le | U samples differing 12 -> 0, Y/V 0 (Y 0, U 0, V 0 after fix)
53+EVIDENCE: /tmp/.../scratchpad/kf1200/{pre.f0,apre.f0} | EC_AV1_PREFILT_DUMP16 ours vs aomdec on the same 1-frame stream | 13 U samples differ pre-loop-filter => reconstruction, not filters/grain
54+EVIDENCE: /tmp/.../scratchpad/kf1200/{opred.txt,apred.txt} | EC_PRED=1 on both decoders | block (352,356) 8x4 mode=2 ad=-2: ours sum=16208 vs EC_PREDOUT sum=16212, oracle EC_PRED ft=1
55+EVIDENCE: gate run `cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact -- --nocapture` | real aomenc, 8-bit and 10-bit arms | 8-bit: 16 compared attempts, 232 16x4 / 244 4x16, 238 chroma pairs, 13 pair-base filt-type flips, PASS; 10-bit: 15 attempts, 198 pairs, 8 flips, PASS
56+EVIDENCE: same gate with the fix reverted (pair_mi -> lmi) | one-line revert, rebuild, rerun | FAILED "frame 0 U vs ffmpeg (8-bit, seed 43)" -- the gate is decisive, not vacuous
57+EVIDENCE: $HOME/.cache/kf1200-census.log | 24 HG key frames, 1-frame truncation, EC_PROBE_OUT16 vs ffmpeg, each stream sha256'd twice (identical) | see table
58+
59+## 24 key-frame census (bytes differing, 1 frame each)
60+
61+| -ss | before (census4) | after |
62+|----:|-----------------:|------:|
63+| 0 | 0 | 0 |
64+| 300 | 463 | 463 |
65+| 600 | 48771 | 48771 |
66+| 900 | 14057195 | 14057191 |
67+| **1200** | **14** | **0** |
68+| 1500 | 16649701 | 16649650 |
69+| **1800** | **248** | **0** |
70+| 2100 | 15147518 | 15147782 |
71+| 2400 | 42343 | 42343 |
72+| 2700 | 7726287 | 7726287 |
73+| 3000 | 0 | 0 |
74+| 3300 | 44500 | **39971** |
75+| **3600** | **1** | **0** |
76+| 3900 | 7554020 | 7554023 |
77+| 4200 | 0 | 0 |
78+| 4500 | 0 | 0 |
79+| 4800 | 2348 | 2348 |
80+| 5100 | 0 | 0 |
81+| 5400 | 0 | 0 |
82+| 5700 | 16375 | 16375 |
83+| 6000 | 15450360 | 15449720 |
84+| 6300 | 15410936 | 15410864 |
85+| 6600 | 15181681 | 15181688 |
86+| 6900 | 0 | 0 |
87+
88+(The census4 numbers were taken with the same recipe; note census4 measured frame 0 of a
89+segment that then refused later frames, and this run truncates to 1 frame identically.
90+The multi-million counts are lane-kf900's entropy-desync territory, unchanged here.)
91+
92+## Residue
93+
94+- deferred: `-ss 300` (463 bytes) — a DIFFERENT shape, also chroma-only and also
95+ pre-loop-filter, but block-constant offsets of +1/+2 over a ~16x16 chroma region at
96+ chroma (412,384) (`EC_AV1_PREFILT_DUMP16` diff, this branch) — reads like CfL alpha or
97+ a chroma DC/dequant defect, not an edge-filter type. Unblocked by: localising that
98+ block's `uv_mode`/CfL alpha the same way (EC_IMODE_VAL + EC_PRED at mi (206,192)).
99+- deferred: `-ss 600 / 2400 / 4800 / 5700 / 3300` (48771 / 42343 / 2348 / 16375 / 39971) —
100+ larger residuals, not triaged in this round.
101+- accepted: the multi-million-byte segments are entropy desyncs owned by lane-kf900.