PARTITION_VERT_A/_B square sub-blocks must read libaom's _vert_ has_tr/has_bl tables
Browse files at this commit02e331ff70ff7fd1c44cf0873d07af4949f395eaParent: ad9ad14- fix
- PARTITION_VERT_A/_B square sub-blocks must read libaom's _vert_ has_tr/has_bl tables
3 changed files +126 -35
- crates/ec-av1/src/decode.rs +26 -5
- crates/ec-av1/src/encode.rs +72 -2
- crates/ec-av1/src/stream.rs +28 -28
crates/ec-av1/src/decode.rsmodified+26 -5
| @@ -764,13 +764,21 @@ pub(crate) fn sb_rect_hits() -> usize { | ||
| 764 | 764 | // `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is |
| 765 | 765 | // the counter the gate hard-asserts. |
| 766 | 766 | thread_local! { |
| 767 | - static SB_AB_HITS: std::cell::Cell<usize> = | |
| 768 | - const { std::cell::Cell::new(0) }; | |
| 767 | + static SB_AB_HITS: std::cell::Cell<[usize; 4]> = | |
| 768 | + const { std::cell::Cell::new([0; 4]) }; | |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | -/// Current value of [`SB_AB_HITS`]. | |
| 771 | +/// Current value of [`SB_AB_HITS`], summed over the four arms. | |
| 772 | 772 | pub(crate) fn sb_ab_hits() -> usize { |
| 773 | - SB_AB_HITS.with(|c| c.get()) | |
| 773 | + SB_AB_HITS.with(|c| c.get().iter().sum()) | |
| 774 | +} | |
| 775 | + | |
| 776 | +/// [`SB_AB_HITS`] split per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, | |
| 777 | +/// `_VERT_A`, `_VERT_B` order -- what the gate hard-asserts arm by arm, so a | |
| 778 | +/// run where aomenc's RD only ever picked (say) `HORZ_A` cannot pass off as | |
| 779 | +/// proof of all four. | |
| 780 | +pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] { | |
| 781 | + SB_AB_HITS.with(std::cell::Cell::get) | |
| 774 | 782 | } |
| 775 | 783 | |
| 776 | 784 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane |
| @@ -7532,6 +7540,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 7532 | 7540 | // width/height swapped (TL, BL, right 16x32 |
| 7533 | 7541 | // strip). |
| 7534 | 7542 | INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1)); |
| 7543 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 7535 | 7544 | decode_block( |
| 7536 | 7545 | &mut dec, |
| 7537 | 7546 | &mut cdfs, |
| @@ -7606,6 +7615,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 7606 | 7615 | // (libaom decode_partition VERT_B: left |
| 7607 | 7616 | // strip, TR, BR). |
| 7608 | 7617 | INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1)); |
| 7618 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 7609 | 7619 | decode_block_rect( |
| 7610 | 7620 | &mut dec, |
| 7611 | 7621 | &mut cdfs, |
| @@ -7758,7 +7768,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 7758 | 7768 | // TR, BR). The pieces are exactly the ones already proven |
| 7759 | 7769 | // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and |
| 7760 | 7770 | // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above. |
| 7761 | - SB_AB_HITS.with(|c| c.set(c.get() + 1)); | |
| 7771 | + SB_AB_HITS.with(|c| { | |
| 7772 | + let mut h = c.get(); | |
| 7773 | + h[part - PARTITION_HORZ_A] += 1; | |
| 7774 | + c.set(h); | |
| 7775 | + }); | |
| 7776 | + // lane-part32 r5: only the two VERTICAL arms reorder the | |
| 7777 | + // square sub-blocks (TL, BL, TR, BR), so only they switch | |
| 7778 | + // libaom's `has_tr`/`has_bl` tables. | |
| 7779 | + let _vert_ab = (part == PARTITION_VERT_A || part == PARTITION_VERT_B) | |
| 7780 | + .then(crate::encode::Reach::vert_ab_partition); | |
| 7762 | 7781 | macro_rules! square32 { |
| 7763 | 7782 | ($at:expr) => { |
| 7764 | 7783 | decode_block( |
| @@ -13427,6 +13446,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 13427 | 13446 | // lane-partab r1: mirror of PARTITION_HORZ_A with |
| 13428 | 13447 | // width/height swapped (TL, BL, right 16x32 strip). |
| 13429 | 13448 | PARTAB_HITS.with(|c| c.set(c.get() + 1)); |
| 13449 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 13430 | 13450 | decode_inter_block( |
| 13431 | 13451 | &mut dec, |
| 13432 | 13452 | &mut cdfs, |
| @@ -13588,6 +13608,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 13588 | 13608 | // 16x16 squares on the right (libaom decode_partition |
| 13589 | 13609 | // PARTITION_VERT_B: left strip, TR, BR). |
| 13590 | 13610 | PARTAB_HITS.with(|c| c.set(c.get() + 1)); |
| 13611 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 13591 | 13612 | decode_inter_block( |
| 13592 | 13613 | &mut dec, |
| 13593 | 13614 | &mut cdfs, |
crates/ec-av1/src/encode.rsmodified+72 -2
| @@ -1043,6 +1043,59 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | ||
| 1043 | 1043 | ], |
| 1044 | 1044 | ]; |
| 1045 | 1045 | |
| 1046 | +/// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by | |
| 1047 | +/// [`Reach::table`] exactly like [`HAS_TOP_RIGHT`]: inside a | |
| 1048 | +/// `PARTITION_VERT_A`/`_B` the square sub-blocks are visited TL, BL, TR, BR | |
| 1049 | +/// rather than in raster order, so the bottom-left square's top-right | |
| 1050 | +/// neighbour is the partition's own right-hand rectangle -- not yet decoded. | |
| 1051 | +/// libaom switches tables on the partition type (`get_has_tr_table`); the | |
| 1052 | +/// ordinary table says 1 where this one says 0 (32x32 at row 1 col 0: | |
| 1053 | +/// `95` bit 4 = 1 vs `15` bit 4 = 0), which is exactly the case | |
| 1054 | +/// lane-part32 r5 caught reading undecoded samples. | |
| 1055 | +const HAS_TOP_RIGHT_VERT: [&[u8]; 3] = [ | |
| 1056 | + // has_tr_vert_16x16 | |
| 1057 | + &[255, 0, 119, 0, 127, 0, 119, 0], | |
| 1058 | + // has_tr_vert_32x32 | |
| 1059 | + &[15, 7], | |
| 1060 | + // has_tr_vert_8x8 | |
| 1061 | + &[ | |
| 1062 | + 255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, 255, 127, 0, 0, 119, 119, | |
| 1063 | + 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, | |
| 1064 | + ], | |
| 1065 | +]; | |
| 1066 | + | |
| 1067 | +/// [`HAS_TOP_RIGHT_VERT`]'s sibling, `has_bl_vert_tables`. | |
| 1068 | +const HAS_BOTTOM_LEFT_VERT: [&[u8]; 3] = [ | |
| 1069 | + // has_bl_vert_16x16 | |
| 1070 | + &[254, 16, 254, 0, 254, 16, 254, 0], | |
| 1071 | + // has_bl_vert_32x32 | |
| 1072 | + &[14, 14], | |
| 1073 | + // has_bl_vert_8x8 | |
| 1074 | + &[ | |
| 1075 | + 254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, 254, 255, 16, 17, 254, | |
| 1076 | + 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, | |
| 1077 | + ], | |
| 1078 | +]; | |
| 1079 | + | |
| 1080 | +thread_local! { | |
| 1081 | + /// Set for the duration of a `PARTITION_VERT_A`/`_B`'s own sub-blocks | |
| 1082 | + /// (see [`Reach::vert_ab_partition`]) -- libaom carries the partition | |
| 1083 | + /// type down into `has_top_right`/`has_bottom_left` as an argument, and | |
| 1084 | + /// threading one bool through this crate's already twenty-argument | |
| 1085 | + /// `decode_block` would touch every call site instead of the two arms | |
| 1086 | + /// that need it. | |
| 1087 | + static VERT_AB_PARTITION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | |
| 1088 | +} | |
| 1089 | + | |
| 1090 | +/// Restores [`VERT_AB_PARTITION`] to what it was when the guard was made. | |
| 1091 | +pub(crate) struct VertAbGuard(bool); | |
| 1092 | + | |
| 1093 | +impl Drop for VertAbGuard { | |
| 1094 | + fn drop(&mut self) { | |
| 1095 | + VERT_AB_PARTITION.with(|c| c.set(self.0)); | |
| 1096 | + } | |
| 1097 | +} | |
| 1098 | + | |
| 1046 | 1099 | /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp |
| 1047 | 1100 | /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 |
| 1048 | 1101 | /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is |
| @@ -1113,6 +1166,15 @@ impl Reach { | ||
| 1113 | 1166 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1114 | 1167 | } |
| 1115 | 1168 | |
| 1169 | + /// Marks every [`Reach::of`] made until the returned guard drops as being | |
| 1170 | + /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` / | |
| 1171 | + /// `get_has_bl_table` partition argument). Rectangular sub-blocks are | |
| 1172 | + /// unaffected: libaom's own comment says vertical rectangles keep their | |
| 1173 | + /// non-vert table, which is what [`Reach::of_rect`] already reads. | |
| 1174 | + pub(crate) fn vert_ab_partition() -> VertAbGuard { | |
| 1175 | + VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true))) | |
| 1176 | + } | |
| 1177 | + | |
| 1116 | 1178 | /// Neither, which is all a mode that reads no further than its own edges |
| 1117 | 1179 | /// needs. |
| 1118 | 1180 | pub(crate) fn none() -> Self { |
| @@ -1145,7 +1207,11 @@ impl Reach { | ||
| 1145 | 1207 | // reference pixels), never a stream desync (Reach never gates a |
| 1146 | 1208 | // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4` |
| 1147 | 1209 | // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row. |
| 1148 | - let table = HAS_TOP_RIGHT[Self::table(side)]; | |
| 1210 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1211 | + HAS_TOP_RIGHT_VERT[Self::table(side)] | |
| 1212 | + } else { | |
| 1213 | + HAS_TOP_RIGHT[Self::table(side)] | |
| 1214 | + }; | |
| 1149 | 1215 | Self::bit( |
| 1150 | 1216 | table, |
| 1151 | 1217 | (row * Self::table_stride(side) + col) % (table.len() * 8), |
| @@ -1165,7 +1231,11 @@ impl Reach { | ||
| 1165 | 1231 | return false; |
| 1166 | 1232 | } |
| 1167 | 1233 | // corner-cut: see `top_right`'s note -- same clamp, same ceiling. |
| 1168 | - let table = HAS_BOTTOM_LEFT[Self::table(side)]; | |
| 1234 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1235 | + HAS_BOTTOM_LEFT_VERT[Self::table(side)] | |
| 1236 | + } else { | |
| 1237 | + HAS_BOTTOM_LEFT[Self::table(side)] | |
| 1238 | + }; | |
| 1169 | 1239 | Self::bit( |
| 1170 | 1240 | table, |
| 1171 | 1241 | (row * Self::table_stride(side) + col) % (table.len() * 8), |
crates/ec-av1/src/stream.rsmodified+28 -28
| @@ -9460,17 +9460,15 @@ mod tests { | ||
| 9460 | 9460 | msg.contains("unsupported"), |
| 9461 | 9461 | "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" |
| 9462 | 9462 | ); |
| 9463 | - // r2: `--enable-ab-partitions=0` does NOT stop aomenc | |
| 9464 | - // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B | |
| 9465 | - // (`partition_w64` value 4-7) even with | |
| 9466 | - // `--min/max-partition-size=32/64` -- a real, separate | |
| 9467 | - // encoder quirk (AB-at-64 is a different, unlanded | |
| 9468 | - // capability, lane-partab's territory is 32x32 and | |
| 9469 | - // below only) discovered live this round, not this | |
| 9470 | - // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT | |
| 9471 | - // (values 0-3) are this gate's territory; a real | |
| 9472 | - // HORZ/VERT (1/2) must still decode pixel-exact, which | |
| 9473 | - // `sb_rect_hits() > 0` below hard-proves. | |
| 9463 | + // r5: the four SB-level AB arms (`partition_w64` 4-7) | |
| 9464 | + // decode since this round, so the only partition refusal | |
| 9465 | + // left at 64x64 is the 1:4 pair (values 8/9, four | |
| 9466 | + // 64x16/16x64 strips, whose luma TX_64X16 this decoder | |
| 9467 | + // has no transform for); the refusals this loop actually | |
| 9468 | + // counts on these fixtures are the pre-existing | |
| 9469 | + // screen-content-palette strip one. Every refusal is | |
| 9470 | + // named, so a genuine decode failure still fails the | |
| 9471 | + // assert above rather than skipping. | |
| 9474 | 9472 | named_refusals += 1; |
| 9475 | 9473 | eprintln!("seed {seed} refusal: {msg}"); |
| 9476 | 9474 | continue; |
| @@ -9621,17 +9619,15 @@ mod tests { | ||
| 9621 | 9619 | msg.contains("unsupported"), |
| 9622 | 9620 | "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" |
| 9623 | 9621 | ); |
| 9624 | - // r2: `--enable-ab-partitions=0` does NOT stop aomenc | |
| 9625 | - // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B | |
| 9626 | - // (`partition_w64` value 4-7) even with | |
| 9627 | - // `--min/max-partition-size=32/64` -- a real, separate | |
| 9628 | - // encoder quirk (AB-at-64 is a different, unlanded | |
| 9629 | - // capability, lane-partab's territory is 32x32 and | |
| 9630 | - // below only) discovered live this round, not this | |
| 9631 | - // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT | |
| 9632 | - // (values 0-3) are this gate's territory; a real | |
| 9633 | - // HORZ/VERT (1/2) must still decode pixel-exact, which | |
| 9634 | - // `sb_rect_hits() > 0` below hard-proves. | |
| 9622 | + // r5: the four SB-level AB arms (`partition_w64` 4-7) | |
| 9623 | + // decode since this round, so the only partition refusal | |
| 9624 | + // left at 64x64 is the 1:4 pair (values 8/9, four | |
| 9625 | + // 64x16/16x64 strips, whose luma TX_64X16 this decoder | |
| 9626 | + // has no transform for); the refusals this loop actually | |
| 9627 | + // counts on these fixtures are the pre-existing | |
| 9628 | + // screen-content-palette strip one. Every refusal is | |
| 9629 | + // named, so a genuine decode failure still fails the | |
| 9630 | + // assert above rather than skipping. | |
| 9635 | 9631 | named_refusals += 1; |
| 9636 | 9632 | eprintln!("seed {seed} refusal: {msg}"); |
| 9637 | 9633 | continue; |
| @@ -9661,14 +9657,18 @@ mod tests { | ||
| 9661 | 9657 | matched > 0, |
| 9662 | 9658 | "{NAME}: every attempt refused; the gate never decoded a stream" |
| 9663 | 9659 | ); |
| 9664 | - assert!( | |
| 9665 | - crate::decode::sb_ab_hits() > 0, | |
| 9666 | - "{NAME}: zero superblock-level AB blocks fired ({matched} matches, \ | |
| 9667 | - {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" | |
| 9668 | - ); | |
| 9660 | + let arms = crate::decode::sb_ab_hits_by_arm(); | |
| 9661 | + for (i, name) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { | |
| 9662 | + assert!( | |
| 9663 | + arms[i] > 0, | |
| 9664 | + "{NAME}: zero superblock-level PARTITION_{name} blocks fired (arms={arms:?}, \ | |
| 9665 | + {matched} matches, {named_refusals} refusals out of {n_attempts}) -- that arm \ | |
| 9666 | + proved nothing this run" | |
| 9667 | + ); | |
| 9668 | + } | |
| 9669 | 9669 | eprintln!( |
| 9670 | 9670 | "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ |
| 9671 | - {n_attempts}, sb_ab_hits={}", | |
| 9671 | + {n_attempts}, sb_ab_hits={} arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}", | |
| 9672 | 9672 | crate::decode::sb_ab_hits() |
| 9673 | 9673 | ); |
| 9674 | 9674 | } |