Merge branch 'main' into lane-superres
Browse files at this commit41 changed files +3728 -323
- crates/ec-av1/src/cdf.rs +41 -0
- crates/ec-av1/src/cdf_state.rs +32 -0
- crates/ec-av1/src/decode.rs +849 -130
- crates/ec-av1/src/encode.rs +124 -58
- crates/ec-av1/src/encoder.rs +11 -8
- crates/ec-av1/src/film_grain.rs +3 -3
- crates/ec-av1/src/intra.rs +27 -27
- crates/ec-av1/src/mc.rs +44 -41
- crates/ec-av1/src/motion.rs +9 -3
- crates/ec-av1/src/refusal_inventory.rs +2 -0
- crates/ec-av1/src/restoration.rs +18 -18
- crates/ec-av1/src/stream.rs +379 -16
- crates/ec-av1/src/superres.rs +27 -12
- crates/ec-av1/src/warp.rs +4 -4
- lanes/hbd-r1.charter.md +51 -0
- lanes/hbd-r2.charter.md +47 -0
- lanes/hbd-r2.report.md +102 -0
- lanes/hbd-r3.charter.md +49 -0
- lanes/hbd-r3.report.md +119 -0
- lanes/hbd-r4.charter.md +67 -0
- lanes/palette2-r1.charter.md +60 -0
- lanes/palette2-r2.charter.md +35 -0
- lanes/palette2-r2.report.md +73 -0
- lanes/realworld-r10.report.md +127 -0
- lanes/realworld-r8.report.md +98 -0
- lanes/sbpart-r2.charter.md +76 -0
- lanes/sbpart-r2.report.md +106 -0
- lanes/sbpart-r3.charter.md +49 -0
- lanes/sbpart-r4.charter.md +44 -0
- lanes/sbpart-r5.charter.md +47 -0
- lanes/sbpart-r5.report.md +119 -0
- lanes/sbpart-r6.charter.md +50 -0
- lanes/sbpart-r6.report.md +135 -0
- lanes/sbpart-r7.charter.md +33 -0
- lanes/sbpart-r7.report.md +192 -0
- lanes/sbpart-r8.charter.md +47 -0
- lanes/sbpart-r8.report.md +94 -0
- lanes/sbpart.charter.md +82 -0
- lanes/sbpart.report.md +98 -0
- scripts/instrument-aom-oracle.sh +153 -0
- tools/ec-bench/src/main.rs +5 -3
crates/ec-av1/src/cdf.rsmodified+41 -0
| @@ -266,6 +266,20 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ | |||
| 266 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, | 266 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, |
| 267 | ]; | 267 | ]; |
| 268 | 268 | ||
| 269 | +/// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`, | ||
| 270 | +/// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded | ||
| 271 | +/// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of | ||
| 272 | +/// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma | ||
| 273 | +/// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan | ||
| 274 | +/// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough | ||
| 275 | +/// that no truncation applies). Unlike every other `EOB_PT_*` table here, | ||
| 276 | +/// libaom's default is the exact same flat distribution at all four | ||
| 277 | +/// q-contexts and both `eob_multi_size` selectors (`token_cdfs.h` rows), so | ||
| 278 | +/// one constant covers every q-context -- no `_Q0`/`_Q1`/`_Q3` siblings. | ||
| 279 | +pub const EOB_PT_512_CHROMA: [u16; 11] = [ | ||
| 280 | + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, | ||
| 281 | +]; | ||
| 282 | + | ||
| 269 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, | 283 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, |
| 270 | /// indexed by whether the neighbouring blocks' DC signs lean negative (1), | 284 | /// indexed by whether the neighbouring blocks' DC signs lean negative (1), |
| 271 | /// positive (2) or neither (0). | 285 | /// positive (2) or neither (0). |
| @@ -747,6 +761,33 @@ pub const NZ_MAP_CTX_OFFSET_32: [[u8; 5]; 5] = [ | |||
| 747 | [21, 21, 21, 21, 21], | 761 | [21, 21, 21, 21, 21], |
| 748 | ]; | 762 | ]; |
| 749 | 763 | ||
| 764 | +/// `Av1_Nz_Map_Ctx_Offset[TX_32X64]` (libaom `txb_common.c` | ||
| 765 | +/// `av1_nz_map_ctx_offset_32x64`, row and column clamped to four): the real | ||
| 766 | +/// 32-wide/64-tall transform's own table, used when a superblock-level | ||
| 767 | +/// `PARTITION_VERT` strip's luma corner is read through [`NZ_MAP_CTX_OFFSET_32`]'s | ||
| 768 | +/// scan/CDF-set but the *un-adjusted* block shape (spec `get_txsize_entropy_ctx` | ||
| 769 | +/// resolves the CDF *set* to `TX_64X64`, but `get_nz_map_ctx_from_stats` still | ||
| 770 | +/// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart | ||
| 771 | +/// r8 root cause) is genuinely rectangular, not square. Distinct from | ||
| 772 | +/// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`. | ||
| 773 | +pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [ | ||
| 774 | + [0, 11, 6, 6, 21], | ||
| 775 | + [11, 11, 6, 21, 21], | ||
| 776 | + [11, 11, 21, 21, 21], | ||
| 777 | + [11, 11, 21, 21, 21], | ||
| 778 | + [11, 11, 21, 21, 21], | ||
| 779 | +]; | ||
| 780 | + | ||
| 781 | +/// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom | ||
| 782 | +/// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner. | ||
| 783 | +pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [ | ||
| 784 | + [0, 16, 16, 16, 16], | ||
| 785 | + [16, 16, 16, 16, 16], | ||
| 786 | + [6, 6, 21, 21, 21], | ||
| 787 | + [6, 21, 21, 21, 21], | ||
| 788 | + [21, 21, 21, 21, 21], | ||
| 789 | +]; | ||
| 790 | + | ||
| 750 | /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a | 791 | /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a |
| 751 | /// 16x16 chroma transform block that covers its whole plane block, for the | 792 | /// 16x16 chroma transform block that covers its whole plane block, for the |
| 752 | /// three contexts its coded neighbours give. | 793 | /// three contexts its coded neighbours give. |
crates/ec-av1/src/cdf_state.rsmodified+32 -0
| @@ -104,6 +104,19 @@ pub(crate) enum TxbSet { | |||
| 104 | /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of | 104 | /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of |
| 105 | /// `Chroma16`'s 256-position one. | 105 | /// `Chroma16`'s 256-position one. |
| 106 | ChromaRect16x8, | 106 | ChromaRect16x8, |
| 107 | + /// The chroma 32x16/16x32 transform of an intra `PARTITION_HORZ`/`VERT` | ||
| 108 | + /// 64x32/32x64 SUPERBLOCK strip (lane-sbpart): `get_txsize_entropy_ctx` | ||
| 109 | + /// (`(txsize_sqr_map + txsize_sqr_up_map + 1) >> 1`) resolves `TX_32X16` | ||
| 110 | + /// to `TX_32X32`, so this shares every table | ||
| 111 | + /// [`Chroma32`](TxbSet::Chroma32) does except `eob_pt`, which reads the | ||
| 112 | + /// true 512-position [`crate::cdf::EOB_PT_512_CHROMA`] instead of | ||
| 113 | + /// `Chroma32`'s 1024-position one. The SIBLING luma plane of this same | ||
| 114 | + /// strip is genuinely truncated (64/32 > 32), so it reads | ||
| 115 | + /// [`Luma64`](TxbSet::Luma64) instead -- `get_txsize_entropy_ctx(TX_64X32)` | ||
| 116 | + /// resolves to `TX_64X64`, not `TX_32X32`, the two axes landing on | ||
| 117 | + /// different existing sets is why this variant exists at all rather than | ||
| 118 | + /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. | ||
| 119 | + ChromaRect32x16, | ||
| 107 | } | 120 | } |
| 108 | 121 | ||
| 109 | /// The tables one transform block is coded with, borrowed from the state for | 122 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -253,6 +266,9 @@ pub(crate) struct Cdfs { | |||
| 253 | /// The end-of-block group of a true 16x8/8x16 rect chroma transform | 266 | /// The end-of-block group of a true 16x8/8x16 rect chroma transform |
| 254 | /// (lane-rectwire), see [`TxbSet::ChromaRect16x8`]. | 267 | /// (lane-rectwire), see [`TxbSet::ChromaRect16x8`]. |
| 255 | pub eob_pt_128_chroma: [u16; 9], | 268 | pub eob_pt_128_chroma: [u16; 9], |
| 269 | + /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform | ||
| 270 | + /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`]. | ||
| 271 | + pub eob_pt_512_chroma: [u16; 11], | ||
| 256 | /// The end-of-block offset bit, per table set. | 272 | /// The end-of-block offset bit, per table set. |
| 257 | pub eob_extra_luma_32: [[u16; 3]; 9], | 273 | pub eob_extra_luma_32: [[u16; 3]; 9], |
| 258 | /// The same, for a 64x64 luma transform. | 274 | /// The same, for a 64x64 luma transform. |
| @@ -607,6 +623,7 @@ impl Cdfs { | |||
| 607 | reset1(&mut self.eob_pt_256_chroma); | 623 | reset1(&mut self.eob_pt_256_chroma); |
| 608 | reset1(&mut self.eob_pt_512_luma); | 624 | reset1(&mut self.eob_pt_512_luma); |
| 609 | reset1(&mut self.eob_pt_128_chroma); | 625 | reset1(&mut self.eob_pt_128_chroma); |
| 626 | + reset1(&mut self.eob_pt_512_chroma); | ||
| 610 | reset2(&mut self.eob_extra_luma_32); | 627 | reset2(&mut self.eob_extra_luma_32); |
| 611 | reset2(&mut self.eob_extra_luma_64); | 628 | reset2(&mut self.eob_extra_luma_64); |
| 612 | reset2(&mut self.eob_extra_chroma_16); | 629 | reset2(&mut self.eob_extra_chroma_16); |
| @@ -993,6 +1010,9 @@ impl Cdfs { | |||
| 993 | cdf::EOB_PT_128_CHROMA, | 1010 | cdf::EOB_PT_128_CHROMA, |
| 994 | cdf::EOB_PT_128_CHROMA_Q3, | 1011 | cdf::EOB_PT_128_CHROMA_Q3, |
| 995 | ), | 1012 | ), |
| 1013 | + // Flat default at every q-context (see the constant's own doc | ||
| 1014 | + // comment) -- no `pick()` needed. | ||
| 1015 | + eob_pt_512_chroma: cdf::EOB_PT_512_CHROMA, | ||
| 996 | eob_extra_luma_32: pick( | 1016 | eob_extra_luma_32: pick( |
| 997 | q_ctx, | 1017 | q_ctx, |
| 998 | cdf::EOB_EXTRA_LUMA_32_Q0, | 1018 | cdf::EOB_EXTRA_LUMA_32_Q0, |
| @@ -1389,6 +1409,18 @@ impl Cdfs { | |||
| 1389 | tx_type: None, | 1409 | tx_type: None, |
| 1390 | eob_pt_class1: None, | 1410 | eob_pt_class1: None, |
| 1391 | }, | 1411 | }, |
| 1412 | + TxbSet::ChromaRect32x16 => TxbTables { | ||
| 1413 | + side: 32, | ||
| 1414 | + txb_skip: &mut self.txb_skip_chroma_32, | ||
| 1415 | + eob_pt: &mut self.eob_pt_512_chroma, | ||
| 1416 | + eob_extra: &mut self.eob_extra_chroma_32, | ||
| 1417 | + base: &mut self.base_chroma_32, | ||
| 1418 | + base_eob: &mut self.base_eob_chroma_32, | ||
| 1419 | + br: &mut self.br_chroma_32, | ||
| 1420 | + dc_sign: &mut self.dc_sign_chroma, | ||
| 1421 | + tx_type: None, | ||
| 1422 | + eob_pt_class1: None, | ||
| 1423 | + }, | ||
| 1392 | } | 1424 | } |
| 1393 | } | 1425 | } |
| 1394 | } | 1426 | } |
crates/ec-av1/src/decode.rsmodified+849 -130
| @@ -76,6 +76,27 @@ pub(crate) fn filter_intra_hits() -> usize { | |||
| 76 | thread_local! { | 76 | thread_local! { |
| 77 | static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) }; | 77 | static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) }; |
| 78 | } | 78 | } |
| 79 | +// lane-realworld r8: the sequence header's `color_config.bit_depth`, set | ||
| 80 | +// once per `decode_key_frame_tile_with_cdfs`/`decode_inter_frame_tile_with_cdfs` | ||
| 81 | +// call the same way `CDEF_BITS` is above. `stream.rs`'s own refusal still | ||
| 82 | +// blocks every non-8-bit stream from reaching a decode call, so this is `8` | ||
| 83 | +// on every path that runs today -- threading it now (rather than the literal | ||
| 84 | +// `8`) is stage 1 of widening past that refusal without re-deriving every | ||
| 85 | +// clamp bound later. `PlaneBuf`'s sample storage stays `u16` regardless of | ||
| 86 | +// depth (this decoder's own internal choice, matches dav1d/libaom). | ||
| 87 | +thread_local! { | ||
| 88 | + static BIT_DEPTH: std::cell::Cell<u8> = const { std::cell::Cell::new(8) }; | ||
| 89 | +} | ||
| 90 | +/// `(1 << bit_depth) - 1` — the reconstruction clamp bound for the current | ||
| 91 | +/// stream's [`BIT_DEPTH`], replacing the crate-wide literal `255`. | ||
| 92 | +pub(crate) fn sample_max() -> i32 { | ||
| 93 | + (1i32 << BIT_DEPTH.with(std::cell::Cell::get)) - 1 | ||
| 94 | +} | ||
| 95 | +/// Sets [`BIT_DEPTH`] for the current thread, called once per frame from | ||
| 96 | +/// [`crate::stream`]'s decode loop. | ||
| 97 | +pub(crate) fn set_bit_depth(bit_depth: u8) { | ||
| 98 | + BIT_DEPTH.with(|c| c.set(bit_depth)); | ||
| 99 | +} | ||
| 79 | // Whether this superblock's single CDEF unit (this decoder has no 128x128 | 100 | // Whether this superblock's single CDEF unit (this decoder has no 128x128 |
| 80 | // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal | 101 | // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal |
| 81 | // read -- reset to `false` at the top of each superblock in the two tile | 102 | // read -- reset to `false` at the top of each superblock in the two tile |
| @@ -451,6 +472,42 @@ pub(crate) fn palette_hits() -> usize { | |||
| 451 | PALETTE_HITS.with(|c| c.get()) | 472 | PALETTE_HITS.with(|c| c.get()) |
| 452 | } | 473 | } |
| 453 | 474 | ||
| 475 | +// lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma | ||
| 476 | +// palette use -- proves a stream actually reconstructed UV palette pixels, | ||
| 477 | +// not just read and refused the `palette_uv_mode` symbol. | ||
| 478 | +thread_local! { | ||
| 479 | + static PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 480 | +} | ||
| 481 | + | ||
| 482 | +/// Current value of [`PALETTE_UV_HITS`]. | ||
| 483 | +pub(crate) fn palette_uv_hits() -> usize { | ||
| 484 | + PALETTE_UV_HITS.with(|c| c.get()) | ||
| 485 | +} | ||
| 486 | + | ||
| 487 | +// lane-palette2 r1: how many HORZ/VERT rect intra strips ([`read_intra_mode_rect`]) | ||
| 488 | +// decoded a real palette-Y use -- proves the rect strip's own palette syntax | ||
| 489 | +// (not just the square path's) actually fired. | ||
| 490 | +thread_local! { | ||
| 491 | + static PALETTE_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 492 | +} | ||
| 493 | + | ||
| 494 | +/// Current value of [`PALETTE_RECT_HITS`]. | ||
| 495 | +pub(crate) fn palette_rect_hits() -> usize { | ||
| 496 | + PALETTE_RECT_HITS.with(|c| c.get()) | ||
| 497 | +} | ||
| 498 | + | ||
| 499 | +// lane-palette2 r1: how many palette-Y blocks decoded with a split luma | ||
| 500 | +// transform (`tx_select && logical_tx != side`) -- proves the per-TU index-map | ||
| 501 | +// slicing actually ran, not just that the whole-block path stayed exact. | ||
| 502 | +thread_local! { | ||
| 503 | + static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 504 | +} | ||
| 505 | + | ||
| 506 | +/// Current value of [`PALETTE_SPLIT_TX_HITS`]. | ||
| 507 | +pub(crate) fn palette_split_tx_hits() -> usize { | ||
| 508 | + PALETTE_SPLIT_TX_HITS.with(|c| c.get()) | ||
| 509 | +} | ||
| 510 | + | ||
| 454 | thread_local! { | 511 | thread_local! { |
| 455 | /// A just-decoded palette-Y block's own predicted pixels | 512 | /// A just-decoded palette-Y block's own predicted pixels |
| 456 | /// (`side*side`, row-major, `colors[map[i]]`), consumed by | 513 | /// (`side*side`, row-major, `colors[map[i]]`), consumed by |
| @@ -460,7 +517,7 @@ thread_local! { | |||
| 460 | /// alternative this avoids). Always empty again once that call consumes | 517 | /// alternative this avoids). Always empty again once that call consumes |
| 461 | /// it (`.take()`), so a non-palette block's own `reconstruct` call never | 518 | /// it (`.take()`), so a non-palette block's own `reconstruct` call never |
| 462 | /// sees stale state. | 519 | /// sees stale state. |
| 463 | - static PALETTE_PRED: std::cell::RefCell<Option<Vec<u8>>> = | 520 | + static PALETTE_PRED: std::cell::RefCell<Option<Vec<u16>>> = |
| 464 | const { std::cell::RefCell::new(None) }; | 521 | const { std::cell::RefCell::new(None) }; |
| 465 | } | 522 | } |
| 466 | 523 | ||
| @@ -621,6 +678,20 @@ pub(crate) fn rect_coeff_hits() -> usize { | |||
| 621 | RECT_COEFF_HITS.with(|c| c.get()) | 678 | RECT_COEFF_HITS.with(|c| c.get()) |
| 622 | } | 679 | } |
| 623 | 680 | ||
| 681 | +// lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 682 | +// blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the | ||
| 683 | +// gate's proof this round's arms actually reached a real block, not just | ||
| 684 | +// that `partition_w64` read one of those two symbol values. | ||
| 685 | +thread_local! { | ||
| 686 | + static SB_RECT_HITS: std::cell::Cell<usize> = | ||
| 687 | + const { std::cell::Cell::new(0) }; | ||
| 688 | +} | ||
| 689 | + | ||
| 690 | +/// Current value of [`SB_RECT_HITS`]. | ||
| 691 | +pub(crate) fn sb_rect_hits() -> usize { | ||
| 692 | + SB_RECT_HITS.with(|c| c.get()) | ||
| 693 | +} | ||
| 694 | + | ||
| 624 | // lane-partab r1: how many 32x32 quadrants decoded an AB partition | 695 | // lane-partab r1: how many 32x32 quadrants decoded an AB partition |
| 625 | // (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one | 696 | // (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one |
| 626 | // 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the | 697 | // 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the |
| @@ -920,7 +991,14 @@ fn nz_map_ctx_offset_1d(i: usize) -> usize { | |||
| 920 | } | 991 | } |
| 921 | } | 992 | } |
| 922 | 993 | ||
| 923 | -fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize, class: TxClass) -> usize { | 994 | +fn base_ctx( |
| 995 | + grid: &[i32], | ||
| 996 | + side: usize, | ||
| 997 | + row: usize, | ||
| 998 | + col: usize, | ||
| 999 | + class: TxClass, | ||
| 1000 | + rect_shape: Option<(usize, usize)>, | ||
| 1001 | +) -> usize { | ||
| 924 | // libaom's `get_nz_map_ctx_from_stats` only special-cases the DC | 1002 | // libaom's `get_nz_map_ctx_from_stats` only special-cases the DC |
| 925 | // coefficient to ctx 0 for `TX_CLASS_2D` (`(tx_class | coeff_idx) == 0`, | 1003 | // coefficient to ctx 0 for `TX_CLASS_2D` (`(tx_class | coeff_idx) == 0`, |
| 926 | // txb_common.h) -- `V_DCT`/`H_DCT` (class `Horiz`/`Vert`) still run the DC | 1004 | // txb_common.h) -- `V_DCT`/`H_DCT` (class `Horiz`/`Vert`) still run the DC |
| @@ -943,7 +1021,22 @@ fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize, class: TxClass) - | |||
| 943 | .sum(); | 1021 | .sum(); |
| 944 | let ctx = ((mag + 1) >> 1).min(4) as usize; | 1022 | let ctx = ((mag + 1) >> 1).min(4) as usize; |
| 945 | match class { | 1023 | match class { |
| 946 | - TxClass::TwoD => ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize, | 1024 | + // libaom's CDF *set* for a truncated 64-wide/tall corner resolves |
| 1025 | + // through `get_txsize_entropy_ctx` to the square `TX_64X64` (this | ||
| 1026 | + // decoder's `TxbSet::Luma64`), but `get_nz_map_ctx_from_stats` | ||
| 1027 | + // separately indexes `av1_nz_map_ctx_offset` by the raw, un-adjusted | ||
| 1028 | + // `tx_size` -- `TX_32X64`/`TX_64X32` for a superblock-level HORZ/VERT | ||
| 1029 | + // strip, which own a genuinely different table from the square one | ||
| 1030 | + // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the | ||
| 1031 | + // square table vs the real ctx 13 the rect table gives). | ||
| 1032 | + TxClass::TwoD => { | ||
| 1033 | + let table = match rect_shape { | ||
| 1034 | + Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64, | ||
| 1035 | + Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32, | ||
| 1036 | + _ => &cdf::NZ_MAP_CTX_OFFSET_32, | ||
| 1037 | + }; | ||
| 1038 | + ctx + table[row.min(4)][col.min(4)] as usize | ||
| 1039 | + } | ||
| 947 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), | 1040 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), |
| 948 | TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), | 1041 | TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), |
| 949 | } | 1042 | } |
| @@ -1166,7 +1259,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) -> | |||
| 1166 | } | 1259 | } |
| 1167 | let group = dec.symbol(eob_pt) + 1; | 1260 | let group = dec.symbol(eob_pt) + 1; |
| 1168 | if trace { | 1261 | if trace { |
| 1169 | - eprintln!("TRACE eob_pt value={group}"); | 1262 | + eprintln!("TRACE eob_pt value={group} rng={}", dec.debug_state().0); |
| 1170 | } | 1263 | } |
| 1171 | let bits = OFFSET_BITS[group]; | 1264 | let bits = OFFSET_BITS[group]; |
| 1172 | let mut offset = 0u32; | 1265 | let mut offset = 0u32; |
| @@ -1236,6 +1329,13 @@ fn read_coeffs( | |||
| 1236 | // a size the spec forces to `DCT_DCT` regardless of mode (32-point and | 1329 | // a size the spec forces to `DCT_DCT` regardless of mode (32-point and |
| 1237 | // up, `EXT_TX_SET_DCTONLY`) -- the caller already folds that in. | 1330 | // up, `EXT_TX_SET_DCTONLY`) -- the caller already folds that in. |
| 1238 | default_tx_type: TxType, | 1331 | default_tx_type: TxType, |
| 1332 | + // `Some((w, h))` with `w != h` when this read is a superblock-level | ||
| 1333 | + // HORZ/VERT strip's truncated luma corner: the CDF *set* resolves square | ||
| 1334 | + // (`side`/`coding` above), but `av1_nz_map_ctx_offset`'s position table | ||
| 1335 | + // is indexed by the real, un-adjusted rectangular shape (lane-sbpart r8 | ||
| 1336 | + // root cause, see [`base_ctx`]). `None` everywhere else -- every other | ||
| 1337 | + // caller's block genuinely is `side` x `side`. | ||
| 1338 | + rect_shape: Option<(usize, usize)>, | ||
| 1239 | ) -> Result<(Vec<i32>, TxType)> { | 1339 | ) -> Result<(Vec<i32>, TxType)> { |
| 1240 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 1340 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 1241 | let side = coding.side; | 1341 | let side = coding.side; |
| @@ -1321,7 +1421,7 @@ fn read_coeffs( | |||
| 1321 | } | 1421 | } |
| 1322 | v | 1422 | v |
| 1323 | } else { | 1423 | } else { |
| 1324 | - let ctx = base_ctx(&levels, side, row, col, class); | 1424 | + let ctx = base_ctx(&levels, side, row, col, class, rect_shape); |
| 1325 | let v = dec.symbol(&mut coding.base[ctx]) as i32; | 1425 | let v = dec.symbol(&mut coding.base[ctx]) as i32; |
| 1326 | if trace { | 1426 | if trace { |
| 1327 | eprintln!( | 1427 | eprintln!( |
| @@ -1630,6 +1730,13 @@ struct Neighbours { | |||
| 1630 | left_palette_size: Vec<usize>, | 1730 | left_palette_size: Vec<usize>, |
| 1631 | above_palette_colors: Vec<[u16; 8]>, | 1731 | above_palette_colors: Vec<[u16; 8]>, |
| 1632 | left_palette_colors: Vec<[u16; 8]>, | 1732 | left_palette_colors: Vec<[u16; 8]>, |
| 1733 | + /// As the four fields above, for the neighbour's own chroma (U-channel | ||
| 1734 | + /// only -- `av1_get_palette_cache`'s plane-1 lookup, [`Self::palette_uv_cache`]) | ||
| 1735 | + /// palette size/colours (lane-palette2 r1). | ||
| 1736 | + above_palette_uv_size: Vec<usize>, | ||
| 1737 | + left_palette_uv_size: Vec<usize>, | ||
| 1738 | + above_palette_uv_colors: Vec<[u16; 8]>, | ||
| 1739 | + left_palette_uv_colors: Vec<[u16; 8]>, | ||
| 1633 | /// This tile's own top-left corner, in 4x4 mode-info units (spec | 1740 | /// This tile's own top-left corner, in 4x4 mode-info units (spec |
| 1634 | /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a | 1741 | /// `MiRowStart`/`MiColStart`) -- lane-tiles: every "is there really a |
| 1635 | /// neighbour" check compares against this instead of literal `0`, since a | 1742 | /// neighbour" check compares against this instead of literal `0`, since a |
| @@ -1684,6 +1791,10 @@ impl Neighbours { | |||
| 1684 | left_palette_size: vec![0; rows], | 1791 | left_palette_size: vec![0; rows], |
| 1685 | above_palette_colors: vec![[0u16; 8]; cols], | 1792 | above_palette_colors: vec![[0u16; 8]; cols], |
| 1686 | left_palette_colors: vec![[0u16; 8]; rows], | 1793 | left_palette_colors: vec![[0u16; 8]; rows], |
| 1794 | + above_palette_uv_size: vec![0; cols], | ||
| 1795 | + left_palette_uv_size: vec![0; rows], | ||
| 1796 | + above_palette_uv_colors: vec![[0u16; 8]; cols], | ||
| 1797 | + left_palette_uv_colors: vec![[0u16; 8]; rows], | ||
| 1687 | tile_row0_mi: 0, | 1798 | tile_row0_mi: 0, |
| 1688 | tile_col0_mi: 0, | 1799 | tile_col0_mi: 0, |
| 1689 | } | 1800 | } |
| @@ -1789,6 +1900,70 @@ impl Neighbours { | |||
| 1789 | (ctx, cache) | 1900 | (ctx, cache) |
| 1790 | } | 1901 | } |
| 1791 | 1902 | ||
| 1903 | + /// As [`Self::record_palette_y`], for a just-decoded block's own chroma | ||
| 1904 | + /// (U-channel) palette size/colours -- `size == 0` clears stale state the | ||
| 1905 | + /// same way (lane-palette2 r1). | ||
| 1906 | + fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { | ||
| 1907 | + let (r, c) = at; | ||
| 1908 | + for cell in 0..side / SUB { | ||
| 1909 | + self.above_palette_uv_size[c + cell] = size; | ||
| 1910 | + self.above_palette_uv_colors[c + cell] = colors; | ||
| 1911 | + } | ||
| 1912 | + for cell in 0..side / SUB { | ||
| 1913 | + self.left_palette_uv_size[r + cell] = size; | ||
| 1914 | + self.left_palette_uv_colors[r + cell] = colors; | ||
| 1915 | + } | ||
| 1916 | + } | ||
| 1917 | + | ||
| 1918 | + /// [`Self::palette_ctx_and_cache`]'s cache half, for the U channel | ||
| 1919 | + /// (`av1_get_palette_cache(xd, 1, cache)`) -- `palette_uv_mode_ctx` needs | ||
| 1920 | + /// no neighbour lookup at all (it is this block's own just-decided Y | ||
| 1921 | + /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`), | ||
| 1922 | + /// so only the cache is wanted here. | ||
| 1923 | + fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> { | ||
| 1924 | + let (r, c) = at; | ||
| 1925 | + let above_ok = r % 4 != 0; | ||
| 1926 | + let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { | ||
| 1927 | + (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) | ||
| 1928 | + } else { | ||
| 1929 | + (0, [0u16; 8]) | ||
| 1930 | + }; | ||
| 1931 | + let (left_n, left_colors) = if self.left_palette_uv_size[r] > 0 { | ||
| 1932 | + (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) | ||
| 1933 | + } else { | ||
| 1934 | + (0, [0u16; 8]) | ||
| 1935 | + }; | ||
| 1936 | + let mut cache = Vec::with_capacity(16); | ||
| 1937 | + let push_dedup = |cache: &mut Vec<u16>, v: u16| { | ||
| 1938 | + if cache.last() != Some(&v) { | ||
| 1939 | + cache.push(v); | ||
| 1940 | + } | ||
| 1941 | + }; | ||
| 1942 | + let (mut ai, mut li) = (0usize, 0usize); | ||
| 1943 | + while ai < above_n && li < left_n { | ||
| 1944 | + let (va, vl) = (above_colors[ai], left_colors[li]); | ||
| 1945 | + if vl < va { | ||
| 1946 | + push_dedup(&mut cache, vl); | ||
| 1947 | + li += 1; | ||
| 1948 | + } else { | ||
| 1949 | + push_dedup(&mut cache, va); | ||
| 1950 | + ai += 1; | ||
| 1951 | + if vl == va { | ||
| 1952 | + li += 1; | ||
| 1953 | + } | ||
| 1954 | + } | ||
| 1955 | + } | ||
| 1956 | + while ai < above_n { | ||
| 1957 | + push_dedup(&mut cache, above_colors[ai]); | ||
| 1958 | + ai += 1; | ||
| 1959 | + } | ||
| 1960 | + while li < left_n { | ||
| 1961 | + push_dedup(&mut cache, left_colors[li]); | ||
| 1962 | + li += 1; | ||
| 1963 | + } | ||
| 1964 | + cache | ||
| 1965 | + } | ||
| 1966 | + | ||
| 1792 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its own | 1967 | /// Marks every 4x4 mi cell a just-decoded coded block covers with its own |
| 1793 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's | 1968 | /// transform width (in pixels) and `is_inter` flag -- the loop filter's |
| 1794 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and | 1969 | /// per-edge lookup (`apply_deblock`), filled at the same call sites and |
| @@ -2339,15 +2514,22 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |||
| 2339 | /// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <= | 2514 | /// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <= |
| 2340 | /// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus | 2515 | /// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus |
| 2341 | /// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize] | 2516 | /// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize] |
| 2342 | -/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `2*log2(side) - 6` for this | 2517 | +/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `log2(bw*bh) - 6`) -- `None` past |
| 2343 | -/// decoder's square-only blocks) -- `None` past the bound (never gates a | 2518 | +/// the bound (never gates a palette read), `Some(bsize_ctx)` otherwise. |
| 2344 | -/// palette read), `Some(bsize_ctx)` otherwise. | ||
| 2345 | fn palette_bsize_ctx(side: usize) -> Option<usize> { | 2519 | fn palette_bsize_ctx(side: usize) -> Option<usize> { |
| 2346 | - match side { | 2520 | + palette_bsize_ctx_wh(side, side) |
| 2347 | - 8 => Some(0), | 2521 | +} |
| 2348 | - 16 => Some(2), | 2522 | + |
| 2349 | - 32 => Some(4), | 2523 | +/// [`palette_bsize_ctx`], generalised to a true `bw`x`bh` rect strip |
| 2350 | - 64 => Some(6), | 2524 | +/// (lane-palette2 r1) -- the same `log2(bw*bh) - 6` formula, this decoder's |
| 2525 | +/// square call sites are just `bw == bh`. | ||
| 2526 | +fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { | ||
| 2527 | + match (bw, bh) { | ||
| 2528 | + (8, 8) => Some(0), | ||
| 2529 | + (16, 16) => Some(2), | ||
| 2530 | + (32, 16) | (16, 32) => Some(3), | ||
| 2531 | + (32, 32) => Some(4), | ||
| 2532 | + (64, 64) => Some(6), | ||
| 2351 | _ => None, | 2533 | _ => None, |
| 2352 | } | 2534 | } |
| 2353 | } | 2535 | } |
| @@ -2361,6 +2543,17 @@ struct PaletteY { | |||
| 2361 | map: Vec<u8>, | 2543 | map: Vec<u8>, |
| 2362 | } | 2544 | } |
| 2363 | 2545 | ||
| 2546 | +/// As [`PaletteY`], for a just-decoded chroma palette block: one shared | ||
| 2547 | +/// per-pixel colour-index map (spec `av1_visit_palette`'s plane-1 pass is | ||
| 2548 | +/// shared between U and V, both co-located after 4:2:0 subsampling) plus | ||
| 2549 | +/// each plane's own base colours. | ||
| 2550 | +struct PaletteUv { | ||
| 2551 | + size: usize, | ||
| 2552 | + u_colors: [u16; 8], | ||
| 2553 | + v_colors: [u16; 8], | ||
| 2554 | + map: Vec<u8>, | ||
| 2555 | +} | ||
| 2556 | + | ||
| 2364 | /// `aom_ceil_log2` (aom_dsp/bitwriter_buffer.h-adjacent helper, used both by | 2557 | /// `aom_ceil_log2` (aom_dsp/bitwriter_buffer.h-adjacent helper, used both by |
| 2365 | /// `read_palette_colors_y`'s shrinking `bits` and `av1_read_uniform`'s | 2558 | /// `read_palette_colors_y`'s shrinking `bits` and `av1_read_uniform`'s |
| 2366 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with | 2559 | /// `get_unsigned_bits`, which is the same formula): smallest `n` with |
| @@ -2446,6 +2639,74 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u | |||
| 2446 | colors | 2639 | colors |
| 2447 | } | 2640 | } |
| 2448 | 2641 | ||
| 2642 | +/// `read_palette_colors_uv` (decodemv.c:509), bit_depth fixed at 8: U reads | ||
| 2643 | +/// exactly [`read_palette_colors_y`]'s cache/delta scheme (against the U-only | ||
| 2644 | +/// cache, `range` starting at `255 - prev` with no `-1`, and each raw `delta` | ||
| 2645 | +/// unbiased by `+1` -- both differences from Y's own reader, matching the C | ||
| 2646 | +/// side by side). V never uses a cache: a leading bit picks either `n` raw | ||
| 2647 | +/// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 | ||
| 2648 | +/// rather than clamp. | ||
| 2649 | +fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ([u16; 8], [u16; 8]) { | ||
| 2650 | + let mut cached = Vec::with_capacity(n); | ||
| 2651 | + for &c in cache { | ||
| 2652 | + if cached.len() >= n { | ||
| 2653 | + break; | ||
| 2654 | + } | ||
| 2655 | + if dec.literal(1) == 1 { | ||
| 2656 | + cached.push(c); | ||
| 2657 | + } | ||
| 2658 | + } | ||
| 2659 | + let mut u_colors = [0u16; 8]; | ||
| 2660 | + let n_cached = cached.len(); | ||
| 2661 | + if n_cached < n { | ||
| 2662 | + let mut transmitted = Vec::with_capacity(n - n_cached); | ||
| 2663 | + let first = dec.literal(8) as u16; | ||
| 2664 | + transmitted.push(first); | ||
| 2665 | + if n_cached + 1 < n { | ||
| 2666 | + let min_bits = 8u32 - 3; | ||
| 2667 | + let mut bits = min_bits + dec.literal(2); | ||
| 2668 | + let mut range = 255i32 - i32::from(first); | ||
| 2669 | + for _ in (n_cached + 1)..n { | ||
| 2670 | + let delta = dec.literal(bits) as i32; | ||
| 2671 | + let prev = *transmitted.last().unwrap(); | ||
| 2672 | + let val = (i32::from(prev) + delta).clamp(0, 255) as u16; | ||
| 2673 | + range -= i32::from(val) - i32::from(prev); | ||
| 2674 | + bits = bits.min(ceil_log2(range.max(0) as u32)); | ||
| 2675 | + transmitted.push(val); | ||
| 2676 | + } | ||
| 2677 | + } | ||
| 2678 | + let merged = merge_colors(&transmitted, &cached); | ||
| 2679 | + u_colors[..n].copy_from_slice(&merged); | ||
| 2680 | + } else { | ||
| 2681 | + u_colors[..n].copy_from_slice(&cached[..n]); | ||
| 2682 | + } | ||
| 2683 | + let mut v_colors = [0u16; 8]; | ||
| 2684 | + if dec.literal(1) == 1 { | ||
| 2685 | + let min_bits_v = 8u32 - 4; | ||
| 2686 | + let bits = min_bits_v + dec.literal(2); | ||
| 2687 | + v_colors[0] = dec.literal(8) as u16; | ||
| 2688 | + for i in 1..n { | ||
| 2689 | + let mut delta = dec.literal(bits) as i32; | ||
| 2690 | + if delta != 0 && dec.literal(1) == 1 { | ||
| 2691 | + delta = -delta; | ||
| 2692 | + } | ||
| 2693 | + let mut val = i32::from(v_colors[i - 1]) + delta; | ||
| 2694 | + if val < 0 { | ||
| 2695 | + val += 256; | ||
| 2696 | + } | ||
| 2697 | + if val >= 256 { | ||
| 2698 | + val -= 256; | ||
| 2699 | + } | ||
| 2700 | + v_colors[i] = val as u16; | ||
| 2701 | + } | ||
| 2702 | + } else { | ||
| 2703 | + for i in 0..n { | ||
| 2704 | + v_colors[i] = dec.literal(8) as u16; | ||
| 2705 | + } | ||
| 2706 | + } | ||
| 2707 | + (u_colors, v_colors) | ||
| 2708 | +} | ||
| 2709 | + | ||
| 2449 | /// `av1_palette_color_index_context_lookup` (entropymode.c:889): maps a | 2710 | /// `av1_palette_color_index_context_lookup` (entropymode.c:889): maps a |
| 2450 | /// `NUM_PALETTE_NEIGHBORS`-weighted score hash (`0..=8`) to the real | 2711 | /// `NUM_PALETTE_NEIGHBORS`-weighted score hash (`0..=8`) to the real |
| 2451 | /// `0..=4` context, `-1` for hashes no real neighbour configuration produces. | 2712 | /// `0..=4` context, `-1` for hashes no real neighbour configuration produces. |
| @@ -2514,7 +2775,13 @@ fn palette_color_index_context( | |||
| 2514 | /// region (every other skip/residual path here does the same), so no | 2775 | /// region (every other skip/residual path here does the same), so no |
| 2515 | /// rows/cols-vs-plane_width/height cropping special case is needed, unlike | 2776 | /// rows/cols-vs-plane_width/height cropping special case is needed, unlike |
| 2516 | /// libaom's own non-block-aligned split. | 2777 | /// libaom's own non-block-aligned split. |
| 2517 | -fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, side: usize) -> Vec<u8> { | 2778 | +fn decode_color_index_map( |
| 2779 | + dec: &mut SymbolDecoder, | ||
| 2780 | + cdfs: &mut Cdfs, | ||
| 2781 | + n: usize, | ||
| 2782 | + side: usize, | ||
| 2783 | + uv: bool, | ||
| 2784 | +) -> Vec<u8> { | ||
| 2518 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 2785 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 2519 | let mut map = vec![0u8; side * side]; | 2786 | let mut map = vec![0u8; side * side]; |
| 2520 | if trace { | 2787 | if trace { |
| @@ -2537,7 +2804,11 @@ fn decode_color_index_map(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, n: usize, si | |||
| 2537 | let (rng, _) = dec.debug_state(); | 2804 | let (rng, _) = dec.debug_state(); |
| 2538 | eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); | 2805 | eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); |
| 2539 | } | 2806 | } |
| 2540 | - let symbol = dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]); | 2807 | + let symbol = if uv { |
| 2808 | + dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) | ||
| 2809 | + } else { | ||
| 2810 | + dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]) | ||
| 2811 | + }; | ||
| 2541 | map[row * side + col] = color_order[symbol]; | 2812 | map[row * side + col] = color_order[symbol]; |
| 2542 | if trace { | 2813 | if trace { |
| 2543 | let (rng, _) = dec.debug_state(); | 2814 | let (rng, _) = dec.debug_state(); |
| @@ -2587,26 +2858,44 @@ fn read_intra_mode_rect( | |||
| 2587 | is consumed for square blocks only)", | 2858 | is consumed for square blocks only)", |
| 2588 | )); | 2859 | )); |
| 2589 | } | 2860 | } |
| 2861 | + let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); | ||
| 2862 | + macro_rules! istep { | ||
| 2863 | + ($name:literal, $val:expr) => { | ||
| 2864 | + if ec_istep { | ||
| 2865 | + let (rng, _) = dec.debug_state(); | ||
| 2866 | + eprintln!( | ||
| 2867 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={rng}", | ||
| 2868 | + $name, $val | ||
| 2869 | + ); | ||
| 2870 | + } | ||
| 2871 | + }; | ||
| 2872 | + } | ||
| 2590 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 2873 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 2874 | + istep!("skip", skip as i32); | ||
| 2591 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | 2875 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); |
| 2876 | + istep!("cdef", 0); | ||
| 2592 | // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never | 2877 | // A HORZ/VERT rect strip is never the whole superblock (`bw`/`bh` never |
| 2593 | // both 64 here -- see this fn's own doc), so `is_whole_sb` is always | 2878 | // both 64 here -- see this fn's own doc), so `is_whole_sb` is always |
| 2594 | // `false`. | 2879 | // `false`. |
| 2595 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); | 2880 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); |
| 2596 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); | 2881 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); |
| 2882 | + istep!("dq", 0); | ||
| 2597 | let above_ctx = INTRA_MODE_CTX[above_mode]; | 2883 | let above_ctx = INTRA_MODE_CTX[above_mode]; |
| 2598 | let left_ctx = INTRA_MODE_CTX[left_mode]; | 2884 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 2599 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | 2885 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| 2886 | + istep!("mode", mode as i32); | ||
| 2600 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | 2887 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { |
| 2601 | read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) | 2888 | read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) |
| 2602 | } else { | 2889 | } else { |
| 2603 | 0 | 2890 | 0 |
| 2604 | }; | 2891 | }; |
| 2892 | + istep!("angle_y", angle_delta_y); | ||
| 2605 | let uv_mode = if cfl { | 2893 | let uv_mode = if cfl { |
| 2606 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | 2894 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 2607 | } else { | 2895 | } else { |
| 2608 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | 2896 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 2609 | }; | 2897 | }; |
| 2898 | + istep!("uv_mode", uv_mode as i32); | ||
| 2610 | let alpha = if cfl && uv_mode == UV_CFL_PRED { | 2899 | let alpha = if cfl && uv_mode == UV_CFL_PRED { |
| 2611 | Some(read_cfl_alphas(dec, cdfs)) | 2900 | Some(read_cfl_alphas(dec, cdfs)) |
| 2612 | } else { | 2901 | } else { |
| @@ -2621,6 +2910,7 @@ fn read_intra_mode_rect( | |||
| 2621 | } else { | 2910 | } else { |
| 2622 | 0 | 2911 | 0 |
| 2623 | }; | 2912 | }; |
| 2913 | + istep!("angle_uv", angle_delta_uv); | ||
| 2624 | let mut filter_intra = None; | 2914 | let mut filter_intra = None; |
| 2625 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 2915 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 2626 | let (rng, _) = dec.debug_state(); | 2916 | let (rng, _) = dec.debug_state(); |
| @@ -3021,6 +3311,306 @@ fn decode_block_rect( | |||
| 3021 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); | 3311 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 3022 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); | 3312 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 3023 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); | 3313 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); |
| 3314 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 3315 | + eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}"); | ||
| 3316 | + } | ||
| 3317 | + Ok(()) | ||
| 3318 | +} | ||
| 3319 | + | ||
| 3320 | +/// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ | ||
| 3321 | +/// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / | ||
| 3322 | +/// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike | ||
| 3323 | +/// that 32x16/16x32 strip, both dimensions here exceed the 32-coefficient | ||
| 3324 | +/// cap, so LUMA needs the same corner truncation [`decode_block`] already | ||
| 3325 | +/// does for a plain 64x64 square (spec 5.11.40): `get_txsize_entropy_ctx` | ||
| 3326 | +/// resolves TX_64X32/TX_32X64 to TX_64X64 regardless of orientation (see | ||
| 3327 | +/// this function's own charter/report), so both strips read a real 32x32 | ||
| 3328 | +/// corner through [`read_coeffs`] with [`TxbSet::Luma64`]/[`SCAN_32`] and | ||
| 3329 | +/// embed it top-left of a zeroed `bw`x`bh` grid, mirroring | ||
| 3330 | +/// [`read_plane`]'s `tx_side != side` branch generalized to non-square. | ||
| 3331 | +/// CHROMA (TX_32X16/TX_16X32) resolves to TX_32X32 -- a real, *untruncated* | ||
| 3332 | +/// `bw/2`x`bh/2` transform via [`read_coeffs_rect`] with | ||
| 3333 | +/// [`TxbSet::ChromaRect32x16`] and the matching [`SCAN_32X16`]/ | ||
| 3334 | +/// [`SCAN_16X32`], same as [`decode_block_rect`]'s own chroma path. Like | ||
| 3335 | +/// that function, only the single-transform-unit (`tx_depth == 0`) case is | ||
| 3336 | +/// supported: a split transform refuses by name rather than guess-decode. | ||
| 3337 | +#[allow(clippy::too_many_arguments)] | ||
| 3338 | +fn decode_block_rect64( | ||
| 3339 | + dec: &mut SymbolDecoder, | ||
| 3340 | + cdfs: &mut Cdfs, | ||
| 3341 | + neighbours: &mut Neighbours, | ||
| 3342 | + at: (usize, usize), | ||
| 3343 | + bw: usize, | ||
| 3344 | + bh: usize, | ||
| 3345 | + y: &mut PlaneBuf, | ||
| 3346 | + u: &mut PlaneBuf, | ||
| 3347 | + v: &mut PlaneBuf, | ||
| 3348 | + enable_filter_intra: bool, | ||
| 3349 | + allow_screen_content_tools: bool, | ||
| 3350 | + base_q_idx: u8, | ||
| 3351 | + tx_select: bool, | ||
| 3352 | +) -> Result<()> { | ||
| 3353 | + let (r, c) = at; | ||
| 3354 | + let (px, py) = (c * SUB, r * SUB); | ||
| 3355 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | ||
| 3356 | + read_intra_mode_rect( | ||
| 3357 | + dec, | ||
| 3358 | + cdfs, | ||
| 3359 | + neighbours.above_mode[c], | ||
| 3360 | + neighbours.left_mode[r], | ||
| 3361 | + // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these | ||
| 3362 | + // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike | ||
| 3363 | + // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is | ||
| 3364 | + // correct), CFL must never be offered here -- passing `true` | ||
| 3365 | + // read `uv_mode` off the 14-symbol `uv_mode_cfl` CDF instead of | ||
| 3366 | + // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile | ||
| 3367 | + // from this block's very first symbol (lane-sbpart r3 bisect). | ||
| 3368 | + false, | ||
| 3369 | + bw, | ||
| 3370 | + bh, | ||
| 3371 | + enable_filter_intra, | ||
| 3372 | + neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), | ||
| 3373 | + allow_screen_content_tools, | ||
| 3374 | + r * (SUB / MI), | ||
| 3375 | + c * (SUB / MI), | ||
| 3376 | + )?; | ||
| 3377 | + let smooth_neighbor = | ||
| 3378 | + is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 3379 | + if smooth_neighbor { | ||
| 3380 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3381 | + } | ||
| 3382 | + let smooth_neighbor_uv = | ||
| 3383 | + is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | ||
| 3384 | + if filter_intra.is_some() { | ||
| 3385 | + // `filter_intra_size_class_rect` already returns `None` for both | ||
| 3386 | + // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at | ||
| 3387 | + // 32 on both axes), so this symbol is never read at this level -- | ||
| 3388 | + // kept only as the same defensive refusal [`decode_block_rect`] has. | ||
| 3389 | + return Err(unsupported( | ||
| 3390 | + "filter intra on a superblock-level HORZ/VERT strip (never expected -- \ | ||
| 3391 | + av1_filter_intra_allowed_bsize caps at 32x32)", | ||
| 3392 | + )); | ||
| 3393 | + } | ||
| 3394 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { | ||
| 3395 | + DC_PRED | ||
| 3396 | + } else { | ||
| 3397 | + uv_mode | ||
| 3398 | + }; | ||
| 3399 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 3400 | + let depth = if tx_select { | ||
| 3401 | + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); | ||
| 3402 | + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) | ||
| 3403 | + } else { | ||
| 3404 | + 0 | ||
| 3405 | + }; | ||
| 3406 | + if depth != 0 { | ||
| 3407 | + TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3408 | + return Err(unsupported( | ||
| 3409 | + "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ | ||
| 3410 | + prediction is not ported)", | ||
| 3411 | + )); | ||
| 3412 | + } | ||
| 3413 | + let (tx_w, tx_h) = (bw, bh); | ||
| 3414 | + let (cpx, cpy) = (px / 2, py / 2); | ||
| 3415 | + let (chroma_w, chroma_h) = (bw / 2, bh / 2); | ||
| 3416 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 3417 | + if skip { | ||
| 3418 | + y.reconstruct_rect( | ||
| 3419 | + px, | ||
| 3420 | + py, | ||
| 3421 | + bw, | ||
| 3422 | + bh, | ||
| 3423 | + mode, | ||
| 3424 | + angle_delta_y, | ||
| 3425 | + reach, | ||
| 3426 | + &vec![0i32; bw * bh], | ||
| 3427 | + None, | ||
| 3428 | + filter_intra, | ||
| 3429 | + smooth_neighbor, | ||
| 3430 | + ); | ||
| 3431 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 3432 | + u.reconstruct_rect( | ||
| 3433 | + cpx, | ||
| 3434 | + cpy, | ||
| 3435 | + chroma_w, | ||
| 3436 | + chroma_h, | ||
| 3437 | + uv_predict_mode, | ||
| 3438 | + angle_delta_uv, | ||
| 3439 | + reach, | ||
| 3440 | + &vec![0i32; chroma_w * chroma_h], | ||
| 3441 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 3442 | + None, | ||
| 3443 | + smooth_neighbor_uv, | ||
| 3444 | + ); | ||
| 3445 | + v.reconstruct_rect( | ||
| 3446 | + cpx, | ||
| 3447 | + cpy, | ||
| 3448 | + chroma_w, | ||
| 3449 | + chroma_h, | ||
| 3450 | + uv_predict_mode, | ||
| 3451 | + angle_delta_uv, | ||
| 3452 | + reach, | ||
| 3453 | + &vec![0i32; chroma_w * chroma_h], | ||
| 3454 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 3455 | + None, | ||
| 3456 | + smooth_neighbor_uv, | ||
| 3457 | + ); | ||
| 3458 | + neighbours.record_rect( | ||
| 3459 | + at, | ||
| 3460 | + bw, | ||
| 3461 | + bh, | ||
| 3462 | + mode, | ||
| 3463 | + uv_predict_mode, | ||
| 3464 | + &[ | ||
| 3465 | + vec![0i32; bw * bh], | ||
| 3466 | + vec![0i32; chroma_w * chroma_h], | ||
| 3467 | + vec![0i32; chroma_w * chroma_h], | ||
| 3468 | + ], | ||
| 3469 | + ); | ||
| 3470 | + } else { | ||
| 3471 | + let around = neighbours.around_rect(at, bw, bh); | ||
| 3472 | + // LUMA: a real 32x32 corner, embedded top-left of the true bw x bh | ||
| 3473 | + // grid (see this function's own doc comment). | ||
| 3474 | + let scan32 = default_scan(TX32); | ||
| 3475 | + let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); | ||
| 3476 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3477 | + let (rng, _) = dec.debug_state(); | ||
| 3478 | + eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size=64corner rng={rng}"); | ||
| 3479 | + } | ||
| 3480 | + let (luma_corner, luma_tx_type) = read_coeffs( | ||
| 3481 | + dec, | ||
| 3482 | + &mut luma_coding, | ||
| 3483 | + &scan32, | ||
| 3484 | + 0, | ||
| 3485 | + dc_sign_ctx(around[0].2), | ||
| 3486 | + TxType::DctDct, | ||
| 3487 | + Some((bw, bh)), | ||
| 3488 | + )?; | ||
| 3489 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3490 | + let (rng, _) = dec.debug_state(); | ||
| 3491 | + eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}"); | ||
| 3492 | + } | ||
| 3493 | + let mut luma_levels = vec![0i32; bw * bh]; | ||
| 3494 | + for row in 0..32 { | ||
| 3495 | + luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]); | ||
| 3496 | + } | ||
| 3497 | + let luma_residual = dequant_and_inverse_typed_wh( | ||
| 3498 | + &luma_levels, | ||
| 3499 | + bw, | ||
| 3500 | + bh, | ||
| 3501 | + 8, | ||
| 3502 | + i32::from(base_q_idx), | ||
| 3503 | + luma_tx_type, | ||
| 3504 | + ); | ||
| 3505 | + y.reconstruct_rect( | ||
| 3506 | + px, | ||
| 3507 | + py, | ||
| 3508 | + bw, | ||
| 3509 | + bh, | ||
| 3510 | + mode, | ||
| 3511 | + angle_delta_y, | ||
| 3512 | + reach, | ||
| 3513 | + &luma_residual, | ||
| 3514 | + None, | ||
| 3515 | + filter_intra, | ||
| 3516 | + smooth_neighbor, | ||
| 3517 | + ); | ||
| 3518 | + // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no | ||
| 3519 | + // corner crop needed (see doc comment). | ||
| 3520 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 3521 | + let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; | ||
| 3522 | + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | ||
| 3523 | + let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); | ||
| 3524 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3525 | + let (rng, _) = dec.debug_state(); | ||
| 3526 | + eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | ||
| 3527 | + } | ||
| 3528 | + let (u_levels, u_tx_type) = read_coeffs_rect( | ||
| 3529 | + dec, | ||
| 3530 | + &mut u_coding, | ||
| 3531 | + chroma_scan, | ||
| 3532 | + chroma_w, | ||
| 3533 | + chroma_h, | ||
| 3534 | + u_skip_ctx, | ||
| 3535 | + dc_sign_ctx(around[1].2), | ||
| 3536 | + TxType::DctDct, | ||
| 3537 | + )?; | ||
| 3538 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3539 | + let (rng, _) = dec.debug_state(); | ||
| 3540 | + eprintln!("EC_COEFF_VAL plane=1 row={mi_r} col={mi_c} rng={rng}"); | ||
| 3541 | + } | ||
| 3542 | + let u_residual = dequant_and_inverse_typed_wh( | ||
| 3543 | + &u_levels, | ||
| 3544 | + chroma_w, | ||
| 3545 | + chroma_h, | ||
| 3546 | + 8, | ||
| 3547 | + i32::from(base_q_idx), | ||
| 3548 | + u_tx_type, | ||
| 3549 | + ); | ||
| 3550 | + u.reconstruct_rect( | ||
| 3551 | + cpx, | ||
| 3552 | + cpy, | ||
| 3553 | + chroma_w, | ||
| 3554 | + chroma_h, | ||
| 3555 | + uv_predict_mode, | ||
| 3556 | + angle_delta_uv, | ||
| 3557 | + reach, | ||
| 3558 | + &u_residual, | ||
| 3559 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 3560 | + None, | ||
| 3561 | + smooth_neighbor_uv, | ||
| 3562 | + ); | ||
| 3563 | + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | ||
| 3564 | + let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); | ||
| 3565 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3566 | + let (rng, _) = dec.debug_state(); | ||
| 3567 | + eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); | ||
| 3568 | + } | ||
| 3569 | + let (v_levels, v_tx_type) = read_coeffs_rect( | ||
| 3570 | + dec, | ||
| 3571 | + &mut v_coding, | ||
| 3572 | + chroma_scan, | ||
| 3573 | + chroma_w, | ||
| 3574 | + chroma_h, | ||
| 3575 | + v_skip_ctx, | ||
| 3576 | + dc_sign_ctx(around[2].2), | ||
| 3577 | + TxType::DctDct, | ||
| 3578 | + )?; | ||
| 3579 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 3580 | + let (rng, _) = dec.debug_state(); | ||
| 3581 | + eprintln!("EC_COEFF_VAL plane=2 row={mi_r} col={mi_c} rng={rng}"); | ||
| 3582 | + } | ||
| 3583 | + let v_residual = dequant_and_inverse_typed_wh( | ||
| 3584 | + &v_levels, | ||
| 3585 | + chroma_w, | ||
| 3586 | + chroma_h, | ||
| 3587 | + 8, | ||
| 3588 | + i32::from(base_q_idx), | ||
| 3589 | + v_tx_type, | ||
| 3590 | + ); | ||
| 3591 | + v.reconstruct_rect( | ||
| 3592 | + cpx, | ||
| 3593 | + cpy, | ||
| 3594 | + chroma_w, | ||
| 3595 | + chroma_h, | ||
| 3596 | + uv_predict_mode, | ||
| 3597 | + angle_delta_uv, | ||
| 3598 | + reach, | ||
| 3599 | + &v_residual, | ||
| 3600 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 3601 | + None, | ||
| 3602 | + smooth_neighbor_uv, | ||
| 3603 | + ); | ||
| 3604 | + neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); | ||
| 3605 | + RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3606 | + } | ||
| 3607 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); | ||
| 3608 | + neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); | ||
| 3609 | + SB_RECT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3610 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 3611 | + let (rng, _) = dec.debug_state(); | ||
| 3612 | + eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}"); | ||
| 3613 | + } | ||
| 3024 | Ok(()) | 3614 | Ok(()) |
| 3025 | } | 3615 | } |
| 3026 | 3616 | ||
| @@ -3056,6 +3646,11 @@ fn read_intra_mode( | |||
| 3056 | // decoder reads either way -- but refuse by name the moment it fires, | 3646 | // decoder reads either way -- but refuse by name the moment it fires, |
| 3057 | // exactly the old behaviour. | 3647 | // exactly the old behaviour. |
| 3058 | palette: Option<(usize, &[u16])>, | 3648 | palette: Option<(usize, &[u16])>, |
| 3649 | + // The U-channel colour cache for a chroma palette read ([`Neighbours::palette_uv_cache`]), | ||
| 3650 | + // `&[]` at the excluded call sites -- same corner-cut as `palette` above, | ||
| 3651 | + // no `mode_ctx` needed (`palette_uv_mode_ctx` is this block's own just-read | ||
| 3652 | + // `use_palette_y`, not a neighbour lookup). | ||
| 3653 | + palette_uv_cache: &[u16], | ||
| 3059 | mi_r: usize, | 3654 | mi_r: usize, |
| 3060 | mi_c: usize, | 3655 | mi_c: usize, |
| 3061 | ) -> Result<( | 3656 | ) -> Result<( |
| @@ -3067,6 +3662,7 @@ fn read_intra_mode( | |||
| 3067 | Option<(i32, i32)>, | 3662 | Option<(i32, i32)>, |
| 3068 | Option<usize>, | 3663 | Option<usize>, |
| 3069 | Option<PaletteY>, | 3664 | Option<PaletteY>, |
| 3665 | + Option<PaletteUv>, | ||
| 3070 | )> { | 3666 | )> { |
| 3071 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 3667 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 3072 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 3668 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| @@ -3174,6 +3770,7 @@ fn read_intra_mode( | |||
| 3174 | // bit-for-bit through the Y colours, diverged only at the old inline | 3770 | // bit-for-bit through the Y colours, diverged only at the old inline |
| 3175 | // `decode_color_index_map` call). | 3771 | // `decode_color_index_map` call). |
| 3176 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | 3772 | let mut palette_y_pending: Option<(usize, [u16; 8])> = None; |
| 3773 | + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | ||
| 3177 | if allow_screen_content_tools | 3774 | if allow_screen_content_tools |
| 3178 | && let Some(bsize_ctx) = palette_bsize_ctx(side) | 3775 | && let Some(bsize_ctx) = palette_bsize_ctx(side) |
| 3179 | { | 3776 | { |
| @@ -3215,15 +3812,12 @@ fn read_intra_mode( | |||
| 3215 | // UV_DC_PRED`, regardless of whether Y just fired -- this decoder's | 3812 | // UV_DC_PRED`, regardless of whether Y just fired -- this decoder's |
| 3216 | // scope always reconstructs chroma alongside luma (`decode_block` | 3813 | // scope always reconstructs chroma alongside luma (`decode_block` |
| 3217 | // always calls `u.reconstruct`/`v.reconstruct`), so `is_chroma_ref` | 3814 | // always calls `u.reconstruct`/`v.reconstruct`), so `is_chroma_ref` |
| 3218 | - // is always true here and does not need threading in. UV palette | 3815 | + // is always true here and does not need threading in. |
| 3219 | - // reconstruction stays out of scope: refusing the moment the mode | ||
| 3220 | - // symbol fires needs no further reads (the whole decode aborts), | ||
| 3221 | - // so `palette_uv_size`/`read_palette_colors_uv` are never reached. | ||
| 3222 | let palette_uv_mode_ctx = usize::from(use_palette_y); | 3816 | let palette_uv_mode_ctx = usize::from(use_palette_y); |
| 3223 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { | 3817 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { |
| 3224 | - return Err(unsupported( | 3818 | + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); |
| 3225 | - "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 3819 | + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); |
| 3226 | - )); | 3820 | + palette_uv_pending = Some((n, u_colors, v_colors)); |
| 3227 | } | 3821 | } |
| 3228 | } | 3822 | } |
| 3229 | // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a | 3823 | // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a |
| @@ -3254,19 +3848,28 @@ fn read_intra_mode( | |||
| 3254 | filter_intra = Some(fi_mode); | 3848 | filter_intra = Some(fi_mode); |
| 3255 | } | 3849 | } |
| 3256 | } | 3850 | } |
| 3257 | - // `av1_visit_palette` (decoder.c:234): the colour-index-map decode runs | 3851 | + // `av1_visit_palette` (decoder.c:234): plane 0 (Y) then plane 1 (chroma, |
| 3258 | - // here, after every mode-info symbol for the block (including UV | 3852 | + // shared U/V map) -- the same order libaom's own loop visits them in. |
| 3259 | - // palette and filter_intra above) -- plane 0 (Y) only in this decoder's | ||
| 3260 | - // scope, since UV palette already refused by name above and never left | ||
| 3261 | - // a pending map to decode. | ||
| 3262 | let palette_y = palette_y_pending.map(|(n, colors)| { | 3853 | let palette_y = palette_y_pending.map(|(n, colors)| { |
| 3263 | - let map = decode_color_index_map(dec, cdfs, n, side); | 3854 | + let map = decode_color_index_map(dec, cdfs, n, side, false); |
| 3264 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); | 3855 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); |
| 3265 | if trace { | 3856 | if trace { |
| 3266 | eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); | 3857 | eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); |
| 3267 | } | 3858 | } |
| 3268 | PaletteY { size: n, colors, map } | 3859 | PaletteY { size: n, colors, map } |
| 3269 | }); | 3860 | }); |
| 3861 | + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | ||
| 3862 | + let map = decode_color_index_map(dec, cdfs, n, side / 2, true); | ||
| 3863 | + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3864 | + if trace { | ||
| 3865 | + eprintln!( | ||
| 3866 | + "TRACE palette_uv size={n} u_colors={:?} v_colors={:?}", | ||
| 3867 | + &u_colors[..n], | ||
| 3868 | + &v_colors[..n] | ||
| 3869 | + ); | ||
| 3870 | + } | ||
| 3871 | + PaletteUv { size: n, u_colors, v_colors, map } | ||
| 3872 | + }); | ||
| 3270 | Ok(( | 3873 | Ok(( |
| 3271 | skip, | 3874 | skip, |
| 3272 | mode, | 3875 | mode, |
| @@ -3276,6 +3879,7 @@ fn read_intra_mode( | |||
| 3276 | alpha, | 3879 | alpha, |
| 3277 | filter_intra, | 3880 | filter_intra, |
| 3278 | palette_y, | 3881 | palette_y, |
| 3882 | + palette_uv, | ||
| 3279 | )) | 3883 | )) |
| 3280 | } | 3884 | } |
| 3281 | 3885 | ||
| @@ -3357,7 +3961,7 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { | |||
| 3357 | /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone. | 3961 | /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone. |
| 3358 | #[derive(Clone)] | 3962 | #[derive(Clone)] |
| 3359 | struct PlaneBuf { | 3963 | struct PlaneBuf { |
| 3360 | - data: Vec<u8>, | 3964 | + data: Vec<u16>, |
| 3361 | width: usize, | 3965 | width: usize, |
| 3362 | height: usize, | 3966 | height: usize, |
| 3363 | /// The frame's true, decodable extent in this plane's own units — past | 3967 | /// The frame's true, decodable extent in this plane's own units — past |
| @@ -3410,7 +4014,7 @@ impl PlaneBuf { | |||
| 3410 | y: usize, | 4014 | y: usize, |
| 3411 | side: usize, | 4015 | side: usize, |
| 3412 | reach: Reach, | 4016 | reach: Reach, |
| 3413 | - ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) { | 4017 | + ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) { |
| 3414 | let own_across = x + side.min(self.true_width.saturating_sub(x)); | 4018 | let own_across = x + side.min(self.true_width.saturating_sub(x)); |
| 3415 | let across = if reach.above_right { | 4019 | let across = if reach.above_right { |
| 3416 | own_across + side.min(self.true_width.saturating_sub(own_across)) | 4020 | own_across + side.min(self.true_width.saturating_sub(own_across)) |
| @@ -3449,7 +4053,7 @@ impl PlaneBuf { | |||
| 3449 | bw: usize, | 4053 | bw: usize, |
| 3450 | bh: usize, | 4054 | bh: usize, |
| 3451 | reach: Reach, | 4055 | reach: Reach, |
| 3452 | - ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) { | 4056 | + ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) { |
| 3453 | let own_across = x + bw.min(self.true_width.saturating_sub(x)); | 4057 | let own_across = x + bw.min(self.true_width.saturating_sub(x)); |
| 3454 | let across = if reach.above_right { | 4058 | let across = if reach.above_right { |
| 3455 | own_across + bw.min(self.true_width.saturating_sub(own_across)) | 4059 | own_across + bw.min(self.true_width.saturating_sub(own_across)) |
| @@ -3497,7 +4101,7 @@ impl PlaneBuf { | |||
| 3497 | smooth_neighbor: bool, | 4101 | smooth_neighbor: bool, |
| 3498 | ) { | 4102 | ) { |
| 3499 | let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); | 4103 | let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); |
| 3500 | - let mut prediction = vec![0u8; bw * bh]; | 4104 | + let mut prediction = vec![0u16; bw * bh]; |
| 3501 | if let Some(fi_mode) = filter_intra { | 4105 | if let Some(fi_mode) = filter_intra { |
| 3502 | crate::intra::predict_filter_intra( | 4106 | crate::intra::predict_filter_intra( |
| 3503 | fi_mode, | 4107 | fi_mode, |
| @@ -3527,9 +4131,9 @@ impl PlaneBuf { | |||
| 3527 | let idx = row * bw + col; | 4131 | let idx = row * bw + col; |
| 3528 | let mut base = i32::from(prediction[idx]); | 4132 | let mut base = i32::from(prediction[idx]); |
| 3529 | if let Some((alpha_q3, ac_q3)) = cfl { | 4133 | if let Some((alpha_q3, ac_q3)) = cfl { |
| 3530 | - base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, 255); | 4134 | + base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max()); |
| 3531 | } | 4135 | } |
| 3532 | - let sample = (base + residual[idx]).clamp(0, 255) as u8; | 4136 | + let sample = (base + residual[idx]).clamp(0, sample_max()) as u16; |
| 3533 | self.data[(y + row) * self.width + x + col] = sample; | 4137 | self.data[(y + row) * self.width + x + col] = sample; |
| 3534 | } | 4138 | } |
| 3535 | } | 4139 | } |
| @@ -3569,7 +4173,7 @@ impl PlaneBuf { | |||
| 3569 | buf | 4173 | buf |
| 3570 | } else { | 4174 | } else { |
| 3571 | let (above, left, corner) = self.edges(x, y, side, reach); | 4175 | let (above, left, corner) = self.edges(x, y, side, reach); |
| 3572 | - let mut prediction = vec![0u8; side * side]; | 4176 | + let mut prediction = vec![0u16; side * side]; |
| 3573 | if let Some(fi_mode) = filter_intra { | 4177 | if let Some(fi_mode) = filter_intra { |
| 3574 | crate::intra::predict_filter_intra( | 4178 | crate::intra::predict_filter_intra( |
| 3575 | fi_mode, | 4179 | fi_mode, |
| @@ -3608,9 +4212,9 @@ impl PlaneBuf { | |||
| 3608 | let idx = row * side + col; | 4212 | let idx = row * side + col; |
| 3609 | let mut base = i32::from(prediction[idx]); | 4213 | let mut base = i32::from(prediction[idx]); |
| 3610 | if let Some((alpha_q3, ac_q3)) = cfl { | 4214 | if let Some((alpha_q3, ac_q3)) = cfl { |
| 3611 | - base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, 255); | 4215 | + base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max()); |
| 3612 | } | 4216 | } |
| 3613 | - let sample = (base + residual[idx]).clamp(0, 255) as u8; | 4217 | + let sample = (base + residual[idx]).clamp(0, sample_max()) as u16; |
| 3614 | self.data[(y + row) * self.width + x + col] = sample; | 4218 | self.data[(y + row) * self.width + x + col] = sample; |
| 3615 | } | 4219 | } |
| 3616 | } | 4220 | } |
| @@ -3682,6 +4286,7 @@ fn read_plane( | |||
| 3682 | skip_ctx, | 4286 | skip_ctx, |
| 3683 | dc_sign_ctx(around.2), | 4287 | dc_sign_ctx(around.2), |
| 3684 | default_tx_type, | 4288 | default_tx_type, |
| 4289 | + None, | ||
| 3685 | )?; | 4290 | )?; |
| 3686 | // A 64x64 luma block's transform covers the whole 64x64 area, but only its | 4291 | // A 64x64 luma block's transform covers the whole 64x64 area, but only its |
| 3687 | // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the | 4292 | // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the |
| @@ -3766,7 +4371,8 @@ fn decode_block( | |||
| 3766 | let (r, c) = at; | 4371 | let (r, c) = at; |
| 3767 | let (px, py) = (c * SUB, r * SUB); | 4372 | let (px, py) = (c * SUB, r * SUB); |
| 3768 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 4373 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 3769 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y) = | 4374 | + let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 4375 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | ||
| 3770 | read_intra_mode( | 4376 | read_intra_mode( |
| 3771 | dec, | 4377 | dec, |
| 3772 | cdfs, | 4378 | cdfs, |
| @@ -3779,6 +4385,7 @@ fn decode_block( | |||
| 3779 | allow_screen_content_tools, | 4385 | allow_screen_content_tools, |
| 3780 | allow_intrabc, | 4386 | allow_intrabc, |
| 3781 | Some((palette_ctx, &palette_cache)), | 4387 | Some((palette_ctx, &palette_cache)), |
| 4388 | + &palette_uv_cache, | ||
| 3782 | r * (SUB / MI), | 4389 | r * (SUB / MI), |
| 3783 | c * (SUB / MI), | 4390 | c * (SUB / MI), |
| 3784 | )?; | 4391 | )?; |
| @@ -3839,9 +4446,24 @@ fn decode_block( | |||
| 3839 | "a palette block with a split luma transform (round 1)", | 4446 | "a palette block with a split luma transform (round 1)", |
| 3840 | )); | 4447 | )); |
| 3841 | } | 4448 | } |
| 3842 | - let buf: Vec<u8> = py.map.iter().map(|&idx| py.colors[idx as usize] as u8).collect(); | 4449 | + let buf: Vec<u16> = py |
| 4450 | + .map | ||
| 4451 | + .iter() | ||
| 4452 | + .map(|&idx| py.colors[idx as usize]) | ||
| 4453 | + .collect(); | ||
| 3843 | PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); | 4454 | PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); |
| 3844 | } | 4455 | } |
| 4456 | + // A UV-palette block's own chroma prediction override (lane-palette2 r1), | ||
| 4457 | + // same [`PALETTE_PRED`] slot as Y above -- set fresh right before each | ||
| 4458 | + // plane's own `reconstruct`/`read_plane` call below (never both planes at | ||
| 4459 | + // once), since Y's own set-then-take already emptied the slot by the time | ||
| 4460 | + // either of these run. | ||
| 4461 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| { | ||
| 4462 | + ( | ||
| 4463 | + puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), | ||
| 4464 | + puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), | ||
| 4465 | + ) | ||
| 4466 | + }); | ||
| 3845 | if skip { | 4467 | if skip { |
| 3846 | // A skipped block codes no residual syntax at all (spec 5.11.34): | 4468 | // A skipped block codes no residual syntax at all (spec 5.11.34): |
| 3847 | // straight prediction, on every plane. | 4469 | // straight prediction, on every plane. |
| @@ -3858,6 +4480,9 @@ fn decode_block( | |||
| 3858 | smooth_neighbor, | 4480 | smooth_neighbor, |
| 3859 | ); | 4481 | ); |
| 3860 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4482 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4483 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4484 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4485 | + } | ||
| 3861 | u.reconstruct( | 4486 | u.reconstruct( |
| 3862 | cpx, | 4487 | cpx, |
| 3863 | cpy, | 4488 | cpy, |
| @@ -3870,6 +4495,9 @@ fn decode_block( | |||
| 3870 | None, | 4495 | None, |
| 3871 | smooth_neighbor_uv, | 4496 | smooth_neighbor_uv, |
| 3872 | ); | 4497 | ); |
| 4498 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4499 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4500 | + } | ||
| 3873 | v.reconstruct( | 4501 | v.reconstruct( |
| 3874 | cpx, | 4502 | cpx, |
| 3875 | cpy, | 4503 | cpy, |
| @@ -3914,6 +4542,9 @@ fn decode_block( | |||
| 3914 | smooth_neighbor, | 4542 | smooth_neighbor, |
| 3915 | )?; | 4543 | )?; |
| 3916 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4544 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4545 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4546 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4547 | + } | ||
| 3917 | let u_grid = read_plane( | 4548 | let u_grid = read_plane( |
| 3918 | dec, | 4549 | dec, |
| 3919 | cdfs, | 4550 | cdfs, |
| @@ -3942,6 +4573,9 @@ fn decode_block( | |||
| 3942 | &u.data[cpy * u.width + cpx..][..chroma_side] | 4573 | &u.data[cpy * u.width + cpx..][..chroma_side] |
| 3943 | ); | 4574 | ); |
| 3944 | } | 4575 | } |
| 4576 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4577 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4578 | + } | ||
| 3945 | let v_grid = read_plane( | 4579 | let v_grid = read_plane( |
| 3946 | dec, | 4580 | dec, |
| 3947 | cdfs, | 4581 | cdfs, |
| @@ -4023,6 +4657,9 @@ fn decode_block( | |||
| 4023 | } | 4657 | } |
| 4024 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 4658 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 4025 | let chroma_around = neighbours.around(at, side); | 4659 | let chroma_around = neighbours.around(at, side); |
| 4660 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 4661 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | ||
| 4662 | + } | ||
| 4026 | let u_grid = read_plane( | 4663 | let u_grid = read_plane( |
| 4027 | dec, | 4664 | dec, |
| 4028 | cdfs, | 4665 | cdfs, |
| @@ -4045,6 +4682,9 @@ fn decode_block( | |||
| 4045 | None, | 4682 | None, |
| 4046 | smooth_neighbor_uv, | 4683 | smooth_neighbor_uv, |
| 4047 | )?; | 4684 | )?; |
| 4685 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 4686 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | ||
| 4687 | + } | ||
| 4048 | let v_grid = read_plane( | 4688 | let v_grid = read_plane( |
| 4049 | dec, | 4689 | dec, |
| 4050 | cdfs, | 4690 | cdfs, |
| @@ -4078,6 +4718,10 @@ fn decode_block( | |||
| 4078 | .as_ref() | 4718 | .as_ref() |
| 4079 | .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | 4719 | .map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 4080 | neighbours.record_palette_y(at, side, py_size, py_colors); | 4720 | neighbours.record_palette_y(at, side, py_size, py_colors); |
| 4721 | + let (puv_size, puv_colors) = palette_uv | ||
| 4722 | + .as_ref() | ||
| 4723 | + .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | ||
| 4724 | + neighbours.record_palette_uv(at, side, puv_size, puv_colors); | ||
| 4081 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); | 4725 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 4082 | neighbours.fill_lf_grid( | 4726 | neighbours.fill_lf_grid( |
| 4083 | (r * (SUB / MI), c * (SUB / MI)), | 4727 | (r * (SUB / MI), c * (SUB / MI)), |
| @@ -4135,7 +4779,7 @@ fn decode_leaf8( | |||
| 4135 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec | 4779 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec |
| 4136 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other | 4780 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other |
| 4137 | // `decode_block` caller at 16x16 and up. | 4781 | // `decode_block` caller at 16x16 and up. |
| 4138 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y) = | 4782 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = |
| 4139 | read_intra_mode( | 4783 | read_intra_mode( |
| 4140 | dec, | 4784 | dec, |
| 4141 | cdfs, | 4785 | cdfs, |
| @@ -4148,6 +4792,7 @@ fn decode_leaf8( | |||
| 4148 | allow_screen_content_tools, | 4792 | allow_screen_content_tools, |
| 4149 | allow_intrabc, | 4793 | allow_intrabc, |
| 4150 | None, | 4794 | None, |
| 4795 | + &[], | ||
| 4151 | leaf_mi.0, | 4796 | leaf_mi.0, |
| 4152 | leaf_mi.1, | 4797 | leaf_mi.1, |
| 4153 | )?; | 4798 | )?; |
| @@ -4594,7 +5239,7 @@ fn cdef_filter_block( | |||
| 4594 | if clipping_required { | 5239 | if clipping_required { |
| 4595 | y = y.clamp(min, max); | 5240 | y = y.clamp(min, max); |
| 4596 | } | 5241 | } |
| 4597 | - dst.data[(oy + i) * dst.width + (ox + j)] = y.clamp(0, 255) as u8; | 5242 | + dst.data[(oy + i) * dst.width + (ox + j)] = y.clamp(0, sample_max()) as u16; |
| 4598 | } | 5243 | } |
| 4599 | } | 5244 | } |
| 4600 | } | 5245 | } |
| @@ -5029,7 +5674,7 @@ fn filter14( | |||
| 5029 | /// the next along the edge's own filtering direction. | 5674 | /// the next along the edge's own filtering direction. |
| 5030 | #[allow(clippy::too_many_arguments)] | 5675 | #[allow(clippy::too_many_arguments)] |
| 5031 | fn filter_edge( | 5676 | fn filter_edge( |
| 5032 | - data: &mut [u8], | 5677 | + data: &mut [u16], |
| 5033 | base: usize, | 5678 | base: usize, |
| 5034 | outer_stride: isize, | 5679 | outer_stride: isize, |
| 5035 | tap_stride: isize, | 5680 | tap_stride: isize, |
| @@ -5049,10 +5694,10 @@ fn filter_edge( | |||
| 5049 | && (q1 - q0).abs() <= limit | 5694 | && (q1 - q0).abs() <= limit |
| 5050 | && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit; | 5695 | && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit; |
| 5051 | let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1); | 5696 | let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1); |
| 5052 | - data[idx(-2)] = op1.clamp(0, 255) as u8; | 5697 | + data[idx(-2)] = op1.clamp(0, sample_max()) as u16; |
| 5053 | - data[idx(-1)] = op0.clamp(0, 255) as u8; | 5698 | + data[idx(-1)] = op0.clamp(0, sample_max()) as u16; |
| 5054 | - data[idx(0)] = oq0.clamp(0, 255) as u8; | 5699 | + data[idx(0)] = oq0.clamp(0, sample_max()) as u16; |
| 5055 | - data[idx(1)] = oq1.clamp(0, 255) as u8; | 5700 | + data[idx(1)] = oq1.clamp(0, sample_max()) as u16; |
| 5056 | } | 5701 | } |
| 5057 | 6 => { | 5702 | 6 => { |
| 5058 | let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2)); | 5703 | let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2)); |
| @@ -5066,10 +5711,10 @@ fn filter_edge( | |||
| 5066 | && (p2 - p0).abs() <= 1 | 5711 | && (p2 - p0).abs() <= 1 |
| 5067 | && (q2 - q0).abs() <= 1; | 5712 | && (q2 - q0).abs() <= 1; |
| 5068 | let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2); | 5713 | let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2); |
| 5069 | - data[idx(-2)] = op1.clamp(0, 255) as u8; | 5714 | + data[idx(-2)] = op1.clamp(0, sample_max()) as u16; |
| 5070 | - data[idx(-1)] = op0.clamp(0, 255) as u8; | 5715 | + data[idx(-1)] = op0.clamp(0, sample_max()) as u16; |
| 5071 | - data[idx(0)] = oq0.clamp(0, 255) as u8; | 5716 | + data[idx(0)] = oq0.clamp(0, sample_max()) as u16; |
| 5072 | - data[idx(1)] = oq1.clamp(0, 255) as u8; | 5717 | + data[idx(1)] = oq1.clamp(0, sample_max()) as u16; |
| 5073 | } | 5718 | } |
| 5074 | 8 => { | 5719 | 8 => { |
| 5075 | let (p3, p2, p1, p0, q0, q1, q2, q3) = | 5720 | let (p3, p2, p1, p0, q0, q1, q2, q3) = |
| @@ -5089,12 +5734,12 @@ fn filter_edge( | |||
| 5089 | && (q3 - q0).abs() <= 1; | 5734 | && (q3 - q0).abs() <= 1; |
| 5090 | let [op2, op1, op0, oq0, oq1, oq2] = | 5735 | let [op2, op1, op0, oq0, oq1, oq2] = |
| 5091 | filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3); | 5736 | filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3); |
| 5092 | - data[idx(-3)] = op2.clamp(0, 255) as u8; | 5737 | + data[idx(-3)] = op2.clamp(0, sample_max()) as u16; |
| 5093 | - data[idx(-2)] = op1.clamp(0, 255) as u8; | 5738 | + data[idx(-2)] = op1.clamp(0, sample_max()) as u16; |
| 5094 | - data[idx(-1)] = op0.clamp(0, 255) as u8; | 5739 | + data[idx(-1)] = op0.clamp(0, sample_max()) as u16; |
| 5095 | - data[idx(0)] = oq0.clamp(0, 255) as u8; | 5740 | + data[idx(0)] = oq0.clamp(0, sample_max()) as u16; |
| 5096 | - data[idx(1)] = oq1.clamp(0, 255) as u8; | 5741 | + data[idx(1)] = oq1.clamp(0, sample_max()) as u16; |
| 5097 | - data[idx(2)] = oq2.clamp(0, 255) as u8; | 5742 | + data[idx(2)] = oq2.clamp(0, sample_max()) as u16; |
| 5098 | } | 5743 | } |
| 5099 | _ => { | 5744 | _ => { |
| 5100 | let (p6, p5, p4, p3, p2, p1, p0) = | 5745 | let (p6, p5, p4, p3, p2, p1, p0) = |
| @@ -5125,7 +5770,7 @@ fn filter_edge( | |||
| 5125 | q6, | 5770 | q6, |
| 5126 | ); | 5771 | ); |
| 5127 | for (k, v) in (-6..=5isize).zip(out) { | 5772 | for (k, v) in (-6..=5isize).zip(out) { |
| 5128 | - data[idx(k)] = v.clamp(0, 255) as u8; | 5773 | + data[idx(k)] = v.clamp(0, sample_max()) as u16; |
| 5129 | } | 5774 | } |
| 5130 | } | 5775 | } |
| 5131 | } | 5776 | } |
| @@ -5524,7 +6169,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5524 | let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK); | 6169 | let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK); |
| 5525 | 6170 | ||
| 5526 | let mut y = PlaneBuf { | 6171 | let mut y = PlaneBuf { |
| 5527 | - data: vec![0u8; width * height], | 6172 | + data: vec![0u16; width * height], |
| 5528 | width, | 6173 | width, |
| 5529 | height, | 6174 | height, |
| 5530 | true_width, | 6175 | true_width, |
| @@ -5535,7 +6180,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5535 | tile_y1: height, | 6180 | tile_y1: height, |
| 5536 | }; | 6181 | }; |
| 5537 | let mut u = PlaneBuf { | 6182 | let mut u = PlaneBuf { |
| 5538 | - data: vec![0u8; width * height / 4], | 6183 | + data: vec![0u16; width * height / 4], |
| 5539 | width: width / 2, | 6184 | width: width / 2, |
| 5540 | height: height / 2, | 6185 | height: height / 2, |
| 5541 | true_width: true_width / 2, | 6186 | true_width: true_width / 2, |
| @@ -5546,7 +6191,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5546 | tile_y1: height / 2, | 6191 | tile_y1: height / 2, |
| 5547 | }; | 6192 | }; |
| 5548 | let mut v = PlaneBuf { | 6193 | let mut v = PlaneBuf { |
| 5549 | - data: vec![0u8; width * height / 4], | 6194 | + data: vec![0u16; width * height / 4], |
| 5550 | width: width / 2, | 6195 | width: width / 2, |
| 5551 | height: height / 2, | 6196 | height: height / 2, |
| 5552 | true_width: true_width / 2, | 6197 | true_width: true_width / 2, |
| @@ -6042,6 +6687,73 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6042 | } | 6687 | } |
| 6043 | } | 6688 | } |
| 6044 | } | 6689 | } |
| 6690 | + PARTITION_HORZ => { | ||
| 6691 | + // lane-sbpart r2: two true 64x32 strips. | ||
| 6692 | + decode_block_rect64( | ||
| 6693 | + &mut dec, | ||
| 6694 | + &mut cdfs, | ||
| 6695 | + &mut neighbours, | ||
| 6696 | + at, | ||
| 6697 | + 64, | ||
| 6698 | + 32, | ||
| 6699 | + &mut y, | ||
| 6700 | + &mut u, | ||
| 6701 | + &mut v, | ||
| 6702 | + enable_filter_intra, | ||
| 6703 | + allow_screen_content_tools, | ||
| 6704 | + base_q_idx, | ||
| 6705 | + tx_select, | ||
| 6706 | + )?; | ||
| 6707 | + decode_block_rect64( | ||
| 6708 | + &mut dec, | ||
| 6709 | + &mut cdfs, | ||
| 6710 | + &mut neighbours, | ||
| 6711 | + (at.0 + 2, at.1), | ||
| 6712 | + 64, | ||
| 6713 | + 32, | ||
| 6714 | + &mut y, | ||
| 6715 | + &mut u, | ||
| 6716 | + &mut v, | ||
| 6717 | + enable_filter_intra, | ||
| 6718 | + allow_screen_content_tools, | ||
| 6719 | + base_q_idx, | ||
| 6720 | + tx_select, | ||
| 6721 | + )?; | ||
| 6722 | + } | ||
| 6723 | + PARTITION_VERT => { | ||
| 6724 | + // lane-sbpart r2: mirror of PARTITION_HORZ above with | ||
| 6725 | + // width/height swapped. | ||
| 6726 | + decode_block_rect64( | ||
| 6727 | + &mut dec, | ||
| 6728 | + &mut cdfs, | ||
| 6729 | + &mut neighbours, | ||
| 6730 | + at, | ||
| 6731 | + 32, | ||
| 6732 | + 64, | ||
| 6733 | + &mut y, | ||
| 6734 | + &mut u, | ||
| 6735 | + &mut v, | ||
| 6736 | + enable_filter_intra, | ||
| 6737 | + allow_screen_content_tools, | ||
| 6738 | + base_q_idx, | ||
| 6739 | + tx_select, | ||
| 6740 | + )?; | ||
| 6741 | + decode_block_rect64( | ||
| 6742 | + &mut dec, | ||
| 6743 | + &mut cdfs, | ||
| 6744 | + &mut neighbours, | ||
| 6745 | + (at.0, at.1 + 2), | ||
| 6746 | + 32, | ||
| 6747 | + 64, | ||
| 6748 | + &mut y, | ||
| 6749 | + &mut u, | ||
| 6750 | + &mut v, | ||
| 6751 | + enable_filter_intra, | ||
| 6752 | + allow_screen_content_tools, | ||
| 6753 | + base_q_idx, | ||
| 6754 | + tx_select, | ||
| 6755 | + )?; | ||
| 6756 | + } | ||
| 6045 | _ => { | 6757 | _ => { |
| 6046 | return Err(unsupported( | 6758 | return Err(unsupported( |
| 6047 | "a superblock-level partition type other than NONE or SPLIT (this \ | 6759 | "a superblock-level partition type other than NONE or SPLIT (this \ |
| @@ -6066,9 +6778,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6066 | use std::io::Write; | 6778 | use std::io::Write; |
| 6067 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 6779 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 6068 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 6780 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 6069 | - let _ = f.write_all(&y.data); | 6781 | + let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; |
| 6070 | - let _ = f.write_all(&u.data); | 6782 | + let _ = f.write_all(&narrow(&y)); |
| 6071 | - let _ = f.write_all(&v.data); | 6783 | + let _ = f.write_all(&narrow(&u)); |
| 6784 | + let _ = f.write_all(&narrow(&v)); | ||
| 6072 | } | 6785 | } |
| 6073 | } else { | 6786 | } else { |
| 6074 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 6787 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -6080,7 +6793,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6080 | let crop_wide = |plane: &PlaneBuf| -> Vec<u8> { | 6793 | let crop_wide = |plane: &PlaneBuf| -> Vec<u8> { |
| 6081 | let mut out = Vec::with_capacity(plane.true_width * plane.true_height); | 6794 | let mut out = Vec::with_capacity(plane.true_width * plane.true_height); |
| 6082 | for row in 0..plane.true_height { | 6795 | for row in 0..plane.true_height { |
| 6083 | - out.extend_from_slice(&plane.data[row * plane.width..][..plane.true_width]); | 6796 | + out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8)); |
| 6084 | } | 6797 | } |
| 6085 | out | 6798 | out |
| 6086 | }; | 6799 | }; |
| @@ -6117,10 +6830,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6117 | result_cdfs, | 6830 | result_cdfs, |
| 6118 | )); | 6831 | )); |
| 6119 | } | 6832 | } |
| 6120 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | 6833 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { |
| 6121 | let mut out = Vec::with_capacity(w * h); | 6834 | let mut out = Vec::with_capacity(w * h); |
| 6122 | for row in 0..h { | 6835 | for row in 0..h { |
| 6123 | - out.extend_from_slice(&plane.data[row * plane.width..][..w]); | 6836 | + out.extend(plane.data[row * plane.width..][..w].iter().copied()); |
| 6124 | } | 6837 | } |
| 6125 | out | 6838 | out |
| 6126 | }; | 6839 | }; |
| @@ -6146,7 +6859,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6146 | static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | 6859 | static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 6147 | let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 6860 | let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 6148 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 6861 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 6149 | - let _ = f.write_all(&yc); | 6862 | + // corner-cut: this diagnostic dump stays 8-bit-narrowed |
| 6863 | + // regardless of the stream's real bit depth (debug-only, | ||
| 6864 | + // never read by a gate); widen if a >8-bit margin dump | ||
| 6865 | + // is ever needed. | ||
| 6866 | + let _ = f.write_all(&yc.iter().map(|&s| s as u8).collect::<Vec<u8>>()); | ||
| 6150 | } | 6867 | } |
| 6151 | } | 6868 | } |
| 6152 | Some(Picture { | 6869 | Some(Picture { |
| @@ -6379,7 +7096,7 @@ impl PlaneBuf { | |||
| 6379 | x: usize, | 7096 | x: usize, |
| 6380 | y: usize, | 7097 | y: usize, |
| 6381 | side: usize, | 7098 | side: usize, |
| 6382 | - prediction: &[u8], | 7099 | + prediction: &[u16], |
| 6383 | residual: &[i32], | 7100 | residual: &[i32], |
| 6384 | ) { | 7101 | ) { |
| 6385 | self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual); | 7102 | self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual); |
| @@ -6400,13 +7117,13 @@ impl PlaneBuf { | |||
| 6400 | side: usize, | 7117 | side: usize, |
| 6401 | w: usize, | 7118 | w: usize, |
| 6402 | h: usize, | 7119 | h: usize, |
| 6403 | - prediction: &[u8], | 7120 | + prediction: &[u16], |
| 6404 | residual: &[i32], | 7121 | residual: &[i32], |
| 6405 | ) { | 7122 | ) { |
| 6406 | for row in 0..h { | 7123 | for row in 0..h { |
| 6407 | for col in 0..w { | 7124 | for col in 0..w { |
| 6408 | let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col]) | 7125 | let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col]) |
| 6409 | - .clamp(0, 255) as u8; | 7126 | + .clamp(0, crate::decode::sample_max()) as u16; |
| 6410 | self.data[(y + row) * self.width + x + col] = sample; | 7127 | self.data[(y + row) * self.width + x + col] = sample; |
| 6411 | } | 7128 | } |
| 6412 | } | 7129 | } |
| @@ -6432,7 +7149,7 @@ fn read_inter_plane( | |||
| 6432 | y: usize, | 7149 | y: usize, |
| 6433 | side: usize, | 7150 | side: usize, |
| 6434 | base_q_idx: u8, | 7151 | base_q_idx: u8, |
| 6435 | - prediction: &[u8], | 7152 | + prediction: &[u16], |
| 6436 | // lane-chromau: this block's own luma transform's *actual coded* | 7153 | // lane-chromau: this block's own luma transform's *actual coded* |
| 6437 | // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's | 7154 | // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's |
| 6438 | // chroma plane never codes its own `tx_type` symbol, but (unlike an | 7155 | // chroma plane never codes its own `tx_type` symbol, but (unlike an |
| @@ -6462,6 +7179,7 @@ fn read_inter_plane( | |||
| 6462 | skip_ctx, | 7179 | skip_ctx, |
| 6463 | dc_sign_ctx(around.2), | 7180 | dc_sign_ctx(around.2), |
| 6464 | default_tx_type, | 7181 | default_tx_type, |
| 7182 | + None, | ||
| 6465 | )?; | 7183 | )?; |
| 6466 | let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type); | 7184 | let residual = dequant_and_inverse_typed(&grid, side, 8, CURRENT_Q_IDX.with(|c| c.get()), tx_type); |
| 6467 | plane.reconstruct_mc(x, y, side, prediction, &residual); | 7185 | plane.reconstruct_mc(x, y, side, prediction, &residual); |
| @@ -6863,8 +7581,8 @@ fn obmc_neighbour_pred( | |||
| 6863 | luma: bool, | 7581 | luma: bool, |
| 6864 | h_kind: mc::InterpFilterKind, | 7582 | h_kind: mc::InterpFilterKind, |
| 6865 | v_kind: mc::InterpFilterKind, | 7583 | v_kind: mc::InterpFilterKind, |
| 6866 | -) -> Vec<u8> { | 7584 | +) -> Vec<u16> { |
| 6867 | - let mut out = vec![0u8; w * h]; | 7585 | + let mut out = vec![0u16; w * h]; |
| 6868 | mc::predict_with_filters( | 7586 | mc::predict_with_filters( |
| 6869 | &refplane.data, | 7587 | &refplane.data, |
| 6870 | refplane.width, | 7588 | refplane.width, |
| @@ -6911,7 +7629,7 @@ fn interintra_blend( | |||
| 6911 | side: usize, | 7629 | side: usize, |
| 6912 | ii_mode: u8, | 7630 | ii_mode: u8, |
| 6913 | wedge: Option<(&'static [u8], usize)>, | 7631 | wedge: Option<(&'static [u8], usize)>, |
| 6914 | - pred: &mut [u8], | 7632 | + pred: &mut [u16], |
| 6915 | ) { | 7633 | ) { |
| 6916 | // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH. | 7634 | // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH. |
| 6917 | let intra_mode = match ii_mode { | 7635 | let intra_mode = match ii_mode { |
| @@ -6929,7 +7647,7 @@ fn interintra_blend( | |||
| 6929 | below_left: false, | 7647 | below_left: false, |
| 6930 | }, | 7648 | }, |
| 6931 | ); | 7649 | ); |
| 6932 | - let mut intra = vec![0u8; side * side]; | 7650 | + let mut intra = vec![0u16; side * side]; |
| 6933 | // Edge filtering never applies here: V/H at delta 0 are plain edge | 7651 | // Edge filtering never applies here: V/H at delta 0 are plain edge |
| 6934 | // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no | 7652 | // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no |
| 6935 | // angle at all. | 7653 | // angle at all. |
| @@ -6973,33 +7691,33 @@ fn interintra_blend( | |||
| 6973 | }); | 7691 | }); |
| 6974 | let idx = i * side + j; | 7692 | let idx = i * side + j; |
| 6975 | pred[idx] = | 7693 | pred[idx] = |
| 6976 | - ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u8; | 7694 | + ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u16; |
| 6977 | } | 7695 | } |
| 6978 | } | 7696 | } |
| 6979 | } | 7697 | } |
| 6980 | 7698 | ||
| 6981 | -fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) { | 7699 | +fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { |
| 6982 | let mask = obmc_mask(h); | 7700 | let mask = obmc_mask(h); |
| 6983 | for row in 0..h { | 7701 | for row in 0..h { |
| 6984 | let m = u32::from(mask[row]); | 7702 | let m = u32::from(mask[row]); |
| 6985 | for col in 0..w { | 7703 | for col in 0..w { |
| 6986 | let d = &mut dst[(oy + row) * stride + ox + col]; | 7704 | let d = &mut dst[(oy + row) * stride + ox + col]; |
| 6987 | let t = u32::from(tmp[row * w + col]); | 7705 | let t = u32::from(tmp[row * w + col]); |
| 6988 | - *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8; | 7706 | + *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16; |
| 6989 | } | 7707 | } |
| 6990 | } | 7708 | } |
| 6991 | } | 7709 | } |
| 6992 | 7710 | ||
| 6993 | /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the | 7711 | /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the |
| 6994 | /// left-neighbour pass, `aom_blend_a64_hmask`). | 7712 | /// left-neighbour pass, `aom_blend_a64_hmask`). |
| 6995 | -fn obmc_blend_h(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) { | 7713 | +fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { |
| 6996 | let mask = obmc_mask(w); | 7714 | let mask = obmc_mask(w); |
| 6997 | for row in 0..h { | 7715 | for row in 0..h { |
| 6998 | for col in 0..w { | 7716 | for col in 0..w { |
| 6999 | let m = u32::from(mask[col]); | 7717 | let m = u32::from(mask[col]); |
| 7000 | let d = &mut dst[(oy + row) * stride + ox + col]; | 7718 | let d = &mut dst[(oy + row) * stride + ox + col]; |
| 7001 | let t = u32::from(tmp[row * w + col]); | 7719 | let t = u32::from(tmp[row * w + col]); |
| 7002 | - *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8; | 7720 | + *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16; |
| 7003 | } | 7721 | } |
| 7004 | } | 7722 | } |
| 7005 | } | 7723 | } |
| @@ -7038,9 +7756,9 @@ fn obmc_blend( | |||
| 7038 | ref_v: &PlaneBuf, | 7756 | ref_v: &PlaneBuf, |
| 7039 | other_refs: &RefSlots, | 7757 | other_refs: &RefSlots, |
| 7040 | interp_fixed: Option<mc::InterpFilterKind>, | 7758 | interp_fixed: Option<mc::InterpFilterKind>, |
| 7041 | - pred_y: &mut [u8], | 7759 | + pred_y: &mut [u16], |
| 7042 | - pred_u: &mut [u8], | 7760 | + pred_u: &mut [u16], |
| 7043 | - pred_v: &mut [u8], | 7761 | + pred_v: &mut [u16], |
| 7044 | ) -> Result<()> { | 7762 | ) -> Result<()> { |
| 7045 | // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has | 7763 | // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has |
| 7046 | // its OWN neighbour cap (width-log2 for above, height-log2 for left) and | 7764 | // its OWN neighbour cap (width-log2 for above, height-log2 for left) and |
| @@ -8119,7 +8837,7 @@ fn decode_inter_block( | |||
| 8119 | v_filter, | 8837 | v_filter, |
| 8120 | &mut inter1_y, | 8838 | &mut inter1_y, |
| 8121 | ); | 8839 | ); |
| 8122 | - let mut pred_y = vec![0u8; side * side]; | 8840 | + let mut pred_y = vec![0u16; side * side]; |
| 8123 | let mut diffwtd_mask_y = Vec::new(); | 8841 | let mut diffwtd_mask_y = Vec::new(); |
| 8124 | // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR | 8842 | // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR |
| 8125 | // the wedge codebook lookup (comp_group_idx==1's two mutually | 8843 | // the wedge codebook lookup (comp_group_idx==1's two mutually |
| @@ -8168,7 +8886,7 @@ fn decode_inter_block( | |||
| 8168 | v_filter, | 8886 | v_filter, |
| 8169 | &mut inter1_u, | 8887 | &mut inter1_u, |
| 8170 | ); | 8888 | ); |
| 8171 | - let mut pred_u = vec![0u8; chroma_side * chroma_side]; | 8889 | + let mut pred_u = vec![0u16; chroma_side * chroma_side]; |
| 8172 | if let Some(mask_y) = mask_y { | 8890 | if let Some(mask_y) = mask_y { |
| 8173 | mc::blend_masked_compound( | 8891 | mc::blend_masked_compound( |
| 8174 | &inter0_u, | 8892 | &inter0_u, |
| @@ -8212,7 +8930,7 @@ fn decode_inter_block( | |||
| 8212 | v_filter, | 8930 | v_filter, |
| 8213 | &mut inter1_v, | 8931 | &mut inter1_v, |
| 8214 | ); | 8932 | ); |
| 8215 | - let mut pred_v = vec![0u8; chroma_side * chroma_side]; | 8933 | + let mut pred_v = vec![0u16; chroma_side * chroma_side]; |
| 8216 | if let Some(mask_y) = mask_y { | 8934 | if let Some(mask_y) = mask_y { |
| 8217 | mc::blend_masked_compound( | 8935 | mc::blend_masked_compound( |
| 8218 | &inter0_v, | 8936 | &inter0_v, |
| @@ -8782,9 +9500,9 @@ fn decode_inter_block( | |||
| 8782 | )); | 9500 | )); |
| 8783 | } | 9501 | } |
| 8784 | 9502 | ||
| 8785 | - let mut pred_y = vec![0u8; side * side]; | 9503 | + let mut pred_y = vec![0u16; side * side]; |
| 8786 | - let mut pred_u = vec![0u8; chroma_side * chroma_side]; | 9504 | + let mut pred_u = vec![0u16; chroma_side * chroma_side]; |
| 8787 | - let mut pred_v = vec![0u8; chroma_side * chroma_side]; | 9505 | + let mut pred_v = vec![0u16; chroma_side * chroma_side]; |
| 8788 | if luma_scale == mc::REF_NO_SCALE { | 9506 | if luma_scale == mc::REF_NO_SCALE { |
| 8789 | mc::predict_with_filters( | 9507 | mc::predict_with_filters( |
| 8790 | &py_ref.data, | 9508 | &py_ref.data, |
| @@ -9642,7 +10360,7 @@ fn decode_inter_block8( | |||
| 9642 | Regular, | 10360 | Regular, |
| 9643 | &mut inter1_y, | 10361 | &mut inter1_y, |
| 9644 | ); | 10362 | ); |
| 9645 | - let mut pred_y = vec![0u8; SIDE * SIDE]; | 10363 | + let mut pred_y = vec![0u16; SIDE * SIDE]; |
| 9646 | let mut diffwtd_mask_y = Vec::new(); | 10364 | let mut diffwtd_mask_y = Vec::new(); |
| 9647 | let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { | 10365 | let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { |
| 9648 | diffwtd_mask_y = vec![0u8; SIDE * SIDE]; | 10366 | diffwtd_mask_y = vec![0u8; SIDE * SIDE]; |
| @@ -9687,7 +10405,7 @@ fn decode_inter_block8( | |||
| 9687 | Regular, | 10405 | Regular, |
| 9688 | &mut inter1_u, | 10406 | &mut inter1_u, |
| 9689 | ); | 10407 | ); |
| 9690 | - let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 10408 | + let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 9691 | if let Some(mask_y) = mask_y { | 10409 | if let Some(mask_y) = mask_y { |
| 9692 | mc::blend_masked_compound( | 10410 | mc::blend_masked_compound( |
| 9693 | &inter0_u, | 10411 | &inter0_u, |
| @@ -9731,7 +10449,7 @@ fn decode_inter_block8( | |||
| 9731 | Regular, | 10449 | Regular, |
| 9732 | &mut inter1_v, | 10450 | &mut inter1_v, |
| 9733 | ); | 10451 | ); |
| 9734 | - let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 10452 | + let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 9735 | if let Some(mask_y) = mask_y { | 10453 | if let Some(mask_y) = mask_y { |
| 9736 | mc::blend_masked_compound( | 10454 | mc::blend_masked_compound( |
| 9737 | &inter0_v, | 10455 | &inter0_v, |
| @@ -9998,7 +10716,7 @@ fn decode_inter_block8( | |||
| 9998 | } | 10716 | } |
| 9999 | mode_for_tx = 0; | 10717 | mode_for_tx = 0; |
| 10000 | 10718 | ||
| 10001 | - let mut pred_y = vec![0u8; SIDE * SIDE]; | 10719 | + let mut pred_y = vec![0u16; SIDE * SIDE]; |
| 10002 | mc::predict( | 10720 | mc::predict( |
| 10003 | &ref_y.data, | 10721 | &ref_y.data, |
| 10004 | ref_y.width, | 10722 | ref_y.width, |
| @@ -10010,7 +10728,7 @@ fn decode_inter_block8( | |||
| 10010 | SIDE, | 10728 | SIDE, |
| 10011 | &mut pred_y, | 10729 | &mut pred_y, |
| 10012 | ); | 10730 | ); |
| 10013 | - let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 10731 | + let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 10014 | mc::predict( | 10732 | mc::predict( |
| 10015 | &ref_u.data, | 10733 | &ref_u.data, |
| 10016 | ref_u.width, | 10734 | ref_u.width, |
| @@ -10022,7 +10740,7 @@ fn decode_inter_block8( | |||
| 10022 | CHROMA_SIDE, | 10740 | CHROMA_SIDE, |
| 10023 | &mut pred_u, | 10741 | &mut pred_u, |
| 10024 | ); | 10742 | ); |
| 10025 | - let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 10743 | + let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; |
| 10026 | mc::predict( | 10744 | mc::predict( |
| 10027 | &ref_v.data, | 10745 | &ref_v.data, |
| 10028 | ref_v.width, | 10746 | ref_v.width, |
| @@ -10502,7 +11220,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10502 | let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK); | 11220 | let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK); |
| 10503 | 11221 | ||
| 10504 | let ref_y = PlaneBuf { | 11222 | let ref_y = PlaneBuf { |
| 10505 | - data: reference.y.clone(), | 11223 | + data: reference.y.iter().map(|&s| s as u16).collect(), |
| 10506 | width: reference.width, | 11224 | width: reference.width, |
| 10507 | height: reference.height, | 11225 | height: reference.height, |
| 10508 | true_width: reference.width, | 11226 | true_width: reference.width, |
| @@ -10513,7 +11231,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10513 | tile_y1: reference.height, | 11231 | tile_y1: reference.height, |
| 10514 | }; | 11232 | }; |
| 10515 | let ref_u = PlaneBuf { | 11233 | let ref_u = PlaneBuf { |
| 10516 | - data: reference.u.clone(), | 11234 | + data: reference.u.iter().map(|&s| s as u16).collect(), |
| 10517 | width: reference.width / 2, | 11235 | width: reference.width / 2, |
| 10518 | height: reference.height / 2, | 11236 | height: reference.height / 2, |
| 10519 | true_width: reference.width / 2, | 11237 | true_width: reference.width / 2, |
| @@ -10524,7 +11242,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10524 | tile_y1: reference.height / 2, | 11242 | tile_y1: reference.height / 2, |
| 10525 | }; | 11243 | }; |
| 10526 | let ref_v = PlaneBuf { | 11244 | let ref_v = PlaneBuf { |
| 10527 | - data: reference.v.clone(), | 11245 | + data: reference.v.iter().map(|&s| s as u16).collect(), |
| 10528 | width: reference.width / 2, | 11246 | width: reference.width / 2, |
| 10529 | height: reference.height / 2, | 11247 | height: reference.height / 2, |
| 10530 | true_width: reference.width / 2, | 11248 | true_width: reference.width / 2, |
| @@ -10547,7 +11265,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10547 | .map(|g| { | 11265 | .map(|g| { |
| 10548 | ( | 11266 | ( |
| 10549 | PlaneBuf { | 11267 | PlaneBuf { |
| 10550 | - data: g.y.clone(), | 11268 | + data: g.y.iter().map(|&s| s as u16).collect(), |
| 10551 | width: g.width, | 11269 | width: g.width, |
| 10552 | height: g.height, | 11270 | height: g.height, |
| 10553 | true_width: g.width, | 11271 | true_width: g.width, |
| @@ -10558,7 +11276,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10558 | tile_y1: g.height, | 11276 | tile_y1: g.height, |
| 10559 | }, | 11277 | }, |
| 10560 | PlaneBuf { | 11278 | PlaneBuf { |
| 10561 | - data: g.u.clone(), | 11279 | + data: g.u.iter().map(|&s| s as u16).collect(), |
| 10562 | width: g.width / 2, | 11280 | width: g.width / 2, |
| 10563 | height: g.height / 2, | 11281 | height: g.height / 2, |
| 10564 | true_width: g.width / 2, | 11282 | true_width: g.width / 2, |
| @@ -10569,7 +11287,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10569 | tile_y1: g.height / 2, | 11287 | tile_y1: g.height / 2, |
| 10570 | }, | 11288 | }, |
| 10571 | PlaneBuf { | 11289 | PlaneBuf { |
| 10572 | - data: g.v.clone(), | 11290 | + data: g.v.iter().map(|&s| s as u16).collect(), |
| 10573 | width: g.width / 2, | 11291 | width: g.width / 2, |
| 10574 | height: g.height / 2, | 11292 | height: g.height / 2, |
| 10575 | true_width: g.width / 2, | 11293 | true_width: g.width / 2, |
| @@ -10586,7 +11304,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10586 | std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c))); | 11304 | std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c))); |
| 10587 | 11305 | ||
| 10588 | let mut y = PlaneBuf { | 11306 | let mut y = PlaneBuf { |
| 10589 | - data: vec![0u8; width * height], | 11307 | + data: vec![0u16; width * height], |
| 10590 | width, | 11308 | width, |
| 10591 | height, | 11309 | height, |
| 10592 | true_width, | 11310 | true_width, |
| @@ -10597,7 +11315,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10597 | tile_y1: height, | 11315 | tile_y1: height, |
| 10598 | }; | 11316 | }; |
| 10599 | let mut u = PlaneBuf { | 11317 | let mut u = PlaneBuf { |
| 10600 | - data: vec![0u8; width * height / 4], | 11318 | + data: vec![0u16; width * height / 4], |
| 10601 | width: width / 2, | 11319 | width: width / 2, |
| 10602 | height: height / 2, | 11320 | height: height / 2, |
| 10603 | true_width: true_width / 2, | 11321 | true_width: true_width / 2, |
| @@ -10608,7 +11326,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 10608 | tile_y1: height / 2, | 11326 | tile_y1: height / 2, |
| 10609 | }; | 11327 | }; |
| 10610 | let mut v = PlaneBuf { | 11328 | let mut v = PlaneBuf { |
| 10611 | - data: vec![0u8; width * height / 4], | 11329 | + data: vec![0u16; width * height / 4], |
| 10612 | width: width / 2, | 11330 | width: width / 2, |
| 10613 | height: height / 2, | 11331 | height: height / 2, |
| 10614 | true_width: true_width / 2, | 11332 | true_width: true_width / 2, |
| @@ -11967,9 +12685,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 11967 | use std::io::Write; | 12685 | use std::io::Write; |
| 11968 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 12686 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 11969 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 12687 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 11970 | - let _ = f.write_all(&y.data); | 12688 | + let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() }; |
| 11971 | - let _ = f.write_all(&u.data); | 12689 | + let _ = f.write_all(&narrow(&y)); |
| 11972 | - let _ = f.write_all(&v.data); | 12690 | + let _ = f.write_all(&narrow(&u)); |
| 12691 | + let _ = f.write_all(&narrow(&v)); | ||
| 11973 | } | 12692 | } |
| 11974 | } else { | 12693 | } else { |
| 11975 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 12694 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -12010,10 +12729,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 12010 | motion_field, | 12729 | motion_field, |
| 12011 | )); | 12730 | )); |
| 12012 | } | 12731 | } |
| 12013 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | 12732 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { |
| 12014 | let mut out = Vec::with_capacity(w * h); | 12733 | let mut out = Vec::with_capacity(w * h); |
| 12015 | for row in 0..h { | 12734 | for row in 0..h { |
| 12016 | - out.extend_from_slice(&plane.data[row * plane.width..][..w]); | 12735 | + out.extend(plane.data[row * plane.width..][..w].iter().copied()); |
| 12017 | } | 12736 | } |
| 12018 | out | 12737 | out |
| 12019 | }; | 12738 | }; |
| @@ -12139,10 +12858,10 @@ mod tests { | |||
| 12139 | /// planes are byte-exact against the encoder's own reconstruction. | 12858 | /// planes are byte-exact against the encoder's own reconstruction. |
| 12140 | fn round_trips(w: usize, h: usize, modes: &[u8]) { | 12859 | fn round_trips(w: usize, h: usize, modes: &[u8]) { |
| 12141 | use crate::encode::{Encoded, Picture as Pic}; | 12860 | use crate::encode::{Encoded, Picture as Pic}; |
| 12142 | - let mut source = vec![0u8; w * h]; | 12861 | + let mut source = vec![0u16; w * h]; |
| 12143 | for row in 0..h { | 12862 | for row in 0..h { |
| 12144 | for col in 0..w { | 12863 | for col in 0..w { |
| 12145 | - source[row * w + col] = ((row * 3 + col * 5) % 251) as u8; | 12864 | + source[row * w + col] = ((row * 3 + col * 5) % 251) as u16; |
| 12146 | } | 12865 | } |
| 12147 | } | 12866 | } |
| 12148 | let picture = Pic { | 12867 | let picture = Pic { |
| @@ -12357,9 +13076,9 @@ mod tests { | |||
| 12357 | Picture { | 13076 | Picture { |
| 12358 | width, | 13077 | width, |
| 12359 | height, | 13078 | height, |
| 12360 | - y: out.stdout[..luma].to_vec(), | 13079 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 12361 | - u: out.stdout[luma..luma + chroma].to_vec(), | 13080 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 12362 | - v: out.stdout[luma + chroma..].to_vec(), | 13081 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 12363 | } | 13082 | } |
| 12364 | } | 13083 | } |
| 12365 | 13084 | ||
| @@ -12405,9 +13124,9 @@ mod tests { | |||
| 12405 | Picture { | 13124 | Picture { |
| 12406 | width, | 13125 | width, |
| 12407 | height, | 13126 | height, |
| 12408 | - y: out.stdout[base..base + luma].to_vec(), | 13127 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), |
| 12409 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | 13128 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 12410 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | 13129 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), |
| 12411 | } | 13130 | } |
| 12412 | }) | 13131 | }) |
| 12413 | .collect() | 13132 | .collect() |
| @@ -12498,14 +13217,14 @@ mod tests { | |||
| 12498 | let mut picture = crate::encode::Picture::grey(width, height); | 13217 | let mut picture = crate::encode::Picture::grey(width, height); |
| 12499 | for row in 0..height { | 13218 | for row in 0..height { |
| 12500 | for col in 0..width { | 13219 | for col in 0..width { |
| 12501 | - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; | 13220 | + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; |
| 12502 | } | 13221 | } |
| 12503 | } | 13222 | } |
| 12504 | for row in 0..height / 2 { | 13223 | for row in 0..height / 2 { |
| 12505 | for col in 0..width / 2 { | 13224 | for col in 0..width / 2 { |
| 12506 | let i = row * width / 2 + col; | 13225 | let i = row * width / 2 + col; |
| 12507 | - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; | 13226 | + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; |
| 12508 | - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; | 13227 | + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; |
| 12509 | } | 13228 | } |
| 12510 | } | 13229 | } |
| 12511 | picture | 13230 | picture |
| @@ -12517,15 +13236,15 @@ mod tests { | |||
| 12517 | for x in 0..width { | 13236 | for x in 0..width { |
| 12518 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; | 13237 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; |
| 12519 | let gradient = sx * 200.0 / width as f64; | 13238 | let gradient = sx * 200.0 / width as f64; |
| 12520 | - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; | 13239 | + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; |
| 12521 | } | 13240 | } |
| 12522 | } | 13241 | } |
| 12523 | for y in 0..height / 2 { | 13242 | for y in 0..height / 2 { |
| 12524 | for x in 0..width / 2 { | 13243 | for x in 0..width / 2 { |
| 12525 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; | 13244 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 12526 | let i = y * width / 2 + x; | 13245 | let i = y * width / 2 + x; |
| 12527 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | 13246 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; |
| 12528 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | 13247 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; |
| 12529 | } | 13248 | } |
| 12530 | } | 13249 | } |
| 12531 | picture | 13250 | picture |
| @@ -12698,7 +13417,7 @@ mod tests { | |||
| 12698 | let data = enc.finish(); | 13417 | let data = enc.finish(); |
| 12699 | 13418 | ||
| 12700 | let (width, height) = (64usize, 64usize); | 13419 | let (width, height) = (64usize, 64usize); |
| 12701 | - let ref_pattern: Vec<u8> = (0..width * height).map(|i| (i % 251) as u8).collect(); | 13420 | + let ref_pattern: Vec<u16> = (0..width * height).map(|i| (i % 251) as u16).collect(); |
| 12702 | let ref_plane = |scale: usize| PlaneBuf { | 13421 | let ref_plane = |scale: usize| PlaneBuf { |
| 12703 | data: ref_pattern | 13422 | data: ref_pattern |
| 12704 | .iter() | 13423 | .iter() |
| @@ -12730,7 +13449,7 @@ mod tests { | |||
| 12730 | let ref_v = ref_plane(2); | 13449 | let ref_v = ref_plane(2); |
| 12731 | 13450 | ||
| 12732 | let mut y = PlaneBuf { | 13451 | let mut y = PlaneBuf { |
| 12733 | - data: vec![0u8; width * height], | 13452 | + data: vec![0u16; width * height], |
| 12734 | width, | 13453 | width, |
| 12735 | height, | 13454 | height, |
| 12736 | true_width: width, | 13455 | true_width: width, |
| @@ -12741,7 +13460,7 @@ mod tests { | |||
| 12741 | tile_y1: height, | 13460 | tile_y1: height, |
| 12742 | }; | 13461 | }; |
| 12743 | let mut u = PlaneBuf { | 13462 | let mut u = PlaneBuf { |
| 12744 | - data: vec![0u8; (width / 2) * (height / 2)], | 13463 | + data: vec![0u16; (width / 2) * (height / 2)], |
| 12745 | width: width / 2, | 13464 | width: width / 2, |
| 12746 | height: height / 2, | 13465 | height: height / 2, |
| 12747 | true_width: width / 2, | 13466 | true_width: width / 2, |
| @@ -12752,7 +13471,7 @@ mod tests { | |||
| 12752 | tile_y1: height / 2, | 13471 | tile_y1: height / 2, |
| 12753 | }; | 13472 | }; |
| 12754 | let mut v = PlaneBuf { | 13473 | let mut v = PlaneBuf { |
| 12755 | - data: vec![0u8; (width / 2) * (height / 2)], | 13474 | + data: vec![0u16; (width / 2) * (height / 2)], |
| 12756 | width: width / 2, | 13475 | width: width / 2, |
| 12757 | height: height / 2, | 13476 | height: height / 2, |
| 12758 | true_width: width / 2, | 13477 | true_width: width / 2, |
| @@ -12818,7 +13537,7 @@ mod tests { | |||
| 12818 | .unwrap(); | 13537 | .unwrap(); |
| 12819 | 13538 | ||
| 12820 | let (px, py) = (c * SUB, r * SUB); | 13539 | let (px, py) = (c * SUB, r * SUB); |
| 12821 | - let mut want_near = vec![0u8; side * side]; | 13540 | + let mut want_near = vec![0u16; side * side]; |
| 12822 | crate::mc::predict( | 13541 | crate::mc::predict( |
| 12823 | &ref_y.data, | 13542 | &ref_y.data, |
| 12824 | ref_y.width, | 13543 | ref_y.width, |
| @@ -12830,7 +13549,7 @@ mod tests { | |||
| 12830 | side, | 13549 | side, |
| 12831 | &mut want_near, | 13550 | &mut want_near, |
| 12832 | ); | 13551 | ); |
| 12833 | - let mut want_nearest = vec![0u8; side * side]; | 13552 | + let mut want_nearest = vec![0u16; side * side]; |
| 12834 | crate::mc::predict( | 13553 | crate::mc::predict( |
| 12835 | &ref_y.data, | 13554 | &ref_y.data, |
| 12836 | ref_y.width, | 13555 | ref_y.width, |
| @@ -12847,7 +13566,7 @@ mod tests { | |||
| 12847 | "test setup: the two candidate MVs must predict differently" | 13566 | "test setup: the two candidate MVs must predict differently" |
| 12848 | ); | 13567 | ); |
| 12849 | 13568 | ||
| 12850 | - let mut got = vec![0u8; side * side]; | 13569 | + let mut got = vec![0u16; side * side]; |
| 12851 | for row in 0..side { | 13570 | for row in 0..side { |
| 12852 | got[row * side..(row + 1) * side].copy_from_slice( | 13571 | got[row * side..(row + 1) * side].copy_from_slice( |
| 12853 | &y.data[(py + row) * y.width + px..(py + row) * y.width + px + side], | 13572 | &y.data[(py + row) * y.width + px..(py + row) * y.width + px + side], |
crates/ec-av1/src/encode.rsmodified+124 -58
| @@ -81,7 +81,15 @@ pub(crate) fn split_blocks() -> bool { | |||
| 81 | SPLIT_BLOCKS | 81 | SPLIT_BLOCKS |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | -/// One 8-bit planar 4:2:0 picture. | 84 | +/// One planar 4:2:0 picture. `y`/`u`/`v` hold one sample per position as |
| 85 | +/// `u16` regardless of bit depth (`crate::decode`'s own `PlaneBuf` has used | ||
| 86 | +/// `u16` throughout since the round-hbd-r1/r2 widen; this is the last | ||
| 87 | +/// narrowing boundary that stayed `u8` -- widened lane-hbd r3 so a 10-bit | ||
| 88 | +/// stream's decode output actually carries 10-bit precision instead of | ||
| 89 | +/// silently losing its low 2 bits). The encoder only ever produces values in | ||
| 90 | +/// `0..=255` (it is still 8-bit-only by design, see `encode.rs`'s r2 | ||
| 91 | +/// decision); `Plane::source` narrows right back to `u8` at its two | ||
| 92 | +/// construction sites, a lossless round trip for that range. | ||
| 85 | #[derive(Clone, Debug, PartialEq, Eq)] | 93 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 86 | pub struct Picture { | 94 | pub struct Picture { |
| 87 | /// The picture's width in luma samples. | 95 | /// The picture's width in luma samples. |
| @@ -89,11 +97,11 @@ pub struct Picture { | |||
| 89 | /// Its height in luma samples. | 97 | /// Its height in luma samples. |
| 90 | pub height: usize, | 98 | pub height: usize, |
| 91 | /// The luma plane, `width * height` samples in raster order. | 99 | /// The luma plane, `width * height` samples in raster order. |
| 92 | - pub y: Vec<u8>, | 100 | + pub y: Vec<u16>, |
| 93 | /// The U plane, at half the width and half the height. | 101 | /// The U plane, at half the width and half the height. |
| 94 | - pub u: Vec<u8>, | 102 | + pub u: Vec<u16>, |
| 95 | /// The V plane, the same shape as U. | 103 | /// The V plane, the same shape as U. |
| 96 | - pub v: Vec<u8>, | 104 | + pub v: Vec<u16>, |
| 97 | } | 105 | } |
| 98 | 106 | ||
| 99 | impl Picture { | 107 | impl Picture { |
| @@ -196,17 +204,56 @@ impl Picture { | |||
| 196 | } | 204 | } |
| 197 | } | 205 | } |
| 198 | 206 | ||
| 207 | +/// lane-hbd r2: the encoder's own reconstruction/source buffers stay `u8` | ||
| 208 | +/// (8-bit only, unchanged this round -- widening the encoder is out of this | ||
| 209 | +/// round's scope, see `lanes/hbd-r2.report.md`); this is the local box that | ||
| 210 | +/// lets it keep calling [`crate::intra::predict`] now that shape is `u16` | ||
| 211 | +/// in and out. A block-sized round-trip through `u16` is exact for 8-bit | ||
| 212 | +/// content (every value fits both ways), so this changes no encoder output. | ||
| 213 | +#[allow(clippy::too_many_arguments)] | ||
| 214 | +fn intra_predict_u8( | ||
| 215 | + mode: u8, | ||
| 216 | + angle_delta: i32, | ||
| 217 | + above: Option<&[u8]>, | ||
| 218 | + left: Option<&[u8]>, | ||
| 219 | + corner: Option<u8>, | ||
| 220 | + bw: usize, | ||
| 221 | + bh: usize, | ||
| 222 | + enable_edge_filter: bool, | ||
| 223 | + smooth_neighbor: bool, | ||
| 224 | + dst: &mut [u8], | ||
| 225 | +) { | ||
| 226 | + let above16: Option<Vec<u16>> = above.map(|s| s.iter().map(|&v| u16::from(v)).collect()); | ||
| 227 | + let left16: Option<Vec<u16>> = left.map(|s| s.iter().map(|&v| u16::from(v)).collect()); | ||
| 228 | + let mut dst16 = vec![0u16; dst.len()]; | ||
| 229 | + crate::intra::predict( | ||
| 230 | + mode, | ||
| 231 | + angle_delta, | ||
| 232 | + above16.as_deref(), | ||
| 233 | + left16.as_deref(), | ||
| 234 | + corner.map(u16::from), | ||
| 235 | + bw, | ||
| 236 | + bh, | ||
| 237 | + enable_edge_filter, | ||
| 238 | + smooth_neighbor, | ||
| 239 | + &mut dst16, | ||
| 240 | + ); | ||
| 241 | + for (d, &s) in dst.iter_mut().zip(dst16.iter()) { | ||
| 242 | + *d = s as u8; | ||
| 243 | + } | ||
| 244 | +} | ||
| 245 | + | ||
| 199 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last | 246 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last |
| 200 | /// row and column, so the block coder always sees a whole number of blocks. | 247 | /// row and column, so the block coder always sees a whole number of blocks. |
| 201 | /// [`crop_plane`] undoes this on the way back out. | 248 | /// [`crop_plane`] undoes this on the way back out. |
| 202 | -fn pad_plane( | 249 | +fn pad_plane<T: Copy + Default>( |
| 203 | - source: &[u8], | 250 | + source: &[T], |
| 204 | width: usize, | 251 | width: usize, |
| 205 | height: usize, | 252 | height: usize, |
| 206 | padded_width: usize, | 253 | padded_width: usize, |
| 207 | padded_height: usize, | 254 | padded_height: usize, |
| 208 | -) -> Vec<u8> { | 255 | +) -> Vec<T> { |
| 209 | - let mut out = vec![0u8; padded_width * padded_height]; | 256 | + let mut out = vec![T::default(); padded_width * padded_height]; |
| 210 | for row in 0..padded_height { | 257 | for row in 0..padded_height { |
| 211 | let src = source[row.min(height - 1) * width..][..width].as_ref(); | 258 | let src = source[row.min(height - 1) * width..][..width].as_ref(); |
| 212 | let dst = &mut out[row * padded_width..][..padded_width]; | 259 | let dst = &mut out[row * padded_width..][..padded_width]; |
| @@ -219,7 +266,7 @@ fn pad_plane( | |||
| 219 | /// The top-left `width` x `height` region of a plane that is `padded_width` | 266 | /// The top-left `width` x `height` region of a plane that is `padded_width` |
| 220 | /// wide, which is the render-size crop [`Picture::padded`]'s replication | 267 | /// wide, which is the render-size crop [`Picture::padded`]'s replication |
| 221 | /// exists to let a decoder undo. | 268 | /// exists to let a decoder undo. |
| 222 | -fn crop_plane(source: &[u8], padded_width: usize, width: usize, height: usize) -> Vec<u8> { | 269 | +fn crop_plane<T: Copy>(source: &[T], padded_width: usize, width: usize, height: usize) -> Vec<T> { |
| 223 | let mut out = Vec::with_capacity(width * height); | 270 | let mut out = Vec::with_capacity(width * height); |
| 224 | for row in 0..height { | 271 | for row in 0..height { |
| 225 | out.extend_from_slice(&source[row * padded_width..][..width]); | 272 | out.extend_from_slice(&source[row * padded_width..][..width]); |
| @@ -597,7 +644,7 @@ impl Plane<'_> { | |||
| 597 | } = at; | 644 | } = at; |
| 598 | let (above, left, corner) = self.edges(x, y, side, reach); | 645 | let (above, left, corner) = self.edges(x, y, side, reach); |
| 599 | let mut prediction = vec![0u8; side * side]; | 646 | let mut prediction = vec![0u8; side * side]; |
| 600 | - crate::intra::predict( | 647 | + intra_predict_u8( |
| 601 | mode, | 648 | mode, |
| 602 | 0, | 649 | 0, |
| 603 | above.as_deref(), | 650 | above.as_deref(), |
| @@ -817,7 +864,7 @@ impl Plane<'_> { | |||
| 817 | .iter() | 864 | .iter() |
| 818 | .map(|&mode| { | 865 | .map(|&mode| { |
| 819 | let mut prediction = vec![0u8; side * side]; | 866 | let mut prediction = vec![0u8; side * side]; |
| 820 | - crate::intra::predict( | 867 | + intra_predict_u8( |
| 821 | mode, | 868 | mode, |
| 822 | 0, | 869 | 0, |
| 823 | above.as_deref(), | 870 | above.as_deref(), |
| @@ -869,7 +916,7 @@ impl Plane<'_> { | |||
| 869 | .iter() | 916 | .iter() |
| 870 | .map(|&mode| { | 917 | .map(|&mode| { |
| 871 | let mut prediction = vec![0u8; side * side]; | 918 | let mut prediction = vec![0u8; side * side]; |
| 872 | - crate::intra::predict( | 919 | + intra_predict_u8( |
| 873 | mode, | 920 | mode, |
| 874 | 0, | 921 | 0, |
| 875 | above.as_deref(), | 922 | above.as_deref(), |
| @@ -1711,9 +1758,16 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1711 | // Prediction reads no further than this, in each plane's own units -- | 1758 | // Prediction reads no further than this, in each plane's own units -- |
| 1712 | // see `Plane::true_width`/`true_height`. | 1759 | // see `Plane::true_width`/`true_height`. |
| 1713 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); | 1760 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); |
| 1761 | + // lane-hbd r4: `Picture.y/u/v` widened to `Vec<u16>` for the decoder's | ||
| 1762 | + // sake (DPB reference slots, 10-bit output); the encoder stays 8-bit by | ||
| 1763 | + // design (see `intra_predict_u8`'s doc comment), so narrow the source | ||
| 1764 | + // once here. | ||
| 1765 | + let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | ||
| 1766 | + let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect(); | ||
| 1767 | + let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect(); | ||
| 1714 | let mut luma = Plane { | 1768 | let mut luma = Plane { |
| 1715 | - source: &picture.y, | 1769 | + source: &picture_y8, |
| 1716 | - reconstruction: vec![128; picture.y.len()], | 1770 | + reconstruction: vec![128; picture_y8.len()], |
| 1717 | width: picture.width, | 1771 | width: picture.width, |
| 1718 | height: picture.height, | 1772 | height: picture.height, |
| 1719 | true_width, | 1773 | true_width, |
| @@ -1721,16 +1775,16 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1721 | }; | 1775 | }; |
| 1722 | let mut chroma = [ | 1776 | let mut chroma = [ |
| 1723 | Plane { | 1777 | Plane { |
| 1724 | - source: &picture.u, | 1778 | + source: &picture_u8, |
| 1725 | - reconstruction: vec![128; picture.u.len()], | 1779 | + reconstruction: vec![128; picture_u8.len()], |
| 1726 | width: picture.width / 2, | 1780 | width: picture.width / 2, |
| 1727 | height: picture.height / 2, | 1781 | height: picture.height / 2, |
| 1728 | true_width: true_width / 2, | 1782 | true_width: true_width / 2, |
| 1729 | true_height: true_height / 2, | 1783 | true_height: true_height / 2, |
| 1730 | }, | 1784 | }, |
| 1731 | Plane { | 1785 | Plane { |
| 1732 | - source: &picture.v, | 1786 | + source: &picture_v8, |
| 1733 | - reconstruction: vec![128; picture.v.len()], | 1787 | + reconstruction: vec![128; picture_v8.len()], |
| 1734 | width: picture.width / 2, | 1788 | width: picture.width / 2, |
| 1735 | height: picture.height / 2, | 1789 | height: picture.height / 2, |
| 1736 | true_width: true_width / 2, | 1790 | true_width: true_width / 2, |
| @@ -1967,9 +2021,9 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1967 | reconstruction: Picture { | 2021 | reconstruction: Picture { |
| 1968 | width: luma.width, | 2022 | width: luma.width, |
| 1969 | height: luma.height, | 2023 | height: luma.height, |
| 1970 | - y: luma.reconstruction, | 2024 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 1971 | - u: u.reconstruction, | 2025 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 1972 | - v: v.reconstruction, | 2026 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 1973 | }, | 2027 | }, |
| 1974 | tile, | 2028 | tile, |
| 1975 | mi_cols: header.mi_cols, | 2029 | mi_cols: header.mi_cols, |
| @@ -2125,7 +2179,7 @@ fn mc_trial( | |||
| 2125 | side: usize, | 2179 | side: usize, |
| 2126 | mv: (i32, i32), | 2180 | mv: (i32, i32), |
| 2127 | luma: bool, | 2181 | luma: bool, |
| 2128 | - reference: &[u8], | 2182 | + reference: &[u16], |
| 2129 | stride: usize, | 2183 | stride: usize, |
| 2130 | ref_width: usize, | 2184 | ref_width: usize, |
| 2131 | ref_height: usize, | 2185 | ref_height: usize, |
| @@ -2136,7 +2190,10 @@ fn mc_trial( | |||
| 2136 | ) -> Trial { | 2190 | ) -> Trial { |
| 2137 | let x_q4 = mv_to_q4(x, mv.1, luma); | 2191 | let x_q4 = mv_to_q4(x, mv.1, luma); |
| 2138 | let y_q4 = mv_to_q4(y, mv.0, luma); | 2192 | let y_q4 = mv_to_q4(y, mv.0, luma); |
| 2139 | - let mut prediction = vec![0u8; side * side]; | 2193 | + // lane-hbd r4: `reference` (a DPB `Picture`'s plane) is `u16` now that |
| 2194 | + // `Picture` is widened; `prediction`/the encoder stay `u8` (encoder is | ||
| 2195 | + // 8-bit only this round, see `intra_predict_u8`'s doc comment). | ||
| 2196 | + let mut prediction16 = vec![0u16; side * side]; | ||
| 2140 | mc::predict( | 2197 | mc::predict( |
| 2141 | reference, | 2198 | reference, |
| 2142 | stride, | 2199 | stride, |
| @@ -2146,8 +2203,9 @@ fn mc_trial( | |||
| 2146 | y_q4, | 2203 | y_q4, |
| 2147 | side, | 2204 | side, |
| 2148 | side, | 2205 | side, |
| 2149 | - &mut prediction, | 2206 | + &mut prediction16, |
| 2150 | ); | 2207 | ); |
| 2208 | + let prediction: Vec<u8> = prediction16.iter().map(|&v| v as u8).collect(); | ||
| 2151 | plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set) | 2209 | plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set) |
| 2152 | } | 2210 | } |
| 2153 | 2211 | ||
| @@ -2409,10 +2467,13 @@ fn search_inter_block( | |||
| 2409 | } | 2467 | } |
| 2410 | 2468 | ||
| 2411 | let source_block = luma.source_block(x, y, BLOCK); | 2469 | let source_block = luma.source_block(x, y, BLOCK); |
| 2470 | + // lane-hbd r4: `motion::search` is 8-bit only (its SAD/cost math is | ||
| 2471 | + // integer-`u8`-scale); narrow the DPB reference plane locally. | ||
| 2472 | + let ref_luma_8: Vec<u8> = ref_luma.0.iter().map(|&v| v as u8).collect(); | ||
| 2412 | #[cfg(test)] | 2473 | #[cfg(test)] |
| 2413 | let t = std::time::Instant::now(); | 2474 | let t = std::time::Instant::now(); |
| 2414 | let found = motion::search( | 2475 | let found = motion::search( |
| 2415 | - ref_luma.0, | 2476 | + &ref_luma_8, |
| 2416 | ref_luma.1, | 2477 | ref_luma.1, |
| 2417 | ref_luma.2, | 2478 | ref_luma.2, |
| 2418 | ref_luma.3, | 2479 | ref_luma.3, |
| @@ -2572,9 +2633,14 @@ pub(crate) fn encode_inter_frame( | |||
| 2572 | header.render_height = render.1 as u32; | 2633 | header.render_height = render.1 as u32; |
| 2573 | 2634 | ||
| 2574 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); | 2635 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); |
| 2636 | + // lane-hbd r4: encoder stays 8-bit by design; narrow the source once | ||
| 2637 | + // here (see `encode_key_frame_inner`). | ||
| 2638 | + let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect(); | ||
| 2639 | + let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect(); | ||
| 2640 | + let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect(); | ||
| 2575 | let mut luma = Plane { | 2641 | let mut luma = Plane { |
| 2576 | - source: &picture.y, | 2642 | + source: &picture_y8, |
| 2577 | - reconstruction: vec![128; picture.y.len()], | 2643 | + reconstruction: vec![128; picture_y8.len()], |
| 2578 | width: picture.width, | 2644 | width: picture.width, |
| 2579 | height: picture.height, | 2645 | height: picture.height, |
| 2580 | true_width, | 2646 | true_width, |
| @@ -2582,16 +2648,16 @@ pub(crate) fn encode_inter_frame( | |||
| 2582 | }; | 2648 | }; |
| 2583 | let mut chroma = [ | 2649 | let mut chroma = [ |
| 2584 | Plane { | 2650 | Plane { |
| 2585 | - source: &picture.u, | 2651 | + source: &picture_u8, |
| 2586 | - reconstruction: vec![128; picture.u.len()], | 2652 | + reconstruction: vec![128; picture_u8.len()], |
| 2587 | width: picture.width / 2, | 2653 | width: picture.width / 2, |
| 2588 | height: picture.height / 2, | 2654 | height: picture.height / 2, |
| 2589 | true_width: true_width / 2, | 2655 | true_width: true_width / 2, |
| 2590 | true_height: true_height / 2, | 2656 | true_height: true_height / 2, |
| 2591 | }, | 2657 | }, |
| 2592 | Plane { | 2658 | Plane { |
| 2593 | - source: &picture.v, | 2659 | + source: &picture_v8, |
| 2594 | - reconstruction: vec![128; picture.v.len()], | 2660 | + reconstruction: vec![128; picture_v8.len()], |
| 2595 | width: picture.width / 2, | 2661 | width: picture.width / 2, |
| 2596 | height: picture.height / 2, | 2662 | height: picture.height / 2, |
| 2597 | true_width: true_width / 2, | 2663 | true_width: true_width / 2, |
| @@ -2898,9 +2964,9 @@ pub(crate) fn encode_inter_frame( | |||
| 2898 | reconstruction: Picture { | 2964 | reconstruction: Picture { |
| 2899 | width: luma.width, | 2965 | width: luma.width, |
| 2900 | height: luma.height, | 2966 | height: luma.height, |
| 2901 | - y: luma.reconstruction, | 2967 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2902 | - u: u.reconstruction, | 2968 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2903 | - v: v.reconstruction, | 2969 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2904 | }, | 2970 | }, |
| 2905 | tile, | 2971 | tile, |
| 2906 | mi_cols: header.mi_cols, | 2972 | mi_cols: header.mi_cols, |
| @@ -3038,9 +3104,9 @@ mod tests { | |||
| 3038 | Picture { | 3104 | Picture { |
| 3039 | width, | 3105 | width, |
| 3040 | height, | 3106 | height, |
| 3041 | - y: out.stdout[..luma].to_vec(), | 3107 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 3042 | - u: out.stdout[luma..luma + chroma].to_vec(), | 3108 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 3043 | - v: out.stdout[luma + chroma..].to_vec(), | 3109 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 3044 | } | 3110 | } |
| 3045 | } | 3111 | } |
| 3046 | 3112 | ||
| @@ -3061,20 +3127,20 @@ mod tests { | |||
| 3061 | 0.0 | 3127 | 0.0 |
| 3062 | }; | 3128 | }; |
| 3063 | picture.y[y * width + x] = | 3129 | picture.y[y * width + x] = |
| 3064 | - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; | 3130 | + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; |
| 3065 | } | 3131 | } |
| 3066 | } | 3132 | } |
| 3067 | for y in 0..height / 2 { | 3133 | for y in 0..height / 2 { |
| 3068 | for x in 0..width / 2 { | 3134 | for x in 0..width / 2 { |
| 3069 | let i = y * width / 2 + x; | 3135 | let i = y * width / 2 + x; |
| 3070 | - picture.u[i] = (100 + (x * 60 / (width / 2))) as u8; | 3136 | + picture.u[i] = (100 + (x * 60 / (width / 2))) as u16; |
| 3071 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | 3137 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; |
| 3072 | } | 3138 | } |
| 3073 | } | 3139 | } |
| 3074 | picture | 3140 | picture |
| 3075 | } | 3141 | } |
| 3076 | 3142 | ||
| 3077 | - fn psnr(a: &[u8], b: &[u8]) -> f64 { | 3143 | + fn psnr(a: &[u16], b: &[u16]) -> f64 { |
| 3078 | let squared: f64 = a | 3144 | let squared: f64 = a |
| 3079 | .iter() | 3145 | .iter() |
| 3080 | .zip(b) | 3146 | .zip(b) |
| @@ -3609,9 +3675,9 @@ mod tests { | |||
| 3609 | Picture { | 3675 | Picture { |
| 3610 | width, | 3676 | width, |
| 3611 | height, | 3677 | height, |
| 3612 | - y: out.stdout[..luma].to_vec(), | 3678 | + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 3613 | - u: out.stdout[luma..luma + chroma].to_vec(), | 3679 | + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 3614 | - v: out.stdout[luma + chroma..].to_vec(), | 3680 | + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 3615 | } | 3681 | } |
| 3616 | } | 3682 | } |
| 3617 | 3683 | ||
| @@ -3731,7 +3797,7 @@ mod tests { | |||
| 3731 | /// Where two planes first disagree, and by how much: a mismatch reported as | 3797 | /// Where two planes first disagree, and by how much: a mismatch reported as |
| 3732 | /// a position says which block and which sample of it went wrong, which a | 3798 | /// a position says which block and which sample of it went wrong, which a |
| 3733 | /// pair of thousand-sample arrays does not. | 3799 | /// pair of thousand-sample arrays does not. |
| 3734 | - fn first_difference(ours: &[u8], theirs: &[u8], width: usize) -> Option<String> { | 3800 | + fn first_difference(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> { |
| 3735 | let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?; | 3801 | let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?; |
| 3736 | let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count(); | 3802 | let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count(); |
| 3737 | Some(format!( | 3803 | Some(format!( |
| @@ -4287,15 +4353,15 @@ mod tests { | |||
| 4287 | 0.0 | 4353 | 0.0 |
| 4288 | }; | 4354 | }; |
| 4289 | picture.y[y * width + x] = | 4355 | picture.y[y * width + x] = |
| 4290 | - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; | 4356 | + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; |
| 4291 | } | 4357 | } |
| 4292 | } | 4358 | } |
| 4293 | for y in 0..height / 2 { | 4359 | for y in 0..height / 2 { |
| 4294 | for x in 0..width / 2 { | 4360 | for x in 0..width / 2 { |
| 4295 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; | 4361 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 4296 | let i = y * width / 2 + x; | 4362 | let i = y * width / 2 + x; |
| 4297 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | 4363 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; |
| 4298 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | 4364 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; |
| 4299 | } | 4365 | } |
| 4300 | } | 4366 | } |
| 4301 | picture | 4367 | picture |
| @@ -4343,9 +4409,9 @@ mod tests { | |||
| 4343 | Picture { | 4409 | Picture { |
| 4344 | width, | 4410 | width, |
| 4345 | height, | 4411 | height, |
| 4346 | - y: out.stdout[base..base + luma].to_vec(), | 4412 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), |
| 4347 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | 4413 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 4348 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | 4414 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), |
| 4349 | } | 4415 | } |
| 4350 | }) | 4416 | }) |
| 4351 | .collect() | 4417 | .collect() |
| @@ -4518,7 +4584,7 @@ mod tests { | |||
| 4518 | let mut prediction = vec![0u8; side * side]; | 4584 | let mut prediction = vec![0u8; side * side]; |
| 4519 | let t = Instant::now(); | 4585 | let t = Instant::now(); |
| 4520 | for _ in 0..N { | 4586 | for _ in 0..N { |
| 4521 | - crate::intra::predict( | 4587 | + intra_predict_u8( |
| 4522 | D45_PRED, | 4588 | D45_PRED, |
| 4523 | 0, | 4589 | 0, |
| 4524 | Some(&above), | 4590 | Some(&above), |
| @@ -4684,9 +4750,9 @@ mod tests { | |||
| 4684 | Picture { | 4750 | Picture { |
| 4685 | width, | 4751 | width, |
| 4686 | height, | 4752 | height, |
| 4687 | - y: bytes[..luma].to_vec(), | 4753 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 4688 | - u: bytes[luma..luma + chroma].to_vec(), | 4754 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 4689 | - v: bytes[luma + chroma..].to_vec(), | 4755 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 4690 | } | 4756 | } |
| 4691 | }) | 4757 | }) |
| 4692 | } | 4758 | } |
| @@ -4811,9 +4877,9 @@ mod tests { | |||
| 4811 | Picture { | 4877 | Picture { |
| 4812 | width, | 4878 | width, |
| 4813 | height, | 4879 | height, |
| 4814 | - y: bytes[..luma].to_vec(), | 4880 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 4815 | - u: bytes[luma..luma + chroma].to_vec(), | 4881 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 4816 | - v: bytes[luma + chroma..].to_vec(), | 4882 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 4817 | } | 4883 | } |
| 4818 | }) | 4884 | }) |
| 4819 | .collect() | 4885 | .collect() |
crates/ec-av1/src/encoder.rsmodified+11 -8
| @@ -376,14 +376,14 @@ mod tests { | |||
| 376 | for y in 0..height { | 376 | for y in 0..height { |
| 377 | for x in 0..width { | 377 | for x in 0..width { |
| 378 | let sx = (x + shift) % width; | 378 | let sx = (x + shift) % width; |
| 379 | - picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u8; | 379 | + picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u16; |
| 380 | } | 380 | } |
| 381 | } | 381 | } |
| 382 | for y in 0..height / 2 { | 382 | for y in 0..height / 2 { |
| 383 | for x in 0..width / 2 { | 383 | for x in 0..width / 2 { |
| 384 | let i = y * (width / 2) + x; | 384 | let i = y * (width / 2) + x; |
| 385 | - picture.u[i] = ((100 + shift * 4) % 256) as u8; | 385 | + picture.u[i] = ((100 + shift * 4) % 256) as u16; |
| 386 | - picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u8; | 386 | + picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u16; |
| 387 | } | 387 | } |
| 388 | } | 388 | } |
| 389 | picture | 389 | picture |
| @@ -679,9 +679,9 @@ mod tests { | |||
| 679 | Picture { | 679 | Picture { |
| 680 | width, | 680 | width, |
| 681 | height, | 681 | height, |
| 682 | - y: bytes[..luma].to_vec(), | 682 | + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), |
| 683 | - u: bytes[luma..luma + chroma].to_vec(), | 683 | + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 684 | - v: bytes[luma + chroma..].to_vec(), | 684 | + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 685 | } | 685 | } |
| 686 | }) | 686 | }) |
| 687 | .collect(), | 687 | .collect(), |
| @@ -759,7 +759,7 @@ mod tests { | |||
| 759 | } | 759 | } |
| 760 | } | 760 | } |
| 761 | 761 | ||
| 762 | - fn psnr(a: &[u8], b: &[u8]) -> f64 { | 762 | + fn psnr(a: &[u16], b: &[u16]) -> f64 { |
| 763 | let squared: f64 = a | 763 | let squared: f64 = a |
| 764 | .iter() | 764 | .iter() |
| 765 | .zip(b) | 765 | .zip(b) |
| @@ -847,7 +847,10 @@ mod tests { | |||
| 847 | let mean_psnr: f64 = decoded | 847 | let mean_psnr: f64 = decoded |
| 848 | .iter() | 848 | .iter() |
| 849 | .zip(&pictures) | 849 | .zip(&pictures) |
| 850 | - .map(|(d, p)| psnr(d, &p.y)) | 850 | + .map(|(d, p)| { |
| 851 | + let d16: Vec<u16> = d.iter().map(|&v| u16::from(v)).collect(); | ||
| 852 | + psnr(&d16, &p.y) | ||
| 853 | + }) | ||
| 851 | .sum::<f64>() | 854 | .sum::<f64>() |
| 852 | / decoded.len() as f64; | 855 | / decoded.len() as f64; |
| 853 | assert!( | 856 | assert!( |
crates/ec-av1/src/film_grain.rsmodified+3 -3
| @@ -353,7 +353,7 @@ fn add_noise_to_block( | |||
| 353 | let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset) | 353 | let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset) |
| 354 | >> scaling_shift; | 354 | >> scaling_shift; |
| 355 | picture.u[cidx] = | 355 | picture.u[cidx] = |
| 356 | - ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8; | 356 | + ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16; |
| 357 | } | 357 | } |
| 358 | if apply_cr { | 358 | if apply_cr { |
| 359 | let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32) | 359 | let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32) |
| @@ -363,7 +363,7 @@ fn add_noise_to_block( | |||
| 363 | let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset) | 363 | let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset) |
| 364 | >> scaling_shift; | 364 | >> scaling_shift; |
| 365 | picture.v[cidx] = | 365 | picture.v[cidx] = |
| 366 | - ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8; | 366 | + ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16; |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | } | 369 | } |
| @@ -376,7 +376,7 @@ fn add_noise_to_block( | |||
| 376 | + rounding_offset) | 376 | + rounding_offset) |
| 377 | >> scaling_shift; | 377 | >> scaling_shift; |
| 378 | picture.y[pidx] = | 378 | picture.y[pidx] = |
| 379 | - ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u8; | 379 | + ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u16; |
| 380 | } | 380 | } |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
crates/ec-av1/src/intra.rsmodified+27 -27
| @@ -145,14 +145,14 @@ impl Edges { | |||
| 145 | /// and `z3_c`'s `max_base_y` use (libaom `reconintra.c`) -- above and | 145 | /// and `z3_c`'s `max_base_y` use (libaom `reconintra.c`) -- above and |
| 146 | /// left both extend that far regardless of which of `bw`/`bh` is larger. | 146 | /// left both extend that far regardless of which of `bw`/`bh` is larger. |
| 147 | fn build( | 147 | fn build( |
| 148 | - above: Option<&[u8]>, | 148 | + above: Option<&[u16]>, |
| 149 | - left: Option<&[u8]>, | 149 | + left: Option<&[u16]>, |
| 150 | - corner: Option<u8>, | 150 | + corner: Option<u16>, |
| 151 | bw: usize, | 151 | bw: usize, |
| 152 | bh: usize, | 152 | bh: usize, |
| 153 | ) -> Self { | 153 | ) -> Self { |
| 154 | let want = bw + bh; | 154 | let want = bw + bh; |
| 155 | - let extend = |samples: &[u8]| { | 155 | + let extend = |samples: &[u16]| { |
| 156 | let mut row: Vec<i32> = samples.iter().map(|&s| i32::from(s)).collect(); | 156 | let mut row: Vec<i32> = samples.iter().map(|&s| i32::from(s)).collect(); |
| 157 | let last = *row.last().expect("an edge that exists has samples"); | 157 | let last = *row.last().expect("an edge that exists has samples"); |
| 158 | row.resize(want, last); | 158 | row.resize(want, last); |
| @@ -230,14 +230,14 @@ impl Edges { | |||
| 230 | pub fn predict( | 230 | pub fn predict( |
| 231 | mode: u8, | 231 | mode: u8, |
| 232 | angle_delta: i32, | 232 | angle_delta: i32, |
| 233 | - above: Option<&[u8]>, | 233 | + above: Option<&[u16]>, |
| 234 | - left: Option<&[u8]>, | 234 | + left: Option<&[u16]>, |
| 235 | - corner: Option<u8>, | 235 | + corner: Option<u16>, |
| 236 | bw: usize, | 236 | bw: usize, |
| 237 | bh: usize, | 237 | bh: usize, |
| 238 | enable_edge_filter: bool, | 238 | enable_edge_filter: bool, |
| 239 | smooth_neighbor: bool, | 239 | smooth_neighbor: bool, |
| 240 | - dst: &mut [u8], | 240 | + dst: &mut [u16], |
| 241 | ) { | 241 | ) { |
| 242 | assert_eq!(dst.len(), bw * bh, "the destination is the block"); | 242 | assert_eq!(dst.len(), bw * bh, "the destination is the block"); |
| 243 | let edges = Edges::build(above, left, corner, bw, bh); | 243 | let edges = Edges::build(above, left, corner, bw, bh); |
| @@ -304,7 +304,7 @@ pub fn predict( | |||
| 304 | PAETH_PRED => paeth(edges.above(c), edges.left(r), edges.above(-1)), | 304 | PAETH_PRED => paeth(edges.above(c), edges.left(r), edges.above(-1)), |
| 305 | other => panic!("intra mode {other} is not one this module predicts"), | 305 | other => panic!("intra mode {other} is not one this module predicts"), |
| 306 | }; | 306 | }; |
| 307 | - dst[row * bw + col] = value.clamp(0, 255) as u8; | 307 | + dst[row * bw + col] = value.clamp(0, crate::decode::sample_max()) as u16; |
| 308 | } | 308 | } |
| 309 | } | 309 | } |
| 310 | } | 310 | } |
| @@ -431,7 +431,7 @@ fn upsample_intra_edge(buf: &[i32]) -> Vec<i32> { | |||
| 431 | out[0] = inp[0]; | 431 | out[0] = inp[0]; |
| 432 | for i in 0..sz { | 432 | for i in 0..sz { |
| 433 | let s = -inp[i] + 9 * inp[i + 1] + 9 * inp[i + 2] - inp[i + 3]; | 433 | let s = -inp[i] + 9 * inp[i + 1] + 9 * inp[i + 2] - inp[i + 3]; |
| 434 | - out[2 * i + 1] = ((s + 8) >> 4).clamp(0, 255); | 434 | + out[2 * i + 1] = ((s + 8) >> 4).clamp(0, crate::decode::sample_max()); |
| 435 | out[2 * i + 2] = inp[i + 2]; | 435 | out[2 * i + 2] = inp[i + 2]; |
| 436 | } | 436 | } |
| 437 | out | 437 | out |
| @@ -452,7 +452,7 @@ fn directional( | |||
| 452 | smooth_neighbor: bool, | 452 | smooth_neighbor: bool, |
| 453 | n_top: usize, | 453 | n_top: usize, |
| 454 | n_left: usize, | 454 | n_left: usize, |
| 455 | - dst: &mut [u8], | 455 | + dst: &mut [u16], |
| 456 | ) { | 456 | ) { |
| 457 | let (w, h) = (bw as i32, bh as i32); | 457 | let (w, h) = (bw as i32, bh as i32); |
| 458 | let reach = w + h; // `av1_dr_prediction_z{1,3}_c`'s `max_base_{x,y}` reach. | 458 | let reach = w + h; // `av1_dr_prediction_z{1,3}_c`'s `max_base_{x,y}` reach. |
| @@ -565,7 +565,7 @@ fn directional( | |||
| 565 | blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1) | 565 | blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1) |
| 566 | } | 566 | } |
| 567 | }; | 567 | }; |
| 568 | - dst[(row * w + col) as usize] = value.clamp(0, 255) as u8; | 568 | + dst[(row * w + col) as usize] = value.clamp(0, crate::decode::sample_max()) as u16; |
| 569 | } | 569 | } |
| 570 | } | 570 | } |
| 571 | } | 571 | } |
| @@ -579,8 +579,8 @@ fn directional( | |||
| 579 | /// before `dc_predictor` averages, so a slice truncated short by the true | 579 | /// before `dc_predictor` averages, so a slice truncated short by the true |
| 580 | /// frame edge must be extended by repetition here too, not averaged over its | 580 | /// frame edge must be extended by repetition here too, not averaged over its |
| 581 | /// own shorter length. | 581 | /// own shorter length. |
| 582 | -fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 { | 582 | +fn dc(above: Option<&[u16]>, left: Option<&[u16]>, bw: usize, bh: usize) -> i32 { |
| 583 | - let extend = |samples: &[u8], want: usize| -> Vec<u8> { | 583 | + let extend = |samples: &[u16], want: usize| -> Vec<u16> { |
| 584 | if samples.len() >= want { | 584 | if samples.len() >= want { |
| 585 | samples[..want].to_vec() | 585 | samples[..want].to_vec() |
| 586 | } else { | 586 | } else { |
| @@ -592,7 +592,7 @@ fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 { | |||
| 592 | }; | 592 | }; |
| 593 | let above = above.map(|a| extend(a, bw)); | 593 | let above = above.map(|a| extend(a, bw)); |
| 594 | let left = left.map(|l| extend(l, bh)); | 594 | let left = left.map(|l| extend(l, bh)); |
| 595 | - let average = |samples: &[u8]| { | 595 | + let average = |samples: &[u16]| { |
| 596 | let sum: u32 = samples.iter().map(|&s| u32::from(s)).sum(); | 596 | let sum: u32 = samples.iter().map(|&s| u32::from(s)).sum(); |
| 597 | ((sum + (samples.len() as u32 >> 1)) / samples.len() as u32) as i32 | 597 | ((sum + (samples.len() as u32 >> 1)) / samples.len() as u32) as i32 |
| 598 | }; | 598 | }; |
| @@ -723,11 +723,11 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4; | |||
| 723 | /// 32x32, and only on square blocks: 4, 8, 16 or 32). | 723 | /// 32x32, and only on square blocks: 4, 8, 16 or 32). |
| 724 | pub fn predict_filter_intra( | 724 | pub fn predict_filter_intra( |
| 725 | mode: usize, | 725 | mode: usize, |
| 726 | - above: Option<&[u8]>, | 726 | + above: Option<&[u16]>, |
| 727 | - left: Option<&[u8]>, | 727 | + left: Option<&[u16]>, |
| 728 | - corner: Option<u8>, | 728 | + corner: Option<u16>, |
| 729 | side: usize, | 729 | side: usize, |
| 730 | - dst: &mut [u8], | 730 | + dst: &mut [u16], |
| 731 | ) { | 731 | ) { |
| 732 | assert_eq!(dst.len(), side * side, "the destination is the block"); | 732 | assert_eq!(dst.len(), side * side, "the destination is the block"); |
| 733 | assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32"); | 733 | assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32"); |
| @@ -759,7 +759,7 @@ pub fn predict_filter_intra( | |||
| 759 | for k in 0..8 { | 759 | for k in 0..8 { |
| 760 | let (r_off, c_off) = (k >> 2, k & 3); | 760 | let (r_off, c_off) = (k >> 2, k & 3); |
| 761 | let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum(); | 761 | let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum(); |
| 762 | - let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, 255); | 762 | + let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max()); |
| 763 | let idx = (r + r_off) * (side + 1) + c + c_off; | 763 | let idx = (r + r_off) * (side + 1) + c + c_off; |
| 764 | buffer[idx] = value; | 764 | buffer[idx] = value; |
| 765 | } | 765 | } |
| @@ -769,7 +769,7 @@ pub fn predict_filter_intra( | |||
| 769 | } | 769 | } |
| 770 | for row in 0..side { | 770 | for row in 0..side { |
| 771 | for col in 0..side { | 771 | for col in 0..side { |
| 772 | - dst[row * side + col] = at(&buffer, row + 1, col + 1) as u8; | 772 | + dst[row * side + col] = at(&buffer, row + 1, col + 1) as u16; |
| 773 | } | 773 | } |
| 774 | } | 774 | } |
| 775 | } | 775 | } |
| @@ -799,15 +799,15 @@ mod tests { | |||
| 799 | 799 | ||
| 800 | /// Same deterministic synthetic ramp `lanes/intrarect_dump.c`'s `fill` | 800 | /// Same deterministic synthetic ramp `lanes/intrarect_dump.c`'s `fill` |
| 801 | /// generates. | 801 | /// generates. |
| 802 | - fn fill(n: usize, seed: i32) -> Vec<u8> { | 802 | + fn fill(n: usize, seed: i32) -> Vec<u16> { |
| 803 | (0..n) | 803 | (0..n) |
| 804 | - .map(|i| ((i as i32 * 7 + seed * 13 + (i as i32 % 5) * 3).rem_euclid(256)) as u8) | 804 | + .map(|i| ((i as i32 * 7 + seed * 13 + (i as i32 % 5) * 3).rem_euclid(256)) as u16) |
| 805 | .collect() | 805 | .collect() |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | /// `lanes/intrarect_dump.c`'s `checksum`: a position-weighted sum so a | 808 | /// `lanes/intrarect_dump.c`'s `checksum`: a position-weighted sum so a |
| 809 | /// wrong value anywhere in the block, not just at index 0, moves it. | 809 | /// wrong value anywhere in the block, not just at index 0, moves it. |
| 810 | - fn checksum(dst: &[u8]) -> u64 { | 810 | + fn checksum(dst: &[u16]) -> u64 { |
| 811 | dst.iter() | 811 | dst.iter() |
| 812 | .enumerate() | 812 | .enumerate() |
| 813 | .map(|(i, &v)| u64::from(v) * (i as u64 + 1)) | 813 | .map(|(i, &v)| u64::from(v) * (i as u64 + 1)) |
| @@ -897,10 +897,10 @@ mod tests { | |||
| 897 | let reach = bw + bh; | 897 | let reach = bw + bh; |
| 898 | let above = fill(reach, 1); | 898 | let above = fill(reach, 1); |
| 899 | let left = fill(reach, 2); | 899 | let left = fill(reach, 2); |
| 900 | - let corner = ((bw * 3 + bh * 5) % 256) as u8; | 900 | + let corner = ((bw * 3 + bh * 5) % 256) as u16; |
| 901 | 901 | ||
| 902 | for (name, mode) in [("DC", DC_PRED), ("SMOOTH", SMOOTH_PRED), ("PAETH", PAETH_PRED)] { | 902 | for (name, mode) in [("DC", DC_PRED), ("SMOOTH", SMOOTH_PRED), ("PAETH", PAETH_PRED)] { |
| 903 | - let mut dst = vec![0u8; bw * bh]; | 903 | + let mut dst = vec![0u16; bw * bh]; |
| 904 | predict( | 904 | predict( |
| 905 | mode, | 905 | mode, |
| 906 | 0, | 906 | 0, |
| @@ -928,7 +928,7 @@ mod tests { | |||
| 928 | for &(angle, mode, delta) in &directional_cases { | 928 | for &(angle, mode, delta) in &directional_cases { |
| 929 | for ef in [false, true] { | 929 | for ef in [false, true] { |
| 930 | for sn in [false, true] { | 930 | for sn in [false, true] { |
| 931 | - let mut dst = vec![0u8; bw * bh]; | 931 | + let mut dst = vec![0u16; bw * bh]; |
| 932 | predict( | 932 | predict( |
| 933 | mode, | 933 | mode, |
| 934 | delta, | 934 | delta, |
crates/ec-av1/src/mc.rsmodified+44 -41
| @@ -228,7 +228,7 @@ impl InterpFilterKind { | |||
| 228 | /// whatever this encoder's own uncoded padding columns/rows hold. | 228 | /// whatever this encoder's own uncoded padding columns/rows hold. |
| 229 | #[allow(clippy::too_many_arguments)] | 229 | #[allow(clippy::too_many_arguments)] |
| 230 | fn sample( | 230 | fn sample( |
| 231 | - reference: &[u8], | 231 | + reference: &[u16], |
| 232 | stride: usize, | 232 | stride: usize, |
| 233 | true_width: usize, | 233 | true_width: usize, |
| 234 | true_height: usize, | 234 | true_height: usize, |
| @@ -258,7 +258,7 @@ fn sample( | |||
| 258 | /// empty. | 258 | /// empty. |
| 259 | #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape | 259 | #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape |
| 260 | pub fn predict( | 260 | pub fn predict( |
| 261 | - reference: &[u8], | 261 | + reference: &[u16], |
| 262 | stride: usize, | 262 | stride: usize, |
| 263 | true_width: usize, | 263 | true_width: usize, |
| 264 | true_height: usize, | 264 | true_height: usize, |
| @@ -266,7 +266,7 @@ pub fn predict( | |||
| 266 | y_q4: i32, | 266 | y_q4: i32, |
| 267 | block_w: usize, | 267 | block_w: usize, |
| 268 | block_h: usize, | 268 | block_h: usize, |
| 269 | - dst: &mut [u8], | 269 | + dst: &mut [u16], |
| 270 | ) { | 270 | ) { |
| 271 | predict_with_filter( | 271 | predict_with_filter( |
| 272 | reference, | 272 | reference, |
| @@ -287,7 +287,7 @@ pub fn predict( | |||
| 287 | /// kernel both directions. | 287 | /// kernel both directions. |
| 288 | #[allow(clippy::too_many_arguments)] | 288 | #[allow(clippy::too_many_arguments)] |
| 289 | pub fn predict_with_filter( | 289 | pub fn predict_with_filter( |
| 290 | - reference: &[u8], | 290 | + reference: &[u16], |
| 291 | stride: usize, | 291 | stride: usize, |
| 292 | true_width: usize, | 292 | true_width: usize, |
| 293 | true_height: usize, | 293 | true_height: usize, |
| @@ -296,7 +296,7 @@ pub fn predict_with_filter( | |||
| 296 | block_w: usize, | 296 | block_w: usize, |
| 297 | block_h: usize, | 297 | block_h: usize, |
| 298 | filter_kind: InterpFilterKind, | 298 | filter_kind: InterpFilterKind, |
| 299 | - dst: &mut [u8], | 299 | + dst: &mut [u16], |
| 300 | ) { | 300 | ) { |
| 301 | predict_with_filters( | 301 | predict_with_filters( |
| 302 | reference, | 302 | reference, |
| @@ -319,7 +319,7 @@ pub fn predict_with_filter( | |||
| 319 | /// so the two passes can genuinely differ. | 319 | /// so the two passes can genuinely differ. |
| 320 | #[allow(clippy::too_many_arguments)] | 320 | #[allow(clippy::too_many_arguments)] |
| 321 | pub fn predict_with_filters( | 321 | pub fn predict_with_filters( |
| 322 | - reference: &[u8], | 322 | + reference: &[u16], |
| 323 | stride: usize, | 323 | stride: usize, |
| 324 | true_width: usize, | 324 | true_width: usize, |
| 325 | true_height: usize, | 325 | true_height: usize, |
| @@ -329,7 +329,7 @@ pub fn predict_with_filters( | |||
| 329 | block_h: usize, | 329 | block_h: usize, |
| 330 | h_kind: InterpFilterKind, | 330 | h_kind: InterpFilterKind, |
| 331 | v_kind: InterpFilterKind, | 331 | v_kind: InterpFilterKind, |
| 332 | - dst: &mut [u8], | 332 | + dst: &mut [u16], |
| 333 | ) { | 333 | ) { |
| 334 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 334 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 335 | assert!(!reference.is_empty(), "a reference plane has samples"); | 335 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -360,7 +360,7 @@ pub fn predict_with_filters( | |||
| 360 | for col in 0..block_w { | 360 | for col in 0..block_w { |
| 361 | let x = x0 + col as i32; | 361 | let x = x0 + col as i32; |
| 362 | dst[row * block_w + col] = | 362 | dst[row * block_w + col] = |
| 363 | - sample(reference, stride, true_width, true_height, x, y) as u8; | 363 | + sample(reference, stride, true_width, true_height, x, y) as u16; |
| 364 | } | 364 | } |
| 365 | } | 365 | } |
| 366 | #[cfg(test)] | 366 | #[cfg(test)] |
| @@ -403,7 +403,7 @@ pub fn predict_with_filters( | |||
| 403 | for (t, &tap) in v_filter.iter().enumerate() { | 403 | for (t, &tap) in v_filter.iter().enumerate() { |
| 404 | sum += tap * intermediate[(row + t) * block_w + col]; | 404 | sum += tap * intermediate[(row + t) * block_w + col]; |
| 405 | } | 405 | } |
| 406 | - dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, 255) as u8; | 406 | + dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16; |
| 407 | } | 407 | } |
| 408 | } | 408 | } |
| 409 | 409 | ||
| @@ -477,7 +477,7 @@ fn round_pow2_signed_64(value: i64, shift: u32) -> i64 { | |||
| 477 | /// empty. | 477 | /// empty. |
| 478 | #[allow(clippy::too_many_arguments)] | 478 | #[allow(clippy::too_many_arguments)] |
| 479 | pub fn predict_scaled( | 479 | pub fn predict_scaled( |
| 480 | - reference: &[u8], | 480 | + reference: &[u16], |
| 481 | stride: usize, | 481 | stride: usize, |
| 482 | true_width: usize, | 482 | true_width: usize, |
| 483 | true_height: usize, | 483 | true_height: usize, |
| @@ -488,7 +488,7 @@ pub fn predict_scaled( | |||
| 488 | block_h: usize, | 488 | block_h: usize, |
| 489 | h_kind: InterpFilterKind, | 489 | h_kind: InterpFilterKind, |
| 490 | v_kind: InterpFilterKind, | 490 | v_kind: InterpFilterKind, |
| 491 | - dst: &mut [u8], | 491 | + dst: &mut [u16], |
| 492 | ) { | 492 | ) { |
| 493 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 493 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 494 | assert!(!reference.is_empty(), "a reference plane has samples"); | 494 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -540,7 +540,8 @@ pub fn predict_scaled( | |||
| 540 | for (t, &tap) in v_filter.iter().enumerate() { | 540 | for (t, &tap) in v_filter.iter().enumerate() { |
| 541 | sum += tap * intermediate[(row + t) * block_w + col]; | 541 | sum += tap * intermediate[(row + t) * block_w + col]; |
| 542 | } | 542 | } |
| 543 | - dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, 255) as u8; | 543 | + dst[row * block_w + col] = |
| 544 | + round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16; | ||
| 544 | } | 545 | } |
| 545 | } | 546 | } |
| 546 | } | 547 | } |
| @@ -579,7 +580,7 @@ const DIST_PRECISION_BITS: u32 = 4; | |||
| 579 | /// empty. | 580 | /// empty. |
| 580 | #[allow(clippy::too_many_arguments)] | 581 | #[allow(clippy::too_many_arguments)] |
| 581 | pub fn predict_compound_intermediate( | 582 | pub fn predict_compound_intermediate( |
| 582 | - reference: &[u8], | 583 | + reference: &[u16], |
| 583 | stride: usize, | 584 | stride: usize, |
| 584 | true_width: usize, | 585 | true_width: usize, |
| 585 | true_height: usize, | 586 | true_height: usize, |
| @@ -649,13 +650,13 @@ pub fn combine_compound( | |||
| 649 | pred1: &[i32], | 650 | pred1: &[i32], |
| 650 | fwd_weight: i32, | 651 | fwd_weight: i32, |
| 651 | bck_weight: i32, | 652 | bck_weight: i32, |
| 652 | - dst: &mut [u8], | 653 | + dst: &mut [u16], |
| 653 | ) { | 654 | ) { |
| 654 | assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block"); | 655 | assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block"); |
| 655 | assert_eq!(dst.len(), pred0.len(), "the destination is the block"); | 656 | assert_eq!(dst.len(), pred0.len(), "the destination is the block"); |
| 656 | for i in 0..dst.len() { | 657 | for i in 0..dst.len() { |
| 657 | let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight; | 658 | let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight; |
| 658 | - dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, 255) as u8; | 659 | + dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, crate::decode::sample_max()) as u16; |
| 659 | } | 660 | } |
| 660 | } | 661 | } |
| 661 | 662 | ||
| @@ -698,7 +699,7 @@ pub fn blend_masked_compound( | |||
| 698 | w: usize, | 699 | w: usize, |
| 699 | h: usize, | 700 | h: usize, |
| 700 | subsampled: bool, | 701 | subsampled: bool, |
| 701 | - dst: &mut [u8], | 702 | + dst: &mut [u16], |
| 702 | ) { | 703 | ) { |
| 703 | assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block"); | 704 | assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block"); |
| 704 | assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block"); | 705 | assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block"); |
| @@ -718,7 +719,7 @@ pub fn blend_masked_compound( | |||
| 718 | i32::from(mask[i * mask_stride + j]) | 719 | i32::from(mask[i * mask_stride + j]) |
| 719 | }; | 720 | }; |
| 720 | let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; | 721 | let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; |
| 721 | - dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, 255) as u8; | 722 | + dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, crate::decode::sample_max()) as u16; |
| 722 | } | 723 | } |
| 723 | } | 724 | } |
| 724 | } | 725 | } |
| @@ -734,7 +735,7 @@ pub fn blend_masked_compound( | |||
| 734 | /// off-by-one from double rounding. | 735 | /// off-by-one from double rounding. |
| 735 | #[test] | 736 | #[test] |
| 736 | fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { | 737 | fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { |
| 737 | - let reference = vec![100u8; 16 * 16]; | 738 | + let reference = vec![100u16; 16 * 16]; |
| 738 | let mut pred0 = vec![0i32; 16]; | 739 | let mut pred0 = vec![0i32; 16]; |
| 739 | predict_compound_intermediate( | 740 | predict_compound_intermediate( |
| 740 | &reference, | 741 | &reference, |
| @@ -752,7 +753,7 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { | |||
| 752 | assert!(pred0.iter().all(|&v| v == 1600), "{pred0:?}"); | 753 | assert!(pred0.iter().all(|&v| v == 1600), "{pred0:?}"); |
| 753 | 754 | ||
| 754 | let pred1 = pred0.clone(); | 755 | let pred1 = pred0.clone(); |
| 755 | - let mut dst = vec![0u8; 16]; | 756 | + let mut dst = vec![0u16; 16]; |
| 756 | combine_compound(&pred0, &pred1, 8, 8, &mut dst); | 757 | combine_compound(&pred0, &pred1, 8, 8, &mut dst); |
| 757 | assert!(dst.iter().all(|&v| v == 100), "{dst:?}"); | 758 | assert!(dst.iter().all(|&v| v == 100), "{dst:?}"); |
| 758 | } | 759 | } |
| @@ -807,9 +808,11 @@ mod tests { | |||
| 807 | // real (0, 0) coordinates -- clamping then reproduces the identical | 808 | // real (0, 0) coordinates -- clamping then reproduces the identical |
| 808 | // extended border the dump already captured. | 809 | // extended border the dump already captured. |
| 809 | let stride = 24; | 810 | let stride = 24; |
| 810 | - let mut reference = vec![0u8; stride * 24]; | 811 | + let mut reference = vec![0u16; stride * 24]; |
| 811 | for (r, row) in window.iter().enumerate() { | 812 | for (r, row) in window.iter().enumerate() { |
| 812 | - reference[r * stride..r * stride + stride].copy_from_slice(row); | 813 | + for (c, &v) in row.iter().enumerate() { |
| 814 | + reference[r * stride + c] = u16::from(v); | ||
| 815 | + } | ||
| 813 | } | 816 | } |
| 814 | // predict()'s own edge clamp starts at true (0,0); shift so the | 817 | // predict()'s own edge clamp starts at true (0,0); shift so the |
| 815 | // dumped window's row/col 4 lands there by biasing x_q4/y_q4's | 818 | // dumped window's row/col 4 lands there by biasing x_q4/y_q4's |
| @@ -819,7 +822,7 @@ mod tests { | |||
| 819 | // whole-pel part of x_q4/y_q4 by +4 to land on real (0,0). | 822 | // whole-pel part of x_q4/y_q4 by +4 to land on real (0,0). |
| 820 | let x_q4 = (4 + 0) * 16 + 15; // real block x0=0, xfrac=15 | 823 | let x_q4 = (4 + 0) * 16 + 15; // real block x0=0, xfrac=15 |
| 821 | let y_q4 = (4 + 0) * 16 + 7; // real block y0=0, yfrac=7 | 824 | let y_q4 = (4 + 0) * 16 + 7; // real block y0=0, yfrac=7 |
| 822 | - let mut dst = vec![0u8; 16 * 16]; | 825 | + let mut dst = vec![0u16; 16 * 16]; |
| 823 | predict_with_filter( | 826 | predict_with_filter( |
| 824 | &reference, | 827 | &reference, |
| 825 | stride, | 828 | stride, |
| @@ -833,7 +836,7 @@ mod tests { | |||
| 833 | &mut dst, | 836 | &mut dst, |
| 834 | ); | 837 | ); |
| 835 | #[rustfmt::skip] | 838 | #[rustfmt::skip] |
| 836 | - let expected_row0: [u8; 16] = | 839 | + let expected_row0: [u16; 16] = |
| 837 | [114,114,114,114,115,115,115,116,116,116,116,116,117,117,116,116]; | 840 | [114,114,114,114,115,115,115,116,116,116,116,116,117,117,116,116]; |
| 838 | assert_eq!( | 841 | assert_eq!( |
| 839 | &dst[0..16], | 842 | &dst[0..16], |
| @@ -841,7 +844,7 @@ mod tests { | |||
| 841 | "row0 vs aomdec's real av1_convolve_2d_sr_c output" | 844 | "row0 vs aomdec's real av1_convolve_2d_sr_c output" |
| 842 | ); | 845 | ); |
| 843 | #[rustfmt::skip] | 846 | #[rustfmt::skip] |
| 844 | - let expected_row15: [u8; 16] = | 847 | + let expected_row15: [u16; 16] = |
| 845 | [103,103,104,104,104,105,105,106,106,106,107,107,107,107,107,107]; | 848 | [103,103,104,104,104,105,105,106,106,106,107,107,107,107,107,107]; |
| 846 | assert_eq!( | 849 | assert_eq!( |
| 847 | &dst[15 * 16..15 * 16 + 16], | 850 | &dst[15 * 16..15 * 16 + 16], |
| @@ -854,8 +857,8 @@ mod tests { | |||
| 854 | fn integer_mv_is_identity() { | 857 | fn integer_mv_is_identity() { |
| 855 | let width = 12; | 858 | let width = 12; |
| 856 | let height = 12; | 859 | let height = 12; |
| 857 | - let reference: Vec<u8> = (0..width * height).map(|i| (i * 7 % 251) as u8).collect(); | 860 | + let reference: Vec<u16> = (0..width * height).map(|i| (i * 7 % 251) as u16).collect(); |
| 858 | - let mut dst = vec![0u8; 6 * 6]; | 861 | + let mut dst = vec![0u16; 6 * 6]; |
| 859 | predict( | 862 | predict( |
| 860 | &reference, | 863 | &reference, |
| 861 | width, | 864 | width, |
| @@ -883,10 +886,10 @@ mod tests { | |||
| 883 | // Step 2 so every half-pel position lands on an exact integer. | 886 | // Step 2 so every half-pel position lands on an exact integer. |
| 884 | let width = 16; | 887 | let width = 16; |
| 885 | let height = 16; | 888 | let height = 16; |
| 886 | - let reference: Vec<u8> = (0..width * height) | 889 | + let reference: Vec<u16> = (0..width * height) |
| 887 | - .map(|i| (2 * (i % width)) as u8) | 890 | + .map(|i| (2 * (i % width)) as u16) |
| 888 | .collect(); | 891 | .collect(); |
| 889 | - let mut dst = vec![0u8; 4 * 4]; | 892 | + let mut dst = vec![0u16; 4 * 4]; |
| 890 | // Half-pel in x only: fraction 8/16, integer part at column 5. | 893 | // Half-pel in x only: fraction 8/16, integer part at column 5. |
| 891 | predict( | 894 | predict( |
| 892 | &reference, | 895 | &reference, |
| @@ -915,10 +918,10 @@ mod tests { | |||
| 915 | fn constant_plane_has_unit_dc_gain_at_every_subpel_position() { | 918 | fn constant_plane_has_unit_dc_gain_at_every_subpel_position() { |
| 916 | let width = 20; | 919 | let width = 20; |
| 917 | let height = 20; | 920 | let height = 20; |
| 918 | - let reference = vec![142u8; width * height]; | 921 | + let reference = vec![142u16; width * height]; |
| 919 | for yfrac in 0..16 { | 922 | for yfrac in 0..16 { |
| 920 | for xfrac in 0..16 { | 923 | for xfrac in 0..16 { |
| 921 | - let mut dst = vec![0u8; 5 * 5]; | 924 | + let mut dst = vec![0u16; 5 * 5]; |
| 922 | predict( | 925 | predict( |
| 923 | &reference, | 926 | &reference, |
| 924 | width, | 927 | width, |
| @@ -947,11 +950,11 @@ mod tests { | |||
| 947 | // it happened to produce two merely-different numbers. | 950 | // it happened to produce two merely-different numbers. |
| 948 | let width = 10; | 951 | let width = 10; |
| 949 | let height = 10; | 952 | let height = 10; |
| 950 | - let reference: Vec<u8> = (0..height) | 953 | + let reference: Vec<u16> = (0..height) |
| 951 | - .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u8)) | 954 | + .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u16)) |
| 952 | .collect(); | 955 | .collect(); |
| 953 | 956 | ||
| 954 | - let mut horiz = vec![0u8; 4 * 4]; | 957 | + let mut horiz = vec![0u16; 4 * 4]; |
| 955 | predict( | 958 | predict( |
| 956 | &reference, | 959 | &reference, |
| 957 | width, | 960 | width, |
| @@ -963,7 +966,7 @@ mod tests { | |||
| 963 | 4, | 966 | 4, |
| 964 | &mut horiz, | 967 | &mut horiz, |
| 965 | ); | 968 | ); |
| 966 | - let mut vert = vec![0u8; 4 * 4]; | 969 | + let mut vert = vec![0u16; 4 * 4]; |
| 967 | predict( | 970 | predict( |
| 968 | &reference, | 971 | &reference, |
| 969 | width, | 972 | width, |
| @@ -1002,8 +1005,8 @@ mod tests { | |||
| 1002 | fn mv_past_the_edge_clamps_instead_of_panicking() { | 1005 | fn mv_past_the_edge_clamps_instead_of_panicking() { |
| 1003 | let width = 8; | 1006 | let width = 8; |
| 1004 | let height = 8; | 1007 | let height = 8; |
| 1005 | - let reference: Vec<u8> = (0..width * height).map(|i| (i * 3 % 200) as u8).collect(); | 1008 | + let reference: Vec<u16> = (0..width * height).map(|i| (i * 3 % 200) as u16).collect(); |
| 1006 | - let mut dst = vec![0u8; 4 * 4]; | 1009 | + let mut dst = vec![0u16; 4 * 4]; |
| 1007 | // Whole-sample position far above and to the left of the plane, with | 1010 | // Whole-sample position far above and to the left of the plane, with |
| 1008 | // an odd fraction so both filter passes exercise the clamp. | 1011 | // an odd fraction so both filter passes exercise the clamp. |
| 1009 | predict( | 1012 | predict( |
| @@ -1023,7 +1026,7 @@ mod tests { | |||
| 1023 | "an MV past the top-left edge must clamp to the corner sample, got {dst:?}" | 1026 | "an MV past the top-left edge must clamp to the corner sample, got {dst:?}" |
| 1024 | ); | 1027 | ); |
| 1025 | 1028 | ||
| 1026 | - let mut dst2 = vec![0u8; 4 * 4]; | 1029 | + let mut dst2 = vec![0u16; 4 * 4]; |
| 1027 | predict( | 1030 | predict( |
| 1028 | &reference, | 1031 | &reference, |
| 1029 | width, | 1032 | width, |
| @@ -1050,12 +1053,12 @@ mod tests { | |||
| 1050 | // a fixed stride-1 walk -- every subpel fraction, every block width. | 1053 | // a fixed stride-1 walk -- every subpel fraction, every block width. |
| 1051 | let width = 24; | 1054 | let width = 24; |
| 1052 | let height = 24; | 1055 | let height = 24; |
| 1053 | - let reference: Vec<u8> = (0..width * height).map(|i| (i * 7 % 251) as u8).collect(); | 1056 | + let reference: Vec<u16> = (0..width * height).map(|i| (i * 7 % 251) as u16).collect(); |
| 1054 | for block_w in [4usize, 8, 16] { | 1057 | for block_w in [4usize, 8, 16] { |
| 1055 | for x_frac in 0..16i32 { | 1058 | for x_frac in 0..16i32 { |
| 1056 | let x_q4 = 3 * 16 + x_frac; | 1059 | let x_q4 = 3 * 16 + x_frac; |
| 1057 | let y_q4 = 2 * 16 + 5; | 1060 | let y_q4 = 2 * 16 + 5; |
| 1058 | - let mut expected = vec![0u8; block_w * 8]; | 1061 | + let mut expected = vec![0u16; block_w * 8]; |
| 1059 | predict_with_filters( | 1062 | predict_with_filters( |
| 1060 | &reference, | 1063 | &reference, |
| 1061 | width, | 1064 | width, |
| @@ -1069,7 +1072,7 @@ mod tests { | |||
| 1069 | InterpFilterKind::Regular, | 1072 | InterpFilterKind::Regular, |
| 1070 | &mut expected, | 1073 | &mut expected, |
| 1071 | ); | 1074 | ); |
| 1072 | - let mut got = vec![0u8; block_w * 8]; | 1075 | + let mut got = vec![0u16; block_w * 8]; |
| 1073 | predict_scaled( | 1076 | predict_scaled( |
| 1074 | &reference, | 1077 | &reference, |
| 1075 | width, | 1078 | width, |
crates/ec-av1/src/motion.rsmodified+9 -3
| @@ -263,16 +263,22 @@ fn search_traced_from_step( | |||
| 263 | assert_eq!(source.len(), block_w * block_h, "source is one block"); | 263 | assert_eq!(source.len(), block_w * block_h, "source is one block"); |
| 264 | assert!(!reference.is_empty(), "a reference plane has samples"); | 264 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| 265 | 265 | ||
| 266 | - let mut dst = vec![0u8; block_w * block_h]; | 266 | + // lane-hbd r2: this encoder-side search stays `u8` (see |
| 267 | + // `encode::intra_predict_u8`'s doc comment) -- `reference` is converted | ||
| 268 | + // once here, outside the per-candidate closure, since `mc::predict` now | ||
| 269 | + // takes `u16`. | ||
| 270 | + let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect(); | ||
| 271 | + let mut dst16 = vec![0u16; block_w * block_h]; | ||
| 267 | let mut cost_of = |mv: (i32, i32)| -> f64 { | 272 | let mut cost_of = |mv: (i32, i32)| -> f64 { |
| 268 | let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3; | 273 | let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3; |
| 269 | let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3; | 274 | let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3; |
| 270 | predict( | 275 | predict( |
| 271 | - reference, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h, &mut dst, | 276 | + &reference16, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h, |
| 277 | + &mut dst16, | ||
| 272 | ); | 278 | ); |
| 273 | let sad: f64 = source | 279 | let sad: f64 = source |
| 274 | .iter() | 280 | .iter() |
| 275 | - .zip(dst.iter()) | 281 | + .zip(dst16.iter()) |
| 276 | .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs())) | 282 | .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs())) |
| 277 | .sum(); | 283 | .sum(); |
| 278 | let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1); | 284 | let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1); |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -0
| @@ -24,6 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | #[cfg(test)] | 25 | #[cfg(test)] |
| 26 | const CAPABILITY_CLAIMS: &[&str] = &[ | 26 | const CAPABILITY_CLAIMS: &[&str] = &[ |
| 27 | + "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", | ||
| 27 | "a non-2D tx class on a rectangular transform (never expected at this size)", | 28 | "a non-2D tx class on a rectangular transform (never expected at this size)", |
| 28 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | 29 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 29 | "a nonzero angle delta (this encoder never writes one)", | 30 | "a nonzero angle delta (this encoder never writes one)", |
| @@ -40,6 +41,7 @@ const REFUSALS: &[&str] = &[ | |||
| 40 | "a 32x32 partition type this decoder does not code (value={part32})", | 41 | "a 32x32 partition type this decoder does not code (value={part32})", |
| 41 | "a Golomb tail longer than this decoder reads", | 42 | "a Golomb tail longer than this decoder reads", |
| 42 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", | 43 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", |
| 44 | + "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", | ||
| 43 | "a tx_type symbol outside its CDF's own set: {t}", | 45 | "a tx_type symbol outside its CDF's own set: {t}", |
| 44 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 46 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 45 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | 47 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
crates/ec-av1/src/restoration.rsmodified+18 -18
| @@ -454,8 +454,8 @@ fn round2(value: i64, shift: u32) -> i64 { | |||
| 454 | /// boundaries do. | 454 | /// boundaries do. |
| 455 | #[allow(clippy::too_many_arguments)] | 455 | #[allow(clippy::too_many_arguments)] |
| 456 | fn lr_sample( | 456 | fn lr_sample( |
| 457 | - cdef: &[u8], | 457 | + cdef: &[u16], |
| 458 | - deblocked: &[u8], | 458 | + deblocked: &[u16], |
| 459 | stride: usize, | 459 | stride: usize, |
| 460 | plane_w: usize, | 460 | plane_w: usize, |
| 461 | plane_h: usize, | 461 | plane_h: usize, |
| @@ -512,9 +512,9 @@ fn lr_sample( | |||
| 512 | /// reproduces the same output byte-for-byte. | 512 | /// reproduces the same output byte-for-byte. |
| 513 | #[allow(clippy::too_many_arguments)] | 513 | #[allow(clippy::too_many_arguments)] |
| 514 | fn apply_wiener_stripe( | 514 | fn apply_wiener_stripe( |
| 515 | - out: &mut [u8], | 515 | + out: &mut [u16], |
| 516 | - cdef: &[u8], | 516 | + cdef: &[u16], |
| 517 | - deblocked: &[u8], | 517 | + deblocked: &[u16], |
| 518 | stride: usize, | 518 | stride: usize, |
| 519 | plane_w: usize, | 519 | plane_w: usize, |
| 520 | plane_h: usize, | 520 | plane_h: usize, |
| @@ -551,7 +551,7 @@ fn apply_wiener_stripe( | |||
| 551 | for (t, &tap) in info.vfilter.iter().enumerate() { | 551 | for (t, &tap) in info.vfilter.iter().enumerate() { |
| 552 | sum += tap as i64 * inter[(r + t) * w + c] as i64; | 552 | sum += tap as i64 * inter[(r + t) * w + c] as i64; |
| 553 | } | 553 | } |
| 554 | - out[(v_start + r) * stride + h_start + c] = round2(sum, 11).clamp(0, 255) as u8; | 554 | + out[(v_start + r) * stride + h_start + c] = round2(sum, 11).clamp(0, crate::decode::sample_max() as i64) as u16; |
| 555 | } | 555 | } |
| 556 | } | 556 | } |
| 557 | } | 557 | } |
| @@ -613,8 +613,8 @@ const SGRPROJ_RST_BITS: u32 = 4; | |||
| 613 | /// reproduces the same values without porting the sliding-window trick. | 613 | /// reproduces the same values without porting the sliding-window trick. |
| 614 | #[allow(clippy::too_many_arguments)] | 614 | #[allow(clippy::too_many_arguments)] |
| 615 | fn compute_ab( | 615 | fn compute_ab( |
| 616 | - cdef: &[u8], | 616 | + cdef: &[u16], |
| 617 | - deblocked: &[u8], | 617 | + deblocked: &[u16], |
| 618 | stride: usize, | 618 | stride: usize, |
| 619 | plane_w: usize, | 619 | plane_w: usize, |
| 620 | plane_h: usize, | 620 | plane_h: usize, |
| @@ -676,9 +676,9 @@ fn compute_ab( | |||
| 676 | /// combined with the decoded `xqd` weights via `av1_decode_xq`. | 676 | /// combined with the decoded `xqd` weights via `av1_decode_xq`. |
| 677 | #[allow(clippy::too_many_arguments)] | 677 | #[allow(clippy::too_many_arguments)] |
| 678 | fn apply_sgrproj_stripe( | 678 | fn apply_sgrproj_stripe( |
| 679 | - out: &mut [u8], | 679 | + out: &mut [u16], |
| 680 | - cdef: &[u8], | 680 | + cdef: &[u16], |
| 681 | - deblocked: &[u8], | 681 | + deblocked: &[u16], |
| 682 | stride: usize, | 682 | stride: usize, |
| 683 | plane_w: usize, | 683 | plane_w: usize, |
| 684 | plane_h: usize, | 684 | plane_h: usize, |
| @@ -807,7 +807,7 @@ fn apply_sgrproj_stripe( | |||
| 807 | ); | 807 | ); |
| 808 | } | 808 | } |
| 809 | } | 809 | } |
| 810 | - let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, 255) as u8; | 810 | + let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, crate::decode::sample_max() as i64) as u16; |
| 811 | out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v; | 811 | out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v; |
| 812 | } | 812 | } |
| 813 | } | 813 | } |
| @@ -822,9 +822,9 @@ fn apply_sgrproj_stripe( | |||
| 822 | /// [`lr_sample`]. | 822 | /// [`lr_sample`]. |
| 823 | #[allow(clippy::too_many_arguments)] | 823 | #[allow(clippy::too_many_arguments)] |
| 824 | fn filter_restoration_unit( | 824 | fn filter_restoration_unit( |
| 825 | - out: &mut [u8], | 825 | + out: &mut [u16], |
| 826 | - cdef: &[u8], | 826 | + cdef: &[u16], |
| 827 | - deblocked: &[u8], | 827 | + deblocked: &[u16], |
| 828 | stride: usize, | 828 | stride: usize, |
| 829 | plane_w: usize, | 829 | plane_w: usize, |
| 830 | plane_h: usize, | 830 | plane_h: usize, |
| @@ -872,8 +872,8 @@ fn filter_restoration_unit( | |||
| 872 | /// place. | 872 | /// place. |
| 873 | #[allow(clippy::too_many_arguments)] | 873 | #[allow(clippy::too_many_arguments)] |
| 874 | pub(crate) fn apply_loop_restoration_plane( | 874 | pub(crate) fn apply_loop_restoration_plane( |
| 875 | - cdef: &[u8], | 875 | + cdef: &[u16], |
| 876 | - deblocked: &[u8], | 876 | + deblocked: &[u16], |
| 877 | stride: usize, | 877 | stride: usize, |
| 878 | plane_w: usize, | 878 | plane_w: usize, |
| 879 | plane_h: usize, | 879 | plane_h: usize, |
| @@ -882,7 +882,7 @@ pub(crate) fn apply_loop_restoration_plane( | |||
| 882 | unit_size: u32, | 882 | unit_size: u32, |
| 883 | grid: &RestorationGrid, | 883 | grid: &RestorationGrid, |
| 884 | plane: usize, | 884 | plane: usize, |
| 885 | -) -> Vec<u8> { | 885 | +) -> Vec<u16> { |
| 886 | let mut out = cdef.to_vec(); | 886 | let mut out = cdef.to_vec(); |
| 887 | if ftype == RestorationType::None || unit_size == 0 { | 887 | if ftype == RestorationType::None || unit_size == 0 { |
| 888 | return out; | 888 | return out; |
crates/ec-av1/src/stream.rsmodified+379 -16
| @@ -650,9 +650,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 650 | use std::io::Write; | 650 | use std::io::Write; |
| 651 | let idx = pictures_decoded; | 651 | let idx = pictures_decoded; |
| 652 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 652 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 653 | - let _ = f.write_all(&picture.y); | 653 | + // lane-hbd r4: debug dump narrows to u8 -- this diagnostic |
| 654 | - let _ = f.write_all(&picture.u); | 654 | + // predates 10-bit support and is an 8-bit-oracle comparison |
| 655 | - let _ = f.write_all(&picture.v); | 655 | + // only (aomdec's own dump is 8-bit here too). |
| 656 | + let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() }; | ||
| 657 | + let _ = f.write_all(&narrow(&picture.y)); | ||
| 658 | + let _ = f.write_all(&narrow(&picture.u)); | ||
| 659 | + let _ = f.write_all(&narrow(&picture.v)); | ||
| 656 | } | 660 | } |
| 657 | } | 661 | } |
| 658 | pictures_decoded += 1; | 662 | pictures_decoded += 1; |
| @@ -692,14 +696,14 @@ mod tests { | |||
| 692 | let mut picture = Pic::grey(width, height); | 696 | let mut picture = Pic::grey(width, height); |
| 693 | for row in 0..height { | 697 | for row in 0..height { |
| 694 | for col in 0..width { | 698 | for col in 0..width { |
| 695 | - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; | 699 | + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; |
| 696 | } | 700 | } |
| 697 | } | 701 | } |
| 698 | for row in 0..height / 2 { | 702 | for row in 0..height / 2 { |
| 699 | for col in 0..width / 2 { | 703 | for col in 0..width / 2 { |
| 700 | let i = row * width / 2 + col; | 704 | let i = row * width / 2 + col; |
| 701 | - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; | 705 | + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; |
| 702 | - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; | 706 | + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; |
| 703 | } | 707 | } |
| 704 | } | 708 | } |
| 705 | picture | 709 | picture |
| @@ -711,15 +715,15 @@ mod tests { | |||
| 711 | for x in 0..width { | 715 | for x in 0..width { |
| 712 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; | 716 | let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; |
| 713 | let gradient = sx * 200.0 / width as f64; | 717 | let gradient = sx * 200.0 / width as f64; |
| 714 | - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; | 718 | + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; |
| 715 | } | 719 | } |
| 716 | } | 720 | } |
| 717 | for y in 0..height / 2 { | 721 | for y in 0..height / 2 { |
| 718 | for x in 0..width / 2 { | 722 | for x in 0..width / 2 { |
| 719 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; | 723 | let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; |
| 720 | let i = y * width / 2 + x; | 724 | let i = y * width / 2 + x; |
| 721 | - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; | 725 | + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; |
| 722 | - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; | 726 | + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; |
| 723 | } | 727 | } |
| 724 | } | 728 | } |
| 725 | picture | 729 | picture |
| @@ -883,9 +887,9 @@ mod tests { | |||
| 883 | Pic { | 887 | Pic { |
| 884 | width, | 888 | width, |
| 885 | height, | 889 | height, |
| 886 | - y: out.stdout[base..base + luma].to_vec(), | 890 | + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), |
| 887 | - u: out.stdout[base + luma..base + luma + chroma].to_vec(), | 891 | + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), |
| 888 | - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), | 892 | + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), |
| 889 | } | 893 | } |
| 890 | }) | 894 | }) |
| 891 | .collect() | 895 | .collect() |
| @@ -1723,6 +1727,124 @@ mod tests { | |||
| 1723 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | 1727 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); |
| 1724 | } | 1728 | } |
| 1725 | 1729 | ||
| 1730 | + /// A real `aomenc` palette-**UV** fixture (lane-palette2 r2): `testsrc2` | ||
| 1731 | + /// (the multicoloured AV1 test pattern -- flat, few-colour, repetitive | ||
| 1732 | + /// per-region colour *and* chroma, unlike `smptebars=hue=s=0` above, | ||
| 1733 | + /// which flattened chroma to a single value specifically to avoid | ||
| 1734 | + /// exercising this path). Same square-only recipe as the palette-Y gate | ||
| 1735 | + /// (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, fixed 32x32 partition) | ||
| 1736 | + /// so a UV palette block never lands inside the still-refused HORZ/VERT | ||
| 1737 | + /// screen-content strip. HARD-asserts [`decode::palette_uv_hits`] moved | ||
| 1738 | + /// -- a stream that never reads a real UV palette block would decode (or | ||
| 1739 | + /// not) by construction without proving this milestone at all | ||
| 1740 | + /// ([[gate-blind-to-feature]]). | ||
| 1741 | + #[test] | ||
| 1742 | + fn a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact() { | ||
| 1743 | + const NAME: &str = "a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact"; | ||
| 1744 | + if !have_ffmpeg() { | ||
| 1745 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 1746 | + return; | ||
| 1747 | + } | ||
| 1748 | + if !have_aomenc() { | ||
| 1749 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 1750 | + return; | ||
| 1751 | + } | ||
| 1752 | + let source = "testsrc2=size=64x64:rate=25"; | ||
| 1753 | + fn render(source: &str) -> Vec<u8> { | ||
| 1754 | + Command::new("ffmpeg") | ||
| 1755 | + .args([ | ||
| 1756 | + "-v", | ||
| 1757 | + "error", | ||
| 1758 | + "-f", | ||
| 1759 | + "lavfi", | ||
| 1760 | + "-i", | ||
| 1761 | + source, | ||
| 1762 | + "-pix_fmt", | ||
| 1763 | + "yuv420p", | ||
| 1764 | + "-t", | ||
| 1765 | + "0.16", | ||
| 1766 | + "-f", | ||
| 1767 | + "yuv4mpegpipe", | ||
| 1768 | + "-", | ||
| 1769 | + ]) | ||
| 1770 | + .stdin(Stdio::null()) | ||
| 1771 | + .stdout(Stdio::piped()) | ||
| 1772 | + .stderr(Stdio::piped()) | ||
| 1773 | + .output() | ||
| 1774 | + .expect("ffmpeg failed to run") | ||
| 1775 | + .stdout | ||
| 1776 | + } | ||
| 1777 | + let y4m_a = render(source); | ||
| 1778 | + let y4m_b = render(source); | ||
| 1779 | + assert_eq!( | ||
| 1780 | + y4m_a, y4m_b, | ||
| 1781 | + "testsrc2 must render byte-identical across two runs" | ||
| 1782 | + ); | ||
| 1783 | + let y4m = y4m_a; | ||
| 1784 | + let mut child = Command::new(aomenc_path()) | ||
| 1785 | + .args([ | ||
| 1786 | + "--codec=av1", | ||
| 1787 | + "--passes=1", | ||
| 1788 | + "--end-usage=q", | ||
| 1789 | + "--cq-level=30", | ||
| 1790 | + "--cpu-used=0", | ||
| 1791 | + "--threads=1", | ||
| 1792 | + "--row-mt=0", | ||
| 1793 | + "--sb-size=64", | ||
| 1794 | + "--tune-content=screen", | ||
| 1795 | + "--enable-palette=1", | ||
| 1796 | + "--enable-intrabc=0", | ||
| 1797 | + "--enable-rect-partitions=0", | ||
| 1798 | + "--enable-ab-partitions=0", | ||
| 1799 | + "--enable-1to4-partitions=0", | ||
| 1800 | + "--min-partition-size=32", | ||
| 1801 | + "--max-partition-size=32", | ||
| 1802 | + "--enable-filter-intra=0", | ||
| 1803 | + "--enable-cdef=0", | ||
| 1804 | + "--enable-restoration=0", | ||
| 1805 | + "--enable-tx-size-search=0", | ||
| 1806 | + "--loopfilter-control=0", | ||
| 1807 | + "--obu", | ||
| 1808 | + "-o", | ||
| 1809 | + "-", | ||
| 1810 | + "-", | ||
| 1811 | + ]) | ||
| 1812 | + .stdin(Stdio::piped()) | ||
| 1813 | + .stdout(Stdio::piped()) | ||
| 1814 | + .stderr(Stdio::piped()) | ||
| 1815 | + .spawn() | ||
| 1816 | + .expect("aomenc failed to start"); | ||
| 1817 | + child | ||
| 1818 | + .stdin | ||
| 1819 | + .take() | ||
| 1820 | + .expect("aomenc stdin") | ||
| 1821 | + .write_all(&y4m) | ||
| 1822 | + .expect("writing y4m to aomenc"); | ||
| 1823 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1824 | + assert!( | ||
| 1825 | + out.status.success(), | ||
| 1826 | + "aomenc refused the fixture: {}", | ||
| 1827 | + String::from_utf8_lossy(&out.stderr) | ||
| 1828 | + ); | ||
| 1829 | + let stream = out.stdout; | ||
| 1830 | + let before = decode::palette_uv_hits(); | ||
| 1831 | + let frames = match decode_stream(&stream) { | ||
| 1832 | + Ok(frames) => frames, | ||
| 1833 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 1834 | + }; | ||
| 1835 | + assert!( | ||
| 1836 | + decode::palette_uv_hits() > before, | ||
| 1837 | + "palette_uv_mode never fired decoding this stream -- gate is vacuous" | ||
| 1838 | + ); | ||
| 1839 | + let frame_count = frames.len(); | ||
| 1840 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, frame_count); | ||
| 1841 | + for i in 0..frame_count { | ||
| 1842 | + assert_eq!(frames[i].y, ffmpeg_frames[i].y, "luma vs ffmpeg, frame {i}"); | ||
| 1843 | + assert_eq!(frames[i].u, ffmpeg_frames[i].u, "U vs ffmpeg, frame {i}"); | ||
| 1844 | + assert_eq!(frames[i].v, ffmpeg_frames[i].v, "V vs ffmpeg, frame {i}"); | ||
| 1845 | + } | ||
| 1846 | + } | ||
| 1847 | + | ||
| 1726 | /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s | 1848 | /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s |
| 1727 | /// harness, but with the deblocking filter left *on* (no | 1849 | /// harness, but with the deblocking filter left *on* (no |
| 1728 | /// `--loopfilter-control=0`) at a crf high enough that libaom actually | 1850 | /// `--loopfilter-control=0`) at a crf high enough that libaom actually |
| @@ -2752,7 +2874,7 @@ mod tests { | |||
| 2752 | // actually produced -- no second ffmpeg invocation needed). | 2874 | // actually produced -- no second ffmpeg invocation needed). |
| 2753 | let ffmpeg_raw: Vec<u8> = ffmpeg_frames | 2875 | let ffmpeg_raw: Vec<u8> = ffmpeg_frames |
| 2754 | .iter() | 2876 | .iter() |
| 2755 | - .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).copied()) | 2877 | + .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).map(|&v| v as u8)) |
| 2756 | .collect(); | 2878 | .collect(); |
| 2757 | let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw); | 2879 | let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw); |
| 2758 | eprintln!( | 2880 | eprintln!( |
| @@ -6615,9 +6737,9 @@ mod tests { | |||
| 6615 | let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames); | 6737 | let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames); |
| 6616 | for f in 0..frames { | 6738 | for f in 0..frames { |
| 6617 | let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64); | 6739 | let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64); |
| 6618 | - yuv.extend_from_slice(&card.y); | 6740 | + yuv.extend(card.y.iter().map(|&v| v as u8)); |
| 6619 | - yuv.extend_from_slice(&card.u); | 6741 | + yuv.extend(card.u.iter().map(|&v| v as u8)); |
| 6620 | - yuv.extend_from_slice(&card.v); | 6742 | + yuv.extend(card.v.iter().map(|&v| v as u8)); |
| 6621 | } | 6743 | } |
| 6622 | std::fs::write(&yuv_path, &yuv).unwrap(); | 6744 | std::fs::write(&yuv_path, &yuv).unwrap(); |
| 6623 | let status = Command::new(aomenc_path()) | 6745 | let status = Command::new(aomenc_path()) |
| @@ -8508,4 +8630,245 @@ mod tests { | |||
| 8508 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | 8630 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" |
| 8509 | ); | 8631 | ); |
| 8510 | } | 8632 | } |
| 8633 | + | ||
| 8634 | + /// lane-sbpart r2: a real `aomenc` stream whose superblock-level | ||
| 8635 | + /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must | ||
| 8636 | + /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- | ||
| 8637 | + /// `sb_rect_hits() > 0` is a HARD assert (this round's rule: a removed | ||
| 8638 | + /// refusal needs a firing gate in the same commit, not a green suite | ||
| 8639 | + /// that never took the new path). Recipe = the charter's own, verified | ||
| 8640 | + /// live by r1: `--min/max-partition-size=32/64` keeps the RD search | ||
| 8641 | + /// from ever recursing below 32x32, so every SB-level decision is | ||
| 8642 | + /// genuinely NONE/SPLIT/HORZ/VERT; a `gradients` source blended with | ||
| 8643 | + /// `testsrc2` (lavfi `blend=all_mode=average`) keeps the content from | ||
| 8644 | + /// being flat enough that the search stops at NONE every time. | ||
| 8645 | + #[test] | ||
| 8646 | + fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact() { | ||
| 8647 | + const NAME: &str = | ||
| 8648 | + "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact"; | ||
| 8649 | + let _gate_lock = lock_gate_counters(); | ||
| 8650 | + if !have_ffmpeg() { | ||
| 8651 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8652 | + return; | ||
| 8653 | + } | ||
| 8654 | + if !have_aomenc() { | ||
| 8655 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 8656 | + return; | ||
| 8657 | + } | ||
| 8658 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | ||
| 8659 | + let mut named_refusals = 0u32; | ||
| 8660 | + let mut matched = 0u32; | ||
| 8661 | + let n_attempts: u32 = std::env::var("EC_SBPART_GATE_ATTEMPTS") | ||
| 8662 | + .ok() | ||
| 8663 | + .and_then(|s| s.parse().ok()) | ||
| 8664 | + .unwrap_or(40); | ||
| 8665 | + for attempt in 0..n_attempts { | ||
| 8666 | + let seed = 42 + attempt; | ||
| 8667 | + let duration = frame_count as f64 / 25.0; | ||
| 8668 | + let source = | ||
| 8669 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | ||
| 8670 | + let y4m = Command::new("ffmpeg") | ||
| 8671 | + .args([ | ||
| 8672 | + "-v", | ||
| 8673 | + "error", | ||
| 8674 | + "-f", | ||
| 8675 | + "lavfi", | ||
| 8676 | + "-i", | ||
| 8677 | + &source, | ||
| 8678 | + "-pix_fmt", | ||
| 8679 | + "yuv420p", | ||
| 8680 | + "-f", | ||
| 8681 | + "yuv4mpegpipe", | ||
| 8682 | + "-", | ||
| 8683 | + ]) | ||
| 8684 | + .stdin(Stdio::null()) | ||
| 8685 | + .stdout(Stdio::piped()) | ||
| 8686 | + .stderr(Stdio::piped()) | ||
| 8687 | + .output() | ||
| 8688 | + .expect("ffmpeg failed to run"); | ||
| 8689 | + assert!( | ||
| 8690 | + y4m.status.success(), | ||
| 8691 | + "ffmpeg fixture: {}", | ||
| 8692 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 8693 | + ); | ||
| 8694 | + let args: Vec<&str> = vec![ | ||
| 8695 | + "--codec=av1", | ||
| 8696 | + "--passes=1", | ||
| 8697 | + "--end-usage=q", | ||
| 8698 | + "--cq-level=45", | ||
| 8699 | + "--cpu-used=0", | ||
| 8700 | + "--threads=1", | ||
| 8701 | + "--row-mt=0", | ||
| 8702 | + "--sb-size=64", | ||
| 8703 | + "--enable-rect-partitions=1", | ||
| 8704 | + "--enable-ab-partitions=0", | ||
| 8705 | + "--enable-1to4-partitions=0", | ||
| 8706 | + "--min-partition-size=32", | ||
| 8707 | + "--max-partition-size=64", | ||
| 8708 | + "--enable-restoration=0", | ||
| 8709 | + "--enable-palette=0", | ||
| 8710 | + "--deltaq-mode=0", | ||
| 8711 | + "--enable-filter-intra=0", | ||
| 8712 | + "--enable-cfl-intra=0", | ||
| 8713 | + "--enable-intrabc=0", | ||
| 8714 | + "--enable-tx-size-search=0", | ||
| 8715 | + "--obu", | ||
| 8716 | + "-o", | ||
| 8717 | + "-", | ||
| 8718 | + "-", | ||
| 8719 | + ]; | ||
| 8720 | + let mut child = Command::new(aomenc_path()) | ||
| 8721 | + .args(&args) | ||
| 8722 | + .stdin(Stdio::piped()) | ||
| 8723 | + .stdout(Stdio::piped()) | ||
| 8724 | + .stderr(Stdio::piped()) | ||
| 8725 | + .spawn() | ||
| 8726 | + .expect("aomenc failed to start"); | ||
| 8727 | + child | ||
| 8728 | + .stdin | ||
| 8729 | + .take() | ||
| 8730 | + .expect("aomenc stdin") | ||
| 8731 | + .write_all(&y4m.stdout) | ||
| 8732 | + .expect("writing y4m to aomenc"); | ||
| 8733 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 8734 | + assert!( | ||
| 8735 | + out.status.success(), | ||
| 8736 | + "aomenc refused the fixture: {}", | ||
| 8737 | + String::from_utf8_lossy(&out.stderr) | ||
| 8738 | + ); | ||
| 8739 | + let stream = out.stdout; | ||
| 8740 | + let frames = match decode_stream(&stream) { | ||
| 8741 | + Err(e) => { | ||
| 8742 | + let msg = e.to_string(); | ||
| 8743 | + assert!( | ||
| 8744 | + msg.contains("unsupported"), | ||
| 8745 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 8746 | + ); | ||
| 8747 | + // r2: `--enable-ab-partitions=0` does NOT stop aomenc | ||
| 8748 | + // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B | ||
| 8749 | + // (`partition_w64` value 4-7) even with | ||
| 8750 | + // `--min/max-partition-size=32/64` -- a real, separate | ||
| 8751 | + // encoder quirk (AB-at-64 is a different, unlanded | ||
| 8752 | + // capability, lane-partab's territory is 32x32 and | ||
| 8753 | + // below only) discovered live this round, not this | ||
| 8754 | + // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT | ||
| 8755 | + // (values 0-3) are this gate's territory; a real | ||
| 8756 | + // HORZ/VERT (1/2) must still decode pixel-exact, which | ||
| 8757 | + // `sb_rect_hits() > 0` below hard-proves. | ||
| 8758 | + named_refusals += 1; | ||
| 8759 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 8760 | + continue; | ||
| 8761 | + } | ||
| 8762 | + Ok(frames) => frames, | ||
| 8763 | + }; | ||
| 8764 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 8765 | + assert_eq!(frames.len(), frame_count); | ||
| 8766 | + let mismatched = frames | ||
| 8767 | + .iter() | ||
| 8768 | + .zip(&ffmpeg_frames) | ||
| 8769 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 8770 | + if mismatched { | ||
| 8771 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 8772 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 8773 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | ||
| 8774 | + } | ||
| 8775 | + } | ||
| 8776 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8777 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 8778 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | ||
| 8779 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | ||
| 8780 | + } | ||
| 8781 | + matched += 1; | ||
| 8782 | + } | ||
| 8783 | + assert!( | ||
| 8784 | + matched > 0, | ||
| 8785 | + "{NAME}: every attempt refused; the gate never decoded a stream" | ||
| 8786 | + ); | ||
| 8787 | + assert!( | ||
| 8788 | + crate::decode::sb_rect_hits() > 0, | ||
| 8789 | + "{NAME}: zero superblock-level HORZ/VERT blocks fired ({matched} matches, \ | ||
| 8790 | + {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" | ||
| 8791 | + ); | ||
| 8792 | + eprintln!( | ||
| 8793 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ | ||
| 8794 | + {n_attempts}, sb_rect_hits={}", | ||
| 8795 | + crate::decode::sb_rect_hits() | ||
| 8796 | + ); | ||
| 8797 | + } | ||
| 8798 | + | ||
| 8799 | + /// lane-sbpart r4: replays a pinned mismatch byte-for-byte off disk (no | ||
| 8800 | + /// aomenc/ffmpeg re-encode), same pattern as `pinned_golden3/4_stream_ | ||
| 8801 | + /// decodes_pixel_exact` -- fast red/green loop for the bisect, and lets | ||
| 8802 | + /// `EC_AV1_TRACE=1` be set for one run without re-driving the encoder. | ||
| 8803 | + #[test] | ||
| 8804 | + #[ignore = "reads a pinned fixture path outside the repo; run manually"] | ||
| 8805 | + fn pinned_sbpart_stream_decodes_pixel_exact() { | ||
| 8806 | + let path = std::env::var("EC_AV1_GATE_DUMP_PIN") | ||
| 8807 | + .map(std::path::PathBuf::from) | ||
| 8808 | + .unwrap_or_else(|_| pin_dir().join("sbpart-pin.obu")); | ||
| 8809 | + let Ok(stream) = std::fs::read(&path) else { | ||
| 8810 | + eprintln!( | ||
| 8811 | + "SKIP pinned_sbpart_stream_decodes_pixel_exact: no pinned bytes at {} \ | ||
| 8812 | + -- re-capture with EC_AV1_GATE_DUMP off the sbpart gate", | ||
| 8813 | + path.display() | ||
| 8814 | + ); | ||
| 8815 | + return; | ||
| 8816 | + }; | ||
| 8817 | + if !have_ffmpeg() { | ||
| 8818 | + eprintln!("SKIP pinned_sbpart_stream_decodes_pixel_exact: no ffmpeg"); | ||
| 8819 | + return; | ||
| 8820 | + } | ||
| 8821 | + let frames = decode_stream(&stream).expect("pinned stream must decode"); | ||
| 8822 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 192, 128, 1); | ||
| 8823 | + let (width, height) = (192usize, 128usize); | ||
| 8824 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8825 | + if std::env::var_os("EC_SBPART_DIAG").is_some() { | ||
| 8826 | + let (mut min_r, mut max_r, mut min_c, mut max_c, mut n) = | ||
| 8827 | + (usize::MAX, 0usize, usize::MAX, 0usize, 0usize); | ||
| 8828 | + for r in 0..height { | ||
| 8829 | + for c in 0..width { | ||
| 8830 | + let idx = r * width + c; | ||
| 8831 | + if got.y[idx] != want.y[idx] { | ||
| 8832 | + min_r = min_r.min(r); | ||
| 8833 | + max_r = max_r.max(r); | ||
| 8834 | + min_c = min_c.min(c); | ||
| 8835 | + max_c = max_c.max(c); | ||
| 8836 | + n += 1; | ||
| 8837 | + } | ||
| 8838 | + } | ||
| 8839 | + } | ||
| 8840 | + eprintln!( | ||
| 8841 | + "DIAG frame {i}: {n} luma mismatches, bbox rows [{min_r}..{max_r}] cols \ | ||
| 8842 | + [{min_c}..{max_c}] of {width}x{height}" | ||
| 8843 | + ); | ||
| 8844 | + // Per-64px-superblock-column mismatch counts, to see whether | ||
| 8845 | + // corruption starts exactly at the rect64 SB or bleeds into | ||
| 8846 | + // SBs decoded earlier (raster order). | ||
| 8847 | + for sb_col in 0..(width + 63) / 64 { | ||
| 8848 | + let c0 = sb_col * 64; | ||
| 8849 | + let c1 = (c0 + 64).min(width); | ||
| 8850 | + let mut cnt = 0usize; | ||
| 8851 | + let mut first = None; | ||
| 8852 | + for r in 0..height { | ||
| 8853 | + for c in c0..c1 { | ||
| 8854 | + let idx = r * width + c; | ||
| 8855 | + if got.y[idx] != want.y[idx] { | ||
| 8856 | + cnt += 1; | ||
| 8857 | + if first.is_none() { | ||
| 8858 | + first = Some((r, c)); | ||
| 8859 | + } | ||
| 8860 | + } | ||
| 8861 | + } | ||
| 8862 | + } | ||
| 8863 | + eprintln!( | ||
| 8864 | + "DIAG frame {i} sb_col {sb_col} (cols {c0}..{c1}): {cnt} mismatches, \ | ||
| 8865 | + first={first:?}" | ||
| 8866 | + ); | ||
| 8867 | + } | ||
| 8868 | + } | ||
| 8869 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (pinned sbpart)"); | ||
| 8870 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (pinned sbpart)"); | ||
| 8871 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned sbpart)"); | ||
| 8872 | + } | ||
| 8873 | + } | ||
| 8511 | } | 8874 | } |
crates/ec-av1/src/superres.rsmodified+27 -12
| @@ -191,30 +191,45 @@ pub(crate) fn upscale_picture( | |||
| 191 | let chroma_in_w = picture.width.div_ceil(2); | 191 | let chroma_in_w = picture.width.div_ceil(2); |
| 192 | let chroma_out_w = upscaled_width.div_ceil(2); | 192 | let chroma_out_w = upscaled_width.div_ceil(2); |
| 193 | let chroma_h = height.div_ceil(2); | 193 | let chroma_h = height.div_ceil(2); |
| 194 | + // lane-hbd r4: superres is 8-bit by construction (`upscale_row` clamps | ||
| 195 | + // to 255) -- narrow at this boundary; callers refuse `bit_depth != 8` | ||
| 196 | + // before ever reaching here (see `stream.rs`). | ||
| 197 | + let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() }; | ||
| 198 | + let picture_y8 = narrow(&picture.y); | ||
| 199 | + let picture_u8 = narrow(&picture.u); | ||
| 200 | + let picture_v8 = narrow(&picture.v); | ||
| 201 | + let margin_y8 = margin.map(|m| narrow(&m.y)); | ||
| 202 | + let margin_u8 = margin.map(|m| narrow(&m.u)); | ||
| 203 | + let margin_v8 = margin.map(|m| narrow(&m.v)); | ||
| 204 | + let widen = |v: Vec<u8>| -> Vec<u16> { v.into_iter().map(u16::from).collect() }; | ||
| 194 | crate::encode::Picture { | 205 | crate::encode::Picture { |
| 195 | width: upscaled_width, | 206 | width: upscaled_width, |
| 196 | height, | 207 | height, |
| 197 | - y: upscale_plane( | 208 | + y: widen(upscale_plane( |
| 198 | - &picture.y, | 209 | + &picture_y8, |
| 199 | height, | 210 | height, |
| 200 | picture.width, | 211 | picture.width, |
| 201 | upscaled_width, | 212 | upscaled_width, |
| 202 | - margin.map(|m| (m.y.as_slice(), m.width)), | 213 | + margin_y8.as_deref().map(|m| (m, margin.unwrap().width)), |
| 203 | - ), | 214 | + )), |
| 204 | - u: upscale_plane( | 215 | + u: widen(upscale_plane( |
| 205 | - &picture.u, | 216 | + &picture_u8, |
| 206 | chroma_h, | 217 | chroma_h, |
| 207 | chroma_in_w, | 218 | chroma_in_w, |
| 208 | chroma_out_w, | 219 | chroma_out_w, |
| 209 | - margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), | 220 | + margin_u8 |
| 210 | - ), | 221 | + .as_deref() |
| 211 | - v: upscale_plane( | 222 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), |
| 212 | - &picture.v, | 223 | + )), |
| 224 | + v: widen(upscale_plane( | ||
| 225 | + &picture_v8, | ||
| 213 | chroma_h, | 226 | chroma_h, |
| 214 | chroma_in_w, | 227 | chroma_in_w, |
| 215 | chroma_out_w, | 228 | chroma_out_w, |
| 216 | - margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), | 229 | + margin_v8 |
| 217 | - ), | 230 | + .as_deref() |
| 231 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), | ||
| 232 | + )), | ||
| 218 | } | 233 | } |
| 219 | } | 234 | } |
| 220 | 235 | ||
crates/ec-av1/src/warp.rsmodified+4 -4
| @@ -415,8 +415,8 @@ pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams> { | |||
| 415 | Some(WarpParams { wmmat, alpha, beta, gamma, delta }) | 415 | Some(WarpParams { wmmat, alpha, beta, gamma, delta }) |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | -fn clip_pixel(v: i32) -> u8 { | 418 | +fn clip_pixel(v: i32) -> u16 { |
| 419 | - v.clamp(0, 255) as u8 | 419 | + v.clamp(0, crate::decode::sample_max()) as u16 |
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | /// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only: | 422 | /// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only: |
| @@ -427,11 +427,11 @@ fn clip_pixel(v: i32) -> u8 { | |||
| 427 | #[allow(clippy::too_many_arguments)] | 427 | #[allow(clippy::too_many_arguments)] |
| 428 | pub fn warp_affine( | 428 | pub fn warp_affine( |
| 429 | params: &WarpParams, | 429 | params: &WarpParams, |
| 430 | - reference: &[u8], | 430 | + reference: &[u16], |
| 431 | width: i32, | 431 | width: i32, |
| 432 | height: i32, | 432 | height: i32, |
| 433 | stride: i32, | 433 | stride: i32, |
| 434 | - dst: &mut [u8], | 434 | + dst: &mut [u16], |
| 435 | p_col: i32, | 435 | p_col: i32, |
| 436 | p_row: i32, | 436 | p_row: i32, |
| 437 | p_width: i32, | 437 | p_width: i32, |
lanes/hbd-r1.charter.mdadded+51 -0
| @@ -0,0 +1,51 @@ | |||
| 1 | +# lane-hbd r1 — widen the sample type | ||
| 2 | + | ||
| 3 | +Fresh worktree off main (71a2624), suite green at 263/0. This lane replaces | ||
| 4 | +lane-realworld, whose decode work is all merged; only the high-bit-depth job is | ||
| 5 | +left, and it now has a clean branch instead of a stale one. Read | ||
| 6 | +`lanes/realworld-r8.report.md` (site inventory) and `lanes/realworld-r10.report.md` | ||
| 7 | +(the previous attempt) first. | ||
| 8 | + | ||
| 9 | +**Why this matters:** both AV1 films in the user's library are `yuv420p10le` and | ||
| 10 | +stop at the `bit_depth != 8` refusal. This is the critical path to his own files. | ||
| 11 | + | ||
| 12 | +## Start from the saved diff, do not retype it | ||
| 13 | +r10 got `PlaneBuf::data -> Vec<u16>` plus all of `intra.rs` type-correct before | ||
| 14 | +its cap, then reverted, saving the 500-line diff at | ||
| 15 | +`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/r10-attempt.diff`. | ||
| 16 | +`git apply` it first. If it no longer applies (main moved: UV palette landed), | ||
| 17 | +re-apply what does and redo the rest by hand — but check before assuming. | ||
| 18 | + | ||
| 19 | +Then, in this order, per r10's own handoff: | ||
| 20 | +1. `restoration.rs`'s `apply_loop_restoration_plane` (still `Vec<u8>` in/out, | ||
| 21 | + 3 call sites at `decode.rs` ~5445/5457/5469), two debug-dump narrowing | ||
| 22 | + closures, and `reconstruct_mc`'s clamp — all small and mechanical. | ||
| 23 | +2. `mc.rs` LAST: 6 functions still `&[u8]`/`&mut [u8]`, ~24 `decode.rs` call | ||
| 24 | + sites resolve for free once they widen. Use the `sample_max()` pattern | ||
| 25 | + `intra.rs` proved. | ||
| 26 | +3. `encode.rs`'s 3 call sites into `intra.rs` (~600, ~820, ~872) — the encoder | ||
| 27 | + shares those predictors. r10 found these; they were NOT in the original | ||
| 28 | + inventory. Decide deliberately: widen the encoder's buffers too, or box | ||
| 29 | + u8<->u16 locally at those three sites. Say which and why. | ||
| 30 | + | ||
| 31 | +**8-bit output must stay bit-exact.** The 263-test suite is the regression gate; | ||
| 32 | +run it before every commit. Do NOT lift the `bit_depth != 8` refusal and do not | ||
| 33 | +build a 10-bit gate this round — `ffmpeg_decode_sequence` hardcodes | ||
| 34 | +`-pix_fmt yuv420p`, so a 10-bit gate needs a second helper with u16 LE parsing, | ||
| 35 | +and that plus the first real 10-bit stream is the next round. | ||
| 36 | + | ||
| 37 | +Note from r10: `git checkout` and `git stash` were blocked in that session; | ||
| 38 | +`git apply -R <saved-diff>` is the working revert mechanism if you need one. | ||
| 39 | + | ||
| 40 | +## Budget discipline | ||
| 41 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 42 | +what compiles and passes, and write your report. Do NOT revert working partial | ||
| 43 | +work to make the report tidier — a compiling, green, partially widened crate is | ||
| 44 | +a fine place to stop. | ||
| 45 | + | ||
| 46 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | ||
| 47 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 48 | +`EC_AV1_REQUIRE_AOMENC=1`. Do NOT open the user's media in a GUI app — ffmpeg | ||
| 49 | +and `decode_probe` only. Sibling worktrees have live agents — never build in or | ||
| 50 | +edit them. Never push, never merge into main; I handle merges. End with | ||
| 51 | +`lanes/hbd-r1.report.md`, VERDICT on line 1. | ||
lanes/hbd-r2.charter.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-hbd r2 — 42 errors to zero | ||
| 2 | + | ||
| 3 | +At a86872b. r1 applied the saved diff and widened well past it before its cap; | ||
| 4 | +I committed its tree verbatim. **It does not compile: `cargo check -p ec-av1 | ||
| 5 | +--lib` reports 42 errors, 41 of them E0308 type mismatches.** There are no | ||
| 6 | +conflict markers — I checked. | ||
| 7 | + | ||
| 8 | +That number is your progress metric. Drive it to zero. | ||
| 9 | + | ||
| 10 | +## Checkpoint policy for this round — read this, it is different | ||
| 11 | +A half-widened crate cannot compile, so "commit only when green" would mean | ||
| 12 | +committing nothing until the very end, which is exactly how two rounds have died | ||
| 13 | +here. Instead: **commit a `wip(hbd):` checkpoint whenever the error count drops | ||
| 14 | +meaningfully** (say every 10 errors), with the count in the message. A | ||
| 15 | +non-compiling commit is acceptable ONLY on this branch, ONLY with that prefix, | ||
| 16 | +and ONLY while the count is falling — it is never merged in that state. Once the | ||
| 17 | +count hits zero, run the full suite and make a real commit. | ||
| 18 | + | ||
| 19 | +## Order (r10's, still valid) | ||
| 20 | +`restoration.rs`'s `apply_loop_restoration_plane` and its 3 `decode.rs` call | ||
| 21 | +sites; the debug-dump narrowing closures; `reconstruct_mc`'s clamp; then `mc.rs` | ||
| 22 | +LAST — its 6 `&[u8]`/`&mut [u8]` functions unlock ~24 `decode.rs` call sites at | ||
| 23 | +once, using the `sample_max()` pattern `intra.rs` already proves. Then | ||
| 24 | +`encode.rs`'s 3 call sites into `intra.rs`: decide deliberately whether the | ||
| 25 | +encoder's buffers widen too or get a local u8<->u16 box, and say which and why — | ||
| 26 | +the encoder shares those predictors and was not in the original inventory. | ||
| 27 | + | ||
| 28 | +**8-bit output must stay bit-exact.** The 263-test suite is the gate once it | ||
| 29 | +compiles; a single pixel of drift there means a clamp bound or a rounding step | ||
| 30 | +was widened wrong. | ||
| 31 | + | ||
| 32 | +Do NOT lift the `bit_depth != 8` refusal and do not build a 10-bit gate — that | ||
| 33 | +is the next round, and it needs a second `ffmpeg_decode_sequence` helper emitting | ||
| 34 | +`yuv420p10le` with u16 LE parsing. | ||
| 35 | + | ||
| 36 | +`git checkout` and `git stash` have been blocked in these sessions; use | ||
| 37 | +`git apply -R <diff>` if you need to undo something. | ||
| 38 | + | ||
| 39 | +## Budget discipline | ||
| 40 | +75 turns, no reset on resume. At about turn 55, stop starting new work, commit | ||
| 41 | +your checkpoint, and write the report with the current error count in it. | ||
| 42 | + | ||
| 43 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | ||
| 44 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 45 | +`EC_AV1_REQUIRE_AOMENC=1`. Do NOT open the user's media in a GUI app. Sibling | ||
| 46 | +worktrees have live agents — never build in or edit them. Never push, never merge | ||
| 47 | +into main; I handle merges. End with `lanes/hbd-r2.report.md`, VERDICT on line 1. | ||
lanes/hbd-r2.report.mdadded+102 -0
| @@ -0,0 +1,102 @@ | |||
| 1 | +VERDICT: Done. `cargo check -p ec-av1 --lib --tests` reports 0 errors (42 -> 0), | ||
| 2 | +and `cargo test -p ec-av1` (`EC_AV1_REQUIRE_AOMENC=1`) is 263 passed, 0 failed, | ||
| 3 | +18 ignored -- 8-bit output is bit-exact. Real commit 213eeac on top of two | ||
| 4 | +`wip(hbd):` checkpoints (177aa1c at 42->5, 6e6dbbb at --lib clean/17 test | ||
| 5 | +errors left). | ||
| 6 | + | ||
| 7 | +## What actually needed doing | ||
| 8 | + | ||
| 9 | +r1's saved diff had already widened `PlaneBuf::data`, intra prediction, and | ||
| 10 | +all six of `mc.rs`'s prediction/blend functions to `u16` -- the charter's own | ||
| 11 | +"mc.rs last, it unlocks ~24 call sites" order was already moot; `mc.rs` was | ||
| 12 | +done. The 42 errors were all downstream call sites that hadn't caught up: | ||
| 13 | + | ||
| 14 | +- `warp.rs`'s `warp_affine` (`reference`/`dst` still `&[u8]`/`&mut [u8]`, | ||
| 15 | + only caller is 3 `decode.rs` sites) -- widened. | ||
| 16 | +- `decode.rs`'s OBMC chain (`obmc_neighbour_pred`, `obmc_blend_v`, | ||
| 17 | + `obmc_blend_h`, `obmc_blend`) and interintra chain (`interintra_blend`, | ||
| 18 | + its local `intra` scratch buffer) -- both fed by the same `pred_y`/ | ||
| 19 | + `pred_u`/`pred_v` buffers `read_inter_plane`'s call sites already needed | ||
| 20 | + widened, so one `vec![0u8; ...]` -> `vec![0u16; ...]` sweep across those | ||
| 21 | + buffer declarations (12 sites) plus the two function chains closed 37 of | ||
| 22 | + the 42 lib errors. | ||
| 23 | +- `read_inter_plane`'s own `prediction: &[u8]` parameter -> `&[u16]`. | ||
| 24 | +- `encode.rs` (3 call sites into `intra::predict`) and `motion.rs` (1 call | ||
| 25 | + site into `mc::predict`) -- see decision below. | ||
| 26 | + | ||
| 27 | +## The encoder decision (charter asked for one) | ||
| 28 | + | ||
| 29 | +The encoder's own buffers (`Plane::source`, `Plane::reconstruction`, the | ||
| 30 | +motion-search `reference`/`source`) stay `u8` -- this round does not widen | ||
| 31 | +the encoder, and nothing forces it to: the encoder is 8-bit-only by design | ||
| 32 | +(`Picture`'s `y`/`u`/`v` are still `Vec<u8>`, unchanged this round), so there | ||
| 33 | +is no wider content for it to ever hold. Widening those buffers to `u16` | ||
| 34 | +would have added real diff for zero behavioural change and speculative | ||
| 35 | +10-bit-encode plumbing nobody asked for. | ||
| 36 | + | ||
| 37 | +Instead, each of the 4 sites gets a local `u8<->u16` round-trip box right at | ||
| 38 | +the call into the now-widened shared `intra::predict`/`mc::predict`: | ||
| 39 | +- `encode.rs`: `intra_predict_u8` (new free fn, `crates/ec-av1/src/encode.rs` | ||
| 40 | + near `pad_plane`) wraps `intra::predict`, used at all 4 of encode.rs's | ||
| 41 | + `crate::intra::predict` call sites (`trial`, `intra_scores`, | ||
| 42 | + `search_block`, and a `#[cfg(test)]` micro-bench). | ||
| 43 | +- `encode.rs::mc_trial`: inline conversion around its one `mc::predict` call. | ||
| 44 | +- `motion.rs::search_traced_from_step`: `reference` converted once, outside | ||
| 45 | + the per-MV-candidate closure (not per-call), so the search's inner loop | ||
| 46 | + cost is unchanged. | ||
| 47 | + | ||
| 48 | +A block-sized `u8`->`u16`->`u8` round-trip is exact for 8-bit content (every | ||
| 49 | +value fits both ways with no rounding), so none of this changes encoder | ||
| 50 | +output -- and the RD-trial/motion-search test suite (`encoder::tests::*`, | ||
| 51 | +`motion` module) stayed green with no changes needed. | ||
| 52 | + | ||
| 53 | +## Test-only fixes (not caught by `--lib`) | ||
| 54 | + | ||
| 55 | +`--lib` hit 0 errors after the above; `--tests` still had 17, all fixture | ||
| 56 | +buffers in `mc.rs`'s and `decode.rs`'s own unit tests declared `Vec<u8>`/ | ||
| 57 | +`vec![0u8; ...]` and calling the now-`u16` `predict`/`predict_with_filter`/ | ||
| 58 | +`combine_compound`. Mechanical widen of the fixture types (one hand-written | ||
| 59 | +`u8` window array in `mc.rs`'s | ||
| 60 | +`smooth_filter_matches_aomdec_chroma_inter_block` stays `u8` as the aomdec | ||
| 61 | +dump's own literal shape, copied element-wise into a `u16` reference plane | ||
| 62 | +instead of `copy_from_slice`). No test assertion changed shape, only types. | ||
| 63 | + | ||
| 64 | +## Files touched | ||
| 65 | + | ||
| 66 | +- `crates/ec-av1/src/warp.rs` -- `warp_affine` signature. | ||
| 67 | +- `crates/ec-av1/src/decode.rs` -- `read_inter_plane` signature; OBMC chain; | ||
| 68 | + interintra chain; 12 `pred_y`/`pred_u`/`pred_v` buffer declarations across | ||
| 69 | + 4 near-identical inter-block-decode sites; one unit test's fixture types. | ||
| 70 | +- `crates/ec-av1/src/mc.rs` -- unit test fixture types only (functions were | ||
| 71 | + already widened). | ||
| 72 | +- `crates/ec-av1/src/encode.rs` -- new `intra_predict_u8` helper + 4 call | ||
| 73 | + sites; `mc_trial`'s inline conversion. | ||
| 74 | +- `crates/ec-av1/src/motion.rs` -- `search_traced_from_step`'s inline | ||
| 75 | + conversion. | ||
| 76 | + | ||
| 77 | +## Checks run | ||
| 78 | + | ||
| 79 | +- `cargo check -p ec-av1 --lib -j4` -- 0 errors (was 42 at round start). | ||
| 80 | +- `cargo check -p ec-av1 --tests -j4` -- 0 errors. | ||
| 81 | +- `cargo check -p ec-hw --lib -j4` -- 0 errors (only other in-tree crate | ||
| 82 | + depending on ec-av1; no `PlaneBuf`/`mc`/`intra` internals are exported | ||
| 83 | + across that boundary, confirmed by a clean check with no `ec-av1` diff | ||
| 84 | + visible to it). | ||
| 85 | +- `cargo test -p ec-av1 -j4` (`EC_AV1_REQUIRE_AOMENC=1`): **263 passed, 0 | ||
| 86 | + failed, 18 ignored**, 177.58s. Every real-aomenc gate (obmc, masked | ||
| 87 | + compound, reference-select, restoration, temporal MVs, warp, superres) | ||
| 88 | + still fires and still matches pixel-exact -- 8-bit decode/encode output is | ||
| 89 | + unchanged. | ||
| 90 | + | ||
| 91 | +## Scope respected | ||
| 92 | + | ||
| 93 | +`bit_depth != 8` refusal untouched (not searched for/touched this round); | ||
| 94 | +no 10-bit gate, no second `ffmpeg_decode_sequence` helper -- both explicitly | ||
| 95 | +next round's job per the charter. | ||
| 96 | + | ||
| 97 | +## Budget | ||
| 98 | + | ||
| 99 | +Landed well inside the 75-turn budget (checkpoint-then-converge discipline | ||
| 100 | +wasn't needed this round; the crate reached 0 errors and a green suite in | ||
| 101 | +one pass). Two `wip(hbd):` checkpoints exist on the branch per the round's | ||
| 102 | +policy even though the whole thing closed in one sitting. | ||
lanes/hbd-r3.charter.mdadded+49 -0
| @@ -0,0 +1,49 @@ | |||
| 1 | +# lane-hbd r3 — the payoff: decode a 10-bit stream | ||
| 2 | + | ||
| 3 | +At main (8440024). The widen is MERGED: the decoder's sample type is `u16` | ||
| 4 | +everywhere, clamp bounds come from `bit_depth`, 8-bit output is bit-exact at | ||
| 5 | +264/0, and the encoder keeps `u8` with a local box at its four call sites. | ||
| 6 | + | ||
| 7 | +Everything now stands behind one refusal: `"a stream whose bit depth is not 8 | ||
| 8 | +(this decoder reconstructs into 8-bit planes)"` in `stream.rs`. The sentence is | ||
| 9 | +already false about the planes. Lift it — properly. | ||
| 10 | + | ||
| 11 | +## Order | ||
| 12 | +1. **A 10-bit reference path.** `ffmpeg_decode_sequence` (`stream.rs`) hardcodes | ||
| 13 | + `-pix_fmt yuv420p`, one byte per sample. Add a second helper emitting | ||
| 14 | + `yuv420p10le` and parsing u16 little-endian, and make the comparison | ||
| 15 | + bit-depth aware. Keep the 8-bit helper exactly as it is — every existing gate | ||
| 16 | + depends on it. | ||
| 17 | +2. **A gate on a real 10-bit aomenc stream.** `aomenc` needs | ||
| 18 | + `--bit-depth=10 --profile=0` and a 10-bit input (`ffmpeg ... -pix_fmt | ||
| 19 | + yuv420p10le`); confirm from the sequence header that `bit_depth` really is 10 | ||
| 20 | + before trusting any pixel match. Hard-assert it. | ||
| 21 | +3. **Lift the refusal** and update `refusal_inventory.rs` in the SAME commit — | ||
| 22 | + only once that gate is pixel-exact. | ||
| 23 | +4. **Then the real target: his own files.** Both AV1 films on this box are | ||
| 24 | + `yuv420p10le`: | ||
| 25 | + `~/Downloads/reelb.mkv` and | ||
| 26 | + `~/Videos/Films/reelc.mkv`. Extract a few seconds | ||
| 27 | + (`ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>`, note `-f obu`) and run | ||
| 28 | + `cargo run -p ec-av1 --example decode_probe -- <out.obu>`. Whatever refusal | ||
| 29 | + comes back next IS the next lane's charter — record it verbatim, with the | ||
| 30 | + film and the header state. Do not open his media in a GUI app; ffmpeg and | ||
| 31 | + decode_probe only, and write extracted streams into this worktree's | ||
| 32 | + `fixtures/`, never beside his files. | ||
| 33 | + | ||
| 34 | +Expect 10-bit to expose rounding that 8-bit hid: the inverse transform's | ||
| 35 | +intermediate clamps already take `bit_depth` (`row_clamp = bit_depth + 8`, | ||
| 36 | +`col_clamp = max(bit_depth + 6, 16)`), but every place that still assumes a | ||
| 37 | +255 ceiling or an 8-bit rounding constant will show up as a small pixel delta, | ||
| 38 | +not a crash. Bisect any mismatch against the oracle rather than by inspection. | ||
| 39 | + | ||
| 40 | +## Budget discipline | ||
| 41 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 42 | +what is green and write your report. | ||
| 43 | + | ||
| 44 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | ||
| 45 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | ||
| 46 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 47 | +`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents — | ||
| 48 | +never build in or edit them. Never push, never merge into main; I handle merges. | ||
| 49 | +End with `lanes/hbd-r3.report.md`, VERDICT on line 1. | ||
lanes/hbd-r3.report.mdadded+119 -0
| @@ -0,0 +1,119 @@ | |||
| 1 | +# lane-hbd r3 report | ||
| 2 | + | ||
| 3 | +VERDICT: NO CHANGE MERGEABLE -- scoping round only, tree left clean at 8281618, next lane's charter attached below. | ||
| 4 | + | ||
| 5 | +## What happened | ||
| 6 | + | ||
| 7 | +This round budgeted 75 turns for "the payoff": a 10-bit reference path, a | ||
| 8 | +real 10-bit aomenc gate, lifting the `bit_depth != 8` refusal, then probing | ||
| 9 | +the user's own films. Most of the budget went to establishing that the | ||
| 10 | +refusal cannot be honestly lifted without widening `encode::Picture` itself | ||
| 11 | +-- a materially bigger job than the charter's framing suggested -- and a | ||
| 12 | +first attempt at that widen, which does not fit in what was left. No commit | ||
| 13 | +was made; `git diff` is empty, worktree is at 8281618 exactly. | ||
| 14 | + | ||
| 15 | +## The real blocker (not visible from the charter alone) | ||
| 16 | + | ||
| 17 | +r2 widened every *intermediate* sample buffer (`PlaneBuf`, `mc.rs`, | ||
| 18 | +`warp.rs`, the OBMC/interintra chains) to `u16`, but the FINAL narrowing -- | ||
| 19 | +where a decoded frame becomes an `encode::Picture` -- was untouched, and | ||
| 20 | +`Picture.y/u/v` are still `Vec<u8>`. Two places do `s as u8` on the way out | ||
| 21 | +(`decode.rs:6823-6825` for key frames, `decode.rs:12594-12596` for inter | ||
| 22 | +frames). Widening only the ffmpeg comparison helper (charter step 1) proves | ||
| 23 | +nothing on its own: even with a correct 10-bit-precision decode internally, | ||
| 24 | +the value that reaches the caller is still an 8-bit truncation, which is | ||
| 25 | +exactly the "silent wrongness" the refusal's own doc names. So "lift the | ||
| 26 | +refusal properly" (step 3) requires `Picture` to actually carry 10-bit | ||
| 27 | +values, not just the reference path to be able to read them. | ||
| 28 | + | ||
| 29 | +`encode::Picture` is shared between the encoder (its own reconstruction | ||
| 30 | +output, `u8`-only by design per r2's explicit decision) and the decoder | ||
| 31 | +(`decode_stream`'s return type, and the DPB's own `ref_slots` storage used | ||
| 32 | +for inter-frame motion compensation -- `reference: &Picture` is read for MC, | ||
| 33 | +not just written at the end, so reference-frame precision matters for | ||
| 34 | +correctness on frame 2+, not only for the final comparison). Widening | ||
| 35 | +`Picture.y/u/v` to `Vec<u16>` is the natural single-source-of-truth fix and | ||
| 36 | +turned out to have a SMALLER encoder blast radius than first feared -- | ||
| 37 | +production encoder code only touches `Picture` at ~10 sites (`Plane` | ||
| 38 | +construction, `pad_plane`/`crop_plane`, `padded_to`, `crop_encoded`), all | ||
| 39 | +either genericizable over the element type or a trivial local `as u8` | ||
| 40 | +narrow (the encoder never needs anything but `0..=255`). The real size was | ||
| 41 | +in test-fixture churn: `cargo check --lib` alone showed 61 errors, dominated | ||
| 42 | +by ~50 encoder test-module literal-assignment sites (`picture.y[i] = ... as | ||
| 43 | +u8`) that all need `as u16`, plus the two decode.rs narrowing sites, plus | ||
| 44 | +whatever `--tests` adds on top (not reached this round). `film_grain.rs` and | ||
| 45 | +`superres.rs` are ADDITIONALLY hardcoded to 8-bit math (grain's scaling LUT | ||
| 46 | +is `[i32; 256]`, its doc says "specialized to this crate's only picture | ||
| 47 | +shape: 8-bit"; superres's `upscale_row` is `&[u8]` with a literal | ||
| 48 | +`.clamp(0, 255) as u8`) -- neither is spec-generalizable to 10-bit inside | ||
| 49 | +this round's remaining budget, so the honest plan was to lift the BLANKET | ||
| 50 | +`bit_depth != 8` refusal but add two NARROWER ones ("film grain on a stream | ||
| 51 | +whose bit depth isn't 8", "use_superres on a stream whose bit depth isn't | ||
| 52 | +8") guarding those two subsystems specifically, since the core | ||
| 53 | +transform/prediction/MC/deblock/CDEF/LR pipeline is otherwise already | ||
| 54 | +bit-depth-generic via `decode::BIT_DEPTH` (which is itself dead code right | ||
| 55 | +now -- `set_bit_depth` is defined but never called from `stream.rs`; wiring | ||
| 56 | +that is also part of the real fix). | ||
| 57 | + | ||
| 58 | +A first attempt at the `Picture` widen was made (`Picture.y/u/v: Vec<u16>`, | ||
| 59 | +`pad_plane`/`crop_plane` genericized over `T: Copy [+ Default]`, the two | ||
| 60 | +decode.rs narrowing sites changed to move `PlaneBuf::data` directly instead | ||
| 61 | +of `.map(|s| s as u8)`) and got `cargo check -p ec-av1 --lib` down from 61 | ||
| 62 | +to a smaller but still nonzero error count before the turn budget forced a | ||
| 63 | +stop; the attempt was reverted (`git checkout --`) rather than left | ||
| 64 | +half-compiling, so the tree stays green at 8281618. The diff is saved for | ||
| 65 | +reference at | ||
| 66 | +`/home/user/Documents/Code/Rust/edith_codecs-hbd/../..` -- actually at | ||
| 67 | +the session scratchpad: `hbd-r3-picture-widen-attempt.diff` (128 lines, | ||
| 68 | +2 files: `decode.rs`, `encode.rs`). It is NOT applied to the worktree. | ||
| 69 | + | ||
| 70 | +## What was NOT reached | ||
| 71 | + | ||
| 72 | +Steps 1 (ffmpeg 10-bit helper), 2 (real 10-bit aomenc gate), 3 (lift + | ||
| 73 | +inventory update), 4 (probe his films) -- none started. No fixture files | ||
| 74 | +were extracted, nothing was written to `fixtures/`. | ||
| 75 | + | ||
| 76 | +## Next lane's charter (hbd-r4) | ||
| 77 | + | ||
| 78 | +1. Apply (or redo, it's small and now-scoped) the `Picture.y/u/v -> | ||
| 79 | + Vec<u16>` widen: `encode.rs` struct + `pad_plane`/`crop_plane` | ||
| 80 | + genericized (both already attempted, low-risk) + ~10 production | ||
| 81 | + `Plane`-construction/padding call sites (local `as u8`/`as u16` box, | ||
| 82 | + same pattern as r2's `intra_predict_u8`) + the ~50 encoder test-fixture | ||
| 83 | + literal touch-ups (mechanical, `cargo check --lib` then `--tests` | ||
| 84 | + enumerates every one) + `decode.rs`'s two narrowing sites (drop the `as | ||
| 85 | + u8` map, move `PlaneBuf::data` directly). | ||
| 86 | +2. Wire `decode::set_bit_depth(seq.color_config.bit_depth)` in `stream.rs` | ||
| 87 | + before the per-frame decode calls -- currently dead code, defaults to 8 | ||
| 88 | + always. | ||
| 89 | +3. Add two narrow refusals (`film_grain.rs`'s `apply_grain` and | ||
| 90 | + `header.use_superres`, both gated on `bit_depth != 8`) rather than | ||
| 91 | + generalizing their 8-bit-hardcoded math this round -- name them | ||
| 92 | + explicitly in `refusal_inventory.rs`. | ||
| 93 | +4. Lift the blanket `bit_depth != 8` refusal in `stream.rs` once (1)-(3) | ||
| 94 | + compile and the existing 264-test 8-bit suite is still green (it should | ||
| 95 | + be structurally: `Vec<u16>` holding `0..=255` compares byte-for-byte | ||
| 96 | + equal in value to the old `Vec<u8>`, only the comparison TYPE changes). | ||
| 97 | +5. THEN do the charter's original steps 1/2/3/4: 10-bit ffmpeg reference | ||
| 98 | + helper (u16 LE parse), real `--bit-depth=10 --profile=0` aomenc gate | ||
| 99 | + hard-asserting `bit_depth == 10` from the sequence header before | ||
| 100 | + trusting any pixel match, and only then probe the user's two real films | ||
| 101 | + (`~/Downloads/reelb.mkv`, | ||
| 102 | + `~/Videos/Films/reelc.mkv`) via `ffmpeg -t 3 -c:v copy -f | ||
| 103 | + obu` into this worktree's `fixtures/` + `decode_probe`. Given both films | ||
| 104 | + are HDR10 (film grain is common in HDR masters), expect the probe to hit | ||
| 105 | + the new film-grain-at-10-bit refusal quickly -- record it verbatim with | ||
| 106 | + header state as instructed, that becomes hbd-r5. | ||
| 107 | + | ||
| 108 | +## Budget | ||
| 109 | + | ||
| 110 | +Spent essentially the whole 75-turn budget on: reading the charter/r2 | ||
| 111 | +report, tracing the full narrowing chain (`Picture` shared by encoder+DPB, | ||
| 112 | +not just a comparison-helper concern), sizing the blast radius across | ||
| 113 | +encode.rs/decode.rs/film_grain.rs/superres.rs, and one partial widen | ||
| 114 | +attempt that was reverted rather than left broken. This was a scoping | ||
| 115 | +failure on my part, not a budget-external blocker: the charter's own | ||
| 116 | +"expect 10-bit to expose rounding" framing undersold that the OUTPUT type | ||
| 117 | +itself, not just intermediate clamps, needed widening -- that should have | ||
| 118 | +been the very first thing checked (grep `Picture.*Vec<u8>`) before reading | ||
| 119 | +deeply into the rest of the pipeline. | ||
lanes/hbd-r4.charter.mdadded+67 -0
| @@ -0,0 +1,67 @@ | |||
| 1 | +# lane-hbd r4 — widen Picture, then lift the refusal | ||
| 2 | + | ||
| 3 | +At 7bb2a18. Read `lanes/hbd-r3.report.md` first. r3 landed no code but did the | ||
| 4 | +scoping that makes this round tractable, and it found the real blocker: | ||
| 5 | +`encode::Picture.y/u/v` (`encode.rs:92`) are still `Vec<u8>`, and that type is | ||
| 6 | +shared by the encoder AND by `decode_stream`'s return value and the DPB | ||
| 7 | +reference slots — which are read back for motion compensation on frame 2+, not | ||
| 8 | +just handed to the caller. So the refusal cannot lift honestly until `Picture` | ||
| 9 | +widens. | ||
| 10 | + | ||
| 11 | +## Checkpoint policy — this applies to the whole round | ||
| 12 | +r3 got `cargo check` from 61 errors down, ran out of budget, and **reverted**; | ||
| 13 | +so did r10 of the predecessor lane. That is twice the same loss. Do NOT revert a | ||
| 14 | +falling error count. Commit a `wip(hbd):` checkpoint every time the count drops | ||
| 15 | +meaningfully, with the number in the message. A non-compiling commit is fine on | ||
| 16 | +this branch under that prefix; it is never merged in that state. The count | ||
| 17 | +reaching zero is when you run the suite and make a real commit. | ||
| 18 | + | ||
| 19 | +Its attempt diff is saved at | ||
| 20 | +`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/hbd-r3-picture-widen-attempt.diff` | ||
| 21 | +(128 lines, `pad_plane`/`crop_plane` genericized over `T: Copy + Default`, the | ||
| 22 | +two `as u8` narrowing sites at `decode.rs` ~6823 and ~12594 dropped). `git apply` | ||
| 23 | +it first rather than retyping. | ||
| 24 | + | ||
| 25 | +r3's measurement of what remains: the PRODUCTION blast radius is small (~10 | ||
| 26 | +sites in `encode.rs`, all genericizable or trivial local narrow boxes); the bulk | ||
| 27 | +of the errors are ~50 mechanical `as u8` → `as u16` touch-ups in encoder TEST | ||
| 28 | +FIXTURES. Do the production sites first and checkpoint, then sweep the fixtures. | ||
| 29 | + | ||
| 30 | +## Then, in order | ||
| 31 | +1. **Wire `decode::set_bit_depth`.** It exists at `decode.rs:97` and is never | ||
| 32 | + called — `stream.rs` never passes `seq.color_config.bit_depth` into it, so the | ||
| 33 | + `BIT_DEPTH` thread-local is dead code defaulting to 8. Everything downstream | ||
| 34 | + silently assumes 8-bit until this is wired. Wire it, and make sure it is set | ||
| 35 | + per frame before decode, not once per process. | ||
| 36 | +2. **Narrow refusals for the two paths that are still 8-bit by construction**: | ||
| 37 | + `film_grain.rs` (grain LUT is `[i32; 256]`) and `superres.rs` | ||
| 38 | + (`upscale_row` takes `&[u8]` and clamps to 255). Each gets its own named | ||
| 39 | + `bit_depth != 8` refusal — these are honest, scoped refusals, not the blanket | ||
| 40 | + one. Declare both in `refusal_inventory.rs`. | ||
| 41 | +3. **Lift the blanket refusal** in `stream.rs`, in the same commit as the gate | ||
| 42 | + that proves 10-bit decodes. | ||
| 43 | +4. **The 10-bit gate**: `ffmpeg_decode_sequence` hardcodes `-pix_fmt yuv420p`; | ||
| 44 | + add a second helper emitting `yuv420p10le` with u16 LE parsing, leaving the | ||
| 45 | + 8-bit helper untouched. aomenc needs `--bit-depth=10` and a 10-bit input. | ||
| 46 | + Confirm from the sequence header that `bit_depth` really is 10 before | ||
| 47 | + trusting a pixel match, and hard-assert it. | ||
| 48 | +5. **His own films.** Both are `yuv420p10le`: ReelB (3840x1608, HDR10, | ||
| 49 | + Main, no film grain flagged) and ReelC (1920x792, bt709, Main, no film grain). | ||
| 50 | + Extract with `ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>` into this | ||
| 51 | + worktree's `fixtures/`, probe with | ||
| 52 | + `cargo run -p ec-av1 --example decode_probe`, and record the next refusal | ||
| 53 | + verbatim — that is the next lane's charter. Never open his media in a GUI app. | ||
| 54 | + | ||
| 55 | +8-bit output must stay bit-exact throughout: 264 tests, every real-aomenc gate | ||
| 56 | +among them. | ||
| 57 | + | ||
| 58 | +## Budget discipline | ||
| 59 | +75 turns, no reset on resume. At about turn 55, stop starting new work, commit | ||
| 60 | +your checkpoint, and write the report with the current error count in it. | ||
| 61 | + | ||
| 62 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground | ||
| 63 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | ||
| 64 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 65 | +`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents — | ||
| 66 | +never build in or edit them. Never push, never merge into main; I handle merges. | ||
| 67 | +End with `lanes/hbd-r4.report.md`, VERDICT on line 1. | ||
lanes/palette2-r1.charter.mdadded+60 -0
| @@ -0,0 +1,60 @@ | |||
| 1 | +# lane-palette2 r1 — the palette frontier | ||
| 2 | + | ||
| 3 | +Fresh lane off main (170a5a3). Palette-Y already decodes pixel-exact; the lane | ||
| 4 | +that landed it is merged and retired. Read its work in `git log` for | ||
| 5 | +`decode_color_index_map` and `read_intra_mode`'s palette branch before editing. | ||
| 6 | + | ||
| 7 | +## Why this lane exists — measured, not guessed | ||
| 8 | +I probed five content classes through plain default-settings aomenc | ||
| 9 | +(`--cpu-used=4 --end-usage=q --cq-level=32`, no `--enable-*` flags) with | ||
| 10 | +`cargo run -p ec-av1 --example decode_probe`. Three of the five stop on a | ||
| 11 | +palette refusal: | ||
| 12 | +- `testsrc2` -> "a block that actually uses a palette (UV) -- reconstruction | ||
| 13 | + is out of scope" | ||
| 14 | +- `smptebars` and `rgbtestsrc` -> "a HORZ/VERT intra strip in a screen-content | ||
| 15 | + frame (palette syntax is consumed for square blocks only)" | ||
| 16 | +- `life` -> "a palette block with a split luma transform (round 1)" | ||
| 17 | + | ||
| 18 | +Palette is the single biggest thing between this decoder and an ordinary AV1 | ||
| 19 | +stream. Close those three, in that order — each is a gate-then-lift. | ||
| 20 | + | ||
| 21 | +## Order | ||
| 22 | +1. **UV palette reconstruction.** The reads already exist and are correct (the | ||
| 23 | + previous lane ported `palette_uv_mode`/`palette_uv_size`; it deliberately | ||
| 24 | + skipped `read_palette_colors_uv` because the refusal aborts immediately, so | ||
| 25 | + that reader still needs writing). Then reconstruct both chroma planes from | ||
| 26 | + the palette and its index map. | ||
| 27 | +2. **Palette on a rectangular (HORZ/VERT) intra strip.** `palette_bsize_ctx` | ||
| 28 | + and the size/context derivation assume a square block today. | ||
| 29 | +3. **Palette block with a split luma transform.** | ||
| 30 | + | ||
| 31 | +Each step: gate FIRST against a real aomenc stream, driving the tile decode | ||
| 32 | +below `decode_stream` so the refusal cannot short-circuit the code you are | ||
| 33 | +measuring ([[refusal-short-circuits-its-own-code]]); then the implementation; | ||
| 34 | +then lift the refusal and update `refusal_inventory.rs` **in the same commit**. | ||
| 35 | +A branch that lifts a refusal without a gate does not merge to main. The gate | ||
| 36 | +must hard-assert that the feature actually fired — a pixel match on a stream | ||
| 37 | +that never used a palette proves nothing ([[gate-blind-to-feature]]). | ||
| 38 | + | ||
| 39 | +Content that reaches each case is known: `testsrc2` for UV, `smptebars` or | ||
| 40 | +`rgbtestsrc` for the rect strips, `life` for the split transform, all at the | ||
| 41 | +default settings above and `--sb-size=64` (this decoder hardcodes 64px | ||
| 42 | +superblocks). `gate_coverage.rs` requires an explicit `--enable-palette=1` for a | ||
| 43 | +gate to count as exercising palette. | ||
| 44 | + | ||
| 45 | +## Budget discipline | ||
| 46 | +75 turns, and they do NOT reset if you are resumed. At about turn 55, stop | ||
| 47 | +starting new work: commit what is green and write your report. Five rounds in a | ||
| 48 | +recent batch died mid-edit with nothing reported, each costing a whole round to | ||
| 49 | +recover. | ||
| 50 | + | ||
| 51 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2`; foreground | ||
| 52 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; fixtures | ||
| 53 | +through `gradients_source(seed, w, h, tail)` where a synthetic source will do; | ||
| 54 | +every ffmpeg generate bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 55 | +`--threads=1 --row-mt=0 --sb-size=64`. Oracle rungs 6, 7, 8, 8b are taken — take | ||
| 56 | +9; `~/.cache/aom-oracle` is SHARED with sibling lanes, so env-gated rungs in | ||
| 57 | +`scripts/instrument-aom-oracle.sh` only, never a throwaway patch left in the | ||
| 58 | +tree. Sibling worktrees have live agents — never build in or edit them. Never | ||
| 59 | +push, never merge into main. End with `lanes/palette2-r1.report.md`, VERDICT on | ||
| 60 | +line 1. | ||
lanes/palette2-r2.charter.mdadded+35 -0
| @@ -0,0 +1,35 @@ | |||
| 1 | +# lane-palette2 r2 — finish UV palette reconstruction | ||
| 2 | + | ||
| 3 | +At 96fde87. **I merged main for you.** r1 hit its cap mid-edit, having just | ||
| 4 | +said "now add `record_palette_uv` at the tail, near `record_palette_y`"; its | ||
| 5 | +tree is committed verbatim at d2ea8e7 and **is unverified — it may not compile.** | ||
| 6 | +Check that first, then continue. | ||
| 7 | + | ||
| 8 | +Your charter is still `lanes/palette2-r1.charter.md`; read it. Step 1 is UV | ||
| 9 | +palette reconstruction: the previous palette lane ported `palette_uv_mode` and | ||
| 10 | +`palette_uv_size` but deliberately skipped `read_palette_colors_uv`, because the | ||
| 11 | +refusal aborted the decode immediately and no later bit needed to stay in sync. | ||
| 12 | +That reader now has to exist, and both chroma planes have to be reconstructed | ||
| 13 | +from the palette and its index map. | ||
| 14 | + | ||
| 15 | +Gate first, below `decode_stream`, hard-asserting the UV palette path actually | ||
| 16 | +fired — a pixel match on a stream that never used a UV palette proves nothing | ||
| 17 | +([[gate-blind-to-feature]]). `testsrc2` at plain default aomenc settings reaches | ||
| 18 | +this case; that is how I found it. Then lift the refusal and update | ||
| 19 | +`refusal_inventory.rs` in the SAME commit. | ||
| 20 | + | ||
| 21 | +Steps 2 and 3 (palette on a HORZ/VERT rect strip, palette with a split luma | ||
| 22 | +transform) stay in the charter for a later round — do not start them until UV is | ||
| 23 | +green and committed. | ||
| 24 | + | ||
| 25 | +## Budget discipline | ||
| 26 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 27 | +what is green and write your report. The merge is already done for you. | ||
| 28 | + | ||
| 29 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2`; foreground | ||
| 30 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg | ||
| 31 | +generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc | ||
| 32 | +`--threads=1 --row-mt=0 --sb-size=64`. Oracle rung 12 is yours; `~/.cache/aom-oracle` | ||
| 33 | +is SHARED, env-gated rungs only. Sibling worktrees have live agents — never build | ||
| 34 | +in or edit them. Never push, never merge into main. End with | ||
| 35 | +`lanes/palette2-r2.report.md`, VERDICT on line 1. | ||
lanes/palette2-r2.report.mdadded+73 -0
| @@ -0,0 +1,73 @@ | |||
| 1 | +VERDICT: DONE -- UV palette reconstruction green and committed (0b79412) | ||
| 2 | + | ||
| 3 | +## What happened | ||
| 4 | + | ||
| 5 | +r1's uncommitted WIP (committed verbatim at d2ea8e7, "unverified") was much | ||
| 6 | +further along than the charter's own description suggested: `read_palette_colors_uv`, | ||
| 7 | +`PaletteUv` reconstruction into both chroma planes (`palette_uv_bufs` -> | ||
| 8 | +`PALETTE_PRED` for `u.reconstruct`/`v.reconstruct`, mirroring the palette-Y | ||
| 9 | +path), and `record_palette_uv` neighbour tracking were all already written | ||
| 10 | +and, on inspection, correct. The tree did not compile for one reason: the | ||
| 11 | +8x8-leaf call site of `read_intra_mode` (crates/ec-av1/src/decode.rs:4394) | ||
| 12 | +was still destructuring the pre-UV 8-tuple and passing the pre-UV 13-arg | ||
| 13 | +call, one edit behind the widened `read_intra_mode` signature (9-tuple | ||
| 14 | +return, 14-arg call with the new `palette_uv_cache: &[u16]` parameter) that | ||
| 15 | +the rest of the file had already moved to. | ||
| 16 | + | ||
| 17 | +Fixed by adding `_palette_uv` to the destructured tuple and `&[]` for | ||
| 18 | +`palette_uv_cache` at that one call site -- the same "read+refuse the | ||
| 19 | +symbol, never reconstruct" corner-cut that site already used for palette_y | ||
| 20 | +(`None` for the `palette` param), extended to UV. That site is the excluded | ||
| 21 | +8x8-leaf path (`prev_leaf`/rect handling), not the intra square-block path | ||
| 22 | +this round's gate exercises, so no new refusal or behaviour needed there. | ||
| 23 | + | ||
| 24 | +## Gate | ||
| 25 | + | ||
| 26 | +`a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact` | ||
| 27 | +(crates/ec-av1/src/stream.rs, new): `testsrc2` (the multicoloured AV1 test | ||
| 28 | +pattern -- flat, few-colour, repetitive chroma per region, unlike | ||
| 29 | +`smptebars=hue=s=0` in the sibling palette-Y gate, which deliberately | ||
| 30 | +flattened chroma to sidestep this exact case) through the same square-only | ||
| 31 | +recipe as the palette-Y gate (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, | ||
| 32 | +fixed 32x32 partition, `--enable-palette=1`, `--sb-size=64 --threads=1 | ||
| 33 | +--row-mt=0`). Hard-asserts `decode::palette_uv_hits()` moved before | ||
| 34 | +comparing pixel output, per [[gate-blind-to-feature]] -- a pixel match on a | ||
| 35 | +stream that never used a UV palette would prove nothing. Live run: 2 UV | ||
| 36 | +palette blocks fire, both frames' Y/U/V match ffmpeg's independent decode | ||
| 37 | +of the same bytes exactly. | ||
| 38 | + | ||
| 39 | +## refusal_inventory.rs | ||
| 40 | + | ||
| 41 | +No edit needed. "a block that actually uses a palette (UV) -- reconstruction | ||
| 42 | +is out of scope" is still genuinely present in decode.rs at two other call | ||
| 43 | +sites -- the HORZ/VERT rect-strip path (decode.rs ~9263) and the inter-frame | ||
| 44 | +8x8-leaf path (decode.rs ~10359) -- both out of this round's scope (charter | ||
| 45 | +steps 2/3, plus inter-frame palette which the charter never named). Those | ||
| 46 | +stay refused; the inventory's scan is string-presence-based, so it already | ||
| 47 | +passes with no change. Confirmed: `refusal_inventory::tests::the_decode_path_refuses_exactly_the_listed_cases` | ||
| 48 | +and `capability_claims_are_declared_not_scattered` both green. | ||
| 49 | + | ||
| 50 | +## Checks run | ||
| 51 | + | ||
| 52 | +- `cargo check -p ec-av1` -- clean (was 2 errors before the fix). | ||
| 53 | +- `cargo test -p ec-av1 --lib` (EC_AV1_REQUIRE_AOMENC=1) -- 263 passed, 18 | ||
| 54 | + ignored, 0 failed, in 133.5s. Includes the new UV palette gate, the | ||
| 55 | + existing palette-Y gate, refusal_inventory, and gate_coverage, all green. | ||
| 56 | +- Command: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2 | ||
| 57 | + EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4` | ||
| 58 | + | ||
| 59 | +## Scope discipline | ||
| 60 | + | ||
| 61 | +Did not touch steps 2 (HORZ/VERT rect-strip palette) or 3 (split-transform | ||
| 62 | +palette) -- both stay refused, per charter instruction to wait until UV is | ||
| 63 | +green and committed first. Turn budget: finished well under the ~55-turn | ||
| 64 | +soft cap (compile fix + one gate + verification), so no further step was | ||
| 65 | +started this round per charter ("do not start them until UV is green and | ||
| 66 | +committed" -- deferring to the next round rather than scope-creeping into | ||
| 67 | +step 2 with remaining budget). | ||
| 68 | + | ||
| 69 | +## Oracle / sibling worktrees | ||
| 70 | + | ||
| 71 | +Used the shared `~/.cache/aom-oracle/build/aomenc` read-only (rung 12 was | ||
| 72 | +not needed -- no change to `scripts/instrument-aom-oracle.sh`). No edits | ||
| 73 | +outside this worktree. Nothing pushed, nothing merged into main. | ||
lanes/realworld-r10.report.mdadded+127 -0
| @@ -0,0 +1,127 @@ | |||
| 1 | +VERDICT: No commit this round. The `u16` widen of `PlaneBuf::data` was attempted, | ||
| 2 | +got substantially further than r9 (67 -> ~35 remaining `cargo check` errors, | ||
| 3 | +`decode.rs`'s own internal sites plus all of `intra.rs` fully widened and | ||
| 4 | +type-correct on their own), but did not reach a compiling state inside the | ||
| 5 | +turn budget. Per the charter's own rule ("a non-compiling [crate] is not [a | ||
| 6 | +fine place to stop]"), the attempt was reversed with `git apply -R` against a | ||
| 7 | +saved diff rather than committed half-wired. Working tree is clean, at | ||
| 8 | +b8ad140 + the r10 charter commit c7b3fa0, `cargo check -p ec-av1 --lib` | ||
| 9 | +clean, matching the round-start state (262/0 suite, unexercised this round | ||
| 10 | +since nothing changed). | ||
| 11 | + | ||
| 12 | +## What was reached this round (and reverted) | ||
| 13 | + | ||
| 14 | +`PlaneBuf::data: Vec<u8>` -> `Vec<u16>` (`decode.rs:3428`), `sample_max()` | ||
| 15 | +made `pub(crate)` for cross-module reuse, then the checker-driven sweep: | ||
| 16 | + | ||
| 17 | +- `PlaneBuf::edges`/`edges_rect` return types -> `(Option<Vec<u16>>, | ||
| 18 | + Option<Vec<u16>>, Option<u16>)`. | ||
| 19 | +- `PlaneBuf::reconstruct`/`reconstruct_rect`: prediction buffer `vec![0u16; | ||
| 20 | + ..]`, both clamp-and-write sites -> `.clamp(0, sample_max()) as u16`. | ||
| 21 | +- `PALETTE_PRED` thread-local widened to `Vec<u16>` (its `colors` source was | ||
| 22 | + already `u16`, this dropped a stale `as u8` truncation). | ||
| 23 | +- CDEF's single write-back site (`decode.rs:4687`) -> `sample_max()`/`u16`. | ||
| 24 | +- The whole deblock `filter_edge` function (`decode.rs:5121`, | ||
| 25 | + 4/6/8/14-tap taps, ~14 write sites) -> `data: &mut [u16]`, every | ||
| 26 | + `.clamp(0, 255) as u8` -> `.clamp(0, sample_max()) as u16`. | ||
| 27 | +- Every `PlaneBuf { data: vec![0u8; ...], ... }` zero-init (key frame, inter | ||
| 28 | + frame, and one more decode entry point — 3 sites) -> `vec![0u16; ...]`. | ||
| 29 | +- Reference-frame ingestion (`Picture.y/u/v` -> `PlaneBuf.data`, 6 struct | ||
| 30 | + literals: `reference.{y,u,v}` and the per-slot `g.{y,u,v}` loop) -> | ||
| 31 | + `.iter().map(|&s| s as u16).collect()` (widening in from `Picture`, which | ||
| 32 | + stays `u8` this stage). | ||
| 33 | +- The two `PlaneBuf -> Picture` narrowing points (both `y/u/v: y.data, ...` | ||
| 34 | + struct literals) -> `.into_iter().map(|s| s as u8).collect()` (narrowing | ||
| 35 | + out to `Picture`, which stays `u8` this stage — this is the exact site r8's | ||
| 36 | + report named as still open, now closed). | ||
| 37 | +- `intra.rs` fully widened end to end: `Edges::build`, `predict`, | ||
| 38 | + `directional`, `dc`, `predict_filter_intra` all take/return `&[u16]`/ | ||
| 39 | + `Option<u16>`/`&mut [u16]` now, every `.clamp(0, 255) as u8` (5 sites, | ||
| 40 | + including 2 internal accumulator clamps that were previously untouched) | ||
| 41 | + -> `.clamp(0, crate::decode::sample_max()) as u16`. Its own `#[cfg(test)]` | ||
| 42 | + module (`fill`/`checksum`/the two `predict()` call sites) updated in step; | ||
| 43 | + this file alone type-checked clean in isolation before the wider sweep | ||
| 44 | + continued. | ||
| 45 | + | ||
| 46 | +That diff (500 lines) is saved at | ||
| 47 | +`/tmp/claude-1000/.../scratchpad/r10-attempt.diff` for the next round to | ||
| 48 | +replay rather than redo by hand — it is NOT applied to the tree right now. | ||
| 49 | + | ||
| 50 | +## Exact remaining error clusters (the live checklist, ~35 sites when this | ||
| 51 | +round stopped, `cargo check -p ec-av1 --lib` against the PlaneBuf-widened | ||
| 52 | +tree) | ||
| 53 | + | ||
| 54 | +- `crates/ec-av1/src/restoration.rs`'s `apply_loop_restoration_plane` still | ||
| 55 | + takes/returns `Vec<u8>` (`decode.rs:5445/5457/5469`, the 3 call sites that | ||
| 56 | + assign its result into `y.data`/`u.data`/`v.data`) — untouched this round, | ||
| 57 | + not inspected past its signature. | ||
| 58 | +- The two remaining debug-dump `write_all(&y.data)` blocks | ||
| 59 | + (`decode.rs:6165-6167` and `12109-12111`, `EC_AV1_PREFILT_DUMP`) and the | ||
| 60 | + `crop_wide`/`crop` closures (`6174`-ish and `6209`/`12151`-ish, both build | ||
| 61 | + a cropped `Vec<u8>` from `plane.data`) still assume `u8` — these are | ||
| 62 | + debug/superres-crop paths, need the same `.iter().map(|&s| s as u8)` | ||
| 63 | + narrowing pattern already used at the two `Picture` literals. | ||
| 64 | +- `decode.rs:6520` — `reconstruct_mc`'s own `prediction: &[u8]` param + its | ||
| 65 | + `.clamp(0, 255) as u8` write, the same pattern as `reconstruct`/ | ||
| 66 | + `reconstruct_rect` above it, not yet touched. | ||
| 67 | +- `decode.rs:6996`/`7071` and `8242` through `10202` (~24 call sites, | ||
| 68 | + `mc::predict`/`predict_with_filter(s)`/`predict_compound_intermediate`/ | ||
| 69 | + `combine_compound`/`blend_masked_compound`, plus `interintra_blend`'s own | ||
| 70 | + `pred: &mut [u8]` and its internal `vec![0u8; side*side]` intra buffer at | ||
| 71 | + `~7040`) — `mc.rs` itself (907 lines, `predict`/`predict_with_filter(s)`/ | ||
| 72 | + `predict_compound_intermediate`/`combine_compound`/ | ||
| 73 | + `blend_masked_compound`, all six still `&[u8]`/`&mut [u8]`) is the one | ||
| 74 | + big remaining piece; the charter's own note that a prior round widened | ||
| 75 | + `mc.rs` alone in ~10 tool calls (using the same `sample_max()` pattern | ||
| 76 | + just proven out in `intra.rs` this round) makes it the right next step — | ||
| 77 | + do it FIRST next round since PlaneBuf is already committed by then and | ||
| 78 | + `cargo check` will point at exactly these call sites. | ||
| 79 | +- `crates/ec-av1/src/encode.rs:600/820/872` — three call sites into | ||
| 80 | + `intra::predict`/`predict_filter_intra` from the ENCODER side, not | ||
| 81 | + inventoried by r8 or the charter at all (a new site class this round's | ||
| 82 | + attempt surfaced: the encoder shares `intra.rs` with the decoder, so | ||
| 83 | + widening `intra.rs` fans out into `encode.rs` too, still on `u8` sample | ||
| 84 | + buffers there — untouched, not even read this round; next round needs to | ||
| 85 | + either widen `encode.rs`'s own picture buffers in step or box the u8<->u16 | ||
| 86 | + conversion at those three call sites specifically since the encoder isn't | ||
| 87 | + in this charter's scope). | ||
| 88 | +- `warp.rs`, `superres.rs` — never reached (errors upstream of them all still | ||
| 89 | + open); charter's own inventory (1 clamp-and-cast site each) is presumably | ||
| 90 | + still accurate but unverified this round. | ||
| 91 | + | ||
| 92 | +## Why this round stopped short | ||
| 93 | + | ||
| 94 | +Turn-budget math: intra.rs's full widen (13 signature/body edits across a | ||
| 95 | +970-line file) and decode.rs's own ~20-site internal sweep both landed | ||
| 96 | +clean and are real, reusable progress — verified by literally getting the | ||
| 97 | +error count from 67 to ~35 with `cargo check` as the checklist, exactly as | ||
| 98 | +charter directed. What remained (`restoration.rs`, `mc.rs`, the newly | ||
| 99 | +discovered `encode.rs` fan-out, two debug-dump closures) was correctly | ||
| 100 | +estimated as too large to land AND leave green before the ~turn-55 stop | ||
| 101 | +point, so the attempt was reversed rather than committed non-compiling. | ||
| 102 | + | ||
| 103 | +## Recommendation for r11 | ||
| 104 | + | ||
| 105 | +1. Re-apply `/tmp/claude-1000/.../scratchpad/r10-attempt.diff` (git apply, | ||
| 106 | + not by hand) as the starting point — it is the PlaneBuf widen + | ||
| 107 | + `intra.rs` widen, both proven type-correct in isolation. | ||
| 108 | +2. Fix `restoration.rs`'s `apply_loop_restoration_plane` (small, self | ||
| 109 | + contained — likely one function). | ||
| 110 | +3. Fix the two debug-dump narrowing closures + `reconstruct_mc`'s clamp | ||
| 111 | + (small, same pattern as everything already done). | ||
| 112 | +4. Widen `mc.rs` LAST as the charter said, following the exact pattern this | ||
| 113 | + round proved out in `intra.rs` (`sample_max()`, no other new machinery | ||
| 114 | + needed) — expect ~24 decode.rs call sites to resolve for free once its | ||
| 115 | + six functions take `&[u16]`/`&mut [u16]`. | ||
| 116 | +5. New this round: budget a pass over `encode.rs`'s 3 call sites into | ||
| 117 | + `intra.rs` — decide whether the encoder's own picture buffers widen too | ||
| 118 | + (likely no, out of this charter's scope) or whether those 3 sites get a | ||
| 119 | + local u8<->u16 box. | ||
| 120 | +6. Run the 262-test suite before committing (per charter); it was NOT run | ||
| 121 | + this round since nothing new landed to test. | ||
| 122 | + | ||
| 123 | +## Merge note | ||
| 124 | + | ||
| 125 | +`git status` clean; nothing to merge. No refusal strings touched. `intra.rs` | ||
| 126 | +and `decode.rs` are byte-identical to c7b3fa0 (`git apply -R` verified with | ||
| 127 | +a clean `cargo check -p ec-av1 --lib`, matching the round-start baseline). | ||
lanes/realworld-r8.report.mdadded+98 -0
| @@ -0,0 +1,98 @@ | |||
| 1 | +VERDICT: Stage 1 partially landed and committed at bd91ad0 (probe + BIT_DEPTH | ||
| 2 | +thread-local + dequant call-site threading). The `u16` widening of | ||
| 3 | +`PlaneBuf`/prediction buffers (item 2 of the charter) was attempted this round, | ||
| 4 | +proved larger than the remaining turn budget, and was REVERTED rather than | ||
| 5 | +left half-wired — this is the charter's own explicitly-sanctioned outcome | ||
| 6 | +("half-wired is the one unacceptable outcome; incomplete-but-named is fine"). | ||
| 7 | + | ||
| 8 | +## What's landed (bd91ad0, prior round) | ||
| 9 | + | ||
| 10 | +- Probed both real films: `ReelB...mkv` -> 3840x1608, `yuv420p10le`, | ||
| 11 | + HDR10 mastering-display metadata present; `ReelC...mkv` -> 1920x792, | ||
| 12 | + `yuv420p10le`, bt709. Neither ffmpeg header dump showed film grain. Both | ||
| 13 | + still stop at the `bit_depth != 8` refusal, as expected. | ||
| 14 | +- `BIT_DEPTH` thread-local + `sample_max()` helper (decode.rs), set once per | ||
| 15 | + frame from the sequence header's real `color_config.bit_depth` in | ||
| 16 | + `stream.rs`'s decode loop. | ||
| 17 | +- The real `bit_depth` threaded into the `dequant_and_inverse_typed*`/`_wh` | ||
| 18 | + call sites that hardcoded `8`. | ||
| 19 | +- Refusal is still in place, so behaviour is provably unchanged for every | ||
| 20 | + existing (8-bit) stream — this increment is inert until PlaneBuf is | ||
| 21 | + widened and the refusal comes off. | ||
| 22 | + | ||
| 23 | +## What was attempted and reverted this round | ||
| 24 | + | ||
| 25 | +Widened `mc.rs`'s prediction/reference functions (`sample`, `predict`, | ||
| 26 | +`predict_with_filter(s)`, `predict_compound_intermediate`, `combine_compound`, | ||
| 27 | +`blend_masked_compound`) from `&[u8]`/`&mut [u8]` to `&[u16]`/`&mut [u16]`, | ||
| 28 | +clamped against `crate::decode::sample_max()` instead of the literal `255`, | ||
| 29 | +and made `sample_max()` `pub(crate)` so `mc.rs` could call it. That much is a | ||
| 30 | +clean, self-contained, mechanically-correct sub-step (`mc.rs`'s own unit test | ||
| 31 | +was updated in step with it). | ||
| 32 | + | ||
| 33 | +It does NOT compile standing alone, because `PlaneBuf::data` (decode.rs:3425) | ||
| 34 | +— every caller of `mc::predict`/`combine_compound`/etc.'s actual argument | ||
| 35 | +type — is still `Vec<u8>`. Starting the PlaneBuf widen (`data: Vec<u16>`) | ||
| 36 | +immediately fans out: `edges()` returns `(Option<Vec<u8>>, Option<Vec<u8>>, | ||
| 37 | +Option<u8>)` consumed by `intra::predict`, `reconstruct`/`reconstruct_rect`/ | ||
| 38 | +`reconstruct_mc`/`reconstruct_mc_rect` all take/write `&[u8]`/`u8` and | ||
| 39 | +`.clamp(0, 255) as u8`, CDEF and ~14 deblock taps do the same, `warp.rs` and | ||
| 40 | +`superres.rs` each have one more clamp-and-cast site, and the final | ||
| 41 | +`PlaneBuf -> Picture` conversion needs an explicit `as u8` narrowing added | ||
| 42 | +back in (Picture's own `y`/`u`/`v` stay `Vec<u8>` in this stage — lifting | ||
| 43 | +that too is stage 2's job, tied to the pixel-format helper `stream.rs`'s own | ||
| 44 | +gate needs). `cargo check -p ec-av1 --lib --tests` on the attempt: **34 | ||
| 45 | +library errors + 40 additional test errors**, all `E0308` mismatched-types / | ||
| 46 | +wrong-argument-type from that one root cause (`PlaneBuf::data` untouched) | ||
| 47 | +propagating through every call site, plus 2 `u16` vs `u8` comparison errors | ||
| 48 | +in existing tests. | ||
| 49 | + | ||
| 50 | +Given the turn budget remaining when this was discovered (partway through a | ||
| 51 | +55-tool-call-deep session), finishing all ~30+ remaining sites blind risked | ||
| 52 | +landing exactly the state the charter calls out by name as unacceptable — a | ||
| 53 | +compiling-looking but subtly wrong half-widen, or an out-of-budget commit | ||
| 54 | +with the crate not compiling at all. Reverted with `git checkout -- | ||
| 55 | +crates/ec-av1/src/decode.rs crates/ec-av1/src/mc.rs`, back to the clean, | ||
| 56 | +green bd91ad0. No uncommitted work lost invisibly: the attempt was stashed | ||
| 57 | +first, popped back, inspected, and only then discarded once its scope was | ||
| 58 | +confirmed too large for the remaining budget — worth stating plainly rather | ||
| 59 | +than silently. | ||
| 60 | + | ||
| 61 | +## Exact sites still assuming 8 bits (for the next round) | ||
| 62 | + | ||
| 63 | +- `decode.rs:3425` `PlaneBuf::data: Vec<u8>` — the root type, must go first. | ||
| 64 | +- `decode.rs` `PlaneBuf::edges()` (~3472) — returns `(Option<Vec<u8>>, | ||
| 65 | + Option<Vec<u8>>, Option<u8>)`, consumed by `intra::predict`. | ||
| 66 | +- `decode.rs` `PlaneBuf::reconstruct`/`reconstruct_rect` and | ||
| 67 | + `reconstruct_mc`/`reconstruct_mc_rect` (~6404 onward) — `prediction: &[u8]` | ||
| 68 | + params, `.clamp(0, 255) as u8` writes (this is the ~30-site sweep the | ||
| 69 | + charter named; 22 `Vec<u8>`/`&[u8]`/`&mut [u8]` occurrences counted in | ||
| 70 | + decode.rs alone this round, plus 4 in `intra.rs`, 1 each in `warp.rs` and | ||
| 71 | + `superres.rs`). | ||
| 72 | +- CDEF's own reconstruction write and the ~14 deblock taps (decode.rs, | ||
| 73 | + un-enumerated this round — same `.clamp(0, 255) as u8` pattern, grep it). | ||
| 74 | +- `mc.rs` — DONE this round in the attempt (stashed then reverted along with | ||
| 75 | + everything else since it doesn't compile alone); the diff is not preserved | ||
| 76 | + anywhere durable, so the next round redoes this specific file, but it is | ||
| 77 | + the smallest, most mechanical piece and took under 10 tool calls the first | ||
| 78 | + time. | ||
| 79 | +- The final `PlaneBuf -> Picture` narrowing point (wherever a finished | ||
| 80 | + `PlaneBuf` is copied into `Picture.y`/`.u`/`.v`) needs an explicit `as u8` | ||
| 81 | + added, since `Picture` itself stays 8-bit output this stage. | ||
| 82 | + | ||
| 83 | +## Recommendation for the next round | ||
| 84 | + | ||
| 85 | +Do the PlaneBuf widen (`data: Vec<u16>`) FIRST, in its own commit-sized step, | ||
| 86 | +before touching `mc.rs` again — the errors it produces are exactly the map | ||
| 87 | +of every remaining site (`cargo check` becomes the sweep's own checklist). | ||
| 88 | +Budget the whole stage 1 as its own round with nothing else assigned, since | ||
| 89 | +one afternoon's attempt (this round, ~20 tool calls) got through `mc.rs` | ||
| 90 | +alone before running short. | ||
| 91 | + | ||
| 92 | +## Merge note | ||
| 93 | + | ||
| 94 | +No refusal strings changed this round (the bit_depth refusal from r7 is | ||
| 95 | +untouched). `crates/ec-av1/src/decode.rs` and `crates/ec-av1/src/mc.rs` are | ||
| 96 | +both back at their bd91ad0 committed content — `git status` clean, nothing | ||
| 97 | +new to merge from this session beyond bd91ad0 (already committed) and this | ||
| 98 | +report. | ||
lanes/sbpart-r2.charter.mdadded+76 -0
| @@ -0,0 +1,76 @@ | |||
| 1 | +# lane-sbpart r2 — build decode_block_rect64, wire HORZ/VERT at 64x64 | ||
| 2 | + | ||
| 3 | +At a2bc6dc. Read `lanes/sbpart.report.md` — it is a typing plan with the | ||
| 4 | +formulas already worked out. Do not re-derive it. | ||
| 5 | + | ||
| 6 | +**Correction to the r1 charter, on the record:** it said this lane was "mostly | ||
| 7 | +extending an existing recursion, not new theory". That was wrong, and r1's | ||
| 8 | +report says why: `decode_block_rect` (32x16 / 16x32) has no truncation logic | ||
| 9 | +because 32 and 16 both fit inside the 32-coefficient cap. A 64x32 / 32x64 strip | ||
| 10 | +does not — its luma plane needs the corner truncation `decode_block` does for a | ||
| 11 | +plain 64x64 square, and `read_plane`'s `tx_side != side` branch is square-only. | ||
| 12 | +That is genuinely new work for a rectangular block, and r1 was right to spend | ||
| 13 | +its round establishing it rather than typing something that could not work. | ||
| 14 | + | ||
| 15 | +## Already landed (0e04b79, green, inert by design) | ||
| 16 | +- `cdf.rs`: `EOB_PT_512_CHROMA`, the true 512-position chroma end-of-block CDF | ||
| 17 | + from libaom's `av1_default_eob_multi512_cdfs[*][1][*]` (token_cdfs.h:874-901). | ||
| 18 | + libaom's default is the same flat distribution at all four q-contexts, so it | ||
| 19 | + is one constant with no `_Q0`/`_Q1`/`_Q3` siblings. | ||
| 20 | +- `cdf_state.rs`: `TxbSet::ChromaRect32x16` with its field, reset, `pick()` / | ||
| 21 | + defaults wiring and `txb()` arm. Shares everything `Chroma32` does except | ||
| 22 | + `eob_pt`. | ||
| 23 | + | ||
| 24 | +r1 also resolved which entropy context each axis lands on, via | ||
| 25 | +`get_txsize_entropy_ctx` = `(txsize_sqr_map[tx] + txsize_sqr_up_map[tx] + 1) >> 1` | ||
| 26 | +(common_data.h:302-341): LUMA TX_64X32/TX_32X64 resolves to **TX_64X64**, so the | ||
| 27 | +already-landed `TxbSet::Luma64` + `SCAN_32` are correct and no new table is | ||
| 28 | +needed; CHROMA TX_32X16/TX_16X32 resolves to **TX_32X32**, which is `Chroma32`'s | ||
| 29 | +tables except the eob — hence this round's new variant. | ||
| 30 | + | ||
| 31 | +## Build, in this order — COMMIT AT EVERY GREEN STEP | ||
| 32 | +1. `decode_block_rect64(bw, bh)` (or generalize `decode_block_rect`): | ||
| 33 | + - mode via `read_intra_mode_rect`, which is already bw/bh-generic but | ||
| 34 | + unverified above 32x16 — check its angle-delta and filter-intra ranges do | ||
| 35 | + not assume `bw, bh <= 32`; | ||
| 36 | + - luma: read a real 32x32 corner with `read_coeffs` (not `_rect`) using | ||
| 37 | + `TxbSet::Luma64` / `SCAN_32`, embed it top-left of a `bw*bh` zero grid | ||
| 38 | + (mirror `read_plane`'s `tx_side != side` branch, generalized to | ||
| 39 | + non-square), then `dequant_and_inverse_typed_wh` over the whole grid; | ||
| 40 | + - chroma: read the real `bw/2 x bh/2` corner with `read_coeffs_rect` using | ||
| 41 | + `TxbSet::ChromaRect32x16` and the matching `SCAN_32X16` / `SCAN_16X32` | ||
| 42 | + (both already exist). | ||
| 43 | +2. Wire `PARTITION_HORZ` / `PARTITION_VERT` into the `_ =>` arm of the `match` | ||
| 44 | + at decode.rs ~5292 (intra tile path, 64x64 level), exactly the way HORZ/VERT | ||
| 45 | + are already wired at the 32x32 level just above it — two calls to the new | ||
| 46 | + function at `at` and `(at.0 + 2, at.1)` or `(at.0, at.1 + 2)`, mi units, | ||
| 47 | + `SUB_MI`-scaled for the 64 level. | ||
| 48 | +3. The gate, with r1's verified recipe (it reproduces the refusal live): | ||
| 49 | + `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=45 --cpu-used=0 | ||
| 50 | + --threads=1 --row-mt=0 --sb-size=64 --enable-rect-partitions=1 | ||
| 51 | + --enable-ab-partitions=0 --enable-1to4-partitions=0 --min-partition-size=32 | ||
| 52 | + --max-partition-size=64 --enable-restoration=0 --enable-palette=0 | ||
| 53 | + --deltaq-mode=0 --enable-filter-intra=0 --enable-cfl-intra=0 | ||
| 54 | + --enable-intrabc=0 --obu` on a 192x128 `gradients` source blended with | ||
| 55 | + `testsrc2` so it is not flat. `min/max-partition-size=32/64` is the key: it | ||
| 56 | + stops the RD search recursing below 32x32, so every SB-level decision is | ||
| 57 | + genuinely NONE/SPLIT/HORZ/VERT. `EC_AV1_REQUIRE_AOMENC=1`, attempt loop | ||
| 58 | + requiring at least one decode, HARD-asserted firing count. | ||
| 59 | +4. Then the 32x32-level `part32` values, then the inter path's two refusals. | ||
| 60 | + | ||
| 61 | +## The rule this batch has now paid for twice | ||
| 62 | +Do NOT remove a refusal in a commit that does not also gate it. A green suite | ||
| 63 | +proves the removal broke nothing that already ran — it cannot prove the | ||
| 64 | +newly-allowed path, because until the gate exists nothing takes it. Two sibling | ||
| 65 | +lanes lifted refusals on a green suite this batch; one of them turned out to | ||
| 66 | +have a firing counter that was never incremented, so its own assert was blind. | ||
| 67 | +If you cannot gate it this round, leave the refusal in place and say so. | ||
| 68 | + | ||
| 69 | +Merge note: main is at 93d9510 (multi-tile decode landed, gated). Report every | ||
| 70 | +refusal string you remove, verbatim, for `refusal_inventory.rs`. | ||
| 71 | + | ||
| 72 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 73 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 74 | +worktrees have live agents — never build in or edit them. Never push, never | ||
| 75 | +merge into `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. | ||
| 76 | +End with `lanes/sbpart-r2.report.md`, VERDICT on line 1. | ||
lanes/sbpart-r2.report.mdadded+106 -0
| @@ -0,0 +1,106 @@ | |||
| 1 | +VERDICT: PARTIAL -- decode_block_rect64 built and wired (green, committed, | ||
| 2 | +c34be7c); the gate reaches it and fires `sb_rect_hits() > 0` live against a | ||
| 3 | +real aomenc stream, but the decoded pixels do NOT yet match ffmpeg's own | ||
| 4 | +decode -- a real mismatch, not a refusal. Gate test is uncommitted (red); | ||
| 5 | +next round's first move is to bisect it. | ||
| 6 | + | ||
| 7 | +## What landed (commit c34be7c, compiles clean, no regression) | ||
| 8 | +- `decode_block_rect64(bw, bh)` in `crates/ec-av1/src/decode.rs`, right after | ||
| 9 | + `decode_block_rect`: mode via `read_intra_mode_rect` (unchanged, its | ||
| 10 | + `filter_intra_size_class_rect` already returns `None` for `(64,32)`/ | ||
| 11 | + `(32,64)` since `av1_filter_intra_allowed_bsize` caps at 32 on both axes, | ||
| 12 | + so no extra work was needed there); `tx_size_cat2` depth read gated on | ||
| 13 | + `tx_select`, `depth != 0` refused by name (per-unit rect prediction not | ||
| 14 | + ported, matching `decode_block_rect`'s own scope limit); LUMA reads a | ||
| 15 | + real 32x32 corner via `read_coeffs` with `TxbSet::Luma64` + a locally | ||
| 16 | + computed `default_scan(TX32)` (matching what `decode_block`'s own 64x64 | ||
| 17 | + corner case uses), embeds it top-left of a zeroed `bw*bh` grid (mirrors | ||
| 18 | + `read_plane`'s `tx_side != side` branch, generalized to non-square); | ||
| 19 | + CHROMA reads a real, untruncated `bw/2 x bh/2` transform via | ||
| 20 | + `read_coeffs_rect` with `TxbSet::ChromaRect32x16` (the r1-landed table) | ||
| 21 | + and `SCAN_32X16`/`SCAN_16X32` depending on orientation, with | ||
| 22 | + `default_tx_type = TxType::DctDct` forced (per r1's derivation: chroma at | ||
| 23 | + this size resolves to TX_32X32, `av1_get_ext_tx_set_type`'s `>= TX_32X32` | ||
| 24 | + rule forces DCT_DCT regardless of mode -- the same rule `read_plane` | ||
| 25 | + already applies via its own `side >= 32` check). | ||
| 26 | +- `PARTITION_HORZ`/`PARTITION_VERT` wired into the SB-level `match part` at | ||
| 27 | + decode.rs (was the `_ =>` catchall): two `decode_block_rect64` calls at | ||
| 28 | + `at`/`(at.0+2, at.1)` (HORZ, two 64x32 strips) or `at`/`(at.0, at.1+2)` | ||
| 29 | + (VERT, two 32x64 strips), mirroring the already-landed 32x32-level | ||
| 30 | + pattern exactly. | ||
| 31 | +- New `SB_RECT_HITS` thread-local + `sb_rect_hits()` accessor | ||
| 32 | + (decode.rs), same pattern as `RECT_PARTITION_HITS`/`RECT_COEFF_HITS`. | ||
| 33 | +- `cargo check -p ec-av1`: clean. `cargo test -p ec-av1 --lib round_trip`: | ||
| 34 | + 16/16 passed, no regression (`EC_AV1_REQUIRE_AOMENC=1`). | ||
| 35 | + | ||
| 36 | +## The gate (uncommitted, RED -- pixel mismatch, not a refusal) | ||
| 37 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | ||
| 38 | +in `crates/ec-av1/src/stream.rs` (end of `mod tests`). Recipe, tuned live | ||
| 39 | +this round from the charter's starting point: | ||
| 40 | +- charter's own flags (`--min/max-partition-size=32/64`, rect on/AB off/ | ||
| 41 | + 1to4 off, restoration/palette/deltaq/filter-intra/cfl-intra/intrabc off) | ||
| 42 | + PLUS `--enable-tx-size-search=0` (missing from the charter's recipe -- | ||
| 43 | + without it every HORZ/VERT strip picks a split transform and hits this | ||
| 44 | + function's own `depth != 0` refusal, never reaching the coefficient | ||
| 45 | + reader at all; same fix `decode_block_rect`'s own gate needed, r1's | ||
| 46 | + report just didn't carry it forward to the 64-level recipe). | ||
| 47 | +- **Dead end, recorded so the next round doesn't re-spend budget**: the | ||
| 48 | + charter's "gradients blended with testsrc2" source (`blend=all_mode= | ||
| 49 | + average` lavfi filter) made `allow_screen_content_tools` fire on nearly | ||
| 50 | + every attempt (screen-content strips are refused by | ||
| 51 | + `read_intra_mode_rect` unconditionally) and, worse, made aomenc pick an | ||
| 52 | + SB-level AB partition (`partition_w64` value 7, VERT_B) on almost every | ||
| 53 | + remaining attempt *despite* `--enable-ab-partitions=0` -- a real, | ||
| 54 | + separate aomenc quirk (AB-at-64 is not gated by that flag the way AB | ||
| 55 | + below 64 is; unconfirmed root cause, not investigated further this | ||
| 56 | + round) -- 40/40 attempts refused, zero decodes. Plain `gradients_source` | ||
| 57 | + alone (no blend) reliably avoids both and reaches real HORZ/VERT single- | ||
| 58 | + TU blocks; the gate now uses that. | ||
| 59 | +- With both fixes the gate reaches `decode_block_rect64` and increments | ||
| 60 | + `sb_rect_hits`, but the one attempt run this round (`EC_SBPART_GATE_ | ||
| 61 | + ATTEMPTS=1`, seed 42, 192x128 single frame) MISMATCHES ffmpeg's own | ||
| 62 | + decode on luma starting partway through row 0 -- not a desync (the | ||
| 63 | + stream still parses/finishes, `matched` would be the only counter that | ||
| 64 | + stays 0), a real wrong-pixel bug in the new function. Not bisected this | ||
| 65 | + round (turn budget) -- **next round's first move**: dump the mismatching | ||
| 66 | + stream (`EC_AV1_GATE_DUMP`, same mechanism the masked-compound gate | ||
| 67 | + uses) and range-ladder the luma corner read / chroma read / the | ||
| 68 | + `dequant_and_inverse_typed_wh` call against a real aomdec EC_TRACE, | ||
| 69 | + the same method that closed `decode_block_rect`'s own r3-r5 desync | ||
| 70 | + (lane-rectwire history, memory `[[Interintra decode landed]]`'s sibling | ||
| 71 | + entries) -- suspects in order of likelihood: (a) the corner-embed loop's | ||
| 72 | + stride (`luma_levels[row*bw..][..32]`) vs whatever `dequant_and_ | ||
| 73 | + inverse_typed_wh`'s `w,h` ordering actually expects for a `64x32` vs | ||
| 74 | + `32x64` grid (an axis swap here would look exactly like this symptom -- | ||
| 75 | + right at first, wrong once the strip's true width diverges from 32); (b) | ||
| 76 | + `default_scan(TX32)` vs the packed/stored `scan32` other call sites | ||
| 77 | + reuse -- should be identical (pure function of `TX32`) but not directly | ||
| 78 | + diffed against the working square-64x64 path's own copy this round. | ||
| 79 | + | ||
| 80 | +## Refusal strings removed | ||
| 81 | +None removed outright -- the SB-level catchall | ||
| 82 | +("a superblock-level partition type other than NONE or SPLIT...") still | ||
| 83 | +fires for AB/4-way/split-tx cases, verbatim, unchanged in | ||
| 84 | +`decode.rs`/`refusal_inventory.rs`. For a genuine single-TU HORZ/VERT it no | ||
| 85 | +longer fires (replaced by the new function), but that path is proven WRONG | ||
| 86 | +(pixel mismatch) by the gate above, not proven right -- so functionally no | ||
| 87 | +capability should be considered landed yet; the gate is red and | ||
| 88 | +uncommitted for exactly that reason. | ||
| 89 | + | ||
| 90 | +## What the next round needs to do | ||
| 91 | +1. Bisect the mismatch (see suspects above) -- likely a small, mechanical | ||
| 92 | + bug given `decode_block_rect`'s own precedent (the 32x16/16x32 sibling | ||
| 93 | + needed 5 rounds for something this shape: a spurious/missing symbol | ||
| 94 | + read, not deep coefficient-context math). | ||
| 95 | +2. Once pixel-exact, re-run the gate with the full `n_attempts=40` default | ||
| 96 | + and hard-assert `sb_rect_hits() > 0` (already written that way, just | ||
| 97 | + currently failing before reaching that assert). | ||
| 98 | +3. Only then move to stage 2 (32x32-level `part32` values beyond NONE/ | ||
| 99 | + SPLIT/HORZ/VERT) and the inter path's two refusals, per the charter. | ||
| 100 | + | ||
| 101 | +## Hard rules followed | ||
| 102 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 103 | +every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1` | ||
| 104 | +on every test run; no push, no merge, no touch to `main`, no other worktree | ||
| 105 | +touched. The one green step (`decode_block_rect64` + wiring, no regression) | ||
| 106 | +is committed; the gate test is left uncommitted because it is red. | ||
lanes/sbpart-r3.charter.mdadded+49 -0
| @@ -0,0 +1,49 @@ | |||
| 1 | +# lane-sbpart r3 — bisect the rect64 luma mismatch | ||
| 2 | + | ||
| 3 | +At 9379e99. Read `lanes/sbpart-r2.report.md` first — r2 built | ||
| 4 | +`decode_block_rect64` and wired it at the SB-level `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 5 | +match (was a `_ =>` catchall), and built the gate that proves it fires. I | ||
| 6 | +committed r2's uncommitted gate verbatim for you; it is RED on purpose. | ||
| 7 | + | ||
| 8 | +## The one job | ||
| 9 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | ||
| 10 | +reaches the new code (`sb_rect_hits() > 0` against real aomenc content) and | ||
| 11 | +mismatches ffmpeg's luma from partway through row 0 of a 192x128 frame. Bisect | ||
| 12 | +it. This is a pixel defect with a bit-exact oracle available, so hand-tracing is | ||
| 13 | +the wrong instrument: use `EC_AV1_GATE_DUMP` plus the oracle's `EC_TRACE` / | ||
| 14 | +`EC_TRACE_COEFF` rungs (`scripts/instrument-aom-oracle.sh`, rebuilt with | ||
| 15 | +`scripts/build-aom-oracle.sh` into `~/.cache/aom-oracle`), exactly the way | ||
| 16 | +`decode_block_rect`'s own r3–r5 desync was closed. Add a rung rather than guess | ||
| 17 | +when a fact is not observable. | ||
| 18 | + | ||
| 19 | +r2's two prime suspects, neither checked: the corner-embed stride in the new | ||
| 20 | +function versus `dequant_and_inverse_typed_wh`'s w/h ordering for non-square | ||
| 21 | +64x32 vs 32x64 grids; and `default_scan(TX32)` versus the `scan32` other call | ||
| 22 | +sites reuse (r2 believed these identical but never diffed them). Note the class | ||
| 23 | +[[scan-weights-cross-axis]]: a scan weight or step can use the CROSS axis, and | ||
| 24 | +square candidates hide every axis swap — if you touch scanning, sweep the | ||
| 25 | +transposed copy in the SAME round. | ||
| 26 | + | ||
| 27 | +Since the symbol reads are already right (the partition fires and the stream | ||
| 28 | +does not desync), the defect is in reconstruction, not entropy — check the | ||
| 29 | +range ladder only if a coefficient value proves wrong. | ||
| 30 | + | ||
| 31 | +## Gate recipe facts r2 paid for — do not rediscover them | ||
| 32 | +- `--enable-tx-size-search=0` is REQUIRED or every strip hits its own | ||
| 33 | + `tx-depth != 0` refusal before the pixels matter. | ||
| 34 | +- `--enable-ab-partitions=0` does NOT gate AB partitions at 64x64: r2's blended | ||
| 35 | + `gradients`+`testsrc2` source made aomenc pick SB-level AB on ~40/40 attempts | ||
| 36 | + anyway. Plain `gradients_source` alone reaches real HORZ/VERT reliably. That | ||
| 37 | + aomenc quirk is out of this lane's scope; do not chase it. | ||
| 38 | + | ||
| 39 | +## After it is green | ||
| 40 | +Commit, then stage 2: the 32x32 `part32` values, then the inter path. Do not | ||
| 41 | +start either while the gate is red. | ||
| 42 | + | ||
| 43 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 44 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; fixtures | ||
| 45 | +through `gradients_source(seed, w, h, tail)`; every ffmpeg generate bounded with | ||
| 46 | +`-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64`. | ||
| 47 | +Sibling worktrees have live agents — never build in or edit them. Never push, | ||
| 48 | +never merge into main. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. | ||
| 49 | +End with `lanes/sbpart-r3.report.md`, VERDICT on line 1. | ||
lanes/sbpart-r4.charter.mdadded+44 -0
| @@ -0,0 +1,44 @@ | |||
| 1 | +# lane-sbpart r4 — finish the rect64 bisect | ||
| 2 | + | ||
| 3 | +At 58f7fb6. Read `lanes/sbpart-r3.charter.md` (still your charter — r3 never | ||
| 4 | +reported) and `lanes/sbpart-r2.report.md`. | ||
| 5 | + | ||
| 6 | +r3 stopped at its turn cap with the words "compiles clean, now run the gate". I | ||
| 7 | +committed its edits to `decode.rs` and `stream.rs` verbatim so nothing was lost. | ||
| 8 | +**Their state is unverified by me: run the gate first.** If it is green, r3 | ||
| 9 | +solved it and your job is to prove that, tidy the diagnostics out, and merge | ||
| 10 | +main. If it is still red, keep bisecting. | ||
| 11 | + | ||
| 12 | +The gate is `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`. | ||
| 13 | +It reaches `decode_block_rect64` (`sb_rect_hits() > 0` on real aomenc content) | ||
| 14 | +and mismatched ffmpeg's luma from partway through row 0 of a 192x128 frame. | ||
| 15 | +Method is `EC_AV1_GATE_DUMP` plus the oracle's `EC_TRACE`/`EC_TRACE_COEFF` rungs, | ||
| 16 | +not hand-tracing; add a rung to `scripts/instrument-aom-oracle.sh` if a fact is | ||
| 17 | +not observable (numbers 6, 7, 8 and 8b are taken on main — take 9). r2's two | ||
| 18 | +suspects, still unchecked as far as I know: the corner-embed stride versus | ||
| 19 | +`dequant_and_inverse_typed_wh`'s w/h ordering for 64x32 vs 32x64; and | ||
| 20 | +`default_scan(TX32)` versus the shared `scan32`. If you touch scanning, sweep the | ||
| 21 | +transposed copy in the SAME round — a scan weight can use the cross axis and | ||
| 22 | +square candidates hide every axis swap ([[scan-weights-cross-axis]]). | ||
| 23 | + | ||
| 24 | +Gate-recipe facts already paid for, do not rediscover: `--enable-tx-size-search=0` | ||
| 25 | +is REQUIRED or every strip hits its own tx-depth refusal first; and | ||
| 26 | +`--enable-ab-partitions=0` does NOT gate AB partitions at 64x64, so use plain | ||
| 27 | +`gradients_source` rather than a blended source. | ||
| 28 | + | ||
| 29 | +Then merge `main` into this branch and resolve it yourself — main is at a8724cb, | ||
| 30 | +far ahead (tile rows, delta_q/delta_lf, key-frame superres, palette-Y, a | ||
| 31 | +`bit_depth != 8` refusal, three guard tests). Expect `refusal_inventory` and | ||
| 32 | +`gate_coverage` to fail until this branch's lists match; that is them working. | ||
| 33 | + | ||
| 34 | +A branch that lifts a refusal without a gate does not merge to main. | ||
| 35 | + | ||
| 36 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 37 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; fixtures | ||
| 38 | +through `gradients_source(seed, w, h, tail)`; ffmpeg generates bounded with `-t`; | ||
| 39 | +`EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64`. The | ||
| 40 | +oracle is SHARED with five sibling lanes — env-gated rungs only, never a | ||
| 41 | +throwaway patch left in the tree. Sibling worktrees have live agents — never | ||
| 42 | +build in or edit them. Never push, never merge into main. 75-turn cap, does not | ||
| 43 | +reset: COMMIT AT EVERY GREEN STEP. End with `lanes/sbpart-r4.report.md`, VERDICT | ||
| 44 | +on line 1. | ||
lanes/sbpart-r5.charter.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-sbpart r5 — the rect64 bisect, third attempt | ||
| 2 | + | ||
| 3 | +At 2f51dc1. Read `lanes/sbpart-r4.charter.md` and `lanes/sbpart-r2.report.md`. | ||
| 4 | + | ||
| 5 | +Two rounds have now died at the cap on this without reporting. r4 stopped while | ||
| 6 | +adding "one more targeted trace print to pin down whether the desync is in symbol | ||
| 7 | +reading or purely in reconstruction" — I committed its edits verbatim, trace | ||
| 8 | +prints included, state unverified. **Answer that exact question first**, because | ||
| 9 | +it splits the search in half: | ||
| 10 | +- If the ENTROPY stream desyncs (a symbol read that libaom does not write, or | ||
| 11 | + vice versa), it is a range-ladder problem: compare msac RANGE element by | ||
| 12 | + element against the oracle, never `tell()` ([[compare-range-not-tell]]), and | ||
| 13 | + remember that a reference range that does not move where ours does means we | ||
| 14 | + read a symbol it never wrote ([[equal-range-means-unread]]). | ||
| 15 | +- If the symbols match and only pixels differ, it is reconstruction: the | ||
| 16 | + corner-embed stride versus `dequant_and_inverse_typed_wh`'s w/h ordering for | ||
| 17 | + 64x32 vs 32x64, or `default_scan(TX32)` versus the shared `scan32`. If you | ||
| 18 | + touch scanning, sweep the transposed copy in the SAME round | ||
| 19 | + ([[scan-weights-cross-axis]]). | ||
| 20 | + | ||
| 21 | +Report which of the two it is even if you fix nothing else. That answer is worth | ||
| 22 | +more than another partial trace, and it is what the last two rounds failed to | ||
| 23 | +deliver. | ||
| 24 | + | ||
| 25 | +Then merge `main` into this branch (now 913df61 — loop restoration filters | ||
| 26 | +landed on top of tile rows, superres, palette-Y and delta_q/delta_lf) and resolve | ||
| 27 | +it yourself. Watch for the merge shape that has now bitten three times: git | ||
| 28 | +merges the text cleanly while a newer gate calls a decoder whose signature this | ||
| 29 | +branch changed. Compile after every merge, not just at the end. | ||
| 30 | + | ||
| 31 | +Gate-recipe facts already paid for: `--enable-tx-size-search=0` is REQUIRED, and | ||
| 32 | +`--enable-ab-partitions=0` does NOT gate AB at 64x64, so use plain | ||
| 33 | +`gradients_source`. | ||
| 34 | + | ||
| 35 | +## Budget discipline (I am serious about this) | ||
| 36 | +You have 75 turns and they do NOT reset if you are resumed. At roughly turn 55, | ||
| 37 | +STOP starting new work: commit what is green, and write your report. Five rounds | ||
| 38 | +in the last batch died mid-edit with nothing reported, and each cost a whole | ||
| 39 | +round to recover. A round that ends with an honest report beats one that ends | ||
| 40 | +five turns deeper into an edit. | ||
| 41 | + | ||
| 42 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 43 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 44 | +`EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64`. Oracle | ||
| 45 | +rungs 6, 7, 8, 8b are taken — take 9; the oracle is SHARED, env-gated rungs only. | ||
| 46 | +Sibling worktrees have live agents — never build in or edit them. Never push, | ||
| 47 | +never merge into main. End with `lanes/sbpart-r5.report.md`, VERDICT on line 1. | ||
lanes/sbpart-r5.report.mdadded+119 -0
| @@ -0,0 +1,119 @@ | |||
| 1 | +VERDICT: PARTIAL -- answered the charter's headline question (ENTROPY DESYNC, | ||
| 2 | +not reconstruction) with decisive evidence; did not fix the bug and did not | ||
| 3 | +attempt the main merge (budget ran out at the diagnostic step; merge deferred | ||
| 4 | +rather than rushed, per r2/r3/r4's own history of dying mid-edit). | ||
| 5 | + | ||
| 6 | +## The answer: ENTROPY DESYNC, not reconstruction | ||
| 7 | + | ||
| 8 | +Reproduced r2's pinned mismatch (`EC_SBPART_GATE_ATTEMPTS=1`, seed 42, dumped | ||
| 9 | +via `EC_AV1_GATE_DUMP` to | ||
| 10 | +`/tmp/.../scratchpad/sbpart-pin.obu`) and added a bounding-box + per-64px | ||
| 11 | +superblock-column mismatch breakdown (env-gated `EC_SBPART_DIAG`, on the | ||
| 12 | +`pinned_sbpart_stream_decodes_pixel_exact` test r4 left uncommitted-verified; | ||
| 13 | +committed this round at dff47f8, diagnostics only, no behavior change to the | ||
| 14 | +live gate). | ||
| 15 | + | ||
| 16 | +Findings, decisive in order: | ||
| 17 | +1. With the gate's own default flags (loop filters on), luma mismatches cover | ||
| 18 | + 74% of the whole 192x128 frame (18291/24576 px), bounding box the entire | ||
| 19 | + image -- already suspicious for a "reconstruction only" bug, which should | ||
| 20 | + stay confined to the block(s) actually decoded by the new code. | ||
| 21 | +2. Re-encoded the identical seed/recipe with `--enable-cdef=0 | ||
| 22 | + --loopfilter-control=0` added (temporarily, reverted before commit -- the | ||
| 23 | + live gate is unchanged) to rule out loop-filter propagation muddying the | ||
| 24 | + bounding box. Result, per 64px superblock column (`TRACE_RECT64_END` | ||
| 25 | + confirms the SB-level VERT split fires at mi_row=0, mi_col=16/24, i.e. the | ||
| 26 | + second SB column, two 32x64 halves): | ||
| 27 | + - SB col 0 (px 0-63, decoded first, plain SPLIT/32x32 path, never touches | ||
| 28 | + `decode_block_rect64`): **zero mismatches**. Pixel-exact. | ||
| 29 | + - SB col 1 (px 64-127, the rect64 SB): the **first** `decode_block_rect64` | ||
| 30 | + call (px 64-95, block1) is **pixel-exact**; the **second** call (px | ||
| 31 | + 96-127, block2) mismatches from its very first pixel (row 0, col 96). | ||
| 32 | + - SB col 2 (px 128-191, decoded right after the rect64 SB, plain | ||
| 33 | + SPLIT/32x32 path again): 8160/8192 px wrong, first mismatch at its very | ||
| 34 | + first pixel (row 0, col 128). | ||
| 35 | + - SB row 1 (below, decoded last): also garbage from its first pixel. | ||
| 36 | +3. This is the textbook entropy-desync signature: a reconstruction bug (wrong | ||
| 37 | + stride, transposed scan table, axis-swapped embed) stays inside the | ||
| 38 | + spatial footprint of the block it corrupts. Here, everything decoded | ||
| 39 | + **after** block2 -- SB col 2, all of SB row 1, none of which ever calls | ||
| 40 | + `decode_block_rect64` or any rect-related code -- is also wrong, and | ||
| 41 | + everything decoded **before** it (SB col 0, and block1 itself) is | ||
| 42 | + perfect. The corruption starts exactly at block2's first symbol read and | ||
| 43 | + never recovers: the bitstream desynced between the end of the first | ||
| 44 | + `decode_block_rect64` call and the start of the second one, inside the | ||
| 45 | + `PARTITION_VERT` (and by construction, symmetrically `PARTITION_HORZ`) arm | ||
| 46 | + of the SB-level match at `decode.rs:5611-5643`. | ||
| 47 | +4. This **overturns r2's suspects (a)/(b)** (corner-embed stride vs | ||
| 48 | + `dequant_and_inverse_typed_wh`'s w/h ordering; `default_scan(TX32)` vs | ||
| 49 | + `scan32`) -- those are both purely within-block reconstruction/coefficient | ||
| 50 | + paths and cannot explain corruption of spatially unrelated blocks decoded | ||
| 51 | + afterward. They are not ruled out as *additional* bugs, but they are not | ||
| 52 | + *this* bug. | ||
| 53 | + | ||
| 54 | +## What is NOT the cause (checked and ruled out this round) | ||
| 55 | +- `maybe_read_cdef_idx`'s `CDEF_TRANSMITTED` guard (`decode.rs:115-134`, | ||
| 56 | + reset per-SB at `decode.rs:5188`): correctly gates a second `cdef_idx` | ||
| 57 | + read within one SB (matches the existing, presumably-working | ||
| 58 | + `decode_block_rect` 32x32-level precedent at `decode.rs:2903`). Confirmed | ||
| 59 | + moot for the observed bug directly -- disabling CDEF entirely | ||
| 60 | + (`--enable-cdef=0`) reproduces the identical symptom (block1 clean, block2 | ||
| 61 | + wrong from pixel 0), so this is not it. | ||
| 62 | +- `fill_skip_grid_rect`/`skip_txfm_ctx`/`skip_at` (decode.rs:1610-1648): | ||
| 63 | + read/write spans for block1 (mi_c 16..24) correctly cover block2's true | ||
| 64 | + left-neighbour cell (mi_c 23); code-audited, looks right. | ||
| 65 | +- `record_rect` (decode.rs:1912-1933): block1's `above_mode`/`left_mode` | ||
| 66 | + writes span `c..c+w/SUB` / `r..r+h/SUB` -- for block1 (bw=32,bh=64) that is | ||
| 67 | + `above_mode[4..6]`, `left_mode[0..4]`; block2 reads `left_mode[at.0]` = | ||
| 68 | + `left_mode[0]`, which block1 did write. Also looks right on inspection. | ||
| 69 | + | ||
| 70 | +## Not yet found (next round's first move) | ||
| 71 | +The exact wrong read is still unlocated -- code audit of every neighbour/ | ||
| 72 | +context computation touched by block2's first three reads (`skip`, | ||
| 73 | +`mode`/`above_ctx`/`left_ctx` via `INTRA_MODE_CTX`, `angle_delta_y`) turned up | ||
| 74 | +nothing obviously wrong by inspection; the previous two rounds' turn-cap | ||
| 75 | +deaths were from chasing exactly this kind of manual trace without a ground | ||
| 76 | +truth to compare against. **The next round should stop code-auditing and get | ||
| 77 | +a real range/bit-position oracle**: an `aomdec` build patched to | ||
| 78 | +`EC_TRACE`-print the same (mi_row, mi_col, symbol name, msac range) tuples our | ||
| 79 | +decoder already prints via `EC_AV1_TRACE`, then range-ladder block2's first | ||
| 80 | +handful of reads against it (per [[compare-range-not-tell]] and | ||
| 81 | +[[price-the-narrowing-not-the-table]]) -- oracle rung 9 was reserved for this | ||
| 82 | +in the charter and was not spent this round; do not add a second throwaway | ||
| 83 | +patch, env-gate it in `scripts/build-aom-oracle.sh` the way rungs 6-8b did. | ||
| 84 | + | ||
| 85 | +## What was committed (dff47f8) | ||
| 86 | +Diagnostics only, no behavior change to the live gate | ||
| 87 | +(`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | ||
| 88 | +is byte-identical to before this round): a `TRACE_RECT32_END` print in | ||
| 89 | +`decode_block_rect` mirroring the existing `TRACE_RECT64_END`, and an | ||
| 90 | +`EC_SBPART_DIAG` env-gated bounding-box/per-SB-column mismatch breakdown on | ||
| 91 | +`pinned_sbpart_stream_decodes_pixel_exact` (r4's pinned-replay test, itself | ||
| 92 | +already committed at 2f51dc1). `cargo check -p ec-av1`: clean. | ||
| 93 | + | ||
| 94 | +## Merge NOT attempted this round | ||
| 95 | +Ran out of turn budget reaching the bisect answer (the diagnostic loop above | ||
| 96 | +took most of this round's calls -- large `cargo test` outputs on this box are | ||
| 97 | +expensive to inspect). Per the charter's own budget discipline ("at turn 55 | ||
| 98 | +stop starting new work"), did not start the `main` (913df61) merge -- three | ||
| 99 | +prior merges in this batch were text-clean/compile-broken, and starting one | ||
| 100 | +with no turns left to fix a broken decoder-signature collision would be worse | ||
| 101 | +than leaving it for a round with full budget. **This is the single biggest | ||
| 102 | +item owed to the next round**, ahead of the bisect continuation above. | ||
| 103 | + | ||
| 104 | +## Hard rules followed | ||
| 105 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 106 | +every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1` | ||
| 107 | +on every aomenc-driven test run; aomenc always `--threads=1 --row-mt=0 | ||
| 108 | +--sb-size=64`; no push, no merge into main, no other worktree touched; no | ||
| 109 | +throwaway oracle patch left in the tree (rung 9 reserved but not spent). | ||
| 110 | + | ||
| 111 | +## Next round, in order | ||
| 112 | +1. Merge `main` (913df61) into `lane-sbpart`, compile immediately, fix any | ||
| 113 | + decoder-signature collision before doing anything else. | ||
| 114 | +2. Build the `EC_TRACE`-patched `aomdec` oracle rung (env-gated, rung 9) and | ||
| 115 | + range-ladder block2's first ~5 symbol reads (`skip`, `mode`, | ||
| 116 | + `angle_delta_y`, `uv_mode`, `angle_delta_uv`) against it to name the exact | ||
| 117 | + wrong read. | ||
| 118 | +3. Fix, then re-run the full-`n_attempts=40` gate and hard-assert | ||
| 119 | + `sb_rect_hits() > 0` (already written that way in the gate). | ||
lanes/sbpart-r6.charter.mdadded+50 -0
| @@ -0,0 +1,50 @@ | |||
| 1 | +# lane-sbpart r6 — range-ladder block2 | ||
| 2 | + | ||
| 3 | +At f68fe19. Read `lanes/sbpart-r5.report.md`. r5 delivered the answer three | ||
| 4 | +rounds had failed to: the rect64 mismatch is an **entropy desync, not | ||
| 5 | +reconstruction**. Block1 of the SB-level `PARTITION_VERT` pair | ||
| 6 | +(`decode.rs:5611-5643`) decodes pixel-exact; block2 is wrong from its first | ||
| 7 | +pixel; everything after it in raster order is wrong; everything before it, | ||
| 8 | +including SB column 0, is exact. That overturns r2's stride and scan-table | ||
| 9 | +suspects — drop them. | ||
| 10 | + | ||
| 11 | +## Order | ||
| 12 | +1. **Merge `main` first** (now 170a5a3 — loop restoration filters, tile-group | ||
| 13 | + OBUs, non-uniform tile spacing, a reworded sub-16x16 partition refusal) and | ||
| 14 | + COMPILE IMMEDIATELY. Three merges in this batch were text-clean and | ||
| 15 | + compile-broken because a newer gate called a decoder whose signature a lane | ||
| 16 | + had changed. r5 owed this and ran out of budget. | ||
| 17 | +2. **Build oracle rung 9**: an `EC_TRACE`-patched decode path in | ||
| 18 | + `scripts/instrument-aom-oracle.sh`, env-gated and silent when unset, that | ||
| 19 | + prints the range after each element for the SB containing block2. Follow the | ||
| 20 | + existing rungs' wrapper-around-impl shape; rebuild with | ||
| 21 | + `scripts/build-aom-oracle.sh`. Rungs 6, 7, 8, 8b are taken and 10 is spoken | ||
| 22 | + for by a sibling lane, so take 9. | ||
| 23 | +3. **Range-ladder block2's first reads** (skip, mode, angle_delta_y, uv_mode) | ||
| 24 | + against it. Compare msac RANGE, never `tell()` — decoders' tell baselines | ||
| 25 | + differ by fixed constants ([[compare-range-not-tell]]). Read the result | ||
| 26 | + strictly: the reference's range unchanged where ours moves means we read a | ||
| 27 | + symbol it never wrote; theirs moving where ours does not means we skipped | ||
| 28 | + one; only when both move differently is a table implicated | ||
| 29 | + ([[equal-range-means-unread]]). | ||
| 30 | +4. Fix, then get the gate pixel-exact, then merge-ready. | ||
| 31 | + | ||
| 32 | +r5 ruled out by direct experiment: `maybe_read_cdef_idx`'s per-SB | ||
| 33 | +`CDEF_TRANSMITTED` guard (`--enable-cdef=0` reproduces the identical symptom). | ||
| 34 | +It also code-audited `fill_skip_grid_rect`/`skip_txfm_ctx`/`record_rect`'s | ||
| 35 | +above/left span writes and found them correct **by inspection only** — which is | ||
| 36 | +exactly the kind of proof this repo has watched fail, so let the ladder decide | ||
| 37 | +rather than trusting that audit ([[shared-oracle-blindness]]). | ||
| 38 | + | ||
| 39 | +## Budget discipline | ||
| 40 | +75 turns, and they do NOT reset if you are resumed. At about turn 55, stop | ||
| 41 | +starting new work: commit what is green and write your report. | ||
| 42 | + | ||
| 43 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 44 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 45 | +`EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64`; | ||
| 46 | +`--enable-tx-size-search=0` is required by this gate's recipe. The oracle is | ||
| 47 | +SHARED with sibling lanes — env-gated rungs only, never a throwaway patch left in | ||
| 48 | +the tree. Sibling worktrees have live agents — never build in or edit them. Never | ||
| 49 | +push, never merge into main. End with `lanes/sbpart-r6.report.md`, VERDICT on | ||
| 50 | +line 1. | ||
lanes/sbpart-r6.report.mdadded+135 -0
| @@ -0,0 +1,135 @@ | |||
| 1 | +VERDICT: PARTIAL -- merged main and compiled clean (charter's order 1), built | ||
| 2 | +oracle rung 10 and range-laddered block2's mode-info reads (charter's order | ||
| 3 | +2-3), got a decisive result that OVERTURNS r5's own framing of where the | ||
| 4 | +desync starts, but did not reach a fix (order 4) before budget ran thin. | ||
| 5 | + | ||
| 6 | +## 1. Merge main (170a5a3), compiled | ||
| 7 | + | ||
| 8 | +`git merge origin/main` conflicted in exactly one file, `stream.rs`: both | ||
| 9 | +lane-realworld (deltaq gate) and lane-tiles (tile-group + non-uniform-spacing | ||
| 10 | +gates) added tests immediately adjacent to this lane's sbpart tests with no | ||
| 11 | +shared context lines between them, so git's 3-way merge produced one large | ||
| 12 | +interleaved conflict block spanning ~630 lines rather than several small | ||
| 13 | +ones. First attempted resolution (character-level "keep both sides") was | ||
| 14 | +WRONG -- it interleaved unrelated functions' local variables mid-body. | ||
| 15 | +Discarded that with `git checkout --merge` and re-resolved by function | ||
| 16 | +boundary instead: every complete test function from each side kept intact, | ||
| 17 | +in sequence (sbpart's rect64 gate + pinned replay, then realworld's deltaq | ||
| 18 | +gate, then tiles' r7/r9/non-uniform-spacing gates) -- no duplicated or | ||
| 19 | +truncated function bodies. `cargo check -p ec-av1 --tests`: clean, only | ||
| 20 | +pre-existing missing-doc warnings. Committed at bfb1b8f. | ||
| 21 | + | ||
| 22 | +## 2. Oracle rung 10 | ||
| 23 | + | ||
| 24 | +Rung 9 (charter's assignment) was already taken by lane-lr on `main` by the | ||
| 25 | +time this round started (`calculate_intermediate_result` export, landed on | ||
| 26 | +main before this merge). Took rung 10 instead, in | ||
| 27 | +`scripts/instrument-aom-oracle.sh`: `EC_TRACE_MODE_STEP=1` prints | ||
| 28 | +`EC_ISTEP mi_row=.. mi_col=.. name=.. val=.. rng=..` after each of `skip`, | ||
| 29 | +`cdef`, `dq`, `mode`, `angle_y`, `uv_mode`, `angle_uv` inside | ||
| 30 | +`ec_read_intra_frame_mode_info_impl` (rung 5's renamed body) -- the finest | ||
| 31 | +granularity the charter asked for, one line per symbol, not one line per | ||
| 32 | +block. Built clean after fixing a Python `%`-operator escaping bug (raw `%d`/ | ||
| 33 | +`%u` C format specifiers in the template collided with Python's own `%` | ||
| 34 | +substitution on the first attempt -- caught by the ninja build failing with | ||
| 35 | +"missing terminating \" character", reverted the bad decodemv.c edit with a | ||
| 36 | +targeted regex strip before rebuilding, not a full `git checkout` of the | ||
| 37 | +oracle source since rungs 1-9's uncommitted patches live in the same | ||
| 38 | +uncommitted working tree). `ninja -C ~/.cache/aom-oracle/build aomdec`: | ||
| 39 | +clean after the fix. | ||
| 40 | + | ||
| 41 | +Added the matching instrumentation to our own decoder | ||
| 42 | +(`read_intra_mode_rect` in `decode.rs`, gated on the same `EC_TRACE_MODE_STEP` | ||
| 43 | +env var, same `EC_ISTEP` line format) so the two traces diff directly by | ||
| 44 | +`grep`, no manual field-mapping between differently-shaped trace formats. | ||
| 45 | + | ||
| 46 | +## 3. Range-ladder result: block2's mode-info prefix is byte-exact | ||
| 47 | + | ||
| 48 | +Regenerated the pinned mismatch fresh this round (old pin was gone -- | ||
| 49 | +scratchpad reaped between sessions per [[oracle-in-reaped-dir]]'s pattern, | ||
| 50 | +though this time it was just session-scoped, not a tmpfs wipe): | ||
| 51 | +`EC_SBPART_GATE_ATTEMPTS=1 EC_AV1_GATE_DUMP=... cargo test ... a_real_aomenc_ | ||
| 52 | +stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact -- | ||
| 53 | +--nocapture`, seed 42, same recipe as r2-r5. Decoded the pinned OBU through | ||
| 54 | +both `aomdec --i420` (oracle) and `pinned_sbpart_stream_decodes_pixel_exact` | ||
| 55 | +(ours), both with `EC_TRACE_MODE_STEP=1`. | ||
| 56 | + | ||
| 57 | +Block2 is `mi_row=0 mi_col=24` (px 96, matching r5's bounding-box finding). | ||
| 58 | +Side-by-side range ladder, every field: | ||
| 59 | + | ||
| 60 | +``` | ||
| 61 | + ours oracle | ||
| 62 | +skip val=0 rng=43948 val=0 rng=43948 | ||
| 63 | +cdef val=0 rng=43948 val=0 rng=43948 | ||
| 64 | +dq rng=43948 val=180 rng=43948 | ||
| 65 | +mode val=0 rng=44880 val=0 rng=44880 | ||
| 66 | +angle_y val=0 rng=44880 val=0 rng=44880 | ||
| 67 | +uv_mode val=0 rng=63764 val=0 rng=63764 | ||
| 68 | +angle_uv val=0 rng=63764 val=0 rng=63764 | ||
| 69 | +``` | ||
| 70 | + | ||
| 71 | +Every decoded value and every `rng` after every read matches exactly. This | ||
| 72 | +is a real per-symbol proof, not inspection -- it **overturns r5's own | ||
| 73 | +framing** ("block2 ... wrong from its very first pixel" was read as "desync | ||
| 74 | +at block2's first symbol"; it is not). The mode-info prefix | ||
| 75 | +(`read_intra_mode_rect`, `decode.rs:2572`) is entropy-correct for block2. | ||
| 76 | +The desync -- confirmed still real by the full oracle trace only ever | ||
| 77 | +visiting `mi_col ∈ {0, 16, 24, 32}` at row 0 and `{0, 16, 32}` at row 16 | ||
| 78 | +(three `NONE` 64x64 blocks plus the one `VERT` pair, seven blocks total), | ||
| 79 | +while our own trace's next `EC_ISTEP` entry after block2 is | ||
| 80 | +`mi_row=16 mi_col=40` -- a rect64 block **that does not exist in the real | ||
| 81 | +partition tree at all** (oracle's `mi_col=32` row-1 block is a single | ||
| 82 | +directional `NONE` block, mode=5, never split) -- must originate somewhere | ||
| 83 | +between `angle_uv` returning and the end of `decode_block_rect64`'s own | ||
| 84 | +symbol reads, i.e. **strictly after** the mode-info prefix this round | ||
| 85 | +laddered clean. | ||
| 86 | + | ||
| 87 | +## Narrowed suspect for next round | ||
| 88 | + | ||
| 89 | +`decode_block_rect64` (decode.rs:3081), after the now-proven-correct prefix, | ||
| 90 | +reads in order: `tx_select`-gated depth symbol (refuses if split; gate's | ||
| 91 | +`--enable-tx-size-search=0` should force `tx_select=false` so this is a | ||
| 92 | +no-op here, unverified this round but low suspicion given r2's precedent fix | ||
| 93 | +comment at decode.rs:2781-2787), then three coefficient reads -- | ||
| 94 | +`read_coeffs` with `TxbSet::Luma64`/`scan32` for the 32x32 luma corner, then | ||
| 95 | +`read_coeffs_rect` with `TxbSet::ChromaRect32x16` for U then V -- each keyed | ||
| 96 | +off `Neighbours::around_rect(at, bw, bh)` (decode.rs:2094) for | ||
| 97 | +`skip_ctx`/`dc_sign_ctx`. **`around_rect` is the sharpest unaudited | ||
| 98 | +suspect**: r5's inspection pass covered `record_rect` (the WRITE side after | ||
| 99 | +block1 decodes) and `fill_skip_grid_rect`/`skip_txfm_ctx` (a different | ||
| 100 | +context path), but never looked at `around_rect` (the READ side block2 | ||
| 101 | +itself calls, gathering over block1's freshly-written span) -- and per | ||
| 102 | +[[context-read-from-one-cell]], a gather that reads the wrong span or wrong | ||
| 103 | +cell for a just-written neighbour is exactly the class of bug that produces | ||
| 104 | +a wrong CDF selection, which changes both the decoded coefficient VALUES | ||
| 105 | +and the number of bits consumed, matching everything observed (wrong pixels | ||
| 106 | +in block2 from coefficient reconstruction AND a real downstream desync). | ||
| 107 | +Next round should range-ladder the coefficient reads themselves (rung 3, | ||
| 108 | +`EC_TRACE_COEFF`, already built by a sibling lane and reusable as-is) at | ||
| 109 | +block2's luma/chroma planes, comparing against `around_rect`'s computed | ||
| 110 | +`skip_ctx`/`dc_sign_ctx` by hand first -- cheaper than a full range-ladder | ||
| 111 | +since there are only 3 reads to check, and the mode-info ladder built this | ||
| 112 | +round proves the harness/methodology works end to end. | ||
| 113 | + | ||
| 114 | +## Hard rules followed | ||
| 115 | + | ||
| 116 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 117 | +every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1` | ||
| 118 | +on the aomenc-driven run; aomenc recipe unchanged (`--threads=1 --row-mt=0 | ||
| 119 | +--sb-size=64 --enable-tx-size-search=0`, inherited from the existing gate, | ||
| 120 | +not re-typed); oracle rung is env-gated (`EC_TRACE_MODE_STEP`), silent when | ||
| 121 | +unset, added to `scripts/instrument-aom-oracle.sh` not left as a standalone | ||
| 122 | +patch; no other worktree touched; no push, no merge into main. | ||
| 123 | + | ||
| 124 | +## Next round, in order | ||
| 125 | + | ||
| 126 | +1. Range-ladder the three coefficient reads in `decode_block_rect64` for | ||
| 127 | + block2 (luma corner via `TxbSet::Luma64`, then U/V via | ||
| 128 | + `TxbSet::ChromaRect32x16`) against oracle rung 3 (`EC_TRACE_COEFF`, | ||
| 129 | + already built, no new rung needed). | ||
| 130 | +2. Hand-check `around_rect` (decode.rs:2094) against libaom's real | ||
| 131 | + neighbour-gather for skip/dc-sign context on a rect strip's right-hand | ||
| 132 | + block -- compare its span math to `record_rect`'s write span for block1, | ||
| 133 | + which r5 already confirmed correct. | ||
| 134 | +3. Fix, then re-run the full `n_attempts=40` gate and confirm | ||
| 135 | + `sb_rect_hits() > 0` stays a hard pass, not just a compile check. | ||
lanes/sbpart-r7.charter.mdadded+33 -0
| @@ -0,0 +1,33 @@ | |||
| 1 | +# lane-sbpart r7 — read the ladder | ||
| 2 | + | ||
| 3 | +At 137f09c. **I merged main for you.** r6 merged, built oracle rung 10 and was | ||
| 4 | +writing its report when it hit the cap; its tree is committed verbatim at | ||
| 5 | +2c27c00, **unverified**. Check it compiles, then continue. | ||
| 6 | + | ||
| 7 | +Read `lanes/sbpart-r5.report.md` and whatever r6 left in `lanes/`. The finding | ||
| 8 | +that matters: the rect64 mismatch is an **entropy desync, not reconstruction**. | ||
| 9 | +Block1 of the SB-level `PARTITION_VERT` pair is pixel-exact; block2 is wrong | ||
| 10 | +from its first pixel; everything after it in raster order is wrong; everything | ||
| 11 | +before it is exact. | ||
| 12 | + | ||
| 13 | +Use the rung to range-ladder block2's first reads — skip, mode, angle_delta_y, | ||
| 14 | +uv_mode. Compare msac RANGE, never `tell()` ([[compare-range-not-tell]]), and | ||
| 15 | +read the result strictly: reference range unchanged where ours moves = we read a | ||
| 16 | +symbol it never wrote; theirs moves and ours does not = we skipped one; only both | ||
| 17 | +moving differently implicates a table ([[equal-range-means-unread]]). | ||
| 18 | + | ||
| 19 | +r5 ruled out the CDEF per-SB guard by experiment. Its clearing of | ||
| 20 | +`fill_skip_grid_rect`/`skip_txfm_ctx`/`record_rect` was **by inspection only** — | ||
| 21 | +let the ladder decide. | ||
| 22 | + | ||
| 23 | +## Budget discipline | ||
| 24 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 25 | +what is green and write your report. The merge is already done for you. | ||
| 26 | + | ||
| 27 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 28 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 29 | +`EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64` and this | ||
| 30 | +gate needs `--enable-tx-size-search=0`. The oracle is SHARED — env-gated rungs | ||
| 31 | +only, never a throwaway patch left in the tree. Sibling worktrees have live | ||
| 32 | +agents — never build in or edit them. Never push, never merge into main. End with | ||
| 33 | +`lanes/sbpart-r7.report.md`, VERDICT on line 1. | ||
lanes/sbpart-r7.report.mdadded+192 -0
| @@ -0,0 +1,192 @@ | |||
| 1 | +VERDICT: PARTIAL -- checked r6's tree compiles clean (charter's order 0), built | ||
| 2 | +oracle rung 11 (per-symbol range ladder inside `read_coeffs_txb`), and used it | ||
| 3 | +to localize block2's real divergence to a specific coefficient `base` symbol | ||
| 4 | +inside the luma corner scan -- a materially sharper answer than r5/r6's | ||
| 5 | +`around_rect`/context-gather suspects, but did not reach or land a fix. | ||
| 6 | + | ||
| 7 | +## 0. Compile check (charter's first step) | ||
| 8 | + | ||
| 9 | +`cargo check -p ec-av1 --tests` on r6's committed-verbatim tree (137f09c): | ||
| 10 | +clean, only pre-existing missing-doc warnings. No merge-conflict debris, no | ||
| 11 | +signature mismatches. r6's tree was in fact fine; only its report write was | ||
| 12 | +interrupted at the cap. | ||
| 13 | + | ||
| 14 | +## 1. r6's own framing, re-checked | ||
| 15 | + | ||
| 16 | +r6 proved block2's mode-info prefix (skip/cdef/dq/mode/angle_y/uv_mode/ | ||
| 17 | +angle_uv) is byte-exact, range-for-range, against the oracle -- and named | ||
| 18 | +`around_rect` as the next suspect, since it feeds the coefficient reads' | ||
| 19 | +`skip_ctx`/`dc_sign_ctx`. This round re-read `around_rect`/`around_mi_rect` | ||
| 20 | +(decode.rs:2094-2118) and `decode_block_rect64`'s call site | ||
| 21 | +(decode.rs:3214) against `decode_block_rect`'s own (already-working, per r5's | ||
| 22 | +"sibling working" framing) `around_rect` usage: identical shape, identical | ||
| 23 | +w/h-split gather pattern (above over the block's own width, left over its own | ||
| 24 | +height), and the u/v skip_ctx formula (`above_coded as usize + | ||
| 25 | +left_coded as usize`) is textually identical between the two functions. No | ||
| 26 | +defect found there by inspection -- consistent with what the range ladder | ||
| 27 | +below actually shows (skip_ctx and dc_sign_ctx both read correctly). | ||
| 28 | + | ||
| 29 | +## 2. Regenerated the pinned mismatch (seed 42, same recipe as r2-r6) | ||
| 30 | + | ||
| 31 | +`EC_SBPART_GATE_ATTEMPTS=1 EC_AV1_GATE_DUMP=<sp>/sbpart-r7-pin.obu | ||
| 32 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib | ||
| 33 | +a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact | ||
| 34 | +-- --nocapture`: reproduced the frame-0 luma mismatch on the first attempt, | ||
| 35 | +pinned OBU captured fresh (scratchpad only, not committed -- per | ||
| 36 | +[[oracle-in-reaped-dir]] these do not survive between sessions, re-capture | ||
| 37 | +with the same command if needed). | ||
| 38 | + | ||
| 39 | +## 3. Oracle rung 11: per-symbol coefficient range ladder | ||
| 40 | + | ||
| 41 | +Rung 3 (`EC_TRACE_COEFF`, built by a sibling lane) only bracketed a whole | ||
| 42 | +`av1_read_coeffs_txb` call -- entry/exit `rng`, nothing inside. That is | ||
| 43 | +coarse enough to prove a block diverges but not where. Added rung 11 (same | ||
| 44 | +env var, no new flag) in `scripts/instrument-aom-oracle.sh`, patching | ||
| 45 | +`read_coeffs_txb` in `decodetxb.c` to print `EC_COEFF_STEP tag=<eob| | ||
| 46 | +base_eob|after_bases|sign|post_golomb> ... rng=..` at four checkpoints: | ||
| 47 | +right after `*eob` is computed, right after the special eob-1 base/br read, | ||
| 48 | +right after the reverse-scan base/br loop for every other position, and | ||
| 49 | +right after each sign/golomb read in the final forward loop. Applied to the | ||
| 50 | +shared `~/.cache/aom-oracle` tree, `ninja -C ~/.cache/aom-oracle/build | ||
| 51 | +aomdec`: clean. | ||
| 52 | + | ||
| 53 | +Mirrored the entry/exit half on our own side: `EC_COEFF`/`EC_COEFF_VAL` | ||
| 54 | +prints (same format) at all three coefficient-read call sites in | ||
| 55 | +`decode_block_rect64` (luma `read_coeffs`, chroma U/V `read_coeffs_rect`, | ||
| 56 | +decode.rs:3214-3320), plus `rng` added to the existing `EC_AV1_TRACE` | ||
| 57 | +`eob_pt`/`eob_extra` lines in `read_eob` (decode.rs:1183,1190) for | ||
| 58 | +comparability. `read_coeffs`'s own existing per-symbol traces | ||
| 59 | +(`all_zero`/`tx_type`/`eob`/`base_eob`/`base`/`br`/`dc_sign`/`golomb`, | ||
| 60 | +decode.rs:1261-1394) already carried enough to read off VALUES; this round | ||
| 61 | +only needed the oracle side widened to carry `rng`. | ||
| 62 | + | ||
| 63 | +Ran both traces on the identical pinned OBU | ||
| 64 | +(`EC_TRACE_COEFF=1 aomdec --i420 -o /dev/null <pin>.obu`, and | ||
| 65 | +`EC_AV1_GATE_DUMP_PIN=<pin>.obu EC_TRACE_COEFF=1 EC_AV1_TRACE=1 cargo test | ||
| 66 | +--lib pinned_sbpart_stream_decodes_pixel_exact -- --ignored --nocapture`). | ||
| 67 | + | ||
| 68 | +## 4. Result: block1 exact, block2's luma coefficient read is where it starts | ||
| 69 | + | ||
| 70 | +Block1 (mi_col=16), all 3 planes, entry-to-exit rng: **byte-for-byte | ||
| 71 | +identical** between ours and the oracle (luma 36949->41600, U 41600->42128, | ||
| 72 | +V 42128->45272, all four numbers matching on both sides). Confirms r5's | ||
| 73 | +pixel-exact finding down to the entropy level, not just pixels. | ||
| 74 | + | ||
| 75 | +Block2 (mi_col=24) luma entry rng: **63764 on both sides** -- exact match, | ||
| 76 | +confirming r6's mode-info-prefix finding held all the way through the | ||
| 77 | +`skip`/`tx_depth` reads too (both zero symbols consumed identically, since | ||
| 78 | +`tx_select=false` under `--enable-tx-size-search=0`). But the luma read's | ||
| 79 | +**exit** range diverges: ours **46984**, oracle **46344**. This overturns | ||
| 80 | +r6's framing that `around_rect` (feeding only `skip_ctx`/`dc_sign_ctx`) was | ||
| 81 | +the leading suspect -- `all_zero` reads `value=0` (not skip) on both sides | ||
| 82 | +and `dc_sign` reads the same value on both sides, so those two ctx values | ||
| 83 | +were consumed correctly; the actual divergence is **inside the coefficient | ||
| 84 | +magnitude loop**, after `eob` and before `dc_sign`. | ||
| 85 | + | ||
| 86 | +Step-by-step inside block2's luma block (rung 11's checkpoints, both sides | ||
| 87 | +agree on `eob=6` and the eob-1 symbol `base_eob level=1`): | ||
| 88 | + | ||
| 89 | +``` | ||
| 90 | +scan position (row,col) ours base value oracle final level | ||
| 91 | +pos=2 (row0,col2) scan5 1 (base_eob) 1 | ||
| 92 | +pos=33 (row1,col1) scan4 1 1 | ||
| 93 | +pos=64 (row2,col0) scan3 1 1 | ||
| 94 | +pos=32 (row1,col0) scan2 3 -> br(ctx8)=0 -> 3 1 <-- FIRST DIVERGENCE | ||
| 95 | +pos=1 (row0,col1) scan1 0 ? (not individually logged | ||
| 96 | + oracle-side; our value 0 | ||
| 97 | + means no sign is read for | ||
| 98 | + it either way, consistent) | ||
| 99 | +pos=0 (row0,col0) scan0 3 -> br,br=3,0 -> 6 1 (downstream, corrupted | ||
| 100 | + by the pos=32 read | ||
| 101 | + already having | ||
| 102 | + consumed the wrong | ||
| 103 | + number/kind of bits) | ||
| 104 | +``` | ||
| 105 | + | ||
| 106 | +The oracle decodes **every** non-eob coefficient in this block at level 1 | ||
| 107 | +(no `br` read ever fires) except the skipped zero at `c=3`. Ours decodes | ||
| 108 | +`pos=32` (scan_idx=2, `row=1,col=0`) as base value **3** -- which is | ||
| 109 | +`> NUM_BASE_LEVELS`, so it additionally reads a `br` symbol the oracle never | ||
| 110 | +consumed at all, and `pos=0` (the DC, scan_idx=0) also comes out base value | ||
| 111 | +3 with a further `br,br=3,0` (final level 6) where the oracle's DC is level | ||
| 112 | +1. The DC divergence is very likely *downstream* corruption from the | ||
| 113 | +scan_idx=2 desync (once one extra symbol is read, everything after it in | ||
| 114 | +the reverse scan reads shifted bits); scan_idx=2 (`pos=32`, `row=1,col=0`) | ||
| 115 | +is the first place values differ and is the actual desync point. | ||
| 116 | + | ||
| 117 | +## Named suspect for next round | ||
| 118 | + | ||
| 119 | +The symbol at `pos=32` is read via `read_coeffs`'s reverse-scan branch | ||
| 120 | +(decode.rs:1338-1339): `let ctx = base_ctx(&levels, side, row, col, class); | ||
| 121 | +let v = dec.symbol(&mut coding.base[ctx]) as i32;` -- our trace shows | ||
| 122 | +`ctx=2` for this position. Since the entry range into the whole coefficient | ||
| 123 | +loop and every earlier symbol (`eob`, `base_eob` at scan_idx 5/4/3`) all | ||
| 124 | +matched the oracle exactly, the *decoder state* (msac range/value, CDF | ||
| 125 | +adaptation counts) going into this read was identical on both sides -- so a | ||
| 126 | +different decoded symbol value here can only come from a different **CDF | ||
| 127 | +row** being read (wrong `ctx` from `base_ctx`, or `coding.base` indexed | ||
| 128 | +under the wrong `TxbSet`/mode row) rather than a desync that already | ||
| 129 | +happened earlier. `base_ctx` (decode.rs, search `fn base_ctx`) computes the | ||
| 130 | +2D neighbour-magnitude context per spec `get_lower_levels_ctx` | ||
| 131 | +(`Mag_Ref_Offset_With_Tx_Class`-style neighbour sum) -- next round should | ||
| 132 | +hand-check `base_ctx`'s neighbour offsets and clamping for exactly | ||
| 133 | +`(row=1, col=0)` in a 32-wide 2D-class scan against libaom's | ||
| 134 | +`get_lower_levels_ctx` (`av1/common/txb_common.h`), and cross-check that | ||
| 135 | +`coding.base` (the `cdfs.txb(TxbSet::Luma64, mode).base` table) is the same | ||
| 136 | +CDF the oracle's `ec_ctx->coeff_base_cdf[txs_ctx][plane_type]` resolves to | ||
| 137 | +for `txs_ctx = get_txsize_entropy_ctx(TX_32X64)` -- **this round did not | ||
| 138 | +check** whether `TxbSet::Luma64`'s `txs_ctx` mapping matches libaom's for a | ||
| 139 | +true `TX_32X64` (as opposed to a square `TX_64X64`); a mismatched `txs_ctx` | ||
| 140 | +would select a differently-adapted CDF row even at the same numeric `ctx` | ||
| 141 | +index and is a strong alternate explanation for a value divergence with no | ||
| 142 | +range mismatch beforehand. | ||
| 143 | + | ||
| 144 | +## What was committed (58a0d59) | ||
| 145 | + | ||
| 146 | +Diagnostics only, no behavior change to the live gate (byte-identical | ||
| 147 | +before/after this round's diffs to the gate's own logic; only tracing | ||
| 148 | +statements added). `cargo check -p ec-av1 --tests`: clean. Oracle rung 11 | ||
| 149 | +applied to the shared `~/.cache/aom-oracle` tree and captured in | ||
| 150 | +`scripts/instrument-aom-oracle.sh` (env-gated, idempotent, reproduces from a | ||
| 151 | +fresh clone) per the charter's "never a throwaway patch left in the tree" | ||
| 152 | +rule. | ||
| 153 | + | ||
| 154 | +## Not attempted this round | ||
| 155 | + | ||
| 156 | +- No fix landed; `sb_rect_hits() > 0` remains unproven (gate still red, | ||
| 157 | + unchanged from r6). | ||
| 158 | +- Did not check `get_txsize_entropy_ctx`'s treatment of `TX_32X64` vs | ||
| 159 | + `TX_64X64` for CDF-set selection purposes (named above as the sharper | ||
| 160 | + alternate suspect to `base_ctx`'s neighbour math) -- ran out of budget | ||
| 161 | + before opening `cdf_state.rs`'s `txb`/`TxbSet::Luma64` resolution path. | ||
| 162 | +- Did not extend rung 11 to chroma (`read_coeffs_rect`, untraced per-symbol | ||
| 163 | + on our side -- only entry/exit) since luma is where entry/exit already | ||
| 164 | + proved the divergence lives; chroma U/V exit ranges were not compared this | ||
| 165 | + round (moot until luma is fixed, since bits already shifted downstream). | ||
| 166 | + | ||
| 167 | +## Hard rules followed | ||
| 168 | + | ||
| 169 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 170 | +every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1` | ||
| 171 | +on the aomenc-driven capture; aomenc recipe unchanged (`--threads=1 | ||
| 172 | +--row-mt=0 --sb-size=64 --enable-tx-size-search=0`, inherited); oracle rung | ||
| 173 | +is env-gated (`EC_TRACE_COEFF`, no new flag), captured in | ||
| 174 | +`scripts/instrument-aom-oracle.sh` not left as a standalone patch; no other | ||
| 175 | +worktree touched; no push, no merge into main; killed a background | ||
| 176 | +`cargo test` full-suite run started by mistake (unscoped `stream::tests::`) | ||
| 177 | +before it could pile up, per turn-cap discipline. | ||
| 178 | + | ||
| 179 | +## Next round, in order | ||
| 180 | + | ||
| 181 | +1. Check `get_txsize_entropy_ctx(TX_32X64)` vs our `TxbSet::Luma64`'s own | ||
| 182 | + `txs_ctx`/CDF-set resolution (`cdf_state.rs`, search `Luma64`) against | ||
| 183 | + libaom's `av1/common/txb_common.h` `get_txsize_entropy_ctx` -- rule in or | ||
| 184 | + out before touching `base_ctx`'s neighbour math, since a wrong CDF-set | ||
| 185 | + selection produces exactly this symptom (same range in, different value | ||
| 186 | + out, no earlier range mismatch). | ||
| 187 | +2. If that's clean, hand-check `base_ctx` (decode.rs) at `(row=1, col=0)` | ||
| 188 | + for a 32-wide `TxClass::TwoD` scan against libaom's | ||
| 189 | + `get_lower_levels_ctx` -- the neighbour offset table/clamping is the | ||
| 190 | + remaining suspect. | ||
| 191 | +3. Fix, then re-run the full `n_attempts=40` gate and confirm | ||
| 192 | + `sb_rect_hits() > 0` stays a hard pass. | ||
lanes/sbpart-r8.charter.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-sbpart r8 — one symbol away | ||
| 2 | + | ||
| 3 | +At 376a086 (I merged main for you). Read `lanes/sbpart-r7.report.md`. | ||
| 4 | + | ||
| 5 | +r7 range-laddered block2's luma coefficient read against a real aomdec and got | ||
| 6 | +the defect down to a single symbol: **entry range, `eob` and `base_eob` all | ||
| 7 | +match the oracle exactly; the first divergence is the `base` symbol at scan | ||
| 8 | +position (row=1, col=0), pos=32** — we decode 3 (triggering an extra `br` read), | ||
| 9 | +libaom decodes level 1. Same entry state on both sides, different value out. | ||
| 10 | +That shape points at a CDF-row selection, not at neighbour arithmetic. | ||
| 11 | + | ||
| 12 | +## Order | ||
| 13 | +1. **First move, named by r7:** check whether `TxbSet::Luma64`'s CDF-set / | ||
| 14 | + `txs_ctx` resolution matches libaom's `get_txsize_entropy_ctx(TX_32X64)` | ||
| 15 | + (`cdf_state.rs`, search `Luma64`). A wrong CDF-set produces exactly this | ||
| 16 | + symptom. Related class: a table narrowed to a pinned row breaks the moment | ||
| 17 | + the indexing field moves ([[cdf-row-held-constant]]). | ||
| 18 | +2. Only if that matches: `base_ctx`'s neighbour math at (row=1, col=0) for a | ||
| 19 | + true `TX_32X64`. Remember that a scan weight or step can use the CROSS axis | ||
| 20 | + and that square candidates hide every axis swap | ||
| 21 | + ([[scan-weights-cross-axis]]) — if you touch it, sweep the transposed copy in | ||
| 22 | + the same round. | ||
| 23 | +3. Fix, get the gate pixel-exact, commit. Then the round is done; do not start | ||
| 24 | + stage 2 (the 32x32 `part32` values) or the inter path. | ||
| 25 | + | ||
| 26 | +Ruled out and not to be revisited: `around_rect` (skip_ctx and dc_sign_ctx both | ||
| 27 | +read identically to the oracle), the CDEF per-SB guard, and — from r5 — the | ||
| 28 | +theory that this is a reconstruction bug at all. | ||
| 29 | + | ||
| 30 | +Reproduction, from r7: the pinned OBU is scratchpad-only and does not survive; | ||
| 31 | +regenerate with | ||
| 32 | +`EC_SBPART_GATE_ATTEMPTS=1 EC_AV1_GATE_DUMP=<path> EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact -- --nocapture` | ||
| 33 | +(seed 42 reproduces first try). Oracle rung 11 is live in `~/.cache/aom-oracle` | ||
| 34 | +and captured in `scripts/instrument-aom-oracle.sh`; drive it with | ||
| 35 | +`EC_TRACE_COEFF=1 aomdec --i420 -o /dev/null <pin>.obu`. | ||
| 36 | + | ||
| 37 | +## Budget discipline | ||
| 38 | +75 turns, no reset on resume. At about turn 55, stop starting new work: commit | ||
| 39 | +what is green and write your report. The merge is already done for you. | ||
| 40 | + | ||
| 41 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground | ||
| 42 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; | ||
| 43 | +`EC_AV1_REQUIRE_AOMENC=1`; aomenc `--threads=1 --row-mt=0 --sb-size=64` and this | ||
| 44 | +gate needs `--enable-tx-size-search=0`. The oracle is SHARED — env-gated rungs | ||
| 45 | +only. Sibling worktrees have live agents — never build in or edit them. Never | ||
| 46 | +push, never merge into main. End with `lanes/sbpart-r8.report.md`, VERDICT on | ||
| 47 | +line 1. | ||
lanes/sbpart-r8.report.mdadded+94 -0
| @@ -0,0 +1,94 @@ | |||
| 1 | +VERDICT: PASS -- fixed, gate pixel-exact, committed d64ad23 | ||
| 2 | + | ||
| 3 | +## Order 1: TxbSet::Luma64 CDF-set resolution | ||
| 4 | + | ||
| 5 | +Checked libaom `get_txsize_entropy_ctx(TX_32X64)` against `txsize_sqr_map`/ | ||
| 6 | +`txsize_sqr_up_map` (`common_data.h`): `(TX_32X32 + TX_64X64 + 1) >> 1 = | ||
| 7 | +TX_64X64`. Matches this decoder's `TxbSet::Luma64` (used for both the plain | ||
| 8 | +64x64 and the superblock-strip 32x64/64x32 corner). **CDF-set selection is | ||
| 9 | +correct** -- ruled in as clean, per the charter's own "only if that matches" | ||
| 10 | +gate to move on. | ||
| 11 | + | ||
| 12 | +## Root cause: not base_ctx's neighbour math, but its position-offset table | ||
| 13 | + | ||
| 14 | +libaom's `read_coeffs_txb` (`decodetxb.c`) passes the **raw, un-adjusted** | ||
| 15 | +`tx_size` (`TX_32X64`/`TX_64X32`, not the corner-cropped `TX_32X32`) into | ||
| 16 | +`get_scan`/`get_lower_levels_ctx`. `get_scan` resolves to the same | ||
| 17 | +`default_scan_32x32` either way (checked `scan.c`, comment: "half of the | ||
| 18 | +coefficients of tx64 at higher frequencies are set to zeros, so tx32's scan | ||
| 19 | +order is used") -- that part this decoder already had right. But | ||
| 20 | +`get_nz_map_ctx_from_stats` (`txb_common.h`) separately indexes | ||
| 21 | +`av1_nz_map_ctx_offset[tx_size][coeff_idx]` by that same raw tx_size, and | ||
| 22 | +`av1_nz_map_ctx_offset_32x64`/`_64x32` (`txb_common.c`) are **distinct | ||
| 23 | +tables** from the square `av1_nz_map_ctx_offset_32x32` one -- e.g. at | ||
| 24 | +`(row=1, col=0)` the square table gives offset 1, the 32x64 (width<height) | ||
| 25 | +table gives offset 11. This decoder's `base_ctx` always used the square | ||
| 26 | +`NZ_MAP_CTX_OFFSET_32` table, regardless of the true block shape, for every | ||
| 27 | +`read_coeffs` caller including `decode_block_rect64`'s truncated-corner | ||
| 28 | +luma read -- exactly the symptom r7 pinned (same range in, wrong symbol | ||
| 29 | +out, no earlier desync). | ||
| 30 | + | ||
| 31 | +This decoder already has the *right pattern* for this, just not wired to | ||
| 32 | +the >32 corner case: `base_ctx_rect` (lane-rectwire, used by | ||
| 33 | +`decode_block_rect`'s 32x16/16x32 strips) implements the same `w<h`/`w>h` | ||
| 34 | +branch libaom's own doc comment names. It couldn't be reused directly here | ||
| 35 | +because its `neighbour_rect` indexes the grid by the *true* `w`/`h` | ||
| 36 | +(64/32), but the truncated-corner grid is genuinely only 32x32 -- reusing it | ||
| 37 | +would break the neighbour bounds. Verified the two real libaom tables | ||
| 38 | +(`av1_nz_map_ctx_offset_32x64`/`_64x32`) reduce to the same `row.min(4)`/ | ||
| 39 | +`col.min(4)` 5x5-clamp pattern `NZ_MAP_CTX_OFFSET_32` already uses (checked | ||
| 40 | +programmatically against all 1024 entries of both tables), so added them as | ||
| 41 | +plain 5x5 consts instead of trying to force-fit `base_ctx_rect`'s neighbour | ||
| 42 | +function onto a 32-wide grid. | ||
| 43 | + | ||
| 44 | +## Fix | ||
| 45 | + | ||
| 46 | +- `cdf.rs`: added `NZ_MAP_CTX_OFFSET_32X64`/`NZ_MAP_CTX_OFFSET_64X32` | ||
| 47 | + (verified against libaom's real tables, not the approximate row/col<2 | ||
| 48 | + formula in its comment -- that formula does not actually reproduce every | ||
| 49 | + cell, e.g. `(row=0, col=2)` is 6 in the real 32x64 table, not the naive | ||
| 50 | + ctx+11 the row<2 branch alone would give). | ||
| 51 | +- `decode.rs`: `base_ctx` gained a `rect_shape: Option<(usize, usize)>` | ||
| 52 | + parameter, used only for `TxClass::TwoD` to pick the matching table | ||
| 53 | + (`w<h` -> 32x64, `w>h` -> 64x32, else/`None` -> square). Threaded through | ||
| 54 | + `read_coeffs` (`rect_shape` param, doc'd). All three `read_coeffs` | ||
| 55 | + callers updated: `decode_block_rect64`'s luma corner passes | ||
| 56 | + `Some((bw, bh))` (the real, un-adjusted strip shape); `decode_block`'s | ||
| 57 | + own 64x64 corner and the inter path pass `None` (genuinely square). | ||
| 58 | + | ||
| 59 | +## Gate result | ||
| 60 | + | ||
| 61 | +``` | ||
| 62 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ | ||
| 63 | + a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact \ | ||
| 64 | + -- --nocapture | ||
| 65 | +``` | ||
| 66 | +Before this round: 0/40 pixel-exact, mismatches on every attempt that | ||
| 67 | +reached a block2-shaped luma read. After: **15/40 pixel-exact matches, 25 | ||
| 68 | +named refusals (unrelated partition/palette/Golomb capability gaps, not this | ||
| 69 | +defect), 0 pixel mismatches, `sb_rect_hits=36`** -- hard pass. | ||
| 70 | + | ||
| 71 | +## Ruled out (per charter, not revisited) | ||
| 72 | + | ||
| 73 | +`around_rect`, the CDEF per-SB guard, the reconstruction theory. | ||
| 74 | + | ||
| 75 | +## Not attempted | ||
| 76 | + | ||
| 77 | +Stage 2 (32x32 `part32`) and the inter path, per the charter's explicit | ||
| 78 | +"do not start" instruction. The same class (offset table indexed by raw vs | ||
| 79 | +adjusted tx_size) could in principle recur wherever a >32 transform corner | ||
| 80 | +is truncated elsewhere in this codebase, but the only other truncation site | ||
| 81 | +(`decode_block`'s plain 64x64) is genuinely square, so it does not need this | ||
| 82 | +fix -- swept by inspection (both non-`decode_block_rect64` `read_coeffs` | ||
| 83 | +call sites checked and confirmed square, see above). | ||
| 84 | + | ||
| 85 | +## Hard rules followed | ||
| 86 | + | ||
| 87 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 88 | +every build; foreground `nice -n 19 cargo ... -j4`; `EC_AV1_REQUIRE_AOMENC=1` | ||
| 89 | +on the gate; aomenc recipe unchanged/inherited (`--threads=1 --row-mt=0 | ||
| 90 | +--sb-size=64 --enable-tx-size-search=0`); read-only use of the shared | ||
| 91 | +`~/.cache/aom-oracle` source tree (no rebuild, no patch left behind -- this | ||
| 92 | +round needed only to read existing libaom `.c`/`.h` source, not to | ||
| 93 | +instrument aomdec further); no other worktree touched; no push, no merge | ||
| 94 | +into main. | ||
lanes/sbpart.charter.mdadded+82 -0
| @@ -0,0 +1,82 @@ | |||
| 1 | +# lane-sbpart — superblock- and 32x32-level partition types | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-sbpart`, branch | ||
| 4 | +`lane-sbpart`, off main 53f5358. | ||
| 5 | + | ||
| 6 | +## Why this lane exists — measured, not guessed | ||
| 7 | +Five default-settings aomenc streams were run through | ||
| 8 | +`cargo run -p ec-av1 --example decode_probe -- <stream.obu>` on 2026-08-30. | ||
| 9 | +Where each stopped: | ||
| 10 | +- testsrc2 192x128 `--cpu-used=4` -> palette (Y) [lane-palette] | ||
| 11 | +- testsrc2 192x128 `--cpu-used=0` -> **a superblock-level partition type** | ||
| 12 | +- smptebars 320x240 `--cpu-used=4` -> delta_q/delta_lf [lane-realworld] | ||
| 13 | +- flat gray 128x128 `--cpu-used=4` -> **an inter superblock-level partition** | ||
| 14 | +- mandelbrot 256x192 `--cpu-used=4` -> delta_q/delta_lf [lane-realworld] | ||
| 15 | + | ||
| 16 | +Two of the five are yours, and they are the same family. Note that these | ||
| 17 | +refusals used to claim "a partition type this encoder never writes" — the | ||
| 18 | +measurement above disproved that, and main reworded them (2be815f). | ||
| 19 | + | ||
| 20 | +## The four refusals you own, verbatim | ||
| 21 | +- `"a superblock-level partition type other than NONE or SPLIT (this decoder's | ||
| 22 | + intra tile path codes only those two at 64x64)"` (decode.rs, intra tile path) | ||
| 23 | +- `"an inter SB-level partition type other than SPLIT (this decoder's inter tile | ||
| 24 | + path only recurses a superblock as SPLIT)"` (decode.rs, inter tile path) | ||
| 25 | +- `"a 32x32 partition type this decoder does not code (value={part32})"` | ||
| 26 | +- `"an INTER 32x32 partition type this decoder does not code (value={part32})"` | ||
| 27 | + | ||
| 28 | +## What is already there | ||
| 29 | +The decoder already codes rectangular partitions BELOW the superblock level — | ||
| 30 | +`decode_block_rect`, HORZ/VERT strips, HORZ_A/VERT_A/VERT_B arms, and | ||
| 31 | +rectangular inverse transforms for all 14 sizes are landed and gated. What is | ||
| 32 | +missing is the same alphabet at the 64x64 and 32x32 levels, on both the intra | ||
| 33 | +and inter tile paths. Read how the existing sub-16x16 arms do it before writing | ||
| 34 | +anything; this is mostly extending an existing recursion, not new theory. | ||
| 35 | + | ||
| 36 | +Spec 5.11.4 `decode_partition`, and libaom `av1/decoder/decodeframe.c` | ||
| 37 | +`decode_partition` — which is one function handling every level, so the | ||
| 38 | +structure you want is visible there in one place. | ||
| 39 | + | ||
| 40 | +## Staging — COMMIT AFTER EVERY GREEN STEP | ||
| 41 | +1. Intra path, 64x64: HORZ and VERT. Gate with a real | ||
| 42 | + `--cpu-used=0` stream (that is the recipe that produces them). COMMIT. | ||
| 43 | +2. Intra path, 32x32: the same, plus whatever `part32` values the gate turns up | ||
| 44 | + — the refusal prints the value, so run it and read it. COMMIT. | ||
| 45 | +3. Inter path, both levels. COMMIT. | ||
| 46 | +4. HORZ_A / HORZ_B / VERT_A / VERT_B at these levels, then HORZ_4 / VERT_4. | ||
| 47 | + COMMIT each. | ||
| 48 | + | ||
| 49 | +## Gate rules | ||
| 50 | +`EC_AV1_REQUIRE_AOMENC=1` on every run (a missing oracle must FAIL, not SKIP); | ||
| 51 | +`-t <seconds>` on every ffmpeg generate; fixtures through the existing | ||
| 52 | +`gradients_source(seed, w, h, tail)` helper (ffmpeg's `gradients` ignores its own | ||
| 53 | +seed); aomenc `--threads=1 --row-mt=0 --sb-size=64` (this decoder hardcodes 64px | ||
| 54 | +superblocks; aomenc's default 128 lands in a dead-ended gap). Firing counts are | ||
| 55 | +HARD asserts via thread-local `Cell<usize>` counters like the existing `*_HITS` | ||
| 56 | +(thread-local, NOT atomics). Main FAILS the suite if a gate turns a decode error | ||
| 57 | +into a printed SKIP — write the gate as an attempt loop that requires at least | ||
| 58 | +one decode. A gate that cannot prove its partition type fired is vacuous. | ||
| 59 | + | ||
| 60 | +## Method | ||
| 61 | +CLASS `compare-range-not-tell`: compare the msac RANGE against the oracle after | ||
| 62 | +each element, never `tell()`. Oracle at `~/.cache/aom-oracle`, rungs `EC_TRACE=1` | ||
| 63 | +(partitions — exactly your subject), `EC_TRACE_COEFF=1`, `EC_TRACE_MODE=1`, | ||
| 64 | +`EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, `EC_AV1_PREFILT_WIDE_DUMP`, | ||
| 65 | +`EC_TRACE_PALETTE=1`. Add rungs via `scripts/instrument-aom-oracle.sh` + | ||
| 66 | +`scripts/build-aom-oracle.sh` in the existing shape if you need one. | ||
| 67 | +CLASS `equal-range-means-unread`: reference range unchanged where ours moves = | ||
| 68 | +we read a symbol it never wrote; theirs moves and ours does not = we skipped one. | ||
| 69 | + | ||
| 70 | +## Hard rules | ||
| 71 | +`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart`; foreground builds | ||
| 72 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms (the suite | ||
| 73 | +runs ~3 min). Sibling worktrees (edith_codecs, -realworld, -lr, -superres, | ||
| 74 | +-tiles, -palette) have live agents — never build in or edit them, and do not | ||
| 75 | +create additional worktrees. Baseline 243 passed / 0 failed. Never push, never | ||
| 76 | +merge, never touch `main`. Refuse-by-name rather than desync, and never write a | ||
| 77 | +refusal claiming an encoder cannot emit a case — this lane exists because three | ||
| 78 | +such claims were false. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP, | ||
| 79 | +and do wide signature changes as ONE scripted sweep plus `cargo check`, not N | ||
| 80 | +hand edits — three lanes have hit the cap mid-sweep. Report every refusal string | ||
| 81 | +you remove, verbatim, for `refusal_inventory.rs`. End with | ||
| 82 | +`lanes/sbpart.report.md`, VERDICT on line 1. | ||
lanes/sbpart.report.mdadded+98 -0
| @@ -0,0 +1,98 @@ | |||
| 1 | +VERDICT: PARTIAL -- one green, inert building-block commit landed; the four | ||
| 2 | +named refusals this lane owns are all still refused. Recon-heavy round; ran | ||
| 3 | +out of turn budget before the actual decode wiring. | ||
| 4 | + | ||
| 5 | +## What landed (commit 0e04b79) | ||
| 6 | +- `crates/ec-av1/src/cdf.rs`: `EOB_PT_512_CHROMA`, the true 512-position | ||
| 7 | + end-of-block CDF for a chroma transform, extracted from libaom's | ||
| 8 | + `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`). Unlike | ||
| 9 | + every other `EOB_PT_*` table in this crate, libaom's default is the | ||
| 10 | + identical flat distribution at all four q-contexts, so this is one | ||
| 11 | + constant, no `_Q0`/`_Q1`/`_Q3` siblings. | ||
| 12 | +- `crates/ec-av1/src/cdf_state.rs`: `TxbSet::ChromaRect32x16` (+ field | ||
| 13 | + `eob_pt_512_chroma`, reset wiring, `pick()`/defaults wiring, `txb()` | ||
| 14 | + resolve arm). Shares every table `Chroma32` does except `eob_pt`. | ||
| 15 | +- `cargo check -p ec-av1`: clean. `cargo test -p ec-av1 --lib round_trip`: | ||
| 16 | + 16/16 passed (no regression). Neither is wired into any decode path yet | ||
| 17 | + (dead code, by design -- next round's first move). | ||
| 18 | + | ||
| 19 | +## The gate recipe that reproduces the SB-level refusal (verified live) | ||
| 20 | +`~/.cache/aom-oracle/build/aomenc --codec=av1 --passes=1 --end-usage=q | ||
| 21 | +--cq-level=45 --cpu-used=0 --threads=1 --row-mt=0 --sb-size=64 | ||
| 22 | +--enable-rect-partitions=1 --enable-ab-partitions=0 | ||
| 23 | +--enable-1to4-partitions=0 --min-partition-size=32 --max-partition-size=64 | ||
| 24 | +--enable-restoration=0 --enable-palette=0 --deltaq-mode=0 | ||
| 25 | +--enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 --obu` on a | ||
| 26 | +`gradients` source (192x128, blended with `testsrc2` so it isn't flat) hits | ||
| 27 | +`TRACE partition_w64 ... value=2` (VERT) and refuses by name | ||
| 28 | +("a superblock-level partition type other than NONE or SPLIT"). `min`/`max` | ||
| 29 | +-partition-size=32/64 is the key: it keeps the RD search from ever | ||
| 30 | +recursing below 32x32, so every SB-level decision is genuinely NONE/SPLIT/ | ||
| 31 | +HORZ/VERT rather than diving into unrelated 16x16/8x8 territory (which is | ||
| 32 | +what a plain default recipe hits first -- see dead ends below). | ||
| 33 | + | ||
| 34 | +## Why this took the whole budget: the spec fact this lane's "mostly | ||
| 35 | +extending an existing recursion" framing undersold | ||
| 36 | +`decode_block_rect` (the existing HORZ/VERT strip decoder, 32x16/16x32) has | ||
| 37 | +no truncation logic at all, because 32 and 16 both already fit inside the | ||
| 38 | +32-coefficient cap. A 64x32/32x64 strip does NOT fit: its LUMA plane needs | ||
| 39 | +the same corner-truncation `decode_block` already does for a plain 64x64 | ||
| 40 | +square (`logical_tx`/`coeff_tx_side` split, `read_plane`'s `tx_side != side` | ||
| 41 | +branch) -- genuinely new for a *rectangular* block, `read_plane` is | ||
| 42 | +square-only. Worked out from libaom's `get_txsize_entropy_ctx` formula | ||
| 43 | +(`(txsize_sqr_map[tx] + txsize_sqr_up_map[tx] + 1) >> 1`, | ||
| 44 | +`common_data.h:302-341`) which table each axis actually resolves to: | ||
| 45 | +- LUMA (TX_64X32/TX_32X64): sqr_map=TX_32X32, sqr_up_map=TX_64X64 -> | ||
| 46 | + ctx resolves to **TX_64X64** = the already-landed `TxbSet::Luma64` + | ||
| 47 | + `SCAN_32` (used exactly as the plain-64x64-square case already does). | ||
| 48 | + No new table needed here. | ||
| 49 | +- CHROMA (TX_32X16/TX_16X32, real untruncated transform, no corner-crop): | ||
| 50 | + sqr_map=TX_16X16, sqr_up_map=TX_32X32 -> ctx resolves to **TX_32X32** = | ||
| 51 | + `Chroma32`'s tables, except the true 512-position `eob_pt` -- this is what | ||
| 52 | + needed the new `ChromaRect32x16` variant landed this round. | ||
| 53 | + | ||
| 54 | +## What the next round needs to build (all groundwork above is done) | ||
| 55 | +1. A `decode_block_rect64(bw, bh)` (or generalize `decode_block_rect`) that: | ||
| 56 | + mode-reads via `read_intra_mode_rect` (already bw/bh-generic, unverified | ||
| 57 | + above 32x16 -- check its angle-delta/filter-intra ranges don't assume | ||
| 58 | + `bw,bh <= 32`), then for luma reads a real `32x32` corner via | ||
| 59 | + `read_coeffs` (not `_rect`) with `TxbSet::Luma64`/`SCAN_32`, embeds it | ||
| 60 | + top-left of a `bw*bh` zero grid (mirror `read_plane`'s `tx_side != side` | ||
| 61 | + branch, generalized to non-square), and `dequant_and_inverse_typed_wh` | ||
| 62 | + the whole `bw x bh` grid; for chroma reads the real `bw/2 x bh/2` corner | ||
| 63 | + via `read_coeffs_rect` with `TxbSet::ChromaRect32x16` (this round's new | ||
| 64 | + variant) and the right `SCAN_32X16`/`SCAN_16X32` table (already exist). | ||
| 65 | +2. Wire `PARTITION_HORZ`/`PARTITION_VERT` into the `match part` at | ||
| 66 | + decode.rs:5292's `_ =>` arm (intra tile path, 64x64 level) the same way | ||
| 67 | + `PARTITION_HORZ`/`VERT` are already wired at the 32x32 level just above | ||
| 68 | + (lines 5217-5283) -- two calls to the new function at `at`/`(at.0+2, | ||
| 69 | + at.1)` or `(at.0, at.1+2)` (mi units, `SUB_MI`-scaled for the 64-level). | ||
| 70 | +3. Gate it with the recipe above (`EC_AV1_REQUIRE_AOMENC=1`, attempt loop, | ||
| 71 | + hard-assert a new `SB_RECT_HITS` thread-local fired, matched > 0) | ||
| 72 | + before touching the inter path or the 32x32-level part of the charter. | ||
| 73 | +4. Only once intra HORZ/VERT is pixel-exact does stage 2 (32x32 `part32` | ||
| 74 | + values beyond NONE/SPLIT/HORZ/VERT the gate turns up), stage 3 (inter | ||
| 75 | + path, same two levels), and stage 4 (AB/4-way at these levels) become | ||
| 76 | + reachable -- none of those were attempted this round. | ||
| 77 | + | ||
| 78 | +## Refusal strings removed | ||
| 79 | +None. All four refusals this lane owns are still in place, verbatim, in | ||
| 80 | +`refusal_inventory.rs` and `decode.rs` -- no capability landed yet that | ||
| 81 | +would make any of them stop firing. | ||
| 82 | + | ||
| 83 | +## Dead ends (worth recording so the next round doesn't re-spend budget) | ||
| 84 | +- A plain default-ish recipe (`--codec=av1 --cpu-used=0 --threads=1 | ||
| 85 | + --row-mt=0 --sb-size=64` with nothing else off) hits loop restoration or | ||
| 86 | + palette or a 16x16-level AB partition first, all lanes this one doesn't | ||
| 87 | + own -- `--enable-restoration=0 --enable-palette=0 --deltaq-mode=0` plus | ||
| 88 | + `--min-partition-size=32 --max-partition-size=64` is what isolates the | ||
| 89 | + SB-level decision cleanly. | ||
| 90 | +- `testsrc2` alone at 192x128/cpu-used=0 without the min/max-partition-size | ||
| 91 | + clamp recurses straight to 8x8 leaves (too much local detail for the RD | ||
| 92 | + search to stop at 32x32) -- blended with a `gradients` source it stays | ||
| 93 | + coarse enough to resolve at 64/32. | ||
| 94 | + | ||
| 95 | +## Hard rules followed | ||
| 96 | +Worked only in this worktree; `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sbpart` | ||
| 97 | +every build; no push, no merge, no touch to `main`, no other worktree | ||
| 98 | +touched. `EC_AV1_REQUIRE_AOMENC=1` on the test run above. | ||
scripts/instrument-aom-oracle.shmodified+153 -0
| @@ -38,6 +38,16 @@ | |||
| 38 | # its superres margin (lane-superres r5: hand-tracing the arithmetic | 38 | # its superres margin (lane-superres r5: hand-tracing the arithmetic |
| 39 | # could only prove our own self-consistency, not correctness against | 39 | # could only prove our own self-consistency, not correctness against |
| 40 | # libaom). | 40 | # libaom). |
| 41 | +# EC_TRACE_MODE_STEP=1 -> per-symbol range ladder inside | ||
| 42 | +# ec_read_intra_frame_mode_info_impl (rung 5's renamed body): | ||
| 43 | +# "EC_ISTEP mi_row=.. mi_col=.. name=skip val=.. rng=.." after | ||
| 44 | +# read_skip_txfm, name=cdef/dq after read_cdef/read_delta_q_params, | ||
| 45 | +# name=mode after mbmi->mode, name=angle_y after the Y angle_delta read, | ||
| 46 | +# name=uv_mode after mbmi->uv_mode, name=angle_uv after the UV | ||
| 47 | +# angle_delta read (rung 10, lane-sbpart r6). EC_TRACE_MODE's own | ||
| 48 | +# before/after prints only bracket the WHOLE block; this is the | ||
| 49 | +# per-symbol ladder the charter asked for to localize block2's first | ||
| 50 | +# wrong read. | ||
| 41 | # Rung 9 (unconditional, no env gate) -- SGR per-tap ground truth | 51 | # Rung 9 (unconditional, no env gate) -- SGR per-tap ground truth |
| 42 | # (lane-lr r7): `calculate_intermediate_result` in | 52 | # (lane-lr r7): `calculate_intermediate_result` in |
| 43 | # av1/common/restoration.c is `static`, so a standalone harness cannot | 53 | # av1/common/restoration.c is `static`, so a standalone harness cannot |
| @@ -488,3 +498,146 @@ s = s.replace(old, new, 1) | |||
| 488 | open(path, "w").write(s) | 498 | open(path, "w").write(s) |
| 489 | print("calculate_intermediate_result exported") | 499 | print("calculate_intermediate_result exported") |
| 490 | PYA | 500 | PYA |
| 501 | + | ||
| 502 | +# --- rung 10: per-symbol range ladder inside intra key-frame mode info -- | ||
| 503 | +python3 - "$SRC/av1/decoder/decodemv.c" <<'PYS' | ||
| 504 | +import sys | ||
| 505 | +path = sys.argv[1] | ||
| 506 | +s = open(path).read() | ||
| 507 | +if "EC_INSTRUMENTED_INTRA_STEP" in s: | ||
| 508 | + print("intra mode-info per-symbol ladder already instrumented (no-op)") | ||
| 509 | + sys.exit(0) | ||
| 510 | + | ||
| 511 | +def step(name, val): | ||
| 512 | + return """ { | ||
| 513 | + const int ec_trace = getenv("EC_TRACE_MODE_STEP") != NULL; | ||
| 514 | + if (ec_trace) { | ||
| 515 | + fprintf(stderr, "EC_ISTEP mi_row=%%d mi_col=%%d name=%s val=%%d rng=%%u\\n", | ||
| 516 | + xd->mi_row, xd->mi_col, (int)(%s), (unsigned)r->ec.rng); | ||
| 517 | + } | ||
| 518 | + } | ||
| 519 | +""" % (name, val) | ||
| 520 | + | ||
| 521 | +old = " mbmi->skip_txfm = read_skip_txfm(cm, xd, mbmi->segment_id, r);\n" | ||
| 522 | +assert old in s, "read_skip_txfm call moved" | ||
| 523 | +s = s.replace(old, old + step("skip", "mbmi->skip_txfm"), 1) | ||
| 524 | + | ||
| 525 | +old = " read_cdef(cm, r, xd);\n" | ||
| 526 | +assert old in s, "read_cdef call moved" | ||
| 527 | +s = s.replace(old, old + step("cdef", "0"), 1) | ||
| 528 | + | ||
| 529 | +old = " read_delta_q_params(cm, xd, r);\n" | ||
| 530 | +assert old in s, "read_delta_q_params call moved" | ||
| 531 | +s = s.replace(old, old + step("dq", "xd->current_base_qindex"), 1) | ||
| 532 | + | ||
| 533 | +old = " mbmi->mode = read_intra_mode(r, get_y_mode_cdf(ec_ctx, above_mi, left_mi));\n" | ||
| 534 | +assert old in s, "y mode read moved" | ||
| 535 | +s = s.replace(old, old + step("mode", "mbmi->mode"), 1) | ||
| 536 | + | ||
| 537 | +old = """ mbmi->angle_delta[PLANE_TYPE_Y] = | ||
| 538 | + (use_angle_delta && av1_is_directional_mode(mbmi->mode)) | ||
| 539 | + ? read_angle_delta(r, ec_ctx->angle_delta_cdf[mbmi->mode - V_PRED]) | ||
| 540 | + : 0; | ||
| 541 | +""" | ||
| 542 | +assert old in s, "angle_delta_y block moved" | ||
| 543 | +s = s.replace(old, old + step("angle_y", "mbmi->angle_delta[PLANE_TYPE_Y]"), 1) | ||
| 544 | + | ||
| 545 | +old = """ mbmi->uv_mode = | ||
| 546 | + read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), mbmi->mode); | ||
| 547 | +""" | ||
| 548 | +assert old in s, "uv_mode read moved" | ||
| 549 | +s = s.replace(old, old + step("uv_mode", "mbmi->uv_mode"), 1) | ||
| 550 | + | ||
| 551 | +old = """ mbmi->angle_delta[PLANE_TYPE_UV] = | ||
| 552 | + (use_angle_delta && av1_is_directional_mode(intra_mode)) | ||
| 553 | + ? read_angle_delta(r, ec_ctx->angle_delta_cdf[intra_mode - V_PRED]) | ||
| 554 | + : 0; | ||
| 555 | +""" | ||
| 556 | +assert old in s, "angle_delta_uv block moved" | ||
| 557 | +s = s.replace(old, old + step("angle_uv", "mbmi->angle_delta[PLANE_TYPE_UV]"), 1) | ||
| 558 | + | ||
| 559 | +marker_old = "static int read_mv_component(aom_reader *r, nmv_component *mvcomp," | ||
| 560 | +assert marker_old in s, "anchor for EC_INSTRUMENTED_INTRA_STEP marker moved" | ||
| 561 | +s = s.replace(marker_old, "/* EC_INSTRUMENTED_INTRA_STEP */\n" + marker_old, 1) | ||
| 562 | + | ||
| 563 | +open(path, "w").write(s) | ||
| 564 | +print("intra mode-info per-symbol ladder instrumented") | ||
| 565 | +PYS | ||
| 566 | + | ||
| 567 | +# --- rung 11: per-symbol range ladder inside read_coeffs_txb (decodetxb.c) -- | ||
| 568 | +# lane-sbpart r7: rung 3's EC_TRACE_COEFF only bracketed a whole coefficient | ||
| 569 | +# block (entry/exit rng) -- too coarse to find WHICH symbol inside a Luma64 | ||
| 570 | +# corner-scan block diverges. This adds EC_COEFF_STEP tag=eob/base_eob/ | ||
| 571 | +# after_bases/sign/post_golomb lines, rng after each, under the same | ||
| 572 | +# EC_TRACE_COEFF flag (no new env var). Localized r7's own bisect to the | ||
| 573 | +# `base` symbol at scan position (row=1,col=0) inside block2's luma corner: | ||
| 574 | +# entry rng and eob/base_eob both match ours byte-for-byte, then our `base` | ||
| 575 | +# read at that position decodes value=3 (triggering an extra `br` read) | ||
| 576 | +# where the oracle's equivalent position decodes level=1 -- see | ||
| 577 | +# lanes/sbpart-r7.report.md. | ||
| 578 | +G="$SRC/av1/decoder/decodetxb.c" | ||
| 579 | +[ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; } | ||
| 580 | + | ||
| 581 | +python3 - "$G" <<'PYC11' | ||
| 582 | +import sys | ||
| 583 | +path = sys.argv[1] | ||
| 584 | +s = open(path).read() | ||
| 585 | +if "EC_COEFF_STEP" in s: | ||
| 586 | + print("decodetxb rung 11 already applied (no-op)") | ||
| 587 | + sys.exit(0) | ||
| 588 | + | ||
| 589 | +old1 = " *eob = rec_eob_pos(eob_pt, eob_extra);\n" | ||
| 590 | +new1 = old1 + """ { | ||
| 591 | + const int ec_trace2 = getenv("EC_TRACE_COEFF") != NULL; | ||
| 592 | + if (ec_trace2) { | ||
| 593 | + fprintf(stderr, "EC_COEFF_STEP tag=eob eob=%d rng=%u\\n", *eob, (unsigned)r->ec.rng); | ||
| 594 | + } | ||
| 595 | + } | ||
| 596 | +""" | ||
| 597 | +assert old1 in s, "eob assign not found" | ||
| 598 | +s = s.replace(old1, new1, 1) | ||
| 599 | + | ||
| 600 | +old2 = " levels[get_padded_idx(pos, bhl)] = level;\n }\n if (*eob > 1) {" | ||
| 601 | +new2 = """ levels[get_padded_idx(pos, bhl)] = level; | ||
| 602 | + if (getenv("EC_TRACE_COEFF") != NULL) { | ||
| 603 | + fprintf(stderr, "EC_COEFF_STEP tag=base_eob level=%d rng=%u\\n", level, (unsigned)r->ec.rng); | ||
| 604 | + } | ||
| 605 | + } | ||
| 606 | + if (*eob > 1) {""" | ||
| 607 | +assert old2 in s, "base_eob block not found" | ||
| 608 | +s = s.replace(old2, new2, 1) | ||
| 609 | + | ||
| 610 | +old3 = """ read_coeffs_reverse(r, tx_size, tx_class, 0, *eob - 1 - 1, scan, bhl, | ||
| 611 | + levels, base_cdf, br_cdf); | ||
| 612 | + } | ||
| 613 | + } | ||
| 614 | +""" | ||
| 615 | +new3 = old3 + """ if (getenv("EC_TRACE_COEFF") != NULL) { | ||
| 616 | + fprintf(stderr, "EC_COEFF_STEP tag=after_bases rng=%u\\n", (unsigned)r->ec.rng); | ||
| 617 | + } | ||
| 618 | +""" | ||
| 619 | +assert old3 in s, "after_bases site not found" | ||
| 620 | +s = s.replace(old3, new3, 1) | ||
| 621 | + | ||
| 622 | +old4 = """ if (level >= MAX_BASE_BR_RANGE) { | ||
| 623 | + level += read_golomb(xd, r); | ||
| 624 | + } | ||
| 625 | + | ||
| 626 | + if (c == 0) dc_val = sign ? -level : level;""" | ||
| 627 | +new4 = """ if (getenv("EC_TRACE_COEFF") != NULL) { | ||
| 628 | + fprintf(stderr, "EC_COEFF_STEP tag=sign c=%d sign=%d rng=%u\\n", c, sign, (unsigned)r->ec.rng); | ||
| 629 | + } | ||
| 630 | + if (level >= MAX_BASE_BR_RANGE) { | ||
| 631 | + level += read_golomb(xd, r); | ||
| 632 | + } | ||
| 633 | + if (getenv("EC_TRACE_COEFF") != NULL) { | ||
| 634 | + fprintf(stderr, "EC_COEFF_STEP tag=post_golomb c=%d level=%d rng=%u\\n", c, level, (unsigned)r->ec.rng); | ||
| 635 | + } | ||
| 636 | + | ||
| 637 | + if (c == 0) dc_val = sign ? -level : level;""" | ||
| 638 | +assert old4 in s, "sign/golomb site not found" | ||
| 639 | +s = s.replace(old4, new4, 1) | ||
| 640 | + | ||
| 641 | +open(path, "w").write(s) | ||
| 642 | +print("decodetxb rung 11 (per-symbol coeff ladder) instrumented") | ||
| 643 | +PYC11 | ||
tools/ec-bench/src/main.rsmodified+5 -3
| @@ -362,9 +362,11 @@ fn bench_av1_encode(rows: &mut Vec<Row>) { | |||
| 362 | let pic = Av1Picture { | 362 | let pic = Av1Picture { |
| 363 | width: w as usize, | 363 | width: w as usize, |
| 364 | height: h as usize, | 364 | height: h as usize, |
| 365 | - y: y.to_vec(), | 365 | + // ec-av1's Picture carries u16 samples since the high-bit-depth |
| 366 | - u: u.to_vec(), | 366 | + // widen; this bench feeds 8-bit y4m, so widen each plane here. |
| 367 | - v: v.to_vec(), | 367 | + y: y.iter().map(|&s| u16::from(s)).collect(), |
| 368 | + u: u.iter().map(|&s| u16::from(s)).collect(), | ||
| 369 | + v: v.iter().map(|&s| u16::from(s)).collect(), | ||
| 368 | }; | 370 | }; |
| 369 | let packet = enc.encode(&pic).expect("av1 encode"); | 371 | let packet = enc.encode(&pic).expect("av1 encode"); |
| 370 | stream.extend_from_slice(&packet.data); | 372 | stream.extend_from_slice(&packet.data); |