forge
Explore
Log in

Don't you dare go Hollow

PARTITION_VERT_A/_B square sub-blocks must read libaom's _vert_ has_tr/has_bl tables

Browse files at this commit

02e331ff70ff7fd1c44cf0873d07af4949f395eaAhmet Kaan GümüşParent: ad9ad14
  • fix
    • PARTITION_VERT_A/_B square sub-blocks must read libaom's _vert_ has_tr/has_bl tables
Show full message
fix(av1): PARTITION_VERT_A/_B square sub-blocks must read libaom's _vert_ has_tr/has_bl tables

lane-part32 r5. A VERT_A/VERT_B partition visits its square sub-blocks
TL, BL, TR, BR -- not raster order -- so the bottom-left square's
top-right neighbour is the partition's own right-hand rectangle, which
is not decoded yet. libaom switches has_top_right/has_bottom_left onto
has_tr_vert_*/has_bl_vert_* for exactly these two partition types
(reconintra.c get_has_tr_table); this crate's `Reach` had only the
raster tables, so the BL 32x32 of an SB-level VERT_A predicted from
never-written samples (has_tr_32x32[0] bit 4 = 1 vs
has_tr_vert_32x32[0] bit 4 = 0).

Symptom on the pinned seed-63 stream: every symbol in sync with the
oracle (aomdec EC_TRACE/EC_TRACE_MODE agree on partition=6 and on every
mode, and the msac range at mi_col=40 matches ours exactly, 53240) yet
the prefilter reconstruction diverges from x=157 of the BL square, and
the 32x64 strip to its right then DC-predicts off that corrupted left
column (107 instead of ~149) and the next superblock row's V_PRED
copies it down -- 4683 luma pixels wrong from one availability bit.

Also lifts the r4 refusal narrowing into a proven capability: the four
SB-level AB arms now decode pixel-exact, hard-asserted arm by arm
(sb_ab_hits_by_arm), and PARTITION_HORZ_4/VERT_4 at 64x64 remain the
only refused 64x64 partition types.
crates/ec-av1/src/decode.rsmodified+26 -5
@@ -764,13 +764,21 @@ pub(crate) fn sb_rect_hits() -> usize {
764 // `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is764 // `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is
765 // the counter the gate hard-asserts.765 // the counter the gate hard-asserts.
766 thread_local! {766 thread_local! {
767- static SB_AB_HITS: std::cell::Cell<usize> =767+ static SB_AB_HITS: std::cell::Cell<[usize; 4]> =
768- const { std::cell::Cell::new(0) };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 pub(crate) fn sb_ab_hits() -> usize {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 // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane784 // 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 // width/height swapped (TL, BL, right 16x327540 // width/height swapped (TL, BL, right 16x32
7533 // strip).7541 // strip).
7534 INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1));7542 INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1));
7543+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
7535 decode_block(7544 decode_block(
7536 &mut dec,7545 &mut dec,
7537 &mut cdfs,7546 &mut cdfs,
@@ -7606,6 +7615,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7606 // (libaom decode_partition VERT_B: left7615 // (libaom decode_partition VERT_B: left
7607 // strip, TR, BR).7616 // strip, TR, BR).
7608 INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1));7617 INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1));
7618+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
7609 decode_block_rect(7619 decode_block_rect(
7610 &mut dec,7620 &mut dec,
7611 &mut cdfs,7621 &mut cdfs,
@@ -7758,7 +7768,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7758 // TR, BR). The pieces are exactly the ones already proven7768 // TR, BR). The pieces are exactly the ones already proven
7759 // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and7769 // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and
7760 // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above.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 macro_rules! square32 {7781 macro_rules! square32 {
7763 ($at:expr) => {7782 ($at:expr) => {
7764 decode_block(7783 decode_block(
@@ -13427,6 +13446,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
13427 // lane-partab r1: mirror of PARTITION_HORZ_A with13446 // lane-partab r1: mirror of PARTITION_HORZ_A with
13428 // width/height swapped (TL, BL, right 16x32 strip).13447 // width/height swapped (TL, BL, right 16x32 strip).
13429 PARTAB_HITS.with(|c| c.set(c.get() + 1));13448 PARTAB_HITS.with(|c| c.set(c.get() + 1));
13449+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
13430 decode_inter_block(13450 decode_inter_block(
13431 &mut dec,13451 &mut dec,
13432 &mut cdfs,13452 &mut cdfs,
@@ -13588,6 +13608,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
13588 // 16x16 squares on the right (libaom decode_partition13608 // 16x16 squares on the right (libaom decode_partition
13589 // PARTITION_VERT_B: left strip, TR, BR).13609 // PARTITION_VERT_B: left strip, TR, BR).
13590 PARTAB_HITS.with(|c| c.set(c.get() + 1));13610 PARTAB_HITS.with(|c| c.set(c.get() + 1));
13611+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
13591 decode_inter_block(13612 decode_inter_block(
13592 &mut dec,13613 &mut dec,
13593 &mut cdfs,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 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp1099 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp
1047 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x321100 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32
1048 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is1101 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is
@@ -1113,6 +1166,15 @@ impl Reach {
1113 Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8))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 /// Neither, which is all a mode that reads no further than its own edges1178 /// Neither, which is all a mode that reads no further than its own edges
1117 /// needs.1179 /// needs.
1118 pub(crate) fn none() -> Self {1180 pub(crate) fn none() -> Self {
@@ -1145,7 +1207,11 @@ impl Reach {
1145 // reference pixels), never a stream desync (Reach never gates a1207 // reference pixels), never a stream desync (Reach never gates a
1146 // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4`1208 // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4`
1147 // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row.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 Self::bit(1215 Self::bit(
1150 table,1216 table,
1151 (row * Self::table_stride(side) + col) % (table.len() * 8),1217 (row * Self::table_stride(side) + col) % (table.len() * 8),
@@ -1165,7 +1231,11 @@ impl Reach {
1165 return false;1231 return false;
1166 }1232 }
1167 // corner-cut: see `top_right`'s note -- same clamp, same ceiling.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 Self::bit(1239 Self::bit(
1170 table,1240 table,
1171 (row * Self::table_stride(side) + col) % (table.len() * 8),1241 (row * Self::table_stride(side) + col) % (table.len() * 8),
crates/ec-av1/src/stream.rsmodified+26 -26
@@ -9460,17 +9460,15 @@ mod tests {
9460 msg.contains("unsupported"),9460 msg.contains("unsupported"),
9461 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"9461 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
9462 );9462 );
9463- // r2: `--enable-ab-partitions=0` does NOT stop aomenc9463+ // r5: the four SB-level AB arms (`partition_w64` 4-7)
9464- // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B9464+ // decode since this round, so the only partition refusal
9465- // (`partition_w64` value 4-7) even with9465+ // left at 64x64 is the 1:4 pair (values 8/9, four
9466- // `--min/max-partition-size=32/64` -- a real, separate9466+ // 64x16/16x64 strips, whose luma TX_64X16 this decoder
9467- // encoder quirk (AB-at-64 is a different, unlanded9467+ // has no transform for); the refusals this loop actually
9468- // capability, lane-partab's territory is 32x32 and9468+ // counts on these fixtures are the pre-existing
9469- // below only) discovered live this round, not this9469+ // screen-content-palette strip one. Every refusal is
9470- // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT9470+ // named, so a genuine decode failure still fails the
9471- // (values 0-3) are this gate's territory; a real9471+ // assert above rather than skipping.
9472- // HORZ/VERT (1/2) must still decode pixel-exact, which
9473- // `sb_rect_hits() > 0` below hard-proves.
9474 named_refusals += 1;9472 named_refusals += 1;
9475 eprintln!("seed {seed} refusal: {msg}");9473 eprintln!("seed {seed} refusal: {msg}");
9476 continue;9474 continue;
@@ -9621,17 +9619,15 @@ mod tests {
9621 msg.contains("unsupported"),9619 msg.contains("unsupported"),
9622 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"9620 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
9623 );9621 );
9624- // r2: `--enable-ab-partitions=0` does NOT stop aomenc9622+ // r5: the four SB-level AB arms (`partition_w64` 4-7)
9625- // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B9623+ // decode since this round, so the only partition refusal
9626- // (`partition_w64` value 4-7) even with9624+ // left at 64x64 is the 1:4 pair (values 8/9, four
9627- // `--min/max-partition-size=32/64` -- a real, separate9625+ // 64x16/16x64 strips, whose luma TX_64X16 this decoder
9628- // encoder quirk (AB-at-64 is a different, unlanded9626+ // has no transform for); the refusals this loop actually
9629- // capability, lane-partab's territory is 32x32 and9627+ // counts on these fixtures are the pre-existing
9630- // below only) discovered live this round, not this9628+ // screen-content-palette strip one. Every refusal is
9631- // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT9629+ // named, so a genuine decode failure still fails the
9632- // (values 0-3) are this gate's territory; a real9630+ // assert above rather than skipping.
9633- // HORZ/VERT (1/2) must still decode pixel-exact, which
9634- // `sb_rect_hits() > 0` below hard-proves.
9635 named_refusals += 1;9631 named_refusals += 1;
9636 eprintln!("seed {seed} refusal: {msg}");9632 eprintln!("seed {seed} refusal: {msg}");
9637 continue;9633 continue;
@@ -9661,14 +9657,18 @@ mod tests {
9661 matched > 0,9657 matched > 0,
9662 "{NAME}: every attempt refused; the gate never decoded a stream"9658 "{NAME}: every attempt refused; the gate never decoded a stream"
9663 );9659 );
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() {
9664 assert!(9662 assert!(
9665- crate::decode::sb_ab_hits() > 0,9663+ arms[i] > 0,
9666- "{NAME}: zero superblock-level AB blocks fired ({matched} matches, \9664+ "{NAME}: zero superblock-level PARTITION_{name} blocks fired (arms={arms:?}, \
9667- {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run"9665+ {matched} matches, {named_refusals} refusals out of {n_attempts}) -- that arm \
9666+ proved nothing this run"
9668 );9667 );
9668+ }
9669 eprintln!(9669 eprintln!(
9670 "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \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 crate::decode::sb_ab_hits()9672 crate::decode::sb_ab_hits()
9673 );9673 );
9674 }9674 }