From 8cb8b42c4f8bf66db7481c4a73de3c0a007e0701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 11:00:03 +0300 Subject: [PATCH] ec-av1: lane-av1-422m -- chunk an 8x32 luma block's 4:2:2 chroma into TX_4X4 units like libaom ss_size_lookup marks that plane BLOCK_INVALID, so libaom never codes a (4, 32) unit: get_vartx_max_txsize resolves the invalid plane size to TX_4X4 and decode_reconstruct_tx never recurses for chroma, giving eight 4x4 chunks per plane. read_inter_rect_chroma now chunks that one shape (4:2:0/4:4:4 bit-identical by construction), drops the inherited tx_type (av1_get_tx_type is DCT_DCT at TX_4X4), and counts units in CHROMA422_CHUNK_HITS (decode_probe: chroma422_chunk). The header refusal stays: with the chunking the 16-frame fixture decodes past the old stop into the intra-in-inter 64x64 arm, which reads a whole (32, 64) chroma plane as one unit and trips the rect-coeff scratch bound; libaom chunks that plane to TX_32X32 units (av1_get_adjusted_tx_size). Named in lanes/av1422m.report.md for the intra 4:2:2 chroma lane. --- crates/ec-av1/examples/decode_probe.rs | 4 + crates/ec-av1/src/decode.rs | 38 +++++++++- lanes/av1422m.report.md | 101 +++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 lanes/av1422m.report.md diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 02dc104d..9f4bcf44 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -42,6 +42,10 @@ fn main() { ); println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits()); + println!( + "chroma422_chunk: {}", + ec_av1::decode::chroma422_chunk_hits() + ); let (h, v, c) = ec_av1::stream::rect4_32_counters(); println!("rect4_32: horz={h} vert={v} coded={c}"); println!( diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 91ca47f1..4a469423 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2069,6 +2069,20 @@ pub fn chroma422_sub8_hits() -> usize { CHROMA422_SUB8_HITS.with(|c| c.get()) } +// lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm +// read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block). +// A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the +// chunked 4:2:2 chroma really decoded. +thread_local! { + static CHROMA422_CHUNK_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_CHUNK_HITS`]. +pub fn chroma422_chunk_hits() -> usize { + CHROMA422_CHUNK_HITS.with(|c| c.get()) +} + // How many HORZ/VERT intra strips actually predicted with filter intra // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name // ("this decoder predicts square-only") until `predict_filter_intra` took @@ -22753,6 +22767,25 @@ fn read_inter_rect_chroma( fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32)); + // lane-av1-422m: an 8x32 luma block HAS no 4:2:2 plane residual block -- + // `av1_ss_size_lookup[BLOCK_8X32][1][0]` is BLOCK_INVALID + // (`av1/common/common_data.c:38`) -- so libaom never codes its chroma as + // a (4, 32) unit, and no such coefficient set exists (no TX_4X32 + // either). The plane is still coded, CHUNKED at luma-granular TX_4X4: + // `decode_token_recon_block` (`decodeframe.c:1022`) steps the plane in + // `get_vartx_max_txsize` units, where the `BLOCK_INVALID` plane size + // indexes `max_txsize_rect_lookup` one past its end and in the pinned + // release build reads the adjacent `vtx_tab[0]` = DCT_1D = 0 = TX_4X4; + // `decode_reconstruct_tx`'s `if (tx_size == plane_tx_size || plane)` + // never recurses for chroma, so every unit reads at TX_4X4. Chunk the + // same way: 8 units per plane over the 4x32 chroma plane. TX_4X4 units + // also never inherit a tx_type (`av1_get_tx_type` returns DCT_DCT for + // `tx_size == TX_4X4`, blockd.h), so the inherited luma type is dropped. + let invalid_ss_plane = ss_x(fctx) == 1 + && ss_y(fctx) == 0 + && (write_chroma_w, write_chroma_h) == (4, 32); + let (uw, uh) = if invalid_ss_plane { (4, 4) } else { (uw, uh) }; + let inherit_tx_type = if invalid_ss_plane { None } else { Some(luma_tx_type) }; let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); let multi = nx * ny > 1; let set = rect_inter_chroma_set(uw, uh)?; @@ -22800,10 +22833,13 @@ fn read_inter_rect_chroma( cu_x, cu_y, cu_pred, - Some(luma_tx_type), + inherit_tx_type, multi.then_some(3), fctx, )? .0; + if invalid_ss_plane { + hit!(CHROMA422_CHUNK_HITS); + } if multi { // Immediately, so the next unit of this block reads this // one's coefficient context (libaom updates the chroma diff --git a/lanes/av1422m.report.md b/lanes/av1422m.report.md new file mode 100644 index 00000000..3124c007 --- /dev/null +++ b/lanes/av1422m.report.md @@ -0,0 +1,101 @@ +# lane-av1-422m — the (4, 32) refusal is replaced by libaom's TX_4X4 chunking for +# that one shape; the header refusal STAYS (the stream's next stop is a +# different class, the intra-in-inter 64x64 chroma (32, 64) panic) + +## Outcome + +1. `read_inter_rect_chroma` no longer refuses (4, 32): an 8x32 luma block's + 4:2:2 chroma plane now codes as EIGHT TX_4X4 chunks per plane, exactly the + chunking libaom's decoder performs for a plane whose `ss_size_lookup` entry + is BLOCK_INVALID. 4:2:0 and 4:4:4 are bit-identical by construction (the + arm gates on ss (1,0) AND write rect exactly (4, 32) — impossible at any + other format). +2. The header refusal is NOT deleted: with the chunking in, the 16-frame + stream decodes PAST the previously refusing block and stops at a NEW hole + owned by another lane — the intra-in-inter 64x64 chroma arm reads its whole + (32, 64) plane as ONE unit and trips the rect-coeff scratch bound. The + delete condition (16-frame pixel-exact vs aomdec) is unmet, so the refusal + stays. + +## The chunking mechanism (measured against the pinned oracle, `~/.cache/aom-oracle/src`) + +- `av1_ss_size_lookup[BLOCK_8X32][1][0] = BLOCK_INVALID` + (`av1/common/common_data.c:38`): an 8x32 luma block HAS no 4:2:2 plane + residual block; no TX_4X32 exists either. +- `decode_token_recon_block`'s inter residual loop + (`av1/decoder/decodeframe.c:1022`) still walks the plane in + `get_vartx_max_txsize` units. `get_vartx_max_txsize` + (`av1/common/blockd.h:1447`) does `max_txsize_rect_lookup[plane_bsize]` + with `plane_bsize == BLOCK_INVALID` — one element PAST the 22-entry table. + The oracle build is Release (`CMakeCache.txt`: `CMAKE_BUILD_TYPE=Release`, + asserts compiled out), and the table's adjacent neighbour in declaration + order is `vtx_tab`, whose first entry `DCT_1D = 0 = TX_4X4`. So the + chroma max tx size resolves to TX_4X4. +- `decode_reconstruct_tx` (`decodeframe.c:303`) NEVER recurses for chroma + (`if (tx_size == plane_tx_size || plane)`), so every chroma unit reads at + TX_4X4: the 4x32 plane codes as 8 stacked 4x4 coefficient units. +- Empirical proof the chunking matches the bitstream: the same fixture bytes + (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`) + stopped at the (4, 32) refusal before the change; after it, decode consumes + that block's chroma and reaches the LATER intra-arm panic below — entropy + stayed consistent across the chunked units. + +## The fix (scoped to the one shape) + +`read_inter_rect_chroma` (`decode.rs`): when ss is (1, 0) and the write rect +is exactly (4, 32), chunk into (4, 4) units — the existing multi-unit loop +then stamps per-unit chroma neighbour contexts, embeds into the square-stride +grid, and returns the per-unit list for the tail's re-stamp, unchanged. Each +unit reads `TxbSet::Chroma4` / `default_scan(4)` (the lane-av1-422j rows) and +inherits NO tx_type (`av1_get_tx_type` returns DCT_DCT for +`tx_size == TX_4X4`, blockd.h), so `inherit_tx_type` is `None` for these +units. + +Counter `CHROMA422_CHUNK_HITS` (+ `chroma422_chunk_hits()`, printed by +`decode_probe` as `chroma422_chunk:`): one hit per TX_4X4 chunk unit read; a +4:2:0/4:4:4 frame cannot increment it. On the current fixture the probe +panics at the later stop before `report()` prints, so the number is not yet +exercised on a full decode; the units demonstrably ran (frontier evidence +above). + +## Next stop named (NOT fixed — another shape, another lane's arm) + +`decode_inter_block`'s INTRA arm (lane-av1-422k's +`read_rect_chroma_unit` call, `decode.rs`:35166/35208) codes a 64x64 intra +block's 4:2:2 chroma plane as ONE (32, 64) unit with `TxbSet::Chroma32`: + +``` +thread 'main' panicked at crates/ec-av1/src/decode.rs:7195:9: +rect coeff scratch w=32 h=64 n=2448 +``` + +libaom chunks that plane too: the intra residual walk +(`read_coeffs_and_intra`, decodeframe.c) steps `av1_get_tx_size` units, and +`av1_get_max_uv_txsize(BLOCK_64X64, 1, 0)` = +`av1_get_adjusted_tx_size(TX_32X64)` = **TX_32X32** (`blockd.h:1361`), i.e. +two 32x32 units per plane. Lifting it means re-plumbing the k lane's +whole-plane arm into a per-unit walk (set rows, per-unit `around_mi_422_chroma` +contexts, restamp) — that is the intra 4:2:2 chroma lane's territory, and the +(4, 32) inter shape this ticket owns is done. + +## Verification + +- `cargo check -p ec-av1 --all-targets` (target dir + `~/.cache/cargo-target-av1422m`): **0 warnings**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact`: 1 passed, 0 failed. +- Header refusal restored byte-identical after the probe bypass + (`stream.rs` refusal block untouched); default 4:2:2 refusal fires as + before. +- Oracle decode reference for the fixture: `$HOME/.cache/aom-oracle/build/ + aomdec` → 16 shown frames (I422 y4m). +- Untouched: the 4:2:0 group-tail chroma SKIP arm, the k lane's + `read_rect_chroma_unit` arms, `rect_inter_chroma_set`'s tables (no new row; + the (4, 32) refusal arm stays for any FUTURE unchunked arrival). + +## State + +- Commit on lane-av1-422m (no push): the chunking + counter + probe print + + this report. +- No table row added. The header refusal stands.