Pin every filter-intra CDF row from the oracle, prove predict_filter_intra bit-exact, record both firing seeds
Browse files at this commitf28a52c70f0302cc7bdc71171d17d37119f51f70Parent: b2b0caf- test
- pin every filter-intra CDF row from the oracle, prove predict_filter_intra bit-exact, record both firing seeds
5 changed files +459 -62
- crates/ec-av1/src/decode.rs +79 -48
- crates/ec-av1/src/intra.rs +192 -0
- crates/ec-av1/src/stream.rs +42 -14
- lanes/fistrip-r2.report.md +116 -0
- scripts/extract-filter-intra-cdfs.py +30 -0
crates/ec-av1/src/decode.rsmodified+79 -48
| @@ -16325,57 +16325,88 @@ mod tests { | ||
| 16325 | 16325 | #[test] |
| 16326 | 16326 | fn filter_intra_classes_carry_their_own_libaom_default_row() { |
| 16327 | 16327 | // `default_filter_intra_cdfs[bsize]`, BLOCK_SIZES_ALL order, as |
| 16328 | - // (width, height, default) for the shapes <= 32 on both axes. | |
| 16329 | - let libaom: &[(usize, usize, u16)] = &[ | |
| 16330 | - (4, 4, 4621), | |
| 16331 | - (4, 8, 6743), | |
| 16332 | - (8, 4, 5893), | |
| 16333 | - (8, 8, 7866), | |
| 16334 | - (8, 16, 12551), | |
| 16335 | - (16, 8, 9394), | |
| 16336 | - (16, 16, 12408), | |
| 16337 | - (16, 32, 14301), | |
| 16338 | - (32, 16, 12756), | |
| 16339 | - (32, 32, 22343), | |
| 16340 | - (4, 16, 16384), | |
| 16341 | - (16, 4, 16384), | |
| 16342 | - (8, 32, 16384), | |
| 16343 | - (32, 8, 16384), | |
| 16328 | + // (width, height, default, refused_by) for the shapes <= 32 on both | |
| 16329 | + // axes. The first three fields are GENERATED from the oracle by | |
| 16330 | + // `scripts/extract-filter-intra-cdfs.py` (it reads BLOCK_SIZES_ALL's | |
| 16331 | + // order from enums.h and the table from entropymode.c, so no hand | |
| 16332 | + // transcription can drift -- lane-fistrip r1 listed the four 1:4 | |
| 16333 | + // shapes as 16384 out of exactly that kind of guess; their real rows | |
| 16334 | + // are 12770/10368/20229/18101). `refused_by` is `None` for a shape | |
| 16335 | + // this decoder's partition tree reaches today -- it must own a class, | |
| 16336 | + // and that class must carry exactly this row -- and the refusal | |
| 16337 | + // string that blocks the shape otherwise. Either way the row is | |
| 16338 | + // pinned HERE, so the round that lifts one of those refusals cannot | |
| 16339 | + // land a wrong CDF row for the shape it unlocks. | |
| 16340 | + const BELOW_8X8: &str = | |
| 16341 | + "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)"; | |
| 16342 | + const PART16: &str = "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes \ | |
| 16343 | + only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)"; | |
| 16344 | + const PART32: &str = "a 32x32 partition type this decoder does not code (value={part32})"; | |
| 16345 | + let libaom: &[(usize, usize, u16, Option<&str>)] = &[ | |
| 16346 | + (4, 4, 4621, None), | |
| 16347 | + (4, 8, 6743, Some(BELOW_8X8)), | |
| 16348 | + (8, 4, 5893, Some(BELOW_8X8)), | |
| 16349 | + (8, 8, 7866, None), | |
| 16350 | + (8, 16, 12551, None), | |
| 16351 | + (16, 8, 9394, None), | |
| 16352 | + (16, 16, 12408, None), | |
| 16353 | + (16, 32, 14301, None), | |
| 16354 | + (32, 16, 12756, None), | |
| 16355 | + (32, 32, 22343, None), | |
| 16356 | + // The 1:4 strips: a 16x16-level PARTITION_HORZ_4/VERT_4 gives | |
| 16357 | + // 4x16/16x4, a 32x32-level one 8x32/32x8, and both partition | |
| 16358 | + // values refuse by name before any leaf is coded. | |
| 16359 | + (4, 16, 12770, Some(PART16)), | |
| 16360 | + (16, 4, 10368, Some(PART16)), | |
| 16361 | + (8, 32, 20229, Some(PART32)), | |
| 16362 | + (32, 8, 18101, Some(PART32)), | |
| 16344 | 16363 | ]; |
| 16345 | - // The shapes this decoder's partition tree can actually reach today | |
| 16346 | - // (squares 4..32 plus the 16x16- and 32x32-level HORZ/VERT strips). | |
| 16347 | - let reachable = [ | |
| 16348 | - (4, 4), | |
| 16349 | - (8, 8), | |
| 16350 | - (16, 16), | |
| 16351 | - (32, 32), | |
| 16352 | - (32, 16), | |
| 16353 | - (16, 32), | |
| 16354 | - (8, 16), | |
| 16355 | - (16, 8), | |
| 16356 | - ]; | |
| 16357 | - for &(bw, bh, default) in libaom { | |
| 16358 | - let class = filter_intra_size_class_rect(bw, bh); | |
| 16359 | - if reachable.contains(&(bw, bh)) { | |
| 16360 | - let class = class.unwrap_or_else(|| { | |
| 16361 | - panic!("{bw}x{bh} is inside av1_filter_intra_allowed_bsize and reachable, \ | |
| 16362 | - but has no CDF class -- its use_filter_intra symbol is never read") | |
| 16363 | - }); | |
| 16364 | - assert_eq!( | |
| 16365 | - crate::cdf::FILTER_INTRA[class][0], | |
| 16366 | - default, | |
| 16367 | - "{bw}x{bh} (class {class}) must carry default_filter_intra_cdfs' own row" | |
| 16368 | - ); | |
| 16369 | - } else { | |
| 16370 | - // 4x8/8x4/4x16/16x4/8x32/32x8: sub-8x8 leaves and the 1:4 | |
| 16371 | - // strips, neither of which this decoder codes yet (their | |
| 16372 | - // partition levels refuse by name first), so no class exists. | |
| 16373 | - assert!( | |
| 16374 | - class.is_none(), | |
| 16375 | - "{bw}x{bh} gained a class without a decode path to use it" | |
| 16376 | - ); | |
| 16364 | + let mut classes_seen = std::collections::BTreeSet::new(); | |
| 16365 | + for &(bw, bh, default, refused_by) in libaom { | |
| 16366 | + match filter_intra_size_class_rect(bw, bh) { | |
| 16367 | + Some(class) => { | |
| 16368 | + assert!( | |
| 16369 | + refused_by.is_none(), | |
| 16370 | + "{bw}x{bh} has a CDF class but is listed as refused by {refused_by:?} -- \ | |
| 16371 | + one of the two is stale" | |
| 16372 | + ); | |
| 16373 | + assert_eq!( | |
| 16374 | + crate::cdf::FILTER_INTRA[class][0], | |
| 16375 | + default, | |
| 16376 | + "{bw}x{bh} (class {class}) must carry default_filter_intra_cdfs' own row" | |
| 16377 | + ); | |
| 16378 | + assert_eq!( | |
| 16379 | + &crate::cdf::FILTER_INTRA[class][1..], | |
| 16380 | + &[32768u16, 0][..], | |
| 16381 | + "{bw}x{bh} (class {class}) is a 2-symbol CDF: {{p, 32768, count}}" | |
| 16382 | + ); | |
| 16383 | + assert!( | |
| 16384 | + classes_seen.insert(class), | |
| 16385 | + "class {class} is claimed by two shapes -- one of them reads the other's \ | |
| 16386 | + probability" | |
| 16387 | + ); | |
| 16388 | + } | |
| 16389 | + None => { | |
| 16390 | + let why = refused_by.unwrap_or_else(|| { | |
| 16391 | + panic!( | |
| 16392 | + "{bw}x{bh} is inside av1_filter_intra_allowed_bsize and reachable, \ | |
| 16393 | + but has no CDF class -- its use_filter_intra symbol is never read" | |
| 16394 | + ) | |
| 16395 | + }); | |
| 16396 | + assert!(!why.is_empty(), "{bw}x{bh}'s refusal string must name the blocker"); | |
| 16397 | + } | |
| 16377 | 16398 | } |
| 16378 | 16399 | } |
| 16400 | + // The other direction: every row of `cdf::FILTER_INTRA` was claimed | |
| 16401 | + // by exactly one shape above, so no row can be left over (or shared) | |
| 16402 | + // once a class is added or removed. | |
| 16403 | + assert_eq!( | |
| 16404 | + classes_seen.len(), | |
| 16405 | + crate::cdf::FILTER_INTRA.len(), | |
| 16406 | + "cdf::FILTER_INTRA has {} rows but only {:?} are claimed by an allowed shape", | |
| 16407 | + crate::cdf::FILTER_INTRA.len(), | |
| 16408 | + classes_seen | |
| 16409 | + ); | |
| 16379 | 16410 | // Past the bound on either axis: no symbol at all (spec |
| 16380 | 16411 | // `filter_intra_mode_info` never reads one). |
| 16381 | 16412 | for (bw, bh) in [(64, 64), (64, 32), (32, 64)] { |
crates/ec-av1/src/intra.rsmodified+192 -0
| @@ -865,6 +865,198 @@ mod tests { | ||
| 865 | 865 | .sum() |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | + /// libaom `av1_filter_intra_taps` (reconintra.c:807-858), transcribed | |
| 869 | + /// here INDEPENDENTLY of [`FILTER_INTRA_TAPS`] -- the point of the test | |
| 870 | + /// below is that two transcriptions of the reference agree, so it must | |
| 871 | + /// not read the table it is checking. (libaom's rows are 8 wide with the | |
| 872 | + /// 8th tap always 0; only seven are used.) | |
| 873 | + const LIBAOM_FILTER_INTRA_TAPS: [[[i32; 7]; 8]; 5] = [ | |
| 874 | + [ | |
| 875 | + [-6, 10, 0, 0, 0, 12, 0], | |
| 876 | + [-5, 2, 10, 0, 0, 9, 0], | |
| 877 | + [-3, 1, 1, 10, 0, 7, 0], | |
| 878 | + [-3, 1, 1, 2, 10, 5, 0], | |
| 879 | + [-4, 6, 0, 0, 0, 2, 12], | |
| 880 | + [-3, 2, 6, 0, 0, 2, 9], | |
| 881 | + [-3, 2, 2, 6, 0, 2, 7], | |
| 882 | + [-3, 1, 2, 2, 6, 3, 5], | |
| 883 | + ], | |
| 884 | + [ | |
| 885 | + [-10, 16, 0, 0, 0, 10, 0], | |
| 886 | + [-6, 0, 16, 0, 0, 6, 0], | |
| 887 | + [-4, 0, 0, 16, 0, 4, 0], | |
| 888 | + [-2, 0, 0, 0, 16, 2, 0], | |
| 889 | + [-10, 16, 0, 0, 0, 0, 10], | |
| 890 | + [-6, 0, 16, 0, 0, 0, 6], | |
| 891 | + [-4, 0, 0, 16, 0, 0, 4], | |
| 892 | + [-2, 0, 0, 0, 16, 0, 2], | |
| 893 | + ], | |
| 894 | + [ | |
| 895 | + [-8, 8, 0, 0, 0, 16, 0], | |
| 896 | + [-8, 0, 8, 0, 0, 16, 0], | |
| 897 | + [-8, 0, 0, 8, 0, 16, 0], | |
| 898 | + [-8, 0, 0, 0, 8, 16, 0], | |
| 899 | + [-4, 4, 0, 0, 0, 0, 16], | |
| 900 | + [-4, 0, 4, 0, 0, 0, 16], | |
| 901 | + [-4, 0, 0, 4, 0, 0, 16], | |
| 902 | + [-4, 0, 0, 0, 4, 0, 16], | |
| 903 | + ], | |
| 904 | + [ | |
| 905 | + [-2, 8, 0, 0, 0, 10, 0], | |
| 906 | + [-1, 3, 8, 0, 0, 6, 0], | |
| 907 | + [-1, 2, 3, 8, 0, 4, 0], | |
| 908 | + [0, 1, 2, 3, 8, 2, 0], | |
| 909 | + [-1, 4, 0, 0, 0, 3, 10], | |
| 910 | + [-1, 3, 4, 0, 0, 4, 6], | |
| 911 | + [-1, 2, 3, 4, 0, 4, 4], | |
| 912 | + [-1, 2, 2, 3, 4, 3, 3], | |
| 913 | + ], | |
| 914 | + [ | |
| 915 | + [-12, 14, 0, 0, 0, 14, 0], | |
| 916 | + [-10, 0, 14, 0, 0, 12, 0], | |
| 917 | + [-9, 0, 0, 14, 0, 11, 0], | |
| 918 | + [-8, 0, 0, 0, 14, 10, 0], | |
| 919 | + [-10, 12, 0, 0, 0, 0, 14], | |
| 920 | + [-9, 1, 12, 0, 0, 0, 12], | |
| 921 | + [-8, 0, 0, 12, 0, 1, 11], | |
| 922 | + [-7, 0, 0, 1, 12, 1, 9], | |
| 923 | + ], | |
| 924 | + ]; | |
| 925 | + | |
| 926 | + /// A straight port of `av1_filter_intra_predictor_c` / | |
| 927 | + /// `highbd_filter_intra_predictor` (reconintra.c:860-905 / 908-955 -- | |
| 928 | + /// identical except for the clip), written from the C rather than from | |
| 929 | + /// [`predict_filter_intra`]. `above` is the C `&above[-1]`, i.e. the | |
| 930 | + /// corner followed by `bw` samples; `left` is `bh` samples. | |
| 931 | + fn libaom_filter_intra_predictor( | |
| 932 | + dst: &mut [u16], | |
| 933 | + bw: usize, | |
| 934 | + bh: usize, | |
| 935 | + above: &[u16], | |
| 936 | + left: &[u16], | |
| 937 | + mode: usize, | |
| 938 | + bd: u32, | |
| 939 | + ) { | |
| 940 | + assert!(bw <= 32 && bh <= 32); | |
| 941 | + let mut buffer = [[0i32; 33]; 33]; | |
| 942 | + for r in 0..bh { | |
| 943 | + buffer[r + 1][0] = i32::from(left[r]); | |
| 944 | + } | |
| 945 | + for c in 0..bw + 1 { | |
| 946 | + buffer[0][c] = i32::from(above[c]); | |
| 947 | + } | |
| 948 | + let max = (1i32 << bd) - 1; | |
| 949 | + let mut r = 1; | |
| 950 | + while r < bh + 1 { | |
| 951 | + let mut c = 1; | |
| 952 | + while c < bw + 1 { | |
| 953 | + let p = [ | |
| 954 | + buffer[r - 1][c - 1], | |
| 955 | + buffer[r - 1][c], | |
| 956 | + buffer[r - 1][c + 1], | |
| 957 | + buffer[r - 1][c + 2], | |
| 958 | + buffer[r - 1][c + 3], | |
| 959 | + buffer[r][c - 1], | |
| 960 | + buffer[r + 1][c - 1], | |
| 961 | + ]; | |
| 962 | + for k in 0..8 { | |
| 963 | + let mut pr = 0i32; | |
| 964 | + for t in 0..7 { | |
| 965 | + pr += LIBAOM_FILTER_INTRA_TAPS[mode][k][t] * p[t]; | |
| 966 | + } | |
| 967 | + // ROUND_POWER_OF_TWO(pr, 4) then clip_pixel[_highbd]. | |
| 968 | + let v = ((pr + 8) >> 4).clamp(0, max); | |
| 969 | + buffer[r + (k >> 2)][c + (k & 3)] = v; | |
| 970 | + } | |
| 971 | + c += 4; | |
| 972 | + } | |
| 973 | + r += 2; | |
| 974 | + } | |
| 975 | + for row in 0..bh { | |
| 976 | + for col in 0..bw { | |
| 977 | + dst[row * bw + col] = buffer[row + 1][col + 1] as u16; | |
| 978 | + } | |
| 979 | + } | |
| 980 | + } | |
| 981 | + | |
| 982 | + /// lane-fistrip r2: [`predict_filter_intra`] had NO unit test at all -- | |
| 983 | + /// the 8x16/16x8 strips r1 unblocked read their `use_filter_intra` flag | |
| 984 | + /// with zero pixel evidence behind it (every firing strip is `skip=0` | |
| 985 | + /// and refuses, see `stream.rs`'s ignored gate). This compares it | |
| 986 | + /// bit-exact against the independent C port above for every filter-intra | |
| 987 | + /// mode, every shape `av1_filter_intra_allowed_bsize` allows (both sides | |
| 988 | + /// <= 32, squares and both orientations of 1:2 and 1:4), 8- and 10-bit, | |
| 989 | + /// on three seeded random edges. | |
| 990 | + #[test] | |
| 991 | + fn filter_intra_matches_the_libaom_predictor_for_every_mode_and_shape() { | |
| 992 | + // xorshift64*: a seeded stream, so a failure names one (shape, mode, | |
| 993 | + // seed) triple that reproduces. | |
| 994 | + let mut rng = |state: &mut u64| { | |
| 995 | + *state ^= *state << 13; | |
| 996 | + *state ^= *state >> 7; | |
| 997 | + *state ^= *state << 17; | |
| 998 | + *state | |
| 999 | + }; | |
| 1000 | + let shapes = [ | |
| 1001 | + (4usize, 4usize), | |
| 1002 | + (8, 8), | |
| 1003 | + (16, 16), | |
| 1004 | + (32, 32), | |
| 1005 | + (4, 8), | |
| 1006 | + (8, 4), | |
| 1007 | + (8, 16), | |
| 1008 | + (16, 8), | |
| 1009 | + (16, 32), | |
| 1010 | + (32, 16), | |
| 1011 | + (4, 16), | |
| 1012 | + (16, 4), | |
| 1013 | + (8, 32), | |
| 1014 | + (32, 8), | |
| 1015 | + ]; | |
| 1016 | + let mut compared = 0u32; | |
| 1017 | + for bd in [8u32, 10] { | |
| 1018 | + crate::decode::set_bit_depth(bd as u8); | |
| 1019 | + let max = (1u32 << bd) - 1; | |
| 1020 | + for &(bw, bh) in &shapes { | |
| 1021 | + for mode in 0..5usize { | |
| 1022 | + for seed in [1u64, 0x5eed_5eed, 0xdead_beef_cafe] { | |
| 1023 | + let mut state = seed | |
| 1024 | + .wrapping_mul(0x9E37_79B9_7F4A_7C15) | |
| 1025 | + .wrapping_add((bw * 97 + bh * 7 + mode) as u64) | |
| 1026 | + | 1; | |
| 1027 | + let sample = |state: &mut u64| (rng(state) % u64::from(max + 1)) as u16; | |
| 1028 | + let corner = sample(&mut state); | |
| 1029 | + let above: Vec<u16> = (0..bw).map(|_| sample(&mut state)).collect(); | |
| 1030 | + let left: Vec<u16> = (0..bh).map(|_| sample(&mut state)).collect(); | |
| 1031 | + let mut want = vec![0u16; bw * bh]; | |
| 1032 | + let mut c_above = vec![corner]; | |
| 1033 | + c_above.extend_from_slice(&above); | |
| 1034 | + libaom_filter_intra_predictor( | |
| 1035 | + &mut want, bw, bh, &c_above, &left, mode, bd, | |
| 1036 | + ); | |
| 1037 | + let mut got = vec![0u16; bw * bh]; | |
| 1038 | + predict_filter_intra( | |
| 1039 | + mode, | |
| 1040 | + Some(&above), | |
| 1041 | + Some(&left), | |
| 1042 | + Some(corner), | |
| 1043 | + bw, | |
| 1044 | + bh, | |
| 1045 | + &mut got, | |
| 1046 | + ); | |
| 1047 | + assert_eq!( | |
| 1048 | + got, want, | |
| 1049 | + "filter intra mode {mode}, {bw}x{bh}, {bd}-bit, seed {seed:#x}" | |
| 1050 | + ); | |
| 1051 | + compared += 1; | |
| 1052 | + } | |
| 1053 | + } | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + crate::decode::set_bit_depth(8); | |
| 1057 | + assert_eq!(compared, 2 * 14 * 5 * 3, "every shape/mode/seed was compared"); | |
| 1058 | + } | |
| 1059 | + | |
| 868 | 1060 | /// lane-intrarect r1: checksum-verify DC/SMOOTH/PAETH and a directional |
| 869 | 1061 | /// sweep across all three zones, `enable_edge_filter`/`smooth_neighbor` |
| 870 | 1062 | /// on and off, for eight rect shapes (both 1:2 and 1:4, both |
crates/ec-av1/src/stream.rsmodified+42 -14
| @@ -12784,6 +12784,11 @@ mod tests { | ||
| 12784 | 12784 | /// 42..61 the 8x16/16x8 strips aomenc writes filter intra on are |
| 12785 | 12785 | /// `skip=0`, which `decode_leaf_rect` refuses, so |
| 12786 | 12786 | /// `filter_intra_rect_sub16_hits` never reaches a pixel compare. |
| 12787 | + /// lane-fistrip r2 adds seeds 49 and 213 to the window: those are the two | |
| 12788 | + /// seeds measured to fire the feature on the 8-BIT twin's recipe (this | |
| 12789 | + /// arm's 10-bit encode is a different stream, so they are a widening, not | |
| 12790 | + /// a measured firing set for this recipe -- the round that un-ignores | |
| 12791 | + /// this gate must re-measure which 10-bit seeds fire it). | |
| 12787 | 12792 | #[ignore = "blocked on the coded (non-skip) rect strip below 16x16 refusal -- see doc"] |
| 12788 | 12793 | #[test] |
| 12789 | 12794 | fn a_real_aomenc_10bit_filter_intra_on_a_sub16_strip_decodes_pixel_exact() { |
| @@ -12797,7 +12802,8 @@ mod tests { | ||
| 12797 | 12802 | eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 12798 | 12803 | return; |
| 12799 | 12804 | } |
| 12800 | - let seeds: Vec<u32> = (42..62).collect(); | |
| 12805 | + let mut seeds: Vec<u32> = (42..62).collect(); | |
| 12806 | + seeds.push(213); | |
| 12801 | 12807 | ten_bit_tool_gate( |
| 12802 | 12808 | NAME, |
| 12803 | 12809 | 192, |
| @@ -12898,15 +12904,20 @@ mod tests { | ||
| 12898 | 12904 | /// [`crate::decode::filter_intra_rect_sub16_hits`], not the wider |
| 12899 | 12905 | /// `filter_intra_rect_hits`: a 32x16 strip firing filter intra would |
| 12900 | 12906 | /// satisfy that one and prove nothing about the new shapes. |
| 12901 | - /// MEASURED THIS ROUND (lane-fistrip r1), which is why it is `#[ignore]`d | |
| 12902 | - /// rather than green: over 200 seeds at cq 25 aomenc put filter intra on | |
| 12903 | - /// an 8x16/16x8 strip TWICE, and both times that strip was `skip=0`, so | |
| 12907 | + /// MEASURED (lane-fistrip r1, seeds 42..=241; r2 re-ran 50..=241), which | |
| 12908 | + /// is why it is `#[ignore]`d rather than green: over those 200 seeds at | |
| 12909 | + /// cq 25 aomenc put filter intra on an 8x16/16x8 strip exactly TWICE -- | |
| 12910 | + /// **seed 49 and seed 213** -- and both times that strip was `skip=0`, so | |
| 12904 | 12911 | /// the attempt refused at the coded-rect-strip-below-16x16 ceiling before |
| 12905 | - /// any pixel compare (177 pixel-exact matches, 23 refusals, compared | |
| 12906 | - /// sub16 delta 0, all-attempt delta 2). Un-ignore this the round that | |
| 12907 | - /// ceiling lifts; the symbol itself is pinned by | |
| 12908 | - /// [`a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag`]. | |
| 12909 | - #[ignore = "blocked on the coded (non-skip) rect strip below 16x16 refusal -- see doc"] | |
| 12912 | + /// any pixel compare (r1: 177 pixel-exact matches, 23 refusals, compared | |
| 12913 | + /// sub16 delta 0, all-attempt delta 2; r2 seeds 50..=241: 172 matches, 20 | |
| 12914 | + /// refusals, the one all-attempt hit at seed 213). BOTH firing seeds are | |
| 12915 | + /// appended to this gate's seed window below, so the un-ignore compares | |
| 12916 | + /// two real hits. Un-ignore this the round that ceiling lifts; the symbol | |
| 12917 | + /// itself is pinned by | |
| 12918 | + /// [`a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag`], whose | |
| 12919 | + /// `expect_err` must become a pixel compare in that same round. | |
| 12920 | + #[ignore = "blocked on the coded (non-skip) rect strip below 16x16 refusal -- both firing seeds (49, 213) put filter intra on a skip=0 strip; see doc"] | |
| 12910 | 12921 | #[test] |
| 12911 | 12922 | fn a_real_aomenc_stream_with_filter_intra_on_a_sub16_horz_vert_strip_decodes_pixel_exact() { |
| 12912 | 12923 | const NAME: &str = |
| @@ -12928,6 +12939,22 @@ mod tests { | ||
| 12928 | 12939 | .ok() |
| 12929 | 12940 | .and_then(|s| s.parse().ok()) |
| 12930 | 12941 | .unwrap_or(40); |
| 12942 | + // lane-fistrip r2: the two seeds that MEASURABLY fire filter intra on | |
| 12943 | + // an 8x16/16x8 strip are 49 and 213 -- the only two in seeds 42..=241 | |
| 12944 | + // (r1 measured 42..=241 and reported "all-attempt delta 2" with seed | |
| 12945 | + // 49; r2 re-ran seeds 50..=241 and found the second, log | |
| 12946 | + // `$HOME/.cache/fistrip-seedscan-r2.log`: "seed 213 refused with sub16 | |
| 12947 | + // filter-intra delta 1"). Both are appended to whatever window | |
| 12948 | + // `EC_FISTRIP_GATE_ATTEMPTS` asks for, so the un-ignore after the | |
| 12949 | + // coded-rect-strip ceiling lifts compares TWO real hits instead of | |
| 12950 | + // depending on the default window happening to contain one. | |
| 12951 | + const FIRING_SEEDS: [u32; 2] = [49, 213]; | |
| 12952 | + let mut seeds: Vec<u32> = (0..n_attempts).map(|a| 42 + a).collect(); | |
| 12953 | + for s in FIRING_SEEDS { | |
| 12954 | + if !seeds.contains(&s) { | |
| 12955 | + seeds.push(s); | |
| 12956 | + } | |
| 12957 | + } | |
| 12931 | 12958 | let cq = format!( |
| 12932 | 12959 | "--cq-level={}", |
| 12933 | 12960 | std::env::var("EC_FISTRIP_CQ").unwrap_or_else(|_| "25".into()) |
| @@ -12939,8 +12966,7 @@ mod tests { | ||
| 12939 | 12966 | // recipe reaches the feature but this decoder's other ceilings hide |
| 12940 | 12967 | // it. |
| 12941 | 12968 | let all_before = crate::decode::filter_intra_rect_sub16_hits(); |
| 12942 | - for attempt in 0..n_attempts { | |
| 12943 | - let seed = 42 + attempt; | |
| 12969 | + for &seed in &seeds { | |
| 12944 | 12970 | let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); |
| 12945 | 12971 | let y4m = Command::new("ffmpeg") |
| 12946 | 12972 | .args([ |
| @@ -13056,13 +13082,15 @@ mod tests { | ||
| 13056 | 13082 | assert!( |
| 13057 | 13083 | compared_hits > 0, |
| 13058 | 13084 | "{NAME}: no 8x16/16x8 strip used filter intra ({matched} pixel-exact matches, \ |
| 13059 | - {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" | |
| 13085 | + {named_refusals} refusals out of {} attempts) -- gate proved nothing this run", | |
| 13086 | + seeds.len() | |
| 13060 | 13087 | ); |
| 13061 | 13088 | eprintln!( |
| 13062 | 13089 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ |
| 13063 | 13090 | filter_intra_rect_sub16_hits delta={compared_hits} (all attempts including \ |
| 13064 | - refused: {}) out of {n_attempts} attempts", | |
| 13065 | - crate::decode::filter_intra_rect_sub16_hits() - all_before | |
| 13091 | + refused: {}) out of {} attempts", | |
| 13092 | + crate::decode::filter_intra_rect_sub16_hits() - all_before, | |
| 13093 | + seeds.len() | |
| 13066 | 13094 | ); |
| 13067 | 13095 | } |
| 13068 | 13096 |
lanes/fistrip-r2.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | ||
| 1 | +# lane-fistrip r2 — verifier fix-now items | |
| 2 | + | |
| 3 | +Round 1 (57f1fcb) landed the defect fix (8x16/16x8 strips never read their | |
| 4 | +`use_filter_intra` flag). This round closes the four fix-now items the verifier | |
| 5 | +raised against it. No decode-path behaviour changed: every edit is a test, a | |
| 6 | +generator script, or a gate's seed window. | |
| 7 | + | |
| 8 | +## 1. The filter-intra CDF row table is generated from the oracle, and pins every allowed shape | |
| 9 | + | |
| 10 | +`scripts/extract-filter-intra-cdfs.py` (new) reads `BLOCK_SIZES_ALL`'s order from | |
| 11 | +`av1/common/enums.h` and `default_filter_intra_cdfs` from `av1/common/entropymode.c` | |
| 12 | +in the oracle tree and prints the `(width, height, default)` rows for the shapes | |
| 13 | +`av1_filter_intra_allowed_bsize` allows. r1 had guessed 16384 for the four 1:4 | |
| 14 | +shapes; their real rows are **4x16=12770, 16x4=10368, 8x32=20229, 32x8=18101** | |
| 15 | +(entropymode.c:827-828, BLOCK_SIZES_ALL indices 16..19). | |
| 16 | + | |
| 17 | +`decode.rs` `filter_intra_classes_carry_their_own_libaom_default_row` now lists all | |
| 18 | +14 allowed shapes with their true row plus a `refused_by` note for the six with no | |
| 19 | +class today (4x8/8x4 → "a partition below 8x8 …"; 4x16/16x4 → the 16x16-level | |
| 20 | +partition refusal; 8x32/32x8 → "a 32x32 partition type this decoder does not code"), | |
| 21 | +and asserts, per shape: the class's row equals the oracle default, the row is a real | |
| 22 | +2-symbol CDF (`{p, 32768, 0}`), no two shapes share a class, and every one of | |
| 23 | +`cdf::FILTER_INTRA`'s 8 rows is claimed by exactly one shape. So the round that | |
| 24 | +lifts one of those refusals cannot land a wrong CDF row for the shape it unlocks. | |
| 25 | + | |
| 26 | +## 2. `predict_filter_intra` now has a bit-exact unit test | |
| 27 | + | |
| 28 | +`intra.rs` `filter_intra_matches_the_libaom_predictor_for_every_mode_and_shape`: | |
| 29 | +`av1_filter_intra_taps` and `av1_filter_intra_predictor_c` / | |
| 30 | +`highbd_filter_intra_predictor` (reconintra.c:807-955) are transcribed into the test | |
| 31 | +module from the C, independently of `FILTER_INTRA_TAPS`, and compared against | |
| 32 | +`predict_filter_intra` for **5 modes x 14 shapes (4x4 … 32x32, both orientations of | |
| 33 | +1:2 and 1:4) x 3 seeded random edge sets x {8-bit, 10-bit} = 420 blocks**, whole | |
| 34 | +block, bit-exact. Before this round the predictor had no unit test at all. | |
| 35 | + | |
| 36 | +## 3. Both firing seeds are inside the ignored gate's default window | |
| 37 | + | |
| 38 | +r1 recorded only the first firing seed (49) of its 200-seed measurement. r2 re-ran | |
| 39 | +just the missing window (seeds 50..=241, `EC_FISTRIP_GATE_SEED0=50 | |
| 40 | +EC_FISTRIP_GATE_ATTEMPTS=192`, 31 s): **172 pixel-exact matches, 20 named refusals, | |
| 41 | +exactly one attempt with a sub16 filter-intra delta -- seed 213**, refusing at | |
| 42 | +"a coded (non-skip) HORZ/VERT rect strip below 16x16". So over seeds 42..=241 the | |
| 43 | +firing set is exactly {49, 213}, both `skip=0`. | |
| 44 | + | |
| 45 | +The 8-bit gate now builds its seed list as `(0..n_attempts).map(|a| 42 + a)` plus | |
| 46 | +`FIRING_SEEDS = [49, 213]` (appended when the window misses them), so the default | |
| 47 | +40-attempt run -- and even a 2-attempt one -- carries both hits; the doc and the | |
| 48 | +`#[ignore]` string both name them. The 10-bit arm gets seed 213 appended too, marked | |
| 49 | +in its doc as a widening from the 8-bit recipe's measurement, NOT a measured 10-bit | |
| 50 | +firing set (its encode is a different stream; the round that un-ignores it must | |
| 51 | +re-measure). The temporary `EC_FISTRIP_GATE_SEED0` knob used for the scan was removed | |
| 52 | +again -- the seeds are in the source, not in an env var. | |
| 53 | + | |
| 54 | +## 4. MERGE NOTE | |
| 55 | + | |
| 56 | +`a_pinned_aomenc_16x8_strip_reads_its_use_filter_intra_flag` (stream.rs) asserts | |
| 57 | +`decode_stream(...).expect_err(...)` on the refusal | |
| 58 | +"a coded (non-skip) HORZ/VERT rect strip below 16x16". **The round that lifts that | |
| 59 | +refusal MUST flip this test from `expect_err` to a full pixel compare against ffmpeg** | |
| 60 | +(the fixture's strip is `skip=0`, so it becomes decodable the moment the ceiling | |
| 61 | +moves) and un-ignore | |
| 62 | +`a_real_aomenc_stream_with_filter_intra_on_a_sub16_horz_vert_strip_decodes_pixel_exact` | |
| 63 | +plus its 10-bit twin. A green `expect_err` after that lift is a stale refusal claim, | |
| 64 | +not a pass. | |
| 65 | + | |
| 66 | +## Files changed | |
| 67 | + | |
| 68 | +- `scripts/extract-filter-intra-cdfs.py` (new) — generates the `default_filter_intra_cdfs` | |
| 69 | + rows from the oracle tree; no hand transcription. | |
| 70 | +- `crates/ec-av1/src/decode.rs:16315` — the domain test now pins all 14 allowed shapes | |
| 71 | + (true rows for the six refused ones) + row shape + class uniqueness + full table coverage. | |
| 72 | +- `crates/ec-av1/src/intra.rs` (tests) — independent C port of | |
| 73 | + `av1_filter_intra_taps`/`av1_filter_intra_predictor_c` and the 420-block bit-exact compare. | |
| 74 | +- `crates/ec-av1/src/stream.rs` — 8-bit sub16 gate: seed window + `FIRING_SEEDS = [49, 213]`, | |
| 75 | + doc and `#[ignore]` string record both firing seeds; 10-bit arm: seed 213 appended with | |
| 76 | + its "widening, not measured" note. | |
| 77 | + | |
| 78 | +## EVIDENCE | |
| 79 | + | |
| 80 | +EVIDENCE: `scripts/extract-filter-intra-cdfs.py` output | run against `~/.cache/aom-oracle/src` | | |
| 81 | +14 rows, 1:4 shapes = 12770/10368/20229/18101 (r1 had 16384 for all four) | |
| 82 | + | |
| 83 | +EVIDENCE: `cargo test -p ec-av1 --lib filter_intra` | 5 passed, 0 failed, 2 ignored (14.9 s) | | |
| 84 | +`filter_intra_matches_the_libaom_predictor_for_every_mode_and_shape` compares 420 blocks | |
| 85 | +(2 depths x 14 shapes x 5 modes x 3 seeds), all bit-exact; the test asserts that count | |
| 86 | + | |
| 87 | +EVIDENCE: `$HOME/.cache/fistrip-seedscan-r2.log` | `EC_FISTRIP_GATE_SEED0=50 | |
| 88 | +EC_FISTRIP_GATE_ATTEMPTS=192` on the ignored 8-bit gate | 172 matches, 20 refusals, one | |
| 89 | +sub16 delta: "seed 213 refused with sub16 filter-intra delta 1" | |
| 90 | + | |
| 91 | +EVIDENCE: `EC_FISTRIP_GATE_ATTEMPTS=2 ... -- --ignored --nocapture` | default window of 2 | |
| 92 | +attempts + FIRING_SEEDS | "seed 49 ... delta 1", "seed 213 ... delta 1", | |
| 93 | +"filter_intra_rect_sub16_hits over ALL attempts (refused included) = 2"; the gate still | |
| 94 | +fails its `compared_hits > 0` assert, which is exactly the ceiling it is ignored for | |
| 95 | + | |
| 96 | +## Residue | |
| 97 | + | |
| 98 | +- deferred: the pixel gates (8- and 10-bit) stay `#[ignore]`d — blocked on | |
| 99 | + "a coded (non-skip) HORZ/VERT rect strip below 16x16"; un-ignore + flip the pinned | |
| 100 | + test's `expect_err` (MERGE NOTE above) the round that lifts it. | |
| 101 | +- deferred: 10-bit firing seeds are unmeasured — the 10-bit encode is a different stream; | |
| 102 | + measure when that gate un-ignores. | |
| 103 | +- accepted: `predict_filter_intra` is now proven on all 14 shapes including the four 1:4 | |
| 104 | + ones whose partition levels refuse — prediction ahead of reach, deliberately. | |
| 105 | + | |
| 106 | +## Suite totals | |
| 107 | + | |
| 108 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` under `systemd-run --user` | |
| 109 | +(log `$HOME/.cache/fistrip-suite-r2.log`, 257 s): **301 passed, 1 failed, 29 ignored** | |
| 110 | +(r1: 300/1/29 — the new predictor test is the +1). | |
| 111 | + | |
| 112 | +The single failure is the PRE-EXISTING one already red on main `df5d630`: | |
| 113 | +`decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` (32x64 nz_map offset at | |
| 114 | +display row 0 col 2), the rectsplit-r4 `[col][row]` convention clash. This round touched | |
| 115 | +neither `NZ_MAP_CTX_OFFSET_*` nor `base_ctx_rect`. | |
| 116 | +`refusal_inventory` (3 passed) and `gate_coverage` (9 passed) both green. |
scripts/extract-filter-intra-cdfs.pyadded+30 -0
| @@ -0,0 +1,30 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Emit `default_filter_intra_cdfs` as (width, height, default) straight from | |
| 3 | +the libaom oracle source, so the ec-av1 test that pins those rows is never | |
| 4 | +transcribed by hand (class: shared-oracle blindness / table-indexed-by-raw). | |
| 5 | + | |
| 6 | +Reads BLOCK_SIZES_ALL's order from av1/common/enums.h and the CDF table from | |
| 7 | +av1/common/entropymode.c, and prints the Rust literal rows for the shapes | |
| 8 | +`av1_filter_intra_allowed_bsize` allows (both sides <= 32). | |
| 9 | + | |
| 10 | + scripts/extract-filter-intra-cdfs.py [<aom source tree>] | |
| 11 | +""" | |
| 12 | +import re | |
| 13 | +import sys | |
| 14 | +from pathlib import Path | |
| 15 | + | |
| 16 | +src = Path(sys.argv[1] if len(sys.argv) > 1 else Path.home() / ".cache/aom-oracle/src") | |
| 17 | + | |
| 18 | +enums = (src / "av1/common/enums.h").read_text() | |
| 19 | +body = enums[enums.index(" BLOCK_4X4,"):enums.index(" BLOCK_SIZES_ALL,")] | |
| 20 | +sizes = [tuple(int(x) for x in m) for m in re.findall(r"BLOCK_(\d+)X(\d+),", body)] | |
| 21 | + | |
| 22 | +ent = (src / "av1/common/entropymode.c").read_text() | |
| 23 | +start = ent.index("default_filter_intra_cdfs") | |
| 24 | +table = ent[start:ent.index("};", start)] | |
| 25 | +values = [int(v) for v in re.findall(r"AOM_CDF2\((\d+)\)", table)] | |
| 26 | + | |
| 27 | +assert len(values) == len(sizes), f"{len(values)} rows vs {len(sizes)} block sizes" | |
| 28 | +for (w, h), v in zip(sizes, values): | |
| 29 | + if w <= 32 and h <= 32: | |
| 30 | + print(f" ({w}, {h}, {v}),") |