wip(rect16): builder's in-flight edits, committed verbatim at the 75-turn cap (state unverified by me)
Browse files at this commitca4790ff3ec50db2bcffb1751a3cbbc29771cd7eParent: e7bd50d3 changed files +230 -2
- crates/ec-av1/src/decode.rs +122 -1
- crates/ec-av1/src/refusal_inventory.rs +2 -1
- crates/ec-av1/src/stream.rs +106 -0
crates/ec-av1/src/decode.rsmodified+122 -1
| @@ -341,6 +341,24 @@ pub(crate) fn tx_depth_hits() -> usize { | |||
| 341 | TX_DEPTH_HITS.with(|c| c.get()) | 341 | TX_DEPTH_HITS.with(|c| c.get()) |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | +// How many `partition_w16` reads (a 16x16 block's own partition symbol, key | ||
| 345 | +// intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a | ||
| 346 | +// plain default-settings aomenc run over lavfi mandelbrot hits this arm on | ||
| 347 | +// frame 0's very first non-NONE/SPLIT `partition_w16` symbol (mi=(3,2)), not | ||
| 348 | +// the plain HORZ/VERT this lane's charter assumed. Left rect (8x16, real | ||
| 349 | +// `decode_block_rect`) + two 8x8 leaves stacked on the right (`decode_leaf8`, | ||
| 350 | +// chained via `prev_leaf` exactly like the existing 16x16-SPLIT-into-4x8x8 | ||
| 351 | +// path above). | ||
| 352 | +thread_local! { | ||
| 353 | + static VERT_B_INTRA_HITS: std::cell::Cell<usize> = | ||
| 354 | + const { std::cell::Cell::new(0) }; | ||
| 355 | +} | ||
| 356 | + | ||
| 357 | +/// Current value of [`VERT_B_INTRA_HITS`]. | ||
| 358 | +pub(crate) fn vert_b_intra_hits() -> usize { | ||
| 359 | + VERT_B_INTRA_HITS.with(|c| c.get()) | ||
| 360 | +} | ||
| 361 | + | ||
| 344 | // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` | 362 | // How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D` |
| 345 | // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every | 363 | // (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every |
| 346 | // call on the current thread -- the same before/after counter pattern as | 364 | // call on the current thread -- the same before/after counter pattern as |
| @@ -2854,6 +2872,21 @@ fn decode_block_rect( | |||
| 2854 | vec![0i32; chroma_w * chroma_h], | 2872 | vec![0i32; chroma_w * chroma_h], |
| 2855 | ], | 2873 | ], |
| 2856 | ); | 2874 | ); |
| 2875 | + } else if (bw, bh) != (32, 16) && (bw, bh) != (16, 32) { | ||
| 2876 | + // lane-rect16 r1: a real (non-skip) coefficient read at this size | ||
| 2877 | + // (8x16/16x32 VERT_B's own left strip) is not ported -- it needs its | ||
| 2878 | + // own `TxbSet`/`eob_pt` tables (a true 128-position luma group has no | ||
| 2879 | + // `EOB_PT_128_LUMA` in this decoder yet, only the *chroma* one | ||
| 2880 | + // `lane-rectwire` built for `ChromaRect16x8`) and, unlike the 32x32 | ||
| 2881 | + // sqr-up case `LumaRect32x16` safely skips, `get_ext_tx_set_type` | ||
| 2882 | + // does NOT return `EXT_TX_SET_DCTONLY` at a 16x16 sqr-up under this | ||
| 2883 | + // encoder's reduced_tx_set -- a real `tx_type` symbol may be coded | ||
| 2884 | + // that no table here reads. Refused by name rather than guess-decoded | ||
| 2885 | + // or silently desynced. | ||
| 2886 | + return Err(unsupported( | ||
| 2887 | + "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only \ | ||
| 2888 | + the skip case at this size)", | ||
| 2889 | + )); | ||
| 2857 | } else { | 2890 | } else { |
| 2858 | // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx` | 2891 | // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx` |
| 2859 | // reduces both size pairs to their square-up CDF sets | 2892 | // reduces both size pairs to their square-up CDF sets |
| @@ -5829,9 +5862,97 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5829 | )?; | 5862 | )?; |
| 5830 | continue; | 5863 | continue; |
| 5831 | } | 5864 | } |
| 5865 | + if part16 == PARTITION_VERT_B { | ||
| 5866 | + VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5867 | + // Left rect: 8x16, real | ||
| 5868 | + // `decode_block_rect`, sat at the | ||
| 5869 | + // 16x16 parent's own origin (no | ||
| 5870 | + // fractional-SUB-grid pixel | ||
| 5871 | + // offset needed -- the plain | ||
| 5872 | + // HORZ/VERT arms this lane's | ||
| 5873 | + // charter named DO need one, | ||
| 5874 | + // since their second half is | ||
| 5875 | + // offset by half the parent; | ||
| 5876 | + // unported, see decode_block_rect's | ||
| 5877 | + // own doc comment). | ||
| 5878 | + decode_block_rect( | ||
| 5879 | + &mut dec, | ||
| 5880 | + &mut cdfs, | ||
| 5881 | + &mut neighbours, | ||
| 5882 | + at16, | ||
| 5883 | + 8, | ||
| 5884 | + 16, | ||
| 5885 | + &mut y, | ||
| 5886 | + &mut u, | ||
| 5887 | + &mut v, | ||
| 5888 | + enable_filter_intra, | ||
| 5889 | + allow_screen_content_tools, | ||
| 5890 | + base_q_idx, | ||
| 5891 | + tx_select, | ||
| 5892 | + )?; | ||
| 5893 | + // Two 8x8 squares stacked on the | ||
| 5894 | + // right, chained through | ||
| 5895 | + // `prev_leaf` exactly like the | ||
| 5896 | + // real (non-straddle) SPLIT path | ||
| 5897 | + // below: the bottom leaf's ABOVE | ||
| 5898 | + // context is the top leaf, not | ||
| 5899 | + // the coarse SUB-grid array (a | ||
| 5900 | + // real block never sat there). | ||
| 5901 | + let (mi_row0, mi_col0) = | ||
| 5902 | + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | ||
| 5903 | + let top_right = | ||
| 5904 | + (mi_row0 as usize, mi_col0 as usize + 2); | ||
| 5905 | + let bot_right = | ||
| 5906 | + (mi_row0 as usize + 2, mi_col0 as usize + 2); | ||
| 5907 | + let mode_tr = decode_leaf8( | ||
| 5908 | + &mut dec, | ||
| 5909 | + &mut cdfs, | ||
| 5910 | + &mut neighbours, | ||
| 5911 | + at16, | ||
| 5912 | + top_right, | ||
| 5913 | + (&scan8, &scan4), | ||
| 5914 | + None, | ||
| 5915 | + &mut y, | ||
| 5916 | + &mut u, | ||
| 5917 | + &mut v, | ||
| 5918 | + base_q_idx, | ||
| 5919 | + enable_filter_intra, | ||
| 5920 | + allow_screen_content_tools, | ||
| 5921 | + allow_intrabc, | ||
| 5922 | + tx_select, | ||
| 5923 | + reduced_tx_set, | ||
| 5924 | + )?; | ||
| 5925 | + let mode_br = decode_leaf8( | ||
| 5926 | + &mut dec, | ||
| 5927 | + &mut cdfs, | ||
| 5928 | + &mut neighbours, | ||
| 5929 | + at16, | ||
| 5930 | + bot_right, | ||
| 5931 | + (&scan8, &scan4), | ||
| 5932 | + Some((top_right, mode_tr)), | ||
| 5933 | + &mut y, | ||
| 5934 | + &mut u, | ||
| 5935 | + &mut v, | ||
| 5936 | + base_q_idx, | ||
| 5937 | + enable_filter_intra, | ||
| 5938 | + allow_screen_content_tools, | ||
| 5939 | + allow_intrabc, | ||
| 5940 | + tx_select, | ||
| 5941 | + reduced_tx_set, | ||
| 5942 | + )?; | ||
| 5943 | + // `record()`'s above_mode/left_mode | ||
| 5944 | + // write is a no-op at an 8x8 | ||
| 5945 | + // leaf's own side (same gap the | ||
| 5946 | + // real-SPLIT path above patches): | ||
| 5947 | + // force it from the last-decoded | ||
| 5948 | + // (bottom-right) leaf. | ||
| 5949 | + neighbours.above_mode[sc] = mode_br; | ||
| 5950 | + neighbours.left_mode[sr] = mode_br; | ||
| 5951 | + continue; | ||
| 5952 | + } | ||
| 5832 | if part16 != PARTITION_SPLIT { | 5953 | if part16 != PARTITION_SPLIT { |
| 5833 | return Err(unsupported( | 5954 | return Err(unsupported( |
| 5834 | - "a partition below 16x16 other than a clean split (this decoder codes only the square arms below 16x16)", | 5955 | + "a partition below 16x16 other than a clean split or a VERT_B (this decoder codes only the square arms, VERT_B, and a clean split below 16x16)", |
| 5835 | )); | 5956 | )); |
| 5836 | } | 5957 | } |
| 5837 | // A real (non-straddle) SPLIT of a | 5958 | // A real (non-straddle) SPLIT of a |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -27,7 +27,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[ | |||
| 27 | "a non-2D tx class on a rectangular transform (never expected at this size)", | 27 | "a non-2D tx class on a rectangular transform (never expected at this size)", |
| 28 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | 28 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 29 | "a nonzero angle delta (this encoder never writes one)", | 29 | "a nonzero angle delta (this encoder never writes one)", |
| 30 | - "a partition below 16x16 other than a clean split (this decoder codes only the square arms below 16x16)", | ||
| 31 | "a partition below 8x8 (this encoder never writes one)", | 30 | "a partition below 8x8 (this encoder never writes one)", |
| 32 | "a tx_type symbol on a rectangular transform (never expected at this size)", | 31 | "a tx_type symbol on a rectangular transform (never expected at this size)", |
| 33 | ]; | 32 | ]; |
| @@ -35,6 +34,8 @@ const CAPABILITY_CLAIMS: &[&str] = &[ | |||
| 35 | #[cfg(test)] | 34 | #[cfg(test)] |
| 36 | const REFUSALS: &[&str] = &[ | 35 | const REFUSALS: &[&str] = &[ |
| 37 | "GLOBALMV (round 3)", | 36 | "GLOBALMV (round 3)", |
| 37 | + "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", | ||
| 38 | + "a partition below 16x16 other than a clean split or a VERT_B (this decoder codes only the square arms, VERT_B, and a clean split below 16x16)", | ||
| 38 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 39 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 39 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 40 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 40 | "a 32x32 partition type this decoder does not code (value={part32})", | 41 | "a 32x32 partition type this decoder does not code (value={part32})", |
crates/ec-av1/src/stream.rsmodified+106 -0
| @@ -4799,6 +4799,112 @@ mod tests { | |||
| 4799 | crate::decode::wii_hits() | 4799 | crate::decode::wii_hits() |
| 4800 | ); | 4800 | ); |
| 4801 | } | 4801 | } |
| 4802 | + | ||
| 4803 | + /// lane-rect16 r1: a plain default-settings aomenc run over lavfi | ||
| 4804 | + /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no | ||
| 4805 | + /// `--enable-*` flags) used to refuse frame 0 outright with "a partition | ||
| 4806 | + /// below 16x16 other than a clean split" -- reproduced live with | ||
| 4807 | + /// `decode_probe`, root-caused to a `PARTITION_VERT_B` `partition_w16` | ||
| 4808 | + /// symbol at mi=(3,2), not the plain HORZ/VERT this lane's charter | ||
| 4809 | + /// assumed (`refusal-names-a-correlate`). The `PARTITION_VERT_B` arm is | ||
| 4810 | + /// now wired (left 8x16 real `decode_block_rect` strip + two stacked | ||
| 4811 | + /// 8x8 `decode_leaf8` leaves on the right); `vert_b_intra_hits` proves | ||
| 4812 | + /// that arm fires. This exact stream's own VERT_B block is *coded* | ||
| 4813 | + /// (real coefficients), which is NOT ported (see the refusal on | ||
| 4814 | + /// `decode_block_rect`'s non-skip else-branch) -- so this gate proves | ||
| 4815 | + /// the new arm fires and no longer trips the OLD (now-false) refusal, | ||
| 4816 | + /// not a pixel-exact decode of this stream. | ||
| 4817 | + #[test] | ||
| 4818 | + fn a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm() { | ||
| 4819 | + const NAME: &str = "a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm"; | ||
| 4820 | + let _gate_lock = lock_gate_counters(); | ||
| 4821 | + if !have_ffmpeg() { | ||
| 4822 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 4823 | + return; | ||
| 4824 | + } | ||
| 4825 | + if !have_aomenc() { | ||
| 4826 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 4827 | + return; | ||
| 4828 | + } | ||
| 4829 | + let (width, height) = (192usize, 128usize); | ||
| 4830 | + let y4m = Command::new("ffmpeg") | ||
| 4831 | + .args([ | ||
| 4832 | + "-v", | ||
| 4833 | + "error", | ||
| 4834 | + "-f", | ||
| 4835 | + "lavfi", | ||
| 4836 | + "-i", | ||
| 4837 | + &format!("mandelbrot=size={width}x{height}"), | ||
| 4838 | + "-pix_fmt", | ||
| 4839 | + "yuv420p", | ||
| 4840 | + "-t", | ||
| 4841 | + "1", | ||
| 4842 | + "-f", | ||
| 4843 | + "yuv4mpegpipe", | ||
| 4844 | + "-", | ||
| 4845 | + ]) | ||
| 4846 | + .stdin(Stdio::null()) | ||
| 4847 | + .stdout(Stdio::piped()) | ||
| 4848 | + .stderr(Stdio::piped()) | ||
| 4849 | + .output() | ||
| 4850 | + .expect("ffmpeg failed to run"); | ||
| 4851 | + assert!( | ||
| 4852 | + y4m.status.success(), | ||
| 4853 | + "ffmpeg fixture: {}", | ||
| 4854 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 4855 | + ); | ||
| 4856 | + let mut child = Command::new(aomenc_path()) | ||
| 4857 | + .args([ | ||
| 4858 | + "--threads=1", | ||
| 4859 | + "--row-mt=0", | ||
| 4860 | + "--sb-size=64", | ||
| 4861 | + "--cpu-used=4", | ||
| 4862 | + "--end-usage=q", | ||
| 4863 | + "--cq-level=32", | ||
| 4864 | + "--obu", | ||
| 4865 | + "-o", | ||
| 4866 | + "-", | ||
| 4867 | + "-", | ||
| 4868 | + ]) | ||
| 4869 | + .stdin(Stdio::piped()) | ||
| 4870 | + .stdout(Stdio::piped()) | ||
| 4871 | + .stderr(Stdio::piped()) | ||
| 4872 | + .spawn() | ||
| 4873 | + .expect("aomenc failed to start"); | ||
| 4874 | + child | ||
| 4875 | + .stdin | ||
| 4876 | + .take() | ||
| 4877 | + .expect("aomenc stdin") | ||
| 4878 | + .write_all(&y4m.stdout) | ||
| 4879 | + .expect("writing y4m to aomenc"); | ||
| 4880 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 4881 | + assert!( | ||
| 4882 | + out.status.success(), | ||
| 4883 | + "aomenc refused the fixture: {}", | ||
| 4884 | + String::from_utf8_lossy(&out.stderr) | ||
| 4885 | + ); | ||
| 4886 | + let stream = out.stdout; | ||
| 4887 | + let result = decode_stream(&stream); | ||
| 4888 | + // The now-lifted false claim ("codes only the square arms below | ||
| 4889 | + // 16x16") must never appear again. | ||
| 4890 | + if let Err(e) = &result { | ||
| 4891 | + let msg = e.to_string(); | ||
| 4892 | + assert!( | ||
| 4893 | + !msg.contains("this decoder codes only the square arms below 16x16"), | ||
| 4894 | + "{NAME}: the OLD (disproved) refusal reappeared: {msg}" | ||
| 4895 | + ); | ||
| 4896 | + } | ||
| 4897 | + assert!( | ||
| 4898 | + crate::decode::vert_b_intra_hits() > 0, | ||
| 4899 | + "{NAME}: the PARTITION_VERT_B arm never fired on this stream (regression -- it fired \ | ||
| 4900 | + deterministically at mi=(3,2) when this gate was written)" | ||
| 4901 | + ); | ||
| 4902 | + eprintln!( | ||
| 4903 | + "{NAME}: vert_b_intra_hits={}, decode result: {:?}", | ||
| 4904 | + crate::decode::vert_b_intra_hits(), | ||
| 4905 | + result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) | ||
| 4906 | + ); | ||
| 4907 | + } | ||
| 4802 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 | 4908 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 |
| 4803 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never | 4909 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never |
| 4804 | /// gets to choose a real rect/ab split. This charter's premise ("rect | 4910 | /// gets to choose a real rect/ab split. This charter's premise ("rect |