SB-level HORZ/VERT split-transform strips -- transposed rect nz_map offset read AND an eob_pt chroma CDF transcribed from libaom's 1D-class row
Browse files at this commitfdfb8e3ba83044023641bcdef0701e657af990e2Parent: 429edc6- fix
- SB-level HORZ/VERT split-transform strips -- transposed rect nz_map offset read AND an eob_pt chroma CDF transcribed from libaom's 1D-class row
6 changed files +270 -59
- crates/ec-av1/src/cdf.rs +23 -6
- crates/ec-av1/src/cdf_state.rs +7 -3
- crates/ec-av1/src/decode.rs +129 -41
- crates/ec-av1/src/refusal_inventory.rs +0 -1
- crates/ec-av1/src/stream.rs +14 -8
- lanes/rectsplit-r4.report.md +97 -0
crates/ec-av1/src/cdf.rsmodified+23 -6
| @@ -266,18 +266,35 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ | |||
| 266 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, | 266 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, |
| 267 | ]; | 267 | ]; |
| 268 | 268 | ||
| 269 | -/// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`, | 269 | +/// `av1_default_eob_multi512_cdfs[*][1][0]` (`token_cdfs.h:874-906`, |
| 270 | /// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded | 270 | /// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded |
| 271 | /// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of | 271 | /// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of |
| 272 | /// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma | 272 | /// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma |
| 273 | /// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan | 273 | /// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan |
| 274 | /// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough | 274 | /// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough |
| 275 | -/// that no truncation applies). Unlike every other `EOB_PT_*` table here, | 275 | +/// that no truncation applies). |
| 276 | -/// libaom's default is the exact same flat distribution at all four | 276 | +/// |
| 277 | -/// q-contexts and both `eob_multi_size` selectors (`token_cdfs.h` rows), so | 277 | +/// lane-rectsplit r4: this used to be ONE flat `3277, 6554, ...` constant at |
| 278 | -/// one constant covers every q-context -- no `_Q0`/`_Q1`/`_Q3` siblings. | 278 | +/// every q-context, transcribed from the wrong row -- the last index of |
| 279 | +/// `[q][plane][2]` is `eob_multi_ctx` (0 = `TX_CLASS_2D`, 1 = `V_DCT`/ | ||
| 280 | +/// `H_DCT`), and the flat distribution is libaom's 1D-class row, identical | ||
| 281 | +/// for both planes at every q. The first real 32x16 chroma transform then | ||
| 282 | +/// read `eob_pt` 7 where aomdec read 2 (seed 43 of the superblock HORZ/VERT | ||
| 283 | +/// gate). | ||
| 279 | pub const EOB_PT_512_CHROMA: [u16; 11] = [ | 284 | pub const EOB_PT_512_CHROMA: [u16; 11] = [ |
| 280 | - 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, | 285 | + 12015, 14769, 19588, 22052, 24222, 25812, 27300, 29219, 32114, 32768, 0, |
| 286 | +]; | ||
| 287 | +/// [`EOB_PT_512_CHROMA`], q-context 0 (`base_q_idx` 0..=20). | ||
| 288 | +pub const EOB_PT_512_CHROMA_Q0: [u16; 11] = [ | ||
| 289 | + 5095, 6446, 9996, 13354, 16017, 17986, 20919, 26129, 29140, 32768, 0, | ||
| 290 | +]; | ||
| 291 | +/// [`EOB_PT_512_CHROMA`], q-context 1 (`base_q_idx` 21..=60). | ||
| 292 | +pub const EOB_PT_512_CHROMA_Q1: [u16; 11] = [ | ||
| 293 | + 7265, 9979, 15819, 19250, 21780, 23846, 26478, 28396, 31811, 32768, 0, | ||
| 294 | +]; | ||
| 295 | +/// [`EOB_PT_512_CHROMA`], q-context 3 (`base_q_idx` 121..=255). | ||
| 296 | +pub const EOB_PT_512_CHROMA_Q3: [u16; 11] = [ | ||
| 297 | + 21093, 23043, 25742, 27658, 29097, 29716, 30073, 30820, 31956, 32768, 0, | ||
| 281 | ]; | 298 | ]; |
| 282 | 299 | ||
| 283 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, | 300 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, |
crates/ec-av1/src/cdf_state.rsmodified+7 -3
| @@ -1010,9 +1010,13 @@ impl Cdfs { | |||
| 1010 | cdf::EOB_PT_128_CHROMA, | 1010 | cdf::EOB_PT_128_CHROMA, |
| 1011 | cdf::EOB_PT_128_CHROMA_Q3, | 1011 | cdf::EOB_PT_128_CHROMA_Q3, |
| 1012 | ), | 1012 | ), |
| 1013 | - // Flat default at every q-context (see the constant's own doc | 1013 | + eob_pt_512_chroma: pick( |
| 1014 | - // comment) -- no `pick()` needed. | 1014 | + q_ctx, |
| 1015 | - eob_pt_512_chroma: cdf::EOB_PT_512_CHROMA, | 1015 | + cdf::EOB_PT_512_CHROMA_Q0, |
| 1016 | + cdf::EOB_PT_512_CHROMA_Q1, | ||
| 1017 | + cdf::EOB_PT_512_CHROMA, | ||
| 1018 | + cdf::EOB_PT_512_CHROMA_Q3, | ||
| 1019 | + ), | ||
| 1016 | eob_extra_luma_32: pick( | 1020 | eob_extra_luma_32: pick( |
| 1017 | q_ctx, | 1021 | q_ctx, |
| 1018 | cdf::EOB_EXTRA_LUMA_32_Q0, | 1022 | cdf::EOB_EXTRA_LUMA_32_Q0, |
crates/ec-av1/src/decode.rsmodified+129 -41
| @@ -1159,33 +1159,30 @@ fn base_ctx( | |||
| 1159 | // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the | 1159 | // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the |
| 1160 | // square table vs the real ctx 13 the rect table gives). | 1160 | // square table vs the real ctx 13 the rect table gives). |
| 1161 | TxClass::TwoD => { | 1161 | TxClass::TwoD => { |
| 1162 | - // OPEN (lane-rectsplit r3, measured): the two rect | 1162 | + // lane-rectsplit r4: apply libaom's GENERATING RULE |
| 1163 | - // transcriptions in [`cdf`] are packed `[col][row]` -- libaom's | 1163 | + // (`txb_common.h:199-209`) directly instead of indexing the |
| 1164 | - // `av1_nz_map_ctx_offset_32x64` is a FLAT 1024-entry array whose | 1164 | + // transcribed 5x5 tables. `av1_nz_map_ctx_offset[tx_size]` is a |
| 1165 | - // `coeff_idx` is COLUMN-major with stride 32 (`TX_CLASS_HORIZ` | 1165 | + // FLAT array read at `coeff_idx`, and `coeff_idx` is COLUMN-major |
| 1166 | - // reads its column back as `coeff_idx >> bhl`), and entries | 1166 | + // (libaom decomposes it as `col = coeff_idx >> bhl`, `bhl` the |
| 1167 | - // 0..5 / 32..35 match the generating rule (txb_common.h:199-209) | 1167 | + // ADJUSTED height's log2, 5 for both `TX_64X32` and `TX_32X64`), |
| 1168 | - // only under `flat[col * 32 + row]`; | 1168 | + // so 32 consecutive entries are one COLUMN: the [`cdf`] |
| 1169 | - // `nz_map_ctx_offset_tables_match_the_rect_rule` pins that. | 1169 | + // transcriptions are `[col][row]` and this read had them as |
| 1170 | - // Yet reading `[col][row]` here BREAKS | 1170 | + // `[row][col]` -- the transpose, i.e. the other shape's rule with |
| 1171 | - // `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | 1171 | + // 11 and 16 swapped. Same values as [`base_ctx_rect`] now, stated |
| 1172 | - // (seed 43) while `[row][col]` breaks the split-transform SB gate | 1172 | + // once; `base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain` |
| 1173 | - // (seed 50); swapping the shape test as well fails BOTH ways. So | 1173 | + // pins the rule against the tables over their whole 5x5 domain. |
| 1174 | - // this read is not the defect -- our (row, col) here come from a | 1174 | + if let Some((w, h)) = rect_shape { |
| 1175 | - // square 32x32-corner scan whose orientation relative to libaom's | ||
| 1176 | - // column-major `coeff_idx` is what is really unproven, and each | ||
| 1177 | - // "fix" only moves which rare corner position desyncs. Left at | ||
| 1178 | - // the r1 reading, the one every merged gate is green under. | ||
| 1179 | - // `EC_NZOFF_DUMP=1` prints every rect-shaped read. | ||
| 1180 | - let table = match rect_shape { | ||
| 1181 | - Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64, | ||
| 1182 | - Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32, | ||
| 1183 | - _ => &cdf::NZ_MAP_CTX_OFFSET_32, | ||
| 1184 | - }; | ||
| 1185 | if std::env::var_os("EC_NZOFF_DUMP").is_some() { | 1175 | if std::env::var_os("EC_NZOFF_DUMP").is_some() { |
| 1186 | - eprintln!("NZOFF side={side} shape={rect_shape:?} row={row} col={col}"); | 1176 | + eprintln!("NZOFF side={side} shape={w}x{h} row={row} col={col}"); |
| 1177 | + } | ||
| 1178 | + if w < h && row < 2 { | ||
| 1179 | + return ctx + 11; | ||
| 1187 | } | 1180 | } |
| 1188 | - ctx + table[row.min(4)][col.min(4)] as usize | 1181 | + if w > h && col < 2 { |
| 1182 | + return ctx + 16; | ||
| 1183 | + } | ||
| 1184 | + } | ||
| 1185 | + ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | ||
| 1189 | } | 1186 | } |
| 1190 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), | 1187 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), |
| 1191 | TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), | 1188 | TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), |
| @@ -1589,6 +1586,15 @@ fn read_coeffs( | |||
| 1589 | } else { | 1586 | } else { |
| 1590 | let ctx = base_ctx(&levels, side, row, col, class, rect_shape); | 1587 | let ctx = base_ctx(&levels, side, row, col, class, rect_shape); |
| 1591 | let v = dec.symbol(&mut coding.base[ctx]) as i32; | 1588 | let v = dec.symbol(&mut coding.base[ctx]) as i32; |
| 1589 | + if ec_trace_coeff { | ||
| 1590 | + let (rng, _) = dec.debug_state(); | ||
| 1591 | + // `pos` in libaom's column-major `coeff_idx` convention, so | ||
| 1592 | + // the ladder lines up with instrumented `aomdec`. | ||
| 1593 | + let apos = col * side + row; | ||
| 1594 | + eprintln!( | ||
| 1595 | + "EC_COEFF_STEP tag=base c={scan_idx} pos={apos} ctx={ctx} level={v} rng={rng}" | ||
| 1596 | + ); | ||
| 1597 | + } | ||
| 1592 | if trace { | 1598 | if trace { |
| 1593 | eprintln!( | 1599 | eprintln!( |
| 1594 | "TRACE base scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}" | 1600 | "TRACE base scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}" |
| @@ -1681,7 +1687,15 @@ fn read_coeffs_rect( | |||
| 1681 | default_tx_type: TxType, | 1687 | default_tx_type: TxType, |
| 1682 | ) -> Result<(Vec<i32>, TxType)> { | 1688 | ) -> Result<(Vec<i32>, TxType)> { |
| 1683 | let mut grid = vec![0i32; w * h]; | 1689 | let mut grid = vec![0i32; w * h]; |
| 1690 | + let trace = std::env::var_os("EC_TRACE_COEFF").is_some(); | ||
| 1684 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | 1691 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 1692 | + if trace { | ||
| 1693 | + let (rng, _) = dec.debug_state(); | ||
| 1694 | + eprintln!( | ||
| 1695 | + "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}", | ||
| 1696 | + all_zero as i32 | ||
| 1697 | + ); | ||
| 1698 | + } | ||
| 1685 | if all_zero { | 1699 | if all_zero { |
| 1686 | return Ok((grid, TxType::DctDct)); | 1700 | return Ok((grid, TxType::DctDct)); |
| 1687 | } | 1701 | } |
| @@ -1697,16 +1711,36 @@ fn read_coeffs_rect( | |||
| 1697 | )); | 1711 | )); |
| 1698 | } | 1712 | } |
| 1699 | let eob = read_eob(dec, coding, TxClass::TwoD); | 1713 | let eob = read_eob(dec, coding, TxClass::TwoD); |
| 1714 | + if trace { | ||
| 1715 | + let (rng, _) = dec.debug_state(); | ||
| 1716 | + eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); | ||
| 1717 | + } | ||
| 1700 | let mut levels = vec![0i32; w * h]; | 1718 | let mut levels = vec![0i32; w * h]; |
| 1701 | for scan_idx in (0..eob).rev() { | 1719 | for scan_idx in (0..eob).rev() { |
| 1702 | let pos = scan[scan_idx] as usize; | 1720 | let pos = scan[scan_idx] as usize; |
| 1703 | let (row, col) = (pos / w, pos % w); | 1721 | let (row, col) = (pos / w, pos % w); |
| 1722 | + // libaom's column-major `coeff_idx`, for ladder comparison. | ||
| 1723 | + let apos = col * h + row; | ||
| 1704 | let level = if scan_idx == eob - 1 { | 1724 | let level = if scan_idx == eob - 1 { |
| 1705 | let ctx = eob_coeff_ctx(scan_idx, w * h); | 1725 | let ctx = eob_coeff_ctx(scan_idx, w * h); |
| 1706 | - dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1 | 1726 | + let v = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; |
| 1727 | + if trace { | ||
| 1728 | + let (rng, _) = dec.debug_state(); | ||
| 1729 | + eprintln!( | ||
| 1730 | + "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={apos} ctx={ctx} level={v} rng={rng}" | ||
| 1731 | + ); | ||
| 1732 | + } | ||
| 1733 | + v | ||
| 1707 | } else { | 1734 | } else { |
| 1708 | let ctx = base_ctx_rect(&levels, w, h, row, col); | 1735 | let ctx = base_ctx_rect(&levels, w, h, row, col); |
| 1709 | - dec.symbol(&mut coding.base[ctx]) as i32 | 1736 | + let v = dec.symbol(&mut coding.base[ctx]) as i32; |
| 1737 | + if trace { | ||
| 1738 | + let (rng, _) = dec.debug_state(); | ||
| 1739 | + eprintln!( | ||
| 1740 | + "EC_COEFF_STEP tag=base c={scan_idx} pos={apos} ctx={ctx} level={v} rng={rng}" | ||
| 1741 | + ); | ||
| 1742 | + } | ||
| 1743 | + v | ||
| 1710 | }; | 1744 | }; |
| 1711 | let level = if level > NUM_BASE_LEVELS { | 1745 | let level = if level > NUM_BASE_LEVELS { |
| 1712 | let ctx = br_ctx_rect(&levels, w, h, row, col); | 1746 | let ctx = br_ctx_rect(&levels, w, h, row, col); |
| @@ -3398,6 +3432,13 @@ fn decode_rect_split( | |||
| 3398 | dc_sign_ctx(around[plane_idx].2), | 3432 | dc_sign_ctx(around[plane_idx].2), |
| 3399 | default_tx, | 3433 | default_tx, |
| 3400 | )?; | 3434 | )?; |
| 3435 | + // The same delta_q proof the unsplit rect64 path records | ||
| 3436 | + // (lane-rectsplit r4: lifting the split-transform refusal moved | ||
| 3437 | + // superblock strips onto this path, so only counting there would | ||
| 3438 | + // leave the delta_q gate's counter silent for them). | ||
| 3439 | + if bw.max(bh) == 64 && CURRENT_Q_IDX.with(|c| c.get()) != i32::from(base_q_idx) { | ||
| 3440 | + RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3441 | + } | ||
| 3401 | let residual = dequant_and_inverse_typed_wh( | 3442 | let residual = dequant_and_inverse_typed_wh( |
| 3402 | &levels, | 3443 | &levels, |
| 3403 | chroma_w, | 3444 | chroma_w, |
| @@ -4061,20 +4102,34 @@ fn decode_block_rect64( | |||
| 4061 | }; | 4102 | }; |
| 4062 | if depth != 0 { | 4103 | if depth != 0 { |
| 4063 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 4104 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 4064 | - // lane-rectsplit r1/r3: [`decode_rect_split`] handles this shape too | 4105 | + // lane-rectsplit r1/r4: the superblock-level strip splits its |
| 4065 | - // and the per-unit port is wired here, but the gate | 4106 | + // transform through the very same per-unit path as its 32x32-level |
| 4066 | - // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`, | 4107 | + // sibling (`sub_tx_size_map[TX_64X32] == TX_32X32`, square from the |
| 4067 | - // `#[ignore]`d with its measurement) is still RED at seed 50 (luma | 4108 | + // first step on, so `bw.min(bh) >> (depth - 1)` names the unit). |
| 4068 | - // (171,56), ours 147 vs ffmpeg 148). r2 believed the cause was a | 4109 | + let tx = bw.min(bh) >> (depth - 1); |
| 4069 | - // transposed `av1_nz_map_ctx_offset` read; r3 measured that | 4110 | + if std::env::var_os("EC_SBPART_DUMP64").is_some() { |
| 4070 | - // transposing it turns THIS gate green and the merged SB-level | 4111 | + eprintln!( |
| 4071 | - // HORZ/VERT partition gate RED (seed 43), so the cause is still | 4112 | + "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ |
| 4072 | - // open. A refusal this lane cannot lift is not one it may ship wrong | 4113 | + depth={depth} tx={tx} mode={mode} uv={uv_predict_mode} skip={skip} \ |
| 4073 | - // pixels past. | 4114 | + angle_y={angle_delta_y}" |
| 4074 | - return Err(unsupported( | 4115 | + ); |
| 4075 | - "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ | 4116 | + } |
| 4076 | - prediction is not ported)", | 4117 | + let modes = RectStripModes { |
| 4077 | - )); | 4118 | + skip, |
| 4119 | + mode, | ||
| 4120 | + angle_delta_y, | ||
| 4121 | + uv_predict_mode, | ||
| 4122 | + angle_delta_uv, | ||
| 4123 | + alpha, | ||
| 4124 | + filter_intra, | ||
| 4125 | + smooth_neighbor, | ||
| 4126 | + smooth_neighbor_uv, | ||
| 4127 | + }; | ||
| 4128 | + decode_rect_split( | ||
| 4129 | + dec, cdfs, neighbours, at, bw, bh, tx, &modes, y, u, v, base_q_idx, reduced_tx_set, | ||
| 4130 | + )?; | ||
| 4131 | + RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); | ||
| 4132 | + return Ok(()); | ||
| 4078 | } | 4133 | } |
| 4079 | let (tx_w, tx_h) = (bw, bh); | 4134 | let (tx_w, tx_h) = (bw, bh); |
| 4080 | let (cpx, cpy) = (px / 2, py / 2); | 4135 | let (cpx, cpy) = (px / 2, py / 2); |
| @@ -13801,6 +13856,39 @@ mod tests { | |||
| 13801 | } | 13856 | } |
| 13802 | } | 13857 | } |
| 13803 | 13858 | ||
| 13859 | + /// lane-rectsplit r4 (class `enumerate-table-domain`): [`base_ctx`]'s | ||
| 13860 | + /// `TX_CLASS_2D` arm must, over the WHOLE 5x5 domain of both rect shapes | ||
| 13861 | + /// and the square one, return exactly what libaom's | ||
| 13862 | + /// `av1_nz_map_ctx_offset[tx_size][coeff_idx]` holds -- the flat tables | ||
| 13863 | + /// transcribed in [`cdf`], read at libaom's own COLUMN-major | ||
| 13864 | + /// `coeff_idx = col * 32 + row`, i.e. `table[col][row]`. r1..r3 read them | ||
| 13865 | + /// `[row][col]`, which is the transpose (the OTHER shape's rule, with 11 | ||
| 13866 | + /// and 16 swapped): it desynced the first superblock strip whose luma | ||
| 13867 | + /// corner held a coefficient off the first row/column. | ||
| 13868 | + #[test] | ||
| 13869 | + fn base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain() { | ||
| 13870 | + let grid = [0i32; 32 * 32]; | ||
| 13871 | + for (shape, table) in [ | ||
| 13872 | + (Some((64usize, 32usize)), &cdf::NZ_MAP_CTX_OFFSET_64X32), | ||
| 13873 | + (Some((32, 64)), &cdf::NZ_MAP_CTX_OFFSET_32X64), | ||
| 13874 | + (None, &cdf::NZ_MAP_CTX_OFFSET_32), | ||
| 13875 | + ] { | ||
| 13876 | + for row in 0..5usize { | ||
| 13877 | + for col in 0..5usize { | ||
| 13878 | + // An all-zero neighbourhood makes the magnitude term 0, | ||
| 13879 | + // so `base_ctx` returns the offset itself. | ||
| 13880 | + let got = base_ctx(&grid, 32, row, col, TxClass::TwoD, shape); | ||
| 13881 | + let want = if row == 0 && col == 0 { | ||
| 13882 | + 0 | ||
| 13883 | + } else { | ||
| 13884 | + table[col][row] as usize | ||
| 13885 | + }; | ||
| 13886 | + assert_eq!(got, want, "{shape:?} at (row {row}, col {col})"); | ||
| 13887 | + } | ||
| 13888 | + } | ||
| 13889 | + } | ||
| 13890 | + } | ||
| 13891 | + | ||
| 13804 | // `crate::tile`'s `flat_key_frame_tile`/`dc_key_frame_tile_levels`/ | 13892 | // `crate::tile`'s `flat_key_frame_tile`/`dc_key_frame_tile_levels`/ |
| 13805 | // `split_dc_key_frame_tile` are not exercised here: they are synthetic | 13893 | // `split_dc_key_frame_tile` are not exercised here: they are synthetic |
| 13806 | // single-purpose writers with their own skip-context rule (keyed to | 13894 | // single-purpose writers with their own skip-context rule (keyed to |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
| @@ -46,7 +46,6 @@ const REFUSALS: &[&str] = &[ | |||
| 46 | "a Golomb tail longer than this decoder reads", | 46 | "a Golomb tail longer than this decoder reads", |
| 47 | "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)", | 47 | "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)", |
| 48 | "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)", | 48 | "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)", |
| 49 | - "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", | ||
| 50 | "a tx_type symbol outside its CDF's own set: {t}", | 49 | "a tx_type symbol outside its CDF's own set: {t}", |
| 51 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 50 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 52 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | 51 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
crates/ec-av1/src/stream.rsmodified+14 -8
| @@ -9767,14 +9767,20 @@ mod tests { | |||
| 9767 | /// which is the per-unit availability rule this port exists for, and no | 9767 | /// which is the per-unit availability rule this port exists for, and no |
| 9768 | /// gate fired one before this round. | 9768 | /// gate fired one before this round. |
| 9769 | /// | 9769 | /// |
| 9770 | - /// This gate was `#[ignore]`d RED through r1 (seed 50 luma (171,56)). | 9770 | + /// This gate was `#[ignore]`d RED through r3 (seed 50 luma (171,56)). |
| 9771 | - /// Root cause, r2: not availability at all -- `av1_nz_map_ctx_offset` is | 9771 | + /// Root cause, r4, TWO defects, neither of them availability -- the |
| 9772 | - /// packed COLUMN-major, so [`crate::decode::base_ctx`] read the | 9772 | + /// strip's own per-unit prediction was exact all along: |
| 9773 | - /// `TX_32X64`/`TX_64X32` offset tables transposed and desynced the first | 9773 | + /// 1. `av1_nz_map_ctx_offset` is indexed by libaom's COLUMN-major |
| 9774 | - /// SB-level strip whose luma corner held a coefficient below row 1 (see | 9774 | + /// `coeff_idx = col * 32 + row`, so [`crate::decode::base_ctx`] read |
| 9775 | - /// that function's comment). The strip's own per-unit prediction was | 9775 | + /// the `TX_32X64`/`TX_64X32` offset tables transposed (r2 saw this and |
| 9776 | - /// already exact. | 9776 | + /// r3 reverted it, because "fixing" it turned the merged SB HORZ/VERT |
| 9777 | - #[ignore = "lane-rectsplit r3: RED at seed 50; the nz_map transposition r2 blamed turns the merged SB HORZ/VERT partition gate RED at seed 43, cause still open"] | 9777 | + /// gate RED at seed 43); |
| 9778 | + /// 2. that seed-43 RED was a SECOND defect the first one had been hiding | ||
| 9779 | + /// behind a refusal: `EOB_PT_512_CHROMA` was transcribed from | ||
| 9780 | + /// `av1_default_eob_multi512_cdfs`'s `eob_multi_ctx = 1` row (the flat | ||
| 9781 | + /// `V_DCT`/`H_DCT` distribution), so the first real 32x16 chroma | ||
| 9782 | + /// transform read `eob_pt` 7 where aomdec read 2. With both fixed, | ||
| 9783 | + /// seeds 43 and 50 are pixel-exact. | ||
| 9778 | #[test] | 9784 | #[test] |
| 9779 | fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { | 9785 | fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { |
| 9780 | const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; | 9786 | const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; |
lanes/rectsplit-r4.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | |||
| 1 | +# lane-rectsplit r4 — SB-level split-transform strips: TWO root causes, refusal lifted | ||
| 2 | + | ||
| 3 | +Branch `lane-rectsplit` off `4c3389a` (r3's safe state). No rebase needed: `main` is still | ||
| 4 | +`3808cf8`, the branch's merge base. | ||
| 5 | + | ||
| 6 | +## Headline | ||
| 7 | + | ||
| 8 | +r3's four-way table was not a contradiction — it was two defects stacked, the first hiding | ||
| 9 | +the second behind a refusal: | ||
| 10 | + | ||
| 11 | +1. **`base_ctx` read the rect `av1_nz_map_ctx_offset` tables transposed.** libaom indexes | ||
| 12 | + them by its own `coeff_idx`, and `get_nz_map_ctx_from_stats` decomposes that as | ||
| 13 | + `col = coeff_idx >> bhl`, `bhl` = log2 of the *adjusted* height (5 for both `TX_64X32` | ||
| 14 | + and `TX_32X64`): `coeff_idx = col * 32 + row`, so 32 consecutive flat entries are one | ||
| 15 | + COLUMN and the `cdf.rs` 5x5 transcriptions are `[col][row]`. `decode.rs:1162` read them | ||
| 16 | + `[row][col]` = the transpose = the other shape's rule with 11 and 16 swapped. | ||
| 17 | + Fixed by stating libaom's generating rule (`txb_common.h:199-209`) once, exactly as | ||
| 18 | + `base_ctx_rect` already did, instead of indexing the tables at all. | ||
| 19 | +2. **`EOB_PT_512_CHROMA` was transcribed from the wrong row of | ||
| 20 | + `av1_default_eob_multi512_cdfs[q][plane][2]`.** The last index is `eob_multi_ctx` | ||
| 21 | + (0 = `TX_CLASS_2D`, 1 = `V_DCT`/`H_DCT`), not a q-context: the flat | ||
| 22 | + `3277, 6554, ...` distribution our table held is the 1D-class row, identical for both | ||
| 23 | + planes at every q, and the real chroma 2D row has four q-context variants like every | ||
| 24 | + other coefficient table. The FIRST real 32x16 chroma transform read `eob_pt` 7 where | ||
| 25 | + aomdec read 2 — that is what made seed 43 RED once defect 1 was fixed. Under r3's | ||
| 26 | + shipped code seed 43 never reached it: it desynced 13 elements EARLIER and exited | ||
| 27 | + through a named refusal, which the gate counts as a pass (class `refusal-hides-a-defect`). | ||
| 28 | + | ||
| 29 | +## Changed | ||
| 30 | + | ||
| 31 | +- `crates/ec-av1/src/decode.rs:1162` `base_ctx` — the `TX_CLASS_2D` rect arm now applies | ||
| 32 | + libaom's generating rule (`row < 2 -> 11` when w<h, `col < 2 -> 16` when w>h, else the | ||
| 33 | + square table), no transposable table read left. | ||
| 34 | +- `crates/ec-av1/src/cdf.rs:269` — `EOB_PT_512_CHROMA` corrected to the 2D chroma row plus | ||
| 35 | + new `_Q0`/`_Q1`/`_Q3` siblings; `cdf_state.rs:1015` now `pick()`s by q-context. | ||
| 36 | +- `crates/ec-av1/src/decode.rs:4102` `decode_block_rect64` — the split-transform refusal is | ||
| 37 | + LIFTED, wired to `decode_rect_split` (r1's per-unit port), `RECT_PARTITION_HITS` bumped. | ||
| 38 | +- `crates/ec-av1/src/decode.rs:3428` `decode_rect_split` — records `RECT64_QIDX_DRIFT_HITS` | ||
| 39 | + for 64-level strips, which now reach this path. | ||
| 40 | +- `crates/ec-av1/src/refusal_inventory.rs:49` — refusal string removed. | ||
| 41 | +- `crates/ec-av1/src/stream.rs:9778` — gate (b) un-`#[ignore]`d, its doc records both causes. | ||
| 42 | +- Instruments kept: `read_coeffs`/`read_coeffs_rect` print an `EC_COEFF_STEP` ladder under | ||
| 43 | + `EC_TRACE_COEFF` in instrumented-aomdec format, with `pos` converted to libaom's | ||
| 44 | + column-major `coeff_idx` so the two ladders `diff` line by line. | ||
| 45 | +- New unit test `decode::tests::base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain` | ||
| 46 | + — evaluates `base_ctx` over the WHOLE 5x5 domain of 64x32 / 32x64 / square against | ||
| 47 | + `table[col][row]` (class `enumerate-table-domain`). | ||
| 48 | + | ||
| 49 | +## Refusals lifted | ||
| 50 | + | ||
| 51 | +- `"a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)"` | ||
| 52 | + — with `a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact` | ||
| 53 | + green, hard-asserting `rect_split_sb_interior_tu_hits` (SB-level AND tx depth >= 2) sampled | ||
| 54 | + per compared attempt. | ||
| 55 | + | ||
| 56 | +## Gates and evidence | ||
| 57 | + | ||
| 58 | +EVIDENCE: msac range ladders `scratchpad/n_ours43.txt` vs `scratchpad/n_aom43.txt` | `EC_TRACE_COEFF=1 decode_probe seed43.obu` vs `EC_TRACE_COEFF=1 aomdec` on the gate-dumped seed-43 stream | first divergent element = the chroma `eob` of the 64x32 strip at mi (0,16): ours `eob_pt` group 8 (eob 103), aomdec group 3 (eob 3), at identical range 44680 — i.e. a CDF-content defect, not a context one | ||
| 59 | +EVIDENCE: `scratchpad/r4_ours43.yuv` vs `scratchpad/r4_aom43.yuv` | `decode_probe seed43.obu out.yuv`; `aomdec --rawvideo` | `cmp` byte-identical (was: frame-0 luma mismatch) | ||
| 60 | +EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3 -- --test-threads=1 --include-ignored superblock_level_horz_vert_partition split_transform_horz_vert_strip filter_intra_on_a_horz split_transform_superblock_strip refusal_inventory gate_coverage nz_map` | gates (a) (b) (c) + merged SB HORZ/VERT + inventory/coverage/table tests | 10 passed, 1 failed (81.41s) — the failure is the already-`#[ignore]`d `..._and_delta_q_...` gate, which fails its own drift counter, not a pixel compare (27/40 pixel-exact, 13 named refusals) | ||
| 61 | +EVIDENCE: third leg from lane-tx64x16 — `scratchpad` sweep seeds 42..81, 192x128 gradients, merged-gate recipe with `--min-partition-size=16 --enable-1to4-partitions=1` | encode with the oracle aomenc, `decode_probe` vs `aomdec --rawvideo`, `cmp` | 33 EXACT, 7 named refusals (6x SB-level AB partition, 1x screen-content strip), 0 mismatches — seed 55 (reported 3944 wrong luma samples, first at (154,59)) is now byte-exact | ||
| 62 | +EVIDENCE: full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` | whole crate lib | **272 passed, 0 failed, 23 ignored**, 490.90s (r3's expectation was 270/0/24; +1 un-ignored gate, +1 new unit test) | ||
| 63 | + | ||
| 64 | +## Film check (ReelB, the lane's critical path) | ||
| 65 | + | ||
| 66 | +`decode_probe` on the coordinator's mid-film extract (`ffmpeg -ss 600 -t 0.5 ... -f obu`, | ||
| 67 | +11.5 MB, 10-bit 2160p, `.../cdc46329-.../scratchpad/reelb5.obu`), which stopped at exactly this | ||
| 68 | +lane's refusal on main: | ||
| 69 | + | ||
| 70 | +``` | ||
| 71 | +before (main 06d856d): REFUSED: a superblock-level HORZ/VERT strip with a split transform ... | ||
| 72 | +after (this branch): REFUSED: AV1 tile (a 32x32 partition type this decoder does not code (value=8)) | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +EVIDENCE: `.../cdc46329-.../scratchpad/reelb5.obu` | `cargo run -p ec-av1 --example decode_probe` on `lane-rectsplit` r4 | the film advances past this lane's refusal to `PARTITION_HORZ_4` (value 8), a 1:4-partition gap owned by lane-part32/tx64x16 | ||
| 76 | + | ||
| 77 | +## Sibling sweep (defect class) | ||
| 78 | + | ||
| 79 | +- Class `table-transcribed-from-the-wrong-row-of-a-multi-dimensional-default`: every other | ||
| 80 | + coefficient CDF in `Cdfs::new` already goes through `pick(q_ctx, ...)`; a grep of | ||
| 81 | + `cdf.rs` for libaom's flat 1D rows (`3277, 6554` / `2979, 5958` / ...) finds no second | ||
| 82 | + instance. `EOB_PT_512_CHROMA` was the only coefficient table initialised without `pick`. | ||
| 83 | +- Class `reference-layout-not-spec` (transposed table): the only other rect offset consumer, | ||
| 84 | + `base_ctx_rect`, already stated the rule and is unchanged; the new domain test covers both. | ||
| 85 | + | ||
| 86 | +## Residue | ||
| 87 | + | ||
| 88 | +- deferred(lane-part32 / lane-tx64x16 — 1:4 partitions): both films and 7/40 seeds of the | ||
| 89 | + third-leg sweep now stop at `PARTITION_HORZ_4/VERT_4` or SB-level AB partitions. | ||
| 90 | +- deferred(lane-rect64q): `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact` | ||
| 91 | + stays `#[ignore]`d as r3 left it — its 40 attempts pixel-match (27 compared, 13 named | ||
| 92 | + refusals) but `deltaq-mode=1` never drifts `CURRENT_Q_IDX` inside a 64-level strip in | ||
| 93 | + that recipe. r4 added the missing counter bump on the split path; the gate still needs a | ||
| 94 | + recipe that actually drifts. | ||
| 95 | +- accepted: the third-leg recipe (`--min-partition-size=16 --enable-1to4-partitions=1`) is | ||
| 96 | + measured here but NOT added as a gate arm — its remaining refusals are 1:4/AB partitions | ||
| 97 | + owned by other lanes, so the arm would be RED for reasons outside this lane. | ||