forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-realworld': cdef_idx decodes, gated on a real aomenc stream

Browse files at this commit

51e931ce9181230206713ad0ab0f4dabfc81397bAhmet Kaan GümüşParent: 093155e5a8c7fe
Blocker 1 of the default-settings chain is closed. The per-64x64 cdef_idx
symbol is read (spec 5.11.56) at all five sites where skip is decoded, kept in
a per-superblock grid, and apply_cdef selects that superblock's strength pair
instead of index 0. Gate a_real_aomenc_stream_with_cdef_decodes_pixel_exact:
40/40 pixel-exact, zero refusals, cdef_idx_hits hard-asserted > 0 (24-40/run).

The lane also established why the obvious gate could never work: cdef_bits
selects among per-SUPERBLOCK strength profiles, so a single-64x64-superblock
fixture gives the encoder nothing to differentiate -- 20 attempts kept the
counter at 0. It needed 128x64.

Both guards on main fired exactly as designed and are updated here:
gate_coverage's NEVER_EXERCISED loses enable-cdef (a gate enables it now), and
refusal_inventory loses "a frame with cdef_bits > 0". The decode.rs conflict was
the counter doc-comment restyle against the lane's new CDEF thread-locals; the
lane's block is kept, restyled to match.

Suite 237 passed / 0 failed.
crates/ec-av1/src/decode.rsmodified+121 -9
@@ -66,6 +66,73 @@ pub(crate) fn filter_intra_hits() -> usize {
66 FILTER_INTRA_HITS.with(|c| c.get())66 FILTER_INTRA_HITS.with(|c| c.get())
67 }67 }
68 68
69+// lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into
70+// [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a
71+// frame-level flag through the recursive block decode -- `0` (the default)
72+// makes every call a true no-op, matching every existing gate stream's
73+// `cdef_bits == 0` behaviour exactly.
74+thread_local! {
75+ static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) };
76+}
77+// Whether this superblock's single CDEF unit (this decoder has no 128x128
78+// SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal
79+// read -- reset to `false` at the top of each superblock in the two tile
80+// loops, spec `read_cdef`'s `cdef_transmitted[index]`.
81+thread_local! {
82+ static CDEF_TRANSMITTED: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
83+}
84+// Number of superblock columns in the current tile's grid, so
85+// [`maybe_read_cdef_idx`] can turn an `(mi_r, mi_c)` into a flat index into
86+// [`CDEF_IDX_GRID`].
87+thread_local! {
88+ static CDEF_SB_COLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
89+}
90+// One resolved `cdef_idx` per superblock, read by [`apply_cdef`] to select
91+// which of the header's `1 << cdef.bits` strength pairs applies to that
92+// superblock's samples.
93+thread_local! {
94+ static CDEF_IDX_GRID: std::cell::RefCell<Vec<u8>> = std::cell::RefCell::new(Vec::new());
95+}
96+// How many real (`cdef.bits > 0`) `cdef_idx` literals [`maybe_read_cdef_idx`]
97+// has read, across every call on the current thread -- the gate's proof that a
98+// `cdef_bits > 0` stream actually reached the new reader rather than every
99+// superblock coincidentally being all-skip.
100+thread_local! {
101+ static CDEF_IDX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
102+}
103+
104+/// Current value of [`CDEF_IDX_HITS`].
105+pub(crate) fn cdef_idx_hits() -> usize {
106+ CDEF_IDX_HITS.with(|c| c.get())
107+}
108+
109+/// `read_cdef` (spec 5.11.56, libaom `decodemv.c:read_cdef`), called right
110+/// after `skip` is known at every block-decode call site. A no-op at
111+/// `cdef.bits == 0` (0-bit literal, nothing to consume) -- and
112+/// `read_cdef_params` already forces `bits = 0` under `coded_lossless`/
113+/// `allow_intrabc`, so neither needs a separate check here. Reads once per
114+/// superblock, at the first non-skip block.
115+fn maybe_read_cdef_idx(dec: &mut SymbolDecoder, mi_r: usize, mi_c: usize, skip: bool) {
116+ let bits = CDEF_BITS.with(|c| c.get());
117+ if bits == 0 || skip || CDEF_TRANSMITTED.with(|c| c.get()) {
118+ return;
119+ }
120+ let idx = dec.literal(u32::from(bits)) as u8;
121+ CDEF_TRANSMITTED.with(|c| c.set(true));
122+ CDEF_IDX_HITS.with(|c| c.set(c.get() + 1));
123+ let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize);
124+ let sb_cols = CDEF_SB_COLS.with(|c| c.get());
125+ if sb_cols > 0 {
126+ CDEF_IDX_GRID.with(|g| {
127+ let mut g = g.borrow_mut();
128+ let i = sb_r * sb_cols + sb_c;
129+ if i < g.len() {
130+ g[i] = idx;
131+ }
132+ });
133+ }
134+}
135+
69 // How many 4-pixel deblocking edge groups [`edge_params`] has actually136 // How many 4-pixel deblocking edge groups [`edge_params`] has actually
70 // selected for filtering, across every call on the current thread -- the same137 // selected for filtering, across every call on the current thread -- the same
71 // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream138 // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
@@ -103,7 +170,7 @@ pub(crate) fn tx_depth_hits() -> usize {
103 170
104 // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`171 // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
105 // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every172 // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every
106-// call in the process -- the same before/after counter pattern as173+// call on the current thread -- the same before/after counter pattern as
107 // [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split174 // [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split
108 // `eob_pt`/1D-neighbour context path rather than every block coincidentally175 // `eob_pt`/1D-neighbour context path rather than every block coincidentally
109 // landing on `DCT_DCT`.176 // landing on `DCT_DCT`.
@@ -1928,6 +1995,8 @@ fn read_intra_mode_rect(
1928 enable_filter_intra: bool,1995 enable_filter_intra: bool,
1929 skip_ctx: usize,1996 skip_ctx: usize,
1930 allow_screen_content_tools: bool,1997 allow_screen_content_tools: bool,
1998+ mi_r: usize,
1999+ mi_c: usize,
1931 ) -> Result<(2000 ) -> Result<(
1932 bool,2001 bool,
1933 usize,2002 usize,
@@ -1948,6 +2017,7 @@ fn read_intra_mode_rect(
1948 ));2017 ));
1949 }2018 }
1950 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;2019 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
2020+ maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
1951 let above_ctx = INTRA_MODE_CTX[above_mode];2021 let above_ctx = INTRA_MODE_CTX[above_mode];
1952 let left_ctx = INTRA_MODE_CTX[left_mode];2022 let left_ctx = INTRA_MODE_CTX[left_mode];
1953 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);2023 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -2089,6 +2159,8 @@ fn decode_block_rect(
2089 enable_filter_intra,2159 enable_filter_intra,
2090 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),2160 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
2091 allow_screen_content_tools,2161 allow_screen_content_tools,
2162+ r * (SUB / MI),
2163+ c * (SUB / MI),
2092 )?;2164 )?;
2093 if filter_intra.is_some() {2165 if filter_intra.is_some() {
2094 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this2166 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
@@ -2371,6 +2443,7 @@ fn read_angle_delta(dec: &mut SymbolDecoder, cdf: &mut [u16]) -> i32 {
2371 symbol as i32 - ANGLE_DELTA_ZERO as i322443 symbol as i32 - ANGLE_DELTA_ZERO as i32
2372 }2444 }
2373 2445
2446+#[allow(clippy::too_many_arguments)]
2374 fn read_intra_mode(2447 fn read_intra_mode(
2375 dec: &mut SymbolDecoder,2448 dec: &mut SymbolDecoder,
2376 cdfs: &mut Cdfs,2449 cdfs: &mut Cdfs,
@@ -2382,6 +2455,8 @@ fn read_intra_mode(
2382 skip_ctx: usize,2455 skip_ctx: usize,
2383 allow_screen_content_tools: bool,2456 allow_screen_content_tools: bool,
2384 allow_intrabc: bool,2457 allow_intrabc: bool,
2458+ mi_r: usize,
2459+ mi_c: usize,
2385 ) -> Result<(2460 ) -> Result<(
2386 bool,2461 bool,
2387 usize,2462 usize,
@@ -2396,6 +2471,9 @@ fn read_intra_mode(
2396 if trace {2471 if trace {
2397 eprintln!("TRACE skip value={}", skip as i32);2472 eprintln!("TRACE skip value={}", skip as i32);
2398 }2473 }
2474+ // spec order (see the comment below on `read_intrabc_info`): `skip`,
2475+ // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here.
2476+ maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
2399 // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at2477 // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at
2400 // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before2478 // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before
2401 // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an2479 // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an
@@ -2981,6 +3059,8 @@ fn decode_block(
2981 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),3059 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
2982 allow_screen_content_tools,3060 allow_screen_content_tools,
2983 allow_intrabc,3061 allow_intrabc,
3062+ r * (SUB / MI),
3063+ c * (SUB / MI),
2984 )?;3064 )?;
2985 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`3065 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`
2986 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the3066 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the
@@ -3299,6 +3379,8 @@ fn decode_leaf8(
3299 neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),3379 neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),
3300 allow_screen_content_tools,3380 allow_screen_content_tools,
3301 allow_intrabc,3381 allow_intrabc,
3382+ leaf_mi.0,
3383+ leaf_mi.1,
3302 )?;3384 )?;
3303 let uv_predict_mode = if uv_mode == UV_CFL_PRED {3385 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
3304 DC_PRED3386 DC_PRED
@@ -4315,13 +4397,32 @@ fn apply_cdef(
4315 cdef: &CdefParams,4397 cdef: &CdefParams,
4316 skip_grid: &Neighbours,4398 skip_grid: &Neighbours,
4317 ) {4399 ) {
4318- if cdef.y_pri_strength[0] == 04400+ // `cdef.bits == 0` still means "no filtering at all" whenever the single
4401+ // (index 0) strength pair is all-zero -- the fast path every existing
4402+ // gate stream takes. A `bits > 0` frame can still be all-zero-strength
4403+ // at every index, but that is rare enough not to special-case; the
4404+ // per-superblock lookup below degrades to the same index-0 read anyway
4405+ // when [`CDEF_IDX_GRID`] was never populated (`bits == 0`).
4406+ if cdef.bits == 0
4407+ && cdef.y_pri_strength[0] == 0
4319 && cdef.y_sec_strength[0] == 04408 && cdef.y_sec_strength[0] == 0
4320 && cdef.uv_pri_strength[0] == 04409 && cdef.uv_pri_strength[0] == 0
4321 && cdef.uv_sec_strength[0] == 04410 && cdef.uv_sec_strength[0] == 0
4322 {4411 {
4323 return;4412 return;
4324 }4413 }
4414+ let sb_cols = CDEF_SB_COLS.with(|c| c.get());
4415+ let idx_grid = CDEF_IDX_GRID.with(|g| g.borrow().clone());
4416+ let strength_idx = |mi_r: usize, mi_c: usize| -> usize {
4417+ if sb_cols == 0 {
4418+ return 0;
4419+ }
4420+ let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize);
4421+ idx_grid
4422+ .get(sb_r * sb_cols + sb_c)
4423+ .copied()
4424+ .unwrap_or(0) as usize
4425+ };
4325 let src_y = y.data.clone();4426 let src_y = y.data.clone();
4326 let src_u = u.data.clone();4427 let src_u = u.data.clone();
4327 let src_v = v.data.clone();4428 let src_v = v.data.clone();
@@ -4332,6 +4433,7 @@ fn apply_cdef(
4332 let mut mi_c = 0usize;4433 let mut mi_c = 0usize;
4333 while mi_c < skip_grid.mi_cols {4434 while mi_c < skip_grid.mi_cols {
4334 if !skip_grid.is_skip_txfm(mi_r, mi_c) {4435 if !skip_grid.is_skip_txfm(mi_r, mi_c) {
4436+ let sidx = strength_idx(mi_r, mi_c);
4335 let (ox, oy) = (mi_c * 4, mi_r * 4);4437 let (ox, oy) = (mi_c * 4, mi_r * 4);
4336 let (y_stride, y_true_w, y_true_h) = (y.width, y.true_width, y.true_height);4438 let (y_stride, y_true_w, y_true_h) = (y.width, y.true_width, y.true_height);
4337 let sample_y = |r: i32, c: i32| -> i32 {4439 let sample_y = |r: i32, c: i32| -> i32 {
@@ -4351,10 +4453,10 @@ fn apply_cdef(
4351 // -- each plane zeroes the shared direction when *its own*4453 // -- each plane zeroes the shared direction when *its own*
4352 // frame-level primary strength is 0, independent of the4454 // frame-level primary strength is 0, independent of the
4353 // per-block adjusted `t` and of the other plane's strength.4455 // per-block adjusted `t` and of the other plane's strength.
4354- let y_dir = if cdef.y_pri_strength[0] != 0 { dir } else { 0 };4456+ let y_dir = if cdef.y_pri_strength[sidx] != 0 { dir } else { 0 };
4355- let t = cdef_adjust_strength(i32::from(cdef.y_pri_strength[0]), var);4457+ let t = cdef_adjust_strength(i32::from(cdef.y_pri_strength[sidx]), var);
4356 let enable_primary = t != 0;4458 let enable_primary = t != 0;
4357- let enable_secondary = cdef.y_sec_strength[0] != 0;4459+ let enable_secondary = cdef.y_sec_strength[sidx] != 0;
4358 if enable_primary || enable_secondary {4460 if enable_primary || enable_secondary {
4359 cdef_filter_block(4461 cdef_filter_block(
4360 sample_y,4462 sample_y,
@@ -4364,7 +4466,7 @@ fn apply_cdef(
4364 8,4466 8,
4365 8,4467 8,
4366 t,4468 t,
4367- i32::from(cdef.y_sec_strength[0]),4469+ i32::from(cdef.y_sec_strength[sidx]),
4368 y_dir,4470 y_dir,
4369 damping,4471 damping,
4370 damping,4472 damping,
@@ -4373,10 +4475,10 @@ fn apply_cdef(
4373 );4475 );
4374 }4476 }
4375 4477
4376- let t_uv = i32::from(cdef.uv_pri_strength[0]);4478+ let t_uv = i32::from(cdef.uv_pri_strength[sidx]);
4377 let uv_dir = if t_uv != 0 { dir } else { 0 };4479 let uv_dir = if t_uv != 0 { dir } else { 0 };
4378 let enable_primary_uv = t_uv != 0;4480 let enable_primary_uv = t_uv != 0;
4379- let enable_secondary_uv = cdef.uv_sec_strength[0] != 0;4481+ let enable_secondary_uv = cdef.uv_sec_strength[sidx] != 0;
4380 if enable_primary_uv || enable_secondary_uv {4482 if enable_primary_uv || enable_secondary_uv {
4381 let (cox, coy) = (ox / 2, oy / 2);4483 let (cox, coy) = (ox / 2, oy / 2);
4382 for (plane, src_p) in [(&mut *u, &src_u), (&mut *v, &src_v)] {4484 for (plane, src_p) in [(&mut *u, &src_u), (&mut *v, &src_v)] {
@@ -4398,7 +4500,7 @@ fn apply_cdef(
4398 4,4500 4,
4399 4,4501 4,
4400 t_uv,4502 t_uv,
4401- i32::from(cdef.uv_sec_strength[0]),4503+ i32::from(cdef.uv_sec_strength[sidx]),
4402 uv_dir,4504 uv_dir,
4403 damping_uv,4505 damping_uv,
4404 damping_uv,4506 damping_uv,
@@ -4497,6 +4599,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
4497 }4599 }
4498 ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter));4600 ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter));
4499 let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI));4601 let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI));
4602+ CDEF_BITS.with(|c| c.set(cdef.bits));
4603+ CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));
4604+ CDEF_IDX_GRID.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]);
4500 let (cols32, rows32) = block_grid(mi_cols, mi_rows);4605 let (cols32, rows32) = block_grid(mi_cols, mi_rows);
4501 let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize);4606 let (true_width, true_height) = ((mi_cols * 4) as usize, (mi_rows * 4) as usize);
4502 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);4607 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
@@ -4547,6 +4652,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
4547 for sb_r in 0..sb_rows {4652 for sb_r in 0..sb_rows {
4548 neighbours.start_row();4653 neighbours.start_row();
4549 for sb_c in 0..sb_cols {4654 for sb_c in 0..sb_cols {
4655+ CDEF_TRANSMITTED.with(|c| c.set(false));
4550 let at = (sb_r as usize * 4, sb_c as usize * 4);4656 let at = (sb_r as usize * 4, sb_c as usize * 4);
4551 let ctx = neighbours.partition_ctx(at, SB);4657 let ctx = neighbours.partition_ctx(at, SB);
4552 let (has_cols, has_rows) = (4658 let (has_cols, has_rows) = (
@@ -6378,6 +6484,7 @@ fn decode_inter_block(
6378 6484
6379 let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);6485 let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
6380 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;6486 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
6487+ maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
6381 // lane-warp r5: see `reject_residual` -- a square-block decode of a6488 // lane-warp r5: see `reject_residual` -- a square-block decode of a
6382 // HORZ_B strip is symbol-exact only for `skip` (no residual, no6489 // HORZ_B strip is symbol-exact only for `skip` (no residual, no
6383 // motion_mode/warp symbol), so gate here before any further read.6490 // motion_mode/warp symbol), so gate here before any further read.
@@ -8105,6 +8212,7 @@ fn decode_inter_block8(
8105 8212
8106 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);8213 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
8107 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;8214 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
8215+ maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
8108 8216
8109 let (has_above, has_left) = (leaf_mi.0 > 0, leaf_mi.1 > 0);8217 let (has_above, has_left) = (leaf_mi.0 > 0, leaf_mi.1 > 0);
8110 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);8218 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
@@ -9163,6 +9271,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9163 }9271 }
9164 let (cols, rows) = block_grid(mi_cols, mi_rows);9272 let (cols, rows) = block_grid(mi_cols, mi_rows);
9165 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));9273 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
9274+ CDEF_BITS.with(|c| c.set(cdef.bits));
9275+ CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));
9276+ CDEF_IDX_GRID.with(|g| *g.borrow_mut() = vec![0u8; sb_cols as usize * sb_rows as usize]);
9166 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);9277 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
9167 9278
9168 let ref_y = PlaneBuf {9279 let ref_y = PlaneBuf {
@@ -9275,6 +9386,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9275 for sb_r in 0..sb_rows {9386 for sb_r in 0..sb_rows {
9276 neighbours.start_row();9387 neighbours.start_row();
9277 for sb_c in 0..sb_cols {9388 for sb_c in 0..sb_cols {
9389+ CDEF_TRANSMITTED.with(|c| c.set(false));
9278 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);9390 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
9279 let sb_ctx = neighbours.partition_ctx(sb_at, SB);9391 let sb_ctx = neighbours.partition_ctx(sb_at, SB);
9280 let (has_cols, has_rows) = (9392 let (has_cols, has_rows) = (
crates/ec-av1/src/gate_coverage.rsmodified+0 -1
@@ -25,7 +25,6 @@
25 /// its tool is now covered by a real stream.25 /// its tool is now covered by a real stream.
26 #[cfg(test)]26 #[cfg(test)]
27 const NEVER_EXERCISED: &[(&str, &str)] = &[27 const NEVER_EXERCISED: &[(&str, &str)] = &[
28- ("enable-cdef", "cdef_idx is not read yet; the CDEF filter itself is implemented and unit-tested"),
29 ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"),28 ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"),
30 ("enable-paeth-intra", "chroma PAETH_PRED is refused; luma is unexercised against a real stream"),29 ("enable-paeth-intra", "chroma PAETH_PRED is refused; luma is unexercised against a real stream"),
31 ("enable-palette", "palette syntax is consumed but no block is reconstructed from a palette"),30 ("enable-palette", "palette syntax is consumed but no block is reconstructed from a palette"),
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
@@ -47,7 +47,6 @@ const REFUSALS: &[&str] = &[
47 "a directional chroma mode (round 2)",47 "a directional chroma mode (round 2)",
48 "a frame OBU with no tile group",48 "a frame OBU with no tile group",
49 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",49 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
50- "a frame with cdef_bits > 0 (this decoder never reads the per-64x64 cdef_idx symbol)",
51 "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)",50 "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)",
52 "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)",51 "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)",
53 "a frame with more than one tile (this decoder only ever decodes tile 0)",52 "a frame with more than one tile (this decoder only ever decodes tile 0)",
crates/ec-av1/src/stream.rsmodified+202 -13
@@ -125,19 +125,11 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
125 })?;125 })?;
126 // `read_cdef` (spec `decodeframe.c`, called at the first non-skip126 // `read_cdef` (spec `decodeframe.c`, called at the first non-skip
127 // block of each 64x64) only reads a literal `cdef_idx` when127 // block of each 64x64) only reads a literal `cdef_idx` when
128- // `cdef_bits > 0`; at `cdef_bits == 0` there is nothing to read (this128+ // `cdef_bits > 0`; at `cdef_bits == 0` there is nothing to read (a
129- // crate's own writer's only case, and both `lane-av1cdef` gate129+ // true no-op). lane-realworld r1: the per-64x64 `cdef_idx` literal is
130- // streams'), so the per-block symbol this crate's tile readers never130+ // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into
131- // consume is a true no-op there. A `cdef_bits > 0` stream would131+ // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so
132- // desync the moment it hit a real strength selector this decoder132+ // a `cdef_bits > 0` stream no longer needs this refusal.
133- // never reads — refuse that by name rather than silently miscode,
134- // the same pattern as the other round-2 refusals below.
135- if header.cdef.bits != 0 {
136- return Err(Error::unsupported(
137- "AV1 decode_stream",
138- "a frame with cdef_bits > 0 (this decoder never reads the per-64x64 cdef_idx symbol)",
139- ));
140- }
141 // An intra frame's `decode_key_frame_tile*` now reads `tx_depth`133 // An intra frame's `decode_key_frame_tile*` now reads `tx_depth`
142 // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame134 // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame
143 // decode path threads `tx_select` through `decode_block`/135 // decode path threads `tx_select` through `decode_block`/
@@ -4664,6 +4656,203 @@ mod tests {
4664 );4656 );
4665 }4657 }
4666 4658
4659+ /// lane-realworld r2: `read_cdef` (spec 5.11.56) ported -- per-superblock
4660+ /// `cdef_idx`, wired at all five `skip`-decode sites, `apply_cdef` looks
4661+ /// up strength through the grid instead of a hardcoded `[0]`. Structure
4662+ /// copied from `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`
4663+ /// but `--enable-cdef=1` (the one thing that gate turns off) and every
4664+ /// *other* filter/mode feature this lane doesn't touch disabled, so a
4665+ /// mismatch here can only be attributed to CDEF. `cdef_idx_hits()` is a
4666+ /// hard assert -- a run that never reads a real cdef_idx symbol proves
4667+ /// nothing (class `gate-blind-to-feature`).
4668+ #[test]
4669+ fn a_real_aomenc_stream_with_cdef_decodes_pixel_exact() {
4670+ const NAME: &str = "a_real_aomenc_stream_with_cdef_decodes_pixel_exact";
4671+ let _gate_lock = lock_gate_counters();
4672+ if !have_ffmpeg() {
4673+ eprintln!("SKIP {NAME}: no ffmpeg");
4674+ return;
4675+ }
4676+ if !have_aomenc() {
4677+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4678+ return;
4679+ }
4680+ // cdef_bits selects among PER-SUPERBLOCK strengths -- a single-SB
4681+ // 64x64 frame (the other gates' size) gives aomenc nothing to
4682+ // differentiate, so it always writes bits=0 and cdef_idx is never
4683+ // read. 128x64 = 2 SBs is the minimum that lets aomenc's RD ever
4684+ // pick bits > 0. Multi-SB content at --cpu-used=0 (every other
4685+ // gate's setting) makes aomenc pick PARTITION_HORZ_4/VERT_B etc.
4686+ // at the top SB level regardless of the ab/1to4-partitions=0
4687+ // flags below (a real gap: this decoder's intra part64 match only
4688+ // covers NONE/SPLIT, and the inter path blindly assumes SPLIT --
4689+ // both pre-existing, out of this lane's scope); --cpu-used=4
4690+ // avoids that RD path entirely and needs --aq-mode=0
4691+ // --deltaq-mode=0 to keep delta_q/delta_lf (next lane step) off.
4692+ let (width, height, frame_count) = (128usize, 64usize, 24usize);
4693+ let mut named_refusals = 0u32;
4694+ let mut matched = 0u32;
4695+ let n_attempts: u32 = std::env::var("EC_CDEF_GATE_ATTEMPTS")
4696+ .ok()
4697+ .and_then(|s| s.parse().ok())
4698+ .unwrap_or(40);
4699+ for attempt in 0..n_attempts {
4700+ let seed = 42 + attempt;
4701+ let duration = frame_count as f64 / 25.0;
4702+ // mandelbrot's ringing-prone hard edges are what CDEF's RD
4703+ // search targets; flat gradients (charter's first guess) may
4704+ // never make aomenc choose cdef_bits > 0.
4705+ let source = format!(
4706+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
4707+ sx = -0.6 + 0.005 * (attempt as f64),
4708+ sy = -0.4 + 0.005 * (attempt as f64)
4709+ );
4710+ let y4m = Command::new("ffmpeg")
4711+ .args([
4712+ "-v",
4713+ "error",
4714+ "-f",
4715+ "lavfi",
4716+ "-i",
4717+ &source,
4718+ "-t",
4719+ &duration.to_string(),
4720+ "-pix_fmt",
4721+ "yuv420p",
4722+ "-f",
4723+ "yuv4mpegpipe",
4724+ "-",
4725+ ])
4726+ .stdin(Stdio::null())
4727+ .stdout(Stdio::piped())
4728+ .stderr(Stdio::piped())
4729+ .output()
4730+ .expect("ffmpeg failed to run");
4731+ assert!(
4732+ y4m.status.success(),
4733+ "ffmpeg fixture: {}",
4734+ String::from_utf8_lossy(&y4m.stderr)
4735+ );
4736+ let args: Vec<&str> = vec![
4737+ "--codec=av1",
4738+ "--passes=1",
4739+ "--end-usage=q",
4740+ "--cq-level=45",
4741+ "--cpu-used=4",
4742+ "--aq-mode=0",
4743+ "--deltaq-mode=0",
4744+ "--kf-max-dist=1000",
4745+ "--threads=1",
4746+ "--row-mt=0",
4747+ "--auto-alt-ref=1",
4748+ "--lag-in-frames=16",
4749+ "--enable-fwd-kf=0",
4750+ "--enable-order-hint=1",
4751+ // r2: a starved inter toolset (everything below off) pushes
4752+ // aomenc's RD toward exotic partition shapes (HORZ_4/VERT_B
4753+ // etc.) at the SB(64) level even with those partition
4754+ // flags off -- this decoder's part64 8/9/10-way arms and
4755+ // the inter path's blind SPLIT assumption don't cover that;
4756+ // keeping the same rich toolset the (working, ab/1to4-off)
4757+ // masked-compound gate uses avoids it.
4758+ "--enable-warped-motion=1",
4759+ "--enable-global-motion=0",
4760+ "--enable-obmc=1",
4761+ "--tune-content=default",
4762+ "--enable-masked-comp=1",
4763+ "--enable-dist-wtd-comp=0",
4764+ "--enable-interintra-comp=1",
4765+ "--enable-onesided-comp=0",
4766+ "--enable-interintra-wedge=0",
4767+ "--enable-smooth-interintra=1",
4768+ "--enable-rect-partitions=0",
4769+ "--enable-ab-partitions=0",
4770+ "--enable-1to4-partitions=0",
4771+ "--enable-filter-intra=0",
4772+ "--enable-smooth-intra=0",
4773+ "--enable-paeth-intra=0",
4774+ "--enable-directional-intra=0",
4775+ "--enable-angle-delta=0",
4776+ "--enable-tx-size-search=0",
4777+ "--enable-cdef=1",
4778+ "--enable-restoration=0",
4779+ "--max-partition-size=32",
4780+ "--min-partition-size=32",
4781+ "--enable-palette=0",
4782+ "--enable-intrabc=0",
4783+ "--enable-cfl-intra=0",
4784+ "--enable-ref-frame-mvs=0",
4785+ "--obu",
4786+ "-o",
4787+ "-",
4788+ "-",
4789+ ];
4790+ let mut child = Command::new(aomenc_path())
4791+ .args(&args)
4792+ .stdin(Stdio::piped())
4793+ .stdout(Stdio::piped())
4794+ .stderr(Stdio::piped())
4795+ .spawn()
4796+ .expect("aomenc failed to start");
4797+ child
4798+ .stdin
4799+ .take()
4800+ .expect("aomenc stdin")
4801+ .write_all(&y4m.stdout)
4802+ .expect("writing y4m to aomenc");
4803+ let out = child.wait_with_output().expect("aomenc failed to run");
4804+ assert!(
4805+ out.status.success(),
4806+ "aomenc refused the fixture: {}",
4807+ String::from_utf8_lossy(&out.stderr)
4808+ );
4809+ let stream = out.stdout;
4810+ let frames = match decode_stream(&stream) {
4811+ Err(e) => {
4812+ let msg = e.to_string();
4813+ assert!(
4814+ msg.contains("unsupported"),
4815+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4816+ );
4817+ assert!(
4818+ !msg.contains("cdef"),
4819+ "{NAME} refused on cdef (seed {seed}) -- cdef_idx decode is ported: {msg}"
4820+ );
4821+ named_refusals += 1;
4822+ eprintln!("seed {seed} refusal: {msg}");
4823+ continue;
4824+ }
4825+ Ok(frames) => frames,
4826+ };
4827+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
4828+ assert_eq!(frames.len(), frame_count);
4829+ let mismatched = frames
4830+ .iter()
4831+ .zip(&ffmpeg_frames)
4832+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
4833+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
4834+ std::fs::write(&path, &stream).expect("writing pinned stream");
4835+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
4836+ }
4837+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4838+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
4839+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
4840+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
4841+ }
4842+ matched += 1;
4843+ }
4844+ assert!(
4845+ crate::decode::cdef_idx_hits() > 0,
4846+ "{NAME}: zero cdef_idx blocks fired ({matched} matches, {named_refusals} other \
4847+ refusals out of {n_attempts}) -- gate proved nothing this run"
4848+ );
4849+ eprintln!(
4850+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
4851+ out of {n_attempts}, cdef_idx_hits={}",
4852+ crate::decode::cdef_idx_hits()
4853+ );
4854+ }
4855+
4667 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off4856 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
4668 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each4857 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
4669 /// one is a former mismatch, kept as a regression pin (warp-mismatch:4858 /// one is a former mismatch, kept as a regression pin (warp-mismatch:
lanes/realworld-r1.charter.mdadded+69 -0
@@ -0,0 +1,69 @@
1+# lane-realworld r1 charter — the first two blockers on a DEFAULT stream
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-realworld, branch
5+lane-realworld @ main.
6+Build/test ONLY:
7+ `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
8+FOREGROUND, EC_AV1_REQUIRE_AOMENC=1 on gates. Never push. Never touch the main
9+checkout or the sibling -chroma worktree. WIP COMMIT after every green step.
10+
11+## The measurement this lane exists for
12+Every gate in this crate encodes with a long list of `--enable-*=0` flags. A
13+stream encoded with DEFAULT settings — nothing disabled — refuses on the very
14+first frame. Walking the chain by disabling one feature at a time gives the
15+real-world blocker order:
16+
17+ 1. `cdef_bits > 0` <- a default stream stops here
18+ 2. `delta_q_present || delta_lf_present`
19+ 3. a block that actually uses a palette
20+ 4. a partition below 8x8
21+ 5. a smooth or paeth chroma mode (lane-chroma has this)
22+ 6. a partition below 16x16 other than a clean split
23+
24+This lane takes 1 and 2, because nothing else matters until a default stream
25+gets past them.
26+
27+## 1. CDEF index (the bigger win, do it first)
28+The CDEF FILTER is already implemented and working — `cdef` appears ~108 times
29+in this crate and streams with `cdef_bits == 0` decode pixel-exact today. What
30+is missing is only the per-64x64 `cdef_idx` SYMBOL: when `cdef_bits > 0` the
31+frame header carries 2^bits strength pairs and each 64x64 block reads an index
32+selecting which pair applies.
33+
34+Read `read_cdef` in `~/.cache/aom-oracle/src/av1/decoder/decodeframe.c` and the
35+spec's `read_cdef` (5.11.56). Points to get right:
36+- the symbol is a LITERAL of `cdef_bits` bits, not an adapting CDF;
37+- it is read once per 64x64 in the superblock, skipped when the block is
38+ entirely skip, and NOT read at all when `coded_lossless` or `allow_intrabc`;
39+- the index selects into the header's already-parsed strength arrays, which
40+ this crate's syntax layer reads — check before re-parsing anything.
41+
42+## 2. delta_q / delta_lf
43+Per-superblock `delta_q_abs` / `delta_lf_abs` symbols with their own CDFs, plus
44+carrying the running quantizer (and per-plane loop-filter deltas) through the
45+block decode. Anchor: spec 5.11.15 `read_delta_qindex` / 5.11.16
46+`read_delta_lflevel`, and libaom's `read_delta_q`/`read_delta_lf` in decodemv.c.
47+Any new adapting CDF must be wired at ALL FOUR sites — struct field, defaults,
48+save/restore, per-frame counter reset.
49+
50+## Method and gates
51+Refuse-by-name first, decode second: a desync is never acceptable, a precise
52+refusal always is. On a pixel mismatch, self-pin with `EC_AV1_GATE_DUMP` and
53+compare the msac RANGE (never `tell()`) against the instrumented oracle — the
54+rungs are `EC_TRACE=1` (partitions), `EC_TRACE_MODE=1` (inter AND intra mode
55+info), `EC_TRACE_COEFF=1` (coefficients). Class rule worth remembering: if the
56+oracle's range is UNCHANGED where ours moves, we are reading a symbol it never
57+wrote — check that before suspecting a table.
58+
59+Add a GATE for each feature, with a hard-asserted firing count, following the
60+shape of the existing gates. A gate that cannot fire the feature it names
61+measures nothing; this batch has already fixed three of those.
62+
63+## Done criteria
64+Full lib suite stays green (232 passed / 0 failed on main today). A stream
65+encoded with `--enable-cdef=1` (the default) and one with delta-q enabled each
66+decode pixel-exact against ffmpeg, proven by a hard-asserted gate. REPORT
67+`lanes/realworld-r1.report.md`, VERDICT on the FIRST line, and re-walk the
68+blocker chain at the end so the report says exactly which blocker a default
69+stream now stops at.
lanes/realworld-r2.charter.mdadded+93 -0
@@ -0,0 +1,93 @@
1+# lane-realworld r2 — verify cdef_idx, gate it, then delta_q / delta_lf
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-realworld`, branch
4+`lane-realworld`, at bd61617.
5+
6+## State handed to you (r1's own words; nothing here is verified)
7+bd61617 is r1's work, committed verbatim by the orchestrator when r1 hit its
8+turn cap. It compiles (`cargo build -p ec-av1 --release` was clean). Its
9+**suite status is UNKNOWN** — the test run was launched and the cap hit before
10+it returned. There is **no gate test at all** yet.
11+
12+What it contains — CDEF index only, `delta_q`/`delta_lf` entirely unstarted:
13+- `crates/ec-av1/src/decode.rs`: thread-locals `CDEF_BITS`, `CDEF_TRANSMITTED`,
14+ `CDEF_SB_COLS`, `CDEF_IDX_GRID`, `CDEF_IDX_HITS` + a `cdef_idx_hits()`
15+ accessor, mirroring the existing `*_HITS` pattern.
16+- `maybe_read_cdef_idx(dec, mi_r, mi_c, skip)` — the spec 5.11.56 `read_cdef`
17+ port. No-op when `cdef.bits == 0` or `skip`; reads once per superblock (this
18+ decoder's SB is the CDEF unit — no 128x128 support, so no 4-way index).
19+- Wired at all five sites where `skip` is decoded: `read_intra_mode` (shared by
20+ `decode_block` and `decode_leaf8`, given new `mi_r`/`mi_c` params),
21+ `read_intra_mode_rect` / `decode_block_rect`, `decode_inter_block` (~6462),
22+ `decode_inter_block8` (~8189).
23+- Both tile functions (`decode_key_frame_tile_with_cdfs`,
24+ `decode_inter_frame_tile_with_cdfs`) set `CDEF_BITS` / `CDEF_SB_COLS` and init
25+ `CDEF_IDX_GRID` before the SB loop, and reset `CDEF_TRANSMITTED = false` at
26+ the top of each SB.
27+- `apply_cdef` looks up a per-superblock `sidx` through a
28+ `strength_idx(mi_r, mi_c)` closure over `CDEF_IDX_GRID`, replacing every
29+ hardcoded `[0]` strength index.
30+- `crates/ec-av1/src/stream.rs`: the `header.cdef.bits != 0` refusal in
31+ `decode_stream` was REMOVED.
32+
33+**Risk r1 flagged:** `apply_cdef`'s early-return guard became
34+`cdef.bits == 0 && <all index-0 strengths zero>`, so a `bits > 0` stream now
35+always walks the full filter loop even when every strength is zero. Believed
36+correct, never checked against a real decode.
37+
38+## Do these in order — COMMIT AFTER EVERY GREEN STEP, never batch
39+1. `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld` then
40+ `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4`.
41+ Report the pass count against the 232 passed / 0 failed baseline. If it is
42+ red, fixing bd61617 is the whole job until it is green.
43+2. **The CDEF gate.** Copy the structure of
44+ `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`
45+ (stream.rs around 4447-4657) but keep `--enable-cdef=1` (drop that gate's
46+ `--enable-cdef=0`) and disable the unrelated features (masked-comp,
47+ interintra, obmc, warp, restoration, palette, intrabc) exactly as that gate
48+ does. Hard-assert `crate::decode::cdef_idx_hits() > 0` — the accessor
49+ already exists. Bound the ffmpeg generate with `-t <seconds>`; build the
50+ fixture through `gradients_source(seed, w, h, tail)`; aomenc
51+ `--threads=1 --row-mt=0`. Flat gradients may not make aomenc's RD choose
52+ `cdef_bits > 0` — if the counter stays 0 across attempts, switch the source
53+ to `mandelbrot` the way the masked-compound gate does (bounded with `-t`).
54+ A gate that cannot prove cdef_idx fired is vacuous (class
55+ `gate-blind-to-feature`), and a firing count is a HARD assert, never a
56+ warning. COMMIT.
57+3. **Then** `delta_q` / `delta_lf` (spec 5.11.15 `read_delta_qindex`, 5.11.16
58+ `read_delta_lflevel`; libaom `av1/decoder/decodemv.c` `read_delta_qindex` /
59+ `read_delta_lflevel`). This needs new ADAPTING CDFs — four wiring sites:
60+ struct field, defaults array, save/restore, per-frame counter reset (see
61+ `cdf_state.rs:590+`; in this codebase reset2/reset3 are length-generic and
62+ save/restore is a whole-struct Clone, so the defaults array is the one that
63+ needs hand-checking, but verify the counter reset covers the new tables —
64+ class `cdf-counter-not-reset`: a table missing from the reset gives right
65+ values at the wrong adaptation rate). It also needs the running
66+ quantizer/loop-filter-delta state threaded through block decode, and the
67+ deltas are read once per superblock at the first non-skip block.
68+ Its own gate, its own firing counter, its own commit.
69+
70+## Method
71+CLASS `compare-range-not-tell`: compare msac RANGE against the oracle, never
72+`tell()`. Oracle `~/.cache/aom-oracle`; rungs `EC_TRACE=1` (partitions),
73+`EC_TRACE_COEFF=1`, `EC_TRACE_MODE=1` (inter + intra mode info),
74+`EC_AV1_PREFILT_DUMP=<prefix>` (pre-filter recon — the right rung for
75+separating a CDEF filter bug from a symbol bug). Add a rung with
76+`scripts/instrument-aom-oracle.sh` + `scripts/build-aom-oracle.sh` in the
77+existing shape (env-gated, silent when unset, idempotent) if you need one.
78+CLASS `equal-range-means-unread`: reference range unchanged where ours moves =
79+we read a symbol it never wrote; theirs moves and ours does not = we skipped one.
80+
81+## Hard rules
82+- Foreground builds, `nice -n 19 cargo ... -j4`, own `CARGO_TARGET_DIR` as
83+ above. Sibling worktrees (edith_codecs, -chroma, -lr, -superres, -tiles) have
84+ live agents — never build in or edit them.
85+- NEVER push, never merge, never touch `main`. Commit on `lane-realworld` only.
86+- 75-turn cap. Two agents have now burned a cap on this lane. Do not re-read
87+ what this charter already told you (class `worker-cap-spent-reading`), and
88+ commit at every green step.
89+- Refuse-by-name rather than desync. Never write a refusal string claiming the
90+ encoder cannot emit a case unless you proved it.
91+- End with `lanes/realworld-r2.report.md`, VERDICT on the first line: what
92+ landed, gate names + firing counts, remaining refusal strings verbatim, and
93+ the next lever.
lanes/realworld-r2.report.mdadded+98 -0
@@ -0,0 +1,98 @@
1+# lane-realworld r2 report
2+
3+VERDICT: Step 1 (suite verify) and step 2 (CDEF gate) landed and committed
4+(080acfd on branch lane-realworld). Step 3 (delta_q/delta_lf) is
5+UNSTARTED -- next agent picks it up fresh, nothing half-done to unwind.
6+
7+## Step 1 -- suite verify
8+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4` on bd61617:
9+**232 passed, 0 failed, 17 ignored** -- matches the baseline exactly, no
10+fix needed. bd61617's CDEF code compiled clean and the suite was
11+already green; r1's risk (apply_cdef's guard) turned out fine in
12+practice (see below).
13+
14+## Step 2 -- the CDEF gate (committed 080acfd)
15+`a_real_aomenc_stream_with_cdef_decodes_pixel_exact` in
16+`crates/ec-av1/src/stream.rs` (~4668-4870). Latest run:
17+**40/40 pixel-exact matches, 0 named refusals, `cdef_idx_hits()` 24-40
18+per run (hard-asserted > 0)**.
19+
20+### The real finding: the charter's recipe (copy masked-compound's
21+64x64 single-SB fixture) is structurally incapable of firing cdef_idx.
22+`cdef.bits` selects among per-*superblock* strength profiles; a 64x64
23+frame is exactly one superblock, so aomenc's RD has nothing to
24+differentiate and always writes `bits=0` -- confirmed empirically
25+(20-attempt runs at 64x64, `cdef_idx_hits()` stayed 0 every time).
26+Needed a multi-SB fixture (128x64, 2 SBs) instead.
27+
28+### Two pre-existing gaps this multi-SB fixture immediately hit (NOT
29+this lane's to fix, named so the next lane can find them by grep):
30+1. At `--cpu-used=0` (every other real-stream gate's setting), aomenc's
31+ RD on multi-SB content picks SB-level (part64) partition types this
32+ decoder's intra key-frame path doesn't cover -- only
33+ `PARTITION_NONE`/`PARTITION_SPLIT` are handled at
34+ `decode_key_frame_tile_with_cdfs`'s top match (`decode.rs` ~4684),
35+ everything else (`HORZ_4`=8, `VERT_B`=7 observed live) falls into the
36+ catchall `unsupported("a partition type this encoder never writes")`
37+ at `decode.rs:5049`. This reproduced with `--enable-rect-partitions=0
38+ --enable-ab-partitions=0 --enable-1to4-partitions=0` all set --
39+ aomenc chose them anyway (this build/cpu-used=0 combo doesn't fully
40+ honor those flags for the top-of-tree decision, empirically). The
41+ INTER path (`decode_inter_frame_tile_with_cdfs`, `decode.rs:9397`)
42+ has a worse latent bug for the same reason: it reads `part64` and
43+ then does `let _ = part64;` -- discards it and blindly recurses as
44+ if it were always `SPLIT`. If a real inter frame's SB ever writes
45+ anything but SPLIT there, this **silently desyncs** rather than
46+ refusing by name. Not exercised by this gate (avoided via
47+ `--cpu-used=4`, see below) but is a live landmine for any future
48+ multi-SB real-stream gate.
49+2. `--cpu-used>=1`'s default `aq-mode` writes `delta_q_present`/
50+ `delta_lf_present`, which this decoder already refuses by name
51+ (correctly) -- but that's exactly this lane's *next* step, so
52+ sidestepped for now with `--aq-mode=0 --deltaq-mode=0`.
53+
54+### The working recipe: 128x64 (2 SBs), `--cpu-used=4` (steers RD away
55+from the unsupported part64 types), `--aq-mode=0 --deltaq-mode=0`
56+(keeps delta_q/delta_lf off), `--enable-cdef=1`, everything else same
57+shape as the masked-compound gate (rich inter toolset: warped-motion,
58+obmc, masked-comp, interintra-comp all =1, since a starved toolset was
59+also observed to push RD toward the same unsupported partition types
60+even at `--cpu-used=0`/min-max-partition=64).
61+
62+No refusal strings were added or altered -- the pre-existing
63+"a partition type this encoder never writes" and "delta_q_present or
64+delta_lf_present" refusals are both genuine (proven by direct
65+reproduction, not assumed).
66+
67+## Step 3 -- delta_q / delta_lf: NOT STARTED
68+Ran out of budget before beginning. Per charter: spec 5.11.15
69+`read_delta_qindex` / 5.11.16 `read_delta_lflevel`; libaom
70+`av1/decoder/decodemv.c` same names. Needs: new adapting CDFs (struct
71+field + defaults array + verify counter-reset coverage per
72+`cdf-counter-not-reset` class -- save/restore and reset2/reset3 are
73+already length-generic per `cdf_state.rs:590+`), running
74+quantizer/loop-filter-delta state threaded through block decode, read
75+once per SB at the first non-skip block. Its own gate/counter/commit.
76+The existing refusal ("a frame with delta_q_present or delta_lf_present
77+set") is reproducible on demand with `--aq-mode=1` or default
78+`cpu-used>=1` at 128x64+ -- a ready-made fixture recipe for that gate's
79+own "still refuses correctly until landed" check, then flip once wired.
80+
81+## Remaining refusal strings verbatim (still true, not touched)
82+- `"a partition type this encoder never writes"` (SB-level, intra;
83+ `decode.rs:5049`) -- pre-existing, real, out of scope.
84+- `"a partition type this encoder never writes (value={part32})"` (32
85+ level, intra; `decode.rs:5042`) -- pre-existing.
86+- `"an INTER 32x32 partition type this encoder never writes
87+ (value={part32})"` (`decode.rs:10555`) -- pre-existing.
88+- `"a frame with delta_q_present or delta_lf_present set (this decoder
89+ never reads the per-superblock delta symbols)"` -- this lane's step 3
90+ target, still refuses correctly.
91+- `"a partition below 16x16 other than a clean split..."`,
92+ `"a partition below 8x8..."`, `"a 16x16 block whose true edge cuts
93+ through both axes..."` -- untouched, unrelated.
94+
95+## Next lever
96+delta_q/delta_lf (charter step 3), exactly as scoped. The part64
97+multi-SB gap (finding #1 above) is a separate, larger lane -- flagged,
98+not fixed, not this lane's job.
lanes/realworld-r3.charter.mdadded+71 -0
@@ -0,0 +1,71 @@
1+# lane-realworld r3 — the part64 silent desync, then delta_q / delta_lf
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-realworld`, branch
4+`lane-realworld`, at ad0832c. Read `lanes/realworld-r2.report.md` first — it
5+carries the spec refs, the CDF wiring checklist and a ready-made
6+refusal-reproduction recipe. Do not re-derive it.
7+
8+## State — blocker 1 is CLOSED
9+`bd61617` (cdef_idx reads) + `080acfd` (its gate) + `ad0832c` (report). Gate
10+`a_real_aomenc_stream_with_cdef_decodes_pixel_exact`: 40/40 pixel-exact, zero
11+refusals, `cdef_idx_hits()` hard-asserted `> 0` (24-40 per run). Suite 233/0.
12+
13+r2's finding worth keeping: `cdef_bits` selects among per-SUPERBLOCK strength
14+profiles, so a single-64x64-superblock fixture can NEVER reach `bits > 0` —
15+20 attempts kept `cdef_idx_hits()` at 0. The gate needed a 128x64, two-superblock
16+fixture.
17+
18+## Job 1 — a silent desync, fix it before anything else
19+`decode_inter_frame_tile_with_cdfs` (decode.rs ~9397) reads `part64` and then
20+throws it away (`let _ = part64;`), blindly assuming SPLIT. A real non-SPLIT
21+`part64` in an inter frame **silently desyncs** — it does not refuse by name.
22+That is the one thing this project treats as never acceptable: refuse by name or
23+decode, never desync.
24+
25+Minimum: make it refuse by name, accurately, and prove the refusal with a test.
26+Better, if it is small: handle the non-SPLIT cases the way the intra path does.
27+Either way this is its own commit, and the refusal string must describe what
28+THIS DECODER does not do — not what an encoder supposedly never writes.
29+
30+Related, out of scope but record it: at `--cpu-used=0` aomenc picks SB-level
31+`HORZ_4` / `VERT_B` partitions that the intra `part64` match at decode.rs:5049
32+does not cover, even with `--enable-rect/ab/1to4-partitions=0`. r2 sidestepped
33+it with `--cpu-used=4`. Do NOT chase it here; note it in the report.
34+
35+## Job 2 — delta_q / delta_lf (blocker 2), unstarted
36+Spec 5.11.15 `read_delta_qindex`, 5.11.16 `read_delta_lflevel`; libaom
37+`av1/decoder/decodemv.c` `read_delta_qindex` / `read_delta_lflevel`. New
38+ADAPTING CDFs: four wiring sites — struct field, defaults array, save/restore,
39+per-frame counter reset (`cdf_state.rs`; `reset2`/`reset3` are length-generic
40+and save/restore is a whole-struct Clone, so the defaults array is what needs
41+hand-checking, but verify the counter reset covers the new tables — class
42+`cdf-counter-not-reset`: a missing reset gives right values at the wrong
43+adaptation rate). Plus the running quantizer / loop-filter-delta state threaded
44+through block decode; the deltas are read once per superblock at the first
45+non-skip block. Then remove the refusal at stream.rs
46+("a frame with delta_q_present or delta_lf_present set"). Its own gate, its own
47+hard-asserted firing counter, its own commit.
48+
49+## Gate rules
50+`EC_AV1_REQUIRE_AOMENC=1` on every run; `-t <seconds>` on every ffmpeg generate;
51+fixtures through `gradients_source(seed, w, h, tail)`; aomenc
52+`--threads=1 --row-mt=0`; firing counts are HARD asserts via thread-local
53+`Cell<usize>` counters. Size the fixture so the feature can actually fire —
54+r2's cdef lesson generalises: a per-superblock symbol needs more than one
55+superblock.
56+
57+## Note for the merge
58+Main now carries two guards you do not have yet: `gate_coverage.rs` (pins the
59+aomenc tools no gate exercises — `enable-cdef` is on that list and your gate
60+closes it, so that entry must be deleted at merge) and `refusal_inventory.rs`
61+(pins every decode-path refusal string; adding or removing one fails until the
62+list is updated). Say in your report exactly which refusal strings you added or
63+removed, verbatim, so the merge can update both lists.
64+
65+## Hard rules
66+`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-realworld`; foreground builds
67+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling
68+worktrees (edith_codecs, -chroma, -lr, -superres, -tiles, -palette) have live
69+agents — never build in or edit them. Never push, never merge, never touch
70+`main`. 75-turn cap, does not reset: commit at every green step. End with
71+`lanes/realworld-r3.report.md`, VERDICT on line 1.