From b39163462bbeed9cd382d181327745c1deff1ba2 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 03:51:02 +0300 Subject: [PATCH] wip(lane-partab): HORZ_A/VERT_A/VERT_B INTER dispatch arms decode (16x16 squares + 16x32/32x16 strips, PARTAB_HITS atomic); gate report prints partab_hits --- crates/ec-av1/src/decode.rs | 470 ++++++++++++++++++++++++++++++++++++ crates/ec-av1/src/stream.rs | 13 +- lanes/partab-r1.charter.md | 62 +++++ 3 files changed, 539 insertions(+), 6 deletions(-) create mode 100644 lanes/partab-r1.charter.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 62b2a091..35153bbd 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -44,7 +44,10 @@ const PARTITION_NONE: usize = 0; const PARTITION_HORZ: usize = 1; const PARTITION_VERT: usize = 2; const PARTITION_SPLIT: usize = 3; +const PARTITION_HORZ_A: usize = 4; const PARTITION_HORZ_B: usize = 5; +const PARTITION_VERT_A: usize = 6; +const PARTITION_VERT_B: usize = 7; const SB_MI: u32 = 16; const BLOCK_MI: u32 = 8; @@ -258,6 +261,18 @@ pub(crate) fn rect_partition_hits() -> usize { RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed) } +/// lane-partab r1: how many 32x32 quadrants decoded an AB partition +/// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one +/// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the +/// free-partition gate's proof this round's arms actually fired. +static PARTAB_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// Current value of [`PARTAB_HITS`]. +pub(crate) fn partab_hits() -> usize { + PARTAB_HITS.load(std::sync::atomic::Ordering::Relaxed) +} + /// How many [`read_inter_compound_mode`] reads actually happened /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound @@ -8613,6 +8628,461 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( BLOCK, )?; } + PARTITION_HORZ_A => { + // lane-partab r1: two 16x16 squares on top + a true + // 32x16 strip below (libaom decode_partition + // PARTITION_HORZ_A: TL, TR, bottom strip). + PARTAB_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + SUB, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2, c32 as usize * 2 + 1), + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + 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_A => { + // lane-partab r1: mirror of PARTITION_HORZ_A with + // width/height swapped (TL, BL, right 16x32 strip). + PARTAB_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + SUB, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + SUB, + )?; + 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, + )?; + } + PARTITION_VERT_B => { + // lane-partab r1: true 16x32 strip on the left + two + // 16x16 squares on the right (libaom decode_partition + // PARTITION_VERT_B: left strip, TR, BR). + PARTAB_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), + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + SUB, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2 + 1), + SUB, + 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::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + 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, + false, + SUB, + SUB, + )?; + } _ => { return Err(unsupported(format!( "a partition type this encoder never writes (value={part32})" diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b6091184..62cae200 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3840,12 +3840,13 @@ mod tests { ({matched} matches, {named_refusals} refusals); sampling, not a regression" ); } - eprintln!( - "{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() - ); - } + eprintln!( + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} extended_partition_hits={} partab_hits={}", + crate::decode::rect_partition_hits(), + crate::decode::extended_partition_hits(), + crate::decode::partab_hits() + ); +} /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type` diff --git a/lanes/partab-r1.charter.md b/lanes/partab-r1.charter.md new file mode 100644 index 00000000..6f99737a --- /dev/null +++ b/lanes/partab-r1.charter.md @@ -0,0 +1,62 @@ +# lane-partab r1 charter — AB partition arms (HORZ_A / VERT_A / VERT_B) decode + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-partab, branch lane-partab @ 6f4ca37. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-partab 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: ~60 calls. Commit compiling WIP + report by call 45. Read ONLY what is named. + +## Facts you build on (verified this batch, do not re-derive) +- HORZ/VERT/HORZ_B already decode for real: 32x16/16x32 strips thread true + write_w/write_h through mvstack (MiInfo.size_h), warp samples, OBMC, deblock + tx_h_grid, and the motion_mode/obmc CDF rect rows (cdf.rs rows 4=BLOCK_16X32, + 5=BLOCK_32X16). All sub-block sizes an AB partition produces (16x16, 32x16, + 16x32) ALREADY decode. +- The INTER dispatch is decode.rs ~8013 `match part32 {` with arms + NONE/HORZ/VERT/SPLIT/HORZ_B; the catch-all `_ =>` at ~8616 refuses + HORZ_A(4)/VERT_A(6)/VERT_B(7)/HORZ_4(8)/VERT_4(9). +- Spec sub-block layout at a 32x32 area, mi origin (r,c) in 4x4 units of 8 + (i.e. `at = (r32*2, c32*2)` is 16px units — CHECK the existing arms' `at` + arithmetic and copy it; lane-warp r5 once lost a round to `at` being 16px + units, decode.rs:4858-9 comment): + - HORZ_A: 16x16 at (r,c) + 16x16 at (r,c+16px) + 32x16 strip at (r+16px,c) + - VERT_A: 16x16 at (r,c) + 16x16 at (r+16px,c) + 16x32 strip at (r,c+16px) + - VERT_B: 16x32 strip at (r,c) + 16x16 at (r,c+16px) + 16x16 at (r+16px,c+16px) + (verify each against /tmp/libaom-src/av1/common/enums.h + decodeframe.c + decode_partition's PARTITION_HORZ_A/VERT_A/VERT_B cases — the A/B naming is + easy to mirror-swap; libaom is the oracle.) +- decode_inter_block's trailing 3 args are (is_rect_strip: bool, write_w, write_h) + in mi-of-16px units (SUB=16px class, BLOCK=32px class) — copy how the HORZ and + VERT arms pass them for the strip + how SPLIT passes for 16x16 leaves. +- Partition CDF/ctx for the arms is already read correctly (VERT_ALIKE/ + HORZ_ALIKE gathers include values 4..9); ONLY the dispatch refuses. + +## Scope +1. decode.rs ~8013 match: add PARTITION_HORZ_A / PARTITION_VERT_A / + PARTITION_VERT_B arms composing the SAME decode_inter_block calls the + HORZ/VERT/SPLIT/HORZ_B arms already make (order = spec decode order). + Declare consts PARTITION_HORZ_A=4, PARTITION_VERT_A=6, PARTITION_VERT_B=7 + next to PARTITION_HORZ_B. Mind per-arm neighbour/ctx recording: copy + exactly what the existing arms do after each sub-block (record_* calls). +2. HORZ_4/VERT_4 and the INTRA-frame dispatch (~3624) stay refusing — do not + touch them. +3. Gate ladder, in order: + a. full 15-pin default list green (pins contain HORZ_B streams — regression + canary): cargo test -p ec-av1 --release --lib pinned_warp -- --nocapture + b. free-partition gate a_real_aomenc_stream_with_free_partitions_decodes_ + pixel_exact 6x with EC_AV1_GATE_DUMP self-pin + (/tmp/claude-1000/partab-flake-N.obu). A mismatch = pin it, report the + recon-diff location (EC_AV1_PREFILT_DUMP both sides), do NOT guess-fix. + c. full lib suite. +4. If aomenc's free recipe never emits an AB partition (grep your decode for + the arm actually firing — add a PARTAB_HITS atomic like WEDGE_HITS), find a + recipe that does (aomenc --enable-ab-partitions=1 is default-on; try + structured content / lower cq) and add a dedicated gate test that forbids + the AB refusal string, soft-skipping on zero-hit runs like the maskcomp + gate. Verified-but-unfired is reportable; unverified is not landable. + +## Done criteria +1. AB arms decode; hits proven fired at least once (atomic count in report); + pins green; free gate 6/6; lib green. +2. Committed to lane-partab (wip commit after EVERY green milestone); REPORT + lanes/partab-r1.report.md, verdict FIRST line, evidence per claim.