The frame-edge partition bit was read and thrown away
Browse files at this commit135feff81373444996e13f88665c1c55c0ffd3b7Parent: 31ae209- fix
- the frame-edge partition bit was read and thrown away
1 changed file +151 -72
- crates/ec-av1/src/decode.rs +151 -72
crates/ec-av1/src/decode.rsmodified+151 -72
| @@ -1861,6 +1861,33 @@ thread_local! { | |||
| 1861 | } | 1861 | } |
| 1862 | 1862 | ||
| 1863 | /// Current value of [`SB_RECT_HITS`]. | 1863 | /// Current value of [`SB_RECT_HITS`]. |
| 1864 | +// lane-hgkf r1: the frame-edge partition bit, one level each. Slot 0 = a | ||
| 1865 | +// 64-level gathered edge bit read as HORZ/VERT, 1 = the same bit read as | ||
| 1866 | +// SPLIT, 2/3 = the 32-level pair. A gate asserting slot 0 or 2 proves the | ||
| 1867 | +// non-SPLIT edge arm actually decoded (before this round the bit was read and | ||
| 1868 | +// thrown away, so that arm was unreachable). | ||
| 1869 | +thread_local! { | ||
| 1870 | + static EDGE_PART_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; | ||
| 1871 | +} | ||
| 1872 | + | ||
| 1873 | +/// Current value of [`EDGE_PART_HITS`]. | ||
| 1874 | +pub(crate) fn edge_part_hits() -> [usize; 4] { | ||
| 1875 | + EDGE_PART_HITS.with(|c| c.get()) | ||
| 1876 | +} | ||
| 1877 | + | ||
| 1878 | +/// Reset [`EDGE_PART_HITS`] (a gate counts one stream at a time). | ||
| 1879 | +pub(crate) fn reset_edge_part_hits() { | ||
| 1880 | + EDGE_PART_HITS.with(|c| c.set([0; 4])); | ||
| 1881 | +} | ||
| 1882 | + | ||
| 1883 | +fn bump_edge_part(slot: usize) { | ||
| 1884 | + EDGE_PART_HITS.with(|c| { | ||
| 1885 | + let mut h = c.get(); | ||
| 1886 | + h[slot] += 1; | ||
| 1887 | + c.set(h); | ||
| 1888 | + }); | ||
| 1889 | +} | ||
| 1890 | + | ||
| 1864 | pub(crate) fn sb_rect_hits() -> usize { | 1891 | pub(crate) fn sb_rect_hits() -> usize { |
| 1865 | SB_RECT_HITS.with(|c| c.get()) | 1892 | SB_RECT_HITS.with(|c| c.get()) |
| 1866 | } | 1893 | } |
| @@ -5421,6 +5448,16 @@ fn decode_rect_split( | |||
| 5421 | let tu_mi = (mi_r + tu_row * (tx_h / MI), mi_c + tu_col * (tx_w / MI)); | 5448 | let tu_mi = (mi_r + tu_row * (tx_h / MI), mi_c + tu_col * (tx_w / MI)); |
| 5422 | let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); | 5449 | let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h); |
| 5423 | let (col_off, row_off) = (tu_col * tx_w, tu_row * tx_h); | 5450 | let (col_off, row_off) = (tu_col * tx_w, tu_row * tx_h); |
| 5451 | + // lane-hgkf r1 (ported from lane-golomb 791d87a, unmerged): | ||
| 5452 | + // libaom clips `av1_foreach_transformed_block_in_plane` to | ||
| 5453 | + // `max_blocks_wide/high` (`mb_to_right_edge`/`mb_to_bottom_edge`, | ||
| 5454 | + // i.e. `mi_cols * 4` / `mi_rows * 4`): a transform unit whose | ||
| 5455 | + // TOP-LEFT sample falls outside the frame is never coded. We read | ||
| 5456 | + // coefficients for those phantom units and desynced the stream at | ||
| 5457 | + // the very next symbol. | ||
| 5458 | + if tu_px >= y.true_width || tu_py >= y.true_height { | ||
| 5459 | + continue; | ||
| 5460 | + } | ||
| 5424 | // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a | 5461 | // `has_top_right`/`has_bottom_left` (libaom `reconintra.c`) for a |
| 5425 | // transform unit INSIDE a block, which is a different rule from | 5462 | // transform unit INSIDE a block, which is a different rule from |
| 5426 | // the standalone-block table [`Reach::of`] applies -- and the | 5463 | // the standalone-block table [`Reach::of`] applies -- and the |
| @@ -8417,6 +8454,12 @@ fn decode_block( | |||
| 8417 | ); | 8454 | ); |
| 8418 | let tu_px = px + tu_col * logical_tx; | 8455 | let tu_px = px + tu_col * logical_tx; |
| 8419 | let tu_py = py + tu_row * logical_tx; | 8456 | let tu_py = py + tu_row * logical_tx; |
| 8457 | + // Same libaom clip as `decode_rect_split`'s loop above; a | ||
| 8458 | + // square block only hangs off the frame when the frame's mi | ||
| 8459 | + // dimensions are odd at the block's own level. | ||
| 8460 | + if tu_px >= y.true_width || tu_py >= y.true_height { | ||
| 8461 | + continue; | ||
| 8462 | + } | ||
| 8420 | let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; | 8463 | let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; |
| 8421 | // A transform unit inside a block is NOT a block at that | 8464 | // A transform unit inside a block is NOT a block at that |
| 8422 | // position (lane-palette2 r12): `Reach::of` granted the | 8465 | // position (lane-palette2 r12): `Reach::of` granted the |
| @@ -11325,16 +11368,26 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11325 | } | 11368 | } |
| 11326 | p | 11369 | p |
| 11327 | } else { | 11370 | } else { |
| 11371 | + // lane-hgkf r1 (class `parsed-then-discarded`, same finding as | ||
| 11372 | + // the unmerged lane-golomb r1): the gathered bit IS the | ||
| 11373 | + // partition -- libaom `ec_read_partition_impl` returns | ||
| 11374 | + // PARTITION_HORZ (resp. VERT) for 0 and only SPLIT for 1. | ||
| 11375 | + // Forcing SPLIT desynced the last superblock row of every | ||
| 11376 | + // frame whose height is not a multiple of 64: the ReelB key frames (3840x1608) diverge at mi_row=400 mi_col=0, | ||
| 11377 | + // the first block of that row. | ||
| 11328 | match (has_cols, has_rows) { | 11378 | match (has_cols, has_rows) { |
| 11329 | (true, false) => { | 11379 | (true, false) => { |
| 11330 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); | 11380 | + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); |
| 11381 | + bump_edge_part(b.min(1) as usize); | ||
| 11382 | + if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } | ||
| 11331 | } | 11383 | } |
| 11332 | (false, true) => { | 11384 | (false, true) => { |
| 11333 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); | 11385 | + let b = dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); |
| 11386 | + bump_edge_part(b.min(1) as usize); | ||
| 11387 | + if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } | ||
| 11334 | } | 11388 | } |
| 11335 | - _ => {} | 11389 | + _ => PARTITION_SPLIT, |
| 11336 | } | 11390 | } |
| 11337 | - PARTITION_SPLIT | ||
| 11338 | }; | 11391 | }; |
| 11339 | match part { | 11392 | match part { |
| 11340 | PARTITION_NONE => { | 11393 | PARTITION_NONE => { |
| @@ -11389,22 +11442,28 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11389 | } | 11442 | } |
| 11390 | p | 11443 | p |
| 11391 | } else { | 11444 | } else { |
| 11445 | + // lane-hgkf r1: the 32-level frame-edge bit is the | ||
| 11446 | + // partition too (same libaom reader as the | ||
| 11447 | + // superblock level above). | ||
| 11392 | match (has_cols32, has_rows32) { | 11448 | match (has_cols32, has_rows32) { |
| 11393 | (true, false) => { | 11449 | (true, false) => { |
| 11394 | - dec.symbol_fixed(&gather( | 11450 | + let b = dec.symbol_fixed(&gather( |
| 11395 | &cdfs.partition_w32[ctx32], | 11451 | &cdfs.partition_w32[ctx32], |
| 11396 | VERT_ALIKE, | 11452 | VERT_ALIKE, |
| 11397 | )); | 11453 | )); |
| 11454 | + bump_edge_part(2 + b.min(1) as usize); | ||
| 11455 | + if b == 1 { PARTITION_SPLIT } else { PARTITION_HORZ } | ||
| 11398 | } | 11456 | } |
| 11399 | (false, true) => { | 11457 | (false, true) => { |
| 11400 | - dec.symbol_fixed(&gather( | 11458 | + let b = dec.symbol_fixed(&gather( |
| 11401 | &cdfs.partition_w32[ctx32], | 11459 | &cdfs.partition_w32[ctx32], |
| 11402 | HORZ_ALIKE, | 11460 | HORZ_ALIKE, |
| 11403 | )); | 11461 | )); |
| 11462 | + bump_edge_part(2 + b.min(1) as usize); | ||
| 11463 | + if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } | ||
| 11404 | } | 11464 | } |
| 11405 | - _ => {} | 11465 | + _ => PARTITION_SPLIT, |
| 11406 | } | 11466 | } |
| 11407 | - PARTITION_SPLIT | ||
| 11408 | }; | 11467 | }; |
| 11409 | match part32 { | 11468 | match part32 { |
| 11410 | PARTITION_NONE => { | 11469 | PARTITION_NONE => { |
| @@ -11981,22 +12040,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11981 | tx_select, | 12040 | tx_select, |
| 11982 | reduced_tx_set, | 12041 | reduced_tx_set, |
| 11983 | )?; | 12042 | )?; |
| 11984 | - decode_block_rect( | 12043 | + // lane-hgkf r1: at the frame edge only the first half of the strip is |
| 11985 | - &mut dec, | 12044 | + // coded (libaom `decode_partition` guards the second half with the same |
| 11986 | - &mut cdfs, | 12045 | + // test that made this partition non-square). |
| 11987 | - &mut neighbours, | 12046 | + if has_rows32 { |
| 11988 | - (at32.0 + 1, at32.1), | 12047 | + decode_block_rect( |
| 11989 | - 32, | 12048 | + &mut dec, |
| 11990 | - 16, | 12049 | + &mut cdfs, |
| 11991 | - &mut y, | 12050 | + &mut neighbours, |
| 11992 | - &mut u, | 12051 | + (at32.0 + 1, at32.1), |
| 11993 | - &mut v, | 12052 | + 32, |
| 11994 | - enable_filter_intra, | 12053 | + 16, |
| 11995 | - allow_screen_content_tools, | 12054 | + &mut y, |
| 11996 | - base_q_idx, | 12055 | + &mut u, |
| 11997 | - tx_select, | 12056 | + &mut v, |
| 11998 | - reduced_tx_set, | 12057 | + enable_filter_intra, |
| 11999 | - )?; | 12058 | + allow_screen_content_tools, |
| 12059 | + base_q_idx, | ||
| 12060 | + tx_select, | ||
| 12061 | + reduced_tx_set, | ||
| 12062 | + )?; | ||
| 12063 | + } | ||
| 12000 | } | 12064 | } |
| 12001 | PARTITION_VERT => { | 12065 | PARTITION_VERT => { |
| 12002 | // lane-intradisp r1: mirror of PARTITION_HORZ | 12066 | // lane-intradisp r1: mirror of PARTITION_HORZ |
| @@ -12017,22 +12081,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12017 | tx_select, | 12081 | tx_select, |
| 12018 | reduced_tx_set, | 12082 | reduced_tx_set, |
| 12019 | )?; | 12083 | )?; |
| 12020 | - decode_block_rect( | 12084 | + // lane-hgkf r1: at the frame edge only the first half of the strip is |
| 12021 | - &mut dec, | 12085 | + // coded (libaom `decode_partition` guards the second half with the same |
| 12022 | - &mut cdfs, | 12086 | + // test that made this partition non-square). |
| 12023 | - &mut neighbours, | 12087 | + if has_cols32 { |
| 12024 | - (at32.0, at32.1 + 1), | 12088 | + decode_block_rect( |
| 12025 | - 16, | 12089 | + &mut dec, |
| 12026 | - 32, | 12090 | + &mut cdfs, |
| 12027 | - &mut y, | 12091 | + &mut neighbours, |
| 12028 | - &mut u, | 12092 | + (at32.0, at32.1 + 1), |
| 12029 | - &mut v, | 12093 | + 16, |
| 12030 | - enable_filter_intra, | 12094 | + 32, |
| 12031 | - allow_screen_content_tools, | 12095 | + &mut y, |
| 12032 | - base_q_idx, | 12096 | + &mut u, |
| 12033 | - tx_select, | 12097 | + &mut v, |
| 12034 | - reduced_tx_set, | 12098 | + enable_filter_intra, |
| 12035 | - )?; | 12099 | + allow_screen_content_tools, |
| 12100 | + base_q_idx, | ||
| 12101 | + tx_select, | ||
| 12102 | + reduced_tx_set, | ||
| 12103 | + )?; | ||
| 12104 | + } | ||
| 12036 | } | 12105 | } |
| 12037 | PARTITION_HORZ_A => { | 12106 | PARTITION_HORZ_A => { |
| 12038 | // lane-part32 r1: two 16x16 squares on top + | 12107 | // lane-part32 r1: two 16x16 squares on top + |
| @@ -12402,22 +12471,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12402 | tx_select, | 12471 | tx_select, |
| 12403 | reduced_tx_set, | 12472 | reduced_tx_set, |
| 12404 | )?; | 12473 | )?; |
| 12405 | - decode_block_rect64( | 12474 | + // lane-hgkf r1: at the frame edge only the first half of the strip is |
| 12406 | - &mut dec, | 12475 | + // coded (libaom `decode_partition` guards the second half with the same |
| 12407 | - &mut cdfs, | 12476 | + // test that made this partition non-square). |
| 12408 | - &mut neighbours, | 12477 | + if has_rows { |
| 12409 | - (at.0 + 2, at.1), | 12478 | + decode_block_rect64( |
| 12410 | - 64, | 12479 | + &mut dec, |
| 12411 | - 32, | 12480 | + &mut cdfs, |
| 12412 | - &mut y, | 12481 | + &mut neighbours, |
| 12413 | - &mut u, | 12482 | + (at.0 + 2, at.1), |
| 12414 | - &mut v, | 12483 | + 64, |
| 12415 | - enable_filter_intra, | 12484 | + 32, |
| 12416 | - allow_screen_content_tools, | 12485 | + &mut y, |
| 12417 | - base_q_idx, | 12486 | + &mut u, |
| 12418 | - tx_select, | 12487 | + &mut v, |
| 12419 | - reduced_tx_set, | 12488 | + enable_filter_intra, |
| 12420 | - )?; | 12489 | + allow_screen_content_tools, |
| 12490 | + base_q_idx, | ||
| 12491 | + tx_select, | ||
| 12492 | + reduced_tx_set, | ||
| 12493 | + )?; | ||
| 12494 | + } | ||
| 12421 | } | 12495 | } |
| 12422 | PARTITION_VERT => { | 12496 | PARTITION_VERT => { |
| 12423 | // lane-sbpart r2: mirror of PARTITION_HORZ above with | 12497 | // lane-sbpart r2: mirror of PARTITION_HORZ above with |
| @@ -12438,22 +12512,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12438 | tx_select, | 12512 | tx_select, |
| 12439 | reduced_tx_set, | 12513 | reduced_tx_set, |
| 12440 | )?; | 12514 | )?; |
| 12441 | - decode_block_rect64( | 12515 | + // lane-hgkf r1: at the frame edge only the first half of the strip is |
| 12442 | - &mut dec, | 12516 | + // coded (libaom `decode_partition` guards the second half with the same |
| 12443 | - &mut cdfs, | 12517 | + // test that made this partition non-square). |
| 12444 | - &mut neighbours, | 12518 | + if has_cols { |
| 12445 | - (at.0, at.1 + 2), | 12519 | + decode_block_rect64( |
| 12446 | - 32, | 12520 | + &mut dec, |
| 12447 | - 64, | 12521 | + &mut cdfs, |
| 12448 | - &mut y, | 12522 | + &mut neighbours, |
| 12449 | - &mut u, | 12523 | + (at.0, at.1 + 2), |
| 12450 | - &mut v, | 12524 | + 32, |
| 12451 | - enable_filter_intra, | 12525 | + 64, |
| 12452 | - allow_screen_content_tools, | 12526 | + &mut y, |
| 12453 | - base_q_idx, | 12527 | + &mut u, |
| 12454 | - tx_select, | 12528 | + &mut v, |
| 12455 | - reduced_tx_set, | 12529 | + enable_filter_intra, |
| 12456 | - )?; | 12530 | + allow_screen_content_tools, |
| 12531 | + base_q_idx, | ||
| 12532 | + tx_select, | ||
| 12533 | + reduced_tx_set, | ||
| 12534 | + )?; | ||
| 12535 | + } | ||
| 12457 | } | 12536 | } |
| 12458 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { | 12537 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { |
| 12459 | // lane-part32 r4: the four superblock-level AB arms, each | 12538 | // lane-part32 r4: the four superblock-level AB arms, each |