forge
Explore
Log in

Don't you dare go Hollow

The seven-type TX_SET_INTRA_1 tx_type row, V_DCT/H_DCT, gate fires

Browse files at this commit

24117910f97bb2a08ca36628ab4bfef31c1798b2Ahmet Kaan GümüşParent: dcf1147
  • feat
    • the seven-type TX_SET_INTRA_1 tx_type row, V_DCT/H_DCT, gate fires
Show full message
feat(av1): the seven-type TX_SET_INTRA_1 tx_type row, V_DCT/H_DCT, gate fires

A reduced_tx_set=0 frame's 8x8-and-under intra transforms read tx_type
from the seven-symbol TX_SET_INTRA_1, not the five-symbol reduced row
our tables carried (the row-held-constant class, on the tx-set
dimension -- our own encoder always writes reduced_tx_set=1, the same
writer-never-needs-it trap as mv_hp). New set-1 CDF row, the set-1
symbol order from av1_ext_tx_inv, and the V_DCT/H_DCT inverse
transforms (one-axis DCT, identity on the other). The tx-select gate
now actually FIRES: mandelbrot content at min-partition 16 splits
16x16 blocks into TX8 TUs that read the set-1 rows and decode
pixel-exact vs ffmpeg, 4/4 runs, no skips. Resolved 4x4 luma stays a
named refusal (no TX4 coefficient tables yet).
crates/ec-av1/examples/probe_txsel.rsdeleted+0 -63
@@ -1,63 +0,0 @@
1-use std::io::Write;
2-use std::process::{Command, Stdio};
3-
4-fn main() {
5- let path = std::env::args()
6- .nth(1)
7- .unwrap_or_else(|| "/tmp/mb.obu".into());
8- let stream = std::fs::read(&path).expect("read stream");
9- let frames = match ec_av1::stream::decode_stream(&stream) {
10- Ok(f) => f,
11- Err(e) => {
12- eprintln!("decode error: {e}");
13- std::process::exit(1);
14- }
15- };
16- let (width, height) = (64usize, 64usize);
17- let mut child = Command::new("ffmpeg")
18- .args([
19- "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
20- ])
21- .stdin(Stdio::piped())
22- .stdout(Stdio::piped())
23- .stderr(Stdio::piped())
24- .spawn()
25- .expect("ffmpeg spawn");
26- child
27- .stdin
28- .take()
29- .unwrap()
30- .write_all(&stream)
31- .expect("write stream");
32- let out = child.wait_with_output().expect("ffmpeg run");
33- if !out.status.success() {
34- eprintln!("ffmpeg refused: {}", String::from_utf8_lossy(&out.stderr));
35- std::process::exit(1);
36- }
37- let luma = width * height;
38- let chroma = luma / 4;
39- let y_ref = &out.stdout[..luma];
40- let u_ref = &out.stdout[luma..luma + chroma];
41- let v_ref = &out.stdout[luma + chroma..luma + 2 * chroma];
42-
43- let pic = &frames[0];
44- let y_match = pic.y == y_ref;
45- let u_match = pic.u == u_ref;
46- let v_match = pic.v == v_ref;
47- println!("decoded ok, y_match={y_match} u_match={u_match} v_match={v_match}");
48- if !y_match {
49- for i in 0..luma {
50- if pic.y[i] != y_ref[i] {
51- println!(
52- "first luma mismatch at idx {i} (row {} col {}): ours={} ref={}",
53- i / width,
54- i % width,
55- pic.y[i],
56- y_ref[i]
57- );
58- break;
59- }
60- }
61- }
62- std::process::exit(if y_match && u_match && v_match { 0 } else { 2 });
63-}
crates/ec-av1/src/cdf_state.rsmodified+24 -0
@@ -41,6 +41,10 @@ pub(crate) enum TxbSet {
4141 /// block (lane-av1-rect). An `is_inter` leaf reads
4242 /// [`Luma8Inter`](TxbSet::Luma8Inter) instead.
4343 Luma8,
44+ /// [`Luma8`](TxbSet::Luma8)'s `reduced_tx_set: false` counterpart (round
45+ /// 8): the same coefficient tables, but the seven-symbol `TX_SET_INTRA_1`
46+ /// `tx_type` table rather than `Luma8`'s five-symbol reduced one.
47+ Luma8Set1,
4448 /// The 8x8 luma transform of an `is_inter` 8x8 leaf under a straddling
4549 /// 16x16 block (lane-av1inter8): the same coefficient tables
4650 /// [`Luma8`](TxbSet::Luma8) reads, but `get_tx_set` (spec 5.11.48)
@@ -225,6 +229,13 @@ pub(crate) struct Cdfs {
225229 pub intra_tx_type_16: [[u16; 6]; 13],
226230 /// The transform type of an 8x8 intra luma transform, by luma mode.
227231 pub intra_tx_type_8: [[u16; 6]; 13],
232+ /// The transform type of an 8x8 intra luma transform, by luma mode, when
233+ /// `reduced_tx_set` is false (spec `TX_SET_INTRA_1`, seven types) --
234+ /// [`Self::intra_tx_type_8`]'s five-type table is only the
235+ /// `reduced_tx_set` row (round 8: a real `aomenc` stream with
236+ /// `reduced_tx_set` off desyncs an 8x8 TU read against this row's
237+ /// wrong-length CDF).
238+ pub intra_tx_type_8_set1: [[u16; 8]; 13],
228239 /// The transform type of an `is_inter` 32x32 luma transform (spec
229240 /// `TX_SET_INTER_3`, `TX_32X32` row) -- unlike the intra 16x16 table, it
230241 /// is not indexed by mode.
@@ -430,6 +441,7 @@ impl Cdfs {
430441 reset2(&mut self.dc_sign_luma);
431442 reset2(&mut self.intra_tx_type_16);
432443 reset2(&mut self.intra_tx_type_8);
444+ reset2(&mut self.intra_tx_type_8_set1);
433445 reset1(&mut self.inter_tx_type_32);
434446 reset1(&mut self.inter_tx_type_16);
435447 reset1(&mut self.inter_tx_type_8);
@@ -795,6 +807,7 @@ impl Cdfs {
795807 dc_sign_luma: cdf::DC_SIGN_LUMA,
796808 intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16,
797809 intra_tx_type_8: cdf::INTRA_TX_TYPE_SET2_8,
810+ intra_tx_type_8_set1: cdf::INTRA_TX_TYPE_SET1_8,
798811 inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32,
799812 inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16,
800813 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,
@@ -886,6 +899,17 @@ impl Cdfs {
886899 dc_sign: &mut self.dc_sign_luma,
887900 tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()),
888901 },
902+ TxbSet::Luma8Set1 => TxbTables {
903+ side: 8,
904+ txb_skip: &mut self.txb_skip_luma_8,
905+ eob_pt: &mut self.eob_pt_64_luma,
906+ eob_extra: &mut self.eob_extra_luma_8,
907+ base: &mut self.base_luma_8,
908+ base_eob: &mut self.base_eob_luma_8,
909+ br: &mut self.br_luma_8,
910+ dc_sign: &mut self.dc_sign_luma,
911+ tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()),
912+ },
889913 TxbSet::Luma8Inter => TxbTables {
890914 side: 8,
891915 txb_skip: &mut self.txb_skip_luma_8,
crates/ec-av1/src/decode.rsmodified+43 -10
@@ -288,13 +288,20 @@ fn read_coeffs(
288288 }
289289 let mut tx_type = TxType::DctDct;
290290 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
291+ // The CDF row's own width names its set: 7 symbols (8 slots) is
292+ // `TX_SET_INTRA_1`, 5 (6 slots) the reduced `TX_SET_INTRA_2` (the
293+ // inter sets we read share set 2's symbol order).
294+ let set1 = tx_type_cdf.len() == 8;
291295 let t = dec.symbol(tx_type_cdf);
292296 if trace {
293- eprintln!("TRACE tx_type value={t}");
297+ eprintln!("TRACE tx_type value={t} set1={set1}");
294298 }
295- tx_type = TxType::from_symbol(t).ok_or_else(|| {
296- unsupported(format!("a tx_type symbol outside its CDF's own set: {t}"))
297- })?;
299+ tx_type = if set1 {
300+ TxType::from_symbol_set1(t)
301+ } else {
302+ TxType::from_symbol(t)
303+ }
304+ .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
298305 }
299306
300307 let eob = read_eob(dec, coding);
@@ -1165,6 +1172,7 @@ fn decode_block(
11651172 scan16: &[u16],
11661173 scan8: &[u16],
11671174 tx_select: bool,
1175+ reduced_tx_set: bool,
11681176 ) -> Result<()> {
11691177 let (r, c) = at;
11701178 let (px, py) = (c * SUB, r * SUB);
@@ -1196,7 +1204,7 @@ fn decode_block(
11961204 (side, luma_tx)
11971205 };
11981206 let luma_set = if tx_select {
1199- txbset_for(logical_tx)
1207+ txbset_for(logical_tx, reduced_tx_set)
12001208 } else {
12011209 luma_set
12021210 };
@@ -1433,6 +1441,7 @@ fn decode_leaf8(
14331441 base_q_idx: u8,
14341442 enable_filter_intra: bool,
14351443 tx_select: bool,
1444+ reduced_tx_set: bool,
14361445 ) -> Result<usize> {
14371446 let (r, c) = outer_at;
14381447 let mut above_mode = neighbours.above_mode[c];
@@ -1504,7 +1513,11 @@ fn decode_leaf8(
15041513 luma_grid = read_plane(
15051514 dec,
15061515 cdfs,
1507- TxbSet::Luma8,
1516+ if reduced_tx_set {
1517+ TxbSet::Luma8
1518+ } else {
1519+ TxbSet::Luma8Set1
1520+ },
15081521 scans.0,
15091522 0,
15101523 around[0],
@@ -1856,13 +1869,19 @@ fn scan_for<'a>(tx_px: usize, scan32: &'a [u16], scan16: &'a [u16], scan8: &'a [
18561869 /// The [`TxbSet`] a resolved luma transform side reads its coefficient tables
18571870 /// from -- 64 is only ever the 64x64-block, depth-0, corner-scanned case
18581871 /// ([`TxbSet::Luma64`]); every other resolved side maps to its own matching
1859-/// set.
1860-fn txbset_for(tx_px: usize) -> TxbSet {
1872+/// set. `get_tx_set` (spec 5.11.48) only splits on `reduced_tx_set` at
1873+/// `TX_8X8`: an intra `TX_16X16` always reads `TX_SET_INTRA_2` regardless of
1874+/// the flag (`av1_get_ext_tx_set_type`'s `tx_size_sqr == TX_16X16` branch
1875+/// ignores `use_reduced_set` once it is past the `TX_32X32`/reduced-set
1876+/// checks), so only the 8x8 case has a second table
1877+/// ([`TxbSet::Luma8Set1`]).
1878+fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
18611879 match tx_px {
18621880 64 => TxbSet::Luma64,
18631881 32 => TxbSet::Luma32,
18641882 16 => TxbSet::Luma16,
1865- 8 => TxbSet::Luma8,
1883+ 8 if reduced_tx_set => TxbSet::Luma8,
1884+ 8 => TxbSet::Luma8Set1,
18661885 _ => unreachable!("read_tx_size never resolves a block's own side to anything else"),
18671886 }
18681887 }
@@ -2408,6 +2427,7 @@ pub fn decode_key_frame_tile(
24082427 cdef: &CdefParams,
24092428 loop_filter: &LoopFilterParams,
24102429 tx_select: bool,
2430+ reduced_tx_set: bool,
24112431 ) -> Result<Picture> {
24122432 decode_key_frame_tile_with_cdfs(
24132433 data,
@@ -2421,6 +2441,7 @@ pub fn decode_key_frame_tile(
24212441 loop_filter,
24222442 None,
24232443 tx_select,
2444+ reduced_tx_set,
24242445 )
24252446 .map(|(picture, _)| picture)
24262447 }
@@ -2445,6 +2466,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
24452466 loop_filter: &LoopFilterParams,
24462467 initial_cdfs: Option<Cdfs>,
24472468 tx_select: bool,
2469+ reduced_tx_set: bool,
24482470 ) -> Result<(Picture, Cdfs)> {
24492471 if mi_cols == 0 || mi_rows == 0 {
24502472 return Err(unsupported("a frame with no mode-info grid"));
@@ -2554,6 +2576,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
25542576 &scan16,
25552577 &scan8,
25562578 tx_select,
2579+ reduced_tx_set,
25572580 )?;
25582581 }
25592582 PARTITION_SPLIT => {
@@ -2615,6 +2638,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
26152638 &scan16,
26162639 &scan8,
26172640 tx_select,
2641+ reduced_tx_set,
26182642 )?;
26192643 }
26202644 PARTITION_SPLIT => {
@@ -2662,6 +2686,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
26622686 &scan16,
26632687 &scan8,
26642688 tx_select,
2689+ reduced_tx_set,
26652690 )?;
26662691 continue;
26672692 }
@@ -2706,6 +2731,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
27062731 base_q_idx,
27072732 enable_filter_intra,
27082733 tx_select,
2734+ reduced_tx_set,
27092735 )?;
27102736 prev_leaf = Some((leaf_mi, leaf_mode));
27112737 }
@@ -2769,6 +2795,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
27692795 base_q_idx,
27702796 enable_filter_intra,
27712797 tx_select,
2798+ reduced_tx_set,
27722799 )?;
27732800 prev_leaf = Some((leaf_mi, leaf_mode));
27742801 }
@@ -4168,7 +4195,8 @@ mod tests {
41684195 false,
41694196 &CdefParams::default(),
41704197 &LoopFilterParams::default(),
4171- false
4198+ false,
4199+ true,
41724200 )
41734201 .is_err()
41744202 );
@@ -4210,6 +4238,7 @@ mod tests {
42104238 &CdefParams::default(),
42114239 &LoopFilterParams::default(),
42124240 false,
4241+ true,
42134242 )
42144243 .unwrap();
42154244 assert_eq!(decoded.width, w, "{w}x{h}: decoded width");
@@ -4292,6 +4321,7 @@ mod tests {
42924321 &CdefParams::default(),
42934322 &LoopFilterParams::default(),
42944323 false,
4324+ true,
42954325 )
42964326 .unwrap();
42974327 assert!(
@@ -4476,6 +4506,7 @@ mod tests {
44764506 &CdefParams::default(),
44774507 &LoopFilterParams::default(),
44784508 false,
4509+ true,
44794510 )
44804511 .unwrap();
44814512 assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg");
@@ -4547,6 +4578,7 @@ mod tests {
45474578 &CdefParams::default(),
45484579 &LoopFilterParams::default(),
45494580 false,
4581+ true,
45504582 )
45514583 .unwrap();
45524584 assert_eq!(
@@ -4821,6 +4853,7 @@ mod tests {
48214853 &CdefParams::default(),
48224854 &LoopFilterParams::default(),
48234855 false,
4856+ true,
48244857 )
48254858 .unwrap();
48264859 assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg");
crates/ec-av1/src/stream.rsmodified+21 -2
@@ -215,6 +215,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
215215 &header.loop_filter,
216216 initial_cdfs,
217217 header.tx_mode == TxMode::Select,
218+ header.reduced_tx_set,
218219 )?
219220 } else {
220221 let last_slot = header.ref_frame_idx[0] as usize;
@@ -341,6 +342,8 @@ mod tests {
341342 &ec_av1_syntax::CdefParams::default(),
342343 &ec_av1_syntax::LoopFilterParams::default(),
343344 false,
345+ // Our own encoder always writes `reduced_tx_set: true`.
346+ true,
344347 )
345348 .unwrap();
346349 let via_stream = decode_stream(&encoded.stream).unwrap();
@@ -1036,9 +1039,13 @@ mod tests {
10361039 // search to prefer a split transform over the block's own full
10371040 // size -- `mandelbrot`'s fractal boundary gives every attempt
10381041 // (a different `start_scale`) sharp, varied-frequency edges.
1042+ // start_scale 5.0 is the proven first try (decodes pixel-exact
1043+ // AND reads the seven-symbol set-1 tx_type rows on TX8 TUs);
1044+ // later attempts walk down for variety when aomenc's RD flips
1045+ // elsewhere.
10391046 let source = format!(
10401047 "mandelbrot=size=64x64:start_scale={}:rate=25",
1041- 3.0 - f64::from(attempt) * 0.06
1048+ 5.0 - f64::from(attempt) * 0.06
10421049 );
10431050 let y4m = Command::new("ffmpeg")
10441051 .args([
@@ -1084,6 +1091,13 @@ mod tests {
10841091 "--enable-ab-partitions=0",
10851092 "--enable-1to4-partitions=0",
10861093 "--enable-filter-intra=0",
1094+ // Every non-DC intra tool off: directional chroma and
1095+ // angle deltas are separate round-2 gaps, and DC-only
1096+ // residual is exactly what gives the RD search a reason
1097+ // to split a transform.
1098+ "--enable-smooth-intra=0",
1099+ "--enable-paeth-intra=0",
1100+ "--enable-directional-intra=0",
10871101 "--enable-angle-delta=0",
10881102 "--enable-cdef=0",
10891103 // Loop restoration is a named refusal (aomenc's RD picks
@@ -1091,9 +1105,14 @@ mod tests {
10911105 // whose test targets a different surface.
10921106 "--enable-restoration=0",
10931107 "--max-partition-size=32",
1108+ // 16x16 blocks are what split into the TX8 TUs whose
1109+ // set-1 tx_type rows this gate exists to prove; some
1110+ // scales resolve depth 2 (TX4, a named refusal) and the
1111+ // attempt loop just moves on.
1112+ "--min-partition-size=16",
10941113 "--enable-palette=0",
10951114 "--enable-intrabc=0",
1096- "--enable-cfl-intra=1",
1115+ "--enable-cfl-intra=0",
10971116 "--obu",
10981117 "-o",
10991118 "-",
crates/ec-av1/src/transform.rsmodified+27 -0
@@ -314,6 +314,12 @@ pub enum TxType {
314314 AdstDct,
315315 /// DCT down the column axis, ADST across the row axis.
316316 DctAdst,
317+ /// DCT down the column axis, identity across the row axis
318+ /// (`V_DCT` -- `TX_SET_INTRA_1` only).
319+ VDct,
320+ /// Identity down the column axis, DCT across the row axis
321+ /// (`H_DCT` -- `TX_SET_INTRA_1` only).
322+ HDct,
317323 }
318324
319325 impl TxType {
@@ -329,6 +335,24 @@ impl TxType {
329335 }
330336 }
331337
338+ /// The inverse of `Tx_Type_Intra_Inv_Set1`'s CDF symbol order
339+ /// (`av1_ext_tx_inv[EXT_TX_SET_DTT4_IDTX_1DDCT]`, entropymode.h:
340+ /// `{9, 0, 10, 11, 3, 1, 2}` = IDTX, DCT_DCT, V_DCT, H_DCT, ADST_ADST,
341+ /// ADST_DCT, DCT_ADST) -- the seven-type set a `reduced_tx_set == 0`
342+ /// frame's small intra transforms read from.
343+ pub fn from_symbol_set1(t: usize) -> Option<Self> {
344+ match t {
345+ 0 => Some(Self::Idtx),
346+ 1 => Some(Self::DctDct),
347+ 2 => Some(Self::VDct),
348+ 3 => Some(Self::HDct),
349+ 4 => Some(Self::AdstAdst),
350+ 5 => Some(Self::AdstDct),
351+ 6 => Some(Self::DctAdst),
352+ _ => None,
353+ }
354+ }
355+
332356 /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass
333357 /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`,
334358 /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/
@@ -343,6 +367,9 @@ impl TxType {
343367 Self::AdstAdst => (Adst, Adst),
344368 Self::AdstDct => (Dct, Adst),
345369 Self::DctAdst => (Adst, Dct),
370+ // `av1_inv_txfm2d.c`: V_DCT vtx=DCT htx=IDTX, H_DCT the mirror.
371+ Self::VDct => (Identity, Dct),
372+ Self::HDct => (Dct, Identity),
346373 }
347374 }
348375 }