wip(av1): EC_RNG per-symbol trace localizes true-size desync to one edge quadrant
Browse files at this commit24b23cea1929d9f639d2f047e97c12b91dc992e1Parent: ec3ad481 changed file +82 -0
- crates/ec-av1/src/tile.rs +82 -0
crates/ec-av1/src/tile.rsmodified+82 -0
| @@ -18,6 +18,30 @@ use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; | |||
| 18 | use crate::msac::SymbolEncoder; | 18 | use crate::msac::SymbolEncoder; |
| 19 | use crate::mvstack::{MiGrid, MiInfo, find_mv_stack, single_ref_ctx}; | 19 | use crate::mvstack::{MiGrid, MiInfo, find_mv_stack, single_ref_ctx}; |
| 20 | 20 | ||
| 21 | +/// round-4 av1-truesize debugging aid: prints `msg()` to stderr when the | ||
| 22 | +/// `EC_RNG` environment variable is set, mirroring the `EC_PART`/`EC_TOK` | ||
| 23 | +/// trace `/tmp/libaom-src`'s debug `aomdec` build already emits under the | ||
| 24 | +/// same variable, so the two traces line up symbol for symbol. Checked once | ||
| 25 | +/// per process, so unset (the default) costs one atomic load per call and no | ||
| 26 | +/// allocation. Only the real tile writer below calls this -- the mode/rate | ||
| 27 | +/// search's own trial encoders never do -- so the trace does not need the | ||
| 28 | +/// throwaway-encoder gating a whole-encoder trace would. | ||
| 29 | +fn ec_rng_trace(msg: impl FnOnce() -> String) { | ||
| 30 | + use std::sync::atomic::{AtomicU8, Ordering}; | ||
| 31 | + static ON: AtomicU8 = AtomicU8::new(2); // 2 = unknown, 1 = on, 0 = off | ||
| 32 | + let on = match ON.load(Ordering::Relaxed) { | ||
| 33 | + 2 => { | ||
| 34 | + let on = u8::from(std::env::var_os("EC_RNG").is_some()); | ||
| 35 | + ON.store(on, Ordering::Relaxed); | ||
| 36 | + on | ||
| 37 | + } | ||
| 38 | + v => v, | ||
| 39 | + }; | ||
| 40 | + if on == 1 { | ||
| 41 | + eprintln!("{}", msg()); | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 21 | /// `PARTITION_NONE` (spec 6.10.4): the whole block, undivided. | 45 | /// `PARTITION_NONE` (spec 6.10.4): the whole block, undivided. |
| 22 | const PARTITION_NONE: usize = 0; | 46 | const PARTITION_NONE: usize = 0; |
| 23 | /// `PARTITION_SPLIT` (spec 6.10.4): the block cut into four quadrants. | 47 | /// `PARTITION_SPLIT` (spec 6.10.4): the block cut into four quadrants. |
| @@ -755,6 +779,15 @@ pub fn sb_coeff_key_frame_tile( | |||
| 755 | for sb_c in 0..sb_cols { | 779 | for sb_c in 0..sb_cols { |
| 756 | let at = (sb_r as usize * 4, sb_c as usize * 4); | 780 | let at = (sb_r as usize * 4, sb_c as usize * 4); |
| 757 | let ctx = neighbours.partition_ctx(at, SB); | 781 | let ctx = neighbours.partition_ctx(at, SB); |
| 782 | + ec_rng_trace(|| { | ||
| 783 | + format!( | ||
| 784 | + "EC_PART mi_row={} mi_col={} bsize=12 ctx={} tell={}", | ||
| 785 | + at.0 * 4, | ||
| 786 | + at.1 * 4, | ||
| 787 | + ctx, | ||
| 788 | + enc.tell() | ||
| 789 | + ) | ||
| 790 | + }); | ||
| 758 | // A superblock whose bottom or right half is outside the frame | 791 | // A superblock whose bottom or right half is outside the frame |
| 759 | // cannot be left unsplit, so the decoder reads a flag instead of | 792 | // cannot be left unsplit, so the decoder reads a flag instead of |
| 760 | // the partition symbol — and reads nothing at all when both halves | 793 | // the partition symbol — and reads nothing at all when both halves |
| @@ -799,6 +832,14 @@ pub fn sb_coeff_key_frame_tile( | |||
| 799 | // luma, so its chroma mode reads the table without it. | 832 | // luma, so its chroma mode reads the table without it. |
| 800 | false, | 833 | false, |
| 801 | ); | 834 | ); |
| 835 | + ec_rng_trace(|| { | ||
| 836 | + format!( | ||
| 837 | + "EC_TOK mi_row={} mi_col={} tell={}", | ||
| 838 | + at.0 * 4, | ||
| 839 | + at.1 * 4, | ||
| 840 | + enc.tell() | ||
| 841 | + ) | ||
| 842 | + }); | ||
| 802 | } | 843 | } |
| 803 | Superblock::Split(quadrants) => { | 844 | Superblock::Split(quadrants) => { |
| 804 | match (has_cols, has_rows) { | 845 | match (has_cols, has_rows) { |
| @@ -833,6 +874,15 @@ pub fn sb_coeff_key_frame_tile( | |||
| 833 | has_half(c as u32 * BLOCK_MI, BLOCK_MI, mi_cols), | 874 | has_half(c as u32 * BLOCK_MI, BLOCK_MI, mi_cols), |
| 834 | has_half(r as u32 * BLOCK_MI, BLOCK_MI, mi_rows), | 875 | has_half(r as u32 * BLOCK_MI, BLOCK_MI, mi_rows), |
| 835 | ); | 876 | ); |
| 877 | + ec_rng_trace(|| { | ||
| 878 | + format!( | ||
| 879 | + "EC_PART mi_row={} mi_col={} bsize=9 ctx={} tell={}", | ||
| 880 | + at.0 * 4, | ||
| 881 | + at.1 * 4, | ||
| 882 | + ctx, | ||
| 883 | + enc.tell() | ||
| 884 | + ) | ||
| 885 | + }); | ||
| 836 | match quadrant { | 886 | match quadrant { |
| 837 | Quadrant::Whole(block) => { | 887 | Quadrant::Whole(block) => { |
| 838 | if !has_cols32 || !has_rows32 { | 888 | if !has_cols32 || !has_rows32 { |
| @@ -860,6 +910,14 @@ pub fn sb_coeff_key_frame_tile( | |||
| 860 | [&scans[0], &scans[1], &scans[1]], | 910 | [&scans[0], &scans[1], &scans[1]], |
| 861 | true, | 911 | true, |
| 862 | ); | 912 | ); |
| 913 | + ec_rng_trace(|| { | ||
| 914 | + format!( | ||
| 915 | + "EC_TOK mi_row={} mi_col={} tell={}", | ||
| 916 | + at.0 * 4, | ||
| 917 | + at.1 * 4, | ||
| 918 | + enc.tell() | ||
| 919 | + ) | ||
| 920 | + }); | ||
| 863 | } | 921 | } |
| 864 | Quadrant::Split(blocks) => { | 922 | Quadrant::Split(blocks) => { |
| 865 | // The 16x16 sub-blocks this quadrant's split | 923 | // The 16x16 sub-blocks this quadrant's split |
| @@ -929,6 +987,15 @@ pub fn sb_coeff_key_frame_tile( | |||
| 929 | } | 987 | } |
| 930 | let at = (sr, sc); | 988 | let at = (sr, sc); |
| 931 | let ctx = neighbours.partition_ctx(at, SUB); | 989 | let ctx = neighbours.partition_ctx(at, SUB); |
| 990 | + ec_rng_trace(|| { | ||
| 991 | + format!( | ||
| 992 | + "EC_PART mi_row={} mi_col={} bsize=6 ctx={} tell={}", | ||
| 993 | + at.0 * 4, | ||
| 994 | + at.1 * 4, | ||
| 995 | + ctx, | ||
| 996 | + enc.tell() | ||
| 997 | + ) | ||
| 998 | + }); | ||
| 932 | enc.symbol(PARTITION_NONE, &mut cdfs.partition_w16[ctx]); | 999 | enc.symbol(PARTITION_NONE, &mut cdfs.partition_w16[ctx]); |
| 933 | let grids = [ | 1000 | let grids = [ |
| 934 | level_grid(&block.luma, TX16)?, | 1001 | level_grid(&block.luma, TX16)?, |
| @@ -947,6 +1014,14 @@ pub fn sb_coeff_key_frame_tile( | |||
| 947 | [&scans[1], &scans[2], &scans[2]], | 1014 | [&scans[1], &scans[2], &scans[2]], |
| 948 | true, | 1015 | true, |
| 949 | ); | 1016 | ); |
| 1017 | + ec_rng_trace(|| { | ||
| 1018 | + format!( | ||
| 1019 | + "EC_TOK mi_row={} mi_col={} tell={}", | ||
| 1020 | + at.0 * 4, | ||
| 1021 | + at.1 * 4, | ||
| 1022 | + enc.tell() | ||
| 1023 | + ) | ||
| 1024 | + }); | ||
| 950 | } | 1025 | } |
| 951 | } | 1026 | } |
| 952 | } | 1027 | } |
| @@ -1056,6 +1131,13 @@ fn write_block_planes( | |||
| 1056 | skip_ctx, | 1131 | skip_ctx, |
| 1057 | dc_sign_ctx(around[plane].dc_vote), | 1132 | dc_sign_ctx(around[plane].dc_vote), |
| 1058 | ); | 1133 | ); |
| 1134 | + ec_rng_trace(|| { | ||
| 1135 | + format!( | ||
| 1136 | + "EC_PLANE plane={plane} nz={} skip_ctx={skip_ctx} tell={}", | ||
| 1137 | + grid.iter().filter(|&&l| l != 0).count(), | ||
| 1138 | + enc.tell() | ||
| 1139 | + ) | ||
| 1140 | + }); | ||
| 1059 | } | 1141 | } |
| 1060 | } | 1142 | } |
| 1061 | 1143 | ||