forge
Explore
Log in

Don't you dare go Hollow

wip(av1): rect bw4/bh4 derivation + grid stamp fix, HORZ/VERT arms resurrected -- pin narrows but not byte-exact yet

Browse files at this commit

4a33f95bdf2180882cbb6730bf69f5c0b64e4e8bAhmet Kaan GümüşParent: 9cec3a2
crates/ec-av1/src/decode.rsmodified+217 -35
@@ -5222,7 +5222,9 @@ fn decode_inter_block(
52225222 )
52235223 };
52245224 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
5225- let bw4 = side / 4;
5225+ // lane-rect r2: true footprint, mirroring the single-ref path below.
5226+ let bw4 = write_w / 4;
5227+ let bh4 = write_h / 4;
52265228 // spec 7.10.2.8, doubled per side (`CompoundTplArgs`): same
52275229 // `use_ref_frame_mvs` gating as the single-ref `tpl` build
52285230 // below, just one `get_relative_dist` per reference.
@@ -5245,7 +5247,7 @@ fn decode_inter_block(
52455247 mi_row,
52465248 mi_col,
52475249 bw4,
5248- bw4,
5250+ bh4,
52495251 (ref0, ref1),
52505252 mi_cols as usize,
52515253 mi_rows as usize,
@@ -5293,7 +5295,12 @@ fn decode_inter_block(
52935295 globalmv_for_lf = is_globalmv;
52945296 ref_frame_for_lf = ref0;
52955297 mode_for_tx = 0;
5296- for dr in 0..bw4 {
5298+ // lane-rect r2: `grid` (mvstack.rs's own MiGrid, distinct from
5299+ // `neighbours`) must be stamped with the block's true footprint
5300+ // too -- a square `bw4`x`bw4` stamp here claims a rect strip's
5301+ // NEXT strip's own rows/cols before it decodes, corrupting
5302+ // every later mvstack scan that reads this cell back.
5303+ for dr in 0..bh4 {
52975304 for dc in 0..bw4 {
52985305 grid.set(
52995306 mi_row + dr,
@@ -5884,13 +5891,14 @@ fn decode_inter_block(
58845891 };
58855892
58865893 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
5887- let bw4 = side / 4;
5888- // lane-warp r5d: `reject_residual` marks the HORZ_B arm's top
5889- // strip, decoded as a square 32x32 block but truly 32x16 -- the
5890- // mv stack must be queried with the block's REAL extent (libaom
5891- // `av1_get_mv_refs` gets bw4=8, bh4=4), else scan_col, the
5892- // corner probes and `clamp_mv_ref` all size a 32-tall block.
5893- let bh4 = if reject_residual { bw4 / 2 } else { bw4 };
5894+ // lane-rect r2: the mv stack must be queried with the block's
5895+ // REAL extent (libaom `av1_get_mv_refs` gets bw4/bh4 from
5896+ // xd->width/xd->height, not a square guess) -- `write_w`/
5897+ // `write_h` already name the true HORZ/VERT/HORZ_B strip
5898+ // footprint (r1's plumbing), so derive bw4/bh4 from those
5899+ // instead of the old `side`-square (HORZ_B-only) heuristic.
5900+ let bw4 = write_w / 4;
5901+ let bh4 = write_h / 4;
58945902 // spec 7.10.2.8: only reached when the frame header set
58955903 // `use_ref_frame_mvs` (`tpl_frame` is `Some` then, `None`
58965904 // otherwise) -- `cur_offset_0` is this query block's own resolved
@@ -6050,7 +6058,7 @@ fn decode_inter_block(
60506058 && !skip_mode
60516059 && interintra_mode.is_none()
60526060 && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()
6053- || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1)
6061+ || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1)
60546062 .is_empty());
60556063 let mut obmc_selected = false;
60566064 // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL
@@ -6193,7 +6201,10 @@ fn decode_inter_block(
61936201 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()
61946202 );
61956203 }
6196- for dr in 0..bw4 {
6204+ // lane-rect r2: see the compound path's matching comment above --
6205+ // `grid` must be stamped with the block's true bh4/bw4 span, not
6206+ // a square `bw4`x`bw4` guess.
6207+ for dr in 0..bh4 {
61976208 for dc in 0..bw4 {
61986209 grid.set(
61996210 mi_row + dr,
@@ -8317,31 +8328,202 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
83178328 }
83188329 }
83198330 PARTITION_HORZ => {
8320- // lane-partitions r1 FINDING (pin rect-flake-1.obu,
8321- // decode frame 16 strip 2): decoding each 32x16 strip
8322- // with `side=32` square contexts desyncs -- a real
8323- // 32x16 block's mvstack weights/DRL selection use
8324- // n4_h=4, and the second strip picked a different
8325- // NEARMV than aomdec (class
8326- // decision-at-wrong-granularity). The write-footprint
8327- // plumbing (`write_w`/`write_h`, `_rect` methods)
8328- // stays; r2 threads true bw4/bh4 through
8329- // find_mv_stack + every neighbour ctx, gated by the
8330- // pinned stream. NOTE: HORZ_B's top strip carries the
8331- // same square-context corner-cut and owes the same
8332- // fix; its pins are byte-exact only because their
8333- // stacks happen to coincide.
8334- return Err(unsupported(
8335- "a HORZ rect partition (32x16 strips need rectangular \
8336- mvstack/context derivation, r2)",
8337- ));
8331+ // lane-rect r2: two true 32x16 strips. Both read at
8332+ // `side=BLOCK` (CDF/size-class selection stays square,
8333+ // matching HORZ_B's accepted corner-cut) but bw4/bh4
8334+ // (mvstack.rs, `motion_mode_eligible`) now derive from
8335+ // `write_w`/`write_h`'s true 32x16 footprint -- the
8336+ // pin's fix (r1's finding).
8337+ RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8338+ decode_inter_block(
8339+ &mut dec,
8340+ &mut cdfs,
8341+ &mut neighbours,
8342+ &mut grid,
8343+ at,
8344+ BLOCK,
8345+ mi_cols,
8346+ mi_rows,
8347+ &mut y,
8348+ &mut u,
8349+ &mut v,
8350+ &ref_y,
8351+ &ref_u,
8352+ &ref_v,
8353+ &ref_slots,
8354+ &sign_bias_table,
8355+ base_q_idx,
8356+ TxbSet::Luma32,
8357+ TxbSet::Luma32Inter,
8358+ TxbSet::Chroma16,
8359+ TX32,
8360+ TX16,
8361+ &scan32,
8362+ &scan16,
8363+ 3,
8364+ allow_high_precision_mv,
8365+ force_integer_mv,
8366+ interp_fixed,
8367+ enable_dual_filter,
8368+ tpl_frame.as_ref(),
8369+ reference_select,
8370+ enable_masked_compound,
8371+ enable_interintra_compound,
8372+ enable_jnt_comp,
8373+ order_hint_bits,
8374+ order_hint,
8375+ ref_order_hints,
8376+ skip_mode_present,
8377+ skip_mode_frame,
8378+ switchable_motion_mode,
8379+ allow_warped_motion,
8380+ true,
8381+ BLOCK,
8382+ SUB,
8383+ )?;
8384+ decode_inter_block(
8385+ &mut dec,
8386+ &mut cdfs,
8387+ &mut neighbours,
8388+ &mut grid,
8389+ (r32 as usize * 2 + 1, c32 as usize * 2),
8390+ BLOCK,
8391+ mi_cols,
8392+ mi_rows,
8393+ &mut y,
8394+ &mut u,
8395+ &mut v,
8396+ &ref_y,
8397+ &ref_u,
8398+ &ref_v,
8399+ &ref_slots,
8400+ &sign_bias_table,
8401+ base_q_idx,
8402+ TxbSet::Luma32,
8403+ TxbSet::Luma32Inter,
8404+ TxbSet::Chroma16,
8405+ TX32,
8406+ TX16,
8407+ &scan32,
8408+ &scan16,
8409+ 3,
8410+ allow_high_precision_mv,
8411+ force_integer_mv,
8412+ interp_fixed,
8413+ enable_dual_filter,
8414+ tpl_frame.as_ref(),
8415+ reference_select,
8416+ enable_masked_compound,
8417+ enable_interintra_compound,
8418+ enable_jnt_comp,
8419+ order_hint_bits,
8420+ order_hint,
8421+ ref_order_hints,
8422+ skip_mode_present,
8423+ skip_mode_frame,
8424+ switchable_motion_mode,
8425+ allow_warped_motion,
8426+ true,
8427+ BLOCK,
8428+ SUB,
8429+ )?;
83388430 }
83398431 PARTITION_VERT => {
8340- // See PARTITION_HORZ above -- same r2 refusal.
8341- return Err(unsupported(
8342- "a VERT rect partition (16x32 strips need rectangular \
8343- mvstack/context derivation, r2)",
8344- ));
8432+ // lane-rect r2: mirror of PARTITION_HORZ above with
8433+ // width/height swapped.
8434+ RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8435+ decode_inter_block(
8436+ &mut dec,
8437+ &mut cdfs,
8438+ &mut neighbours,
8439+ &mut grid,
8440+ at,
8441+ BLOCK,
8442+ mi_cols,
8443+ mi_rows,
8444+ &mut y,
8445+ &mut u,
8446+ &mut v,
8447+ &ref_y,
8448+ &ref_u,
8449+ &ref_v,
8450+ &ref_slots,
8451+ &sign_bias_table,
8452+ base_q_idx,
8453+ TxbSet::Luma32,
8454+ TxbSet::Luma32Inter,
8455+ TxbSet::Chroma16,
8456+ TX32,
8457+ TX16,
8458+ &scan32,
8459+ &scan16,
8460+ 3,
8461+ allow_high_precision_mv,
8462+ force_integer_mv,
8463+ interp_fixed,
8464+ enable_dual_filter,
8465+ tpl_frame.as_ref(),
8466+ reference_select,
8467+ enable_masked_compound,
8468+ enable_interintra_compound,
8469+ enable_jnt_comp,
8470+ order_hint_bits,
8471+ order_hint,
8472+ ref_order_hints,
8473+ skip_mode_present,
8474+ skip_mode_frame,
8475+ switchable_motion_mode,
8476+ allow_warped_motion,
8477+ true,
8478+ SUB,
8479+ BLOCK,
8480+ )?;
8481+ decode_inter_block(
8482+ &mut dec,
8483+ &mut cdfs,
8484+ &mut neighbours,
8485+ &mut grid,
8486+ (r32 as usize * 2, c32 as usize * 2 + 1),
8487+ BLOCK,
8488+ mi_cols,
8489+ mi_rows,
8490+ &mut y,
8491+ &mut u,
8492+ &mut v,
8493+ &ref_y,
8494+ &ref_u,
8495+ &ref_v,
8496+ &ref_slots,
8497+ &sign_bias_table,
8498+ base_q_idx,
8499+ TxbSet::Luma32,
8500+ TxbSet::Luma32Inter,
8501+ TxbSet::Chroma16,
8502+ TX32,
8503+ TX16,
8504+ &scan32,
8505+ &scan16,
8506+ 3,
8507+ allow_high_precision_mv,
8508+ force_integer_mv,
8509+ interp_fixed,
8510+ enable_dual_filter,
8511+ tpl_frame.as_ref(),
8512+ reference_select,
8513+ enable_masked_compound,
8514+ enable_interintra_compound,
8515+ enable_jnt_comp,
8516+ order_hint_bits,
8517+ order_hint,
8518+ ref_order_hints,
8519+ skip_mode_present,
8520+ skip_mode_frame,
8521+ switchable_motion_mode,
8522+ allow_warped_motion,
8523+ true,
8524+ SUB,
8525+ BLOCK,
8526+ )?;
83458527 }
83468528 _ => {
83478529 return Err(unsupported(format!(
lanes/rect-r2.charter.mdadded+66 -0
@@ -0,0 +1,66 @@
1+# lane-rect r2 charter — rectangular mvstack/context threading; HORZ/VERT decode for real
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-rect2, branch lane-rect2 @ f9f9767.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rect2 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink.
7+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.
8+
9+## Read first (in this order, nothing else)
10+1. lanes/partitions-r1.report.md — the defect you are fixing, fully localized.
11+2. git show 4782e57 -- crates/ec-av1/src/decode.rs — the strip-decode implementation
12+ to resurrect (HORZ/VERT arms with write_w/write_h; the arms currently refuse at
13+ decode.rs ~8212/~8232 with the finding in a comment).
14+3. crates/ec-av1/src/mvstack.rs — find_mv_stack's signature and its row/col scan +
15+ weight math (it takes a square bw4 today).
16+4. libaom /tmp/libaom-src/av1/common/mvref_common.c setup_ref_mv_list + scan_row_mbmi
17+ /scan_col_mbmi/scan_blk_mbmi: everywhere xd->width vs xd->height (n4_w/n4_h)
18+ appear asymmetrically — row scans use n4_w, col scans n4_h, weights use
19+ AOMMIN(2, ...) of each, max_row/col_offset derivation, has_top_right.
20+
21+## The defect (pinned, deterministic)
22+fixtures/rect-flake-1.obu, decode frame 16, block (0,8) = PARTITION_HORZ:
23+strip 2 (32x16 at mi 4,8) must build its mvstack as a 32x16 block (n4_w=8, n4_h=4);
24+our square-context decode picked the wrong NEARMV DRL entry (got strip 1's (0,-16),
25+aom gets (0,0)). Range ladder diverges inside strip 2.
26+
27+## Scope
28+1. Give find_mv_stack (and its ctx outputs new_mv_ctx/ref_mv_ctx + drl weighting)
29+ separate bw4/bh4 params; audit inside it every use of the current square bw4 and
30+ split per libaom (row scan lengths/weights vs col scan lengths/weights,
31+ max offsets, the extra-search + has_top_right rules). Square callers pass
32+ (bw4, bw4) — zero behavior change there (the lib suite proves it).
33+2. Thread bw4/bh4 through decode_inter_block's other side-derived SYNTAX surfaces
34+ for a rect block: is_inter/skip/ref ctx gathers over the true mi span (the _rect
35+ record methods from r1 already write the true span — the READ side must match),
36+ warp num_proj_ref/find_samples (bw4 vs bh4 in its row/col walks), obmc overlap
37+ eligibility (above row uses width, left col uses height). grep `bw4` inside
38+ decode_inter_block and adjudicate each use: width, height, or both.
39+3. Resurrect the HORZ/VERT arms from 4782e57 on top of this (side still drives CDF
40+ size-class selection — bsize 32x16 shares the 32-class tables? NO: check libaom
41+ size lookups: partition ctx bsize, tx size TX_32X16, size_group_lookup,
42+ skip/mode CDFs are indexed by bsize where 32x16 != 32x32 — verify EACH indexed
43+ table against libaom's bsize enum for BLOCK_32X16/16X32 and use the right rows;
44+ class cdf-row-held-constant).
45+4. GATE LADDER (in order): (a) rect-flake-1 pin must decode byte-exact:
46+ `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`
47+ (b) existing 11-pin default list stays green (c) un-clamp the free-partition gate
48+ recipe (stream.rs a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact:
49+ set --enable-rect-partitions=1 and --min-partition-size=16; the comment there
50+ documents this) and hammer 6x with EC_AV1_GATE_DUMP self-pin
51+ (/tmp/claude-1000/rect-flake-N.obu) — new mismatches: pin + localize via the
52+ report's ladder (recon dump → range ladder ours[k]=aom[k+1] → EC_AV1_TELL).
53+ (d) full lib suite.
54+5. Sweep HORZ_B's top strip (same class, latent): its arm should build the strip's
55+ stack as 32x16 too once find_mv_stack is rect-capable — flip it and confirm the
56+ 3 warp pins + ii pins stay byte-exact (they contain HORZ_B).
57+6. Add rect-flake-1 to the pinned test's default fixture list ONLY once it passes.
58+
59+## Done criteria
60+1. rect-flake-1 byte-exact; free gate un-clamped green 6/6 (or new pins + localization
61+ for anything beyond HORZ/VERT scope, refusing by name is fine for HORZ_A etc.);
62+ 12-fixture pin list green; lib suite green.
63+2. Committed to lane-rect2 (wip commits as you go — commit after EVERY green
64+ milestone); REPORT lanes/rect-r2.report.md, verdict FIRST line.
65+If the full ctx audit cannot finish: land find_mv_stack rect-capability + the pin
66+green + arms still refusing the residue you did not audit, report what is left.