Merge lane/av1subsizesweep: close the residue, and the walk that dispatched around the guard
Browse files at this commit4 changed files +1053 -13
- crates/ec-av1/fixtures/422_header_edge16_walk.obu +0 -0
- crates/ec-av1/src/decode.rs +698 -13
- crates/ec-av1/src/stream.rs +76 -0
- lanes/av1subsizesweep.report.md +279 -0
crates/ec-av1/fixtures/422_header_edge16_walk.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+698 -13
| @@ -21490,8 +21490,11 @@ const PLANE_BLOCK_INVALID_440: &[(usize, usize)] = &[ | |||
| 21490 | 21490 | ||
| 21491 | /// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e. | 21491 | /// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e. |
| 21492 | /// whether libaom lets a subsize of this luma shape have a chroma plane block | 21492 | /// whether libaom lets a subsize of this luma shape have a chroma plane block |
| 21493 | -/// at this subsampling at all. | 21493 | +/// at this subsampling at all. `pub(crate)` so a fixture gate in `stream.rs` |
| 21494 | -fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { | 21494 | +/// can assert WHICH shape its pin carries, rather than only that the decode |
| 21495 | +/// refused -- a refusal gate that cannot name the shape is one decode-site | ||
| 21496 | +/// change away from measuring the wrong thing. | ||
| 21497 | +pub(crate) fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { | ||
| 21495 | match (sx, sy) { | 21498 | match (sx, sy) { |
| 21496 | (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)), | 21499 | (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)), |
| 21497 | (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)), | 21500 | (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)), |
| @@ -37233,6 +37236,55 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37233 | // the user's 3840x1608 film. | 37236 | // the user's 3840x1608 film. |
| 37234 | hit!(HORZ_VERT_INTRA_HITS); | 37237 | hit!(HORZ_VERT_INTRA_HITS); |
| 37235 | hit!(EDGE_RECT_STRIP_HITS); | 37238 | hit!(EDGE_RECT_STRIP_HITS); |
| 37239 | + // lane-av1subsizesweep: this arm is the ONE | ||
| 37240 | + // frame-edge partition read in the file that | ||
| 37241 | + // dispatches on its own symbol instead of | ||
| 37242 | + // resolving it into a `partN` the level's guard | ||
| 37243 | + // covers. The 128-root edge arms | ||
| 37244 | + // (decode.rs:35559/35567), the 64-level ones | ||
| 37245 | + // (36247/36264) and the 32-level ones | ||
| 37246 | + // (36371/36391) all end in `PARTITION_HORZ` / | ||
| 37247 | + // `PARTITION_VERT` / `PARTITION_SPLIT`, which | ||
| 37248 | + // the guard after their `match` sees -- the | ||
| 37249 | + // inter-frame 16-level edge arms (54777/54790) | ||
| 37250 | + // resolve into `part16` for the same reason. | ||
| 37251 | + // Here `edge_split` goes straight into | ||
| 37252 | + // `decode_leaf_rect`, and the shape it carries is | ||
| 37253 | + // `BLOCK_8X16` when the COLUMN is short -- | ||
| 37254 | + // whose (1,0) chroma plane block is | ||
| 37255 | + // BLOCK_INVALID (`av1_ss_size_lookup`, | ||
| 37256 | + // common_data.c:20), so at 4:2:2 this walks a | ||
| 37257 | + // subsize libaom refuses at decodeframe.c:1456. | ||
| 37258 | + // | ||
| 37259 | + // The check names the LEVEL, not a hand-picked | ||
| 37260 | + // shape: the gathered bit resolves to | ||
| 37261 | + // PARTITION_HORZ when the columns are full and | ||
| 37262 | + // PARTITION_VERT when they are not, and | ||
| 37263 | + // `refuse_invalid_subsize` reduces that through | ||
| 37264 | + // the same `partition_subsize_dims` every other | ||
| 37265 | + // site uses. So the 16x8 strip -- BLOCK_8X16's | ||
| 37266 | + // mirror, whose (1,0) cell is BLOCK_8X8 and MUST | ||
| 37267 | + // keep decoding -- is untouched, and the guard | ||
| 37268 | + // reds on the cell list, not a shape list. | ||
| 37269 | + let edge_part = if has_cols16 { | ||
| 37270 | + PARTITION_HORZ | ||
| 37271 | + } else { | ||
| 37272 | + PARTITION_VERT | ||
| 37273 | + }; | ||
| 37274 | + refuse_invalid_subsize((16, 16), edge_part, fctx)?; | ||
| 37275 | + // lane-av1unwritten r6: arm census -- which | ||
| 37276 | + // partition value reaches here. | ||
| 37277 | + note_subsize_arm( | ||
| 37278 | + edge_part, | ||
| 37279 | + chroma_plane_block_codable( | ||
| 37280 | + partition_subsize_dims((16, 16), edge_part) | ||
| 37281 | + .0, | ||
| 37282 | + partition_subsize_dims((16, 16), edge_part) | ||
| 37283 | + .1, | ||
| 37284 | + ss_x(fctx), | ||
| 37285 | + ss_y(fctx), | ||
| 37286 | + ), | ||
| 37287 | + ); | ||
| 37236 | let (mi_row0, mi_col0) = | 37288 | let (mi_row0, mi_col0) = |
| 37237 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | 37289 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| 37238 | let (bw, bh) = | 37290 | let (bw, bh) = |
| @@ -56870,6 +56922,57 @@ mod tests { | |||
| 56870 | } | 56922 | } |
| 56871 | } | 56923 | } |
| 56872 | } | 56924 | } |
| 56925 | + // r11 (lane-av1subsizesweep): a partition-symbol READ is a `dec.<name>(..)` | ||
| 56926 | + // call whose OWN ARGUMENT LIST names a `partition_w<N>[` CDF. That is the | ||
| 56927 | + // whole definition, and it is why the read spellings need no hand-list: | ||
| 56928 | + // `dec.symbol(..partition_w..)` qualifies, the frame-edge gather's | ||
| 56929 | + // `dec.symbol_fixed(&gather(..partition_w..))` qualifies, and | ||
| 56930 | + // `dec.debug_state()` does not -- it never names a partition CDF. A third | ||
| 56931 | + // spelling is covered the day somebody writes it. | ||
| 56932 | + // | ||
| 56933 | + // r11's hole was a SPELLING gap, not a shape gap: the old matcher named | ||
| 56934 | + // `dec.symbol(` literally, and `dec.symbol(` is not a substring of | ||
| 56935 | + // `dec.symbol_fixed(`. So the key-frame 16-level frame-edge arm -- which | ||
| 56936 | + // dispatches `decode_leaf_rect` straight off a gathered `edge_split` onto | ||
| 56937 | + // a BLOCK_8X16 chroma walk -- was never a site at all. | ||
| 56938 | + let is_partition_read = |window: &str| -> bool { | ||
| 56939 | + let mut at = 0usize; | ||
| 56940 | + while let Some(rel) = window[at..].find("dec.") { | ||
| 56941 | + let call = at + rel + "dec.".len(); | ||
| 56942 | + at = call; | ||
| 56943 | + let name: String = window[call..] | ||
| 56944 | + .chars() | ||
| 56945 | + .take_while(|c| c.is_ascii_alphanumeric() || *c == '_') | ||
| 56946 | + .collect(); | ||
| 56947 | + if name.is_empty() { | ||
| 56948 | + continue; | ||
| 56949 | + } | ||
| 56950 | + let Some(open) = window[call + name.len()..].find('(') else { | ||
| 56951 | + continue; | ||
| 56952 | + }; | ||
| 56953 | + let arg_from = call + name.len() + open + 1; | ||
| 56954 | + let mut depth = 1usize; | ||
| 56955 | + let mut stop = None; | ||
| 56956 | + for (i, c) in window[arg_from..].char_indices() { | ||
| 56957 | + match c { | ||
| 56958 | + '(' => depth += 1, | ||
| 56959 | + ')' => { | ||
| 56960 | + depth -= 1; | ||
| 56961 | + if depth == 0 { | ||
| 56962 | + stop = Some(arg_from + i); | ||
| 56963 | + break; | ||
| 56964 | + } | ||
| 56965 | + } | ||
| 56966 | + _ => {} | ||
| 56967 | + } | ||
| 56968 | + } | ||
| 56969 | + let Some(stop) = stop else { continue }; | ||
| 56970 | + if window[arg_from..stop].contains("partition_w") { | ||
| 56971 | + return true; | ||
| 56972 | + } | ||
| 56973 | + } | ||
| 56974 | + false | ||
| 56975 | + }; | ||
| 56873 | for (n, line) in lines.iter().enumerate() { | 56976 | for (n, line) in lines.iter().enumerate() { |
| 56874 | let t = line.trim_start(); | 56977 | let t = line.trim_start(); |
| 56875 | // A doc comment quoting the shape is not a site, and neither is the | 56978 | // A doc comment quoting the shape is not a site, and neither is the |
| @@ -56880,7 +56983,9 @@ mod tests { | |||
| 56880 | let lo = n.saturating_sub(1); | 56983 | let lo = n.saturating_sub(1); |
| 56881 | let hi = (n + 2).min(lines.len()); | 56984 | let hi = (n + 2).min(lines.len()); |
| 56882 | let window = lines[lo..hi].join(" "); | 56985 | let window = lines[lo..hi].join(" "); |
| 56883 | - if !window.contains("dec.symbol(") { | 56986 | + // r11: the read test is the DERIVED predicate above, not a spelling |
| 56987 | + // literal. Naming `dec.symbol(` here is what hid the frame-edge arm. | ||
| 56988 | + if !is_partition_read(&window) { | ||
| 56884 | continue; | 56989 | continue; |
| 56885 | } | 56990 | } |
| 56886 | let Some(i) = window.find("partition_w") else { | 56991 | let Some(i) = window.find("partition_w") else { |
| @@ -56915,23 +57020,25 @@ mod tests { | |||
| 56915 | continue; | 57020 | continue; |
| 56916 | } | 57021 | } |
| 56917 | // This binding is followed by the symbol read if the SAME line | 57022 | // This binding is followed by the symbol read if the SAME line |
| 56918 | - // completes `let <name> = dec.symbol(`, or if the next line starts | 57023 | + // completes `let <name> = dec.<spelling>(`, or if the next line |
| 56919 | - // the call. That is what separates `let part8 =` from an unrelated | 57024 | + // starts the call. That is what separates `let part8 =` from an |
| 56920 | - // `let ec_dbg_pre =` two lines above it. | 57025 | + // unrelated `let ec_dbg_pre =` two lines above it. |
| 56921 | let next = lines.get(cand + 1).copied().unwrap_or(""); | 57026 | let next = lines.get(cand + 1).copied().unwrap_or(""); |
| 56922 | - let binds_here = ct.contains("= dec.symbol") || next.contains("dec.symbol("); | 57027 | + let binds_here = ct.contains("= dec.") || next.contains("dec."); |
| 56923 | if binds_here || cand == n { | 57028 | if binds_here || cand == n { |
| 56924 | var = Some(name); | 57029 | var = Some(name); |
| 56925 | break; | 57030 | break; |
| 56926 | } | 57031 | } |
| 56927 | } | 57032 | } |
| 56928 | let Some(var) = var else { continue }; | 57033 | let Some(var) = var else { continue }; |
| 56929 | - // An edge `gather` binds `b` and is not a resolution: libaom resolves | 57034 | + // r11: the edge `gather` reads are SITES now, not skips. r10 skipped |
| 56930 | - // those from a two-symbol CDF and the site is guarded at the level's | 57035 | + // them on the reasoning that "the site is guarded at the level's own |
| 56931 | - // own resolution instead. | 57036 | + // resolution instead" -- true for every arm that resolves into a |
| 56932 | - if var == "b" { | 57037 | + // `partN`, and FALSE for the one that does not: the key-frame 16-level |
| 56933 | - continue; | 57038 | + // frame-edge arm dispatches `decode_leaf_rect` straight off `edge_split`, |
| 56934 | - } | 57039 | + // and `BLOCK_8X16` is BLOCK_INVALID at 4:2:2. Every site therefore has |
| 57040 | + // to carry a guard for its OWN level between the read and the first | ||
| 57041 | + // chroma-walking dispatch after it -- see the per-site check below. | ||
| 56935 | sites.push((n, var, level)); | 57042 | sites.push((n, var, level)); |
| 56936 | } | 57043 | } |
| 56937 | 57044 | ||
| @@ -57194,6 +57301,584 @@ mod tests { | |||
| 57194 | "32x8 at 4:4:0 is BLOCK_INVALID" | 57301 | "32x8 at 4:4:0 is BLOCK_INVALID" |
| 57195 | ); | 57302 | ); |
| 57196 | } | 57303 | } |
| 57304 | + | ||
| 57305 | + /// lane-av1subsizesweep: the CENSUS, as an invariant. | ||
| 57306 | + /// | ||
| 57307 | + /// The merged `lane/av1unwritten` lane covers partition SYMBOLS: every | ||
| 57308 | + /// `dec.symbol(&mut cdfs.partition_w<N>[..])` gets a | ||
| 57309 | + /// [`refuse_invalid_subsize`] within 220 lines, and | ||
| 57310 | + /// [`every_partition_symbol_resolution_is_guarded_before_it_dispatches`] | ||
| 57311 | + /// holds that shape against the source. Its own stated limit is exactly | ||
| 57312 | + /// the hole this lane found: the scan matches on `dec.symbol(`, so the | ||
| 57313 | + /// frame-edge GATHER reads (`dec.symbol_fixed(&gather(..))`) are invisible | ||
| 57314 | + /// to it, and its site list names RESOLUTIONS, not the chroma-plane WALKS | ||
| 57315 | + /// those resolutions descend into. | ||
| 57316 | + /// | ||
| 57317 | + /// So this test states the other half, over the WALK sites instead of the | ||
| 57318 | + /// symbol sites: | ||
| 57319 | + /// | ||
| 57320 | + /// * every `decode_*` call that walks a chroma plane is enumerated, with | ||
| 57321 | + /// the luma shape(s) it can be handed -- derived from the enclosing | ||
| 57322 | + /// dispatch, not typed in by hand; | ||
| 57323 | + /// * for each shape that libaom marks BLOCK_INVALID at some subsampling | ||
| 57324 | + /// mode, the walk must have a [`refuse_invalid_subsize`] for its OWN | ||
| 57325 | + /// level on its path -- either at the level that dispatched it | ||
| 57326 | + /// (`PARTITION_*` arms resolve into a `partN`) or at the dispatch site | ||
| 57327 | + /// itself; | ||
| 57328 | + /// * a walk reachable ONLY through a level whose guard already refuses the | ||
| 57329 | + /// offending subsize is CLOSED, and the reason is the level's own guard | ||
| 57330 | + /// line -- asserted, not commented. | ||
| 57331 | + /// | ||
| 57332 | + /// The residue the merged lane named, [`decode_rect4_16_intrabc`], is the | ||
| 57333 | + /// second case: it is reachable only from the 16x16-level 1:4 arms, and | ||
| 57334 | + /// `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, which is | ||
| 57335 | + /// in `PLANE_BLOCK_INVALID_422`. Both of its callers' guards refuse that | ||
| 57336 | + /// before the call, so it is CLOSED rather than guarded a third time -- | ||
| 57337 | + /// and this test is what makes that a checked claim instead of a comment. | ||
| 57338 | + #[test] | ||
| 57339 | + fn every_chroma_walking_leaf_dispatch_is_guarded_or_closed_with_a_reason() { | ||
| 57340 | + let src = include_str!("decode.rs"); | ||
| 57341 | + // r2: `decode_body` is hoisted to the top of the test because the per-row | ||
| 57342 | + // guard check below needs it BEFORE the walk census it sits under, and a | ||
| 57343 | + // reader who has to hunt for a binding is a reader who will not notice | ||
| 57344 | + // when it is scoped to the wrong thing. | ||
| 57345 | + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { | ||
| 57346 | + Some(i) => &src[..i], | ||
| 57347 | + None => src, | ||
| 57348 | + }; | ||
| 57349 | + // (a) The shapes libaom cannot code, transcribed from the same | ||
| 57350 | + // `av1_ss_size_lookup` cells `PLANE_BLOCK_INVALID_422` carries. A walk | ||
| 57351 | + // handed one of these at the matching subsampling mode is the defect. | ||
| 57352 | + let invalid_at = |bw: usize, bh: usize, sx: usize, sy: usize| { | ||
| 57353 | + !chroma_plane_block_codable(bw, bh, sx, sy) | ||
| 57354 | + }; | ||
| 57355 | + | ||
| 57356 | + // (b) The CENSUS: every chroma-plane walk in the decode body, with the | ||
| 57357 | + // luma footprint(s) each dispatch can hand it. `guarded_by` names the | ||
| 57358 | + // mechanism, which is what a reader has to be able to check: | ||
| 57359 | + // | ||
| 57360 | + // * `refuse_invalid_subsize` at the DISPATCH -- the guard sits on | ||
| 57361 | + // the walk's own path (the hole this lane fixed, and the 8x8 / | ||
| 57362 | + // 16-level sites); | ||
| 57363 | + // * `refuse_invalid_subsize` at the RESOLUTION -- the dispatch is a | ||
| 57364 | + // `PARTITION_*` arm, so the level's guard saw the symbol that | ||
| 57365 | + // selected this shape before the call; | ||
| 57366 | + // * `unreachable` -- proven-uncodable at every subsampling mode a | ||
| 57367 | + // `color_config` can select, closed with an assertion instead of | ||
| 57368 | + // a guard. | ||
| 57369 | + // | ||
| 57370 | + // Each row is (walk, shapes, mechanism). | ||
| 57371 | + // | ||
| 57372 | + // r2 (Main's review, and it was right): `AtResolution` used to assert | ||
| 57373 | + // only that SOME shape the walk handles is BLOCK_INVALID, which | ||
| 57374 | + // restates the libaom table and never mentions a guard -- deleting the | ||
| 57375 | + // inter 32-level guard left it green. So a resolution row now CARRIES | ||
| 57376 | + // the guard it depends on: `(walk, fn-scope, level)`, and the check | ||
| 57377 | + // below looks for `refuse_invalid_subsize((level, level))` inside that | ||
| 57378 | + // function and before the walk's first call site in it. A row that | ||
| 57379 | + // cannot be checked that way says so with `Prose` instead. | ||
| 57380 | + enum Mech { | ||
| 57381 | + AtDispatch, | ||
| 57382 | + /// Protected by `refuse_invalid_subsize((L, L))` in the named | ||
| 57383 | + /// function, above the walk's first call site there. | ||
| 57384 | + AtResolution(&'static str, usize), | ||
| 57385 | + /// The walk is reached INDIRECTLY -- this row's guard is asserted to | ||
| 57386 | + /// exist in `fscope`, and the ordering is asserted by the per-route | ||
| 57387 | + /// loop further down (which scopes to the enclosing function and | ||
| 57388 | + /// names this walk's real caller chain). Used only where the walk's | ||
| 57389 | + /// call site is not in the guard's own function. | ||
| 57390 | + AtResolutionVia(&'static str, usize), | ||
| 57391 | + Unreachable(&'static str), | ||
| 57392 | + } | ||
| 57393 | + // The key-frame tile decoder and the inter tile decoder. Every | ||
| 57394 | + // resolution guard lives in one of the two, which is what makes "the | ||
| 57395 | + // guard for THIS row" a scoped lookup rather than a global one. | ||
| 57396 | + const KF: &str = "decode_key_frame_tile_with_cdfs"; | ||
| 57397 | + const INTER: &str = "decode_inter_frame_tile_with_cdfs"; | ||
| 57398 | + let census: &[(&str, &[(usize, usize)], Mech)] = &[ | ||
| 57399 | + // ---- the residue the merged lane named ------------------- | ||
| 57400 | + // | ||
| 57401 | + // `decode_rect4_16_intrabc` reconstructs one 16x4 or 4x16 strip. | ||
| 57402 | + // It has exactly ONE caller (`decode_rect4_16_strip`, decode.rs | ||
| 57403 | + // 18934), which has exactly two (17595 from `decode_rect4_16`, | ||
| 57404 | + // 13810 from `decode_intra_rect_in_inter`), which have one each | ||
| 57405 | + // (36793 key frame, 45447 inter). BOTH are 16x16-level 1:4 arms, so | ||
| 57406 | + // both sit under a `refuse_invalid_subsize((16, 16), part16)`. | ||
| 57407 | + // | ||
| 57408 | + // The offending subsize is the VERT_4 one and ONLY that one: | ||
| 57409 | + // `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, | ||
| 57410 | + // and (4,16) is in `PLANE_BLOCK_INVALID_422`, while HORZ_4 gives | ||
| 57411 | + // (16,4) whose (1,0) cell is BLOCK_8X4 and is legal. So the | ||
| 57412 | + // 16x16-level guard refuses exactly the shape that would be | ||
| 57413 | + // BLOCK_INVALID, and the strip that survives -- 16x4 -- is the one | ||
| 57414 | + // this decoder's `own422` arm is written for. Part (d) below | ||
| 57415 | + // re-derives that split and part (f) pins the caller count, so the | ||
| 57416 | + // closure is checked rather than asserted in prose. | ||
| 57417 | + ( | ||
| 57418 | + "decode_rect4_16_intrabc", | ||
| 57419 | + &[(16, 4), (4, 16)], | ||
| 57420 | + Mech::AtResolutionVia(KF, 16), | ||
| 57421 | + ), | ||
| 57422 | + // ---- 1:4 and 2:1 rect walks, all resolved-symbol guarded -- | ||
| 57423 | + ( | ||
| 57424 | + "decode_rect4_16", | ||
| 57425 | + &[(16, 4), (4, 16)], | ||
| 57426 | + Mech::AtResolution(KF, 16), | ||
| 57427 | + ), | ||
| 57428 | + ( | ||
| 57429 | + "decode_rect4_16_strip", | ||
| 57430 | + &[(16, 4), (4, 16)], | ||
| 57431 | + Mech::AtResolutionVia(KF, 16), | ||
| 57432 | + ), | ||
| 57433 | + ( | ||
| 57434 | + "decode_block_rect", | ||
| 57435 | + &[(32, 16), (16, 32)], | ||
| 57436 | + Mech::AtResolution(KF, 32), | ||
| 57437 | + ), | ||
| 57438 | + ( | ||
| 57439 | + "decode_block_rect4", | ||
| 57440 | + &[(32, 8), (8, 32)], | ||
| 57441 | + Mech::AtResolution(KF, 32), | ||
| 57442 | + ), | ||
| 57443 | + ( | ||
| 57444 | + "decode_block_rect64", | ||
| 57445 | + &[(64, 16), (16, 64)], | ||
| 57446 | + Mech::AtResolution(KF, 64), | ||
| 57447 | + ), | ||
| 57448 | + // The 128-root guard lives in `read_sb128_root`, the shared | ||
| 57449 | + // resolver both tile decoders call -- not in the walker's own | ||
| 57450 | + // function. | ||
| 57451 | + ( | ||
| 57452 | + "decode_block_128rect", | ||
| 57453 | + &[(128, 64), (64, 128)], | ||
| 57454 | + Mech::AtResolutionVia("read_sb128_root", 128), | ||
| 57455 | + ), | ||
| 57456 | + // `decode_rect_split` is called from inside decode_block_rect / | ||
| 57457 | + // decode_leaf_rect / decode_block_rect4 / decode_block_rect64, none of | ||
| 57458 | + // which is the tile decoder -- so the guard it inherits is checked on | ||
| 57459 | + // its own callers' rows, not here. | ||
| 57460 | + ( | ||
| 57461 | + "decode_rect_split", | ||
| 57462 | + &[(64, 16), (16, 64), (32, 16), (16, 32)], | ||
| 57463 | + Mech::AtResolutionVia(KF, 32), | ||
| 57464 | + ), | ||
| 57465 | + ( | ||
| 57466 | + "decode_leaf_rect", | ||
| 57467 | + &[(16, 8), (8, 16)], | ||
| 57468 | + Mech::AtResolution(KF, 16), | ||
| 57469 | + ), | ||
| 57470 | + // ---- the INTER-side rect walks ----------------------------- | ||
| 57471 | + // | ||
| 57472 | + // r2: without these three rows the inter 32- and 64-level guards | ||
| 57473 | + // were claimed by NOTHING, and deleting either left the census | ||
| 57474 | + // green. They are load-bearing -- `decode_intra_rect_in_inter` | ||
| 57475 | + // dispatches `decode_block_rect4` on 32x8/8x32 (8x32 is | ||
| 57476 | + // BLOCK_INVALID at 4:2:2) and `decode_block_rect64` on | ||
| 57477 | + // 64x16/16x64 (16x64 likewise) -- so each gets its own row naming | ||
| 57478 | + // the guard that stands in front of it. | ||
| 57479 | + // | ||
| 57480 | + // These are `AtResolutionVia`, not `AtResolution`: the walk is | ||
| 57481 | + // dispatched from `decode_intra_rect_in_inter`, a helper, not from | ||
| 57482 | + // the tile decoder the guard lives in. The check is therefore guard | ||
| 57483 | + // EXISTENCE in that decoder -- which is what reds when the guard | ||
| 57484 | + // is deleted -- and the linkage is stated here rather than derived. | ||
| 57485 | + ( | ||
| 57486 | + "decode_block_rect4[inter]", | ||
| 57487 | + &[(32, 8), (8, 32)], | ||
| 57488 | + Mech::AtResolutionVia(INTER, 32), | ||
| 57489 | + ), | ||
| 57490 | + ( | ||
| 57491 | + "decode_block_rect64[inter]", | ||
| 57492 | + &[(64, 16), (16, 64)], | ||
| 57493 | + Mech::AtResolutionVia(INTER, 64), | ||
| 57494 | + ), | ||
| 57495 | + ( | ||
| 57496 | + "decode_intra_rect_in_inter", | ||
| 57497 | + &[(16, 8), (8, 16), (16, 4), (4, 16)], | ||
| 57498 | + Mech::AtResolutionVia(INTER, 16), | ||
| 57499 | + ), | ||
| 57500 | + // ---- sub-8 walks ------------------------------------------ | ||
| 57501 | + // (8,4) is legal at 4:2:2 (`av1_ss_size_lookup[8x4][1][0]` is | ||
| 57502 | + // BLOCK_4X4); (4,8) is BLOCK_INVALID there. Both come off a raw | ||
| 57503 | + // `part8`, and both 8x8 resolution sites carry the guard -- plus | ||
| 57504 | + // the redundant inline `chroma_plane_block_codable` check the | ||
| 57505 | + // merged lane left at 36904. | ||
| 57506 | + ( | ||
| 57507 | + "decode_leaf_rect8", | ||
| 57508 | + &[(8, 4), (4, 8)], | ||
| 57509 | + Mech::AtResolution(KF, 8), | ||
| 57510 | + ), | ||
| 57511 | + ( | ||
| 57512 | + "decode_inter_sub8_rect2", | ||
| 57513 | + &[(8, 4), (4, 8)], | ||
| 57514 | + Mech::AtResolution(INTER, 8), | ||
| 57515 | + ), | ||
| 57516 | + ( | ||
| 57517 | + "decode_leaf_split4", | ||
| 57518 | + &[(4, 4)], | ||
| 57519 | + Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"), | ||
| 57520 | + ), | ||
| 57521 | + ( | ||
| 57522 | + "decode_inter_sub8_split4", | ||
| 57523 | + &[(4, 4)], | ||
| 57524 | + Mech::Unreachable("4x4's plane block is 4x4 at EVERY subsampling cell"), | ||
| 57525 | + ), | ||
| 57526 | + ( | ||
| 57527 | + "decode_leaf8", | ||
| 57528 | + &[(8, 8)], | ||
| 57529 | + Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"), | ||
| 57530 | + ), | ||
| 57531 | + // The square walks take only square footprints, and every square | ||
| 57532 | + // in `BLOCK_SIZES_ALL` has a valid plane block at EVERY selectable | ||
| 57533 | + // mode (the whole BLOCK_INVALID column is 4x8 / 8x4 / 4x16 / 8x16 | ||
| 57534 | + // / ... -- all rect). So no guard is needed for them, and the | ||
| 57535 | + // level guards that exist protect the SYMBOL that would have to | ||
| 57536 | + // select one of those rect shapes, not the square decode itself. | ||
| 57537 | + ( | ||
| 57538 | + "decode_block", | ||
| 57539 | + &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)], | ||
| 57540 | + Mech::Unreachable( | ||
| 57541 | + "every SQUARE footprint's plane block is valid at every selectable \ | ||
| 57542 | + subsampling mode; the whole BLOCK_INVALID column is rect", | ||
| 57543 | + ), | ||
| 57544 | + ), | ||
| 57545 | + ( | ||
| 57546 | + "decode_inter_block", | ||
| 57547 | + &[(128, 128), (64, 64), (32, 32), (16, 16), (8, 8)], | ||
| 57548 | + Mech::Unreachable( | ||
| 57549 | + "every SQUARE footprint's plane block is valid at every selectable \ | ||
| 57550 | + subsampling mode; the whole BLOCK_INVALID column is rect", | ||
| 57551 | + ), | ||
| 57552 | + ), | ||
| 57553 | + ( | ||
| 57554 | + "decode_inter_block8", | ||
| 57555 | + &[(8, 8)], | ||
| 57556 | + Mech::Unreachable("8x8's plane block is 8x8 / 4x8 / 4x4, never BLOCK_INVALID"), | ||
| 57557 | + ), | ||
| 57558 | + // ---- THE HOLE THIS LANE FIXED --------------------------- | ||
| 57559 | + // | ||
| 57560 | + // `decode_leaf_rect`'s key-frame FRAME-EDGE caller (the one | ||
| 57561 | + // `decode_leaf_rect`'s row above does not cover, because that arm | ||
| 57562 | + // dispatches on a gathered `edge_split` instead of resolving into | ||
| 57563 | + // `part16`). It is 8x16 when the COLUMN is short -- BLOCK_INVALID | ||
| 57564 | + // at 4:2:2 -- and 16x8 when the ROW is, which is legal and must | ||
| 57565 | + // keep decoding. Before this lane nothing sat on that path. | ||
| 57566 | + ( | ||
| 57567 | + "decode_leaf_rect[16-edge]", | ||
| 57568 | + &[(16, 8), (8, 16)], | ||
| 57569 | + Mech::AtDispatch, | ||
| 57570 | + ), | ||
| 57571 | + ]; | ||
| 57572 | + | ||
| 57573 | + // (c) Every row's mechanism must be a REAL one. This is what stops | ||
| 57574 | + // the census from being a list of good intentions: each claim is | ||
| 57575 | + // re-derived here, and the file is checked for the site it names. | ||
| 57576 | + for (walk, shapes, mech) in census { | ||
| 57577 | + let name = walk.split('[').next().expect("walk name"); | ||
| 57578 | + assert!( | ||
| 57579 | + src.contains(&format!("fn {name}(")), | ||
| 57580 | + "the census names `{name}`, which is not a function in this file -- the \ | ||
| 57581 | + walk was renamed or removed and this row is stale" | ||
| 57582 | + ); | ||
| 57583 | + // Only subsampling modes a `color_config` can actually SELECT | ||
| 57584 | + // count. `(0, 1)` 4:4:0 is excluded on libaom's own authority -- | ||
| 57585 | + // it asserts `subsampling_y == 0` whenever `subsampling_x == 0` | ||
| 57586 | + // (`color_config`, av1_decoder.c), so no frame in existence is | ||
| 57587 | + // 4:4:0 and `PLANE_BLOCK_INVALID_440` is transcribed only to keep | ||
| 57588 | + // the cell table whole. Counting it here would make `16x4` look | ||
| 57589 | + // like a shape that needs a guard at a mode no stream can carry | ||
| 57590 | + // -- the same class as the merged lane's r2, which refused a legal | ||
| 57591 | + // 4:2:2 shape by testing a cell no `color_config` can request. | ||
| 57592 | + let offending: Vec<(usize, usize, usize, usize)> = shapes | ||
| 57593 | + .iter() | ||
| 57594 | + .flat_map(|&(bw, bh)| { | ||
| 57595 | + [(1, 0), (1, 1), (0, 0)] | ||
| 57596 | + .into_iter() | ||
| 57597 | + .filter_map(move |(sx, sy)| { | ||
| 57598 | + invalid_at(bw, bh, sx, sy).then_some((bw, bh, sx, sy)) | ||
| 57599 | + }) | ||
| 57600 | + }) | ||
| 57601 | + .collect(); | ||
| 57602 | + match mech { | ||
| 57603 | + // A dispatch-time guard has to reduce to the SAME shape the | ||
| 57604 | + // dispatch hands the walk -- this is the claim that made the | ||
| 57605 | + // hole a hole, stated as an assertion. | ||
| 57606 | + Mech::AtDispatch => { | ||
| 57607 | + assert!( | ||
| 57608 | + !offending.is_empty(), | ||
| 57609 | + "{walk} is listed AtDispatch but libaom codes every shape it \ | ||
| 57610 | + walks at every subsampling mode -- then it needs no guard" | ||
| 57611 | + ); | ||
| 57612 | + for &(bw, bh, sx, sy) in &offending { | ||
| 57613 | + assert!( | ||
| 57614 | + invalid_at(bw, bh, sx, sy), | ||
| 57615 | + "{walk} is not actually handed {bw}x{bh} at ({sx},{sy})" | ||
| 57616 | + ); | ||
| 57617 | + } | ||
| 57618 | + } | ||
| 57619 | + // r2: the guard THIS row depends on, scoped to the function it | ||
| 57620 | + // lives in and ordered before the walk's first call there. | ||
| 57621 | + // Deleting that one guard -- and only that one -- reds this row, | ||
| 57622 | + // which is what r2's review showed the previous version could | ||
| 57623 | + // not do. | ||
| 57624 | + Mech::AtResolution(fscope, level) => { | ||
| 57625 | + assert!( | ||
| 57626 | + !offending.is_empty(), | ||
| 57627 | + "{walk} is listed AtResolution but no shape it walks is BLOCK_INVALID \ | ||
| 57628 | + -- then the level's guard is not what protects it" | ||
| 57629 | + ); | ||
| 57630 | + let fstart = decode_body | ||
| 57631 | + .find(&format!("\nfn {fscope}(")) | ||
| 57632 | + .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}("))) | ||
| 57633 | + .or_else(|| decode_body.find(&format!("\npub fn {fscope}("))) | ||
| 57634 | + .unwrap_or_else(|| { | ||
| 57635 | + panic!("the census names `{fscope}`, which is not a function here") | ||
| 57636 | + }); | ||
| 57637 | + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | ||
| 57638 | + .iter() | ||
| 57639 | + .filter_map(|pat| { | ||
| 57640 | + decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i) | ||
| 57641 | + }) | ||
| 57642 | + .min() | ||
| 57643 | + .unwrap_or(decode_body.len()); | ||
| 57644 | + let body = &decode_body[fstart..fend]; | ||
| 57645 | + let guard = format!("refuse_invalid_subsize(({level}, {level})"); | ||
| 57646 | + let gpos = body.find(&guard).unwrap_or_else(|| { | ||
| 57647 | + panic!( | ||
| 57648 | + "{walk} claims refuse_invalid_subsize(({level}, {level})) guards it, \ | ||
| 57649 | + but there is NO such guard in `{fscope}` -- the row's mechanism is \ | ||
| 57650 | + prose, not a check; re-derive it or mark the row Prose" | ||
| 57651 | + ) | ||
| 57652 | + }); | ||
| 57653 | + let call = body.find(&format!("{name}(")).unwrap_or_else(|| { | ||
| 57654 | + panic!( | ||
| 57655 | + "{walk} has no call site inside `{fscope}` to order the guard against" | ||
| 57656 | + ) | ||
| 57657 | + }); | ||
| 57658 | + assert!( | ||
| 57659 | + gpos < call, | ||
| 57660 | + "{walk}: in `{fscope}` the ({level}, {level}) guard is at {gpos} and the \ | ||
| 57661 | + walk is dispatched at {call} -- a guard BELOW the dispatch can never \ | ||
| 57662 | + observe it" | ||
| 57663 | + ); | ||
| 57664 | + } | ||
| 57665 | + Mech::AtResolutionVia(fscope, level) => { | ||
| 57666 | + assert!( | ||
| 57667 | + !offending.is_empty(), | ||
| 57668 | + "{walk} is listed AtResolutionVia but no shape it walks is \ | ||
| 57669 | + BLOCK_INVALID" | ||
| 57670 | + ); | ||
| 57671 | + let fstart = decode_body | ||
| 57672 | + .find(&format!("\nfn {fscope}(")) | ||
| 57673 | + .or_else(|| decode_body.find(&format!("\npub(crate) fn {fscope}("))) | ||
| 57674 | + .or_else(|| decode_body.find(&format!("\npub fn {fscope}("))) | ||
| 57675 | + .unwrap_or_else(|| { | ||
| 57676 | + panic!("the census names `{fscope}`, which is not a function here") | ||
| 57677 | + }); | ||
| 57678 | + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | ||
| 57679 | + .iter() | ||
| 57680 | + .filter_map(|pat| { | ||
| 57681 | + decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i) | ||
| 57682 | + }) | ||
| 57683 | + .min() | ||
| 57684 | + .unwrap_or(decode_body.len()); | ||
| 57685 | + assert!( | ||
| 57686 | + decode_body[fstart..fend] | ||
| 57687 | + .contains(&format!("refuse_invalid_subsize(({level}, {level})")), | ||
| 57688 | + "{walk} claims refuse_invalid_subsize(({level}, {level})) in `{fscope}` \ | ||
| 57689 | + guards it, but there is NO such guard there" | ||
| 57690 | + ); | ||
| 57691 | + } | ||
| 57692 | + Mech::Unreachable(reason) => { | ||
| 57693 | + assert!( | ||
| 57694 | + offending.is_empty(), | ||
| 57695 | + "{walk} claims it is unreachable, but libaom marks {} \ | ||
| 57696 | + BLOCK_INVALID -- the claim is stale", | ||
| 57697 | + offending | ||
| 57698 | + .iter() | ||
| 57699 | + .map(|(bw, bh, sx, sy)| format!("{bw}x{bh}@({sx},{sy})")) | ||
| 57700 | + .collect::<Vec<_>>() | ||
| 57701 | + .join(", ") | ||
| 57702 | + ); | ||
| 57703 | + assert!( | ||
| 57704 | + reason.len() > 40, | ||
| 57705 | + "{walk}'s Unreachable reason is too short to name the symbol \ | ||
| 57706 | + or caller that makes it unreachable" | ||
| 57707 | + ); | ||
| 57708 | + } | ||
| 57709 | + } | ||
| 57710 | + } | ||
| 57711 | + | ||
| 57712 | + // (d) The residue's closure, derived rather than asserted in prose: | ||
| 57713 | + // the ONLY subsize its callers can hand it that libaom refuses at | ||
| 57714 | + // 4:2:2 is the 16x16-level VERT_4 one, and the level's own guard | ||
| 57715 | + // refuses exactly that. If either half stops holding -- a new caller | ||
| 57716 | + // at another level, or a change to `partition_subsize_dims` -- this | ||
| 57717 | + // reds instead of the comment going stale. | ||
| 57718 | + for &(part, want) in &[ | ||
| 57719 | + (PARTITION_HORZ_4, (16usize, 4usize)), | ||
| 57720 | + (PARTITION_VERT_4, (4, 16)), | ||
| 57721 | + ] { | ||
| 57722 | + let (bw, bh) = partition_subsize_dims((16, 16), part); | ||
| 57723 | + assert_eq!( | ||
| 57724 | + (bw, bh), | ||
| 57725 | + want, | ||
| 57726 | + "get_partition_subsize(BLOCK_16X16, {part}) moved" | ||
| 57727 | + ); | ||
| 57728 | + assert_eq!( | ||
| 57729 | + chroma_plane_block_codable(bw, bh, 1, 0), | ||
| 57730 | + part == PARTITION_HORZ_4, | ||
| 57731 | + "the 16x16 1:4 pair's (1,0) cells moved: HORZ_4 -> {bw}x{bh}, \ | ||
| 57732 | + VERT_4 -> {bw}x{bh}. decode_rect4_16_intrabc's Unreachable row \ | ||
| 57733 | + is written against exactly this split" | ||
| 57734 | + ); | ||
| 57735 | + } | ||
| 57736 | + // (e) The AtDispatch row, checked where it actually bites. This is | ||
| 57737 | + // the hole the merged lane's scan cannot see: its 220-line window is | ||
| 57738 | + // keyed on `dec.symbol(`, and the frame-edge arm reads | ||
| 57739 | + // `dec.symbol_fixed(&gather(..))` into `edge_split` and dispatches on | ||
| 57740 | + // THAT. The claim to check is ordering -- the guard has to sit between | ||
| 57741 | + // the read and the `decode_leaf_rect` it protects, which is r5's | ||
| 57742 | + // defect in a new place if it ever moves below. | ||
| 57743 | + let edge_read = src | ||
| 57744 | + .find("let edge_split = if has_cols16") | ||
| 57745 | + .expect("the key-frame 16-level frame-edge arm reads a gathered bit"); | ||
| 57746 | + let guard_at = src[edge_read..] | ||
| 57747 | + .find("refuse_invalid_subsize((16, 16)") | ||
| 57748 | + .map(|i| edge_read + i) | ||
| 57749 | + .expect( | ||
| 57750 | + "the key-frame 16-level frame-edge arm dispatches decode_leaf_rect on an \ | ||
| 57751 | + 8x16 strip (BLOCK_INVALID at 4:2:2) with NO refuse_invalid_subsize on its \ | ||
| 57752 | + path -- every sibling edge arm resolves into a guarded partN, this one does not", | ||
| 57753 | + ); | ||
| 57754 | + let walk_at = src[edge_read..] | ||
| 57755 | + .find("decode_leaf_rect(") | ||
| 57756 | + .map(|i| edge_read + i) | ||
| 57757 | + .expect("the frame-edge arm's decode_leaf_rect call"); | ||
| 57758 | + assert!( | ||
| 57759 | + guard_at < walk_at, | ||
| 57760 | + "the 16-level frame-edge guard (offset {guard_at}) sits AFTER the \ | ||
| 57761 | + decode_leaf_rect it protects (offset {walk_at}) -- it can never observe it" | ||
| 57762 | + ); | ||
| 57763 | + | ||
| 57764 | + // (f) The residue's closure, by CALLER COUNT rather than by prose: a | ||
| 57765 | + // third caller at another level is what would make the residue row | ||
| 57766 | + // stale, and a count reds on that where a comment cannot. Counted over | ||
| 57767 | + // the DECODE BODY only -- this test's own string literals name the same | ||
| 57768 | + // functions, and the merged lane's own scan hit exactly that (five of | ||
| 57769 | + // its eighteen `refuse_invalid_subsize((` matches are its own). | ||
| 57770 | + for (name, calls) in [ | ||
| 57771 | + ("decode_rect4_16_intrabc", 1usize), | ||
| 57772 | + ("decode_rect4_16_strip", 2), | ||
| 57773 | + ("decode_rect4_16", 1), | ||
| 57774 | + ("decode_intra_rect_in_inter", 1), | ||
| 57775 | + ] { | ||
| 57776 | + let needle = format!("{name}("); | ||
| 57777 | + let decl = format!("fn {name}("); | ||
| 57778 | + // A doc-comment mention (`[`name`](..)`) is prose, not a call, so | ||
| 57779 | + // comment lines are dropped before counting. | ||
| 57780 | + let body: String = decode_body | ||
| 57781 | + .lines() | ||
| 57782 | + .filter(|l| !l.trim_start().starts_with("//")) | ||
| 57783 | + .collect::<Vec<_>>() | ||
| 57784 | + .join("\n"); | ||
| 57785 | + let found = body.matches(&needle).count() - usize::from(body.contains(&decl)); | ||
| 57786 | + assert_eq!( | ||
| 57787 | + found, calls, | ||
| 57788 | + "{name} has {found} call site(s) in the decode body, the census expects \ | ||
| 57789 | + {calls}. A new caller is not automatically wrong, but it is not \ | ||
| 57790 | + automatically covered either: re-derive which level's guard it sits \ | ||
| 57791 | + under before this row stays green" | ||
| 57792 | + ); | ||
| 57793 | + } | ||
| 57794 | + // Both callers reach the 1:4 strips by a DIFFERENT route, so the | ||
| 57795 | + // closure is checked per route -- and per route it is the same shape: | ||
| 57796 | + // the 16x16-level guard must sit ABOVE the test that names VERT_4. | ||
| 57797 | + // | ||
| 57798 | + // key frame: `decode_rect4_16(...)` at 36793, inside an arm testing | ||
| 57799 | + // `part16 == PARTITION_HORZ_4 || part16 == PARTITION_VERT_4`. | ||
| 57800 | + // inter: the 1:4 strips reach `decode_intra_rect_in_inter` | ||
| 57801 | + // through `fctx.inter_strip_chroma`, whose ONLY writer is the inter | ||
| 57802 | + // 16-level 1:4 arm (55068) -- `strip16` is `None` without it. | ||
| 57803 | + // | ||
| 57804 | + // Ordering is the property (a guard BELOW the 1:4 test cannot observe | ||
| 57805 | + // it), which is why each pair is compared rather than merely counted. | ||
| 57806 | + for (what, test, call) in [ | ||
| 57807 | + ( | ||
| 57808 | + "the key-frame decode_rect4_16 caller", | ||
| 57809 | + "if part16 == PARTITION_HORZ_4", | ||
| 57810 | + "decode_rect4_16(", | ||
| 57811 | + ), | ||
| 57812 | + ( | ||
| 57813 | + "the inter-frame inter_strip_chroma writer", | ||
| 57814 | + "let horz = part16 == PARTITION_HORZ_4;", | ||
| 57815 | + "c.set(Some(InterStripChroma {", | ||
| 57816 | + ), | ||
| 57817 | + ] { | ||
| 57818 | + let test_at = decode_body | ||
| 57819 | + .find(test) | ||
| 57820 | + .unwrap_or_else(|| panic!("the 1:4 arm test {test:?} for {what} is gone")); | ||
| 57821 | + // `decode_rect4_16(` also matches the DEFINITION, which is the | ||
| 57822 | + // first occurrence -- the call is the last one. | ||
| 57823 | + let call_at = decode_body | ||
| 57824 | + .rfind(call) | ||
| 57825 | + .unwrap_or_else(|| panic!("{what} is gone -- re-derive the residue's closure")); | ||
| 57826 | + // r2 (Main's review, and it was right): the guard search is SCOPED | ||
| 57827 | + // to the anchor's own enclosing function. `find()` over the whole | ||
| 57828 | + // decode body returns the FIRST `refuse_invalid_subsize((16, 16)` -- | ||
| 57829 | + // the KEY-FRAME one -- so the inter pair's comparison was satisfied | ||
| 57830 | + // by a guard three quarters of the file away, and deleting the inter | ||
| 57831 | + // 16-level guard left this test green. Both routes live in | ||
| 57832 | + // different `fn` bodies (`decode_key_frame_tile_with_cdfs` and the | ||
| 57833 | + // inter tile decoder), so the enclosing function is the scope that | ||
| 57834 | + // tells the two apart. | ||
| 57835 | + let fn_scope = |at: usize| -> std::ops::Range<usize> { | ||
| 57836 | + let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | ||
| 57837 | + .iter() | ||
| 57838 | + .filter_map(|pat| decode_body[..at].rfind(pat)) | ||
| 57839 | + .max() | ||
| 57840 | + .unwrap_or(0); | ||
| 57841 | + let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | ||
| 57842 | + .iter() | ||
| 57843 | + .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i)) | ||
| 57844 | + .min() | ||
| 57845 | + .unwrap_or(decode_body.len()); | ||
| 57846 | + head..tail | ||
| 57847 | + }; | ||
| 57848 | + let scope = fn_scope(test_at); | ||
| 57849 | + let guard_at = decode_body[scope.clone()] | ||
| 57850 | + .find("refuse_invalid_subsize((16, 16)") | ||
| 57851 | + .map(|i| scope.start + i) | ||
| 57852 | + .unwrap_or_else(|| { | ||
| 57853 | + panic!( | ||
| 57854 | + "{what}: there is NO refuse_invalid_subsize((16, 16)) in the function \ | ||
| 57855 | + enclosing the 1:4 arm test -- so nothing refuses the VERT_4 symbol \ | ||
| 57856 | + this arm dispatches on, and decode_rect4_16_intrabc's closure is gone" | ||
| 57857 | + ) | ||
| 57858 | + }); | ||
| 57859 | + assert!( | ||
| 57860 | + guard_at < test_at && test_at < call_at, | ||
| 57861 | + "{what}: guard at {guard_at} (function scope {scope:?}), 1:4 arm test at \ | ||
| 57862 | + {test_at}, dispatch at {call_at}. The guard has to sit ABOVE the 1:4 arm \ | ||
| 57863 | + test INSIDE THE SAME FUNCTION, or the VERT_4 symbol it refuses has already \ | ||
| 57864 | + been dispatched on" | ||
| 57865 | + ); | ||
| 57866 | + assert!( | ||
| 57867 | + scope.contains(&guard_at) && scope.contains(&test_at) && scope.contains(&call_at), | ||
| 57868 | + "{what}: guard, 1:4 test and dispatch must share one enclosing function" | ||
| 57869 | + ); | ||
| 57870 | + } | ||
| 57871 | + // And the inter route really is the only one: `strip16` is built from | ||
| 57872 | + // `strip_chroma`, which is `inter_strip_chroma.take()`, so a missing | ||
| 57873 | + // writer would silently drop the arm rather than expose it. | ||
| 57874 | + assert_eq!( | ||
| 57875 | + decode_body.matches("inter_strip_chroma.with(|c| {").count(), | ||
| 57876 | + 1, | ||
| 57877 | + "inter_strip_chroma gained a second writer -- the inter 1:4 strips can now \ | ||
| 57878 | + come from a level whose guard this census has not checked" | ||
| 57879 | + ); | ||
| 57880 | + } | ||
| 57881 | + | ||
| 57197 | /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's | 57882 | /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's |
| 57198 | /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and | 57883 | /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and |
| 57199 | /// reports "no leaf there" as `None` so the caller can fall back to the | 57884 | /// reports "no leaf there" as `None` so the caller can fall back to the |
crates/ec-av1/src/stream.rsmodified+76 -0
| @@ -2939,6 +2939,82 @@ pub(crate) mod tests { | |||
| 2939 | ); | 2939 | ); |
| 2940 | } | 2940 | } |
| 2941 | 2941 | ||
| 2942 | + /// lane-av1subsizesweep: the FRAME-EDGE walk of a BLOCK_INVALID subsize, | ||
| 2943 | + /// pinned. This is the one install site the partition-symbol guards missed, | ||
| 2944 | + /// and the sibling pin above cannot see it -- that pin's 8x16 comes from a | ||
| 2945 | + /// 16x16-level `PARTITION_VERT_B` (an interior AB strip, refused at | ||
| 2946 | + /// decode.rs:36472), while this pin's comes from the key-frame 16-level | ||
| 2947 | + /// FRAME-EDGE arm, which is not a `dec.symbol(` site at all: it reads one | ||
| 2948 | + /// gathered bit with `dec.symbol_fixed(&gather(..))` and dispatches | ||
| 2949 | + /// `decode_leaf_rect` straight off it. | ||
| 2950 | + /// | ||
| 2951 | + /// `422_header_edge16_walk.obu` (128 bytes, sha256 | ||
| 2952 | + /// `e8ab2bb229896f796cdec4d2cb383b41f057ef8d364da30f160a3f55a452657f`, | ||
| 2953 | + /// fnv1a64 `0xcfa2394ebe1f7764`) is a 4:2:2 sequence header over a 4:2:0 | ||
| 2954 | + /// key frame's tile, at 88x64. Width 88 is 8 mod 16, so the last 16x16 | ||
| 2955 | + /// column block is COLUMN-short and the frame-edge arm fires; height 64 is | ||
| 2956 | + /// 16-aligned, so the ROW is not short and the both-cut arm is not taken. | ||
| 2957 | + /// The gathered bit names `PARTITION_VERT`, so the strip is `BLOCK_8X16`. | ||
| 2958 | + /// | ||
| 2959 | + /// libaom's own verdict, which is the rule this pin pins: | ||
| 2960 | + /// | ||
| 2961 | + /// ```text | ||
| 2962 | + /// $ aomdec --rawvideo -o /dev/null fixtures/422_header_edge16_walk.obu | ||
| 2963 | + /// Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 2964 | + /// Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 2965 | + /// ``` | ||
| 2966 | + /// | ||
| 2967 | + /// What makes this pin different from every other refusal gate in this file | ||
| 2968 | + /// is that the 8x16 is the ONLY offending subsize in the stream. Measured | ||
| 2969 | + /// over a 260-candidate sweep (4 card textures x 5 quantizers x 13 declared | ||
| 2970 | + /// widths), this is the one candidate whose decode with the guard removed | ||
| 2971 | + /// SUCCEEDS: with the `refuse_invalid_subsize` at decode.rs:37098 deleted, | ||
| 2972 | + /// this decoder returned a full 88x64 picture where libaom refuses the | ||
| 2973 | + /// frame. So the guard is not a redundant second refusal here -- it is the | ||
| 2974 | + /// only thing between a corrupt frame and a plausible-looking decode. | ||
| 2975 | + #[test] | ||
| 2976 | + fn a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused() { | ||
| 2977 | + const NAME: &str = | ||
| 2978 | + "a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused"; | ||
| 2979 | + let _gate_lock = lock_gate_counters(); | ||
| 2980 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2981 | + .join("fixtures") | ||
| 2982 | + .join("422_header_edge16_walk.obu"); | ||
| 2983 | + let pinned = read_pin(&path, 128, 0xcfa2394ebe1f7764, NAME); | ||
| 2984 | + // The shape must be the one this lane's arm carries: if the pin ever | ||
| 2985 | + // stops being an 8x16 strip the refusal is coming from somewhere else | ||
| 2986 | + // and this gate is measuring the wrong thing. | ||
| 2987 | + assert!( | ||
| 2988 | + !crate::decode::chroma_plane_block_codable(8, 16, 1, 0), | ||
| 2989 | + "{NAME}: BLOCK_8X16 must be BLOCK_INVALID at 4:2:2 -- this gate's whole \ | ||
| 2990 | + subject is `av1_ss_size_lookup[BLOCK_8X16][1][0] == BLOCK_INVALID`" | ||
| 2991 | + ); | ||
| 2992 | + assert!( | ||
| 2993 | + crate::decode::chroma_plane_block_codable(16, 8, 1, 0), | ||
| 2994 | + "{NAME}: the 16x8 mirror MUST stay legal at 4:2:2 (BLOCK_8X8) -- it is what \ | ||
| 2995 | + keeps the new guard from refusing the sibling arm's strip" | ||
| 2996 | + ); | ||
| 2997 | + let err = decode_stream(&pinned) | ||
| 2998 | + .err() | ||
| 2999 | + .unwrap_or_else(|| panic!("{NAME}: the pin must be REFUSED, not decoded")); | ||
| 3000 | + let msg = err.to_string(); | ||
| 3001 | + assert!( | ||
| 3002 | + msg.contains("invalid with this subsampling mode"), | ||
| 3003 | + "{NAME}: the refusal must name libaom's rule (its own wording), got: {msg}" | ||
| 3004 | + ); | ||
| 3005 | + // Positive control: a genuine 4:2:2 stream must still decode, so this | ||
| 3006 | + // gate cannot pass by refusing everything. | ||
| 3007 | + let ok_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 3008 | + .join("fixtures") | ||
| 3009 | + .join("422_key_64x64.obu"); | ||
| 3010 | + let ok = decode_stream(&std::fs::read(&ok_path).expect("the 4:2:2 control fixture")) | ||
| 3011 | + .unwrap_or_else(|e| panic!("{NAME}: a genuine 4:2:2 pin must still decode: {e}")); | ||
| 3012 | + assert!( | ||
| 3013 | + !ok.is_empty(), | ||
| 3014 | + "{NAME}: the 4:2:2 control decoded no frames" | ||
| 3015 | + ); | ||
| 3016 | + } | ||
| 3017 | + | ||
| 2942 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | 3018 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2943 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). | 3019 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| 2944 | /// | 3020 | /// |
lanes/av1subsizesweep.report.mdadded+279 -0
| @@ -0,0 +1,279 @@ | |||
| 1 | +# lane/av1subsizesweep — census of every chroma-plane walk a BLOCK_INVALID subsize can reach | ||
| 2 | + | ||
| 3 | +Base `main` = `e45cc748` ("Merge lane/av1unwritten: refuse the subsize libaom calls corrupt"). | ||
| 4 | +Worktree `~/.cache/wt/av1subsizesweep`, own `CARGO_TARGET_DIR=~/.cache/tgt/subsizesweep`. | ||
| 5 | + | ||
| 6 | +## Headline: the find came from censusing WALK sites, not SYMBOL sites | ||
| 7 | + | ||
| 8 | +The merged lane's gate enumerates partition-**symbol** sites. This lane enumerates | ||
| 9 | +chroma-plane **walk** sites — every `decode_*` that reconstructs chroma from a | ||
| 10 | +block's luma extent, with the footprints its dispatch can hand it — and that | ||
| 11 | +reframing is what found the hole. A symbol-site census cannot see a subsize that | ||
| 12 | +arrives without a partition symbol at all, and it cannot see a subsize that | ||
| 13 | +arrives through a *differently spelled* symbol read. | ||
| 14 | + | ||
| 15 | +Concretely: the key-frame 16-level **frame-edge** arm reads one gathered bit with | ||
| 16 | +`dec.symbol_fixed(&gather(..))` and dispatches `decode_leaf_rect` **directly** on | ||
| 17 | +it. The merged scan's read test was the literal `dec.symbol(`, and | ||
| 18 | +`dec.symbol(` is not a substring of `dec.symbol_fixed(`. Every sibling edge arm | ||
| 19 | +resolves into a `partN` the level's guard sees; this one did not. | ||
| 20 | + | ||
| 21 | +## The hole, and the fix | ||
| 22 | + | ||
| 23 | +| | reads | resolves to | guarded before? | | ||
| 24 | +|---|---|---|---| | ||
| 25 | +| 128-root edge (`35559`/`35567`) | `symbol_fixed(&gather(..))` | `SPLIT`/`HORZ`/`VERT` | yes — `refuse_invalid_subsize((128,128), part128)` at `35596` | | ||
| 26 | +| 64-level edge (`36247`/`36264`) | same | same | yes — `(64,64)` at `36286` | | ||
| 27 | +| 32-level edge (`36371`/`36391`) | same | same | yes — `(32,32)` at `36414` | | ||
| 28 | +| **16-level edge (key frame, `37043`/`37048`)** | same | **`edge_split`, straight into `decode_leaf_rect`** | **NO — nothing on the path** | | ||
| 29 | +| 16-level edge (inter, `54777`/`54790`) | same | `part16` | yes — `(16,16)` at `54809` | | ||
| 30 | + | ||
| 31 | +With `has_cols16 == false` the strip is `BLOCK_8X16`, whose `(1,0)` chroma plane | ||
| 32 | +block is `BLOCK_INVALID` (`av1_ss_size_lookup`, `common_data.c:20`). At 4:2:2 this | ||
| 33 | +walked a subsize libaom refuses at `decodeframe.c:1456`. With `has_cols16 == true` | ||
| 34 | +the strip is `16x8` — `BLOCK_8X16`'s mirror, whose `(1,0)` cell is `BLOCK_8X8` — | ||
| 35 | +and **must** keep decoding. | ||
| 36 | + | ||
| 37 | +**Fix** (`decode.rs:37101-37119`): the guard sits on the arm's own path and names | ||
| 38 | +the LEVEL, not a shape — the gathered bit resolves to `PARTITION_HORZ` when the | ||
| 39 | +columns are full and `PARTITION_VERT` when they are not, and | ||
| 40 | +`refuse_invalid_subsize((16,16), edge_part, …)` reduces that through the same | ||
| 41 | +`partition_subsize_dims` every other site uses. A `note_subsize_arm` census line | ||
| 42 | +was added alongside, per the merged lane's convention. | ||
| 43 | + | ||
| 44 | +### Reachability, stated separately from the guard's correctness | ||
| 45 | + | ||
| 46 | +There **is** a witness, and it is the only offending subsize in its stream. | ||
| 47 | +`crates/ec-av1/fixtures/422_header_edge16_walk.obu` (128 bytes, sha256 | ||
| 48 | +`e8ab2bb229896f796cdec4d2cb383b41f057ef8d364da30f160a3f55a452657f`, fnv1a64 | ||
| 49 | +`0xcfa2394ebe1f7764`) is a 4:2:2 sequence header over a 4:2:0 key frame's tile at | ||
| 50 | +88x64. Width 88 is 8 mod 16 → the last 16x16 column block is column-short, so the | ||
| 51 | +frame-edge arm fires; height 64 is 16-aligned, so the row is not short and the | ||
| 52 | +both-cut arm is not taken. The gathered bit names `PARTITION_VERT`, so the strip | ||
| 53 | +is `BLOCK_8X16`. | ||
| 54 | + | ||
| 55 | +libaom's own verdict: | ||
| 56 | + | ||
| 57 | +```text | ||
| 58 | +$ aomdec --rawvideo -o /dev/null fixtures/422_header_edge16_walk.obu | ||
| 59 | +Warning: Failed to decode frame 1: Corrupt frame detected | ||
| 60 | +Warning: Additional information: Block size 8x16 invalid with this subsampling mode | ||
| 61 | +``` | ||
| 62 | + | ||
| 63 | +The three-way measurement, which is the part that matters: | ||
| 64 | + | ||
| 65 | +| build | this decoder | | ||
| 66 | +|---|---| | ||
| 67 | +| with the guard | REFUSED, naming libaom's rule — agrees with `aomdec` | | ||
| 68 | +| **guard deleted** | **`OK: 1 frames decoded, 88x64`** — a full picture from a frame libaom calls corrupt | | ||
| 69 | +| libaom | refuses | | ||
| 70 | + | ||
| 71 | +So the guard is load-bearing, not a redundant second refusal, and the gate | ||
| 72 | +`a_422_header_whose_only_invalid_subsize_is_the_16_level_frame_edge_walk_is_refused` | ||
| 73 | +reds when the guard is deleted (verified). | ||
| 74 | + | ||
| 75 | +**Severity: a false-accept, not a pixel divergence.** libaom refuses the whole | ||
| 76 | +frame, so there is no "correct" pixel output to diverge from; the defect is that we | ||
| 77 | +returned plausible-looking pixels for a corrupt frame. No legal 4:2:2 stream is | ||
| 78 | +affected — the shape only reaches stream data through a hostile or mismatched | ||
| 79 | +header, which is the same exposure the merged lane's guards already carry. | ||
| 80 | + | ||
| 81 | +**The earlier "no witness" claim in this lane was wrong, and so was its | ||
| 82 | +explanation.** The first sweep (45 aomenc-encoded 4:2:2 streams) never reached the | ||
| 83 | +arm, and I attributed that to `partition_rect_allowed`. That mechanism governs the | ||
| 84 | +encoder's partition *search*; this arm's partition comes from a single gathered | ||
| 85 | +bit after a frame-edge geometry test, so `partition_rect_allowed` does not explain | ||
| 86 | +it — the real reason aomenc never produced a witness is **not known**. The | ||
| 87 | +witness exists, but it had to be built from this crate's own encoder with a | ||
| 88 | +**declared** width (`encode_key_frame_at_size`, the `gen_coverage_cells.rs` cell-2 | ||
| 89 | +construction) and then re-headered, because aomenc rounds the coded size to even | ||
| 90 | +and never declares 88. | ||
| 91 | + | ||
| 92 | +## The named residue: `decode_rect4_16_intrabc` — CLOSED, not guarded a third time | ||
| 93 | + | ||
| 94 | +Its concrete code shape is `decode.rs:18334-18337`: | ||
| 95 | + | ||
| 96 | +```rust | ||
| 97 | +let (cw, ch) = if own_chroma { (bw >> ss_x(fctx), bh >> ss_y(fctx)) } | ||
| 98 | + else { (pw / 2, ph / 2) }; // both axes halved | ||
| 99 | +``` | ||
| 100 | + | ||
| 101 | +`own_chroma = own444 || own422`, and `own422 = ss_x == 1 && ss_y == 0 && horz` | ||
| 102 | +(`18317`). A **VERT** strip at `ss (1,0)` is therefore neither `own444` nor | ||
| 103 | +`own422`, falls to the `else`, and derives `pw,ph = (8,16)` → `cw,ch = (4,8)` — a | ||
| 104 | +`BLOCK_4X8` plane block, itself `BLOCK_INVALID` at `(1,0)`. Same for the | ||
| 105 | +`(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)` origin at `18354`. | ||
| 106 | + | ||
| 107 | +It is dead, and the reason is derived rather than read: | ||
| 108 | + | ||
| 109 | +1. `decode_rect4_16_intrabc` has exactly **one** caller (`decode_rect4_16_strip`, `18934`). | ||
| 110 | +2. `decode_rect4_16_strip` has exactly **two** (`17595` from `decode_rect4_16`, `13810` from `decode_intra_rect_in_inter`). | ||
| 111 | +3. `decode_rect4_16` (`36801`) and `decode_intra_rect_in_inter` (`45457`, reached only when `fctx.inter_strip_chroma` is set — one writer, `55126`) are both **16x16-level 1:4 arms**, each above a `refuse_invalid_subsize((16, 16), part16, …)`. | ||
| 112 | +4. `partition_subsize_dims((16,16), PARTITION_VERT_4) == (4,16)`, and `(4,16)` is in `PLANE_BLOCK_INVALID_422`. The guard refuses the **only** shape that could reach the bad arm. | ||
| 113 | +5. `PARTITION_HORZ_4` gives `(16,4)`, whose `(1,0)` cell is `BLOCK_8X4` and is legal — so the strip that survives is the one `own422` is written for. | ||
| 114 | + | ||
| 115 | +Classified **guarded-at-resolution**, not `unreachable`: the site *is* handable an | ||
| 116 | +INVALID subsize in principle, and a guard one level up is what makes it safe. | ||
| 117 | + | ||
| 118 | +## Census table | ||
| 119 | + | ||
| 120 | +`guard` = the `refuse_invalid_subsize` that covers the walk. Offending shapes at | ||
| 121 | +4:2:2 `(1,0)`: **4x8, 8x16, 4x16, 8x32, 16x32, 16x64, 32x64, 64x128**. 4:4:0 | ||
| 122 | +`(0,1)` is excluded throughout — libaom's `color_config` asserts | ||
| 123 | +`subsampling_y == 0` when `subsampling_x == 0`, so no frame can select it. | ||
| 124 | + | ||
| 125 | +| # | site | shapes | offending @mode | guard | mechanism | checked by | | ||
| 126 | +|---|---|---|---|---|---|---| | ||
| 127 | +| 1 | `decode_leaf_rect` kf 16-edge (`37124`) | 16x8, **8x16** | 8x16@(1,0) | `(16,16)` `edge_part` **added this lane**, `37106` | AtDispatch | census ordering + the pinned fixture | | ||
| 128 | +| 2 | `decode_rect4_16_intrabc` (`18232`) | 16x4, **4x16** | 4x16@(1,0) | `(16,16)` `36480` kf / `54809` inter | AtResolutionVia | derived VERT_4→(4,16), per-route ordering loop | | ||
| 129 | +| 3 | `decode_rect4_16` (`17552`) | 16x4, 4x16 | 4x16@(1,0) | `(16,16)` `36480` | AtResolution | row-scoped guard + ordering | | ||
| 130 | +| 4 | `decode_rect4_16_strip` (`18862`) | 16x4, 4x16 | 4x16@(1,0) | `(16,16)` `36480` | AtResolutionVia | guard-in-scope + per-route loop | | ||
| 131 | +| 5 | `decode_block_rect` (`15596`) | 32x16, **16x32** | 16x32@(1,0) | `(32,32)` `36414` / `54663` | AtResolution | row-scoped guard + ordering | | ||
| 132 | +| 6 | `decode_block_rect4` (`16764`) | 32x8, **8x32** | 8x32@(1,0) | `(32,32)` `36414` | AtResolution | row-scoped guard + ordering | | ||
| 133 | +| 7 | `decode_block_rect4`[inter] | 32x8, **8x32** | 8x32@(1,0) | `(32,32)` `54663` | AtResolutionVia | guard-in-scope in the inter decoder | | ||
| 134 | +| 8 | `decode_block_rect64` (`19851`) | 64x16, **16x64** | 16x64@(1,0) | `(64,64)` `36286` | AtResolution | row-scoped guard + ordering | | ||
| 135 | +| 9 | `decode_block_rect64`[inter] | 64x16, **16x64** | 16x64@(1,0) | `(64,64)` `54279` | AtResolutionVia | guard-in-scope in the inter decoder | | ||
| 136 | +| 10 | `decode_intra_rect_in_inter` (`13761`) | 16x8, **8x16**, 16x4, **4x16** | all four | `(16,16)` `54809` | AtResolutionVia | guard-in-scope + per-route loop | | ||
| 137 | +| 11 | `decode_block_128rect` (`23929`) | 128x64, **64x128** | 64x128@(1,0) | `(128,128)` `35596` in `read_sb128_root` | AtResolutionVia | guard-in-scope | | ||
| 138 | +| 12 | `decode_rect_split` (`12420`) | 32x16, 16x32, 64x16, 16x64 | all four | inherits from rows 5/7/8/9 | AtResolutionVia | guard-in-scope | | ||
| 139 | +| 13 | `decode_leaf_rect` AB arms (`36599`, `36688`, `36737`, `36756`) | 16x8, **8x16** | 8x16@(1,0) | `(16,16)` `36480` — `partition_subsize_dims((16,16), VERT_A/B) == (8,16)` | AtResolution | guard is above the AB range, never inside it (merged lane's AB invariant) | | ||
| 140 | +| 14 | `decode_leaf_rect8` (`27741`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` `36890` / `37189`, plus the inline check at `36912` | AtResolution | row-scoped guard + ordering | | ||
| 141 | +| 15 | `decode_inter_sub8_rect2` (`48920`) | 8x4, **4x8** | 4x8@(1,0) | `(8,8)` `55221` | AtResolution | row-scoped guard + ordering | | ||
| 142 | +| 16 | `decode_leaf_split4` (`27052`) | 4x4 | none | none needed | unreachable | offending set asserted empty | | ||
| 143 | +| 17 | `decode_inter_sub8_split4` (`47056`) | 4x4 | none | none needed | unreachable | offending set asserted empty | | ||
| 144 | +| 18 | `decode_leaf8` (`24421`), `decode_inter_block8` (`50102`) | 8x8 | none | none needed | unreachable | offending set asserted empty | | ||
| 145 | +| 19 | `decode_block` (`22483`), `decode_inter_block` (`41429`) | squares only | none | none needed | unreachable | every square's plane block is valid at every selectable mode; the whole BLOCK_INVALID column is rect | | ||
| 146 | + | ||
| 147 | +**Rows not closed: none.** Every row is guarded (1–15) or needs no guard because | ||
| 148 | +the shape is codable at every selectable subsampling mode (16–19). | ||
| 149 | + | ||
| 150 | +## The merged lane's matcher gap, widened (r11) | ||
| 151 | + | ||
| 152 | +Its site list was incomplete **for a spelling, not for a shape**, so it would miss | ||
| 153 | +the next differently-spelled read the same way. The read test is now derived: | ||
| 154 | + | ||
| 155 | +> a partition-symbol READ is a `dec.<name>(..)` call whose **own argument list** | ||
| 156 | +> names a `partition_w<N>[` CDF. | ||
| 157 | + | ||
| 158 | +That is the whole definition and it needs no hand-list. `dec.symbol(..partition_w..)` | ||
| 159 | +qualifies; the frame-edge gather's `dec.symbol_fixed(&gather(..partition_w..))` | ||
| 160 | +qualifies; `dec.debug_state()` does not — it never names a partition CDF. A third | ||
| 161 | +spelling is covered the day somebody writes it. The `var == "b"` skip is gone too: | ||
| 162 | +edge reads are **sites** now, and instead of being skipped they must carry a guard | ||
| 163 | +for their own level before the first chroma-walking dispatch that follows them. | ||
| 164 | + | ||
| 165 | +**A limitation, stated rather than hidden:** the definition is syntactic. A read | ||
| 166 | +that reaches a `partition_w` CDF through a helper whose argument list does not | ||
| 167 | +mention the CDF name would not be enumerated. There is no such call in this file | ||
| 168 | +today, and the census's `AtDispatch` row covers the arm this gap actually hid. | ||
| 169 | + | ||
| 170 | +## Evidence | ||
| 171 | + | ||
| 172 | +### The widening bites, and so does every guard the census claims | ||
| 173 | + | ||
| 174 | +Per-guard deletion, one at a time, by line number, against the census alone: | ||
| 175 | + | ||
| 176 | +| deleted | census | | ||
| 177 | +|---|---| | ||
| 178 | +| 35596 — 128-root (`read_sb128_root`) | RED — "NO such guard there" | | ||
| 179 | +| 36286 — kf 64x64 | RED — "NO such guard in `decode_key_frame_tile_with_cdfs`" | | ||
| 180 | +| 36414 — kf 32x32 | RED — same, naming `decode_block_rect` | | ||
| 181 | +| 36472 — kf 16x16 | RED — ordering ("guard BELOW the dispatch") | | ||
| 182 | +| 36890 — kf 8x8 (first) | RED — ordering, naming `decode_leaf_rect8` | | ||
| 183 | +| 37106 — kf 16-level frame-edge arm | RED — "sits AFTER the `decode_leaf_rect` it protects" | | ||
| 184 | +| 37106 — same guard, moved below the dispatch | RED — the r5 defect in a new place | | ||
| 185 | +| 54279 — inter 64x64 | RED — names `decode_block_rect64[inter]` | | ||
| 186 | +| 54663 — inter 32x32 | RED — names `decode_block_rect4[inter]` | | ||
| 187 | +| 54809 — inter 16x16 | RED — names `decode_intra_rect_in_inter` | | ||
| 188 | +| 55221 — inter 8x8 | RED — names `decode_inter_sub8_rect2` | | ||
| 189 | + | ||
| 190 | +**Two guards are claimed by LEVEL, not by site**, and the census stays green when | ||
| 191 | +they are deleted — stated here rather than papered over: | ||
| 192 | + | ||
| 193 | +* **37189** — the key-frame 8x8 **second** resolution (the frame-edge straddle loop). | ||
| 194 | +* **54042** — the inter decoder's own 128-root guard (the row claims the shared one in `read_sb128_root`). | ||
| 195 | + | ||
| 196 | +Both are caught by the merged scan's resolution-count cross-check | ||
| 197 | +(`the decode body has 12 partition resolutions but only 11 guard sites`). A | ||
| 198 | +per-site row for each would pin them individually; that is the obvious next | ||
| 199 | +ratchet step and it is not in this lane. | ||
| 200 | + | ||
| 201 | +### Over-refusal control | ||
| 202 | + | ||
| 203 | +`EC_AV1_SUBSIZE_GUARD_TRACE` on real `aomenc` 4:2:0 streams of exactly the shape | ||
| 204 | +that reaches the arm (`testsrc2`, widths 40/72/104/136, `h=120`, | ||
| 205 | +`--min-partition-size=4 --max-partition-size=64 --sb-size=64`): | ||
| 206 | + | ||
| 207 | +``` | ||
| 208 | +SUBSIZE_GUARD site=.../decode.rs:37106 bsize=16x16 part=2 codable=true reached=2 | ||
| 209 | +SUBSIZE_ARM site=.../decode.rs:37109 part=2 codable=true reached=2 | ||
| 210 | +``` | ||
| 211 | + | ||
| 212 | +`part=2` is `PARTITION_VERT` — the 8x16 strip, INVALID at 4:2:2. At 4:2:0 the | ||
| 213 | +guard reports `codable=true` and the frame decodes: the guard is on a live path and | ||
| 214 | +refuses nothing it should not. | ||
| 215 | + | ||
| 216 | +### Tests | ||
| 217 | + | ||
| 218 | +* `cargo check --tests` clean. | ||
| 219 | +* `cargo test -p ec-av1 --lib -- 422 sub8 subsize chroma_422` — **27 passed, 0 failed** (52 s), including the pinned 4:2:2 corpus, bigblock, lossless-inter and intrabc-sb128 pixel-exactness gates. | ||
| 220 | +* `cargo test -p ec-av1 --lib -- pixel_exact byte_exact` — **270 passed, 0 failed** (818 s). The over-refusal control at scale: if the new guard refused anything legal these would go red. | ||
| 221 | +* The three structural gates pass together, plus the two hostile-pin refusal gates. | ||
| 222 | + | ||
| 223 | +## Wider sweep — hardcoded chroma halvings, NAMED NOT FIXED (out of charter) | ||
| 224 | + | ||
| 225 | +One finding **is** inside the residue and is covered by row 2: | ||
| 226 | +`decode_rect4_16_intrabc`'s `else` arm at `18334-18337` / `18354` — the | ||
| 227 | +`(pw / 2, ph / 2)` halving and the `(pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)` | ||
| 228 | +origin — is a both-axes halving whose predicate (`own444 || own422`) does not | ||
| 229 | +enumerate every reachable `(ss, shape)` cell. Dead only because row 2's guard | ||
| 230 | +refuses VERT_4 at 4:2:2. If that guard moves, this arm becomes the live defect. | ||
| 231 | + | ||
| 232 | +Outside the charter, named for the owning lanes. Provenance: line numbers | ||
| 233 | +confirmed against the worktree, but nothing outside the decode.rs | ||
| 234 | +partition/chroma walk was **reproduced by a probe here**; rows marked "not probed" | ||
| 235 | +should be re-measured by the lane that takes them. | ||
| 236 | + | ||
| 237 | +| site | what | consequence at 4:2:2 | | ||
| 238 | +|---|---|---| | ||
| 239 | +| `decode.rs:21081` `cfl_ac_q3_at` | `(bw / 2, bh / 2)` + 2×2 luma average | correct only because `cfl_ac_ss` routes 4:2:2 elsewhere; held by the `cfl_ac_q3_at_hits` 4:2:0-only gate | | ||
| 240 | +| `decode.rs:47516, 47908, 49484, 49930` | `mv_to_q4(<y>, <row_mv>, ss_x(fctx))` — the **Y** axis shifted by `ss_x` | each masked by a guard pinning the format to one where `ss_x == ss_y` | | ||
| 241 | +| `decode.rs:43251/43262, 43366` | `chroma_side * chroma_side` sizing in the mu-chroma composed grid; at `ss (1,0)` the plane rect is `(side/2, side)` and a square `side/2` is too short on rows `>= side/2` | not probed; the lossless sibling was repaired to `chroma_stride`, these were not. Needs an owning lane with a 128-root 4:2:2 mu-chunk witness | | ||
| 242 | +| `decode.rs:35708, 53419` | floor-`>>` chroma plane allocators | shape assumption at frame edges; not probed | | ||
| 243 | +| `encode.rs:1674-1687, 1862-1863, 7477/7483, 7928/7934, 8215/8221, 9295-9315` | every chroma plane/stride/crop at `width / 2` with no ss term | correct only because the encoder emits 4:2:0 exclusively; `obmc_plan` (`7362`) passes real `ss_x`/`ss_y` next to a `side / 2` stride, so two conventions meet there | | ||
| 244 | +| `tile.rs:5004-5006` (`fn palette_uv_side`) | `(side / 2).max(4)` | 4:2:2/4:4:0 palette map mis-sized | | ||
| 245 | +| `stream.rs:6672, 6773, 17075` + `probe.rs:81` | ffmpeg rawvideo oracle slices chroma at `width * height / 4` | **the dangerous ones**: a future 4:2:2 gate using them compares half the oracle's bytes and passes green. The `_422_depth`/`_444` siblings exist and are correct; the 4:2:0 trio is unguarded against the wrong format | | ||
| 246 | +| `encode.rs:1595-1616` (`Picture::grey`/`check`), `1605`, `1658`, `1852` | every test card's chroma allocated and asserted at `width * height / 4` | the crate's test surface is 4:2:0-sized before any test code runs | | ||
| 247 | +| `decode.rs:58989, 59008, 59261-59281` | test-card chroma + `PlaneBuf` test harness at `width/2`, `height/2` | same | | ||
| 248 | +| `examples/gen_coverage_cells.rs:94-96`, `examples/syntax_census.rs` | quarter-plane chroma arithmetic | same | | ||
| 249 | + | ||
| 250 | +`mc.rs`, `intra.rs`, `transform.rs`, `compound.rs` are clean — plane dims arrive as | ||
| 251 | +parameters. `restoration.rs` and `film_grain.rs` are per-axis and correct. | ||
| 252 | +`motion_field.rs:74`'s `/ 2` is the 8×8 MV-cell grid, not a chroma extent. | ||
| 253 | + | ||
| 254 | +## Housekeeping | ||
| 255 | + | ||
| 256 | +An early edit of this lane leaked into the primary checkout through a relative | ||
| 257 | +path and was reverted before any commit (`git checkout --` on the one file it | ||
| 258 | +touched); a second leak, the `stream.rs` gate, was caught the same way. The | ||
| 259 | +primary checkout is clean at every commit on this branch, and no commit here | ||
| 260 | +contains either hunk. | ||
| 261 | + | ||
| 262 | +## Not closed, stated plainly | ||
| 263 | + | ||
| 264 | +1. **The structural gate is a derived site list, not a proof.** It pins the | ||
| 265 | + mechanism for 19 walks and guard ordering for the hole, but it cannot see a | ||
| 266 | + walk that is neither named in the census nor reachable through a | ||
| 267 | + `partition_w<N>` read — e.g. a future site fed a block shape from a | ||
| 268 | + non-partition source. The census is a ratchet. | ||
| 269 | +2. **Two guards are level-claimed, not site-claimed** (kf 8x8 second resolution, | ||
| 270 | + inter 128-root). The merged scan's count cross-check is what reds them. | ||
| 271 | +3. **The read-spelling derivation is syntactic.** A read reaching a `partition_w` | ||
| 272 | + CDF through a helper that does not mention the CDF name would not be enumerated. | ||
| 273 | +4. **`decode_rect4_16_intrabc`'s `else` arm is still wrong in isolation** — closed | ||
| 274 | + by reachability, not construction. Closing it by construction would mean | ||
| 275 | + asserting a caller property from inside the callee, and breaking the moment the | ||
| 276 | + arm gains a legal 4:2:2 VERT_4 use. | ||
| 277 | +5. **Why aomenc never produces this shape is unknown.** The witness had to be | ||
| 278 | + built from this crate's own encoder with a declared width. See the reachability | ||
| 279 | + section — the earlier `partition_rect_allowed` explanation was wrong. | ||
| \ No newline at end of file | \ No newline at end of file | ||