Enumerate the var-tx leaf domain against the two too-large-leaf refusals
Browse files at this commit8f932d53d66eea282c326437f48e2a84d22432bbParent: 34574f5- test
- enumerate the var-tx leaf domain against the two too-large-leaf refusals
2 changed files +87 -0
crates/ec-av1/src/decode.rsmodified+75 -0
| @@ -14351,6 +14351,81 @@ fn sub_tx_size_map_matches_libaom() { | |||
| 14351 | } | 14351 | } |
| 14352 | } | 14352 | } |
| 14353 | 14353 | ||
| 14354 | +/// The domain of var-tx leaf sizes, enumerated against the two refusals that | ||
| 14355 | +/// name a leaf "larger than 32x32" / "larger than 64x64". | ||
| 14356 | +/// | ||
| 14357 | +/// [`read_var_tx_size`] emits a leaf in exactly three places, and each one is | ||
| 14358 | +/// either the unit it was entered with or a `sub_tx_size_map` step below it: | ||
| 14359 | +/// the depth cap, the `!split` return, and libaom's `sub_txs == TX_4X4` early | ||
| 14360 | +/// return. So the leaf set reachable from an entry unit is that unit plus the | ||
| 14361 | +/// chain of `sub_tx_size_map` steps under it, capped at `MAX_VARTX_DEPTH` -- | ||
| 14362 | +/// which this test enumerates, and over which no leaf is ever larger than the | ||
| 14363 | +/// entry. | ||
| 14364 | +/// | ||
| 14365 | +/// That closes both refusals: | ||
| 14366 | +/// | ||
| 14367 | +/// * [`read_block_tx_size_rect`]'s `bw.max(bh) > 64` branch enters every unit | ||
| 14368 | +/// at TX_64X64 (`max_txsize_rect_lookup[BLOCK_128X64]`), so "larger than | ||
| 14369 | +/// 64x64" names a leaf the tree cannot produce; | ||
| 14370 | +/// * [`read_block_tx_size`] enters at `side.min(64)` with a ceiling of 32 | ||
| 14371 | +/// below the 128 root. The only entry that exceeds that ceiling is 64x64, | ||
| 14372 | +/// reached only when `side == 64`, and then the block is ONE unit whose only | ||
| 14373 | +/// above-ceiling leaf is the whole 64x64 unit itself -- which is the `single` | ||
| 14374 | +/// case the refusal is guarded by. | ||
| 14375 | +#[test] | ||
| 14376 | +fn a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered() { | ||
| 14377 | + // Every leaf `read_var_tx_size` can reach from `entry`, as (depth, w, h). | ||
| 14378 | + fn reachable(entry: (usize, usize), depth: usize, out: &mut Vec<(usize, usize, usize)>) { | ||
| 14379 | + out.push((depth, entry.0, entry.1)); | ||
| 14380 | + if depth == MAX_VARTX_DEPTH { | ||
| 14381 | + return; | ||
| 14382 | + } | ||
| 14383 | + let sub = sub_tx_size_map(entry.0, entry.1); | ||
| 14384 | + if sub == (4, 4) { | ||
| 14385 | + out.push((depth + 1, 4, 4)); | ||
| 14386 | + return; | ||
| 14387 | + } | ||
| 14388 | + reachable(sub, depth + 1, out); | ||
| 14389 | + } | ||
| 14390 | + | ||
| 14391 | + for entry in [(4, 4), (8, 8), (16, 16), (32, 32), (64, 64)] { | ||
| 14392 | + let mut leaves = Vec::new(); | ||
| 14393 | + reachable(entry, 0, &mut leaves); | ||
| 14394 | + for (depth, w, h) in &leaves { | ||
| 14395 | + assert!( | ||
| 14396 | + w.max(h) <= &entry.0.max(entry.1), | ||
| 14397 | + "a {}x{} unit reaches a {w}x{h} leaf at depth {depth}", | ||
| 14398 | + entry.0, | ||
| 14399 | + entry.1 | ||
| 14400 | + ); | ||
| 14401 | + } | ||
| 14402 | + // Above-ceiling leaves of a 64x64 entry: the entry itself, at depth 0. | ||
| 14403 | + if entry == (64, 64) { | ||
| 14404 | + let above: Vec<&(usize, usize, usize)> = | ||
| 14405 | + leaves.iter().filter(|(_, w, h)| w.max(h) > &32).collect(); | ||
| 14406 | + assert_eq!(above, [&(0usize, 64usize, 64usize)], "64x64 entry, leaves above 32"); | ||
| 14407 | + } | ||
| 14408 | + } | ||
| 14409 | + | ||
| 14410 | + // The entry size and ceiling each caller uses, over the block sides that | ||
| 14411 | + // reach them (`read_block_tx_size`'s square path; the 128-root rect path | ||
| 14412 | + // enters at a fixed 64). | ||
| 14413 | + for side in [8usize, 16, 32, 64, 128] { | ||
| 14414 | + let max_tx = side.min(64); | ||
| 14415 | + let ceiling = if side > 64 { 64 } else { 32 }; | ||
| 14416 | + let units = (side / max_tx) * (side / max_tx); | ||
| 14417 | + if max_tx <= ceiling { | ||
| 14418 | + continue; | ||
| 14419 | + } | ||
| 14420 | + assert_eq!( | ||
| 14421 | + (side, units), | ||
| 14422 | + (64, 1), | ||
| 14423 | + "a {side}px block enters var-tx at {max_tx} over a ceiling of {ceiling} in \ | ||
| 14424 | + {units} units -- an above-ceiling leaf there would NOT be the `single` case" | ||
| 14425 | + ); | ||
| 14426 | + } | ||
| 14427 | +} | ||
| 14428 | + | ||
| 14354 | /// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c` | 14429 | /// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c` |
| 14355 | /// `read_tx_size_vartx`): the recursive `txfm_split` tree of one | 14430 | /// `read_tx_size_vartx`): the recursive `txfm_split` tree of one |
| 14356 | /// max-transform-sized unit of an inter block, collecting the resolved leaf | 14431 | /// max-transform-sized unit of an inter block, collecting the resolved leaf |
crates/ec-av1/src/refusal_inventory.rsmodified+12 -0
| @@ -166,6 +166,18 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 166 | "a rectangular transform unit whose shape has no coefficient scan table here", | 166 | "a rectangular transform unit whose shape has no coefficient scan table here", |
| 167 | "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | 167 | "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", |
| 168 | ), | 168 | ), |
| 169 | + // lane-t900 r21, enumeration: a var-tx leaf is never larger than the unit | ||
| 170 | + // the tree was entered with, and both callers enter at or below their own | ||
| 171 | + // ceiling (the one case that does not, a 64px block at TX_64X64, is the | ||
| 172 | + // `single` whole-block case the refusal is guarded by). | ||
| 173 | + ( | ||
| 174 | + "an inter var-tx tree with a leaf transform larger than 32x32", | ||
| 175 | + "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered", | ||
| 176 | + ), | ||
| 177 | + ( | ||
| 178 | + "an inter var-tx tree with a leaf transform larger than 64x64", | ||
| 179 | + "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered", | ||
| 180 | + ), | ||
| 169 | // Pre-existing proofs, registered by lane-t900 r21: a negative gate (a | 181 | // Pre-existing proofs, registered by lane-t900 r21: a negative gate (a |
| 170 | // hand-built 12-bit sequence header is refused BY THIS EXACT STRING rather | 182 | // hand-built 12-bit sequence header is refused BY THIS EXACT STRING rather |
| 171 | // than decoded wrong) and a witness gate (a real aomenc screen key frame | 183 | // than decoded wrong) and a witness gate (a real aomenc screen key frame |