Merge lane-av1toolgates @ 4c4bd3e2 — gate enable-rect-tx at both depths on the PARSED partition shape
Browse files at this commit1 changed file +332 -0
- crates/ec-av1/src/stream.rs +332 -0
crates/ec-av1/src/stream.rsmodified+332 -0
| @@ -10014,6 +10014,338 @@ pub(crate) mod tests { | |||
| 10014 | ); | 10014 | ); |
| 10015 | } | 10015 | } |
| 10016 | 10016 | ||
| 10017 | + /// lane-av1toolgates: the shared body of the two `enable-rect-tx` | ||
| 10018 | + /// coverage gates (8-bit and 10-bit). | ||
| 10019 | + /// | ||
| 10020 | + /// The aomenc ARGUMENT VECTOR is built by each gate and passed in, never | ||
| 10021 | + /// assembled here. That is not tidiness: `gate_coverage`'s `gate_bodies()` | ||
| 10022 | + /// splits `stream.rs` on `\n #[` and keeps a segment only if that | ||
| 10023 | + /// segment itself contains `--passes=1`, so a flag living in a helper is | ||
| 10024 | + /// invisible to the coverage derivation. A helper that owns the recipe | ||
| 10025 | + /// would leave this gate counted at whatever depth the helper's own text | ||
| 10026 | + /// implies -- which is the blind spot that kept `enable-rect-tx` on the | ||
| 10027 | + /// `NEVER_EXERCISED` lists after real streams had exercised it. | ||
| 10028 | + /// | ||
| 10029 | + /// WHAT THIS GATE IS AND IS NOT. `enable_rect_tx` has no sequence-header | ||
| 10030 | + /// bit in AV1 -- aom reads it only in `tx_search.c` (`search_tx_size`'s | ||
| 10031 | + /// `!enable_rect_tx && tx_size_wide != tx_size_high` skip and the | ||
| 10032 | + /// `tx_size_max_32_square` remap) -- so the flag never reaches a decoder. | ||
| 10033 | + /// Spelling `--enable-rect-tx=1` proves the ENCODER was ALLOWED the tool | ||
| 10034 | + /// and nothing more. It is CONTEXT here, not the witness: a gate that | ||
| 10035 | + /// stopped at the flag would be the `tool-disabled-in-every-gate` defect | ||
| 10036 | + /// `NEVER_EXERCISED` exists to prevent, in a new costume. | ||
| 10037 | + /// | ||
| 10038 | + /// The witness is the PARSED PARTITION SHAPE, the only thing in the | ||
| 10039 | + /// bitstream that can carry a rect transform: | ||
| 10040 | + /// [`decode::rect_partition_hits`] counts `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 10041 | + /// symbols actually read, i.e. a rect partition in the tree this decoder | ||
| 10042 | + /// walked, and [`decode::rect_coeff_tu_hits`] counts the rectangular | ||
| 10043 | + /// transform units that then coded coefficients through `read_coeffs_rect` | ||
| 10044 | + /// (`all_zero == 0`) -- the rect coefficient TABLES being read, not a | ||
| 10045 | + /// header bit. Both are asserted above zero over the arms that decoded AND | ||
| 10046 | + /// compared, and every frame is pixel-compared against ffmpeg's own decode | ||
| 10047 | + /// of the identical bytes. | ||
| 10048 | + /// | ||
| 10049 | + /// LIMIT, stated because it bounds what this gate can claim: this | ||
| 10050 | + /// repository has no INDEPENDENT partition parser to list leaves from -- | ||
| 10051 | + /// `ec-av1-syntax` parses OBU headers and the sequence header only -- and | ||
| 10052 | + /// `ec_av1::census`'s per-frame `blocks`/`tx` shape maps, the one true | ||
| 10053 | + /// leaf list, are armed by a process-global `OnceLock` on | ||
| 10054 | + /// `EC_AV1_BITCENSUS`, so arming them inside a lib test would switch the | ||
| 10055 | + /// accountant on for every other gate in the process. The partition walk is | ||
| 10056 | + /// therefore observed through the decoder's own counters, which is weaker | ||
| 10057 | + /// than a second opinion but is still a shape fact about the stream rather | ||
| 10058 | + /// than a fact about the flag. | ||
| 10059 | + /// | ||
| 10060 | + /// RED-BEFORE: the COUNTERS, one per assert, both measured. | ||
| 10061 | + /// `--enable-rect-tx=0` is deliberately NOT claimed as the mutation: it | ||
| 10062 | + /// does NOT zero these counters (39 rect coefficient TUs against 210 on | ||
| 10063 | + /// the cq20 arm, because `--enable-rect-partitions=1` already forces | ||
| 10064 | + /// non-square transform sizes regardless), and with every partition shape | ||
| 10065 | + /// off the flag yields no rect transform at either setting. `=0` does turn | ||
| 10066 | + /// the gate red, but through the ORACLE -- its `--enable-tx-size-search=0` | ||
| 10067 | + /// arm is a stream ffmpeg cannot decode past frame 6 of 15 -- so the | ||
| 10068 | + /// frame-count assert fires first and proves nothing about the tool. | ||
| 10069 | + fn rect_tx_tool_gate(name: &str, ten_bit: bool, args: &[String]) -> (usize, usize) { | ||
| 10070 | + // A missing tool SKIPs, so the totals the caller sums stay 0 and the | ||
| 10071 | + // gate's own witness assert fails loudly instead of passing vacuously | ||
| 10072 | + // on a run that decoded nothing. | ||
| 10073 | + if !have_ffmpeg() { | ||
| 10074 | + eprintln!("SKIP {name}: no ffmpeg"); | ||
| 10075 | + return (0, 0); | ||
| 10076 | + } | ||
| 10077 | + if !have_aomenc() { | ||
| 10078 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 10079 | + return (0, 0); | ||
| 10080 | + } | ||
| 10081 | + let (width, height) = (64usize, 64usize); | ||
| 10082 | + let y4m = Command::new("ffmpeg") | ||
| 10083 | + .args([ | ||
| 10084 | + "-v", | ||
| 10085 | + "error", | ||
| 10086 | + "-f", | ||
| 10087 | + "lavfi", | ||
| 10088 | + "-i", | ||
| 10089 | + "mandelbrot=size=64x64:rate=25", | ||
| 10090 | + "-pix_fmt", | ||
| 10091 | + if ten_bit { "yuv420p10le" } else { "yuv420p" }, | ||
| 10092 | + // y4m calls 10-bit an unofficial pixel format (no-op at 8). | ||
| 10093 | + "-strict", | ||
| 10094 | + "-1", | ||
| 10095 | + "-t", | ||
| 10096 | + "0.60", | ||
| 10097 | + "-f", | ||
| 10098 | + "yuv4mpegpipe", | ||
| 10099 | + "-", | ||
| 10100 | + ]) | ||
| 10101 | + .stdin(Stdio::null()) | ||
| 10102 | + .stdout(Stdio::piped()) | ||
| 10103 | + .stderr(Stdio::piped()) | ||
| 10104 | + .output() | ||
| 10105 | + .expect("ffmpeg failed to run"); | ||
| 10106 | + assert!( | ||
| 10107 | + y4m.status.success(), | ||
| 10108 | + "{name}: ffmpeg fixture: {}", | ||
| 10109 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 10110 | + ); | ||
| 10111 | + let out = run_with_stdin(Command::new(aomenc_path()).args(args), &y4m.stdout); | ||
| 10112 | + assert!( | ||
| 10113 | + out.status.success(), | ||
| 10114 | + "{name}: aomenc refused the fixture: {}", | ||
| 10115 | + String::from_utf8_lossy(&out.stderr) | ||
| 10116 | + ); | ||
| 10117 | + let stream = out.stdout; | ||
| 10118 | + assert!(!stream.is_empty(), "{name}: aomenc wrote an empty stream"); | ||
| 10119 | + if ten_bit { | ||
| 10120 | + assert_eq!( | ||
| 10121 | + parsed_bit_depth(&stream), | ||
| 10122 | + 10, | ||
| 10123 | + "{name}: aomenc did not write a 10-bit sequence header" | ||
| 10124 | + ); | ||
| 10125 | + } | ||
| 10126 | + let parts_before = decode::rect_partition_hits(); | ||
| 10127 | + let tus_before = decode::rect_coeff_tu_hits(); | ||
| 10128 | + let decoded = match decode_stream(&stream) { | ||
| 10129 | + Ok(frames) => frames, | ||
| 10130 | + Err(e) => panic!("{name}: decode_stream refused: {e}"), | ||
| 10131 | + }; | ||
| 10132 | + // Sampled after the decode, before the pixel compare, so a mismatch | ||
| 10133 | + // report can still say whether the arm fired. | ||
| 10134 | + let parts = decode::rect_partition_hits() - parts_before; | ||
| 10135 | + let tus = decode::rect_coeff_tu_hits() - tus_before; | ||
| 10136 | + let reference = if ten_bit { | ||
| 10137 | + ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()) | ||
| 10138 | + } else { | ||
| 10139 | + ffmpeg_decode_sequence(&stream, width, height, decoded.len()) | ||
| 10140 | + }; | ||
| 10141 | + assert_eq!( | ||
| 10142 | + decoded.len(), | ||
| 10143 | + reference.len(), | ||
| 10144 | + "{name}: shown-frame count vs ffmpeg (rect partitions {parts}, rect coefficient \ | ||
| 10145 | + TUs {tus})" | ||
| 10146 | + ); | ||
| 10147 | + for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { | ||
| 10148 | + for (plane, (a, b), w) in [ | ||
| 10149 | + ("Y", (&ours.y, &theirs.y), width), | ||
| 10150 | + ("U", (&ours.u, &theirs.u), width / 2), | ||
| 10151 | + ("V", (&ours.v, &theirs.v), width / 2), | ||
| 10152 | + ] { | ||
| 10153 | + assert_eq!(a.len(), b.len(), "{name}: frame {i} {plane} plane length"); | ||
| 10154 | + if a != b { | ||
| 10155 | + let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu")); | ||
| 10156 | + let _ = std::fs::write(&pin, &stream); | ||
| 10157 | + let at = a | ||
| 10158 | + .iter() | ||
| 10159 | + .zip(b.iter()) | ||
| 10160 | + .position(|(x, y)| x != y) | ||
| 10161 | + .unwrap_or(0); | ||
| 10162 | + panic!( | ||
| 10163 | + "{name}: frame {i} {plane} mismatch vs ffmpeg at row {}, col {}: {} vs \ | ||
| 10164 | + {} (rect partitions {parts}, rect coefficient TUs {tus}; stream pinned \ | ||
| 10165 | + at {})", | ||
| 10166 | + at / w, | ||
| 10167 | + at % w, | ||
| 10168 | + a[at], | ||
| 10169 | + b[at], | ||
| 10170 | + pin.display() | ||
| 10171 | + ); | ||
| 10172 | + } | ||
| 10173 | + } | ||
| 10174 | + } | ||
| 10175 | + eprintln!( | ||
| 10176 | + "{name}: {} bit, pixel-exact vs ffmpeg; parsed rect partitions {parts}, rect \ | ||
| 10177 | + coefficient TUs {tus}", | ||
| 10178 | + if ten_bit { "10" } else { "8" } | ||
| 10179 | + ); | ||
| 10180 | + (parts, tus) | ||
| 10181 | + } | ||
| 10182 | + | ||
| 10183 | + /// lane-av1toolgates: the gate-level WITNESS, summed over the arms that | ||
| 10184 | + /// decoded AND compared. It cannot be asserted per arm: the cq20 / | ||
| 10185 | + /// tx-size-search=1 arm reaches a rect transform through the var-tx | ||
| 10186 | + /// search on a SQUARE block (a nonzero rect coefficient count with zero | ||
| 10187 | + /// rect partitions read -- the purest form of what `--enable-rect-tx` | ||
| 10188 | + /// buys), while the rect PARTITION only shows up on the | ||
| 10189 | + /// tx-size-search=0 arm. Either fact alone would let a stream through on | ||
| 10190 | + /// which the tool was allowed and unused, which is the defect this | ||
| 10191 | + /// coverage entry was written for; together they are the parsed-shape | ||
| 10192 | + /// evidence the entry asked for. | ||
| 10193 | + #[track_caller] | ||
| 10194 | + fn assert_rect_tx_witness(name: &str, parts: usize, tus: usize) { | ||
| 10195 | + assert!( | ||
| 10196 | + parts > 0, | ||
| 10197 | + "{name}: no PARTITION_HORZ/PARTITION_VERT symbol was read on any pixel-exact decode \ | ||
| 10198 | + -- the parsed partition tree never yielded a rect leaf, so `--enable-rect-tx=1` \ | ||
| 10199 | + was allowed and unused" | ||
| 10200 | + ); | ||
| 10201 | + assert!( | ||
| 10202 | + tus > 0, | ||
| 10203 | + "{name}: no rectangular transform unit coded coefficients through read_coeffs_rect \ | ||
| 10204 | + ({parts} rect partitions read) -- the rect coefficient path was never taken" | ||
| 10205 | + ); | ||
| 10206 | + } | ||
| 10207 | + | ||
| 10208 | + /// lane-av1toolgates: `enable-rect-tx` at 8 BITS. See | ||
| 10209 | + /// [`rect_tx_tool_gate`] for what the flag does and does not prove, and | ||
| 10210 | + /// why the recipe is spelled here rather than in the helper. | ||
| 10211 | + /// | ||
| 10212 | + /// The whole recipe is inline: `--passes=1` has to be findable in this | ||
| 10213 | + /// segment for the coverage derivation to count the gate at all, and | ||
| 10214 | + /// `--enable-rect-tx=1` has to be findable here for it to count the | ||
| 10215 | + /// TOOL. The quantiser and the tx-size-search setting are swept as two | ||
| 10216 | + /// arms so the witness cannot rest on one RD interaction. | ||
| 10217 | + #[test] | ||
| 10218 | + fn a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact() { | ||
| 10219 | + let mut totals = (0usize, 0usize); | ||
| 10220 | + for (cq, tx_search) in [("20", "1"), ("40", "0")] { | ||
| 10221 | + let args: Vec<String> = [ | ||
| 10222 | + "--codec=av1", | ||
| 10223 | + "--passes=1", | ||
| 10224 | + "--end-usage=q", | ||
| 10225 | + "--cpu-used=0", | ||
| 10226 | + "--threads=1", | ||
| 10227 | + "--row-mt=0", | ||
| 10228 | + "--lag-in-frames=0", | ||
| 10229 | + "--auto-alt-ref=0", | ||
| 10230 | + "--kf-max-dist=1000", | ||
| 10231 | + "--error-resilient=1", | ||
| 10232 | + "--sb-size=64", | ||
| 10233 | + // The tool under test, spelled explicitly. CONTEXT, per | ||
| 10234 | + // `rect_tx_tool_gate`: aomenc was ALLOWED rect tx sizes. | ||
| 10235 | + "--enable-rect-tx=1", | ||
| 10236 | + "--enable-rect-partitions=1", | ||
| 10237 | + "--enable-ab-partitions=0", | ||
| 10238 | + "--enable-1to4-partitions=0", | ||
| 10239 | + "--enable-restoration=0", | ||
| 10240 | + "--enable-palette=0", | ||
| 10241 | + "--enable-cdef=0", | ||
| 10242 | + "--enable-cfl-intra=0", | ||
| 10243 | + "--enable-intrabc=0", | ||
| 10244 | + "--enable-order-hint=0", | ||
| 10245 | + "--min-partition-size=8", | ||
| 10246 | + "--max-partition-size=32", | ||
| 10247 | + ] | ||
| 10248 | + .map(String::from) | ||
| 10249 | + .into_iter() | ||
| 10250 | + .chain([ | ||
| 10251 | + format!("--cq-level={cq}"), | ||
| 10252 | + format!("--enable-tx-size-search={tx_search}"), | ||
| 10253 | + ]) | ||
| 10254 | + // The output tail comes LAST: aomenc stops reading flags at the | ||
| 10255 | + // first bare argument, so a sweep flag appended after `-o - -` is | ||
| 10256 | + // silently dropped and the arm encodes a different recipe than the | ||
| 10257 | + // one this gate claims to have run. | ||
| 10258 | + .chain(["--obu", "-o", "-", "-"].map(String::from)) | ||
| 10259 | + .collect(); | ||
| 10260 | + let name = format!( | ||
| 10261 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact[cq{cq}/tx{tx_search}]" | ||
| 10262 | + ); | ||
| 10263 | + let (p, t) = rect_tx_tool_gate(&name, false, &args); | ||
| 10264 | + totals.0 += p; | ||
| 10265 | + totals.1 += t; | ||
| 10266 | + } | ||
| 10267 | + assert_rect_tx_witness( | ||
| 10268 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact", | ||
| 10269 | + totals.0, | ||
| 10270 | + totals.1, | ||
| 10271 | + ); | ||
| 10272 | + eprintln!( | ||
| 10273 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact: 2 arms \ | ||
| 10274 | + pixel-exact; parsed rect partitions {}, rect coefficient TUs {}", | ||
| 10275 | + totals.0, totals.1 | ||
| 10276 | + ); | ||
| 10277 | + } | ||
| 10278 | + | ||
| 10279 | + /// lane-av1toolgates: `enable-rect-tx` at 10 BITS -- the same recipe, the | ||
| 10280 | + /// same parsed-shape witness, at the depth the 8-bit arm says nothing | ||
| 10281 | + /// about (the per-depth rule `NEVER_EXERCISED_10BIT` is built on: | ||
| 10282 | + /// lane-hbdinter's two 10-bit-only defects survived because every 10-bit | ||
| 10283 | + /// gate pinned the filters off). The depth is spelled in THIS body, | ||
| 10284 | + /// which is what files the gate in the 10-bit bucket. | ||
| 10285 | + #[test] | ||
| 10286 | + fn a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact() { | ||
| 10287 | + let mut totals = (0usize, 0usize); | ||
| 10288 | + for (cq, tx_search) in [("20", "1"), ("40", "0")] { | ||
| 10289 | + let args: Vec<String> = [ | ||
| 10290 | + "--codec=av1", | ||
| 10291 | + "--passes=1", | ||
| 10292 | + "--end-usage=q", | ||
| 10293 | + "--cpu-used=0", | ||
| 10294 | + "--threads=1", | ||
| 10295 | + "--row-mt=0", | ||
| 10296 | + "--lag-in-frames=0", | ||
| 10297 | + "--auto-alt-ref=0", | ||
| 10298 | + "--kf-max-dist=1000", | ||
| 10299 | + "--error-resilient=1", | ||
| 10300 | + "--sb-size=64", | ||
| 10301 | + "--input-bit-depth=10", | ||
| 10302 | + "--bit-depth=10", | ||
| 10303 | + // The tool under test, spelled explicitly. CONTEXT, per | ||
| 10304 | + // `rect_tx_tool_gate`: aomenc was ALLOWED rect tx sizes. | ||
| 10305 | + "--enable-rect-tx=1", | ||
| 10306 | + "--enable-rect-partitions=1", | ||
| 10307 | + "--enable-ab-partitions=0", | ||
| 10308 | + "--enable-1to4-partitions=0", | ||
| 10309 | + "--enable-restoration=0", | ||
| 10310 | + "--enable-palette=0", | ||
| 10311 | + "--enable-cdef=0", | ||
| 10312 | + "--enable-cfl-intra=0", | ||
| 10313 | + "--enable-intrabc=0", | ||
| 10314 | + "--enable-order-hint=0", | ||
| 10315 | + "--min-partition-size=8", | ||
| 10316 | + "--max-partition-size=32", | ||
| 10317 | + ] | ||
| 10318 | + .map(String::from) | ||
| 10319 | + .into_iter() | ||
| 10320 | + .chain([ | ||
| 10321 | + format!("--cq-level={cq}"), | ||
| 10322 | + format!("--enable-tx-size-search={tx_search}"), | ||
| 10323 | + ]) | ||
| 10324 | + // The output tail comes LAST: aomenc stops reading flags at the | ||
| 10325 | + // first bare argument, so a sweep flag appended after `-o - -` is | ||
| 10326 | + // silently dropped and the arm encodes a different recipe than the | ||
| 10327 | + // one this gate claims to have run. | ||
| 10328 | + .chain(["--obu", "-o", "-", "-"].map(String::from)) | ||
| 10329 | + .collect(); | ||
| 10330 | + let name = format!( | ||
| 10331 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact[cq{cq}/tx{tx_search}]" | ||
| 10332 | + ); | ||
| 10333 | + let (p, t) = rect_tx_tool_gate(&name, true, &args); | ||
| 10334 | + totals.0 += p; | ||
| 10335 | + totals.1 += t; | ||
| 10336 | + } | ||
| 10337 | + assert_rect_tx_witness( | ||
| 10338 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact", | ||
| 10339 | + totals.0, | ||
| 10340 | + totals.1, | ||
| 10341 | + ); | ||
| 10342 | + eprintln!( | ||
| 10343 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact: 2 arms \ | ||
| 10344 | + pixel-exact; parsed rect partitions {}, rect coefficient TUs {}", | ||
| 10345 | + totals.0, totals.1 | ||
| 10346 | + ); | ||
| 10347 | + } | ||
| 10348 | + | ||
| 10017 | /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. | 10349 | /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. |
| 10018 | /// | 10350 | /// |
| 10019 | /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, | 10351 | /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, |