Gate the mv-stack top-right probe on has_top_right
Browse files at this commitb6c54c5d4613a09b235c18b1fc6b11e3f8062643Parent: a948429- fix
- gate the mv-stack top-right probe on has_top_right
- 128-root motion_mode/obmc CDF rows
- TX_64X64 coded corner on the intra-in-inter path
5 changed files +141 -8
- crates/ec-av1/src/cdf.rs +14 -2
- crates/ec-av1/src/cdf_state.rs +2 -2
- crates/ec-av1/src/decode.rs +11 -2
- crates/ec-av1/src/mvstack.rs +12 -2
- lanes/sb128c-r5.handoff.md +102 -0
crates/ec-av1/src/cdf.rsmodified+14 -2
| @@ -1645,7 +1645,7 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812 | |||
| 1645 | /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers | 1645 | /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers |
| 1646 | /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 | 1646 | /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 |
| 1647 | /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. | 1647 | /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. |
| 1648 | -pub const OBMC: [[u16; 3]; 14] = [ | 1648 | +pub const OBMC: [[u16; 3]; 17] = [ |
| 1649 | [10437, 32768, 0], | 1649 | [10437, 32768, 0], |
| 1650 | [17432, 32768, 0], | 1650 | [17432, 32768, 0], |
| 1651 | [25817, 32768, 0], | 1651 | [25817, 32768, 0], |
| @@ -1669,6 +1669,11 @@ pub const OBMC: [[u16; 3]; 14] = [ | |||
| 1669 | // BLOCK_8X16 (4) and BLOCK_16X8 (5) of libaom's `default_obmc_cdf`. | 1669 | // BLOCK_8X16 (4) and BLOCK_16X8 (5) of libaom's `default_obmc_cdf`. |
| 1670 | [9371, 32768, 0], | 1670 | [9371, 32768, 0], |
| 1671 | [9301, 32768, 0], | 1671 | [9301, 32768, 0], |
| 1672 | + // lane-sb128c r5: the 128-root rows -- BLOCK_64X128 (13), BLOCK_128X64 | ||
| 1673 | + // (14), BLOCK_128X128 (15) of libaom's `default_obmc_cdf`. | ||
| 1674 | + [31014, 32768, 0], | ||
| 1675 | + [31560, 32768, 0], | ||
| 1676 | + [32638, 32768, 0], | ||
| 1672 | ]; | 1677 | ]; |
| 1673 | 1678 | ||
| 1674 | /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize | 1679 | /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize |
| @@ -1678,7 +1683,7 @@ pub const OBMC: [[u16; 3]; 14] = [ | |||
| 1678 | /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` | 1683 | /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` |
| 1679 | /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` | 1684 | /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` |
| 1680 | /// under `allow_warped_motion`) -- lane-warp round 1. | 1685 | /// under `allow_warped_motion`) -- lane-warp round 1. |
| 1681 | -pub const MOTION_MODE: [[u16; 4]; 14] = [ | 1686 | +pub const MOTION_MODE: [[u16; 4]; 17] = [ |
| 1682 | [7651, 24760, 32768, 0], | 1687 | [7651, 24760, 32768, 0], |
| 1683 | [19419, 26810, 32768, 0], | 1688 | [19419, 26810, 32768, 0], |
| 1684 | [26260, 29116, 32768, 0], | 1689 | [26260, 29116, 32768, 0], |
| @@ -1698,6 +1703,13 @@ pub const MOTION_MODE: [[u16; 4]; 14] = [ | |||
| 1698 | // `default_motion_mode_cdf` indices 4 and 5). | 1703 | // `default_motion_mode_cdf` indices 4 and 5). |
| 1699 | [4738, 24765, 32768, 0], | 1704 | [4738, 24765, 32768, 0], |
| 1700 | [5391, 25528, 32768, 0], | 1705 | [5391, 25528, 32768, 0], |
| 1706 | + // lane-sb128c r5: BLOCK_64X128 / 128X64 / 128X128 rows (libaom | ||
| 1707 | + // `default_motion_mode_cdf` indices 13, 14, 15). Without them a 128x128 | ||
| 1708 | + // inter block fell through `w == h => trailing_zeros - 3` to row 4 (the | ||
| 1709 | + // BLOCK_16X32 row) and narrowed the msac by the wrong interval. | ||
| 1710 | + [28898, 30397, 32768, 0], | ||
| 1711 | + [30878, 31335, 32768, 0], | ||
| 1712 | + [32507, 32558, 32768, 0], | ||
| 1701 | ]; | 1713 | ]; |
| 1702 | 1714 | ||
| 1703 | /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by | 1715 | /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by |
crates/ec-av1/src/cdf_state.rsmodified+2 -2
| @@ -522,13 +522,13 @@ pub(crate) struct Cdfs { | |||
| 522 | /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` | 522 | /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` |
| 523 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- | 523 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- |
| 524 | /// this decoder only ever codes those four square sizes). | 524 | /// this decoder only ever codes those four square sizes). |
| 525 | - pub obmc: [[u16; 3]; 14], | 525 | + pub obmc: [[u16; 3]; 17], |
| 526 | /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol | 526 | /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol |
| 527 | /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read | 527 | /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read |
| 528 | /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to | 528 | /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to |
| 529 | /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. | 529 | /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. |
| 530 | /// lane-warp round 1. | 530 | /// lane-warp round 1. |
| 531 | - pub motion_mode: [[u16; 4]; 14], | 531 | + pub motion_mode: [[u16; 4]; 17], |
| 532 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see | 532 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see |
| 533 | /// `cdf::INTERINTRA`'s own doc. | 533 | /// `cdf::INTERINTRA`'s own doc. |
| 534 | pub interintra: [[u16; 3]; 4], | 534 | pub interintra: [[u16; 3]; 4], |
crates/ec-av1/src/decode.rsmodified+11 -2
| @@ -17968,6 +17968,11 @@ fn decode_inter_block( | |||
| 17968 | // interval narrowing, not a wrong value (class | 17968 | // interval narrowing, not a wrong value (class |
| 17969 | // wrong-alphabet-same-value). | 17969 | // wrong-alphabet-same-value). |
| 17970 | let bsize_idx = match (write_w, write_h) { | 17970 | let bsize_idx = match (write_w, write_h) { |
| 17971 | + // lane-sb128c r5: the 128 root's own rows come FIRST -- | ||
| 17972 | + // the square arm below maps 128 to row 4 (BLOCK_16X32). | ||
| 17973 | + (64, 128) => 14, | ||
| 17974 | + (128, 64) => 15, | ||
| 17975 | + (128, 128) => 16, | ||
| 17971 | (w, h) if w == h => (w.trailing_zeros() - 3) as usize, | 17976 | (w, h) if w == h => (w.trailing_zeros() - 3) as usize, |
| 17972 | (16, 32) => 4, | 17977 | (16, 32) => 4, |
| 17973 | (32, 16) => 5, | 17978 | (32, 16) => 5, |
| @@ -18985,7 +18990,11 @@ fn decode_inter_block( | |||
| 18985 | dec, | 18990 | dec, |
| 18986 | cdfs, | 18991 | cdfs, |
| 18987 | txbset_for(tx_px, reduced), | 18992 | txbset_for(tx_px, reduced), |
| 18988 | - &default_scan(tx_px), | 18993 | + // lane-sb128c r5: a TX_64X64 unit codes only its |
| 18994 | + // top-left 32x32 of frequencies (spec 5.11.40), so | ||
| 18995 | + // the scan and `tx_side` are the CODED corner while | ||
| 18996 | + // `side` stays the transform's true 64. | ||
| 18997 | + &default_scan(tx_px.min(32)), | ||
| 18989 | 0, | 18998 | 0, |
| 18990 | neighbours.around_mi(tu_mi, tx_px)[0], | 18999 | neighbours.around_mi(tu_mi, tx_px)[0], |
| 18991 | mode, | 19000 | mode, |
| @@ -18996,7 +19005,7 @@ fn decode_inter_block( | |||
| 18996 | tu_px, | 19005 | tu_px, |
| 18997 | tu_py, | 19006 | tu_py, |
| 18998 | tx_px, | 19007 | tx_px, |
| 18999 | - tx_px, | 19008 | + tx_px.min(32), |
| 19000 | base_q_idx, | 19009 | base_q_idx, |
| 19001 | None, | 19010 | None, |
| 19002 | filter_intra, | 19011 | filter_intra, |
crates/ec-av1/src/mvstack.rsmodified+12 -2
| @@ -875,7 +875,12 @@ pub fn find_mv_stack_with_sign_bias( | |||
| 875 | &mut newmv_count, | 875 | &mut newmv_count, |
| 876 | &mut processed_cols, | 876 | &mut processed_cols, |
| 877 | ); | 877 | ); |
| 878 | - let found_top_right = scan_top_right( | 878 | + // libaom `setup_ref_mv_list` gates this probe on `has_top_right` |
| 879 | + // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 | ||
| 880 | + // block sits in decoded memory but is NOT available (bs > 16), so an | ||
| 881 | + // ungated grid probe invents a candidate and desyncs the drl symbols. | ||
| 882 | + let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4) | ||
| 883 | + && scan_top_right( | ||
| 879 | grid, | 884 | grid, |
| 880 | mi_row, | 885 | mi_row, |
| 881 | mi_col, | 886 | mi_col, |
| @@ -1668,7 +1673,12 @@ pub fn find_mv_stack_compound( | |||
| 1668 | &mut newmv_count, | 1673 | &mut newmv_count, |
| 1669 | &mut processed_cols, | 1674 | &mut processed_cols, |
| 1670 | ); | 1675 | ); |
| 1671 | - let found_top_right = scan_top_right_compound( | 1676 | + // libaom `setup_ref_mv_list` gates this probe on `has_top_right` |
| 1677 | + // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 | ||
| 1678 | + // block sits in decoded memory but is NOT available (bs > 16), so an | ||
| 1679 | + // ungated grid probe invents a candidate and desyncs the drl symbols. | ||
| 1680 | + let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4) | ||
| 1681 | + && scan_top_right_compound( | ||
| 1672 | grid, | 1682 | grid, |
| 1673 | mi_row, | 1683 | mi_row, |
| 1674 | mi_col, | 1684 | mi_col, |
lanes/sb128c-r5.handoff.mdadded+102 -0
| @@ -0,0 +1,102 @@ | |||
| 1 | +# lane-sb128c r5 -> r6 handoff | ||
| 2 | + | ||
| 3 | +Worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. | ||
| 4 | +Work stream: `$HOME/.cache/sb128c-work/g-61-8-0.obu` (arm 1) and `a3.obu` (arm 3, | ||
| 5 | +copied out of the gate's pinned `/tmp` dir -- keep it, /tmp is reaped). | ||
| 6 | + | ||
| 7 | +## (1) The r4 residue: THREE root causes, all fixed, arms 1+2 GREEN | ||
| 8 | + | ||
| 9 | +r4's "frame 5 pre-filter wrong, entropy in sync" premise was WRONG: the mode-value | ||
| 10 | +ladder (`EC_TRACE_MODE`, values only -- our `EC_MODE_VAL` prints its `rng` at | ||
| 11 | +libaom's `EC_MODE_MV` point, so RANGE is not comparable line-for-line) diverges at | ||
| 12 | +mode-value line 43, `mi(32,0)`, a 128x128 NEWMV block: | ||
| 13 | + | ||
| 14 | +``` | ||
| 15 | +oracle EC_MODE_VAL mi_row=32 mi_col=0 mode=16 ref0=1 mv0=(63,0) stack=1 | ||
| 16 | +ours EC_MODE_VAL mi_row=32 mi_col=0 mode=16 ref0=1 mv0=(0,0) stack=2 | ||
| 17 | +``` | ||
| 18 | + | ||
| 19 | +a) **mv stack: the top-right probe was never gated on `has_top_right`.** | ||
| 20 | +`crates/ec-av1/src/mvstack.rs:882` (`find_mv_stack`) and `:1680` | ||
| 21 | +(`find_mv_stack_compound`) called `scan_top_right{,_compound}` unconditionally. | ||
| 22 | +libaom `setup_ref_mv_list` (mvref_common.c:497 + :546) computes | ||
| 23 | +`has_tr = has_top_right(cm, xd, mi_row, mi_col, AOMMAX(width,height))` and only | ||
| 24 | +then `scan_blk_mbmi(-1, xd->width)`. `has_top_right` returns 0 for `bs > 16`, so a | ||
| 25 | +128x128 block has NO top-right candidate -- but the cell diagonally above-right of | ||
| 26 | +`mi(32,0)` (= `mi(31,32)`, in the previous SB row) IS populated, so our grid probe | ||
| 27 | +invented `(441,441) w=644` and the extra stack entry desynced the drl symbols. | ||
| 28 | +The module's own `mvstack::has_top_right` port already existed and was correct; it | ||
| 29 | +just was not wired into the mv-stack scan (only into the warp-sample gather). | ||
| 30 | + | ||
| 31 | +b) **`motion_mode`/`obmc` CDF row 4 for a 128x128 block.** | ||
| 32 | +`decode.rs:17977` mapped square sizes with `w == h => (w.trailing_zeros() - 3)`, | ||
| 33 | +which sends 128 to row 4 -- our packed `BLOCK_16X32` row. Wrong alphabet narrowing, | ||
| 34 | +no wrong value (class `wrong-alphabet-same-value`). Added libaom | ||
| 35 | +`default_motion_mode_cdf` / `default_obmc_cdf` rows 13/14/15 (BLOCK_64X128, | ||
| 36 | +128X64, 128X128) as our packed indices 14/15/16 in `cdf.rs` (arrays 14 -> 17, | ||
| 37 | +`cdf_state.rs` types too) and explicit `(64,128)/(128,64)/(128,128)` match arms | ||
| 38 | +BEFORE the square arm. | ||
| 39 | + | ||
| 40 | +c) **A TX_64X64 luma unit of an INTRA-in-inter 128 block used the full 64x64 scan.** | ||
| 41 | +`decode.rs:18995` passed `default_scan(tx_px)` and `tx_side = tx_px`; a TX_64X64 | ||
| 42 | +codes only its top-left 32x32 (spec 5.11.40). Panicked | ||
| 43 | +`transform.rs:828 assertion left==right: one coefficient per position, 1024 vs 4096` | ||
| 44 | +on gate arm 2. Now `.min(32)` on both, matching every other 64-capable site | ||
| 45 | +(`coeff_tx_side`, `default_scan(tx_px.min(32))` at :17429/:18494). | ||
| 46 | + | ||
| 47 | +EVIDENCE: `$HOME/.cache/sb128c-work/pf-{o,m}.f0..f8` | `EC_AV1_PREFILT_DUMP` on | ||
| 48 | +aomdec oracle + `decode_probe`, g-61-8-0.obu | all 9 decode-order frames 0 bytes | ||
| 49 | +differ (was 19550/14164/26667/26716 on f5..f8), mode-value ladder MODE_IDENTICAL. | ||
| 50 | + | ||
| 51 | +Gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact`: | ||
| 52 | +- arm 1 (yuv420p, tx_search=0, seed 61): **9/9 frames exact**, `inter_sb128_none_hits=14 chroma_units=16 intra_128_in_inter=0` | ||
| 53 | +- arm 2 (yuv420p10le, tx_search=0, seed 61): **9/9 frames exact**, `hits=29 chroma_units=28 intra_128_in_inter=1` | ||
| 54 | +- arm 3 (yuv420p, tx_search=1, seed 62): **RED**, 7 bytes, see below. | ||
| 55 | +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` and | ||
| 56 | +`a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact` stay green. | ||
| 57 | + | ||
| 58 | +## (2) EXACT NEXT STEP: arm 3, a phantom CHROMA deblock edge (4 px), stage-bisected | ||
| 59 | + | ||
| 60 | +Stream `$HOME/.cache/sb128c-work/a3.obu` (909 B, 256x256 8-bit, 9 decode-order | ||
| 61 | +frames). Mode ladder is IDENTICAL to the oracle -- no entropy defect. | ||
| 62 | + | ||
| 63 | +Stage bisection (oracle rungs `EC_AV1_PREFILT_DUMP` / `EC_AV1_POSTDEBLOCK_DUMP` / | ||
| 64 | +`EC_AV1_FINAL_DUMP`; NOTE our POSTDEBLOCK dump indexes 0,2,4,... so oracle `fN` | ||
| 65 | +pairs with ours `f2N`, and on THIS stream it really is pre-CDEF): | ||
| 66 | +``` | ||
| 67 | +pre-filter f0..f8 : 0 0 0 0 7 6 6 6 0 (f4+ is propagation) | ||
| 68 | +post-deblock f3 : 4 px <-- the defect | ||
| 69 | +final f3 : 7 px, f4..f7 6 px each | ||
| 70 | +``` | ||
| 71 | +The 4 post-deblock pixels are V-plane only: | ||
| 72 | +`V(46,56) V(46,57) V(47,54) V(47,55)`, ours 170 vs oracle 167 -- two pairs | ||
| 73 | +straddling a VERTICAL chroma edge at chroma x=56 (luma x=112), inside the | ||
| 74 | +`mi(0,0)` `side=128 is_inter=1 skip=0` block of decode-order frame 3. | ||
| 75 | + | ||
| 76 | +Root cause (identified, NOT yet fixed): `decode.rs:19303`, the per-vartx-leaf | ||
| 77 | +`fill_lf_grid_rect` loop in `decode_inter_block`, passes the LUMA leaf extent, and | ||
| 78 | +`fill_lf_grid_rect` derives `uv_tx_w/h` from its own `w_mi/h_mi` (`decode.rs:4211`). | ||
| 79 | +So a 16x16 luma leaf publishes a chroma TU extent of 8 and creates chroma edges | ||
| 80 | +every 8 px -- e.g. at chroma 56. libaom takes a chroma plane's transform size from | ||
| 81 | +`av1_get_max_uv_txsize(mbmi->bsize, ...)` (the BLOCK's, = TX_32X32 for a 128 root) | ||
| 82 | +in `set_one_param_for_line_chroma`, never from the luma var-tx leaf. Fix shape: | ||
| 83 | +leave the chroma half of the grid at the BLOCK's uv extent when writing per-leaf | ||
| 84 | +(a leaf-only luma write, or an explicit uv re-publish after the loop, mirroring | ||
| 85 | +r4's `suppress_internal_lf_edges`). Beware r4's trap: the block-level uv `.min(32)` | ||
| 86 | +cap must stay (an INTRA 128 block's internal chroma edges ARE filtered). | ||
| 87 | +Re-run the key-frame 128 sibling gate after touching this (class | ||
| 88 | +`fix-trades-sibling-gate`). | ||
| 89 | + | ||
| 90 | +## (3) NOT STARTED | ||
| 91 | + | ||
| 92 | +deferred: 128-level HORZ/VERT + AB partitions (key and inter) -- r5's budget went | ||
| 93 | +to the three r4-residue root causes; unblocked by nothing. Refusal | ||
| 94 | +`refusal_inventory.rs:45` "a 128x128 superblock HORZ/VERT or AB partition (only | ||
| 95 | +SPLIT and NONE are decoded at the 128 root)" is untouched. `cdf::MOTION_MODE`/ | ||
| 96 | +`cdf::OBMC` now already carry the BLOCK_64X128 / BLOCK_128X64 rows that work needs. | ||
| 97 | +deferred: full suite -- not run this round (r4's was also incomplete); r6 must run | ||
| 98 | +`systemd-run --user --unit=sb128c-suite-$(date +%s) -p MemoryMax=10G --same-dir bash -lc '...'` | ||
| 99 | +per COMMON, log to `$HOME/.cache/sb128c-suite-r6.log`. | ||
| 100 | +deferred: ReelC re-probe -- not re-run; r4 measured both extracts still stopping at | ||
| 101 | +the 128 HORZ/VERT/AB refusal with `EC_AV1_FINAL_DUMP` count 1, byte-identical to | ||
| 102 | +ffmpeg. Nothing in r5 touches that stop string. | ||