ec-av1: lane-av1-422m -- chunk an 8x32 luma block's 4:2:2 chroma into TX_4X4 units like libaom
Browse files at this commit8cb8b42c4f8bf66db7481c4a73de3c0a007e0701Parent: 74dab5c3 changed files +142 -1
- crates/ec-av1/examples/decode_probe.rs +4 -0
- crates/ec-av1/src/decode.rs +37 -1
- lanes/av1422m.report.md +101 -0
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
| @@ -42,6 +42,10 @@ fn main() { | |||
| 42 | ); | 42 | ); |
| 43 | println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); | 43 | println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); |
| 44 | println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits()); | 44 | println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits()); |
| 45 | + println!( | ||
| 46 | + "chroma422_chunk: {}", | ||
| 47 | + ec_av1::decode::chroma422_chunk_hits() | ||
| 48 | + ); | ||
| 45 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 49 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 46 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 50 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 47 | println!( | 51 | println!( |
crates/ec-av1/src/decode.rsmodified+37 -1
| @@ -2069,6 +2069,20 @@ pub fn chroma422_sub8_hits() -> usize { | |||
| 2069 | CHROMA422_SUB8_HITS.with(|c| c.get()) | 2069 | CHROMA422_SUB8_HITS.with(|c| c.get()) |
| 2070 | } | 2070 | } |
| 2071 | 2071 | ||
| 2072 | +// lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm | ||
| 2073 | +// read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block). | ||
| 2074 | +// A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the | ||
| 2075 | +// chunked 4:2:2 chroma really decoded. | ||
| 2076 | +thread_local! { | ||
| 2077 | + static CHROMA422_CHUNK_HITS: std::cell::Cell<usize> = | ||
| 2078 | + const { std::cell::Cell::new(0) }; | ||
| 2079 | +} | ||
| 2080 | + | ||
| 2081 | +/// Current value of [`CHROMA422_CHUNK_HITS`]. | ||
| 2082 | +pub fn chroma422_chunk_hits() -> usize { | ||
| 2083 | + CHROMA422_CHUNK_HITS.with(|c| c.get()) | ||
| 2084 | +} | ||
| 2085 | + | ||
| 2072 | // How many HORZ/VERT intra strips actually predicted with filter intra | 2086 | // How many HORZ/VERT intra strips actually predicted with filter intra |
| 2073 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name | 2087 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name |
| 2074 | // ("this decoder predicts square-only") until `predict_filter_intra` took | 2088 | // ("this decoder predicts square-only") until `predict_filter_intra` took |
| @@ -22753,6 +22767,25 @@ fn read_inter_rect_chroma( | |||
| 22753 | fctx: &crate::decode::FrameCtx, | 22767 | fctx: &crate::decode::FrameCtx, |
| 22754 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { | 22768 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { |
| 22755 | let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32)); | 22769 | let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32)); |
| 22770 | + // lane-av1-422m: an 8x32 luma block HAS no 4:2:2 plane residual block -- | ||
| 22771 | + // `av1_ss_size_lookup[BLOCK_8X32][1][0]` is BLOCK_INVALID | ||
| 22772 | + // (`av1/common/common_data.c:38`) -- so libaom never codes its chroma as | ||
| 22773 | + // a (4, 32) unit, and no such coefficient set exists (no TX_4X32 | ||
| 22774 | + // either). The plane is still coded, CHUNKED at luma-granular TX_4X4: | ||
| 22775 | + // `decode_token_recon_block` (`decodeframe.c:1022`) steps the plane in | ||
| 22776 | + // `get_vartx_max_txsize` units, where the `BLOCK_INVALID` plane size | ||
| 22777 | + // indexes `max_txsize_rect_lookup` one past its end and in the pinned | ||
| 22778 | + // release build reads the adjacent `vtx_tab[0]` = DCT_1D = 0 = TX_4X4; | ||
| 22779 | + // `decode_reconstruct_tx`'s `if (tx_size == plane_tx_size || plane)` | ||
| 22780 | + // never recurses for chroma, so every unit reads at TX_4X4. Chunk the | ||
| 22781 | + // same way: 8 units per plane over the 4x32 chroma plane. TX_4X4 units | ||
| 22782 | + // also never inherit a tx_type (`av1_get_tx_type` returns DCT_DCT for | ||
| 22783 | + // `tx_size == TX_4X4`, blockd.h), so the inherited luma type is dropped. | ||
| 22784 | + let invalid_ss_plane = ss_x(fctx) == 1 | ||
| 22785 | + && ss_y(fctx) == 0 | ||
| 22786 | + && (write_chroma_w, write_chroma_h) == (4, 32); | ||
| 22787 | + let (uw, uh) = if invalid_ss_plane { (4, 4) } else { (uw, uh) }; | ||
| 22788 | + let inherit_tx_type = if invalid_ss_plane { None } else { Some(luma_tx_type) }; | ||
| 22756 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); | 22789 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); |
| 22757 | let multi = nx * ny > 1; | 22790 | let multi = nx * ny > 1; |
| 22758 | let set = rect_inter_chroma_set(uw, uh)?; | 22791 | let set = rect_inter_chroma_set(uw, uh)?; |
| @@ -22800,10 +22833,13 @@ fn read_inter_rect_chroma( | |||
| 22800 | cu_x, | 22833 | cu_x, |
| 22801 | cu_y, | 22834 | cu_y, |
| 22802 | cu_pred, | 22835 | cu_pred, |
| 22803 | - Some(luma_tx_type), | 22836 | + inherit_tx_type, |
| 22804 | multi.then_some(3), fctx, | 22837 | multi.then_some(3), fctx, |
| 22805 | )? | 22838 | )? |
| 22806 | .0; | 22839 | .0; |
| 22840 | + if invalid_ss_plane { | ||
| 22841 | + hit!(CHROMA422_CHUNK_HITS); | ||
| 22842 | + } | ||
| 22807 | if multi { | 22843 | if multi { |
| 22808 | // Immediately, so the next unit of this block reads this | 22844 | // Immediately, so the next unit of this block reads this |
| 22809 | // one's coefficient context (libaom updates the chroma | 22845 | // one's coefficient context (libaom updates the chroma |
lanes/av1422m.report.mdadded+101 -0
| @@ -0,0 +1,101 @@ | |||
| 1 | +# lane-av1-422m — the (4, 32) refusal is replaced by libaom's TX_4X4 chunking for | ||
| 2 | +# that one shape; the header refusal STAYS (the stream's next stop is a | ||
| 3 | +# different class, the intra-in-inter 64x64 chroma (32, 64) panic) | ||
| 4 | + | ||
| 5 | +## Outcome | ||
| 6 | + | ||
| 7 | +1. `read_inter_rect_chroma` no longer refuses (4, 32): an 8x32 luma block's | ||
| 8 | + 4:2:2 chroma plane now codes as EIGHT TX_4X4 chunks per plane, exactly the | ||
| 9 | + chunking libaom's decoder performs for a plane whose `ss_size_lookup` entry | ||
| 10 | + is BLOCK_INVALID. 4:2:0 and 4:4:4 are bit-identical by construction (the | ||
| 11 | + arm gates on ss (1,0) AND write rect exactly (4, 32) — impossible at any | ||
| 12 | + other format). | ||
| 13 | +2. The header refusal is NOT deleted: with the chunking in, the 16-frame | ||
| 14 | + stream decodes PAST the previously refusing block and stops at a NEW hole | ||
| 15 | + owned by another lane — the intra-in-inter 64x64 chroma arm reads its whole | ||
| 16 | + (32, 64) plane as ONE unit and trips the rect-coeff scratch bound. The | ||
| 17 | + delete condition (16-frame pixel-exact vs aomdec) is unmet, so the refusal | ||
| 18 | + stays. | ||
| 19 | + | ||
| 20 | +## The chunking mechanism (measured against the pinned oracle, `~/.cache/aom-oracle/src`) | ||
| 21 | + | ||
| 22 | +- `av1_ss_size_lookup[BLOCK_8X32][1][0] = BLOCK_INVALID` | ||
| 23 | + (`av1/common/common_data.c:38`): an 8x32 luma block HAS no 4:2:2 plane | ||
| 24 | + residual block; no TX_4X32 exists either. | ||
| 25 | +- `decode_token_recon_block`'s inter residual loop | ||
| 26 | + (`av1/decoder/decodeframe.c:1022`) still walks the plane in | ||
| 27 | + `get_vartx_max_txsize` units. `get_vartx_max_txsize` | ||
| 28 | + (`av1/common/blockd.h:1447`) does `max_txsize_rect_lookup[plane_bsize]` | ||
| 29 | + with `plane_bsize == BLOCK_INVALID` — one element PAST the 22-entry table. | ||
| 30 | + The oracle build is Release (`CMakeCache.txt`: `CMAKE_BUILD_TYPE=Release`, | ||
| 31 | + asserts compiled out), and the table's adjacent neighbour in declaration | ||
| 32 | + order is `vtx_tab`, whose first entry `DCT_1D = 0 = TX_4X4`. So the | ||
| 33 | + chroma max tx size resolves to TX_4X4. | ||
| 34 | +- `decode_reconstruct_tx` (`decodeframe.c:303`) NEVER recurses for chroma | ||
| 35 | + (`if (tx_size == plane_tx_size || plane)`), so every chroma unit reads at | ||
| 36 | + TX_4X4: the 4x32 plane codes as 8 stacked 4x4 coefficient units. | ||
| 37 | +- Empirical proof the chunking matches the bitstream: the same fixture bytes | ||
| 38 | + (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`) | ||
| 39 | + stopped at the (4, 32) refusal before the change; after it, decode consumes | ||
| 40 | + that block's chroma and reaches the LATER intra-arm panic below — entropy | ||
| 41 | + stayed consistent across the chunked units. | ||
| 42 | + | ||
| 43 | +## The fix (scoped to the one shape) | ||
| 44 | + | ||
| 45 | +`read_inter_rect_chroma` (`decode.rs`): when ss is (1, 0) and the write rect | ||
| 46 | +is exactly (4, 32), chunk into (4, 4) units — the existing multi-unit loop | ||
| 47 | +then stamps per-unit chroma neighbour contexts, embeds into the square-stride | ||
| 48 | +grid, and returns the per-unit list for the tail's re-stamp, unchanged. Each | ||
| 49 | +unit reads `TxbSet::Chroma4` / `default_scan(4)` (the lane-av1-422j rows) and | ||
| 50 | +inherits NO tx_type (`av1_get_tx_type` returns DCT_DCT for | ||
| 51 | +`tx_size == TX_4X4`, blockd.h), so `inherit_tx_type` is `None` for these | ||
| 52 | +units. | ||
| 53 | + | ||
| 54 | +Counter `CHROMA422_CHUNK_HITS` (+ `chroma422_chunk_hits()`, printed by | ||
| 55 | +`decode_probe` as `chroma422_chunk:`): one hit per TX_4X4 chunk unit read; a | ||
| 56 | +4:2:0/4:4:4 frame cannot increment it. On the current fixture the probe | ||
| 57 | +panics at the later stop before `report()` prints, so the number is not yet | ||
| 58 | +exercised on a full decode; the units demonstrably ran (frontier evidence | ||
| 59 | +above). | ||
| 60 | + | ||
| 61 | +## Next stop named (NOT fixed — another shape, another lane's arm) | ||
| 62 | + | ||
| 63 | +`decode_inter_block`'s INTRA arm (lane-av1-422k's | ||
| 64 | +`read_rect_chroma_unit` call, `decode.rs`:35166/35208) codes a 64x64 intra | ||
| 65 | +block's 4:2:2 chroma plane as ONE (32, 64) unit with `TxbSet::Chroma32`: | ||
| 66 | + | ||
| 67 | +``` | ||
| 68 | +thread 'main' panicked at crates/ec-av1/src/decode.rs:7195:9: | ||
| 69 | +rect coeff scratch w=32 h=64 n=2448 | ||
| 70 | +``` | ||
| 71 | + | ||
| 72 | +libaom chunks that plane too: the intra residual walk | ||
| 73 | +(`read_coeffs_and_intra`, decodeframe.c) steps `av1_get_tx_size` units, and | ||
| 74 | +`av1_get_max_uv_txsize(BLOCK_64X64, 1, 0)` = | ||
| 75 | +`av1_get_adjusted_tx_size(TX_32X64)` = **TX_32X32** (`blockd.h:1361`), i.e. | ||
| 76 | +two 32x32 units per plane. Lifting it means re-plumbing the k lane's | ||
| 77 | +whole-plane arm into a per-unit walk (set rows, per-unit `around_mi_422_chroma` | ||
| 78 | +contexts, restamp) — that is the intra 4:2:2 chroma lane's territory, and the | ||
| 79 | +(4, 32) inter shape this ticket owns is done. | ||
| 80 | + | ||
| 81 | +## Verification | ||
| 82 | + | ||
| 83 | +- `cargo check -p ec-av1 --all-targets` (target dir | ||
| 84 | + `~/.cache/cargo-target-av1422m`): **0 warnings**. | ||
| 85 | +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: | ||
| 86 | + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ | ||
| 87 | + pixel_exact`: 1 passed, 0 failed. | ||
| 88 | +- Header refusal restored byte-identical after the probe bypass | ||
| 89 | + (`stream.rs` refusal block untouched); default 4:2:2 refusal fires as | ||
| 90 | + before. | ||
| 91 | +- Oracle decode reference for the fixture: `$HOME/.cache/aom-oracle/build/ | ||
| 92 | + aomdec` → 16 shown frames (I422 y4m). | ||
| 93 | +- Untouched: the 4:2:0 group-tail chroma SKIP arm, the k lane's | ||
| 94 | + `read_rect_chroma_unit` arms, `rect_inter_chroma_set`'s tables (no new row; | ||
| 95 | + the (4, 32) refusal arm stays for any FUTURE unchunked arrival). | ||
| 96 | + | ||
| 97 | +## State | ||
| 98 | + | ||
| 99 | +- Commit on lane-av1-422m (no push): the chunking + counter + probe print + | ||
| 100 | + this report. | ||
| 101 | +- No table row added. The header refusal stands. | ||