ec-av1: gate enable-rect-tx at both depths on the PARSED partition shape
Browse files at this commit0f3e8bf2214332ab5cf7cf7b2abb27abb0e66906Parent: a460dca1 changed file +332 -0
- crates/ec-av1/src/stream.rs +332 -0
crates/ec-av1/src/stream.rsmodified+332 -0
| @@ -9637,6 +9637,338 @@ pub(crate) mod tests { | ||
| 9637 | 9637 | ); |
| 9638 | 9638 | } |
| 9639 | 9639 | |
| 9640 | + /// lane-av1toolgates: the shared body of the two `enable-rect-tx` | |
| 9641 | + /// coverage gates (8-bit and 10-bit). | |
| 9642 | + /// | |
| 9643 | + /// The aomenc ARGUMENT VECTOR is built by each gate and passed in, never | |
| 9644 | + /// assembled here. That is not tidiness: `gate_coverage`'s `gate_bodies()` | |
| 9645 | + /// splits `stream.rs` on `\n #[` and keeps a segment only if that | |
| 9646 | + /// segment itself contains `--passes=1`, so a flag living in a helper is | |
| 9647 | + /// invisible to the coverage derivation. A helper that owns the recipe | |
| 9648 | + /// would leave this gate counted at whatever depth the helper's own text | |
| 9649 | + /// implies -- which is the blind spot that kept `enable-rect-tx` on the | |
| 9650 | + /// `NEVER_EXERCISED` lists after real streams had exercised it. | |
| 9651 | + /// | |
| 9652 | + /// WHAT THIS GATE IS AND IS NOT. `enable_rect_tx` has no sequence-header | |
| 9653 | + /// bit in AV1 -- aom reads it only in `tx_search.c` (`search_tx_size`'s | |
| 9654 | + /// `!enable_rect_tx && tx_size_wide != tx_size_high` skip and the | |
| 9655 | + /// `tx_size_max_32_square` remap) -- so the flag never reaches a decoder. | |
| 9656 | + /// Spelling `--enable-rect-tx=1` proves the ENCODER was ALLOWED the tool | |
| 9657 | + /// and nothing more. It is CONTEXT here, not the witness: a gate that | |
| 9658 | + /// stopped at the flag would be the `tool-disabled-in-every-gate` defect | |
| 9659 | + /// `NEVER_EXERCISED` exists to prevent, in a new costume. | |
| 9660 | + /// | |
| 9661 | + /// The witness is the PARSED PARTITION SHAPE, the only thing in the | |
| 9662 | + /// bitstream that can carry a rect transform: | |
| 9663 | + /// [`decode::rect_partition_hits`] counts `PARTITION_HORZ`/`PARTITION_VERT` | |
| 9664 | + /// symbols actually read, i.e. a rect partition in the tree this decoder | |
| 9665 | + /// walked, and [`decode::rect_coeff_tu_hits`] counts the rectangular | |
| 9666 | + /// transform units that then coded coefficients through `read_coeffs_rect` | |
| 9667 | + /// (`all_zero == 0`) -- the rect coefficient TABLES being read, not a | |
| 9668 | + /// header bit. Both are asserted above zero over the arms that decoded AND | |
| 9669 | + /// compared, and every frame is pixel-compared against ffmpeg's own decode | |
| 9670 | + /// of the identical bytes. | |
| 9671 | + /// | |
| 9672 | + /// LIMIT, stated because it bounds what this gate can claim: this | |
| 9673 | + /// repository has no INDEPENDENT partition parser to list leaves from -- | |
| 9674 | + /// `ec-av1-syntax` parses OBU headers and the sequence header only -- and | |
| 9675 | + /// `ec_av1::census`'s per-frame `blocks`/`tx` shape maps, the one true | |
| 9676 | + /// leaf list, are armed by a process-global `OnceLock` on | |
| 9677 | + /// `EC_AV1_BITCENSUS`, so arming them inside a lib test would switch the | |
| 9678 | + /// accountant on for every other gate in the process. The partition walk is | |
| 9679 | + /// therefore observed through the decoder's own counters, which is weaker | |
| 9680 | + /// than a second opinion but is still a shape fact about the stream rather | |
| 9681 | + /// than a fact about the flag. | |
| 9682 | + /// | |
| 9683 | + /// RED-BEFORE: the COUNTERS, one per assert, both measured. | |
| 9684 | + /// `--enable-rect-tx=0` is deliberately NOT claimed as the mutation: it | |
| 9685 | + /// does NOT zero these counters (39 rect coefficient TUs against 210 on | |
| 9686 | + /// the cq20 arm, because `--enable-rect-partitions=1` already forces | |
| 9687 | + /// non-square transform sizes regardless), and with every partition shape | |
| 9688 | + /// off the flag yields no rect transform at either setting. `=0` does turn | |
| 9689 | + /// the gate red, but through the ORACLE -- its `--enable-tx-size-search=0` | |
| 9690 | + /// arm is a stream ffmpeg cannot decode past frame 6 of 15 -- so the | |
| 9691 | + /// frame-count assert fires first and proves nothing about the tool. | |
| 9692 | + fn rect_tx_tool_gate(name: &str, ten_bit: bool, args: &[String]) -> (usize, usize) { | |
| 9693 | + // A missing tool SKIPs, so the totals the caller sums stay 0 and the | |
| 9694 | + // gate's own witness assert fails loudly instead of passing vacuously | |
| 9695 | + // on a run that decoded nothing. | |
| 9696 | + if !have_ffmpeg() { | |
| 9697 | + eprintln!("SKIP {name}: no ffmpeg"); | |
| 9698 | + return (0, 0); | |
| 9699 | + } | |
| 9700 | + if !have_aomenc() { | |
| 9701 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | |
| 9702 | + return (0, 0); | |
| 9703 | + } | |
| 9704 | + let (width, height) = (64usize, 64usize); | |
| 9705 | + let y4m = Command::new("ffmpeg") | |
| 9706 | + .args([ | |
| 9707 | + "-v", | |
| 9708 | + "error", | |
| 9709 | + "-f", | |
| 9710 | + "lavfi", | |
| 9711 | + "-i", | |
| 9712 | + "mandelbrot=size=64x64:rate=25", | |
| 9713 | + "-pix_fmt", | |
| 9714 | + if ten_bit { "yuv420p10le" } else { "yuv420p" }, | |
| 9715 | + // y4m calls 10-bit an unofficial pixel format (no-op at 8). | |
| 9716 | + "-strict", | |
| 9717 | + "-1", | |
| 9718 | + "-t", | |
| 9719 | + "0.60", | |
| 9720 | + "-f", | |
| 9721 | + "yuv4mpegpipe", | |
| 9722 | + "-", | |
| 9723 | + ]) | |
| 9724 | + .stdin(Stdio::null()) | |
| 9725 | + .stdout(Stdio::piped()) | |
| 9726 | + .stderr(Stdio::piped()) | |
| 9727 | + .output() | |
| 9728 | + .expect("ffmpeg failed to run"); | |
| 9729 | + assert!( | |
| 9730 | + y4m.status.success(), | |
| 9731 | + "{name}: ffmpeg fixture: {}", | |
| 9732 | + String::from_utf8_lossy(&y4m.stderr) | |
| 9733 | + ); | |
| 9734 | + let out = run_with_stdin(Command::new(aomenc_path()).args(args), &y4m.stdout); | |
| 9735 | + assert!( | |
| 9736 | + out.status.success(), | |
| 9737 | + "{name}: aomenc refused the fixture: {}", | |
| 9738 | + String::from_utf8_lossy(&out.stderr) | |
| 9739 | + ); | |
| 9740 | + let stream = out.stdout; | |
| 9741 | + assert!(!stream.is_empty(), "{name}: aomenc wrote an empty stream"); | |
| 9742 | + if ten_bit { | |
| 9743 | + assert_eq!( | |
| 9744 | + parsed_bit_depth(&stream), | |
| 9745 | + 10, | |
| 9746 | + "{name}: aomenc did not write a 10-bit sequence header" | |
| 9747 | + ); | |
| 9748 | + } | |
| 9749 | + let parts_before = decode::rect_partition_hits(); | |
| 9750 | + let tus_before = decode::rect_coeff_tu_hits(); | |
| 9751 | + let decoded = match decode_stream(&stream) { | |
| 9752 | + Ok(frames) => frames, | |
| 9753 | + Err(e) => panic!("{name}: decode_stream refused: {e}"), | |
| 9754 | + }; | |
| 9755 | + // Sampled after the decode, before the pixel compare, so a mismatch | |
| 9756 | + // report can still say whether the arm fired. | |
| 9757 | + let parts = decode::rect_partition_hits() - parts_before; | |
| 9758 | + let tus = decode::rect_coeff_tu_hits() - tus_before; | |
| 9759 | + let reference = if ten_bit { | |
| 9760 | + ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len()) | |
| 9761 | + } else { | |
| 9762 | + ffmpeg_decode_sequence(&stream, width, height, decoded.len()) | |
| 9763 | + }; | |
| 9764 | + assert_eq!( | |
| 9765 | + decoded.len(), | |
| 9766 | + reference.len(), | |
| 9767 | + "{name}: shown-frame count vs ffmpeg (rect partitions {parts}, rect coefficient \ | |
| 9768 | + TUs {tus})" | |
| 9769 | + ); | |
| 9770 | + for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { | |
| 9771 | + for (plane, (a, b), w) in [ | |
| 9772 | + ("Y", (&ours.y, &theirs.y), width), | |
| 9773 | + ("U", (&ours.u, &theirs.u), width / 2), | |
| 9774 | + ("V", (&ours.v, &theirs.v), width / 2), | |
| 9775 | + ] { | |
| 9776 | + assert_eq!(a.len(), b.len(), "{name}: frame {i} {plane} plane length"); | |
| 9777 | + if a != b { | |
| 9778 | + let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu")); | |
| 9779 | + let _ = std::fs::write(&pin, &stream); | |
| 9780 | + let at = a | |
| 9781 | + .iter() | |
| 9782 | + .zip(b.iter()) | |
| 9783 | + .position(|(x, y)| x != y) | |
| 9784 | + .unwrap_or(0); | |
| 9785 | + panic!( | |
| 9786 | + "{name}: frame {i} {plane} mismatch vs ffmpeg at row {}, col {}: {} vs \ | |
| 9787 | + {} (rect partitions {parts}, rect coefficient TUs {tus}; stream pinned \ | |
| 9788 | + at {})", | |
| 9789 | + at / w, | |
| 9790 | + at % w, | |
| 9791 | + a[at], | |
| 9792 | + b[at], | |
| 9793 | + pin.display() | |
| 9794 | + ); | |
| 9795 | + } | |
| 9796 | + } | |
| 9797 | + } | |
| 9798 | + eprintln!( | |
| 9799 | + "{name}: {} bit, pixel-exact vs ffmpeg; parsed rect partitions {parts}, rect \ | |
| 9800 | + coefficient TUs {tus}", | |
| 9801 | + if ten_bit { "10" } else { "8" } | |
| 9802 | + ); | |
| 9803 | + (parts, tus) | |
| 9804 | + } | |
| 9805 | + | |
| 9806 | + /// lane-av1toolgates: the gate-level WITNESS, summed over the arms that | |
| 9807 | + /// decoded AND compared. It cannot be asserted per arm: the cq20 / | |
| 9808 | + /// tx-size-search=1 arm reaches a rect transform through the var-tx | |
| 9809 | + /// search on a SQUARE block (a nonzero rect coefficient count with zero | |
| 9810 | + /// rect partitions read -- the purest form of what `--enable-rect-tx` | |
| 9811 | + /// buys), while the rect PARTITION only shows up on the | |
| 9812 | + /// tx-size-search=0 arm. Either fact alone would let a stream through on | |
| 9813 | + /// which the tool was allowed and unused, which is the defect this | |
| 9814 | + /// coverage entry was written for; together they are the parsed-shape | |
| 9815 | + /// evidence the entry asked for. | |
| 9816 | + #[track_caller] | |
| 9817 | + fn assert_rect_tx_witness(name: &str, parts: usize, tus: usize) { | |
| 9818 | + assert!( | |
| 9819 | + parts > 0, | |
| 9820 | + "{name}: no PARTITION_HORZ/PARTITION_VERT symbol was read on any pixel-exact decode \ | |
| 9821 | + -- the parsed partition tree never yielded a rect leaf, so `--enable-rect-tx=1` \ | |
| 9822 | + was allowed and unused" | |
| 9823 | + ); | |
| 9824 | + assert!( | |
| 9825 | + tus > 0, | |
| 9826 | + "{name}: no rectangular transform unit coded coefficients through read_coeffs_rect \ | |
| 9827 | + ({parts} rect partitions read) -- the rect coefficient path was never taken" | |
| 9828 | + ); | |
| 9829 | + } | |
| 9830 | + | |
| 9831 | + /// lane-av1toolgates: `enable-rect-tx` at 8 BITS. See | |
| 9832 | + /// [`rect_tx_tool_gate`] for what the flag does and does not prove, and | |
| 9833 | + /// why the recipe is spelled here rather than in the helper. | |
| 9834 | + /// | |
| 9835 | + /// The whole recipe is inline: `--passes=1` has to be findable in this | |
| 9836 | + /// segment for the coverage derivation to count the gate at all, and | |
| 9837 | + /// `--enable-rect-tx=1` has to be findable here for it to count the | |
| 9838 | + /// TOOL. The quantiser and the tx-size-search setting are swept as two | |
| 9839 | + /// arms so the witness cannot rest on one RD interaction. | |
| 9840 | + #[test] | |
| 9841 | + fn a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact() { | |
| 9842 | + let mut totals = (0usize, 0usize); | |
| 9843 | + for (cq, tx_search) in [("20", "1"), ("40", "0")] { | |
| 9844 | + let args: Vec<String> = [ | |
| 9845 | + "--codec=av1", | |
| 9846 | + "--passes=1", | |
| 9847 | + "--end-usage=q", | |
| 9848 | + "--cpu-used=0", | |
| 9849 | + "--threads=1", | |
| 9850 | + "--row-mt=0", | |
| 9851 | + "--lag-in-frames=0", | |
| 9852 | + "--auto-alt-ref=0", | |
| 9853 | + "--kf-max-dist=1000", | |
| 9854 | + "--error-resilient=1", | |
| 9855 | + "--sb-size=64", | |
| 9856 | + // The tool under test, spelled explicitly. CONTEXT, per | |
| 9857 | + // `rect_tx_tool_gate`: aomenc was ALLOWED rect tx sizes. | |
| 9858 | + "--enable-rect-tx=1", | |
| 9859 | + "--enable-rect-partitions=1", | |
| 9860 | + "--enable-ab-partitions=0", | |
| 9861 | + "--enable-1to4-partitions=0", | |
| 9862 | + "--enable-restoration=0", | |
| 9863 | + "--enable-palette=0", | |
| 9864 | + "--enable-cdef=0", | |
| 9865 | + "--enable-cfl-intra=0", | |
| 9866 | + "--enable-intrabc=0", | |
| 9867 | + "--enable-order-hint=0", | |
| 9868 | + "--min-partition-size=8", | |
| 9869 | + "--max-partition-size=32", | |
| 9870 | + ] | |
| 9871 | + .map(String::from) | |
| 9872 | + .into_iter() | |
| 9873 | + .chain([ | |
| 9874 | + format!("--cq-level={cq}"), | |
| 9875 | + format!("--enable-tx-size-search={tx_search}"), | |
| 9876 | + ]) | |
| 9877 | + // The output tail comes LAST: aomenc stops reading flags at the | |
| 9878 | + // first bare argument, so a sweep flag appended after `-o - -` is | |
| 9879 | + // silently dropped and the arm encodes a different recipe than the | |
| 9880 | + // one this gate claims to have run. | |
| 9881 | + .chain(["--obu", "-o", "-", "-"].map(String::from)) | |
| 9882 | + .collect(); | |
| 9883 | + let name = format!( | |
| 9884 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact[cq{cq}/tx{tx_search}]" | |
| 9885 | + ); | |
| 9886 | + let (p, t) = rect_tx_tool_gate(&name, false, &args); | |
| 9887 | + totals.0 += p; | |
| 9888 | + totals.1 += t; | |
| 9889 | + } | |
| 9890 | + assert_rect_tx_witness( | |
| 9891 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact", | |
| 9892 | + totals.0, | |
| 9893 | + totals.1, | |
| 9894 | + ); | |
| 9895 | + eprintln!( | |
| 9896 | + "a_real_aomenc_8bit_stream_with_a_rect_transform_decodes_pixel_exact: 2 arms \ | |
| 9897 | + pixel-exact; parsed rect partitions {}, rect coefficient TUs {}", | |
| 9898 | + totals.0, totals.1 | |
| 9899 | + ); | |
| 9900 | + } | |
| 9901 | + | |
| 9902 | + /// lane-av1toolgates: `enable-rect-tx` at 10 BITS -- the same recipe, the | |
| 9903 | + /// same parsed-shape witness, at the depth the 8-bit arm says nothing | |
| 9904 | + /// about (the per-depth rule `NEVER_EXERCISED_10BIT` is built on: | |
| 9905 | + /// lane-hbdinter's two 10-bit-only defects survived because every 10-bit | |
| 9906 | + /// gate pinned the filters off). The depth is spelled in THIS body, | |
| 9907 | + /// which is what files the gate in the 10-bit bucket. | |
| 9908 | + #[test] | |
| 9909 | + fn a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact() { | |
| 9910 | + let mut totals = (0usize, 0usize); | |
| 9911 | + for (cq, tx_search) in [("20", "1"), ("40", "0")] { | |
| 9912 | + let args: Vec<String> = [ | |
| 9913 | + "--codec=av1", | |
| 9914 | + "--passes=1", | |
| 9915 | + "--end-usage=q", | |
| 9916 | + "--cpu-used=0", | |
| 9917 | + "--threads=1", | |
| 9918 | + "--row-mt=0", | |
| 9919 | + "--lag-in-frames=0", | |
| 9920 | + "--auto-alt-ref=0", | |
| 9921 | + "--kf-max-dist=1000", | |
| 9922 | + "--error-resilient=1", | |
| 9923 | + "--sb-size=64", | |
| 9924 | + "--input-bit-depth=10", | |
| 9925 | + "--bit-depth=10", | |
| 9926 | + // The tool under test, spelled explicitly. CONTEXT, per | |
| 9927 | + // `rect_tx_tool_gate`: aomenc was ALLOWED rect tx sizes. | |
| 9928 | + "--enable-rect-tx=1", | |
| 9929 | + "--enable-rect-partitions=1", | |
| 9930 | + "--enable-ab-partitions=0", | |
| 9931 | + "--enable-1to4-partitions=0", | |
| 9932 | + "--enable-restoration=0", | |
| 9933 | + "--enable-palette=0", | |
| 9934 | + "--enable-cdef=0", | |
| 9935 | + "--enable-cfl-intra=0", | |
| 9936 | + "--enable-intrabc=0", | |
| 9937 | + "--enable-order-hint=0", | |
| 9938 | + "--min-partition-size=8", | |
| 9939 | + "--max-partition-size=32", | |
| 9940 | + ] | |
| 9941 | + .map(String::from) | |
| 9942 | + .into_iter() | |
| 9943 | + .chain([ | |
| 9944 | + format!("--cq-level={cq}"), | |
| 9945 | + format!("--enable-tx-size-search={tx_search}"), | |
| 9946 | + ]) | |
| 9947 | + // The output tail comes LAST: aomenc stops reading flags at the | |
| 9948 | + // first bare argument, so a sweep flag appended after `-o - -` is | |
| 9949 | + // silently dropped and the arm encodes a different recipe than the | |
| 9950 | + // one this gate claims to have run. | |
| 9951 | + .chain(["--obu", "-o", "-", "-"].map(String::from)) | |
| 9952 | + .collect(); | |
| 9953 | + let name = format!( | |
| 9954 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact[cq{cq}/tx{tx_search}]" | |
| 9955 | + ); | |
| 9956 | + let (p, t) = rect_tx_tool_gate(&name, true, &args); | |
| 9957 | + totals.0 += p; | |
| 9958 | + totals.1 += t; | |
| 9959 | + } | |
| 9960 | + assert_rect_tx_witness( | |
| 9961 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact", | |
| 9962 | + totals.0, | |
| 9963 | + totals.1, | |
| 9964 | + ); | |
| 9965 | + eprintln!( | |
| 9966 | + "a_real_aomenc_10bit_stream_with_a_rect_transform_decodes_pixel_exact: 2 arms \ | |
| 9967 | + pixel-exact; parsed rect partitions {}, rect coefficient TUs {}", | |
| 9968 | + totals.0, totals.1 | |
| 9969 | + ); | |
| 9970 | + } | |
| 9971 | + | |
| 9640 | 9972 | /// lane-kf900 r5, the gate for the rect-strip `use_intrabc` read. |
| 9641 | 9973 | /// |
| 9642 | 9974 | /// `av1_allow_intrabc` is a FRAME-level test (`decodemv.c:892`, |