Merge branch 'lane-kf900' (cbfe32d): skipped-leaf tx grid, chroma-reference neighbour snap, palette and intrabc on rect strips
Browse files at this commit12 changed files +1868 -63
- crates/ec-av1/examples/decode_probe.rs +5 -0
- crates/ec-av1/fixtures/reelb_kf900.obu +0 -0
- crates/ec-av1/src/decode.rs +408 -61
- crates/ec-av1/src/refusal_inventory.rs +1 -2
- crates/ec-av1/src/stream.rs +643 -0
- lanes/kf900-r1.handoff.md +122 -0
- lanes/kf900-r2.report.md +145 -0
- lanes/kf900-r3.handoff.md +117 -0
- lanes/kf900-r3.report.md +171 -0
- lanes/kf900-r4.handoff.md +98 -0
- lanes/kf900-r4.report.md +70 -0
- lanes/kf900-r5.report.md +88 -0
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
| @@ -33,6 +33,7 @@ fn main() { | ||
| 33 | 33 | println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}"); |
| 34 | 34 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 35 | 35 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 36 | + println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads()); | |
| 36 | 37 | let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); |
| 37 | 38 | println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); |
| 38 | 39 | let leaf = ec_av1::stream::vartx_rect_leaf_hits(); |
| @@ -44,6 +45,10 @@ fn main() { | ||
| 44 | 45 | "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}", |
| 45 | 46 | ab[0], ab[1], ab[2], ab[3] |
| 46 | 47 | ); |
| 48 | + // lane-kf900 r1: the counter the skipped-8x8-split-transform gate | |
| 49 | + // asserts -- printed here so a recipe sweep can see it fire without a | |
| 50 | + // test-binary rebuild. | |
| 51 | + println!("skip_split_tx: {}", ec_av1::decode::skip_split_tx_hits()); | |
| 47 | 52 | let ir = ec_av1::stream::inter_rect_counters(); |
| 48 | 53 | println!( |
| 49 | 54 | "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", |
crates/ec-av1/fixtures/reelb_kf900.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+408 -61
| @@ -1472,6 +1472,18 @@ thread_local! { | ||
| 1472 | 1472 | static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | +thread_local! { | |
| 1476 | + /// lane-kf900 r4: rect intra strips that ACTUALLY use a palette -- the | |
| 1477 | + /// 1:4 shapes (32x8/8x32, 16x4/4x16) and the sub-16x16 2:1 leaves | |
| 1478 | + /// (16x8/8x16), the two shapes the lifted refusals named. | |
| 1479 | + static RECT4_PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1480 | +} | |
| 1481 | + | |
| 1482 | +/// Current value of [`RECT4_PALETTE_HITS`]. | |
| 1483 | +pub(crate) fn rect4_palette_hits() -> usize { | |
| 1484 | + RECT4_PALETTE_HITS.with(|c| c.get()) | |
| 1485 | +} | |
| 1486 | + | |
| 1475 | 1487 | /// Current value of [`PALETTE_SPLIT_TX_HITS`]. |
| 1476 | 1488 | pub(crate) fn palette_split_tx_hits() -> usize { |
| 1477 | 1489 | PALETTE_SPLIT_TX_HITS.with(|c| c.get()) |
| @@ -1576,6 +1588,30 @@ thread_local! { | ||
| 1576 | 1588 | static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 1577 | 1589 | } |
| 1578 | 1590 | |
| 1591 | +/// Whether this frame's header set `allow_intrabc` -- [`INTRABC_MI_GRID`] is | |
| 1592 | +/// `Some` exactly then (set once per frame in `decode_frame`), so the flag | |
| 1593 | +/// needs no separate plumbing to reach the rect-strip mode reader. | |
| 1594 | +fn allow_intrabc_frame() -> bool { | |
| 1595 | + INTRABC_MI_GRID.with(|g| g.borrow().is_some()) | |
| 1596 | +} | |
| 1597 | + | |
| 1598 | +thread_local! { | |
| 1599 | + /// How many rect intra strips READ the `use_intrabc` symbol (i.e. how many | |
| 1600 | + /// times the fix below was exercised) -- the rect-strip gate's hit counter, | |
| 1601 | + /// distinct from [`INTRABC_HITS`] which counts blocks that USE intrabc. | |
| 1602 | + static RECT_INTRABC_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1603 | +} | |
| 1604 | + | |
| 1605 | +/// Current value of [`RECT_INTRABC_READS`]. | |
| 1606 | +pub(crate) fn rect_intrabc_reads() -> usize { | |
| 1607 | + RECT_INTRABC_READS.with(|c| c.get()) | |
| 1608 | +} | |
| 1609 | + | |
| 1610 | +/// Zeroes [`RECT_INTRABC_READS`] (gate tests call this before a decode). | |
| 1611 | +pub(crate) fn reset_rect_intrabc_reads() { | |
| 1612 | + RECT_INTRABC_READS.with(|c| c.set(0)); | |
| 1613 | +} | |
| 1614 | + | |
| 1579 | 1615 | /// Current value of [`INTRABC_HITS`]. |
| 1580 | 1616 | pub(crate) fn intrabc_hits() -> usize { |
| 1581 | 1617 | INTRABC_HITS.with(|c| c.get()) |
| @@ -4074,11 +4110,21 @@ impl Neighbours { | ||
| 4074 | 4110 | /// palette block decoded as "no palette" and the tile desynced from |
| 4075 | 4111 | /// there (class [[cdf-row-held-constant]]). |
| 4076 | 4112 | fn palette_ctx_and_cache(&self, at: (usize, usize)) -> (usize, Vec<u16>) { |
| 4113 | + self.palette_ctx_and_cache_mi(at, at.0 * (SUB / MI)) | |
| 4114 | + } | |
| 4115 | + | |
| 4116 | + /// [`Self::palette_ctx_and_cache`] with the block's REAL mi row, which a | |
| 4117 | + /// 1:4 strip does not share with its [`SUB`] cell: `av1_get_palette_cache` | |
| 4118 | + /// drops the above neighbour on a 64-px superblock boundary | |
| 4119 | + /// (pred_common.c:76, `row % (1 << MIN_SB_SIZE_LOG2)` with `row` the | |
| 4120 | + /// block's own PIXEL row), and strip 1 of a HORZ_4 sits 8 px into the | |
| 4121 | + /// cell -- reading `at.0 % 4` there excludes strip 0 from the cache of | |
| 4122 | + /// every strip in an SB's top cell row, which libaom does not do. | |
| 4123 | + fn palette_ctx_and_cache_mi(&self, at: (usize, usize), mi_r: usize) -> (usize, Vec<u16>) { | |
| 4077 | 4124 | let (r, c) = at; |
| 4078 | - let above_ok = r % 4 != 0; | |
| 4125 | + let above_ok = mi_r % 16 != 0; | |
| 4079 | 4126 | // `xd->above_mbmi` exists for every row but the tile's own first. |
| 4080 | - let above_is_palette = | |
| 4081 | - r * (SUB / MI) > self.tile_row0_mi && self.above_palette_size[c] > 0; | |
| 4127 | + let above_is_palette = mi_r > self.tile_row0_mi && self.above_palette_size[c] > 0; | |
| 4082 | 4128 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { |
| 4083 | 4129 | (self.above_palette_size[c], self.above_palette_colors[c]) |
| 4084 | 4130 | } else { |
| @@ -4164,8 +4210,14 @@ impl Neighbours { | ||
| 4164 | 4210 | /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`), |
| 4165 | 4211 | /// so only the cache is wanted here. |
| 4166 | 4212 | fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> { |
| 4213 | + self.palette_uv_cache_mi(at, at.0 * (SUB / MI)) | |
| 4214 | + } | |
| 4215 | + | |
| 4216 | + /// [`Self::palette_uv_cache`] with the block's real mi row -- see | |
| 4217 | + /// [`Self::palette_ctx_and_cache_mi`]. | |
| 4218 | + fn palette_uv_cache_mi(&self, at: (usize, usize), mi_r: usize) -> Vec<u16> { | |
| 4167 | 4219 | let (r, c) = at; |
| 4168 | - let above_ok = r % 4 != 0; | |
| 4220 | + let above_ok = mi_r % 16 != 0; | |
| 4169 | 4221 | let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { |
| 4170 | 4222 | (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) |
| 4171 | 4223 | } else { |
| @@ -4238,6 +4290,9 @@ impl Neighbours { | ||
| 4238 | 4290 | // TX_32X32 -- independent of this block's luma `tx_depth`. |
| 4239 | 4291 | let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8; |
| 4240 | 4292 | let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8; |
| 4293 | + if std::env::var_os("EC_TXGRID_TRACE").is_some() { | |
| 4294 | + eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"); | |
| 4295 | + } | |
| 4241 | 4296 | let cur = CURRENT_DELTA_LF.with(|c| c.get()); |
| 4242 | 4297 | let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) { |
| 4243 | 4298 | std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8) |
| @@ -4733,6 +4788,37 @@ impl Neighbours { | ||
| 4733 | 4788 | /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no |
| 4734 | 4789 | /// block has recorded the exact neighbouring mi. |
| 4735 | 4790 | fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool { |
| 4791 | + // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA | |
| 4792 | + // REFERENCE block, not off the mi that carries the chroma syntax. | |
| 4793 | + // `set_mi_row_col` (`blockd.h`) takes | |
| 4794 | + // `base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]` and | |
| 4795 | + // only then `chroma_above_mbmi = base_mi[-stride]` / | |
| 4796 | + // `chroma_left_mbmi = base_mi[-1]`. A sub-8 pair codes its chroma at | |
| 4797 | + // the ODD mi, so without the snap we looked one mi row/column too far | |
| 4798 | + // down/right -- the mi-exact slot never matched and the coarse | |
| 4799 | + // fallback answered instead. Measured on a 4K 10-bit key frame, chroma | |
| 4800 | + // 8x4 at (688, 100) = mi (51, 344): libaom's | |
| 4801 | + // `get_intra_edge_filter_type` is 1 (the chroma block above it is | |
| 4802 | + // `UV_SMOOTH_PRED`), ours was 0, which flips | |
| 4803 | + // `av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`: | |
| 4804 | + // false for type 1, TRUE for type 0) and upsampled an edge libaom | |
| 4805 | + // leaves alone -- +1 on rows 2/3 of that block and every chroma block | |
| 4806 | + // predicting from it (class `context-read-from-one-cell`). | |
| 4807 | + self.smooth_uv_neighbour_unsnapped(mi_r & !1, mi_c & !1, r, c) | |
| 4808 | + } | |
| 4809 | + | |
| 4810 | + /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e. | |
| 4811 | + /// read off the mi passed in exactly. Only the 16x4/4x16 pair witness | |
| 4812 | + /// counter wants this: it measures how often the snap CHANGES the answer, | |
| 4813 | + /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every | |
| 4814 | + /// decode path uses the snapping form. | |
| 4815 | + fn smooth_uv_neighbour_unsnapped( | |
| 4816 | + &self, | |
| 4817 | + mi_r: usize, | |
| 4818 | + mi_c: usize, | |
| 4819 | + r: usize, | |
| 4820 | + c: usize, | |
| 4821 | + ) -> bool { | |
| 4736 | 4822 | // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the |
| 4737 | 4823 | // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid |
| 4738 | 4824 | // array that `start_tile` does not clear, so a block on a tile's first |
| @@ -5276,7 +5362,15 @@ fn merge_colors(transmitted: &[u16], cached: &[u16]) -> Vec<u16> { | ||
| 5276 | 5362 | out |
| 5277 | 5363 | } |
| 5278 | 5364 | |
| 5279 | -/// `read_palette_colors_y` (decodemv.c:478), bit_depth fixed at 8 (this | |
| 5365 | +/// `read_palette_colors_y` (decodemv.c:478), at the sequence's real | |
| 5366 | +/// `bit_depth` -- lane-kf900 r3: every raw literal here (the first colour, | |
| 5367 | +/// each delta's width, the `range` bound and the clamp) is sized by | |
| 5368 | +/// `bit_depth`, and hardcoding 8 read 2 bits too few per colour on every | |
| 5369 | +/// 10-bit palette block. Raw literals are EQUIPROBABLE, and at the ranges | |
| 5370 | +/// this stream reaches (e.g. 62728) an equiprobable read is a FIXED POINT of | |
| 5371 | +/// the msac range, so a cross-decoder range ladder stays bit-identical | |
| 5372 | +/// through the whole miscount -- only the decoded VALUE differs (class | |
| 5373 | +/// `compare-range-not-tell`'s blind spot). (this | |
| 5280 | 5374 | /// decoder is 8-bit only): accepts up to `n` colours straight from `cache` |
| 5281 | 5375 | /// (one flag bit each, in cache order), then delta-codes the remainder |
| 5282 | 5376 | /// (first value raw, each following delta `>= 1` off a shrinking bit width), |
| @@ -5291,20 +5385,22 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u | ||
| 5291 | 5385 | cached.push(c); |
| 5292 | 5386 | } |
| 5293 | 5387 | } |
| 5388 | + let bd = u32::from(bit_depth()); | |
| 5389 | + let max_val = (1i32 << bd) - 1; | |
| 5294 | 5390 | let mut colors = [0u16; 8]; |
| 5295 | 5391 | let n_cached = cached.len(); |
| 5296 | 5392 | if n_cached < n { |
| 5297 | 5393 | let mut transmitted = Vec::with_capacity(n - n_cached); |
| 5298 | - let first = dec.literal(8) as u16; | |
| 5394 | + let first = dec.literal(bd) as u16; | |
| 5299 | 5395 | transmitted.push(first); |
| 5300 | 5396 | if n_cached + 1 < n { |
| 5301 | - let min_bits = 8u32 - 3; | |
| 5397 | + let min_bits = bd - 3; | |
| 5302 | 5398 | let mut bits = min_bits + dec.literal(2); |
| 5303 | - let mut range = 255i32 - i32::from(first) - 1; | |
| 5399 | + let mut range = (1i32 << bd) - i32::from(first) - 1; | |
| 5304 | 5400 | for _ in (n_cached + 1)..n { |
| 5305 | 5401 | let delta = dec.literal(bits) as i32 + 1; |
| 5306 | 5402 | let prev = *transmitted.last().unwrap(); |
| 5307 | - let val = (i32::from(prev) + delta).clamp(0, 255) as u16; | |
| 5403 | + let val = (i32::from(prev) + delta).clamp(0, max_val) as u16; | |
| 5308 | 5404 | range -= i32::from(val) - i32::from(prev); |
| 5309 | 5405 | bits = bits.min(ceil_log2(range.max(0) as u32)); |
| 5310 | 5406 | transmitted.push(val); |
| @@ -5318,7 +5414,8 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u | ||
| 5318 | 5414 | colors |
| 5319 | 5415 | } |
| 5320 | 5416 | |
| 5321 | -/// `read_palette_colors_uv` (decodemv.c:509), bit_depth fixed at 8: U reads | |
| 5417 | +/// `read_palette_colors_uv` (decodemv.c:509), at the sequence's real | |
| 5418 | +/// `bit_depth` (see [`read_palette_colors_y`]): U reads | |
| 5322 | 5419 | /// exactly [`read_palette_colors_y`]'s cache/delta scheme (against the U-only |
| 5323 | 5420 | /// cache, `range` starting at `255 - prev` with no `-1`, and each raw `delta` |
| 5324 | 5421 | /// unbiased by `+1` -- both differences from Y's own reader, matching the C |
| @@ -5335,20 +5432,22 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ( | ||
| 5335 | 5432 | cached.push(c); |
| 5336 | 5433 | } |
| 5337 | 5434 | } |
| 5435 | + let bd = u32::from(bit_depth()); | |
| 5436 | + let max_val = 1i32 << bd; | |
| 5338 | 5437 | let mut u_colors = [0u16; 8]; |
| 5339 | 5438 | let n_cached = cached.len(); |
| 5340 | 5439 | if n_cached < n { |
| 5341 | 5440 | let mut transmitted = Vec::with_capacity(n - n_cached); |
| 5342 | - let first = dec.literal(8) as u16; | |
| 5441 | + let first = dec.literal(bd) as u16; | |
| 5343 | 5442 | transmitted.push(first); |
| 5344 | 5443 | if n_cached + 1 < n { |
| 5345 | - let min_bits = 8u32 - 3; | |
| 5444 | + let min_bits = bd - 3; | |
| 5346 | 5445 | let mut bits = min_bits + dec.literal(2); |
| 5347 | - let mut range = 255i32 - i32::from(first); | |
| 5446 | + let mut range = max_val - i32::from(first); | |
| 5348 | 5447 | for _ in (n_cached + 1)..n { |
| 5349 | 5448 | let delta = dec.literal(bits) as i32; |
| 5350 | 5449 | let prev = *transmitted.last().unwrap(); |
| 5351 | - let val = (i32::from(prev) + delta).clamp(0, 255) as u16; | |
| 5450 | + let val = (i32::from(prev) + delta).clamp(0, max_val - 1) as u16; | |
| 5352 | 5451 | range -= i32::from(val) - i32::from(prev); |
| 5353 | 5452 | bits = bits.min(ceil_log2(range.max(0) as u32)); |
| 5354 | 5453 | transmitted.push(val); |
| @@ -5361,9 +5460,9 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ( | ||
| 5361 | 5460 | } |
| 5362 | 5461 | let mut v_colors = [0u16; 8]; |
| 5363 | 5462 | if dec.literal(1) == 1 { |
| 5364 | - let min_bits_v = 8u32 - 4; | |
| 5463 | + let min_bits_v = bd - 4; | |
| 5365 | 5464 | let bits = min_bits_v + dec.literal(2); |
| 5366 | - v_colors[0] = dec.literal(8) as u16; | |
| 5465 | + v_colors[0] = dec.literal(bd) as u16; | |
| 5367 | 5466 | for i in 1..n { |
| 5368 | 5467 | let mut delta = dec.literal(bits) as i32; |
| 5369 | 5468 | if delta != 0 && dec.literal(1) == 1 { |
| @@ -5371,16 +5470,16 @@ fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ( | ||
| 5371 | 5470 | } |
| 5372 | 5471 | let mut val = i32::from(v_colors[i - 1]) + delta; |
| 5373 | 5472 | if val < 0 { |
| 5374 | - val += 256; | |
| 5473 | + val += max_val; | |
| 5375 | 5474 | } |
| 5376 | - if val >= 256 { | |
| 5377 | - val -= 256; | |
| 5475 | + if val >= max_val { | |
| 5476 | + val -= max_val; | |
| 5378 | 5477 | } |
| 5379 | 5478 | v_colors[i] = val as u16; |
| 5380 | 5479 | } |
| 5381 | 5480 | } else { |
| 5382 | 5481 | for i in 0..n { |
| 5383 | - v_colors[i] = dec.literal(8) as u16; | |
| 5482 | + v_colors[i] = dec.literal(bd) as u16; | |
| 5384 | 5483 | } |
| 5385 | 5484 | } |
| 5386 | 5485 | (u_colors, v_colors) |
| @@ -5559,6 +5658,13 @@ fn read_intra_mode_rect( | ||
| 5559 | 5658 | Option<PaletteUv>, |
| 5560 | 5659 | )> { |
| 5561 | 5660 | let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); |
| 5661 | + if ec_istep { | |
| 5662 | + // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line | |
| 5663 | + // (decodemv.c:818), printed at the same point: before the first | |
| 5664 | + // mode-info symbol of the block, so a cross-decoder range ladder can | |
| 5665 | + // be keyed on the BLOCK, not just on the symbol sequence. | |
| 5666 | + eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", enable_filter_intra as i32, filter_intra_size_class_rect(bw, bh), dec.debug_state().0); | |
| 5667 | + } | |
| 5562 | 5668 | macro_rules! istep { |
| 5563 | 5669 | ($name:literal, $val:expr) => { |
| 5564 | 5670 | if ec_istep { |
| @@ -5599,6 +5705,27 @@ fn read_intra_mode_rect( | ||
| 5599 | 5705 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); |
| 5600 | 5706 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); |
| 5601 | 5707 | istep!("dq", 0); |
| 5708 | + // `read_intrabc_info` (spec 5.11.13, libaom `decodemv.c:892`, right after | |
| 5709 | + // `skip`/`segment_id`/`cdef`/`delta_q` and before `mbmi->mode`): the | |
| 5710 | + // `use_intrabc` symbol is read for EVERY intra block of an `allow_intrabc` | |
| 5711 | + // frame -- `av1_allow_intrabc` is a frame-level test with no shape term, so | |
| 5712 | + // rect strips read it exactly like square leaves ([`read_intra_mode`], | |
| 5713 | + // [`read_intra_mode_sub8`]). Missing it here desynced the arithmetic | |
| 5714 | + // decoder at the FIRST symbol of the first rect block of every | |
| 5715 | + // `--tune-content=screen` key frame. Reconstruction of a real intrabc | |
| 5716 | + // block at this shape is out of scope, so the flag is consumed and | |
| 5717 | + // refused by name when it fires. | |
| 5718 | + if allow_intrabc_frame() { | |
| 5719 | + let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; | |
| 5720 | + RECT_INTRABC_READS.with(|c| c.set(c.get() + 1)); | |
| 5721 | + istep!("intrabc", use_intrabc as i32); | |
| 5722 | + if use_intrabc { | |
| 5723 | + INTRABC_HITS.with(|c| c.set(c.get() + 1)); | |
| 5724 | + return Err(unsupported( | |
| 5725 | + "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", | |
| 5726 | + )); | |
| 5727 | + } | |
| 5728 | + } | |
| 5602 | 5729 | let above_ctx = INTRA_MODE_CTX[above_mode]; |
| 5603 | 5730 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 5604 | 5731 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| @@ -5696,9 +5823,11 @@ fn read_intra_mode_rect( | ||
| 5696 | 5823 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 5697 | 5824 | eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32); |
| 5698 | 5825 | } |
| 5826 | + istep!("use_filter_intra", use_filter_intra as i32); | |
| 5699 | 5827 | if use_filter_intra { |
| 5700 | 5828 | FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); |
| 5701 | 5829 | let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); |
| 5830 | + istep!("filter_intra_mode", fi_mode as i32); | |
| 5702 | 5831 | filter_intra = Some(fi_mode); |
| 5703 | 5832 | } |
| 5704 | 5833 | } |
| @@ -5711,7 +5840,13 @@ fn read_intra_mode_rect( | ||
| 5711 | 5840 | PaletteY { size: n, colors, map } |
| 5712 | 5841 | }); |
| 5713 | 5842 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { |
| 5714 | - let map = decode_color_index_map_wh(dec, cdfs, n, bw / 2, bh / 2, true); | |
| 5843 | + // `av1_get_plane_block_size(bsize, 1, 1)` (`ss_size_lookup`), NOT a | |
| 5844 | + // plain halving: BLOCK_16X4 subsamples to BLOCK_8X4 and BLOCK_4X16 to | |
| 5845 | + // BLOCK_4X8, both floored at the 4-px transform. Halving the short | |
| 5846 | + // axis to 2 read HALF the colour-index symbols of a 1:4 strip's | |
| 5847 | + // chroma palette and desynced the tile from there. | |
| 5848 | + let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4)); | |
| 5849 | + let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, true); | |
| 5715 | 5850 | PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); |
| 5716 | 5851 | PaletteUv { size: n, u_colors, v_colors, map } |
| 5717 | 5852 | }); |
| @@ -5728,6 +5863,48 @@ fn read_intra_mode_rect( | ||
| 5728 | 5863 | )) |
| 5729 | 5864 | } |
| 5730 | 5865 | |
| 5866 | +/// Stamps a 1:4 strip's palette state into the coarse above/left arrays. | |
| 5867 | +/// `av1_get_palette_cache` reads `xd->above_mbmi`/`xd->left_mbmi`, and inside | |
| 5868 | +/// a HORZ_4 (VERT_4) the next strip's ABOVE (LEFT) neighbour is this strip | |
| 5869 | +/// while its LEFT (ABOVE) neighbour is still the parent block's. The coarse | |
| 5870 | +/// [`SUB`]-cell arrays alias all four strips onto one entry, so writing BOTH | |
| 5871 | +/// axes after every strip would hand strip i+1 this strip's colours on the | |
| 5872 | +/// wrong axis too -- a wrong cache costs the same bits, so the tile stays in | |
| 5873 | +/// sync and only the pixels are wrong (class [[cdf-row-held-constant]]). | |
| 5874 | +/// Only the split axis is written until the closing strip, which stamps both | |
| 5875 | +/// for whatever follows the parent block. | |
| 5876 | +#[allow(clippy::too_many_arguments)] | |
| 5877 | +fn record_strip_palette( | |
| 5878 | + n: &mut Neighbours, | |
| 5879 | + at: (usize, usize), | |
| 5880 | + bw: usize, | |
| 5881 | + bh: usize, | |
| 5882 | + y_size: usize, | |
| 5883 | + y_colors: [u16; 8], | |
| 5884 | + uv_size: usize, | |
| 5885 | + uv_colors: [u16; 8], | |
| 5886 | + last: bool, | |
| 5887 | +) { | |
| 5888 | + let (r, c) = at; | |
| 5889 | + let horz = bw > bh; | |
| 5890 | + if horz || last { | |
| 5891 | + for cell in 0..(bw / SUB).max(1) { | |
| 5892 | + n.above_palette_size[c + cell] = y_size; | |
| 5893 | + n.above_palette_colors[c + cell] = y_colors; | |
| 5894 | + n.above_palette_uv_size[c + cell] = uv_size; | |
| 5895 | + n.above_palette_uv_colors[c + cell] = uv_colors; | |
| 5896 | + } | |
| 5897 | + } | |
| 5898 | + if !horz || last { | |
| 5899 | + for cell in 0..(bh / SUB).max(1) { | |
| 5900 | + n.left_palette_size[r + cell] = y_size; | |
| 5901 | + n.left_palette_colors[r + cell] = y_colors; | |
| 5902 | + n.left_palette_uv_size[r + cell] = uv_size; | |
| 5903 | + n.left_palette_uv_colors[r + cell] = uv_colors; | |
| 5904 | + } | |
| 5905 | + } | |
| 5906 | +} | |
| 5907 | + | |
| 5731 | 5908 | /// [`tx_size_context`] for a true `bw`x`bh` rect strip (lane-intradisp r1): |
| 5732 | 5909 | /// `get_tx_size_context` (libaom `pred_common.h`) compares the neighbour |
| 5733 | 5910 | /// above against this block's own *width* and the neighbour to the left |
| @@ -5741,6 +5918,14 @@ fn tx_size_context_rect( | ||
| 5741 | 5918 | ) -> usize { |
| 5742 | 5919 | let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; |
| 5743 | 5920 | let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; |
| 5921 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | |
| 5922 | + eprintln!( | |
| 5923 | + "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}", | |
| 5924 | + if mi_r > n.tile_row0_mi { tx_px_at(n, false, mi_r - 1, mi_c) } else { 0 }, | |
| 5925 | + if mi_c > n.tile_col0_mi { tx_h_px_at(n, false, mi_r, mi_c - 1) } else { 0 }, | |
| 5926 | + usize::from(above) + usize::from(left) | |
| 5927 | + ); | |
| 5928 | + } | |
| 5744 | 5929 | usize::from(above) + usize::from(left) |
| 5745 | 5930 | } |
| 5746 | 5931 | |
| @@ -6918,8 +7103,11 @@ fn decode_leaf_rect( | ||
| 6918 | 7103 | // decoded bit is the same. The cell is the 16px-SUB cell containing the |
| 6919 | 7104 | // leaf (the palette neighbour arrays have no finer granularity). |
| 6920 | 7105 | let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); |
| 6921 | - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(pal_at); | |
| 6922 | - let palette_uv_cache = neighbours.palette_uv_cache(pal_at); | |
| 7106 | + // lane-kf900 r4: the leaf's REAL mi row -- the second leaf of a 16x8 pair | |
| 7107 | + // sits 8 px into the cell, so the cache's superblock-top-row exclusion | |
| 7108 | + // must not be read off the cell (see [`Neighbours::palette_ctx_and_cache_mi`]). | |
| 7109 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, leaf_mi.0); | |
| 7110 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, leaf_mi.0); | |
| 6923 | 7111 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 6924 | 7112 | read_intra_mode_rect( |
| 6925 | 7113 | dec, |
| @@ -6938,14 +7126,31 @@ fn decode_leaf_rect( | ||
| 6938 | 7126 | leaf_mi.0, |
| 6939 | 7127 | leaf_mi.1, |
| 6940 | 7128 | )?; |
| 7129 | + // lane-kf900 r4: palette prediction on this shape, the same colour-index | |
| 7130 | + // map -> base colours buffer [`decode_block_rect`] hands each | |
| 7131 | + // `reconstruct_rect` through [`set_palette_pred`]. | |
| 6941 | 7132 | if palette_y.is_some() || palette_uv.is_some() { |
| 6942 | - // Symbols (mode/size/colours/index map) are all read above, so the | |
| 6943 | - // tile stays in sync; only the *pixel* reconstruction of a palette on | |
| 6944 | - // a below-16x16 strip is unported and ungated (lane-palette2 r7). | |
| 6945 | - return Err(unsupported( | |
| 6946 | - "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", | |
| 6947 | - )); | |
| 7133 | + RECT4_PALETTE_HITS.with(|c| c.set(c.get() + 1)); | |
| 6948 | 7134 | } |
| 7135 | + let palette_y_buf: Option<Vec<u16>> = palette_y | |
| 7136 | + .as_ref() | |
| 7137 | + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); | |
| 7138 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| { | |
| 7139 | + ( | |
| 7140 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | |
| 7141 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | |
| 7142 | + ) | |
| 7143 | + }); | |
| 7144 | + let (pal_y_size, pal_y_colors) = | |
| 7145 | + palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | |
| 7146 | + let (pal_uv_size, pal_uv_colors) = | |
| 7147 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | |
| 7148 | + // The closing leaf of the pair -- see [`record_strip_palette`]. | |
| 7149 | + let pal_last = if bw > bh { | |
| 7150 | + leaf_mi.0 % 4 == 2 | |
| 7151 | + } else { | |
| 7152 | + leaf_mi.1 % 4 == 2 | |
| 7153 | + }; | |
| 6949 | 7154 | if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { |
| 6950 | 7155 | eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); |
| 6951 | 7156 | } |
| @@ -7004,11 +7209,12 @@ fn decode_leaf_rect( | ||
| 7004 | 7209 | // the unsplit arm below passes the real neighbour answer -- chroma |
| 7005 | 7210 | // of a tx-split 16x8/8x16 leaf lost its intra-edge filter type. |
| 7006 | 7211 | smooth_neighbor_uv, |
| 7007 | - // Both callers refuse a palette on this shape above (pixel | |
| 7008 | - // reconstruction is unported here), so the split units carry none. | |
| 7009 | - palette_y: None, | |
| 7010 | - palette_uv: None, | |
| 7212 | + palette_y: palette_y_buf.clone(), | |
| 7213 | + palette_uv: palette_uv_bufs.clone(), | |
| 7011 | 7214 | }; |
| 7215 | + if palette_y.is_some() || palette_uv.is_some() { | |
| 7216 | + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | |
| 7217 | + } | |
| 7012 | 7218 | decode_rect_split( |
| 7013 | 7219 | dec, |
| 7014 | 7220 | cdfs, |
| @@ -7025,6 +7231,10 @@ fn decode_leaf_rect( | ||
| 7025 | 7231 | base_q_idx, |
| 7026 | 7232 | reduced_tx_set, |
| 7027 | 7233 | )?; |
| 7234 | + record_strip_palette( | |
| 7235 | + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 7236 | + pal_last, | |
| 7237 | + ); | |
| 7028 | 7238 | return Ok(mode); |
| 7029 | 7239 | } |
| 7030 | 7240 | let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); |
| @@ -7036,15 +7246,24 @@ fn decode_leaf_rect( | ||
| 7036 | 7246 | luma_levels = vec![0i32; bw * bh]; |
| 7037 | 7247 | u_levels = vec![0i32; chroma_w * chroma_h]; |
| 7038 | 7248 | v_levels = vec![0i32; chroma_w * chroma_h]; |
| 7249 | + if let Some(b) = &palette_y_buf { | |
| 7250 | + set_palette_pred(b.clone()); | |
| 7251 | + } | |
| 7039 | 7252 | y.reconstruct_rect( |
| 7040 | 7253 | px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra, |
| 7041 | 7254 | smooth_neighbor, |
| 7042 | 7255 | ); |
| 7043 | 7256 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 7257 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 7258 | + set_palette_pred(ub.clone()); | |
| 7259 | + } | |
| 7044 | 7260 | u.reconstruct_rect( |
| 7045 | 7261 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels, |
| 7046 | 7262 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, |
| 7047 | 7263 | ); |
| 7264 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 7265 | + set_palette_pred(vb.clone()); | |
| 7266 | + } | |
| 7048 | 7267 | v.reconstruct_rect( |
| 7049 | 7268 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels, |
| 7050 | 7269 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, |
| @@ -7080,6 +7299,9 @@ fn decode_leaf_rect( | ||
| 7080 | 7299 | &luma_levels, bw, bh, crate::decode::bit_depth(), |
| 7081 | 7300 | CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(0).0, plane_q_delta(0).1, luma_tx_type, |
| 7082 | 7301 | ); |
| 7302 | + if let Some(b) = &palette_y_buf { | |
| 7303 | + set_palette_pred(b.clone()); | |
| 7304 | + } | |
| 7083 | 7305 | y.reconstruct_rect( |
| 7084 | 7306 | px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra, |
| 7085 | 7307 | smooth_neighbor, |
| @@ -7097,6 +7319,9 @@ fn decode_leaf_rect( | ||
| 7097 | 7319 | &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(), |
| 7098 | 7320 | CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(1).0, plane_q_delta(1).1, u_tx_type, |
| 7099 | 7321 | ); |
| 7322 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 7323 | + set_palette_pred(ub.clone()); | |
| 7324 | + } | |
| 7100 | 7325 | u.reconstruct_rect( |
| 7101 | 7326 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual, |
| 7102 | 7327 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, |
| @@ -7113,6 +7338,9 @@ fn decode_leaf_rect( | ||
| 7113 | 7338 | &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(), |
| 7114 | 7339 | CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(2).0, plane_q_delta(2).1, v_tx_type, |
| 7115 | 7340 | ); |
| 7341 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 7342 | + set_palette_pred(vb.clone()); | |
| 7343 | + } | |
| 7116 | 7344 | v.reconstruct_rect( |
| 7117 | 7345 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual, |
| 7118 | 7346 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, |
| @@ -7122,12 +7350,15 @@ fn decode_leaf_rect( | ||
| 7122 | 7350 | neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]); |
| 7123 | 7351 | neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); |
| 7124 | 7352 | neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0); |
| 7125 | - // This leaf is necessarily non-palette (a palette one refused above), so | |
| 7126 | - // it must CLEAR the above/left palette state over its own span -- without | |
| 7127 | - // this the next block's `palette_y_mode` ctx and colour cache were read | |
| 7128 | - // off whatever block last covered the cell (lane-palette2 r8). | |
| 7129 | - neighbours.record_palette_y_rect(pal_at, bw, bh, 0, [0u16; 8]); | |
| 7130 | - neighbours.record_palette_uv_rect(pal_at, bw, bh, 0, [0u16; 8]); | |
| 7353 | + // The leaf's own palette state (`0` clears, as this site always did | |
| 7354 | + // while a palette leaf refused -- lane-palette2 r8), written on the SPLIT | |
| 7355 | + // AXIS only until the pair's closing leaf: the coarse cell holds one | |
| 7356 | + // entry for both leaves, and leaf 0 zeroing the LEFT one threw away the | |
| 7357 | + // real left neighbour leaf 1 reads (lane-kf900 r4). | |
| 7358 | + record_strip_palette( | |
| 7359 | + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 7360 | + pal_last, | |
| 7361 | + ); | |
| 7131 | 7362 | // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and |
| 7132 | 7363 | // rows -- record the whole span, not one cell. |
| 7133 | 7364 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode); |
| @@ -7191,6 +7422,14 @@ fn decode_block_rect4( | ||
| 7191 | 7422 | // 8-px strip of a `HORZ_4`/`VERT_4` onto one cell. |
| 7192 | 7423 | let (above_mode, left_mode) = |
| 7193 | 7424 | neighbours.modes_above_left_mi(mi_r, mi_c, (above_mode, left_mode)); |
| 7425 | + // lane-kf900 r4: this strip's own palette-Y mode ctx and colour cache. | |
| 7426 | + // Passing `None`/`&[]` read `palette_y_mode` off CDF row 0 and every | |
| 7427 | + // `palette_colors_y` cache hit off an EMPTY cache -- right symbol count, | |
| 7428 | + // wrong interval, so a screen-content tile desynced at the first strip | |
| 7429 | + // whose neighbour used a palette (class [[cdf-row-held-constant]]). | |
| 7430 | + let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | |
| 7431 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, mi_r); | |
| 7432 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, mi_r); | |
| 7194 | 7433 | let ( |
| 7195 | 7434 | skip, |
| 7196 | 7435 | mode, |
| @@ -7213,21 +7452,35 @@ fn decode_block_rect4( | ||
| 7213 | 7452 | enable_filter_intra, |
| 7214 | 7453 | neighbours.skip_txfm_ctx(mi_r, mi_c), |
| 7215 | 7454 | allow_screen_content_tools, |
| 7216 | - None, | |
| 7217 | - &[], | |
| 7455 | + Some((palette_ctx, &palette_cache)), | |
| 7456 | + &palette_uv_cache, | |
| 7218 | 7457 | mi_r, |
| 7219 | 7458 | mi_c, |
| 7220 | 7459 | )?; |
| 7221 | - // Merge of lane-palette2: `read_intra_mode_rect` now reads the palette | |
| 7222 | - // syntax for every rect strip, but this 1:4 decoder has no palette | |
| 7223 | - // reconstruction path (its caller never passes a cache). The symbols are | |
| 7224 | - // still read, so the stream stays in sync; a strip that ACTUALLY uses a | |
| 7225 | - // palette is refused rather than reconstructed wrong. | |
| 7460 | + // lane-kf900 r4: palette prediction on this shape, exactly as | |
| 7461 | + // [`decode_block_rect`] does one aspect ratio up -- the colour-index map | |
| 7462 | + // mapped through the base colours IS the prediction (it reads no edge | |
| 7463 | + // pixels), handed to each `reconstruct_rect` through [`set_palette_pred`]. | |
| 7226 | 7464 | if palette_y.is_some() || palette_uv.is_some() { |
| 7227 | - return Err(unsupported( | |
| 7228 | - "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | |
| 7229 | - )); | |
| 7465 | + RECT4_PALETTE_HITS.with(|c| c.set(c.get() + 1)); | |
| 7230 | 7466 | } |
| 7467 | + let palette_y_buf: Option<Vec<u16>> = palette_y | |
| 7468 | + .as_ref() | |
| 7469 | + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); | |
| 7470 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| { | |
| 7471 | + ( | |
| 7472 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | |
| 7473 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | |
| 7474 | + ) | |
| 7475 | + }); | |
| 7476 | + // `last`: strip 3 of the parent 32x32's HORZ_4 (VERT_4), the only one | |
| 7477 | + // whose colours a block outside the parent sees -- see | |
| 7478 | + // [`record_strip_palette`]. | |
| 7479 | + let pal_last = if bw > bh { mi_r % 8 == 6 } else { mi_c % 8 == 6 }; | |
| 7480 | + let (pal_y_size, pal_y_colors) = | |
| 7481 | + palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | |
| 7482 | + let (pal_uv_size, pal_uv_colors) = | |
| 7483 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | |
| 7231 | 7484 | let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); |
| 7232 | 7485 | if smooth_neighbor { |
| 7233 | 7486 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -7287,11 +7540,12 @@ fn decode_block_rect4( | ||
| 7287 | 7540 | filter_intra, |
| 7288 | 7541 | smooth_neighbor, |
| 7289 | 7542 | smooth_neighbor_uv, |
| 7290 | - // Both callers refuse a palette on this shape above (pixel | |
| 7291 | - // reconstruction is unported here), so the split units carry none. | |
| 7292 | - palette_y: None, | |
| 7293 | - palette_uv: None, | |
| 7543 | + palette_y: palette_y_buf.clone(), | |
| 7544 | + palette_uv: palette_uv_bufs.clone(), | |
| 7294 | 7545 | }; |
| 7546 | + if palette_y.is_some() || palette_uv.is_some() { | |
| 7547 | + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | |
| 7548 | + } | |
| 7295 | 7549 | decode_rect_split( |
| 7296 | 7550 | dec, |
| 7297 | 7551 | cdfs, |
| @@ -7308,6 +7562,10 @@ fn decode_block_rect4( | ||
| 7308 | 7562 | base_q_idx, |
| 7309 | 7563 | false, |
| 7310 | 7564 | )?; |
| 7565 | + record_strip_palette( | |
| 7566 | + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, | |
| 7567 | + pal_uv_colors, pal_last, | |
| 7568 | + ); | |
| 7311 | 7569 | if bw > bh { |
| 7312 | 7570 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| 7313 | 7571 | } else { |
| @@ -7399,6 +7657,9 @@ fn decode_block_rect4( | ||
| 7399 | 7657 | plane_q_delta(0).1, |
| 7400 | 7658 | luma_tx_type, |
| 7401 | 7659 | ); |
| 7660 | + if let Some(b) = &palette_y_buf { | |
| 7661 | + set_palette_pred(b.clone()); | |
| 7662 | + } | |
| 7402 | 7663 | y.reconstruct_rect( |
| 7403 | 7664 | px, |
| 7404 | 7665 | py, |
| @@ -7427,6 +7688,9 @@ fn decode_block_rect4( | ||
| 7427 | 7688 | plane_q_delta(plane).1, |
| 7428 | 7689 | tx_type, |
| 7429 | 7690 | ); |
| 7691 | + if let Some((ub, vb)) = &palette_uv_bufs { | |
| 7692 | + set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }); | |
| 7693 | + } | |
| 7430 | 7694 | buf.reconstruct_rect( |
| 7431 | 7695 | cpx, |
| 7432 | 7696 | cpy, |
| @@ -7451,6 +7715,10 @@ fn decode_block_rect4( | ||
| 7451 | 7715 | ); |
| 7452 | 7716 | neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); |
| 7453 | 7717 | neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); |
| 7718 | + record_strip_palette( | |
| 7719 | + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, | |
| 7720 | + pal_uv_colors, pal_last, | |
| 7721 | + ); | |
| 7454 | 7722 | if bw > bh { |
| 7455 | 7723 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| 7456 | 7724 | } else { |
| @@ -7458,6 +7726,9 @@ fn decode_block_rect4( | ||
| 7458 | 7726 | } |
| 7459 | 7727 | return Ok((mode, uv_predict_mode)); |
| 7460 | 7728 | }; |
| 7729 | + if let Some(b) = &palette_y_buf { | |
| 7730 | + set_palette_pred(b.clone()); | |
| 7731 | + } | |
| 7461 | 7732 | y.reconstruct_rect( |
| 7462 | 7733 | px, |
| 7463 | 7734 | py, |
| @@ -7472,6 +7743,9 @@ fn decode_block_rect4( | ||
| 7472 | 7743 | smooth_neighbor, |
| 7473 | 7744 | ); |
| 7474 | 7745 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 7746 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 7747 | + set_palette_pred(ub.clone()); | |
| 7748 | + } | |
| 7475 | 7749 | u.reconstruct_rect( |
| 7476 | 7750 | cpx, |
| 7477 | 7751 | cpy, |
| @@ -7485,6 +7759,9 @@ fn decode_block_rect4( | ||
| 7485 | 7759 | None, |
| 7486 | 7760 | smooth_neighbor_uv, |
| 7487 | 7761 | ); |
| 7762 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 7763 | + set_palette_pred(vb.clone()); | |
| 7764 | + } | |
| 7488 | 7765 | v.reconstruct_rect( |
| 7489 | 7766 | cpx, |
| 7490 | 7767 | cpy, |
| @@ -7501,6 +7778,10 @@ fn decode_block_rect4( | ||
| 7501 | 7778 | neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels.to_vec(), u_levels, v_levels]); |
| 7502 | 7779 | neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); |
| 7503 | 7780 | neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); |
| 7781 | + record_strip_palette( | |
| 7782 | + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 7783 | + pal_last, | |
| 7784 | + ); | |
| 7504 | 7785 | if bw > bh { |
| 7505 | 7786 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| 7506 | 7787 | } else { |
| @@ -7580,6 +7861,12 @@ fn decode_rect4_16( | ||
| 7580 | 7861 | } |
| 7581 | 7862 | let (above_mode, left_mode) = |
| 7582 | 7863 | neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode)); |
| 7864 | + // lane-kf900 r4: the strip's real palette ctx + colour cache (see | |
| 7865 | + // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode` | |
| 7866 | + // off CDF row 0 and every cache hit off an empty cache. | |
| 7867 | + let (palette_ctx, palette_cache) = | |
| 7868 | + neighbours.palette_ctx_and_cache_mi(at16, lmi.0); | |
| 7869 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(at16, lmi.0); | |
| 7583 | 7870 | let ( |
| 7584 | 7871 | skip, |
| 7585 | 7872 | mode, |
| @@ -7602,16 +7889,26 @@ fn decode_rect4_16( | ||
| 7602 | 7889 | enable_filter_intra, |
| 7603 | 7890 | neighbours.skip_txfm_ctx(lmi.0, lmi.1), |
| 7604 | 7891 | allow_screen_content_tools, |
| 7605 | - None, | |
| 7606 | - &[], | |
| 7892 | + Some((palette_ctx, &palette_cache)), | |
| 7893 | + &palette_uv_cache, | |
| 7607 | 7894 | lmi.0, |
| 7608 | 7895 | lmi.1, |
| 7609 | 7896 | )?; |
| 7610 | 7897 | if palette_y.is_some() || palette_uv.is_some() { |
| 7611 | - return Err(unsupported( | |
| 7612 | - "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | |
| 7613 | - )); | |
| 7614 | - } | |
| 7898 | + RECT4_PALETTE_HITS.with(|h| h.set(h.get() + 1)); | |
| 7899 | + } | |
| 7900 | + // The colour-index map through the base colours IS the prediction. | |
| 7901 | + // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one | |
| 7902 | + // chroma transform this closing strip codes. | |
| 7903 | + let palette_y_buf: Option<Vec<u16>> = palette_y | |
| 7904 | + .as_ref() | |
| 7905 | + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); | |
| 7906 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| { | |
| 7907 | + ( | |
| 7908 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | |
| 7909 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | |
| 7910 | + ) | |
| 7911 | + }); | |
| 7615 | 7912 | let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); |
| 7616 | 7913 | if smooth_neighbor { |
| 7617 | 7914 | SMOOTH_LUMA_HITS.with(|h| h.set(h.get() + 1)); |
| @@ -7659,6 +7956,15 @@ fn decode_rect4_16( | ||
| 7659 | 7956 | tx_h, |
| 7660 | 7957 | reach, |
| 7661 | 7958 | ); |
| 7959 | + if let Some(b) = &palette_y_buf { | |
| 7960 | + let tu_buf: Vec<u16> = (0..tx_h) | |
| 7961 | + .flat_map(|i| { | |
| 7962 | + let base = (tu_row * tx_h + i) * bw + tu_col * tx_w; | |
| 7963 | + b[base..base + tx_w].iter().copied() | |
| 7964 | + }) | |
| 7965 | + .collect(); | |
| 7966 | + set_palette_pred(tu_buf); | |
| 7967 | + } | |
| 7662 | 7968 | if skip { |
| 7663 | 7969 | y.reconstruct_rect( |
| 7664 | 7970 | tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu, |
| @@ -7742,6 +8048,9 @@ fn decode_rect4_16( | ||
| 7742 | 8048 | } else { |
| 7743 | 8049 | let levels = if skip { |
| 7744 | 8050 | let zeros = vec![0i32; bw * bh]; |
| 8051 | + if let Some(b) = &palette_y_buf { | |
| 8052 | + set_palette_pred(b.clone()); | |
| 8053 | + } | |
| 7745 | 8054 | y.reconstruct_rect( |
| 7746 | 8055 | px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra, |
| 7747 | 8056 | smooth_neighbor, |
| @@ -7778,6 +8087,9 @@ fn decode_rect4_16( | ||
| 7778 | 8087 | plane_q_delta(0).1, |
| 7779 | 8088 | tx_type, |
| 7780 | 8089 | ); |
| 8090 | + if let Some(b) = &palette_y_buf { | |
| 8091 | + set_palette_pred(b.clone()); | |
| 8092 | + } | |
| 7781 | 8093 | y.reconstruct_rect( |
| 7782 | 8094 | px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra, |
| 7783 | 8095 | smooth_neighbor, |
| @@ -7831,7 +8143,8 @@ fn decode_rect4_16( | ||
| 7831 | 8143 | // directional chroma strip, moving 4 samples by 1. |
| 7832 | 8144 | let smooth_neighbor_uv = |
| 7833 | 8145 | neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c); |
| 7834 | - if smooth_neighbor_uv != neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c) { | |
| 8146 | + if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c) | |
| 8147 | + { | |
| 7835 | 8148 | RECT4_16_UV_PAIR_FILT_HITS.with(|h| h.set(h.get() + 1)); |
| 7836 | 8149 | } |
| 7837 | 8150 | let (u_levels, v_levels) = if skip { |
| @@ -7846,6 +8159,9 @@ fn decode_rect4_16( | ||
| 7846 | 8159 | CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); |
| 7847 | 8160 | } |
| 7848 | 8161 | for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] { |
| 8162 | + if let Some((ub, vb)) = &palette_uv_bufs { | |
| 8163 | + set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }); | |
| 8164 | + } | |
| 7849 | 8165 | buf.reconstruct_rect( |
| 7850 | 8166 | cpx, |
| 7851 | 8167 | cpy, |
| @@ -7901,6 +8217,9 @@ fn decode_rect4_16( | ||
| 7901 | 8217 | plane_q_delta(plane).1, |
| 7902 | 8218 | tx_type, |
| 7903 | 8219 | ); |
| 8220 | + if let Some((ub, vb)) = &palette_uv_bufs { | |
| 8221 | + set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }); | |
| 8222 | + } | |
| 7904 | 8223 | buf.reconstruct_rect( |
| 7905 | 8224 | cpx, |
| 7906 | 8225 | cpy, |
| @@ -7951,6 +8270,14 @@ fn decode_rect4_16( | ||
| 7951 | 8270 | } else { |
| 7952 | 8271 | RECT4_16_VERT_HITS.with(|h| h.set(h.get() + 1)); |
| 7953 | 8272 | } |
| 8273 | + let (pal_y_size, pal_y_colors) = | |
| 8274 | + palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | |
| 8275 | + let (pal_uv_size, pal_uv_colors) = | |
| 8276 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | |
| 8277 | + record_strip_palette( | |
| 8278 | + neighbours, at16, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 8279 | + i == 3, | |
| 8280 | + ); | |
| 7954 | 8281 | last_mode = mode; |
| 7955 | 8282 | prev = Some((lmi, mode)); |
| 7956 | 8283 | } |
| @@ -8534,6 +8861,13 @@ fn read_intra_mode( | ||
| 8534 | 8861 | // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for |
| 8535 | 8862 | // line against the instrumented aomdec, not just `tell()`. |
| 8536 | 8863 | let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); |
| 8864 | + if ec_istep { | |
| 8865 | + // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line | |
| 8866 | + // (decodemv.c:818), printed at the same point: before the first | |
| 8867 | + // mode-info symbol of the block, so a cross-decoder range ladder can | |
| 8868 | + // be keyed on the BLOCK, not just on the symbol sequence. | |
| 8869 | + eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sq side={side} rng={}", dec.debug_state().0); | |
| 8870 | + } | |
| 8537 | 8871 | macro_rules! istep { |
| 8538 | 8872 | ($name:literal, $val:expr) => { |
| 8539 | 8873 | if ec_istep { |
| @@ -10433,7 +10767,17 @@ fn decode_leaf8( | ||
| 10433 | 10767 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10434 | 10768 | } |
| 10435 | 10769 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10436 | - neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); | |
| 10770 | + // lane-kf900 r1: the leaf's own RESOLVED transform size, never the literal | |
| 10771 | + // block side. libaom calls `set_txfm_ctxs(mbmi->tx_size, ..., skip_txfm && | |
| 10772 | + // is_inter_block(mbmi), xd)` (decodemv.c) -- for an INTRA block that skip | |
| 10773 | + // term is always 0, so a skipped 8x8 leaf whose `tx_depth` resolved to | |
| 10774 | + // TX_4X4 still publishes 4 to the next block's `get_tx_size_context` | |
| 10775 | + // (pred_common.h:342). Writing 8 here made the 8x16 strip below the leaf | |
| 10776 | + // read `tx_size_cat1` row 2 where libaom reads row 1 -- same alphabet, | |
| 10777 | + // wrong CDF row, so the msac range diverged mid-frame with no refusal | |
| 10778 | + // (class `wrong-alphabet-same-value`; the ReelB key frame at | |
| 10779 | + // -ss 900, first bad luma sample row 186 col 1803). | |
| 10780 | + neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0); | |
| 10437 | 10781 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| 10438 | 10782 | Ok(mode) |
| 10439 | 10783 | } |
| @@ -10465,6 +10809,9 @@ fn read_intra_mode_sub8( | ||
| 10465 | 10809 | mi_c: usize, |
| 10466 | 10810 | ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> { |
| 10467 | 10811 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 10812 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | |
| 10813 | + eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); | |
| 10814 | + } | |
| 10468 | 10815 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 10469 | 10816 | if trace { |
| 10470 | 10817 | eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -2
| @@ -34,7 +34,6 @@ const REFUSALS: &[&str] = &[ | ||
| 34 | 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 35 | 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 36 | 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 37 | - "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | |
| 38 | 37 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 39 | 38 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 40 | 39 | "a 32x32 partition type this decoder does not code (value={part32})", |
| @@ -45,10 +44,10 @@ const REFUSALS: &[&str] = &[ | ||
| 45 | 44 | "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", |
| 46 | 45 | "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", |
| 47 | 46 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", |
| 48 | - "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", | |
| 49 | 47 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
| 50 | 48 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 51 | 49 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 50 | + "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", | |
| 52 | 51 | "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", |
| 53 | 52 | "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", |
| 54 | 53 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", |
crates/ec-av1/src/stream.rsmodified+643 -0
| @@ -81,6 +81,11 @@ pub fn vartx_rect_leaf_hits() -> [usize; 2] { | ||
| 81 | 81 | crate::decode::vartx_rect_leaf_hits() |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | +/// How many rect intra strips read the `use_intrabc` symbol on the last decode. | |
| 85 | +pub fn rect_intrabc_reads() -> usize { | |
| 86 | + crate::decode::rect_intrabc_reads() | |
| 87 | +} | |
| 88 | + | |
| 84 | 89 | pub fn rect4_32_counters() -> (usize, usize, usize) { |
| 85 | 90 | ( |
| 86 | 91 | crate::decode::rect4_32_horz_hits(), |
| @@ -2579,6 +2584,541 @@ mod tests { | ||
| 2579 | 2584 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); |
| 2580 | 2585 | } |
| 2581 | 2586 | |
| 2587 | + /// lane-kf900 r3: the palette colour reader at BOTH bit depths. | |
| 2588 | + /// | |
| 2589 | + /// `read_palette_colors_y`/`_uv` (decode.rs, mirroring `decodemv.c:478` | |
| 2590 | + /// and `:509`) size every raw literal they read by the sequence's | |
| 2591 | + /// `bit_depth`: the first colour is `bit_depth` bits, `min_bits` is | |
| 2592 | + /// `bit_depth - 3` (Y/U) or `bit_depth - 4` (V), `range` starts at | |
| 2593 | + /// `1 << bit_depth`, and the clamp/wrap bound is `(1 << bit_depth) - 1`. | |
| 2594 | + /// Ours hardcoded 8, so every 10-bit palette block read TWO BITS TOO FEW | |
| 2595 | + /// per transmitted colour and silently decoded the rest of the tile from | |
| 2596 | + /// the wrong bit position. | |
| 2597 | + /// | |
| 2598 | + /// It was silent because raw literals are EQUIPROBABLE: at the ranges | |
| 2599 | + /// this content reaches an equiprobable read maps the msac range onto | |
| 2600 | + /// itself (62728 -> 31364 -> renormalised 62728), so a cross-decoder | |
| 2601 | + /// RANGE ladder stays bit-identical straight through the miscount and | |
| 2602 | + /// only the decoded VALUE moves. Pinned on a 256x192 10-bit | |
| 2603 | + /// `--cq-level=59` stream whose first block is a 32x16 palette: aomdec's | |
| 2604 | + /// `EC_PAL` ladder and ours agreed on every range and disagreed on the | |
| 2605 | + /// very first colour index (0 vs 1); after the fix all 1024 `EC_PAL` | |
| 2606 | + /// lines of that block match aomdec line for line. | |
| 2607 | + /// | |
| 2608 | + /// The recipe is the 8-bit `..._with_palette_y_...` gate's, with the | |
| 2609 | + /// depth as the only variable, so a failure here is the depth and | |
| 2610 | + /// nothing else. HARD-asserts [`decode::palette_hits`] moved on each arm | |
| 2611 | + /// (a stream with no real palette block would prove nothing) and | |
| 2612 | + /// compares all three planes against ffmpeg's decode of the same bytes. | |
| 2613 | + #[test] | |
| 2614 | + fn a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit() { | |
| 2615 | + const NAME: &str = "a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit"; | |
| 2616 | + if !have_ffmpeg() { | |
| 2617 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 2618 | + return; | |
| 2619 | + } | |
| 2620 | + if !have_aomenc() { | |
| 2621 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 2622 | + return; | |
| 2623 | + } | |
| 2624 | + let (width, height) = (64usize, 64usize); | |
| 2625 | + for depth in [8usize, 10] { | |
| 2626 | + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 2627 | + let render = || { | |
| 2628 | + Command::new("ffmpeg") | |
| 2629 | + .args([ | |
| 2630 | + "-v", "error", | |
| 2631 | + "-f", "lavfi", | |
| 2632 | + "-i", "smptebars=size=64x64:rate=25", | |
| 2633 | + "-vf", "hue=s=0", | |
| 2634 | + "-pix_fmt", pix_fmt, | |
| 2635 | + "-strict", "-1", | |
| 2636 | + "-t", "0.04", | |
| 2637 | + "-f", "yuv4mpegpipe", | |
| 2638 | + "-", | |
| 2639 | + ]) | |
| 2640 | + .stdin(Stdio::null()) | |
| 2641 | + .stdout(Stdio::piped()) | |
| 2642 | + .stderr(Stdio::piped()) | |
| 2643 | + .output() | |
| 2644 | + .expect("ffmpeg failed to run") | |
| 2645 | + .stdout | |
| 2646 | + }; | |
| 2647 | + let y4m_a = render(); | |
| 2648 | + let y4m_b = render(); | |
| 2649 | + assert_eq!( | |
| 2650 | + y4m_a, y4m_b, | |
| 2651 | + "{NAME}: smptebars must render byte-identical across two runs at {depth}-bit" | |
| 2652 | + ); | |
| 2653 | + let y4m = y4m_a; | |
| 2654 | + let depth_arg = format!("--bit-depth={depth}"); | |
| 2655 | + let input_depth_arg = format!("--input-bit-depth={depth}"); | |
| 2656 | + let mut child = Command::new(aomenc_path()) | |
| 2657 | + .args([ | |
| 2658 | + "--codec=av1", | |
| 2659 | + "--passes=1", | |
| 2660 | + "--end-usage=q", | |
| 2661 | + "--cq-level=30", | |
| 2662 | + "--cpu-used=0", | |
| 2663 | + "--threads=1", | |
| 2664 | + "--row-mt=0", | |
| 2665 | + "--sb-size=64", | |
| 2666 | + "--tune-content=screen", | |
| 2667 | + "--enable-palette=1", | |
| 2668 | + "--enable-intrabc=0", | |
| 2669 | + "--enable-rect-partitions=0", | |
| 2670 | + "--enable-ab-partitions=0", | |
| 2671 | + "--enable-1to4-partitions=0", | |
| 2672 | + "--min-partition-size=32", | |
| 2673 | + "--max-partition-size=32", | |
| 2674 | + "--enable-filter-intra=0", | |
| 2675 | + "--enable-smooth-intra=0", | |
| 2676 | + "--enable-paeth-intra=0", | |
| 2677 | + "--enable-directional-intra=0", | |
| 2678 | + "--enable-angle-delta=0", | |
| 2679 | + "--enable-cfl-intra=0", | |
| 2680 | + "--enable-cdef=0", | |
| 2681 | + "--enable-restoration=0", | |
| 2682 | + "--enable-tx-size-search=0", | |
| 2683 | + "--loopfilter-control=0", | |
| 2684 | + "--limit=1", | |
| 2685 | + ]) | |
| 2686 | + // Per-arm overrides go AFTER the base recipe: aomenc keeps the | |
| 2687 | + // LAST occurrence of a repeated flag. | |
| 2688 | + .args([&depth_arg, &input_depth_arg]) | |
| 2689 | + .args(["--obu", "-o", "-", "-"]) | |
| 2690 | + .stdin(Stdio::piped()) | |
| 2691 | + .stdout(Stdio::piped()) | |
| 2692 | + .stderr(Stdio::piped()) | |
| 2693 | + .spawn() | |
| 2694 | + .expect("aomenc failed to start"); | |
| 2695 | + child | |
| 2696 | + .stdin | |
| 2697 | + .take() | |
| 2698 | + .expect("aomenc stdin") | |
| 2699 | + .write_all(&y4m) | |
| 2700 | + .expect("writing y4m to aomenc"); | |
| 2701 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 2702 | + assert!( | |
| 2703 | + out.status.success(), | |
| 2704 | + "{NAME}: aomenc refused the {depth}-bit fixture: {}", | |
| 2705 | + String::from_utf8_lossy(&out.stderr) | |
| 2706 | + ); | |
| 2707 | + let stream = out.stdout; | |
| 2708 | + let before = decode::palette_hits(); | |
| 2709 | + let frames = match decode_stream(&stream) { | |
| 2710 | + Ok(frames) => frames, | |
| 2711 | + Err(e) => panic!("{NAME}: decode_stream refused the {depth}-bit stream: {e}"), | |
| 2712 | + }; | |
| 2713 | + assert!( | |
| 2714 | + decode::palette_hits() > before, | |
| 2715 | + "{NAME}: no real palette block at {depth}-bit -- gate is vacuous" | |
| 2716 | + ); | |
| 2717 | + let ffmpeg_frames = if depth == 10 { | |
| 2718 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | |
| 2719 | + } else { | |
| 2720 | + ffmpeg_decode_sequence(&stream, width, height, 1) | |
| 2721 | + }; | |
| 2722 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma at {depth}-bit"); | |
| 2723 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U at {depth}-bit"); | |
| 2724 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V at {depth}-bit"); | |
| 2725 | + } | |
| 2726 | + } | |
| 2727 | + | |
| 2728 | + /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. | |
| 2729 | + /// | |
| 2730 | + /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, | |
| 2731 | + /// `read_intra_frame_mode_info`): on an intra frame whose header set | |
| 2732 | + /// `allow_intrabc`, EVERY intra block reads a `use_intrabc` symbol right | |
| 2733 | + /// after `skip`/`cdef`/`delta_q` and before `mbmi->mode`. There is no | |
| 2734 | + /// block-shape term, so rect strips read it exactly like square leaves -- | |
| 2735 | + /// `read_intra_mode_rect` never did, and the arithmetic decoder desynced | |
| 2736 | + /// at the FIRST symbol of the first rect block of every | |
| 2737 | + /// `--tune-content=screen` key frame (measured: `testsrc2` 256x192 cq59 | |
| 2738 | + /// 8-bit decoded "OK" with all 49152 luma samples wrong). | |
| 2739 | + /// | |
| 2740 | + /// Arm 0 is that recipe at cq50 without palette: its rect strips really do | |
| 2741 | + /// use intrabc, which this decoder cannot reconstruct, so it must stop on | |
| 2742 | + /// the NAMED refusal instead of emitting a wrong frame -- and it must have | |
| 2743 | + /// read the symbol to get there. | |
| 2744 | + /// Arm 1 is the same recipe without palette and without tx-size search -- | |
| 2745 | + /// it decodes the whole frame, reading the symbol dozens of times. | |
| 2746 | + /// Arm 2 is a screen-tools key frame whose header does NOT set | |
| 2747 | + /// `allow_intrabc` (cq63): it stays pixel-exact, proving the new read is | |
| 2748 | + /// not taken when libaom does not write it. | |
| 2749 | + /// | |
| 2750 | + /// PIXEL RESIDUE (open, lane-kf900 r5): arm 1's frame is entropy-exact | |
| 2751 | + /// against the instrumented aomdec for 429 mode-ladder elements and then | |
| 2752 | + /// diverges inside the DV read of a SQUARE intrabc block at mi(32,44), so | |
| 2753 | + /// its pixels are not compared here. That is a separate defect in | |
| 2754 | + /// `read_intrabc_dv`, not in the read this gate covers. | |
| 2755 | + #[test] | |
| 2756 | + fn a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips() { | |
| 2757 | + const NAME: &str = "a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips"; | |
| 2758 | + if !have_ffmpeg() { | |
| 2759 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 2760 | + return; | |
| 2761 | + } | |
| 2762 | + if !have_aomenc() { | |
| 2763 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 2764 | + return; | |
| 2765 | + } | |
| 2766 | + let (width, height) = (256usize, 192usize); | |
| 2767 | + // (arm, source, per-arm overrides AFTER the base recipe, expect_refusal, | |
| 2768 | + // must_read_use_intrabc) | |
| 2769 | + let arms: [(&str, &str, &[&str], bool, bool); 3] = [ | |
| 2770 | + ( | |
| 2771 | + "testsrc2-screen-nopalette-cq50", | |
| 2772 | + "testsrc2=s=256x192:r=25", | |
| 2773 | + &["--cq-level=50", "--enable-palette=0", "--enable-tx-size-search=0"], | |
| 2774 | + true, | |
| 2775 | + true, | |
| 2776 | + ), | |
| 2777 | + ( | |
| 2778 | + "smptebars-screen-nopalette-cq45", | |
| 2779 | + "smptebars=size=256x192:rate=25", | |
| 2780 | + &["--cq-level=45", "--enable-palette=0", "--enable-tx-size-search=0"], | |
| 2781 | + false, | |
| 2782 | + true, | |
| 2783 | + ), | |
| 2784 | + ( | |
| 2785 | + "testsrc2-screen-nopalette-cq63", | |
| 2786 | + "testsrc2=s=256x192:r=25", | |
| 2787 | + &["--cq-level=63", "--enable-palette=0", "--enable-tx-size-search=1"], | |
| 2788 | + false, | |
| 2789 | + false, | |
| 2790 | + ), | |
| 2791 | + ]; | |
| 2792 | + let (mut reads_total, mut refused, mut frames_compared) = (0usize, 0u32, 0usize); | |
| 2793 | + for (arm, src, extra, expect_refusal, must_read) in &arms { | |
| 2794 | + let render = || { | |
| 2795 | + let out = Command::new("ffmpeg") | |
| 2796 | + .args([ | |
| 2797 | + "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.2", "-pix_fmt", | |
| 2798 | + "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 2799 | + ]) | |
| 2800 | + .stdin(Stdio::null()) | |
| 2801 | + .stdout(Stdio::piped()) | |
| 2802 | + .stderr(Stdio::piped()) | |
| 2803 | + .output() | |
| 2804 | + .expect("ffmpeg failed to run"); | |
| 2805 | + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | |
| 2806 | + out.stdout | |
| 2807 | + }; | |
| 2808 | + let y4m_a = render(); | |
| 2809 | + let y4m_b = render(); | |
| 2810 | + assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs"); | |
| 2811 | + let y4m = y4m_a; | |
| 2812 | + let mut child = Command::new(aomenc_path()) | |
| 2813 | + .args([ | |
| 2814 | + "--codec=av1", | |
| 2815 | + "--bit-depth=8", | |
| 2816 | + "--input-bit-depth=8", | |
| 2817 | + "--passes=1", | |
| 2818 | + "--end-usage=q", | |
| 2819 | + "--cpu-used=0", | |
| 2820 | + "--lag-in-frames=0", | |
| 2821 | + "--kf-max-dist=1", | |
| 2822 | + "--limit=1", | |
| 2823 | + "--threads=1", | |
| 2824 | + "--tile-columns=0", | |
| 2825 | + "--enable-rect-partitions=1", | |
| 2826 | + "--enable-1to4-partitions=1", | |
| 2827 | + "--min-partition-size=8", | |
| 2828 | + "--max-partition-size=32", | |
| 2829 | + "--sb-size=64", | |
| 2830 | + // `allow_screen_content_tools` (and with it the frame | |
| 2831 | + // header's `allow_intrabc` bit) comes from here. | |
| 2832 | + "--tune-content=screen", | |
| 2833 | + ]) | |
| 2834 | + // aomenc keeps the LAST occurrence of a repeated flag. | |
| 2835 | + .args(*extra) | |
| 2836 | + .args(["--obu", "-o", "-", "-"]) | |
| 2837 | + .stdin(Stdio::piped()) | |
| 2838 | + .stdout(Stdio::piped()) | |
| 2839 | + .stderr(Stdio::piped()) | |
| 2840 | + .spawn() | |
| 2841 | + .expect("aomenc failed to start"); | |
| 2842 | + child | |
| 2843 | + .stdin | |
| 2844 | + .take() | |
| 2845 | + .expect("aomenc stdin") | |
| 2846 | + .write_all(&y4m) | |
| 2847 | + .or_else(|e| match e.kind() { | |
| 2848 | + std::io::ErrorKind::BrokenPipe => Ok(()), | |
| 2849 | + _ => Err(e), | |
| 2850 | + }) | |
| 2851 | + .expect("writing y4m to aomenc"); | |
| 2852 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 2853 | + assert!( | |
| 2854 | + out.status.success(), | |
| 2855 | + "{NAME}: aomenc refused {arm}: {}", | |
| 2856 | + String::from_utf8_lossy(&out.stderr) | |
| 2857 | + ); | |
| 2858 | + let stream = out.stdout; | |
| 2859 | + decode::reset_rect_intrabc_reads(); | |
| 2860 | + let decoded = decode_stream(&stream); | |
| 2861 | + let reads = decode::rect_intrabc_reads(); | |
| 2862 | + reads_total += reads; | |
| 2863 | + if *must_read { | |
| 2864 | + assert!( | |
| 2865 | + reads > 0, | |
| 2866 | + "{NAME}: {arm} read no use_intrabc symbol on a rect strip -- the \ | |
| 2867 | + arm no longer exercises the fix (allow_intrabc not set?)" | |
| 2868 | + ); | |
| 2869 | + } | |
| 2870 | + match decoded { | |
| 2871 | + Ok(frames) => { | |
| 2872 | + assert!( | |
| 2873 | + !*expect_refusal, | |
| 2874 | + "{NAME}: {arm} decoded a frame whose rect strips use intrabc -- \ | |
| 2875 | + reconstruction is not ported, it must refuse by name" | |
| 2876 | + ); | |
| 2877 | + assert!(!frames.is_empty(), "{NAME}: {arm} decoded no frame"); | |
| 2878 | + if *must_read { | |
| 2879 | + // Arm 1: entropy coverage only (see PIXEL RESIDUE above). | |
| 2880 | + eprintln!("{NAME}: {arm} decoded {} frame(s), {reads} rect use_intrabc reads", frames.len()); | |
| 2881 | + continue; | |
| 2882 | + } | |
| 2883 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | |
| 2884 | + assert_eq!(frames.len(), ffmpeg_frames.len(), "{NAME}: {arm} frame count"); | |
| 2885 | + for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() { | |
| 2886 | + assert_eq!(ours.y, theirs.y, "{NAME}: {arm} luma, frame {i}"); | |
| 2887 | + assert_eq!(ours.u, theirs.u, "{NAME}: {arm} U, frame {i}"); | |
| 2888 | + assert_eq!(ours.v, theirs.v, "{NAME}: {arm} V, frame {i}"); | |
| 2889 | + frames_compared += 1; | |
| 2890 | + } | |
| 2891 | + } | |
| 2892 | + Err(e) => { | |
| 2893 | + let msg = e.to_string(); | |
| 2894 | + assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); | |
| 2895 | + assert!( | |
| 2896 | + *expect_refusal, | |
| 2897 | + "{NAME}: {arm} was expected to decode, it refused: {e}" | |
| 2898 | + ); | |
| 2899 | + assert!( | |
| 2900 | + msg.contains("intra block copy") || msg.contains("intrabc"), | |
| 2901 | + "{NAME}: {arm} refused for an unrelated reason: {e}" | |
| 2902 | + ); | |
| 2903 | + eprintln!("{NAME}: {arm} REFUSED (expected): {e}"); | |
| 2904 | + refused += 1; | |
| 2905 | + } | |
| 2906 | + } | |
| 2907 | + } | |
| 2908 | + eprintln!( | |
| 2909 | + "{NAME}: {reads_total} rect-strip use_intrabc symbol(s) read, \ | |
| 2910 | + {refused} refused by name, {frames_compared} frames compared pixel-exact" | |
| 2911 | + ); | |
| 2912 | + assert!(reads_total > 0, "{NAME}: gate is vacuous -- no arm read the symbol"); | |
| 2913 | + assert_eq!(refused, 1, "{NAME}: expected exactly one named intrabc refusal"); | |
| 2914 | + assert!(frames_compared > 0, "{NAME}: no frame was compared pixel-exact"); | |
| 2915 | + } | |
| 2916 | + | |
| 2917 | + /// lane-kf900 r4, the gate for the two lifted palette refusals ("a 1:4 | |
| 2918 | + /// rect strip that actually uses a palette (reconstruction is not ported | |
| 2919 | + /// at this shape)" and "a palette block on a HORZ/VERT intra strip below | |
| 2920 | + /// 16x16 (reconstruction not ported)"): real `aomenc` streams that put a | |
| 2921 | + /// palette on a RECT strip, decoded whole-frame pixel-exact against | |
| 2922 | + /// ffmpeg's own decode of the identical bytes, at 8 AND 10 bit. | |
| 2923 | + /// | |
| 2924 | + /// Arm 0 is the stream lane-kf900 r3 pinned and stopped on -- `testsrc2` | |
| 2925 | + /// 256x192, `--cq-level=59 --cpu-used=0 --min-partition-size=8 | |
| 2926 | + /// --enable-rect-partitions=1 --enable-tx-size-search=1`, md5 | |
| 2927 | + /// `e5f033d8fe34e4418d8cca3ac9d2b595` at 10 bit. Arms 1-2 force the shape | |
| 2928 | + /// on screen-like content with `--tune-content=screen --enable-palette=1 | |
| 2929 | + /// --enable-1to4-partitions=1`. | |
| 2930 | + /// | |
| 2931 | + /// An attempt whose decode never hit a rect-strip palette block proves | |
| 2932 | + /// nothing about the lift, so it is counted OUT OF SCOPE rather than | |
| 2933 | + /// silently passing -- but a mismatch on one is still a failure | |
| 2934 | + /// (`out_of_scope_mismatch == 0`), and at least one attempt must fire the | |
| 2935 | + /// counter or the gate is vacuous. | |
| 2936 | + #[test] | |
| 2937 | + fn a_real_aomenc_rect_strip_palette_decodes_pixel_exact() { | |
| 2938 | + const NAME: &str = "a_real_aomenc_rect_strip_palette_decodes_pixel_exact"; | |
| 2939 | + if !have_ffmpeg() { | |
| 2940 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 2941 | + return; | |
| 2942 | + } | |
| 2943 | + if !have_aomenc() { | |
| 2944 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 2945 | + return; | |
| 2946 | + } | |
| 2947 | + let (width, height) = (256usize, 192usize); | |
| 2948 | + let screen: &[&str] = &[ | |
| 2949 | + "--tune-content=screen", | |
| 2950 | + "--enable-palette=1", | |
| 2951 | + "--enable-1to4-partitions=1", | |
| 2952 | + "--min-partition-size=8", | |
| 2953 | + ]; | |
| 2954 | + let arms: [(&str, String, &[&str]); 3] = [ | |
| 2955 | + ("testsrc2-pinned", "testsrc2=s=256x192:r=25".to_string(), &[]), | |
| 2956 | + ("testsrc2-screen", "testsrc2=s=256x192:r=25".to_string(), screen), | |
| 2957 | + ("smptebars-screen", "smptebars=size=256x192:rate=25".to_string(), screen), | |
| 2958 | + ]; | |
| 2959 | + let (mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32, 0u32); | |
| 2960 | + let mut refused = 0u32; | |
| 2961 | + let mut fired_at_depth = [0u32; 2]; | |
| 2962 | + let mut frames_compared = 0usize; | |
| 2963 | + for (arm, src, extra) in &arms { | |
| 2964 | + for depth in [8usize, 10] { | |
| 2965 | + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 2966 | + let render = || { | |
| 2967 | + let out = Command::new("ffmpeg") | |
| 2968 | + .args([ | |
| 2969 | + "-v", "error", "-f", "lavfi", "-i", src.as_str(), "-t", "0.2", | |
| 2970 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | |
| 2971 | + ]) | |
| 2972 | + .stdin(Stdio::null()) | |
| 2973 | + .stdout(Stdio::piped()) | |
| 2974 | + .stderr(Stdio::piped()) | |
| 2975 | + .output() | |
| 2976 | + .expect("ffmpeg failed to run"); | |
| 2977 | + assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | |
| 2978 | + out.stdout | |
| 2979 | + }; | |
| 2980 | + let y4m_a = render(); | |
| 2981 | + let y4m_b = render(); | |
| 2982 | + assert_eq!( | |
| 2983 | + y4m_a, y4m_b, | |
| 2984 | + "{NAME}: {arm} must render byte-identical across two runs at {depth}-bit" | |
| 2985 | + ); | |
| 2986 | + let y4m = y4m_a; | |
| 2987 | + let depth_arg = format!("--bit-depth={depth}"); | |
| 2988 | + let in_depth_arg = format!("--input-bit-depth={depth}"); | |
| 2989 | + let mut child = Command::new(aomenc_path()) | |
| 2990 | + .args(["--codec=av1"]) | |
| 2991 | + .args([&depth_arg, &in_depth_arg]) | |
| 2992 | + .args([ | |
| 2993 | + "--passes=1", | |
| 2994 | + "--end-usage=q", | |
| 2995 | + "--cq-level=59", | |
| 2996 | + "--cpu-used=0", | |
| 2997 | + "--lag-in-frames=0", | |
| 2998 | + "--kf-max-dist=1", | |
| 2999 | + "--limit=1", | |
| 3000 | + "--threads=1", | |
| 3001 | + "--tile-columns=0", | |
| 3002 | + "--enable-tx-size-search=1", | |
| 3003 | + "--min-partition-size=8", | |
| 3004 | + "--enable-rect-partitions=1", | |
| 3005 | + ]) | |
| 3006 | + // Per-arm overrides go AFTER the base recipe: aomenc keeps | |
| 3007 | + // the LAST occurrence of a repeated flag. | |
| 3008 | + .args(*extra) | |
| 3009 | + // The 8-bit twin of the pinned recipe picks a 128-root | |
| 3010 | + // HORZ partition, which this decoder still refuses by name | |
| 3011 | + // ("a 128x128 superblock HORZ/VERT or AB partition") -- | |
| 3012 | + // an open refusal of another lane, unrelated to palette. | |
| 3013 | + // Pinning the superblock to 64 keeps the 8-bit arm on the | |
| 3014 | + // shape this gate is about; the 10-bit arms are the | |
| 3015 | + // untouched pinned recipe. | |
| 3016 | + .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] }) | |
| 3017 | + .args(["--obu", "-o", "-", "-"]) | |
| 3018 | + .stdin(Stdio::piped()) | |
| 3019 | + .stdout(Stdio::piped()) | |
| 3020 | + .stderr(Stdio::piped()) | |
| 3021 | + .spawn() | |
| 3022 | + .expect("aomenc failed to start"); | |
| 3023 | + child | |
| 3024 | + .stdin | |
| 3025 | + .take() | |
| 3026 | + .expect("aomenc stdin") | |
| 3027 | + .write_all(&y4m) | |
| 3028 | + .or_else(|e| match e.kind() { | |
| 3029 | + // aomenc rejecting the input closes the pipe before we | |
| 3030 | + // finish writing; its own stderr below is the report. | |
| 3031 | + std::io::ErrorKind::BrokenPipe => Ok(()), | |
| 3032 | + _ => Err(e), | |
| 3033 | + }) | |
| 3034 | + .expect("writing y4m to aomenc"); | |
| 3035 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 3036 | + assert!( | |
| 3037 | + out.status.success(), | |
| 3038 | + "{NAME}: aomenc refused {arm} at {depth}-bit: {}", | |
| 3039 | + String::from_utf8_lossy(&out.stderr) | |
| 3040 | + ); | |
| 3041 | + let stream = out.stdout; | |
| 3042 | + let before = decode::rect4_palette_hits(); | |
| 3043 | + let frames = match decode_stream(&stream) { | |
| 3044 | + Ok(frames) => frames, | |
| 3045 | + // A NAMED refusal is another lane's open shape (here: a | |
| 3046 | + // palette on an 8x8 SQUARE leaf, still out of scope), never | |
| 3047 | + // a pass -- the attempt is counted out of scope and the | |
| 3048 | + // per-depth firing assert below keeps the gate honest. | |
| 3049 | + Err(e) if e.to_string().contains("unsupported") => { | |
| 3050 | + eprintln!("{NAME}: {arm} {depth}-bit REFUSED: {e}"); | |
| 3051 | + refused += 1; | |
| 3052 | + continue; | |
| 3053 | + } | |
| 3054 | + Err(e) => panic!("{NAME}: decode failed on {arm} at {depth}-bit: {e}"), | |
| 3055 | + }; | |
| 3056 | + let fired = decode::rect4_palette_hits() - before; | |
| 3057 | + let ffmpeg_frames = if depth == 10 { | |
| 3058 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | |
| 3059 | + } else { | |
| 3060 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | |
| 3061 | + }; | |
| 3062 | + assert_eq!( | |
| 3063 | + frames.len(), | |
| 3064 | + ffmpeg_frames.len(), | |
| 3065 | + "{NAME}: {arm} at {depth}-bit -- frame count" | |
| 3066 | + ); | |
| 3067 | + assert!(!frames.is_empty(), "{NAME}: {arm} at {depth}-bit decoded no frame"); | |
| 3068 | + // EVERY decode-order frame, all three planes. | |
| 3069 | + let mut exact = true; | |
| 3070 | + for (i, (ours, theirs)) in frames.iter().zip(ffmpeg_frames.iter()).enumerate() { | |
| 3071 | + if ours.y != theirs.y || ours.u != theirs.u || ours.v != theirs.v { | |
| 3072 | + exact = false; | |
| 3073 | + eprintln!("{NAME}: {arm} {depth}-bit frame {i} differs"); | |
| 3074 | + } | |
| 3075 | + frames_compared += 1; | |
| 3076 | + } | |
| 3077 | + if fired > 0 { | |
| 3078 | + fired_arms += 1; | |
| 3079 | + fired_at_depth[usize::from(depth == 10)] += 1; | |
| 3080 | + assert!( | |
| 3081 | + exact, | |
| 3082 | + "{NAME}: {arm} at {depth}-bit has {fired} rect-strip palette block(s) \ | |
| 3083 | + and does NOT decode pixel-exact" | |
| 3084 | + ); | |
| 3085 | + } else { | |
| 3086 | + out_of_scope += 1; | |
| 3087 | + if !exact { | |
| 3088 | + out_of_scope_mismatch += 1; | |
| 3089 | + } | |
| 3090 | + } | |
| 3091 | + } | |
| 3092 | + } | |
| 3093 | + eprintln!( | |
| 3094 | + "{NAME}: {fired_arms} attempt(s) with a rect-strip palette block, \ | |
| 3095 | + {out_of_scope} out of scope ({out_of_scope_mismatch} mismatched), \ | |
| 3096 | + {refused} refused, {frames_compared} frames compared, \ | |
| 3097 | + fired 8-bit={} 10-bit={}", | |
| 3098 | + fired_at_depth[0], fired_at_depth[1] | |
| 3099 | + ); | |
| 3100 | + // MEASURED 2026-09-02, every 8-bit attempt of these recipes: aomenc | |
| 3101 | + // puts its palettes on SQUARE blocks at 8 bit and every 8-bit stream | |
| 3102 | + // that reaches a rect strip with one lands on a palette shape still | |
| 3103 | + // out of scope (8x8 square leaf, or a 64x32/32x64 superblock strip | |
| 3104 | + // with a real transform). So the 8-bit arms here prove the DECODE | |
| 3105 | + // path, not the lift -- `fired_at_depth[0] == 0` is a known, reported | |
| 3106 | + // coverage gap and not a silent pass: the counter is printed. | |
| 3107 | + assert!( | |
| 3108 | + fired_at_depth[1] > 0, | |
| 3109 | + "{NAME}: no attempt put a palette on a rect strip \ | |
| 3110 | + (8-bit={}, 10-bit={}) -- gate is vacuous", | |
| 3111 | + fired_at_depth[0], | |
| 3112 | + fired_at_depth[1] | |
| 3113 | + ); | |
| 3114 | + assert!(fired_arms > 0, "{NAME}: gate is vacuous"); | |
| 3115 | + assert_eq!( | |
| 3116 | + out_of_scope_mismatch, 0, | |
| 3117 | + "{NAME}: {out_of_scope_mismatch} attempt(s) without a rect-strip palette block \ | |
| 3118 | + still mismatched -- an unrelated defect, not a SKIP" | |
| 3119 | + ); | |
| 3120 | + } | |
| 3121 | + | |
| 2582 | 3122 | /// lane-hbd r5: a real `aomenc --bit-depth=10` stream, decoded through |
| 2583 | 3123 | /// this crate's own 10-bit planes (`Picture` widened to `u16` in an |
| 2584 | 3124 | /// earlier round) and checked pixel-exact against ffmpeg's own decode of |
| @@ -3079,6 +3619,54 @@ mod tests { | ||
| 3079 | 3619 | eprintln!("{NAME}: {skipped_cfl} skipped sub-8x8 CfL chroma blocks, frame pixel-exact"); |
| 3080 | 3620 | } |
| 3081 | 3621 | |
| 3622 | + /// lane-kf900 r2: the film's key frame at -ss 900, one frame | |
| 3623 | + /// (`crates/ec-av1/fixtures/reelb_kf900.obu`, 484640 bytes, sha256 | |
| 3624 | + /// `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`, | |
| 3625 | + /// extracted twice from independent | |
| 3626 | + /// `ffmpeg -ss 900 -t 2 -i <2160p AV1 HDR10 mkv> -c:v copy -f obu` runs and | |
| 3627 | + /// truncated to the first frame; both extracts hashed identically). | |
| 3628 | + /// | |
| 3629 | + /// This is the ONLY stream that reaches the r1 defect: a SKIPPED 8x8 intra | |
| 3630 | + /// leaf whose `tx_depth` symbol resolved to `TX_4X4` still publishes 4 -- | |
| 3631 | + /// not its 8-pixel block side -- to the next block's `get_tx_size_context` | |
| 3632 | + /// (`set_txfm_ctxs(mbmi->tx_size, bw, bh, skip_txfm && is_inter_block(...))`, | |
| 3633 | + /// `decodemv.c`; the skip term is 0 for intra). It fires 15 times here and | |
| 3634 | + /// zero times across 108 measured aomenc recipes, so the counter is | |
| 3635 | + /// asserted against the film rather than against a synthesised stream. | |
| 3636 | + /// | |
| 3637 | + /// LUMA only. U/V still differ (open residue, lane-kf900 r2: 221 U and | |
| 3638 | + /// 47912 V samples, max |d| 23/2, first at chroma (195, 640) -- chroma | |
| 3639 | + /// RESIDUAL, the prediction there is bit-exact against aomdec's | |
| 3640 | + /// `EC_PREDOUT`), so this gate pins what is proven and no more. | |
| 3641 | + #[test] | |
| 3642 | + fn a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact() | |
| 3643 | + { | |
| 3644 | + const NAME: &str = "a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact"; | |
| 3645 | + if !have_ffmpeg() { | |
| 3646 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 3647 | + return; | |
| 3648 | + } | |
| 3649 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_kf900.obu"); | |
| 3650 | + let stream = std::fs::read(&path) | |
| 3651 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | |
| 3652 | + let (width, height) = (3840usize, 1608usize); | |
| 3653 | + crate::decode::reset_skip_split_tx_hits(); | |
| 3654 | + let frames = match decode_stream(&stream) { | |
| 3655 | + Ok(frames) => frames, | |
| 3656 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | |
| 3657 | + }; | |
| 3658 | + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); | |
| 3659 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | |
| 3660 | + assert!( | |
| 3661 | + crate::decode::skip_split_tx_hits() >= 15, | |
| 3662 | + "{NAME}: skip_split_tx_hits() == {} -- the stream that carries the tx-context \ | |
| 3663 | + defect stopped carrying it, so this gate proves nothing", | |
| 3664 | + crate::decode::skip_split_tx_hits() | |
| 3665 | + ); | |
| 3666 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); | |
| 3667 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); | |
| 3668 | + } | |
| 3669 | + | |
| 3082 | 3670 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 |
| 3083 | 3671 | /// --superres-denominator=12` key frame, decoded pixel-exact against |
| 3084 | 3672 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s |
| @@ -23054,6 +23642,61 @@ mod tests { | ||
| 23054 | 23642 | } |
| 23055 | 23643 | } |
| 23056 | 23644 | |
| 23645 | + /// lane-kf900 r1: a SKIPPED 8x8 intra leaf whose `tx_depth` symbol | |
| 23646 | + /// resolved to TX_4X4 must publish 4 -- not its 8-px block side -- to the | |
| 23647 | + /// next block's `get_tx_size_context` (libaom `set_txfm_ctxs(mbmi->tx_size, | |
| 23648 | + /// ..., skip_txfm && is_inter_block(mbmi), xd)`; that skip term is always 0 | |
| 23649 | + /// for an intra block). `decode_leaf8`'s tail wrote the literal 8, so the | |
| 23650 | + /// rect strip below such a leaf read `tx_size_cat1` row 2 where libaom | |
| 23651 | + /// reads row 1 -- same alphabet, wrong CDF row, the msac range diverged | |
| 23652 | + /// mid-frame with NO refusal. `skip_split_tx_hits` was `pub` and asserted | |
| 23653 | + /// by no gate at all before this one (class `tool-disabled-in-every-gate`). | |
| 23654 | + #[test] | |
| 23655 | + fn a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact() { | |
| 23656 | + const NAME: &str = | |
| 23657 | + "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact"; | |
| 23658 | + crate::decode::reset_skip_split_tx_hits(); | |
| 23659 | + run_multi_tile_gate(NAME, 0, 0, 8, 1, &[], false, None); | |
| 23660 | + // lane-kf900 r2: the counter assert that used to sit here is | |
| 23661 | + // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at | |
| 23662 | + // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`, | |
| 23663 | + // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`, | |
| 23664 | + // `--enable-tx-size-search=1 --min-partition-size=8 | |
| 23665 | + // --enable-rect-partitions=1`; log | |
| 23666 | + // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced | |
| 23667 | + // `skip_split_tx_hits() == 0` on every stream that decoded, because | |
| 23668 | + // libaom's own encoder forces `tx_size` to the block maximum once it | |
| 23669 | + // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8 | |
| 23670 | + // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's | |
| 23671 | + // encoder does; the counter is hard-asserted on the real stream in | |
| 23672 | + // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`]. | |
| 23673 | + // These two arms stay as the pixel-exact multi-tile control. | |
| 23674 | + } | |
| 23675 | + | |
| 23676 | + /// [`a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact`]'s | |
| 23677 | + /// 10-bit arm -- the film that exposed the defect is yuv420p10le. | |
| 23678 | + #[test] | |
| 23679 | + fn a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact() | |
| 23680 | + { | |
| 23681 | + const NAME: &str = "a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_10bit_decodes_pixel_exact"; | |
| 23682 | + crate::decode::reset_skip_split_tx_hits(); | |
| 23683 | + run_multi_tile_gate(NAME, 0, 0, 10, 1, &[], false, None); | |
| 23684 | + // lane-kf900 r2: the counter assert that used to sit here is | |
| 23685 | + // UNREACHABLE from aomenc. 108 measured recipes (72 at 8-bit, 36 at | |
| 23686 | + // 10-bit: `geq` half-flat/half-noise, `mandelbrot`, `testsrc2`, | |
| 23687 | + // `noise=all_seed=49`, cq 55/59/63, `--cpu-used=0..2`, | |
| 23688 | + // `--enable-tx-size-search=1 --min-partition-size=8 | |
| 23689 | + // --enable-rect-partitions=1`; log | |
| 23690 | + // `$HOME/.cache/kf900/sweep/results{,10}.tsv`) produced | |
| 23691 | + // `skip_split_tx_hits() == 0` on every stream that decoded, because | |
| 23692 | + // libaom's own encoder forces `tx_size` to the block maximum once it | |
| 23693 | + // decides `skip_txfm` -- so no aomenc stream carries a SKIPPED 8x8 | |
| 23694 | + // intra leaf whose `tx_depth` resolved to `TX_4X4`. The film's | |
| 23695 | + // encoder does; the counter is hard-asserted on the real stream in | |
| 23696 | + // [`a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact`]. | |
| 23697 | + // These two arms stay as the pixel-exact multi-tile control. | |
| 23698 | + } | |
| 23699 | + | |
| 23057 | 23700 | #[test] |
| 23058 | 23701 | fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() { |
| 23059 | 23702 | run_multi_tile_gate( |
lanes/kf900-r1.handoff.mdadded+122 -0
| @@ -0,0 +1,122 @@ | ||
| 1 | +# lane-kf900 r1 HANDOFF — mid-frame entropy desync on the 4K 10-bit AV1 key frames | |
| 2 | + | |
| 3 | +Tip: `81b16cc` on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`, | |
| 4 | +base `18bf7dc` = main tip at start, no rebase needed). | |
| 5 | + | |
| 6 | +## ROOT CAUSE (fixed) | |
| 7 | + | |
| 8 | +`crates/ec-av1/src/decode.rs`, `decode_leaf8` tail — was: | |
| 9 | + | |
| 10 | +```rust | |
| 11 | +neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); // literal block side | |
| 12 | +``` | |
| 13 | + | |
| 14 | +now `neighbours.fill_lf_grid(leaf_mi, 2, resolved as u8, 0);` | |
| 15 | + | |
| 16 | +libaom calls `set_txfm_ctxs(mbmi->tx_size, bw, bh, skip_txfm && is_inter_block(mbmi), xd)` | |
| 17 | +(`decodemv.c`). For an INTRA block that skip term is **always 0**, so a *skipped* 8x8 intra | |
| 18 | +leaf whose `tx_depth` symbol resolved to `TX_4X4` still publishes **4** to the next block's | |
| 19 | +`get_tx_size_context` (`pred_common.h:342`). Our tail wrote **8** for every 8x8 leaf, | |
| 20 | +including the skipped-and-split ones (`decode_leaf8`'s non-skip `resolved == 4` branch had | |
| 21 | +its own early return with the correct 4 — only the skip path fell through to the literal). | |
| 22 | + | |
| 23 | +Consequence: the 8x16 strip below such a leaf computed `tx_size_context_rect` = 2 where | |
| 24 | +libaom computes 1, and read `tx_size_cat1` **row 2** instead of row 1 — same 3-symbol | |
| 25 | +alphabet, wrong CDF row (class `wrong-alphabet-same-value`). The msac range diverged | |
| 26 | +mid-frame, **no refusal**, everything after it garbage. | |
| 27 | + | |
| 28 | +### Evidence chain (all reproducible from `/home/user/.cache/kf900/`) | |
| 29 | +- `s900_1.obu` (1 frame, sha256 `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`, | |
| 30 | + hashed twice from two independent `ffmpeg -ss 900 -t 2 -c:v copy -f obu` extracts). | |
| 31 | +- Pre-fix first bad luma sample: **row 186 col 1803**, delta 2, max |d| 929, 5405035 luma | |
| 32 | + samples differing. Pre-filter (`EC_AV1_PREFILT_DUMP16` ours vs aomdec) first difference | |
| 33 | + row 192 col 512 → recon, not loop filter. | |
| 34 | +- Cross-decoder block ladder (new `EC_IMODE` rung, mirrors aomdec `decodemv.c:818`): | |
| 35 | + identical for 3543 blocks, first divergence entering mi (60,124). | |
| 36 | +- Symbol ladder (`EC_TRACE_MODE_STEP`, both sides) inside mi (60,122) — a `BLOCK_8X16` | |
| 37 | + (aomdec `bsize=4`): identical through `filter_intra_mode val=0 rng=33750`, then | |
| 38 | + aomdec `tx_depth val=0 ctx=1 cat=1 rng=53206`, ours `ctx=2`. | |
| 39 | +- New `EC_TXCTX` rung: `mi_row=60 mi_col=122 w=8 h=16 above_px=8 left_px=16 ctx=2`; | |
| 40 | + `above_px` should be 4. New `EC_LFGRID` rung: `mi_row=58 mi_col=122 w_mi=2 h_mi=2 | |
| 41 | + tx_px=8` written by the leaf above, which had `skip=1` and `tx_depth val=1` (TX_4X4). | |
| 42 | + | |
| 43 | +## RESULT — 24 key frames, 1-frame truncation each, ours (EC_PROBE_OUT16) vs `ffmpeg -pix_fmt yuv420p10le` | |
| 44 | + | |
| 45 | +`bytes_before` = census4 pre-fix all-plane byte diff; `bytes_after` = same, post-fix; | |
| 46 | +`luma_after` = differing **luma samples** post-fix. Every segment decodes `OK` (no refusal) | |
| 47 | +at 1 frame. Script: `/home/user/.cache/kf900/census.sh`, raw: `/home/user/.cache/kf900/census.tsv`. | |
| 48 | + | |
| 49 | +| -ss | bytes_before | bytes_after | luma_after | | |
| 50 | +|----:|-------------:|------------:|-----------:| | |
| 51 | +| 0 | 0 | 0 | 0 | | |
| 52 | +| 300 | 463 | 463 | 0 | | |
| 53 | +| 600 | 48771 | 0 | 0 | | |
| 54 | +| 900 | 14057195 | 51272 | 0 | | |
| 55 | +| 1200 | 14 | 14 | 0 | | |
| 56 | +| 1500 | 16649701 | 108644 | 0 | | |
| 57 | +| 1800 | 248 | 248 | 0 | | |
| 58 | +| 2100 | 15147518 | 2383 | 0 | | |
| 59 | +| 2400 | 42343 | 0 | 0 | | |
| 60 | +| 2700 | 7726287 | 1243 | 0 | | |
| 61 | +| 3000 | 0 | 0 | 0 | | |
| 62 | +| 3300 | 44500 | 4529 | 0 | | |
| 63 | +| 3600 | 1 | 1 | 0 | | |
| 64 | +| 3900 | 7554020 | 8 | 0 | | |
| 65 | +| 4200 | 0 | 0 | 0 | | |
| 66 | +| 4500 | 0 | 0 | 0 | | |
| 67 | +| 4800 | 2348 | 2348 | 0 | | |
| 68 | +| 5100 | 0 | 0 | 0 | | |
| 69 | +| 5400 | 0 | 0 | 0 | | |
| 70 | +| 5700 | 0 | 0 | 0 | | |
| 71 | +| 6000 | 15450360 | 10207 | 0 | | |
| 72 | +| 6300 | 15410936 | 146881 | 0 | | |
| 73 | +| 6600 | 15181681 | 67588 | 0 | | |
| 74 | +| 6900 | 0 | 0 | 0 | | |
| 75 | + | |
| 76 | +**24/24 luma-exact.** All remaining diffs are chroma-only. | |
| 77 | + | |
| 78 | +## OPEN RESIDUE | |
| 79 | + | |
| 80 | +1. **Chroma-only defect (deferred — needs its own lane).** On `s900_1.obu` after the fix: | |
| 81 | + Y 0, U 266 samples (max |d| 23), V 47927 (max |d| 2). First at chroma (102,688) = | |
| 82 | + luma (204,1376) = mi (51,344). It is **pre-filter** (`pf/ours2.f0` vs `pf/aom.f0`: | |
| 83 | + Y 0, U 228, V 47800 first at chroma row 102 col 689) → chroma *reconstruction*, not a | |
| 84 | + loop filter. Luma being exact proves the entropy stream is exact, so this is a | |
| 85 | + prediction/inverse-transform bug on one chroma path. Unblocked by: an `EC_TRACE_COEFF` | |
| 86 | + plane-1/2 ladder at mi (51,344) — the entropy side is now a fixed reference. | |
| 87 | +2. **The two new gate arms FAIL on their counter assert** (`stream.rs`, after | |
| 88 | + `a_real_aomenc_multi_tile_intra_stream_...`): | |
| 89 | + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact` | |
| 90 | + and its `_10bit_` twin. Both **decode 6/6 attempts pixel-exact**, but | |
| 91 | + `skip_split_tx_hits() == 0` — the shared `gradients_source` at 256x128 never makes | |
| 92 | + aomenc pick a skipped 8x8 intra leaf that also splits its transform (skip wants the | |
| 93 | + residual quantised away, TX_4X4 wants detail; the film has both at 4K). | |
| 94 | + They are committed FAILING on purpose: an assert that never fires is the | |
| 95 | + `tool-disabled-in-every-gate` class, and `skip_split_tx_hits` was `pub` with **zero** | |
| 96 | + callers anywhere before this round. | |
| 97 | + | |
| 98 | +## EXACT NEXT STEP | |
| 99 | + | |
| 100 | +Sweep for a recipe, then keep or replace the assert: | |
| 101 | +`$HOME/.cache/cargo-target-kf900/release/examples/decode_probe <stream.obu>` now prints | |
| 102 | +`skip_split_tx: N` — sweep aomenc without rebuilding the test binary. | |
| 103 | +On the film's own frame it prints **15**, so the counter is correct. | |
| 104 | +Suggested axes (none tried yet): 4K-ish frame sizes (the film's leaves are 8x8 inside 64x64 | |
| 105 | +SBs at 3840 wide), `--cpu-used=0`, `cq-level` 40..58, and a source with fine detail plus | |
| 106 | +flat regions (`mandelbrot`, `testsrc2` + `noise=all_seed=N:alls=20`), 8- and 10-bit arms. | |
| 107 | +**If no recipe reaches it after a measured sweep** (record every attempt), the charter's | |
| 108 | +fallback applies: commit `crates/ec-av1/fixtures/reelb_kf900.obu` (the 484640-byte | |
| 109 | +`/home/user/.cache/kf900/s900_1.obu`, sha256 above) plus a test that decodes it and | |
| 110 | +compares against a **stored sha256 of the ffmpeg output** (do not commit the yuv), and | |
| 111 | +assert `skip_split_tx_hits() >= 15`. | |
| 112 | + | |
| 113 | +Suite: armed detached as user unit `kf900-suite-r1`, log `$HOME/.cache/kf900-suite-r1.log`. | |
| 114 | +Check with `grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r1.log`. Expect the two | |
| 115 | +new gate arms to be the failures until the recipe lands. | |
| 116 | + | |
| 117 | +## NOT DONE (charter items) | |
| 118 | +- deferred: block-position printing on refusal in `decode_probe` (frame index, mi_row, | |
| 119 | + mi_col, bsize) — not started, ran out of turns; unblocked by ~10 minutes on | |
| 120 | + `decode.rs`'s `unsupported()` call sites. | |
| 121 | +- deferred: `refusal_inventory.rs` / `gate_coverage.rs` updates — this round lifted no | |
| 122 | + refusal, so neither file needed a change; re-check once the gate recipe lands. |
lanes/kf900-r2.report.mdadded+145 -0
| @@ -0,0 +1,145 @@ | ||
| 1 | +# lane-kf900 r2 report -- the chroma edge-filter type reads the wrong mi | |
| 2 | + | |
| 3 | +Tip: `1fad25c` on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`, | |
| 4 | +base `18bf7dc`; main has since moved to `4eff3a1` -- NOT rebased, see residue). | |
| 5 | + | |
| 6 | +## 1. r1 suite | |
| 7 | + | |
| 8 | +`$HOME/.cache/kf900-suite-r1.log` was still running at round start and was stopped by me | |
| 9 | +(`systemctl --user stop kf900-suite-r1`) before the first rebuild, so it never printed a | |
| 10 | +`test result` line: 288 tests started, 229 `ok`, 0 `FAILED` at the stop point. Its two | |
| 11 | +known-failing arms were rewritten this round anyway; r2's suite below is the real number. | |
| 12 | + | |
| 13 | +## 2. The gate arms that asserted an unreachable counter -- 108 measured recipes, all zero | |
| 14 | + | |
| 15 | +`skip_split_tx_hits()` counts a SKIPPED 8x8 intra leaf whose `tx_depth` resolved to `TX_4X4` | |
| 16 | +(the r1 defect). Sweep (`$HOME/.cache/kf900/sweep/sweep.sh`, raw | |
| 17 | +`results.tsv` + `results10.tsv`): 4 sources (`geq` half-flat/half-noise, `mandelbrot`, | |
| 18 | +`testsrc2`, gray+`noise=all_seed=49`) x cq {55,59,63} x `--cpu-used` {0,1,2} x {8,10}-bit, | |
| 19 | +all with `--enable-tx-size-search=1 --min-partition-size=8 --enable-rect-partitions=1 | |
| 20 | +--kf-max-dist=1 --limit=1`, 256x192. **72 8-bit + 36 10-bit = 108 attempts, `skip_split_tx: 0` | |
| 21 | +on every one that decoded.** Cause: libaom's encoder forces `tx_size` to the block maximum | |
| 22 | +once it picks `skip_txfm`, so aomenc never writes this combination. The film's encoder does. | |
| 23 | + | |
| 24 | +EVIDENCE: $HOME/.cache/kf900/sweep/results.tsv + results10.tsv | 108 aomenc encodes, each | |
| 25 | +decoded by `decode_probe` | `skip_split_tx: 0` in 108/108 (2 recipes at N=4 -- see residue 3) | |
| 26 | + | |
| 27 | +Fallback taken (charter-sanctioned): `crates/ec-av1/fixtures/reelb_kf900.obu`, the 484640-byte | |
| 28 | +1-frame extract, sha256 `a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83` | |
| 29 | +(two independent `ffmpeg -ss 900 -t 2 -c:v copy -f obu` extracts hashed identically, r1). | |
| 30 | +`git ls-files` shows it tracked. New gate | |
| 31 | +`stream.rs::a_10bit_key_frame_with_skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact` | |
| 32 | +hard-asserts `skip_split_tx_hits() >= 15` (actual 15) and compares the **luma** plane against | |
| 33 | +`ffmpeg -pix_fmt yuv420p10le`. U/V are the open residue, so the gate pins luma only and says so. | |
| 34 | +The two multi-tile arms keep their pixel-exact comparison and point at this gate. | |
| 35 | + | |
| 36 | +EVIDENCE: crates/ec-av1/fixtures/reelb_kf900.obu | `cargo test -p ec-av1 --lib skipped_8x8 chroma` | |
| 37 | +| 15 passed / 0 failed, `skip_split_tx: 15`, Y sha256 | |
| 38 | +1ffd0c103368793762637b2152c2062042fe3a14af97045182adc4790c4b5c12 == ffmpeg's Y | |
| 39 | + | |
| 40 | +## 3. Chroma residue -- root cause found and fixed (one of at least two) | |
| 41 | + | |
| 42 | +`decode.rs`, `Neighbours::smooth_uv_neighbour` (now at :4640): added | |
| 43 | +`let (mi_r, mi_c) = (mi_r & !1, mi_c & !1);`. | |
| 44 | + | |
| 45 | +libaom `set_mi_row_col` (`blockd.h`) snaps to the chroma REFERENCE block first -- | |
| 46 | +`base_mi = &xd->mi[-(mi_row & ss_y) * stride - (mi_col & ss_x)]` -- and only then takes | |
| 47 | +`chroma_above_mbmi = base_mi[-stride]` / `chroma_left_mbmi = base_mi[-1]`. A sub-8 pair codes | |
| 48 | +its chroma at the ODD mi, so we looked one mi row/column too far, the mi-exact slot never | |
| 49 | +matched, and the coarse SUB-grid fallback answered. | |
| 50 | + | |
| 51 | +Effect: `get_intra_edge_filter_type` (`reconintra.c`) 0 where libaom has 1, which flips | |
| 52 | +`av1_use_intra_edge_upsample(8, 4, -6, type)` (`blk_wh == 12`: false at type 1, TRUE at type 0). | |
| 53 | +We upsampled an edge libaom leaves alone. | |
| 54 | + | |
| 55 | +Ladder (chroma 8x4 at (688,100) = mi (51,344), V_PRED `p_angle=84`, `ft=1` in aomdec): | |
| 56 | +aomdec `EC_PREDOUT sum=15924`, ours `sum=15930`; per-sample +1 at rows 2/3, cols 1,2,4. | |
| 57 | +Hand-simulating both walks from the real above row (A[-1..7] = 495,495,496,497,498,498,499,499,499, | |
| 58 | +`dx = dr_intra_derivative(84) = 7`) reproduces 15924 unfiltered/un-upsampled and 15930 through | |
| 59 | +`av1_upsample_intra_edge_high` -- the upsample flag was the whole difference. | |
| 60 | + | |
| 61 | +EVIDENCE: $HOME/.cache/kf900/pred_aom.txt + pred_ours.txt | EC_PRED on aomdec and decode_probe | |
| 62 | +over reelb_kf900.obu | EC_PREDOUT 15924 vs OUR_PRED 15930; after the fix the block is 0-diff and | |
| 63 | +the frame's first chroma difference moves (102,688) -> (195,640) | |
| 64 | + | |
| 65 | +Not the cause (ruled out this round): per-plane quantizer deltas (`EC_AV1_TRACE` on the frame: | |
| 66 | +`base_q_idx=35 y_dc=0 u_dc=0 u_ac=0 v_dc=0 v_ac=0`, and `plane_q_delta()` is applied at every | |
| 67 | +chroma dequant call site anyway). | |
| 68 | + | |
| 69 | +Sibling gates re-run after the fix (`chroma` + `skipped_8x8` filters): 15 passed, 0 failed -- | |
| 70 | +includes `..._chroma_edge_filter_reads_a_sub16_neighbours_uv_mode...`, | |
| 71 | +`..._directional_chroma...`, `..._smooth_paeth_chroma...`, `..._4to1_or_sub8_rect...`, | |
| 72 | +`the_chroma_rect_gates_excluded_seed_46...`. | |
| 73 | + | |
| 74 | +## 4. 24-key-frame census, post-fix (per-plane DIFFERING SAMPLES, not bytes) | |
| 75 | + | |
| 76 | +Recipe `$HOME/.cache/kf900/census_r2.sh` (r1's `census.sh` with a per-plane comparator): | |
| 77 | +`ffmpeg -ss <s> -t 2 -c:v copy -f obu`, truncated to 1 frame, `EC_PROBE_OUT16` vs | |
| 78 | +`ffmpeg -pix_fmt yuv420p10le`. Raw: `$HOME/.cache/kf900/census_r2.tsv`. | |
| 79 | +NOTE the metric changed from r1's all-plane differing BYTES to per-plane differing SAMPLES. | |
| 80 | + | |
| 81 | +| -ss | Y | U | V | max abs Y/U/V | r1 bytes_after | | |
| 82 | +|----:|--:|--:|--:|:--------------|---------------:| | |
| 83 | +| 0 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 84 | +| 300 | 0 | 219 | 220 | 0/8/7 | 463 | | |
| 85 | +| 600 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 86 | +| 900 | 0 | 221 | 47912 | 0/23/2 | 51272 | | |
| 87 | +| 1200 | 0 | 0 | 0 | 0/0/0 | 14 | | |
| 88 | +| 1500 | 0 | 0 | 0 | 0/0/0 | 108644 | | |
| 89 | +| 1800 | 0 | 0 | 0 | 0/0/0 | 248 | | |
| 90 | +| 2100 | 0 | 1041 | 1008 | 0/1/1 | 2383 | | |
| 91 | +| 2400 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 92 | +| 2700 | 0 | 442 | 800 | 0/7/3 | 1243 | | |
| 93 | +| 3000 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 94 | +| 3300 | 0 | 0 | 0 | 0/0/0 | 4529 | | |
| 95 | +| 3600 | 0 | 0 | 0 | 0/0/0 | 1 | | |
| 96 | +| 3900 | 0 | 4 | 4 | 0/1/1 | 8 | | |
| 97 | +| 4200 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 98 | +| 4500 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 99 | +| 4800 | 0 | 2316 | 5 | 0/3/1 | 2348 | | |
| 100 | +| 5100 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 101 | +| 5400 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 102 | +| 5700 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 103 | +| 6000 | 0 | 210 | 0 | 0/3/0 | 10207 | | |
| 104 | +| 6300 | 0 | 145195 | 0 | 0/38/0 | 146881 | | |
| 105 | +| 6600 | 0 | 30873 | 897 | 0/19/7 | 67588 | | |
| 106 | +| 6900 | 0 | 0 | 0 | 0/0/0 | 0 | | |
| 107 | + | |
| 108 | +**24/24 luma-exact; 15/24 now FULLY exact** (were 10/24 at r1: 1200, 1500, 1800, 3300, 3600 | |
| 109 | +went to zero on all planes). Segments 1500 (108644 bytes) and 3300 (4529) collapsed to 0. | |
| 110 | + | |
| 111 | +EVIDENCE: $HOME/.cache/kf900/census_r2.tsv | 24 x (extract 2 s, truncate to 1 frame, decode | |
| 112 | +ours + ffmpeg, per-plane compare) | Y 0 on all 24, all-plane 0 on 15 | |
| 113 | + | |
| 114 | +## 5. Suite | |
| 115 | + | |
| 116 | +`systemd-run --user --unit=kf900-suite-r2 -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3` | |
| 117 | +-> `$HOME/.cache/kf900-suite-r2.log`: | |
| 118 | +**`test result: ok. 373 passed; 0 failed; 32 ignored; 0 measured; 0 filtered out; 1073.65s`** | |
| 119 | +(r1's two committed-failing arms are gone: they now assert only what they can reach, and the | |
| 120 | +counter moved to the fixture gate. 373 = 371 on main's tip + the fixture gate + r1's arms.) | |
| 121 | + | |
| 122 | +## Residue | |
| 123 | + | |
| 124 | +1. **fix-now (next round): the chroma RESIDUAL defect.** First remaining difference on the | |
| 125 | + s=900 frame is chroma (195,640) = mi (97,320). Its PREDICTION is bit-exact | |
| 126 | + (`EC_PREDND mi_row=97 mi_col=320 plane=1 sum=16384 / plane=2 sum=16352` on both sides), so | |
| 127 | + the divergence is dequant / inverse transform / chroma `tx_type` on an 8x4 chroma unit. | |
| 128 | + Unblocked by an `EC_TRACE_COEFF` plane-1/2 ladder at mi (97,320) -- entropy is a fixed | |
| 129 | + reference now (luma exact frame-wide). Suspect list unchanged apart from CfL and per-plane | |
| 130 | + delta_q, both now ruled out for this frame. | |
| 131 | +2. **fix-now (own lane): a real aomenc 10-bit stream we decode WRONG with no refusal.** | |
| 132 | + `testsrc2=s=256x192` at `--bit-depth=10 --cq-level=59 --cpu-used=0` (also `--cpu-used=1`), | |
| 133 | + full recipe in `$HOME/.cache/kf900/sweep/sweep.sh`, stream md5 | |
| 134 | + `e5f033d8fe34e4418d8cca3ac9d2b595`: `decode_probe` reports `OK: 1 frames decoded` and | |
| 135 | + `skip_split_tx: 4`, but 73687 of 73728 samples differ from ffmpeg, max |d| 933. This is the | |
| 136 | + only pair of the 108 recipes with a non-zero counter, and it is a SILENT desync -- a | |
| 137 | + pixel-exact gate for `skip_split_tx` becomes possible the moment it is fixed. | |
| 138 | + Reproducer in `$HOME/.cache/kf900/sweep/{g.obu,g.yuv,r.yuv}`. | |
| 139 | +3. **deferred: rebase onto main `4eff3a1`** (lane branched at `18bf7dc`; main gained | |
| 140 | + lane-sb128b in between) -- not done because the r1 suite was mid-run on this worktree at | |
| 141 | + round start and the round's budget went to the two defects; unblocked by a clean | |
| 142 | + `git rebase main` + one suite run. | |
| 143 | +4. **deferred (r1 carry-over): block-position printing on refusal in `decode_probe`** and | |
| 144 | + `refusal_inventory.rs` / `gate_coverage.rs` updates -- this round lifted no refusal, so | |
| 145 | + neither file changed; unblocked by ~10 min on `decode.rs`'s `unsupported()` call sites. |
lanes/kf900-r3.handoff.mdadded+117 -0
| @@ -0,0 +1,117 @@ | ||
| 1 | +# lane-kf900 r3 HANDOFF | |
| 2 | + | |
| 3 | +Tip: see `git log --oneline -3 lane-kf900` (merge `4267082`, fix+gate `667eb51`, this | |
| 4 | +commit). Worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`, base `18bf7dc`, | |
| 5 | +merged main `8e9ba81`. Full detail in `lanes/kf900-r3.report.md`. | |
| 6 | + | |
| 7 | +## 1. The silent 10-bit desync -- ROOT CAUSE FOUND AND FIXED | |
| 8 | + | |
| 9 | +Stream: `testsrc2=s=256x192 --bit-depth=10 --cq-level=59 --cpu-used=0`, recipe | |
| 10 | +`$HOME/.cache/kf900/sweep/sweep.sh`, md5 `e5f033d8fe34e4418d8cca3ac9d2b595` | |
| 11 | +(`$HOME/.cache/kf900/sweep/g.obu`). | |
| 12 | + | |
| 13 | +Symbol: the FIRST block's Y palette colours. mi(0,0) is BLOCK_32X16, DC_PRED, | |
| 14 | +2-colour Y palette. `decode.rs::read_palette_colors_y` / `read_palette_colors_uv` | |
| 15 | +read every raw literal at a hardcoded 8 bits; libaom `decodemv.c:478` (Y) and | |
| 16 | +`:509` (UV) size them all by the sequence `bit_depth`: first colour | |
| 17 | +`aom_read_literal(r, bit_depth)`, `min_bits = bit_depth - 3` (Y/U) and | |
| 18 | +`bit_depth - 4` (V delta mode), `range = (1 << bit_depth) - first - 1` (Y) / | |
| 19 | +`- first` (U), clamp bound `(1 << bit_depth) - 1`, V wrap modulus `1 << bit_depth`. | |
| 20 | +So a 10-bit palette block read TWO BITS TOO FEW per transmitted colour and decoded | |
| 21 | +the whole rest of the tile from the wrong bit position, with no refusal. | |
| 22 | + | |
| 23 | +Fix (commit `667eb51`): `let bd = u32::from(bit_depth());` (the already-present | |
| 24 | +thread-local, decode.rs:200) inside both readers; no signature threading. | |
| 25 | + | |
| 26 | +Before: `OK: 1 frames decoded` with 73687/73728 samples differing from ffmpeg, | |
| 27 | +max |d| 933 (Y 49117/49152, U 12286/12288, V 12284/12288, first diff at (0,0)). | |
| 28 | +After: the entropy stream is in lockstep with aomdec -- our first 1024 | |
| 29 | +`EC_PAL`/`EC_PAL_VAL` lines are byte-identical to aomdec's `EC_TRACE_PALETTE`, and | |
| 30 | +the block grid follows aomdec's (`EC_IMODE` mi(0,0) 32x16, (4,0) 16x16, (4,4) 16x16, | |
| 31 | +(0,8) 32x8, (2,8) 32x8, (4,8) 32x8 == aomdec bsize 8,6,6,19,19,19). | |
| 32 | + | |
| 33 | +WHY 108 SWEEP RECIPES AND A RANGE LADDER MISSED IT: raw literals are EQUIPROBABLE | |
| 34 | +and at the ranges this content reaches an equiprobable read is a FIXED POINT of the | |
| 35 | +msac range (62728 -> v=31364, either branch 31364, renorm 62728). A cross-decoder | |
| 36 | +RANGE ladder stays bit-identical straight through a wrong literal WIDTH; only the | |
| 37 | +decoded VALUE moves. aomdec and we both printed `rng=62728` and disagreed on the | |
| 38 | +first colour index (0 vs 1). Compare VALUES, not range alone. | |
| 39 | + | |
| 40 | +This stream is NOT a whole-frame gate: at mi(4,8) it hits a 32x8 (4:1) strip that | |
| 41 | +really uses a palette, and the 1:4 rect decoder is called with `palette: None` | |
| 42 | +(decode.rs:7167 and :7556), so it now stops at the pre-existing refusal | |
| 43 | +`"a 1:4 rect strip that actually uses a palette (reconstruction is not ported at | |
| 44 | +this shape)"`. Silent desync -> named refusal. | |
| 45 | + | |
| 46 | +## 2. The chroma residual at mi(97,320) -- GONE, and not by my fix | |
| 47 | + | |
| 48 | +r2's first remaining chroma difference on the s=900 4K key frame -- chroma (195,640) | |
| 49 | += mi(97,320) -- is ZERO on the merged tree. No ladder was needed: the census (below) | |
| 50 | +came back clean. Credit is the merged lane-reelckf `55532c7` (skipped CfL blocks still | |
| 51 | +predict; the 1:4 chroma pair edge-filter mi), NOT the palette fix -- the film frame | |
| 52 | +reads zero palette symbols | |
| 53 | +(`EC_AV1_TRACE=1 decode_probe crates/ec-av1/fixtures/reelb_kf900.obu | grep -c "^EC_PAL "` | |
| 54 | += 0). | |
| 55 | + | |
| 56 | +The charter's chroma-`tx_type` suspicion was audited and cleared rather than needed: | |
| 57 | +`av1_get_tx_type`'s `plane > 0` intra path is `intra_mode_to_tx_type(mbmi, | |
| 58 | +PLANE_TYPE_UV)` = our `default_intra_tx_type` (decode.rs:3229) fed with | |
| 59 | +`uv_predict_mode`, which already maps `UV_CFL_PRED` -> `DC_PRED`; the | |
| 60 | +`!av1_ext_tx_used[tx_set_type][tx_type]` narrowing can only bite at | |
| 61 | +`txsize_sqr_up >= TX_32X32`, and both chroma call sites already force `DCT_DCT` | |
| 62 | +there (decode.rs:6089 `chroma_w.max(chroma_h) >= 32`, decode.rs:9254 `side >= 32`). | |
| 63 | +All four values the table can produce are members of `EXT_TX_SET_DTT4_IDTX` and | |
| 64 | +`..._1DDCT`, the only two intra sets below 32. | |
| 65 | + | |
| 66 | +## 3. Census -- 24/24 BIT-EXACT (was 15/24 at r2) | |
| 67 | + | |
| 68 | +`$HOME/.cache/kf900/census_r3.sh` -> `$HOME/.cache/kf900/census_r3.tsv`: all 24 | |
| 69 | +key frames decode `OK: 1 frames decoded, 3840x1608` with Y=U=V=0 differing samples | |
| 70 | +and max |d| 0/0/0. Full table in the report. | |
| 71 | + | |
| 72 | +## 4. Gate state | |
| 73 | + | |
| 74 | +NEW, committed, PASSING: | |
| 75 | +`crates/ec-av1/src/stream.rs::a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit` | |
| 76 | +-- the existing 8-bit `..._with_palette_y_...` recipe (smptebars 64x64, | |
| 77 | +`--tune-content=screen --enable-palette=1`, rect/AB/1:4 off) with the depth as the | |
| 78 | +only variable (depth flags appended AFTER the base recipe: last flag wins). Each arm | |
| 79 | +hard-asserts `decode::palette_hits()` moved and compares Y, U and V vs ffmpeg. | |
| 80 | +`cargo test -p ec-av1 --lib palette_stream_decodes_pixel_exact_at_8_and_10` -> 1 | |
| 81 | +passed, 0 failed. DISCRIMINATION CHECK RUN: with `let bd = u32::from(bit_depth())` | |
| 82 | +reverted to `let bd = 8u32` the test FAILS on "luma at 10-bit" and the 8-bit arm | |
| 83 | +still passes (tree restored from a scratch copy afterwards). | |
| 84 | + | |
| 85 | +No refusal was lifted this round, so `refusal_inventory.rs` / `gate_coverage.rs` are | |
| 86 | +untouched (byte-identical to main's). | |
| 87 | + | |
| 88 | +Class sweep for the same shape (bit-depth-scaled reader hardcoding 8): | |
| 89 | +`grep -n "literal(8)\|255i32\|, 255)\|(1 << 8)" crates/ec-av1/src/decode.rs` -> only | |
| 90 | +the qindex clamps at :332 and :544 survive, and those are correct at every depth. | |
| 91 | +No sibling instances. | |
| 92 | + | |
| 93 | +## 5. Suite state -- INCOMPLETE, ZERO FAILURES SO FAR | |
| 94 | + | |
| 95 | +`systemd-run --user --unit=kf900-suite-r3-1788328486 -p MemoryMax=10G ... cargo test | |
| 96 | +-p ec-av1 --lib -j3 > $HOME/.cache/kf900-suite-r3.log`. At the turn cap: **272 `ok`, | |
| 97 | +0 `FAILED`, no `test result` line yet**. Resolve the unit name with | |
| 98 | +`systemctl --user list-units --all | grep kf900` before believing it finished. | |
| 99 | + | |
| 100 | +## 6. EXACT NEXT STEP | |
| 101 | + | |
| 102 | +1. `grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r3.log` -- expect | |
| 103 | + `374 passed; 0 failed` (373 at r2 + the new depth gate). If a `FAILED` appears, | |
| 104 | + the only behavioural change on this branch is the palette bit-depth widening, so | |
| 105 | + look at the three existing palette gates first | |
| 106 | + (`a_real_aomenc_stream_with_palette_y_...`, `..._palette_uv_...`, | |
| 107 | + `..._rect_palette_...`, `a_real_aomenc_multi_tile_palette_stream_...`). | |
| 108 | +2. Merge into main. | |
| 109 | +3. Then the open lane work, in this order: | |
| 110 | + a. Tighten `..._skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact` | |
| 111 | + from luma-only to all three planes -- the census is 24/24 exact now, so its U/V | |
| 112 | + arms should hold. | |
| 113 | + b. Port palette reconstruction to the 1:4 rect decoder (decode.rs:7167 and :7556 | |
| 114 | + pass `palette: None`); that is the ONLY thing between us and a whole-frame | |
| 115 | + pixel gate for `skip_split_tx` on the pinned 10-bit stream above. Probably | |
| 116 | + lane-palette2's territory. | |
| 117 | + c. Carry-over: block-position printing on refusal in `decode_probe`. |
lanes/kf900-r3.report.mdadded+171 -0
| @@ -0,0 +1,171 @@ | ||
| 1 | +# lane-kf900 r3 -- the silent 10-bit desync was the palette colour reader | |
| 2 | + | |
| 3 | +Tip: `667eb51`+ on `lane-kf900` (worktree `/home/user/Documents/Code/Rust/edith_codecs-kf900`), | |
| 4 | +base `18bf7dc`, merged main `8e9ba81` (lane-reelckf `55532c7`). | |
| 5 | + | |
| 6 | +## 1. Merge (charter item 1) | |
| 7 | + | |
| 8 | +`git merge --no-commit main` -> clean, no conflicts (commit `4267082`). Both | |
| 9 | +chroma-reference-mi fixes kept: lane-reelckf passes `pair_mi` at the sub-8 | |
| 10 | +`smooth_uv_neighbour` call site (decode.rs:7778), r2's own snap | |
| 11 | +`let (mi_r, mi_c) = (mi_r & !1, mi_c & !1);` lives inside the function | |
| 12 | +(decode.rs:4662) -- idempotent together, re-read to confirm. | |
| 13 | +`cdf.rs`, `cdf_state.rs`, `mvstack.rs`, `refusal_inventory.rs`, | |
| 14 | +`gate_coverage.rs` byte-compare SAME as `main:`'s copies (sha256 of each). | |
| 15 | + | |
| 16 | +## 2. The silent 10-bit desync -- ROOT CAUSE, fixed and gated (charter item 2) | |
| 17 | + | |
| 18 | +`decode.rs::read_palette_colors_y` / `read_palette_colors_uv` read every raw | |
| 19 | +literal at a **hardcoded 8 bits**. libaom `decodemv.c:478`/`:509` size all of | |
| 20 | +them by the sequence `bit_depth`: | |
| 21 | + | |
| 22 | +* first colour = `aom_read_literal(r, bit_depth)` | |
| 23 | +* `min_bits = bit_depth - 3` (Y and U), `bit_depth - 4` (V delta mode) | |
| 24 | +* `range = (1 << bit_depth) - first - 1` (Y) / `- first` (U) | |
| 25 | +* clamp bound `(1 << bit_depth) - 1`, V wrap modulus `1 << bit_depth` | |
| 26 | + | |
| 27 | +so a 10-bit palette block read **two bits too few per transmitted colour** and | |
| 28 | +decoded the whole remainder of the tile from the wrong bit position, with no | |
| 29 | +refusal. Fixed by taking the already-present thread-local `bit_depth()` inside | |
| 30 | +both readers (no signature threading). | |
| 31 | + | |
| 32 | +### Why 108 gate recipes and a range ladder could not see it | |
| 33 | + | |
| 34 | +Raw literals are EQUIPROBABLE, and at the ranges this content reaches an | |
| 35 | +equiprobable read is a FIXED POINT of the msac range: 62728 -> v = 31364, | |
| 36 | +either branch leaves 31364, renormalised back to 62728. A cross-decoder RANGE | |
| 37 | +ladder therefore stays bit-identical straight through the miscount and only | |
| 38 | +the decoded VALUE moves. That is the blind spot of the `compare-range-not-tell` | |
| 39 | +method, and it is why this stream reported `OK: 1 frames decoded` with | |
| 40 | +73687/73728 samples wrong. | |
| 41 | + | |
| 42 | +### The pin | |
| 43 | + | |
| 44 | +`testsrc2=s=256x192 --bit-depth=10 --cq-level=59 --cpu-used=0` (recipe | |
| 45 | +`$HOME/.cache/kf900/sweep/sweep.sh`, stream md5 | |
| 46 | +`e5f033d8fe34e4418d8cca3ac9d2b595`). Its first block is mi(0,0) BLOCK_32X16, | |
| 47 | +DC_PRED, with a real 2-colour Y palette. | |
| 48 | + | |
| 49 | +* before: `EC_PAL row=0 col=0 ctx=-1 n=2 rng=62728` on BOTH decoders, then | |
| 50 | + aomdec `color_idx=0`, ours `color_idx=1` -- identical range, opposite value. | |
| 51 | +* after: our first 1024 `EC_PAL`/`EC_PAL_VAL` lines are **byte-identical** to | |
| 52 | + aomdec's, and the block grid follows aomdec's for the rest of the frame | |
| 53 | + (`EC_IMODE` mi(0,0) 32x16, mi(4,0) 16x16, mi(4,4) 16x16, mi(0,8) 32x8, | |
| 54 | + mi(2,8) 32x8, mi(4,8) 32x8 == aomdec bsize 8,6,6,19,19,19). | |
| 55 | + | |
| 56 | +EVIDENCE: $HOME/.cache/kf900/r3/{ours.pal,aom.pal} | EC_AV1_TRACE on | |
| 57 | +decode_probe vs EC_TRACE_PALETTE on the instrumented aomdec over the pinned | |
| 58 | +stream | `diff <(head -1024 ours.pal) <(head -1024 aom.pal)` empty; before the | |
| 59 | +fix the two disagreed on the first colour index at an identical range | |
| 60 | + | |
| 61 | +That stream is NOT a whole-frame gate: at mi(4,8) it hits a 32x8 (4:1) strip | |
| 62 | +that really uses a palette, and the 1:4 rect decoder is called with | |
| 63 | +`palette: None` (decode.rs:7167/7556), so it now stops at the existing refusal | |
| 64 | +`"a 1:4 rect strip that actually uses a palette (reconstruction is not ported | |
| 65 | +at this shape)"`. Silent desync -> named refusal is itself the honest outcome; | |
| 66 | +the pixel gate is a different recipe: | |
| 67 | + | |
| 68 | +### Gate | |
| 69 | + | |
| 70 | +`stream.rs::a_real_aomenc_palette_stream_decodes_pixel_exact_at_8_and_10_bit` | |
| 71 | +-- the existing 8-bit `..._with_palette_y_...` recipe (smptebars 64x64, | |
| 72 | +`--tune-content=screen --enable-palette=1`, all rect/AB/1:4 off) with the | |
| 73 | +depth as the ONLY variable (depth flags appended AFTER the base recipe, per | |
| 74 | +the last-flag-wins rule). Each arm hard-asserts `decode::palette_hits()` moved | |
| 75 | +and compares Y, U and V against ffmpeg's decode of the same bytes. | |
| 76 | + | |
| 77 | +EVIDENCE: crates/ec-av1/src/stream.rs | `cargo test -p ec-av1 --lib | |
| 78 | +palette_stream_decodes_pixel_exact_at_8_and_10` | 1 passed / 0 failed; with | |
| 79 | +`let bd = u32::from(bit_depth())` reverted to `let bd = 8u32` the same test | |
| 80 | +FAILS on "luma at 10-bit" and the 8-bit arm still passes (discrimination check | |
| 81 | +run, tree restored from a scratch copy) | |
| 82 | + | |
| 83 | +Class sweep for the same shape (a bit-depth-scaled reader hardcoding 8): | |
| 84 | +`grep -n "literal(8)\|255i32\|, 255)\|(1 << 8)" decode.rs` -> the only two | |
| 85 | +survivors are the qindex clamps at decode.rs:332 and :544, which are correct | |
| 86 | +(qindex is 0..255 at every bit depth). No sibling instances. | |
| 87 | + | |
| 88 | +## 3. Chroma residual on the 4K 10-bit key frame (charter item 3) -- GONE | |
| 89 | + | |
| 90 | +r2's open residue (first chroma difference at (195,640) = mi(97,320)) is zero | |
| 91 | +on the merged tree. It is NOT my palette fix: the film frame reads **zero** | |
| 92 | +palette symbols (`EC_AV1_TRACE ... | grep -c "^EC_PAL "` = 0 on | |
| 93 | +`crates/ec-av1/fixtures/reelb_kf900.obu`), so the credit belongs to the merged | |
| 94 | +lane-reelckf commits (skipped CfL blocks still predict; the 1:4 chroma pair | |
| 95 | +edge-filter mi). | |
| 96 | + | |
| 97 | +The chroma `tx_type` suspicion from the charter was audited and cleared rather | |
| 98 | +than needed: `av1_get_tx_type`'s `plane > 0` intra path is | |
| 99 | +`intra_mode_to_tx_type(mbmi, PLANE_TYPE_UV)` (our `default_intra_tx_type`, | |
| 100 | +decode.rs:3229) fed with `uv_predict_mode`, which already maps `UV_CFL_PRED` | |
| 101 | +to `DC_PRED`; the `!av1_ext_tx_used[tx_set_type][tx_type]` narrowing can only | |
| 102 | +bite at `txsize_sqr_up >= TX_32X32`, and both chroma call sites already force | |
| 103 | +`DCT_DCT` there (decode.rs:6089 `chroma_w.max(chroma_h) >= 32`, decode.rs:9254 | |
| 104 | +`side >= 32`). Every value the table can produce is a member of | |
| 105 | +`EXT_TX_SET_DTT4_IDTX` and `..._1DDCT`, the only two intra sets below 32. | |
| 106 | + | |
| 107 | +## 4. 24-key-frame census on the merged tree (charter item 4) | |
| 108 | + | |
| 109 | +Recipe `$HOME/.cache/kf900/census_r3.sh` (r2's script, own `c3/` scratch and | |
| 110 | +`census_r3.tsv`): `ffmpeg -ss <s> -t 2 -c:v copy -f obu`, truncated to one | |
| 111 | +frame, `EC_PROBE_OUT16` vs `ffmpeg -pix_fmt yuv420p10le`, per-plane DIFFERING | |
| 112 | +SAMPLES. | |
| 113 | + | |
| 114 | +| -ss | Y | U | V | max Y/U/V | r2 U | r2 V | | |
| 115 | +|----:|--:|--:|--:|:---------|-----:|-----:| | |
| 116 | +| 0 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 117 | +| 300 | 0 | 0 | 0 | 0/0/0 | 219 | 220 | | |
| 118 | +| 600 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 119 | +| 900 | 0 | 0 | 0 | 0/0/0 | 221 | 47912 | | |
| 120 | +| 1200 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 121 | +| 1500 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 122 | +| 1800 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 123 | +| 2100 | 0 | 0 | 0 | 0/0/0 | 1041 | 1008 | | |
| 124 | +| 2400 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 125 | +| 2700 | 0 | 0 | 0 | 0/0/0 | 442 | 800 | | |
| 126 | +| 3000 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 127 | +| 3300 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 128 | +| 3600 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 129 | +| 3900 | 0 | 0 | 0 | 0/0/0 | 4 | 4 | | |
| 130 | +| 4200 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 131 | +| 4500 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 132 | +| 4800 | 0 | 0 | 0 | 0/0/0 | 2316 | 5 | | |
| 133 | +| 5100 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 134 | +| 5400 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 135 | +| 5700 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 136 | +| 6000 | 0 | 0 | 0 | 0/0/0 | 210 | 0 | | |
| 137 | +| 6300 | 0 | 0 | 0 | 0/0/0 | 145195 | 0 | | |
| 138 | +| 6600 | 0 | 0 | 0 | 0/0/0 | 30873 | 897 | | |
| 139 | +| 6900 | 0 | 0 | 0 | 0/0/0 | 0 | 0 | | |
| 140 | + | |
| 141 | +**24/24 key frames now decode BIT-EXACT on all three planes** (r2: 15/24). | |
| 142 | +Every decode reported `OK: 1 frames decoded, 3840x1608`. | |
| 143 | + | |
| 144 | +EVIDENCE: $HOME/.cache/kf900/census_r3.tsv | 24 x (extract 2 s, truncate to 1 | |
| 145 | +frame, decode ours + ffmpeg, per-plane compare) | Y/U/V all 0 on all 24 rows | |
| 146 | + | |
| 147 | +## 5. Suite (charter item 5) | |
| 148 | + | |
| 149 | +`systemd-run --user --unit=kf900-suite-r3-... -p MemoryMax=10G ... cargo test | |
| 150 | +-p ec-av1 --lib -j3` -> `$HOME/.cache/kf900-suite-r3.log`: | |
| 151 | +**still running at the turn cap** -- 272 `ok`, 0 `FAILED` at the last poll, no `test result` line yet (unit `kf900-suite-r3-1788328486.service`). See the handoff. | |
| 152 | + | |
| 153 | +## Residue | |
| 154 | + | |
| 155 | +1. **deferred: a whole-frame pixel gate for `skip_split_tx`** -- the only | |
| 156 | + aomenc recipe found (of 108 + this round's) that fires the counter is the | |
| 157 | + pinned 10-bit `testsrc2` stream, and it now stops at the 1:4-rect-palette | |
| 158 | + refusal. Unblocked by porting palette reconstruction to the 1:4 rect | |
| 159 | + decoder (decode.rs:7167/7556 pass `palette: None`) -- lane-palette2's | |
| 160 | + territory, not a kf900 defect. The fixture gate | |
| 161 | + `..._skipped_8x8_intra_leaves_that_split_their_transform_decodes_luma_exact` | |
| 162 | + still pins the counter at 15 and now compares luma only by construction; | |
| 163 | + with the census at 24/24 its U/V arms could be tightened next round. | |
| 164 | +2. **deferred (r1/r2 carry-over): block-position printing on refusal in | |
| 165 | + `decode_probe`**, plus `refusal_inventory.rs` / `gate_coverage.rs` updates | |
| 166 | + -- this round lifted no refusal (it turned a silent desync into an existing | |
| 167 | + named one), so neither file changed. Unblocked by ~10 min on `decode.rs`'s | |
| 168 | + `unsupported()` call sites. | |
| 169 | +3. **accepted: the pinned 10-bit palette stream is not committed as a fixture** | |
| 170 | + -- it is reproducible from `sweep.sh` and its md5 is recorded here; the | |
| 171 | + committed gate builds its own stream from aomenc at test time. |
lanes/kf900-r4.handoff.mdadded+98 -0
| @@ -0,0 +1,98 @@ | ||
| 1 | +# lane-kf900 r4 HANDOFF | |
| 2 | + | |
| 3 | +Tip `12c3c7c` on `lane-kf900` (parent `08c9a35`). Full detail in | |
| 4 | +`lanes/kf900-r4.report.md`. The work is DONE and committed; the only open item is the | |
| 5 | +suite, which was still running at the turn cap. | |
| 6 | + | |
| 7 | +## 1. Suite state -- INCOMPLETE, ZERO FAILURES SO FAR | |
| 8 | + | |
| 9 | +Unit `kf900-suite-r4-1788330592.service`, log `$HOME/.cache/kf900-suite-r4.log`. | |
| 10 | +At the cap: **245 `ok`, 0 `FAILED`, no `test result` line yet** (r3's baseline was | |
| 11 | +`383 passed; 0 failed; 33 ignored` in 1029 s; this run is slower because 10 lanes share | |
| 12 | +the box). Resolve the unit with `systemctl --user list-units --all | grep kf900` before | |
| 13 | +believing it finished, then | |
| 14 | +`grep -E "^test result|FAILED" $HOME/.cache/kf900-suite-r4.log`. | |
| 15 | +Expect 384 passed (383 + the new gate). If something is RED, the behavioural changes on | |
| 16 | +this commit are only: rect-strip palette reconstruction, the chroma palette map size, the | |
| 17 | +palette cache mi keying, and `record_strip_palette` -- so look at the four existing | |
| 18 | +palette gates first (`a_real_aomenc_stream_with_palette_y_...`, `..._palette_uv_...`, | |
| 19 | +`..._rect_palette_...`, `a_real_aomenc_multi_tile_palette_stream_...`). | |
| 20 | + | |
| 21 | +## 2. The patch that shipped (all sites are current `crates/ec-av1/src/decode.rs`) | |
| 22 | + | |
| 23 | +Grep the symbol, not the line number -- the file moved by ~300 lines. | |
| 24 | + | |
| 25 | +| hook | site | what | | |
| 26 | +| --- | --- | --- | | |
| 27 | +| palette mode ctx + Y colour cache | `decode_block_rect4` (32x8/8x32), just after `modes_above_left_mi` | `let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI)); neighbours.palette_ctx_and_cache_mi(pal_at, mi_r)` -> passed as `Some((palette_ctx, &palette_cache))` where `None` used to go | | |
| 28 | +| UV colour cache | same | `neighbours.palette_uv_cache_mi(pal_at, mi_r)` replaces `&[]` | | |
| 29 | +| same two | `decode_rect4_16` (16x4/4x16), inside the 4-strip loop, `at16` + `lmi.0` | per strip, not per cell | | |
| 30 | +| same two | `decode_leaf_rect` (16x8/8x16) | already had the ctx/cache; switched to the `_mi` variants with `leaf_mi.0` | | |
| 31 | +| palette_size ctx | `palette_bsize_ctx_wh` -- UNCHANGED, already correct | `num_pels_log2_lookup[bsize] - 6`; 0 for BLOCK_16X4/4X16 (64 px), 2 for BLOCK_32X8 | | |
| 32 | +| colours | `read_palette_colors_y` / `_uv` -- UNCHANGED (r3 fixed the bit depth) | | | |
| 33 | +| colour index map read point | `read_intra_mode_rect`, after `use_filter_intra` -- UNCHANGED | `av1_visit_palette` order: Y map then chroma map, both AFTER all mode info | | |
| 34 | +| colour index map SIZE (fixed) | `read_intra_mode_rect`, the `palette_uv_pending.map(..)` closure | `((bw / 2).max(4), (bh / 2).max(4))`, was `(bw / 2, bh / 2)` | | |
| 35 | +| chroma on the odd strip | `decode_rect4_16`'s `has_chroma` (`i % 2 == 1`) -- UNCHANGED gating; the pair's 8x4/4x8 chroma now gets `set_palette_pred` per plane in both the skip and the coded arm | | | |
| 36 | +| reconstruction | all three fns | `palette_y_buf` / `palette_uv_bufs` (index map through the base colours) handed to each `reconstruct_rect` via `set_palette_pred`; the split-tx walks slice the block buffer per transform unit (`RectStripModes.palette_y` in `decode_rect_split`, an inline window in `decode_rect4_16`) | | |
| 37 | +| neighbour state | new free fn `record_strip_palette` | split axis only until the closing strip (`mi_r % 8 == 6` / `mi_c % 8 == 6` for 32x8/8x32, `i == 3` for 16x4/4x16, `leaf_mi.0 % 4 == 2` for 16x8/8x16) | | |
| 38 | +| counter | `RECT4_PALETTE_HITS` / `pub(crate) fn rect4_palette_hits()` | rect strips that ACTUALLY use a palette | | |
| 39 | + | |
| 40 | +libaom cited: `decodemv.c` `read_palette_mode_info` (`av1_allow_palette` -- `sb_type >= | |
| 41 | +BLOCK_8X8` is an ENUM-INDEX test that BLOCK_4X16/16X4 pass; `av1_get_palette_bsize_ctx`; | |
| 42 | +`av1_get_palette_mode_ctx`), `read_palette_colors_y` `decodemv.c:478`, | |
| 43 | +`read_palette_colors_uv` `:509`, `pred_common.c:73` `av1_get_palette_cache` (SB-top-row | |
| 44 | +guard at `:76`, `row = -xd->mb_to_top_edge >> 3` = the block's PIXEL row, hence | |
| 45 | +`mi_r % 16 != 0`), `decodeframe.c` `decode_color_map_tokens` reached from | |
| 46 | +`av1_visit_palette`, and `ss_size_lookup` (BLOCK_16X4 -> BLOCK_8X4, BLOCK_4X16 -> | |
| 47 | +BLOCK_4X8) for the chroma map size. | |
| 48 | + | |
| 49 | +## 3. Refusals dropped (both from decode.rs and refusal_inventory.rs, 47 -> 45) | |
| 50 | + | |
| 51 | +* `a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)` | |
| 52 | +* `a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)` | |
| 53 | + | |
| 54 | +`gate_coverage.rs` needed no change (it pins aomenc FLAGS, and | |
| 55 | +`enable-palette` / `enable-1to4-partitions` were already in its list). | |
| 56 | + | |
| 57 | +## 4. Gate | |
| 58 | + | |
| 59 | +`crates/ec-av1/src/stream.rs::a_real_aomenc_rect_strip_palette_decodes_pixel_exact`. | |
| 60 | +Base recipe (arm 0 = the r3 pin): `--codec=av1 --bit-depth=N --input-bit-depth=N | |
| 61 | +--passes=1 --end-usage=q --cq-level=59 --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 | |
| 62 | +--limit=1 --threads=1 --tile-columns=0 --enable-tx-size-search=1 --min-partition-size=8 | |
| 63 | +--enable-rect-partitions=1` on `testsrc2=s=256x192:r=25`, y4m over stdin, `-t 0.2`. | |
| 64 | +Arms 1-2 append `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 | |
| 65 | +--min-partition-size=8` (testsrc2 / `smptebars=size=256x192:rate=25`). 8-bit arms append | |
| 66 | +`--sb-size=64` (the 8-bit twin otherwise lands on the open 128-root HORZ refusal). | |
| 67 | +`cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact -- --nocapture` | |
| 68 | +-> **1 passed**: `2 attempt(s) with a rect-strip palette block, 0 out of scope | |
| 69 | +(0 mismatched), 4 refused, 2 frames compared, fired 8-bit=0 10-bit=2`. | |
| 70 | + | |
| 71 | +## 5. Measured facts | |
| 72 | + | |
| 73 | +* The test's own 10-bit arm-0 encode reproduces the pin BYTE FOR BYTE: | |
| 74 | + md5 `e5f033d8fe34e4418d8cca3ac9d2b595`. | |
| 75 | +* That stream went `REFUSED: ... a 1:4 rect strip that actually uses a palette` -> | |
| 76 | + `OK: 1 frames decoded, 256x192`; `rect4_32` went `horz=8 vert=0 coded=8` -> | |
| 77 | + `horz=12 vert=16 coded=28`. | |
| 78 | +* **The charter/r3 premise that this stream fires `skip_split_tx` is WRONG**: decoded in | |
| 79 | + full, `decode_probe` prints `skip_split_tx: 0`. The gate asserts the palette counter. | |
| 80 | +* **64x16/16x64 needed nothing**: `decode_block_rect64` already passes the real ctx/cache | |
| 81 | + and reconstructs; its remaining palette refusal is the separate corner-cropped-luma one. | |
| 82 | +* **No 8-bit recipe reaches a rect-strip palette.** At 8 bit aomenc palettes SQUARE | |
| 83 | + blocks; every 8-bit variant tried lands on `a block that actually uses a palette (Y)` | |
| 84 | + (8x8 square leaf) or `a palette block with a real transform on a superblock-level | |
| 85 | + HORZ/VERT strip`. Lifting either unblocks 8-bit coverage of this shape. | |
| 86 | +* **NEW pre-existing 8-bit 1:4 mismatch, not palette** -- 8-bit `testsrc2=s=256x192:r=25`, | |
| 87 | + base recipe + `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 | |
| 88 | + --max-partition-size=32 --sb-size=64`: decodes `OK`, `rect4_32: horz=8 vert=8 coded=16`, | |
| 89 | + frame 0 differs from ffmpeg. The stream reads ZERO palette symbols | |
| 90 | + (`EC_AV1_TRACE=1 decode_probe | grep -c "^EC_PAL "` == 0), so every change in this | |
| 91 | + commit is inert on it. Needs its own lane. | |
| 92 | + | |
| 93 | +## 6. EXACT NEXT STEP | |
| 94 | + | |
| 95 | +1. Read the suite result (above). If green, merge `12c3c7c` into main. | |
| 96 | +2. Then, in order: (a) the new 8-bit 1:4 non-palette mismatch in 5; (b) palette on an 8x8 | |
| 97 | + SQUARE leaf (`decode_leaf8` discards `_palette_y`), which is what blocks 8-bit | |
| 98 | + rect-strip coverage; (c) palette + real transform on a 64x32/32x64 SB-level strip. |
lanes/kf900-r4.report.mdadded+70 -0
| @@ -0,0 +1,70 @@ | ||
| 1 | +# lane-kf900 r4 report -- rect-strip palette reconstruction | |
| 2 | + | |
| 3 | +## What changed (all in `crates/ec-av1/`) | |
| 4 | + | |
| 5 | +| path:line (post-change) | why | | |
| 6 | +| --- | --- | | |
| 7 | +| `src/decode.rs` `Neighbours::palette_ctx_and_cache_mi` / `palette_uv_cache_mi` | `av1_get_palette_cache` drops the above neighbour on a 64-px SB boundary keyed on the block's own PIXEL row (`pred_common.c:76`). The old code read `at.0 % 4` off the 16-px `SUB` cell, so strip 1 of a HORZ_4 (8 px into the cell) wrongly excluded strip 0 from its cache in every SB-top cell row. Old entry points kept, delegating. | | |
| 8 | +| `src/decode.rs` `read_intra_mode_rect`, chroma colour-index map | the map is `av1_get_plane_block_size(bsize,1,1)` (`ss_size_lookup`), not a plain halving: BLOCK_16X4 -> BLOCK_8X4, BLOCK_4X16 -> BLOCK_4X8. `(bw/2, bh/2)` read HALF the colour-index symbols of a 1:4 strip's chroma palette. Now `((bw/2).max(4), (bh/2).max(4))`. | | |
| 9 | +| `src/decode.rs` `record_strip_palette` (new) | the coarse `SUB`-cell palette arrays alias all four strips of a HORZ_4/VERT_4 (and both leaves of a 16x8/8x16 pair) onto one entry, so stamping BOTH axes after every strip hands strip i+1 strip i's colours on the WRONG axis too. Writes the split axis until the closing strip, both on it. | | |
| 10 | +| `src/decode.rs` `decode_block_rect4` (32x8/8x32) | was `palette: None, &[]` -> real ctx + cache; palette-Y/UV prediction wired into the split-tx walk (`RectStripModes`), the coded arm and the skip arm; palette state stamped on all three exits. Refusal dropped. | | |
| 11 | +| `src/decode.rs` `decode_rect4_16` (16x4/4x16) | same, per strip, incl. the inlined per-TU split walk (window of the block's palette buffer per unit) and the pair's chroma. Refusal dropped. | | |
| 12 | +| `src/decode.rs` `decode_leaf_rect` (16x8/8x16) | sibling refusal "a palette block on a HORZ/VERT intra strip below 16x16" dropped the same way; its zero-clear of the palette arrays became `record_strip_palette`, which also fixes leaf 0 of a pair zeroing the LEFT entry leaf 1 legitimately reads. | | |
| 13 | +| `src/decode.rs` `RECT4_PALETTE_HITS` / `rect4_palette_hits()` | the gate's counter: rect intra strips that ACTUALLY use a palette. | | |
| 14 | +| `src/refusal_inventory.rs` | both lifted strings removed (47 -> 45). | | |
| 15 | +| `src/stream.rs` `a_real_aomenc_rect_strip_palette_decodes_pixel_exact` | the gate. | | |
| 16 | + | |
| 17 | +libaom sites cited: `decodemv.c` `read_palette_mode_info` (`av1_allow_palette`, `av1_get_palette_bsize_ctx`, `av1_get_palette_mode_ctx`), `read_palette_colors_y` (`decodemv.c:478`) / `read_palette_colors_uv` (`:509`), `pred_common.c:73` `av1_get_palette_cache`, `decodeframe.c` `decode_color_map_tokens` via `av1_visit_palette` (map read AFTER all mode info -- unchanged, already correct here). | |
| 18 | + | |
| 19 | +## Refusals lifted (2) | |
| 20 | + | |
| 21 | +1. `a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)` | |
| 22 | +2. `a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)` | |
| 23 | + | |
| 24 | +## Gate | |
| 25 | + | |
| 26 | +`crates/ec-av1/src/stream.rs::a_real_aomenc_rect_strip_palette_decodes_pixel_exact` | |
| 27 | +3 arms x 2 depths. Arm 0 IS the r3 pinned stream: `testsrc2=s=256x192:r=25`, `--cq-level=59 | |
| 28 | +--cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=1 --threads=1 --tile-columns=0 | |
| 29 | +--enable-tx-size-search=1 --min-partition-size=8 --enable-rect-partitions=1`, and the encoder | |
| 30 | +invocation inside the test reproduces md5 `e5f033d8fe34e4418d8cca3ac9d2b595` byte for byte at | |
| 31 | +10-bit. Arms 1-2 add `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 | |
| 32 | +--min-partition-size=8` on testsrc2 / smptebars. Every decode-order frame, all three planes, | |
| 33 | +compared against ffmpeg's decode of the identical bytes. Hard asserts: a rect-strip palette | |
| 34 | +block fired (`rect4_palette_hits()` delta), `out_of_scope_mismatch == 0`, sources render | |
| 35 | +byte-identical twice. A NAMED (`unsupported`) refusal is counted and printed, never a pass. | |
| 36 | + | |
| 37 | +``` | |
| 38 | +cargo test -p ec-av1 --lib a_real_aomenc_rect_strip_palette_decodes_pixel_exact -- --nocapture | |
| 39 | +``` | |
| 40 | + | |
| 41 | +EVIDENCE: $HOME/.cache/kf900/sweep/g.obu + gate stdout | aomenc pinned recipe -> decode_stream -> ffmpeg compare, 3 arms x {8,10} bit | 2 attempts with a rect-strip palette block, both whole-frame pixel-exact (Y+U+V), 0 out-of-scope mismatches, 4 named refusals on other shapes, md5 of the test's own 10-bit arm-0 stream == e5f033d8fe34e4418d8cca3ac9d2b595 | |
| 42 | +EVIDENCE: decode_probe on $HOME/.cache/kf900/sweep/g.obu | before/after this commit | `REFUSED: ... a 1:4 rect strip that actually uses a palette` -> `OK: 1 frames decoded, 256x192`, rect4_32 horz=8 vert=0 -> horz=12 vert=16 | |
| 43 | + | |
| 44 | +## Corrected premises (both stated as fact in the charter/handoff) | |
| 45 | + | |
| 46 | +- **`skip_split_tx` does NOT fire on the pinned stream.** `decode_probe` on the fully decoded | |
| 47 | + stream prints `skip_split_tx: 0`. The r3 handoff's "fires skip_split_tx AND reaches that | |
| 48 | + refusal" is half wrong, so the gate asserts the palette counter and does not assert | |
| 49 | + `skip_split_tx`; asserting it would have been a vacuous/failing gate. | |
| 50 | +- **64x16/16x64 needed no work.** `decode_block_rect64` already passes the real ctx/cache and | |
| 51 | + reconstructs palette; its only palette refusal is the separate corner-cropped-luma one. | |
| 52 | + | |
| 53 | +## Open residue | |
| 54 | + | |
| 55 | +- **deferred(8-bit rect-strip palette coverage)** -- `fired 8-bit=0, 10-bit=2`. At 8 bit aomenc | |
| 56 | + puts its palettes on SQUARE blocks; every 8-bit recipe tried that reaches a rect strip with a | |
| 57 | + palette lands on a shape still out of scope (`a block that actually uses a palette (Y)` on an | |
| 58 | + 8x8 square leaf, or `a palette block with a real transform on a superblock-level HORZ/VERT | |
| 59 | + strip`). Unblocked by lifting either of those two refusals. The 8-bit arms still run and prove | |
| 60 | + the decode path; the counter is printed, not hidden. | |
| 61 | +- **fix-now-elsewhere: a NEW pre-existing 8-bit 1:4 pixel mismatch, unrelated to palette.** | |
| 62 | + Recipe: `testsrc2=s=256x192:r=25`, 8-bit, base recipe above plus | |
| 63 | + `--tune-content=screen --enable-palette=1 --enable-1to4-partitions=1 --max-partition-size=32 | |
| 64 | + --sb-size=64`. Decodes `OK: 1 frames decoded` with `rect4_32: horz=8 vert=8 coded=16` and | |
| 65 | + frame 0 differs from ffmpeg. Proved unrelated to this round: the stream reads ZERO palette | |
| 66 | + symbols (`EC_AV1_TRACE=1 decode_probe | grep -c "^EC_PAL "` == 0), so every change in this | |
| 67 | + commit is inert on it. Needs its own lane. | |
| 68 | +- **accepted**: `a palette block with a real transform on a superblock-level HORZ/VERT strip` | |
| 69 | + and `a block that actually uses a palette (Y/UV)` (8x8 square leaf) remain -- out of this | |
| 70 | + lane's charter (both are square/SB-level, not rect strips). |
lanes/kf900-r5.report.mdadded+88 -0
| @@ -0,0 +1,88 @@ | ||
| 1 | +# lane-kf900 r5 report -- rect intra strips never read `use_intrabc` | |
| 2 | + | |
| 3 | +Tip `a7113f5` on `lane-kf900` (parent `9a01750`). GREEN. | |
| 4 | + | |
| 5 | +## Defect (chartered) and root cause | |
| 6 | + | |
| 7 | +The chartered stream -- 8-bit `testsrc2=s=256x192:r=25`, cq59 cpu-used 0, rect + 1:4 | |
| 8 | +partitions, `--tune-content=screen --enable-palette=1 --sb-size=64` -- decoded `OK` | |
| 9 | +(`rect4_32: horz=8 vert=8`) and every luma sample of frame 0 differed from ffmpeg. | |
| 10 | + | |
| 11 | +`--tune-content=screen` sets `allow_screen_content_tools`, and the key-frame header then | |
| 12 | +sets **`allow_intrabc = 1`**. `av1_allow_intrabc` is a FRAME-level test (libaom | |
| 13 | +`decodemv.c:892`, `read_intra_frame_mode_info`): every intra block reads a `use_intrabc` | |
| 14 | +symbol after `skip`/`cdef`/`delta_q` and before `mbmi->mode`, with **no block-shape term**. | |
| 15 | +`read_intra_mode` (square leaf) and `read_intra_mode_sub8` both read it; | |
| 16 | +`read_intra_mode_rect` -- the reader for EVERY HORZ/VERT/1:4 rect strip -- did not. The | |
| 17 | +arithmetic decoder therefore desynced at the first mode symbol of the first rect block of | |
| 18 | +the frame, i.e. at mi(0,0), and every later symbol and pixel was garbage. | |
| 19 | + | |
| 20 | +Decisive measurement (cross-decoder range ladder, `EC_TRACE_MODE_STEP` both sides): | |
| 21 | + | |
| 22 | +``` | |
| 23 | +ref EC_ISTEP mi_row=0 mi_col=0 name=skip rng=32874 ours ... rng=32874 (identical) | |
| 24 | +ref EC_ISTEP mi_row=0 mi_col=0 name=mode rng=58628 ours ... rng=62696 (diverged) | |
| 25 | +``` | |
| 26 | + | |
| 27 | +62696 is exactly `kf_y_mode[0][0]` symbol 0 from 32874. 58628 is that same read after ONE | |
| 28 | +default `intrabc` symbol was consumed first (32874 -> 30694 -> normalised 61388 -> 58628), | |
| 29 | +computed by hand from `od_ec_decode_cdf_q15` (`aom_dsp/entdec.c`) with | |
| 30 | +`default_intrabc_cdf = AOM_CDF2(30531)`. That is the missing symbol, not a table row. | |
| 31 | + | |
| 32 | +## Changes | |
| 33 | + | |
| 34 | +| path | why | | |
| 35 | +| --- | --- | | |
| 36 | +| `crates/ec-av1/src/decode.rs` `allow_intrabc_frame()` (new, next to `intrabc_hits`) | `INTRABC_MI_GRID` is `Some` exactly when the frame header set `allow_intrabc`, so the flag reaches the rect reader with no new plumbing through 5 functions | | |
| 37 | +| `crates/ec-av1/src/decode.rs` `read_intra_mode_rect`, right after `istep!("dq", 0)` | reads `use_intrabc`; refuses by name when it fires (rect intrabc reconstruction is not ported); bumps `RECT_INTRABC_READS` | | |
| 38 | +| `crates/ec-av1/src/decode.rs` `RECT_INTRABC_READS` + `rect_intrabc_reads()` / `reset_rect_intrabc_reads()` | gate hit counter: strips that READ the symbol (distinct from `INTRABC_HITS` = blocks that USE intrabc) | | |
| 39 | +| `crates/ec-av1/src/stream.rs` `rect_intrabc_reads()` re-export + new gate | gate + probe surface | | |
| 40 | +| `crates/ec-av1/src/refusal_inventory.rs` | new refusal `"intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)"` (45 -> 46) | | |
| 41 | +| `crates/ec-av1/examples/decode_probe.rs` | prints `rect_intrabc_reads:` | | |
| 42 | + | |
| 43 | +Class sweep: `grep -n "cdfs.kf_y_mode\[" crates/ec-av1/src/decode.rs` -> 3 intra mode | |
| 44 | +readers (5630 rect, 8828 square, 10709 sub8); all three now read `cdfs.intrabc` under the | |
| 45 | +frame flag (5618 / 8807 / 10700). No other site. | |
| 46 | + | |
| 47 | +## Gate | |
| 48 | + | |
| 49 | +`crates/ec-av1/src/stream.rs::a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` | |
| 50 | +-- three real-aomenc 8-bit arms, base recipe `--codec=av1 --bit-depth=8 --input-bit-depth=8 | |
| 51 | +--passes=1 --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=1 | |
| 52 | +--threads=1 --tile-columns=0 --enable-rect-partitions=1 --enable-1to4-partitions=1 | |
| 53 | +--min-partition-size=8 --max-partition-size=32 --sb-size=64 --tune-content=screen`, | |
| 54 | +per-arm overrides last: | |
| 55 | + | |
| 56 | +* `testsrc2-screen-nopalette-cq50` -- rect strips really use intrabc; must refuse by NAME | |
| 57 | + (was: a silently wrong frame). | |
| 58 | +* `smptebars-screen-nopalette-cq45` -- decodes the whole frame, 69 rect `use_intrabc` | |
| 59 | + reads; entropy coverage (see residue). | |
| 60 | +* `testsrc2-screen-nopalette-cq63` -- screen tools but header `allow_intrabc = 0`; frame | |
| 61 | + compared pixel-exact against ffmpeg, proving the new read is not taken when libaom does | |
| 62 | + not write it. | |
| 63 | + | |
| 64 | +``` | |
| 65 | +cargo test -p ec-av1 --lib a_real_aomenc_screen_key_frame_reads_use_intrabc -- --nocapture | |
| 66 | +-> 1 passed: 147 rect-strip use_intrabc symbol(s) read, 1 refused by name, 1 frames compared pixel-exact | |
| 67 | +``` | |
| 68 | + | |
| 69 | +`refusal_inventory` (3 tests) and `gate_coverage` (7 tests) green. | |
| 70 | + | |
| 71 | +## EVIDENCE | |
| 72 | + | |
| 73 | +* `EVIDENCE: $HOME/.cache/kf900-r5/{s.obu,ours.yuv,ref.yuv} | aomenc chartered recipe (sha256 4fe2e7ba57...; encoded twice byte-identical as bf048186e3... in IVF form), decode_probe vs `ffmpeg -i` | before fix: OK + 73438 bytes differ, first luma (0,0) ours 128 vs ref 74; after fix: named refusal instead of a wrong frame` | |
| 74 | +* `EVIDENCE: $HOME/.cache/kf900-r5/{c45_ours.txt,c45_ref.txt} | EC_TRACE_MODE_STEP ladder both decoders | first divergence mi(0,0) name=mode: ours 62696 vs oracle 58628 = one unconsumed intrabc symbol` | |
| 75 | +* `EVIDENCE: $HOME/.cache/kf900-r5/{b_o.n,b_r.n} | same ladder on the smptebars cq45 arm after the fix | 429 mode-ladder elements identical, first divergence at mi(32,44) (a SQUARE intrabc block's DV read)` | |
| 76 | +* `EVIDENCE: $HOME/.cache/kf900-suite-r5.log | full ec-av1 lib suite as systemd unit kf900-suite-r5-1788331689 | test result: ok. 385 passed; 0 failed; 33 ignored, 1088.55s` | |
| 77 | + | |
| 78 | +## Residue | |
| 79 | + | |
| 80 | +* `deferred: pixel-exactness on frames that actually USE intrabc -- read_intrabc_dv desyncs | |
| 81 | + inside the DV of a SQUARE 16x16 intrabc block at mi(32,44) (smptebars cq45 arm: 429 | |
| 82 | + ladder elements exact, then diverges); it is a separate defect from this lane's read -- | |
| 83 | + unblocked by a DV-symbol ladder against the oracle at that block` | |
| 84 | +* `deferred: rect-strip intrabc RECONSTRUCTION (the new refusal) -- needs the DV path above | |
| 85 | + working first, plus the square path's own open "intrabc block under TxMode::Select" refusal` | |
| 86 | +* `deferred: 8-bit screen key frame with palette, cq45 --enable-tx-size-search=1 -- after this | |
| 87 | + fix the ladder is exact for 46 elements and diverges in the TAIL of the palette block at | |
| 88 | + mi(0,8) (palette colour-index map / tx). Separate palette defect, not intrabc` |