Every rect block shape gets its own has_tr/has_bl row -- a `_` arm sent 16x8 strips to libaom's has_tr_32x16
Browse files at this commit2159b114983b0a4926038a09377f9ca7cce5162fParent: 43c2434- fix
- every rect block shape gets its own has_tr/has_bl row -- a `_` arm sent 16x8 strips to libaom's has_tr_32x16
5 changed files +655 -42
- crates/ec-av1/src/decode.rs +24 -0
- crates/ec-av1/src/encode.rs +197 -40
- crates/ec-av1/src/stream.rs +231 -2
- lanes/COMMON-20260901.md +87 -0
- lanes/tx4x8-r3.report.md +116 -0
crates/ec-av1/src/decode.rsmodified+24 -0
| @@ -949,6 +949,14 @@ thread_local! { | |||
| 949 | /// counter from [`TX_DEPTH_HITS`] (which every square path also bumps) so | 949 | /// counter from [`TX_DEPTH_HITS`] (which every square path also bumps) so |
| 950 | /// the gate can prove THIS path fired. | 950 | /// the gate can prove THIS path fired. |
| 951 | static RECT8_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 951 | static RECT8_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 952 | + /// 16x8/8x16 intra strips whose prediction actually read past the block's | ||
| 953 | + /// own width (above-right) or height (below-left) -- the samples | ||
| 954 | + /// `Reach::of_rect` decides on, and the only ones a wrong `has_tr_*`/ | ||
| 955 | + /// `has_bl_*` table row can corrupt (lane-tx4x8 r3). | ||
| 956 | + static RECT_STRIP_REACH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 957 | + /// Every 16x8/8x16 intra strip predicted, reaching or not -- the | ||
| 958 | + /// denominator [`RECT_STRIP_REACH_HITS`] is a fraction of. | ||
| 959 | + static RECT_STRIP_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 952 | } | 960 | } |
| 953 | 961 | ||
| 954 | /// Current value of [`RECT8_SPLIT_TX_HITS`]. | 962 | /// Current value of [`RECT8_SPLIT_TX_HITS`]. |
| @@ -956,6 +964,16 @@ pub(crate) fn rect8_split_tx_hits() -> usize { | |||
| 956 | RECT8_SPLIT_TX_HITS.with(|c| c.get()) | 964 | RECT8_SPLIT_TX_HITS.with(|c| c.get()) |
| 957 | } | 965 | } |
| 958 | 966 | ||
| 967 | +/// Current value of [`RECT_STRIP_PRED_HITS`]. | ||
| 968 | +pub(crate) fn rect_strip_pred_hits() -> usize { | ||
| 969 | + RECT_STRIP_PRED_HITS.with(|c| c.get()) | ||
| 970 | +} | ||
| 971 | + | ||
| 972 | +/// Current value of [`RECT_STRIP_REACH_HITS`]. | ||
| 973 | +pub(crate) fn rect_strip_reach_hits() -> usize { | ||
| 974 | + RECT_STRIP_REACH_HITS.with(|c| c.get()) | ||
| 975 | +} | ||
| 976 | + | ||
| 959 | /// Current value of [`TX4X8_CODED_HITS`]. | 977 | /// Current value of [`TX4X8_CODED_HITS`]. |
| 960 | pub(crate) fn tx4x8_coded_hits() -> usize { | 978 | pub(crate) fn tx4x8_coded_hits() -> usize { |
| 961 | TX4X8_CODED_HITS.with(|c| c.get()) | 979 | TX4X8_CODED_HITS.with(|c| c.get()) |
| @@ -4766,6 +4784,12 @@ impl PlaneBuf { | |||
| 4766 | }); | 4784 | }); |
| 4767 | let corner = | 4785 | let corner = |
| 4768 | (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); | 4786 | (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); |
| 4787 | + if matches!((bw, bh), (16, 8) | (8, 16)) { | ||
| 4788 | + RECT_STRIP_PRED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 4789 | + if across > own_across || down > own_down { | ||
| 4790 | + RECT_STRIP_REACH_HITS.with(|h| h.set(h.get() + 1)); | ||
| 4791 | + } | ||
| 4792 | + } | ||
| 4769 | (above, left, corner) | 4793 | (above, left, corner) |
| 4770 | } | 4794 | } |
| 4771 | 4795 | ||
crates/ec-av1/src/encode.rsmodified+197 -40
| @@ -1070,50 +1070,94 @@ const HAS_BOTTOM_LEFT: [&[u8]; 4] = [ | |||
| 1070 | ], | 1070 | ], |
| 1071 | ]; | 1071 | ]; |
| 1072 | 1072 | ||
| 1073 | -/// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp | 1073 | +/// The `has_tr_*` / `has_bl_*` tables for every rectangular shape this |
| 1074 | -/// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 | 1074 | +/// decoder codes (libaom `reconintra.c`, generated from the oracle's source |
| 1075 | -/// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is | 1075 | +/// so no byte is retyped). Each is indexed by |
| 1076 | -/// 16-wide. | 1076 | +/// `(blk_row_in_sb << (5 - log2(bw / 4))) + blk_col_in_sb`, i.e. row stride |
| 1077 | -const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; | 1077 | +/// `128 / bw` bits ([`Reach::table_stride`]) on libaom's 128-pixel |
| 1078 | -/// `has_bl_32x16`/`has_bl_16x32`, same source, same order. | 1078 | +/// superblock grid; on this crate's 64-pixel superblock the highest index a |
| 1079 | -const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; | 1079 | +/// shape can reach stays inside its own table, so no wrap is involved. |
| 1080 | - | 1080 | +/// |
| 1081 | -/// `has_tr_4x8` (libaom `reconintra.c`), transcribed verbatim -- lane-tx4x8's | 1081 | +/// lane-tx4x8 r3: the previous two-row `HAS_TOP_RIGHT_RECT`/ |
| 1082 | -/// `PARTITION_VERT` leaf of an 8x8 block. Row stride is | 1082 | +/// `HAS_BOTTOM_LEFT_RECT` pair held 32x16/16x32 only and a `_` arm routed |
| 1083 | -/// [`Reach::table_stride`]`(4)` = 32 bits, as for every other entry of | 1083 | +/// every other shape -- 16x8 strips among them -- to the 32x16 row, wrong at |
| 1084 | -/// libaom's own `has_tr_tables`. | 1084 | +/// 10 of the 21 reachable superblock positions for above-right and 7 for |
| 1085 | -const HAS_TR_4X8: [u8; 64] = [ | 1085 | +/// below-left. |
| 1086 | - 255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, | 1086 | +/// `has_tr_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 1087 | - 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, | 1087 | +const HAS_TR_4X8: [u8; 64] = [255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119]; |
| 1088 | - 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, | 1088 | +/// `has_bl_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 1089 | - 127, 127, 127, 119, 119, 119, 119, | 1089 | +const HAS_BL_4X8: [u8; 64] = [16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0]; |
| 1090 | -]; | 1090 | +/// `has_tr_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 1091 | -/// `has_tr_8x4`, same source -- the `PARTITION_HORZ` leaf. | 1091 | +const HAS_TR_8X4: [u8; 64] = [255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0]; |
| 1092 | -const HAS_TR_8X4: [u8; 64] = [ | 1092 | +/// `has_bl_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 1093 | - 255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, | 1093 | +const HAS_BL_8X4: [u8; 64] = [254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0]; |
| 1094 | - 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, | 1094 | +/// `has_tr_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 1095 | - 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, | 1095 | +const HAS_TR_8X16: [u8; 16] = [255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119]; |
| 1096 | -]; | 1096 | +/// `has_bl_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 1097 | -/// `has_bl_4x8`, same source. | 1097 | +const HAS_BL_8X16: [u8; 16] = [16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0]; |
| 1098 | -const HAS_BL_4X8: [u8; 64] = [ | 1098 | +/// `has_tr_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). |
| 1099 | - 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, | 1099 | +const HAS_TR_16X8: [u8; 16] = [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0]; |
| 1100 | - 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, | 1100 | +/// `has_bl_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). |
| 1101 | - 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, | 1101 | +const HAS_BL_16X8: [u8; 16] = [254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0]; |
| 1102 | -]; | 1102 | +/// `has_tr_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). |
| 1103 | -/// `has_bl_8x4`, same source. | 1103 | +const HAS_TR_16X32: [u8; 4] = [255, 119, 127, 119]; |
| 1104 | -const HAS_BL_8X4: [u8; 64] = [ | 1104 | +/// `has_bl_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). |
| 1105 | - 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, | 1105 | +const HAS_BL_16X32: [u8; 4] = [16, 0, 16, 0]; |
| 1106 | - 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, | 1106 | +/// `has_tr_32x16` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 4 bits (`128 / 32`). |
| 1107 | - 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, | 1107 | +const HAS_TR_32X16: [u8; 4] = [15, 5, 7, 5]; |
| 1108 | -]; | 1108 | +/// `has_bl_32x16` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 4 bits (`128 / 32`). |
| 1109 | +const HAS_BL_32X16: [u8; 4] = [78, 14, 78, 14]; | ||
| 1110 | +/// `has_tr_32x64` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 4 bits (`128 / 32`). | ||
| 1111 | +const HAS_TR_32X64: [u8; 1] = [127]; | ||
| 1112 | +/// `has_bl_32x64` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 4 bits (`128 / 32`). | ||
| 1113 | +const HAS_BL_32X64: [u8; 1] = [0]; | ||
| 1114 | +/// `has_tr_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). | ||
| 1115 | +const HAS_TR_64X32: [u8; 1] = [19]; | ||
| 1116 | +/// `has_bl_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). | ||
| 1117 | +const HAS_BL_64X32: [u8; 1] = [34]; | ||
| 1118 | +/// `has_tr_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | ||
| 1119 | +const HAS_TR_4X16: [u8; 32] = [255, 255, 255, 255, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127, 255, 255, 255, 127, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127]; | ||
| 1120 | +/// `has_bl_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | ||
| 1121 | +const HAS_BL_4X16: [u8; 32] = [0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0]; | ||
| 1122 | +/// `has_tr_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | ||
| 1123 | +const HAS_TR_16X4: [u8; 32] = [255, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0, 127, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0]; | ||
| 1124 | +/// `has_bl_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | ||
| 1125 | +const HAS_BL_16X4: [u8; 32] = [254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0, 254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0]; | ||
| 1126 | +/// `has_tr_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | ||
| 1127 | +const HAS_TR_8X32: [u8; 8] = [255, 255, 127, 127, 255, 127, 127, 127]; | ||
| 1128 | +/// `has_bl_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | ||
| 1129 | +const HAS_BL_8X32: [u8; 8] = [0, 1, 0, 0, 0, 1, 0, 0]; | ||
| 1130 | +/// `has_tr_32x8` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 4 bits (`128 / 32`). | ||
| 1131 | +const HAS_TR_32X8: [u8; 8] = [15, 0, 5, 0, 7, 0, 5, 0]; | ||
| 1132 | +/// `has_bl_32x8` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 4 bits (`128 / 32`). | ||
| 1133 | +const HAS_BL_32X8: [u8; 8] = [238, 78, 238, 14, 238, 78, 238, 14]; | ||
| 1134 | +/// `has_tr_16x64` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 8 bits (`128 / 16`). | ||
| 1135 | +const HAS_TR_16X64: [u8; 2] = [255, 127]; | ||
| 1136 | +/// `has_bl_16x64` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 8 bits (`128 / 16`). | ||
| 1137 | +const HAS_BL_16X64: [u8; 2] = [0, 0]; | ||
| 1138 | +/// `has_tr_64x16` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 2 bits (`128 / 64`). | ||
| 1139 | +const HAS_TR_64X16: [u8; 2] = [3, 1]; | ||
| 1140 | +/// `has_bl_64x16` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 2 bits (`128 / 64`). | ||
| 1141 | +const HAS_BL_64X16: [u8; 2] = [42, 42]; | ||
| 1109 | 1142 | ||
| 1110 | /// The `has_tr_*`/`has_bl_*` row for one rectangular block shape. | 1143 | /// The `has_tr_*`/`has_bl_*` row for one rectangular block shape. |
| 1111 | fn rect_reach_tables(bw: usize, bh: usize) -> (&'static [u8], &'static [u8]) { | 1144 | fn rect_reach_tables(bw: usize, bh: usize) -> (&'static [u8], &'static [u8]) { |
| 1112 | match (bw, bh) { | 1145 | match (bw, bh) { |
| 1113 | (4, 8) => (&HAS_TR_4X8, &HAS_BL_4X8), | 1146 | (4, 8) => (&HAS_TR_4X8, &HAS_BL_4X8), |
| 1114 | (8, 4) => (&HAS_TR_8X4, &HAS_BL_8X4), | 1147 | (8, 4) => (&HAS_TR_8X4, &HAS_BL_8X4), |
| 1115 | - (16, 32) => (HAS_TOP_RIGHT_RECT[1], HAS_BOTTOM_LEFT_RECT[1]), | 1148 | + (8, 16) => (&HAS_TR_8X16, &HAS_BL_8X16), |
| 1116 | - _ => (HAS_TOP_RIGHT_RECT[0], HAS_BOTTOM_LEFT_RECT[0]), | 1149 | + (16, 8) => (&HAS_TR_16X8, &HAS_BL_16X8), |
| 1150 | + (16, 32) => (&HAS_TR_16X32, &HAS_BL_16X32), | ||
| 1151 | + (32, 16) => (&HAS_TR_32X16, &HAS_BL_32X16), | ||
| 1152 | + (32, 64) => (&HAS_TR_32X64, &HAS_BL_32X64), | ||
| 1153 | + (64, 32) => (&HAS_TR_64X32, &HAS_BL_64X32), | ||
| 1154 | + (4, 16) => (&HAS_TR_4X16, &HAS_BL_4X16), | ||
| 1155 | + (16, 4) => (&HAS_TR_16X4, &HAS_BL_16X4), | ||
| 1156 | + (8, 32) => (&HAS_TR_8X32, &HAS_BL_8X32), | ||
| 1157 | + (32, 8) => (&HAS_TR_32X8, &HAS_BL_32X8), | ||
| 1158 | + (16, 64) => (&HAS_TR_16X64, &HAS_BL_16X64), | ||
| 1159 | + (64, 16) => (&HAS_TR_64X16, &HAS_BL_64X16), | ||
| 1160 | + _ => unreachable!("no libaom has_tr/has_bl table for a {bw}x{bh} block"), | ||
| 1117 | } | 1161 | } |
| 1118 | } | 1162 | } |
| 1119 | 1163 | ||
| @@ -1164,7 +1208,7 @@ impl Reach { | |||
| 1164 | return false; | 1208 | return false; |
| 1165 | } | 1209 | } |
| 1166 | let table = rect_reach_tables(bw, bh).0; | 1210 | let table = rect_reach_tables(bw, bh).0; |
| 1167 | - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1211 | + Self::bit(table, row * Self::table_stride(bw) + col) |
| 1168 | } | 1212 | } |
| 1169 | 1213 | ||
| 1170 | fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { | 1214 | fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { |
| @@ -1176,7 +1220,7 @@ impl Reach { | |||
| 1176 | return false; | 1220 | return false; |
| 1177 | } | 1221 | } |
| 1178 | let table = rect_reach_tables(bw, bh).1; | 1222 | let table = rect_reach_tables(bw, bh).1; |
| 1179 | - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1223 | + Self::bit(table, row * Self::table_stride(bw) + col) |
| 1180 | } | 1224 | } |
| 1181 | 1225 | ||
| 1182 | /// Neither, which is all a mode that reads no further than its own edges | 1226 | /// Neither, which is all a mode that reads no further than its own edges |
| @@ -3118,11 +3162,124 @@ pub fn encode_sequence( | |||
| 3118 | 3162 | ||
| 3119 | #[cfg(test)] | 3163 | #[cfg(test)] |
| 3120 | mod tests { | 3164 | mod tests { |
| 3165 | + | ||
| 3121 | use super::*; | 3166 | use super::*; |
| 3122 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; | 3167 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; |
| 3123 | use std::io::Write; | 3168 | use std::io::Write; |
| 3124 | use std::process::{Command, Stdio}; | 3169 | use std::process::{Command, Stdio}; |
| 3125 | 3170 | ||
| 3171 | + /// Every rectangular shape this decoder codes, at every position a block | ||
| 3172 | + /// of that shape can sit inside a 64x64 superblock: [`Reach::of_rect`] | ||
| 3173 | + /// must answer exactly what libaom's `has_top_right`/`has_bottom_left` | ||
| 3174 | + /// (`reconintra.c`) answer, whose bodies are ported below. | ||
| 3175 | + /// | ||
| 3176 | + /// lane-tx4x8 r3 ([[enumerate-table-domain]], [[tool-disabled-in-every-gate]]): | ||
| 3177 | + /// `rect_reach_tables` used to route every shape but 4x8/8x4/16x32 to the | ||
| 3178 | + /// 32x16 row, so live 16x8 strips read the wrong bit at 10 (above-right) | ||
| 3179 | + /// and 7 (below-left) of the 21 reachable positions with no gate seeing | ||
| 3180 | + /// it. The per-shape `(len, byte sum)` fingerprints below come from the | ||
| 3181 | + /// oracle's own arrays, so a re-routed or truncated table fails here even | ||
| 3182 | + /// where the two rows happen to agree. | ||
| 3183 | + /// | ||
| 3184 | + /// Not covered (no parameter for either on `of_rect`): chroma `ss_x`/ | ||
| 3185 | + /// `ss_y`, and sub-block transforms (`row_off`/`col_off` > 0), which the | ||
| 3186 | + /// callers handle by predicting each transform unit as its own block. | ||
| 3187 | + /// `PARTITION_VERT_A`/`VERT_B` need no arm either: libaom's | ||
| 3188 | + /// `has_tr_vert_tables`/`has_bl_vert_tables` entry for every RECT bsize is | ||
| 3189 | + /// either the plain table itself (4x8, 8x16, 16x32, 32x64) or NULL | ||
| 3190 | + /// (the horizontal shapes, which those partitions never produce). | ||
| 3191 | + #[test] | ||
| 3192 | + fn every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock() { | ||
| 3193 | + // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum). | ||
| 3194 | + const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [ | ||
| 3195 | + (4, 8, 64, 9280, 64, 550), | ||
| 3196 | + (8, 4, 64, 3712, 64, 9630), | ||
| 3197 | + (8, 16, 16, 2352, 16, 134), | ||
| 3198 | + (16, 8, 16, 960, 16, 2400), | ||
| 3199 | + (16, 32, 4, 620, 4, 32), | ||
| 3200 | + (32, 16, 4, 32, 4, 184), | ||
| 3201 | + (32, 64, 1, 127, 1, 0), | ||
| 3202 | + (64, 32, 1, 19, 1, 34), | ||
| 3203 | + (4, 16, 32, 5472, 32, 14), | ||
| 3204 | + (16, 4, 32, 960, 32, 6464), | ||
| 3205 | + (8, 32, 8, 1400, 8, 2), | ||
| 3206 | + (32, 8, 8, 32, 8, 1136), | ||
| 3207 | + (16, 64, 2, 382, 2, 0), | ||
| 3208 | + (64, 16, 2, 4, 2, 84), | ||
| 3209 | + ]; | ||
| 3210 | + /// libaom `reconintra.c` `has_top_right`/`has_bottom_left`, ported for | ||
| 3211 | + /// a block whose transform covers it whole (`row_off == col_off == 0`, | ||
| 3212 | + /// `tx_size == bsize`) and luma (`ss_x == ss_y == 0`) on a 64-pixel | ||
| 3213 | + /// superblock (`sb_mi_size == 16`). | ||
| 3214 | + fn libaom_reach( | ||
| 3215 | + bw: usize, | ||
| 3216 | + bh: usize, | ||
| 3217 | + x: usize, | ||
| 3218 | + y: usize, | ||
| 3219 | + width: usize, | ||
| 3220 | + height: usize, | ||
| 3221 | + ) -> (bool, bool) { | ||
| 3222 | + let (bw_log2, bh_log2) = ((bw / 4).ilog2() as usize, (bh / 4).ilog2() as usize); | ||
| 3223 | + let (_bw_unit, bh_unit) = (bw / 4, bh / 4); | ||
| 3224 | + let sb_mi_size = 16usize; | ||
| 3225 | + let blk_row_in_sb = ((y / 4) & (sb_mi_size - 1)) >> bh_log2; | ||
| 3226 | + let blk_col_in_sb = ((x / 4) & (sb_mi_size - 1)) >> bw_log2; | ||
| 3227 | + let this_blk_index = (blk_row_in_sb << (5 - bw_log2)) + blk_col_in_sb; | ||
| 3228 | + let (tr_table, bl_table) = rect_reach_tables(bw, bh); | ||
| 3229 | + let bit = |t: &[u8]| (t[this_blk_index / 8] >> (this_blk_index % 8)) & 1 != 0; | ||
| 3230 | + // has_top_right: top_available && right_available, then row_off == 0. | ||
| 3231 | + let top_right = if y == 0 || x + bw >= width { | ||
| 3232 | + false | ||
| 3233 | + } else if blk_row_in_sb == 0 { | ||
| 3234 | + // (`col_off + tx_wide_unit < plane_bw_unit` above this is | ||
| 3235 | + // `bw_unit < bw_unit`, false for a whole-block transform.) | ||
| 3236 | + true | ||
| 3237 | + } else if ((blk_col_in_sb + 1) << bw_log2) >= sb_mi_size { | ||
| 3238 | + false | ||
| 3239 | + } else { | ||
| 3240 | + bit(tr_table) | ||
| 3241 | + }; | ||
| 3242 | + // has_bottom_left: bottom_available && left_available, col_off == 0. | ||
| 3243 | + let bottom_left = if x == 0 || y + bh >= height { | ||
| 3244 | + false | ||
| 3245 | + } else if blk_col_in_sb == 0 { | ||
| 3246 | + // (`row_off + tx_high_unit < plane_bh_unit` is likewise false.) | ||
| 3247 | + (blk_row_in_sb << bh_log2) + bh_unit < sb_mi_size | ||
| 3248 | + } else if ((blk_row_in_sb + 1) << bh_log2) >= sb_mi_size { | ||
| 3249 | + false | ||
| 3250 | + } else { | ||
| 3251 | + bit(bl_table) | ||
| 3252 | + }; | ||
| 3253 | + (top_right, bottom_left) | ||
| 3254 | + } | ||
| 3255 | + for (bw, bh, tr_len, tr_sum, bl_len, bl_sum) in SHAPES { | ||
| 3256 | + let (tr, bl) = rect_reach_tables(bw, bh); | ||
| 3257 | + let sum = |t: &[u8]| t.iter().map(|&b| u32::from(b)).sum::<u32>(); | ||
| 3258 | + assert_eq!( | ||
| 3259 | + (tr.len(), sum(tr), bl.len(), sum(bl)), | ||
| 3260 | + (tr_len, tr_sum, bl_len, bl_sum), | ||
| 3261 | + "rect_reach_tables({bw}, {bh}) is not libaom's has_tr_{bw}x{bh}/has_bl_{bw}x{bh}" | ||
| 3262 | + ); | ||
| 3263 | + // Two superblocks across and down, so the superblock-relative | ||
| 3264 | + // position (and not the frame position) is what decides. | ||
| 3265 | + for sb_y in [0usize, 64] { | ||
| 3266 | + for sb_x in [0usize, 64] { | ||
| 3267 | + for y in (sb_y..sb_y + 64).step_by(bh) { | ||
| 3268 | + for x in (sb_x..sb_x + 64).step_by(bw) { | ||
| 3269 | + let got = Reach::of_rect(bw, bh, x, y, 256, 256); | ||
| 3270 | + let want = libaom_reach(bw, bh, x, y, 256, 256); | ||
| 3271 | + assert_eq!( | ||
| 3272 | + (got.above_right, got.below_left), | ||
| 3273 | + want, | ||
| 3274 | + "{bw}x{bh} at ({x}, {y})" | ||
| 3275 | + ); | ||
| 3276 | + } | ||
| 3277 | + } | ||
| 3278 | + } | ||
| 3279 | + } | ||
| 3280 | + } | ||
| 3281 | + } | ||
| 3282 | + | ||
| 3126 | fn have_ffmpeg() -> bool { | 3283 | fn have_ffmpeg() -> bool { |
| 3127 | Command::new("ffmpeg") | 3284 | Command::new("ffmpeg") |
| 3128 | .arg("-version") | 3285 | .arg("-version") |
crates/ec-av1/src/stream.rsmodified+231 -2
| @@ -7423,8 +7423,9 @@ mod tests { | |||
| 7423 | /// hard-asserted per firing attempt so neither orientation can ride along | 7423 | /// hard-asserted per firing attempt so neither orientation can ride along |
| 7424 | /// on the other ([[gate-blind-to-feature]]), and only leaves that coded | 7424 | /// on the other ([[gate-blind-to-feature]]), and only leaves that coded |
| 7425 | /// REAL coefficients count -- a skipped leaf never runs the transform. | 7425 | /// REAL coefficients count -- a skipped leaf never runs the transform. |
| 7426 | - /// Arms: 8-bit 64x64, an 8-bit `--tile-columns=1` 128x64 (the mi-granular | 7426 | + /// Arms: 8-bit 16x16, an 8-bit `--tile-columns=1` 128x16 (the mi-granular |
| 7427 | - /// mode maps are per tile), and a 10-bit 64x64. | 7427 | + /// mode maps are per tile), and a 10-bit 16x16 -- 16-pixel fixtures, for |
| 7428 | + /// the reason the comment inside the loop gives. | ||
| 7428 | #[test] | 7429 | #[test] |
| 7429 | fn a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact() { | 7430 | fn a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact() { |
| 7430 | const NAME: &str = "a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact"; | 7431 | const NAME: &str = "a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact"; |
| @@ -7627,6 +7628,234 @@ mod tests { | |||
| 7627 | } | 7628 | } |
| 7628 | } | 7629 | } |
| 7629 | 7630 | ||
| 7631 | + /// lane-tx4x8 r3 ([[enumerate-table-domain]], [[tool-disabled-in-every-gate]]): | ||
| 7632 | + /// a 16x8/8x16 intra strip whose DIRECTIONAL mode reads above-right or | ||
| 7633 | + /// below-left samples. Which of those the decoder may read is | ||
| 7634 | + /// `Reach::of_rect`'s answer, and until this round `rect_reach_tables` | ||
| 7635 | + /// had no 16x8 row at all -- every 16x8 strip read libaom's `has_tr_32x16` | ||
| 7636 | + /// row instead of `has_tr_16x8`, wrong at 10 of the 21 reachable | ||
| 7637 | + /// superblock positions for above-right and 7 for below-left. No gate saw | ||
| 7638 | + /// it: the sibling strip gate (`coded_rect_strip_below_16x16`) runs with | ||
| 7639 | + /// smooth/paeth/DC modes, which never read past the block, so the wrong | ||
| 7640 | + /// bit changed no pixel there. | ||
| 7641 | + /// | ||
| 7642 | + /// So this gate turns every non-directional intra tool OFF | ||
| 7643 | + /// (`--enable-smooth-intra=0 --enable-paeth-intra=0 | ||
| 7644 | + /// --enable-filter-intra=0`) at `--min-partition-size=8 | ||
| 7645 | + /// --max-partition-size=16 --enable-rect-partitions=1`, and counts, per | ||
| 7646 | + /// attempt, the 16x8/8x16 strips whose prediction actually reached past | ||
| 7647 | + /// their own width or height ([`decode::rect_strip_reach_hits`], recorded | ||
| 7648 | + /// in the predictor's edge fetch). An attempt only counts when that | ||
| 7649 | + /// counter moved AND the frame is pixel-exact against ffmpeg. | ||
| 7650 | + /// | ||
| 7651 | + /// BLOCKED, and `#[ignore]`d for it, not skipped from inside | ||
| 7652 | + /// ([[gate-skips-on-its-own-failure]]): the 16x16-level strip decoder | ||
| 7653 | + /// refuses every NON-SKIP 16x8/8x16 strip ("a coded (non-skip) HORZ/VERT | ||
| 7654 | + /// rect strip below 16x16", `decode.rs`), and that is what real streams | ||
| 7655 | + /// contain -- measured on this exact recipe, 38 of 40 attempts died on | ||
| 7656 | + /// that refusal and 2 on a sub-16x16 AB partition, at cq 30/45/58 and at | ||
| 7657 | + /// `--min-partition-size=16` (which yields no 16x8 at all, aomenc bounds a | ||
| 7658 | + /// rect shape by its smaller side). What unblocks it: the lane that ports | ||
| 7659 | + /// the coded 16x16-level strip; then drop this attribute. Until then the | ||
| 7660 | + /// table routing is pinned by the domain test | ||
| 7661 | + /// `encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock` | ||
| 7662 | + /// against libaom's own `has_tr_*`/`has_bl_*` arrays. | ||
| 7663 | + #[test] | ||
| 7664 | + #[ignore = "the coded 16x8/8x16 strip is a live refusal; see the doc above"] | ||
| 7665 | + fn a_directional_16x8_strip_reads_the_right_above_right_samples() { | ||
| 7666 | + const NAME: &str = "a_directional_16x8_strip_reads_the_right_above_right_samples"; | ||
| 7667 | + if !have_ffmpeg() { | ||
| 7668 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 7669 | + return; | ||
| 7670 | + } | ||
| 7671 | + if !have_aomenc() { | ||
| 7672 | + let msg = format!("no aomenc at {}", aomenc_path().display()); | ||
| 7673 | + assert!( | ||
| 7674 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 7675 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | ||
| 7676 | + ); | ||
| 7677 | + eprintln!("SKIP {NAME}: {msg}"); | ||
| 7678 | + return; | ||
| 7679 | + } | ||
| 7680 | + // 64x16, not 64x64: a 16-tall frame is a single row of 16x16 blocks, | ||
| 7681 | + // so a HORZ arm is a 16x8 strip at column 0..3 of the superblock -- | ||
| 7682 | + // exactly the positions whose `has_tr_16x8`/`has_bl_16x8` bit the old | ||
| 7683 | + // routing got wrong -- while the frame is too short for aomenc to | ||
| 7684 | + // build the deep sub-16x16 partitions other lanes still refuse. It | ||
| 7685 | + // must also be WIDER than one block: at width 16 the block is the | ||
| 7686 | + // frame, and `x + bw < width` kills above-right before any table. | ||
| 7687 | + for (width, height, bit_depth) in [(64usize, 16usize, 8u8), (64, 16, 10u8)] { | ||
| 7688 | + let mut refusals = Vec::new(); | ||
| 7689 | + let mut fired_runs = 0u32; | ||
| 7690 | + let mut reach_hits = 0usize; | ||
| 7691 | + for attempt in 0..40u32 { | ||
| 7692 | + let seed = 700 + attempt; | ||
| 7693 | + // Coarse quantisers on lightly-dithered content: fine detail | ||
| 7694 | + // at low cq makes aomenc build the sub-16x16 partitions other | ||
| 7695 | + // lanes refuse, and 40/40 attempts died there. | ||
| 7696 | + let cq = 45 + (attempt % 4); | ||
| 7697 | + let half = height / 2; | ||
| 7698 | + let pix_fmt = if bit_depth == 10 { | ||
| 7699 | + "yuv420p10le" | ||
| 7700 | + } else { | ||
| 7701 | + "yuv420p" | ||
| 7702 | + }; | ||
| 7703 | + let y4m = Command::new("ffmpeg") | ||
| 7704 | + .args([ | ||
| 7705 | + "-v", | ||
| 7706 | + "error", | ||
| 7707 | + "-f", | ||
| 7708 | + "lavfi", | ||
| 7709 | + "-i", | ||
| 7710 | + &format!("testsrc2=size={width}x{half}:rate=25"), | ||
| 7711 | + "-f", | ||
| 7712 | + "lavfi", | ||
| 7713 | + "-i", | ||
| 7714 | + &format!("color=c=gray:s={width}x{half}:rate=25"), | ||
| 7715 | + "-filter_complex", | ||
| 7716 | + &format!( | ||
| 7717 | + "[0]noise=alls=8:allf=t:all_seed={seed}[t];[t][1]vstack,\ | ||
| 7718 | + format={pix_fmt}" | ||
| 7719 | + ), | ||
| 7720 | + "-strict", | ||
| 7721 | + "-1", | ||
| 7722 | + "-t", | ||
| 7723 | + "0.04", | ||
| 7724 | + "-f", | ||
| 7725 | + "yuv4mpegpipe", | ||
| 7726 | + "-", | ||
| 7727 | + ]) | ||
| 7728 | + .stdin(Stdio::null()) | ||
| 7729 | + .stdout(Stdio::piped()) | ||
| 7730 | + .stderr(Stdio::piped()) | ||
| 7731 | + .output() | ||
| 7732 | + .expect("ffmpeg failed to run"); | ||
| 7733 | + assert!( | ||
| 7734 | + y4m.status.success(), | ||
| 7735 | + "ffmpeg fixture: {}", | ||
| 7736 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 7737 | + ); | ||
| 7738 | + let mut child = Command::new(aomenc_path()) | ||
| 7739 | + .args([ | ||
| 7740 | + "--codec=av1", | ||
| 7741 | + "--passes=1", | ||
| 7742 | + "--end-usage=q", | ||
| 7743 | + &format!("--cq-level={cq}"), | ||
| 7744 | + "--cpu-used=0", | ||
| 7745 | + "--threads=1", | ||
| 7746 | + "--row-mt=0", | ||
| 7747 | + "--sb-size=64", | ||
| 7748 | + // The tool under test: 16x8/8x16 strips, predicted by | ||
| 7749 | + // a mode that reads beyond the block. | ||
| 7750 | + // aomenc bounds a RECT shape by its smaller side, so | ||
| 7751 | + // `--min-partition-size=16` yields no 16x8 at all | ||
| 7752 | + // (measured: 0 strips in 40 attempts); 8 is the | ||
| 7753 | + // smallest value that lets a 16x16 split HORZ/VERT. | ||
| 7754 | + "--min-partition-size=8", | ||
| 7755 | + "--max-partition-size=16", | ||
| 7756 | + // Largest transform per block: a split (depth-1) rect | ||
| 7757 | + // strip is a named refusal of another lane, and it | ||
| 7758 | + // ate every attempt while it was on. | ||
| 7759 | + "--enable-tx-size-search=0", | ||
| 7760 | + "--enable-rect-partitions=1", | ||
| 7761 | + "--enable-directional-intra=1", | ||
| 7762 | + "--enable-smooth-intra=0", | ||
| 7763 | + "--enable-paeth-intra=0", | ||
| 7764 | + "--enable-filter-intra=0", | ||
| 7765 | + "--enable-ab-partitions=0", | ||
| 7766 | + "--enable-1to4-partitions=0", | ||
| 7767 | + "--enable-palette=0", | ||
| 7768 | + "--enable-intrabc=0", | ||
| 7769 | + "--enable-restoration=0", | ||
| 7770 | + "--enable-cdef=0", | ||
| 7771 | + "--loopfilter-control=0", | ||
| 7772 | + "--enable-ref-frame-mvs=0", | ||
| 7773 | + "--limit=1", | ||
| 7774 | + "--obu", | ||
| 7775 | + "-o", | ||
| 7776 | + "-", | ||
| 7777 | + "-", | ||
| 7778 | + ]) | ||
| 7779 | + .args(if bit_depth == 10 { | ||
| 7780 | + &["--input-bit-depth=10", "--bit-depth=10"][..] | ||
| 7781 | + } else { | ||
| 7782 | + &[][..] | ||
| 7783 | + }) | ||
| 7784 | + .stdin(Stdio::piped()) | ||
| 7785 | + .stdout(Stdio::piped()) | ||
| 7786 | + .stderr(Stdio::piped()) | ||
| 7787 | + .spawn() | ||
| 7788 | + .expect("aomenc failed to start"); | ||
| 7789 | + child | ||
| 7790 | + .stdin | ||
| 7791 | + .take() | ||
| 7792 | + .expect("aomenc stdin") | ||
| 7793 | + .write_all(&y4m.stdout) | ||
| 7794 | + .expect("writing y4m to aomenc"); | ||
| 7795 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 7796 | + if !out.status.success() { | ||
| 7797 | + refusals.push(format!( | ||
| 7798 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | ||
| 7799 | + )); | ||
| 7800 | + continue; | ||
| 7801 | + } | ||
| 7802 | + let stream = out.stdout; | ||
| 7803 | + let reach_before = decode::rect_strip_reach_hits(); | ||
| 7804 | + let pred_before = decode::rect_strip_pred_hits(); | ||
| 7805 | + let frames = match decode_stream(&stream) { | ||
| 7806 | + Ok(frames) => frames, | ||
| 7807 | + Err(e) => { | ||
| 7808 | + let msg = e.to_string(); | ||
| 7809 | + assert!( | ||
| 7810 | + msg.starts_with("unsupported: "), | ||
| 7811 | + "decode error that is not a named refusal \ | ||
| 7812 | + (seed={seed} cq={cq} depth={bit_depth}): {msg}" | ||
| 7813 | + ); | ||
| 7814 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | ||
| 7815 | + continue; | ||
| 7816 | + } | ||
| 7817 | + }; | ||
| 7818 | + let reached = decode::rect_strip_reach_hits() - reach_before; | ||
| 7819 | + let predicted = decode::rect_strip_pred_hits() - pred_before; | ||
| 7820 | + if predicted == 0 { | ||
| 7821 | + refusals.push(format!( | ||
| 7822 | + "seed={seed} cq={cq}: decoded, but no 16x8/8x16 strip in the frame" | ||
| 7823 | + )); | ||
| 7824 | + continue; | ||
| 7825 | + } | ||
| 7826 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 7827 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 7828 | + } else { | ||
| 7829 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 7830 | + }; | ||
| 7831 | + assert_eq!( | ||
| 7832 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 7833 | + "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth}, {predicted} strips, \ | ||
| 7834 | + {reached} of them reaching)" | ||
| 7835 | + ); | ||
| 7836 | + assert_eq!( | ||
| 7837 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 7838 | + "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 7839 | + ); | ||
| 7840 | + assert_eq!( | ||
| 7841 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 7842 | + "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 7843 | + ); | ||
| 7844 | + fired_runs += 1; | ||
| 7845 | + reach_hits += reached; | ||
| 7846 | + if fired_runs >= 4 { | ||
| 7847 | + break; | ||
| 7848 | + } | ||
| 7849 | + } | ||
| 7850 | + assert!( | ||
| 7851 | + fired_runs >= 4, | ||
| 7852 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | ||
| 7853 | + ({width}x{height} depth={bit_depth}, {reach_hits} reaching strips):\n{}", | ||
| 7854 | + refusals.join("\n") | ||
| 7855 | + ); | ||
| 7856 | + } | ||
| 7857 | + } | ||
| 7858 | + | ||
| 7630 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, | 7859 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 7631 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 | 7860 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 7632 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced | 7861 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |
lanes/COMMON-20260901.mdadded+87 -0
| @@ -0,0 +1,87 @@ | |||
| 1 | +# COMMON CHARTER PREAMBLE — batch 2026-09-01 (ec-av1 decode, his real films) | ||
| 2 | + | ||
| 3 | +GOAL (why): ec-av1 must decode the user's two real AV1 films bit-exact | ||
| 4 | +(`/home/user/Videos/Films/reelc.mkv`, | ||
| 5 | +`/home/user/Downloads/reelb.mkv`, | ||
| 6 | +both yuv420p10le). 47 refusal strings remain in crates/ec-av1/src/refusal_inventory.rs. | ||
| 7 | +Each lane lifts its cluster of refusals WITH a real-aomenc gate proving it. | ||
| 8 | + | ||
| 9 | +WORKING RULES (binding): | ||
| 10 | +- Work ONLY in your worktree; branch named in your charter. Never touch main, never | ||
| 11 | + merge into main, never `git checkout <file>` to revert (copy to scratch first). | ||
| 12 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-<lane>` (named in charter) for EVERY cargo | ||
| 13 | + command. sccache is the global rustc wrapper. Use `nice -n 10 cargo ... -j3` — 10 lanes | ||
| 14 | + run concurrently on 12 cores / 30G RAM. Long/lavfi runs under | ||
| 15 | + `systemd-run --user --scope -p MemoryMax=8G` and bound ffmpeg with `-t`. | ||
| 16 | +- Test scope: `cargo test -p ec-av1 --lib` only (plus `cargo check -p ec-av1`). Never the | ||
| 17 | + workspace suite. Set `EC_AV1_REQUIRE_AOMENC=1` so an absent oracle FAILS, never SKIPs. | ||
| 18 | +- Oracle: `~/.cache/aom-oracle/build/aomenc` and instrumented `aomdec` (scripts/build-aom-oracle.sh, | ||
| 19 | + scripts/instrument-aom-oracle.sh; rungs EC_TRACE=1 / EC_TRACE_COEFF=1 / EC_TRACE_MODE=1 / | ||
| 20 | + EC_AV1_PREFILT_DUMP). Ours: EC_TRACE_COEFF / EC_TRACE_MODE / EC_TRACE_MODE_STEP in decode.rs. | ||
| 21 | + Cross-decoder bisection compares msac RANGE element by element, never tell(). | ||
| 22 | + The reference is at the oracle source tree (find via scripts/build-aom-oracle.sh). | ||
| 23 | +- FIRST STEP, always: `git log --oneline -8 main` and rebase your branch onto main | ||
| 24 | + (`git rebase main`; resolve conflicts, keeping main's fixes). Then RE-MEASURE your lane's | ||
| 25 | + premise before building — charters may carry stale premises. Cite the command that | ||
| 26 | + produced every premise you act on. | ||
| 27 | +- Fixtures: `fixtures` is a symlink to main's fixtures dir (shared). Pin any new stream | ||
| 28 | + fixture under crates/ec-av1/fixtures/ or fixtures/ with a hash; hash an aomenc output | ||
| 29 | + TWICE before trusting a seed (lavfi gradients ignores its seed). | ||
| 30 | +- A refusal is lifted ONLY together with a gate: a real-aomenc stream (tool explicitly | ||
| 31 | + enabled on the aomenc command line) decoded pixel-exact vs ffmpeg/aomdec, that | ||
| 32 | + HARD-ASSERTS a hit counter proving the feature fired, and never turns a decode error or | ||
| 33 | + pixel mismatch into SKIP. Update refusal_inventory.rs + gate_coverage.rs in the same | ||
| 34 | + commit. `refusal_inventory` and `gate_coverage` tests must stay green. | ||
| 35 | +- Defect classes to check first (memory-proven, each cost rounds): CDF row indexed by a | ||
| 36 | + field that moves; table indexed by RAW vs adjusted tx_size; scan/ctx tables transposed | ||
| 37 | + vs spec (libaom layout is not the spec's — gate on asymmetric behaviour); neighbour ctx | ||
| 38 | + read from one cell instead of gathered over the span; a symbol we read that the | ||
| 39 | + reference never wrote (reference range unchanged = unread); a header field parsed then | ||
| 40 | + never consumed; counter-reset list missing a table; call-site arg order; a probe loop | ||
| 41 | + reusing last run's output file (rm -f first, check exit status). | ||
| 42 | +- Tool-call ceiling ~70. If you hit it: commit everything on your branch, write | ||
| 43 | + `lanes/<lane>-r<N>.handoff.md` with exact facts (ranges, stream, element) so a fresh | ||
| 44 | + agent continues without re-reading. | ||
| 45 | +- DONE = commit(s) on your branch + `lanes/<lane>-r<N>.report.md` in your worktree with: | ||
| 46 | + what changed (path:line), gate name + command + result, refusals lifted, test totals | ||
| 47 | + (`cargo test -p ec-av1 --lib` passed/failed/ignored), and EVIDENCE lines of the form | ||
| 48 | + `EVIDENCE: <artifact> | <steps> | <measurement>`. State open residue with | ||
| 49 | + fix-now | deferred(<what unblocks>) | accepted. Never claim "done" beyond what you ran. | ||
| 50 | +- Film check, when your lane targets a film blocker: extract 0.4s with | ||
| 51 | + `ffmpeg -t 0.4 -i <film> -c:v copy -f obu <out>.obu` (bounded), run | ||
| 52 | + `cargo run -p ec-av1 --example decode_probe -- <out>.obu` before and after; report | ||
| 53 | + the refusal string each film now stops at. | ||
| 54 | + | ||
| 55 | +VERIFIERS (added 2026-09-01 22:40 after a verifier left a lane worktree on a detached HEAD | ||
| 56 | +while its builder was mid-round): a verifier NEVER runs `git checkout`, `git switch`, | ||
| 57 | +`git stash` or any tree-changing git command inside a lane worktree. To test a specific | ||
| 58 | +commit, `git worktree add --detach /tmp/claude-1000/.../scratchpad/verify-<lane> <sha>` with its | ||
| 59 | +own CARGO_TARGET_DIR, and remove it when done. | ||
| 60 | + | ||
| 61 | +NEIGHBOUR MAPS (added 2026-09-02 00:50, class new-map-ignores-tile-edge): any per-mi side band | ||
| 62 | +you add or inherit (mode, uv_mode, skip, ref, filter, txfm ctx, palette) MUST (1) guard | ||
| 63 | +availability with `mi_r > tile_row0_mi` / `mi_c > tile_col0_mi`, never `> 0`; (2) be reset in | ||
| 64 | +start_tile AND start_row; (3) have a `--tile-columns=1` arm in the lane's gate. Gate Err arms | ||
| 65 | +tolerate ONLY messages containing "unsupported"; lavfi sources carry an explicit seed | ||
| 66 | +(noise=all_seed=N) and the report shows two identical hashes. | ||
| 67 | + | ||
| 68 | +SIBLING GATES (added 2026-09-02 03:00, rectsplit r3): a root-cause fix that turns YOUR gate green | ||
| 69 | +is not done until every gate that exercises the same tables/paths (grep the table name and the | ||
| 70 | +function in stream.rs) is re-run — rectsplit r2 shipped a transposition that fixed its gate and | ||
| 71 | +broke the merged SB HORZ/VERT gate at seed 43. Run the siblings before writing "root cause". | ||
| 72 | + | ||
| 73 | +FORMAT + LOGS (added 2026-09-02 03:30): never run a repo-wide `cargo fmt` in a lane (txselect | ||
| 74 | +carried 5000 lines of churn that the merge had to strip; format only files you touched, or | ||
| 75 | +not at all). Suite logs go to a PRIVATE path (`$CARGO_TARGET_DIR/../<lane>-suite.log`), never | ||
| 76 | +a shared scratchpad name — another session overwrote a verifier's log mid-run. | ||
| 77 | + | ||
| 78 | +## AOMENC FLAG PRECEDENCE (measured 2026-09-02 08:45, md5 of 4 orderings) | ||
| 79 | +aomenc keeps the LAST occurrence of a repeated `--enable-*` flag. Per-arm overrides go AFTER the | ||
| 80 | +base recipe. Every gate proves its flag arrived through a decoder-side counter or a header field; | ||
| 81 | +a counter at 0 means the flag did not arrive or the encoder declined — never weaken the assert. | ||
| 82 | + | ||
| 83 | +## SUITE RUNS (3 self-kills on 2026-09-02) | ||
| 84 | +Start the full suite detached: `setsid -f nohup env ... cargo test ... > $HOME/.cache/<lane>-suite.log 2>&1` | ||
| 85 | +or via the Bash tool's run_in_background. NEVER wait on it with a foreground `until/while ... sleep` loop | ||
| 86 | +or `tail --pid`: the 10-minute foreground cap SIGTERMs the whole process group (rc 144, no `test result` | ||
| 87 | +line). Check the log with single instantaneous `grep` calls between other work. | ||
lanes/tx4x8-r3.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | |||
| 1 | +# lane-tx4x8 r3 -- every rect shape gets its own has_tr/has_bl row | ||
| 2 | + | ||
| 3 | +## Root cause (verifier's finding, confirmed) | ||
| 4 | + | ||
| 5 | +`encode.rs` `rect_reach_tables(bw, bh)` had rows for 4x8, 8x4 and 16x32 only and | ||
| 6 | +a `_` arm that routed **every other rectangular shape** to libaom's | ||
| 7 | +`has_tr_32x16`/`has_bl_32x16`. 16x8 strips are live (`decode_leaf_rect`, | ||
| 8 | +`decode.rs`), and neither the old `HAS_TOP_RIGHT_RECT[bw == 16]` selection nor | ||
| 9 | +the r2 `_` arm matches `has_tr_16x8`/`has_bl_16x8` (`reconintra.c:96` / `:282`, | ||
| 10 | +16 bytes each): over the 21 reachable superblock positions, has_tr was wrong at | ||
| 11 | +14 (old) / 10 (r2) and has_bl at 14 / 7. Class: | ||
| 12 | +[[enumerate-table-domain]] + [[tool-disabled-in-every-gate]]. | ||
| 13 | + | ||
| 14 | +## Fix | ||
| 15 | + | ||
| 16 | +* `encode.rs`: all 14 rect shapes this decoder codes or will code (4x8, 8x4, | ||
| 17 | + 8x16, 16x8, 16x32, 32x16, 32x64, 64x32, 4x16, 16x4, 8x32, 32x8, 16x64, 64x16) | ||
| 18 | + now have their own `HAS_TR_*`/`HAS_BL_*` const, **generated** from | ||
| 19 | + `~/.cache/aom-oracle/src/av1/common/reconintra.c` (no byte retyped), and | ||
| 20 | + `rect_reach_tables` is an exhaustive match ending in | ||
| 21 | + `unreachable!("no libaom has_tr/has_bl table for a {bw}x{bh} block")`. | ||
| 22 | +* Index rule verified per shape: libaom's | ||
| 23 | + `(blk_row_in_sb << (5 - bw_in_mi_log2)) + blk_col_in_sb` == row stride | ||
| 24 | + `128 / bw` == the existing `Reach::table_stride(bw)`. For a 64-pixel | ||
| 25 | + superblock the largest index any shape can produce is | ||
| 26 | + `(64/bh - 1) * (128/bw) + (64/bw - 1)`, which is inside every one of the 14 | ||
| 27 | + oracle tables -- so the `% (table.len() * 8)` wrap the rect path used to | ||
| 28 | + apply is not just unnecessary, it was masking exactly this kind of | ||
| 29 | + mis-routing; it is gone (the square path keeps its own). | ||
| 30 | + | ||
| 31 | +## Check 1 -- domain test (runnable, green) | ||
| 32 | + | ||
| 33 | +`encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock`: | ||
| 34 | +for all 14 shapes, at every position a block of that shape can sit in a 64x64 | ||
| 35 | +superblock (and in a second superblock at (64,64), so SB-relative position is | ||
| 36 | +what decides), `Reach::of_rect` == a port of libaom's `has_top_right` / | ||
| 37 | +`has_bottom_left` bodies incl. every early exit (top/right/bottom/left | ||
| 38 | +availability, `blk_row_in_sb == 0`, rightmost column, leftmost column's | ||
| 39 | +`row_off_in_sb + count < sb_height_unit`, bottom row). Each shape's table is | ||
| 40 | +additionally pinned by a `(len, byte sum)` fingerprint taken from the oracle's | ||
| 41 | +arrays, so a re-routed or truncated row fails even where two rows agree. | ||
| 42 | + | ||
| 43 | +Not covered, stated rather than implied: chroma `ss_x`/`ss_y` and sub-block | ||
| 44 | +transforms (`row_off`/`col_off` > 0) -- `of_rect` takes neither parameter | ||
| 45 | +(callers predict each transform unit as its own block); `PARTITION_VERT_A/B` | ||
| 46 | +needs no arm because libaom's `has_tr_vert_tables` entry for every *rect* bsize | ||
| 47 | +is either the plain table (4x8, 8x16, 16x32, 32x64) or NULL. | ||
| 48 | + | ||
| 49 | + cd /home/user/Documents/Code/Rust/edith_codecs-tx4x8 | ||
| 50 | + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 EC_NOMEMGUARD=1 \ | ||
| 51 | + cargo test -p ec-av1 --lib -j3 every_rect_shape | ||
| 52 | + | ||
| 53 | +EVIDENCE: $HOME/.cache/tx4x8-suite-r3.log | cargo test -p ec-av1 --lib every_rect_shape | 1 passed, 0 failed | ||
| 54 | + | ||
| 55 | +MUTATION (the check that says the test has teeth): restoring r2's routing for | ||
| 56 | +one shape -- `(16, 8) => (&HAS_TR_32X16, &HAS_BL_32X16)` -- fails it: | ||
| 57 | + | ||
| 58 | + assertion `left == right` failed: rect_reach_tables(16, 8) is not libaom's has_tr_16x8/has_bl_16x8 | ||
| 59 | + left: (4, 32, 4, 184) | ||
| 60 | + right: (16, 960, 16, 2400) | ||
| 61 | + | ||
| 62 | +## Check 2 -- the asymmetric strip stream gate: BLOCKED, `#[ignore]`d | ||
| 63 | + | ||
| 64 | +`stream::tests::a_directional_16x8_strip_reads_the_right_above_right_samples` | ||
| 65 | +is written in full (directional-only intra: `--enable-smooth-intra=0 | ||
| 66 | +--enable-paeth-intra=0 --enable-filter-intra=0 --enable-directional-intra=1 | ||
| 67 | +--enable-rect-partitions=1 --enable-ab-partitions=0`, 64x16 fixture whose | ||
| 68 | +bottom half is flat so a HORZ arm can be a skip strip, 8-bit and 10-bit arms, | ||
| 69 | +per-attempt counters `decode::rect_strip_pred_hits` / `rect_strip_reach_hits` | ||
| 70 | +recorded in the predictor's edge fetch, pixel-exact vs ffmpeg) but it cannot | ||
| 71 | +pass today and is `#[ignore]`d with the reason in its doc rather than skipping | ||
| 72 | +from inside ([[gate-skips-on-its-own-failure]]). | ||
| 73 | + | ||
| 74 | +Why: the 16x16-level strip decoder refuses every **non-skip** 16x8/8x16 strip | ||
| 75 | +("a coded (non-skip) HORZ/VERT rect strip below 16x16"), which is what real | ||
| 76 | +streams contain. Measured on this recipe, per 40 attempts: | ||
| 77 | + | ||
| 78 | +| recipe | outcome | | ||
| 79 | +| --- | --- | | ||
| 80 | +| `--min-partition-size=16 --max-partition-size=16` | 40/40 decode, **0** 16x8/8x16 strips (aomenc bounds a rect shape by its smaller side, so 16x8 is never searched) | | ||
| 81 | +| `--min-partition-size=8`, cq 8..20, noise 30, 64x64 | 40/40 refused (split-transform strip / non-skip strip / sub-16x16 AB) | | ||
| 82 | +| `--min-partition-size=8 --enable-tx-size-search=0`, cq 30/45/55/62, noise 4 and 15, 64x16 | 0 firing; at cq 45 with the half-flat fixture: **38/40 "coded (non-skip) rect strip below 16x16"**, 2/40 sub-16x16 AB | | ||
| 83 | + | ||
| 84 | +MUTATION for this gate is therefore not reportable at stream level: with the | ||
| 85 | +old `_` routing the gate fails for the same reason it fails with the fix (no | ||
| 86 | +attempt gets past the refusal). The mutation evidence for the fix is the | ||
| 87 | +domain-test one above. | ||
| 88 | + | ||
| 89 | +deferred: the stream-level pixel gate for 16x8/8x16 reach -- blocked by the | ||
| 90 | +live "coded (non-skip) HORZ/VERT rect strip below 16x16" refusal -- unblocked | ||
| 91 | +by the lane that ports the coded 16x16-level strip; then delete the | ||
| 92 | +`#[ignore]` attribute (nothing else in the test changes). | ||
| 93 | + | ||
| 94 | +## Also | ||
| 95 | + | ||
| 96 | +* `stream.rs` doc of the sub-8x8 rect gate said "Arms: 8-bit 64x64, ... 128x64, | ||
| 97 | + ... 10-bit 64x64"; the arms are 16x16 / 128x16 / 16x16. Fixed. | ||
| 98 | +* New counters `rect_strip_pred_hits` / `rect_strip_reach_hits` in `decode.rs` | ||
| 99 | + (bumped in `Plane::edges_rect`) are the instrument the blocked gate needs the | ||
| 100 | + day the refusal lifts. | ||
| 101 | + | ||
| 102 | +## Suite | ||
| 103 | + | ||
| 104 | + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 EC_NOMEMGUARD=1 \ | ||
| 105 | + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 -j3 | ||
| 106 | + | ||
| 107 | +275 passed, 0 failed, 23 ignored (r2: 274 / 0 / 22 -- +1 = the domain test, | ||
| 108 | ++1 ignored = the blocked gate). Log: `$HOME/.cache/tx4x8-suite-r3.log`. | ||
| 109 | + | ||
| 110 | +## Merge note | ||
| 111 | + | ||
| 112 | +This round deletes `HAS_TOP_RIGHT_RECT` / `HAS_BOTTOM_LEFT_RECT` (the 2-row | ||
| 113 | +arrays lane-tx64x16 r3 extends to 4 rows with its own 32x8/8x32 entries). On a | ||
| 114 | +merge, keep this branch's per-shape consts -- `HAS_TR_32X8` / `HAS_BL_32X8` / | ||
| 115 | +`HAS_TR_8X32` / `HAS_BL_8X32` are already here, byte-identical to the oracle -- | ||
| 116 | +and drop the array form together with `Reach::rect_table`. | ||