From ebb03bdb1c71dfeb1eb54b5bd179fc7dfbdb1a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 29 Aug 2026 00:14:00 +0300 Subject: [PATCH] feat(av1): rect write-footprint plumbing; HORZ/VERT strips refuse by name pending rectangular mvstack (r2) Square-context strip decode desyncs (pin rect-flake-1.obu, frame 16 strip 2: NEARMV picked a different DRL entry -- a 32x16 block's stack weights use n4_h=4). Full strip decode kept in history (4782e57) for r2; free gate recipe re-clamped, green 3/3; lib 220/0; 11 pins byte-exact. HORZ_B's top strip carries the same latent corner-cut -- r2 scope. --- crates/ec-av1/src/decode.rs | 222 ++++------------------------------ crates/ec-av1/src/stream.rs | 27 +++-- lanes/partitions-r1.report.md | 55 +++++++++ 3 files changed, 98 insertions(+), 206 deletions(-) create mode 100644 lanes/partitions-r1.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 421f0af2..4389ad83 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -8210,205 +8210,31 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } } PARTITION_HORZ => { - // lane-partitions r1: 32x32 -> two 32x16 strips. Both - // read at `side=BLOCK` (matching HORZ_B's already- - // accepted square-context corner-cut, lane-warp r5) - // but each writes only its own true 32x16 footprint - // (`write_w=32, write_h=16`); the bottom strip's `at` - // is one SUB-row down, same offset HORZ_B's own - // bottom leaves use. - 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, - )?; + // 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)", + )); } PARTITION_VERT => { - // lane-partitions r1: 32x32 -> two 16x32 strips, - // mirroring PARTITION_HORZ above with width/height - // swapped; the right strip's `at` is one SUB-column - // right. - 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, - )?; + // See PARTITION_HORZ above -- same r2 refusal. + return Err(unsupported( + "a VERT rect partition (16x32 strips need rectangular \ + mvstack/context derivation, r2)", + )); } _ => { return Err(unsupported(format!( @@ -9169,6 +8995,8 @@ mod tests { false, false, false, + side, + side, ) .unwrap(); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 0f1b6744..41f31920 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3741,6 +3741,10 @@ mod tests { "--enable-onesided-comp=0", "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", + // lane-partitions r1: the free (rect=1, min=16) recipe found + // and PINNED rect-flake-1.obu -- the 32x16 strip mvstack + // desync now refused by name for r2; recipe re-clamped so the + // gate stays green until rectangular contexts land. "--enable-rect-partitions=0", "--enable-ab-partitions=1", "--enable-1to4-partitions=0", @@ -3824,16 +3828,21 @@ mod tests { matched > 0, "{NAME}: every attempt refused; the gate never decoded a free-partition stream" ); - // lane-rectgate r1 finding, not asserted (see the fn doc comment): - // `extended_partition_hits` stayed 0 across every recipe tried this - // round, including this one and the *already-green* warp gate run - // with the same probe wired in -- aomenc simply never selects - // PARTITION_HORZ_B for this small gradient fixture at cq=45, so the - // charter's diversity assertion cannot fire without a different - // fixture/recipe. A hard `assert!` here would fail every future run - // for a reason unrelated to decoder correctness. + // lane-partitions r1: HORZ/VERT arms landed, so the diversity probe + // graduates from rectgate r1's eprintln to a report line on + // `rect_partition_hits`; a zero-hit run SOFT-reports (aomenc RD may + // legitimately never pick a rect split in a small window -- same + // sampling caveat as the masked-compound gate's zero-hit runs). + // `extended_partition_hits` (HORZ_B) stays unasserted per rectgate r1. + if crate::decode::rect_partition_hits() == 0 { + eprintln!( + "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ + ({matched} matches, {named_refusals} refusals); sampling, not a regression" + ); + } eprintln!( - "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, extended_partition_hits={} (0 expected this round -- see fn doc)", + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} extended_partition_hits={}", + crate::decode::rect_partition_hits(), crate::decode::extended_partition_hits() ); } diff --git a/lanes/partitions-r1.report.md b/lanes/partitions-r1.report.md new file mode 100644 index 00000000..db153c4f --- /dev/null +++ b/lanes/partitions-r1.report.md @@ -0,0 +1,55 @@ +# lane-partitions r1 report + +VERDICT: PARTIAL — rect write-footprint plumbing landed and a REAL defect in the +square-context strip approach was found, pinned, and refused by name; pixel-exact +HORZ/VERT decode moves to r2 with the pin as its gate. + +## What landed +- `decode_inter_block` gained `write_w`/`write_h`: `side` still drives syntax, the + pixel write and every neighbour/grid stamp clip to the true footprint. New `_rect` + siblings on `Neighbours`/`PlaneBuf` (`record_inter_rect`, `fill_lf_grid_rect`, + `fill_skip_grid_rect`, `record_compound_ctx_rect`, `record_rect`, `record_mi_rect`, + `reconstruct_mc_rect`); all square callers delegate — zero behavior change on + existing paths (full lib suite 220/0, all 11 pins byte-exact). +- `RECT_PARTITION_HITS` counter + `rect_partition_hits()`. +- HORZ/VERT arms exist but REFUSE by name: "rect partition (32x16/16x32 strips need + rectangular mvstack/context derivation, r2)". The full strip-decode implementation + is in git history (commit 4782e57) for r2 to resurrect. + +## The defect (why the arms refuse) +The builder's strip decode ran each 32x16 strip with `side=32` square contexts +(HORZ_B's accepted corner-cut). The free-recipe gate immediately found mismatches +(4/6 runs); pin `fixtures/rect-flake-1.obu`, decode frame 16, block (0,8) = HORZ: +- strip 1 (mi 0,8): decodes EXACTLY (NEWMV (0,-16), WARPED — matches aomdec). +- strip 2 (mi 4,8): aomdec NEARMV mv=(0,0); ours picked mv=(0,-16) — the DRL/stack + differ because a true 32x16 block's mvstack scan/weights use n4_h=4, not 8. + Range ladder diverges inside the strip (consumption via drl/ctx), recon wrong in + 3 quadrants from f16 on. +Class: decision-at-wrong-granularity. COROLLARY: HORZ_B's top strip carries the SAME +corner-cut; its pins pass only because those stacks coincide — r2's rectangular +context threading must cover HORZ_B too (noted in the arm comment). + +## Gate state +`a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact` re-clamped to the +rectgate recipe (rect=0, ab=1, min=32) — green 3/3 (29–33 matches/40). The free +recipe (rect=1, min=16) that found the pin is documented in the gate comment; r2 +un-clamps it once rectangular contexts land. + +## Evidence +- rect-flake-1.obu pinned to fixtures; repro deterministic (frame 16 luma). +- Localization: recon diff f16 quads [0,466,996,860]; range ladder exact through + decode frame 15, diverges in frame 16 block (0,8) strip 2; per-block trace diff + (aom EC_TRACE vs ours) shows the NEARMV mv disagreement above. +- lib suite 220/0; pins 11/11; re-clamped gate 3/3. + +## r2 charter seed +Thread true bw4/bh4 through find_mv_stack (row/col scan lengths + weights), DRL ctx, +is_inter/ref/skip ctx gathers, warp num_proj_ref/samples, obmc overlap — libaom uses +xd->width/height everywhere `side` is square here. Gate = rect-flake-1 pin first, +then the free recipe with HORZ/VERT refusals forbidden. Sweep HORZ_B's strip in the +same round (same class, latent). + +Orchestrator note: builder hit its turn cap twice; WIP committed by orchestrator +(4782e57), gate reactivation + test-cfg compile fix + defect hunt + refusal revert +done inline. Verification: orchestrator-run gates/suites above (cross-provider seats +still down).