diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index edf671ee..8ae63656 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5222,7 +5222,9 @@ fn decode_inter_block( ) }; let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); - let bw4 = side / 4; + // lane-rect r2: true footprint, mirroring the single-ref path below. + let bw4 = write_w / 4; + let bh4 = write_h / 4; // spec 7.10.2.8, doubled per side (`CompoundTplArgs`): same // `use_ref_frame_mvs` gating as the single-ref `tpl` build // below, just one `get_relative_dist` per reference. @@ -5245,7 +5247,7 @@ fn decode_inter_block( mi_row, mi_col, bw4, - bw4, + bh4, (ref0, ref1), mi_cols as usize, mi_rows as usize, @@ -5293,7 +5295,12 @@ fn decode_inter_block( globalmv_for_lf = is_globalmv; ref_frame_for_lf = ref0; mode_for_tx = 0; - for dr in 0..bw4 { + // lane-rect r2: `grid` (mvstack.rs's own MiGrid, distinct from + // `neighbours`) must be stamped with the block's true footprint + // too -- a square `bw4`x`bw4` stamp here claims a rect strip's + // NEXT strip's own rows/cols before it decodes, corrupting + // every later mvstack scan that reads this cell back. + for dr in 0..bh4 { for dc in 0..bw4 { grid.set( mi_row + dr, @@ -5884,13 +5891,14 @@ fn decode_inter_block( }; let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); - let bw4 = side / 4; - // lane-warp r5d: `reject_residual` marks the HORZ_B arm's top - // strip, decoded as a square 32x32 block but truly 32x16 -- the - // mv stack must be queried with the block's REAL extent (libaom - // `av1_get_mv_refs` gets bw4=8, bh4=4), else scan_col, the - // corner probes and `clamp_mv_ref` all size a 32-tall block. - let bh4 = if reject_residual { bw4 / 2 } else { bw4 }; + // lane-rect r2: the mv stack must be queried with the block's + // REAL extent (libaom `av1_get_mv_refs` gets bw4/bh4 from + // xd->width/xd->height, not a square guess) -- `write_w`/ + // `write_h` already name the true HORZ/VERT/HORZ_B strip + // footprint (r1's plumbing), so derive bw4/bh4 from those + // instead of the old `side`-square (HORZ_B-only) heuristic. + let bw4 = write_w / 4; + let bh4 = write_h / 4; // spec 7.10.2.8: only reached when the frame header set // `use_ref_frame_mvs` (`tpl_frame` is `Some` then, `None` // otherwise) -- `cur_offset_0` is this query block's own resolved @@ -6050,7 +6058,7 @@ fn decode_inter_block( && !skip_mode && interintra_mode.is_none() && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty() - || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1) + || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1) .is_empty()); let mut obmc_selected = false; // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL @@ -6193,7 +6201,10 @@ fn decode_inter_block( skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos() ); } - for dr in 0..bw4 { + // lane-rect r2: see the compound path's matching comment above -- + // `grid` must be stamped with the block's true bh4/bw4 span, not + // a square `bw4`x`bw4` guess. + for dr in 0..bh4 { for dc in 0..bw4 { grid.set( mi_row + dr, @@ -8317,31 +8328,202 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } } PARTITION_HORZ => { - // lane-partitions r1 FINDING (pin rect-flake-1.obu, - // decode frame 16 strip 2): decoding each 32x16 strip - // with `side=32` square contexts desyncs -- a real - // 32x16 block's mvstack weights/DRL selection use - // n4_h=4, and the second strip picked a different - // NEARMV than aomdec (class - // decision-at-wrong-granularity). The write-footprint - // plumbing (`write_w`/`write_h`, `_rect` methods) - // stays; r2 threads true bw4/bh4 through - // find_mv_stack + every neighbour ctx, gated by the - // pinned stream. NOTE: HORZ_B's top strip carries the - // same square-context corner-cut and owes the same - // fix; its pins are byte-exact only because their - // stacks happen to coincide. - return Err(unsupported( - "a HORZ rect partition (32x16 strips need rectangular \ - mvstack/context derivation, r2)", - )); + // lane-rect r2: two true 32x16 strips. Both read at + // `side=BLOCK` (CDF/size-class selection stays square, + // matching HORZ_B's accepted corner-cut) but bw4/bh4 + // (mvstack.rs, `motion_mode_eligible`) now derive from + // `write_w`/`write_h`'s true 32x16 footprint -- the + // pin's fix (r1's finding). + RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + )?; } PARTITION_VERT => { - // See PARTITION_HORZ above -- same r2 refusal. - return Err(unsupported( - "a VERT rect partition (16x32 strips need rectangular \ - mvstack/context derivation, r2)", - )); + // lane-rect r2: mirror of PARTITION_HORZ above with + // width/height swapped. + RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2, c32 as usize * 2 + 1), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + )?; } _ => { return Err(unsupported(format!( diff --git a/lanes/rect-r2.charter.md b/lanes/rect-r2.charter.md new file mode 100644 index 00000000..779f6b53 --- /dev/null +++ b/lanes/rect-r2.charter.md @@ -0,0 +1,66 @@ +# lane-rect r2 charter — rectangular mvstack/context threading; HORZ/VERT decode for real + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-rect2, branch lane-rect2 @ f9f9767. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rect2 cargo test -p ec-av1 --release --lib -- --nocapture` +FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink. +BUDGET DISCIPLINE (you have ~75 tool calls, two predecessors died at the cap): read ONLY the files/lines named here; commit compiling WIP + write the report by call 60, whatever state you are in. + +## Read first (in this order, nothing else) +1. lanes/partitions-r1.report.md — the defect you are fixing, fully localized. +2. git show 4782e57 -- crates/ec-av1/src/decode.rs — the strip-decode implementation + to resurrect (HORZ/VERT arms with write_w/write_h; the arms currently refuse at + decode.rs ~8212/~8232 with the finding in a comment). +3. crates/ec-av1/src/mvstack.rs — find_mv_stack's signature and its row/col scan + + weight math (it takes a square bw4 today). +4. libaom /tmp/libaom-src/av1/common/mvref_common.c setup_ref_mv_list + scan_row_mbmi + /scan_col_mbmi/scan_blk_mbmi: everywhere xd->width vs xd->height (n4_w/n4_h) + appear asymmetrically — row scans use n4_w, col scans n4_h, weights use + AOMMIN(2, ...) of each, max_row/col_offset derivation, has_top_right. + +## The defect (pinned, deterministic) +fixtures/rect-flake-1.obu, decode frame 16, block (0,8) = PARTITION_HORZ: +strip 2 (32x16 at mi 4,8) must build its mvstack as a 32x16 block (n4_w=8, n4_h=4); +our square-context decode picked the wrong NEARMV DRL entry (got strip 1's (0,-16), +aom gets (0,0)). Range ladder diverges inside strip 2. + +## Scope +1. Give find_mv_stack (and its ctx outputs new_mv_ctx/ref_mv_ctx + drl weighting) + separate bw4/bh4 params; audit inside it every use of the current square bw4 and + split per libaom (row scan lengths/weights vs col scan lengths/weights, + max offsets, the extra-search + has_top_right rules). Square callers pass + (bw4, bw4) — zero behavior change there (the lib suite proves it). +2. Thread bw4/bh4 through decode_inter_block's other side-derived SYNTAX surfaces + for a rect block: is_inter/skip/ref ctx gathers over the true mi span (the _rect + record methods from r1 already write the true span — the READ side must match), + warp num_proj_ref/find_samples (bw4 vs bh4 in its row/col walks), obmc overlap + eligibility (above row uses width, left col uses height). grep `bw4` inside + decode_inter_block and adjudicate each use: width, height, or both. +3. Resurrect the HORZ/VERT arms from 4782e57 on top of this (side still drives CDF + size-class selection — bsize 32x16 shares the 32-class tables? NO: check libaom + size lookups: partition ctx bsize, tx size TX_32X16, size_group_lookup, + skip/mode CDFs are indexed by bsize where 32x16 != 32x32 — verify EACH indexed + table against libaom's bsize enum for BLOCK_32X16/16X32 and use the right rows; + class cdf-row-held-constant). +4. GATE LADDER (in order): (a) rect-flake-1 pin must decode byte-exact: + `EC_AV1_GATE_DUMP_PIN=/home/user/Documents/Code/Rust/edith_codecs/fixtures/rect-flake-1.obu cargo test -p ec-av1 --release --lib pinned_warp_stream_decodes_pixel_exact -- --ignored --nocapture` + (b) existing 11-pin default list stays green (c) un-clamp the free-partition gate + recipe (stream.rs a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact: + set --enable-rect-partitions=1 and --min-partition-size=16; the comment there + documents this) and hammer 6x with EC_AV1_GATE_DUMP self-pin + (/tmp/claude-1000/rect-flake-N.obu) — new mismatches: pin + localize via the + report's ladder (recon dump → range ladder ours[k]=aom[k+1] → EC_AV1_TELL). + (d) full lib suite. +5. Sweep HORZ_B's top strip (same class, latent): its arm should build the strip's + stack as 32x16 too once find_mv_stack is rect-capable — flip it and confirm the + 3 warp pins + ii pins stay byte-exact (they contain HORZ_B). +6. Add rect-flake-1 to the pinned test's default fixture list ONLY once it passes. + +## Done criteria +1. rect-flake-1 byte-exact; free gate un-clamped green 6/6 (or new pins + localization + for anything beyond HORZ/VERT scope, refusing by name is fine for HORZ_A etc.); + 12-fixture pin list green; lib suite green. +2. Committed to lane-rect2 (wip commits as you go — commit after EVERY green + milestone); REPORT lanes/rect-r2.report.md, verdict FIRST line. +If the full ctx audit cannot finish: land find_mv_stack rect-capability + the pin +green + arms still refusing the residue you did not audit, report what is left.