Merge lane/unwritten-dep: two of the three unwritten-content rows were dump artefacts
Browse files at this commit3 changed files +908 -17
- crates/ec-av1/src/decode.rs +203 -17
- crates/ec-av1/src/stream.rs +260 -0
- lanes/unwritten-dep.report.md +445 -0
crates/ec-av1/src/decode.rsmodified+203 -17
| @@ -21117,8 +21117,25 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { | |||
| 21117 | /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written | 21117 | /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written |
| 21118 | /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`. | 21118 | /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`. |
| 21119 | /// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of | 21119 | /// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of |
| 21120 | -/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) -- | 21120 | +/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects). |
| 21121 | -/// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). | 21121 | +/// lane-unwritten-dep: this doc previously said the dump "matches aomdec's own |
| 21122 | +/// `ec_dump16` rung byte for byte (crop dims, u16 LE)", which was true only of | ||
| 21123 | +/// the 4:2:0 crop it then used. The crop is now PER-AXIS, which is what the | ||
| 21124 | +/// oracle's rung 1 actually does -- it writes `y_crop_width` x `y_crop_height`, | ||
| 21125 | +/// `uv_crop_width` x `uv_crop_height`, `uv_crop_width` x `uv_crop_height` (the | ||
| 21126 | +/// libaom `YV12_BUFFER_CONFIG` fields, each already per-axis). Byte shape per | ||
| 21127 | +/// subsampling, `fw x fh` luma then both chroma planes, u16 LE, so: | ||
| 21128 | +/// | ||
| 21129 | +/// ```text | ||
| 21130 | +/// ss_x ss_y format luma chroma (each) | ||
| 21131 | +/// 0 0 4:4:4 fw x fh fw x fh fw*fh*3 samples | ||
| 21132 | +/// 1 1 4:2:0 fw x fh fw/2 x fh/2 fw*fh*3/2 samples | ||
| 21133 | +/// 1 0 4:2:2 fw x fh fw/2 x fh fw*fh*2 samples | ||
| 21134 | +/// 0 1 4:4:0 fw x fh fw x fh/2 fw*fh*3/2 samples | ||
| 21135 | +/// ``` | ||
| 21136 | +/// | ||
| 21137 | +/// (`round_ss` is the rounding the decoder's own plane extents use; at ss = 1 it | ||
| 21138 | +/// is `div_ceil(2)`, so every 4:2:0 dump is byte-for-byte unchanged by this.) | ||
| 21122 | /// lane-mc64 r1: the decode-order index the stage dumps below key their file | 21139 | /// lane-mc64 r1: the decode-order index the stage dumps below key their file |
| 21123 | /// name on. `PREFILT_PICTURE_IDX` is bumped once per frame just BEFORE the | 21140 | /// name on. `PREFILT_PICTURE_IDX` is bumped once per frame just BEFORE the |
| 21124 | /// deblock/CDEF stages run, so the frame being dumped here is `idx - 1` -- | 21141 | /// deblock/CDEF stages run, so the frame being dumped here is `idx - 1` -- |
| @@ -21138,19 +21155,38 @@ fn dump_stage16( | |||
| 21138 | v: &PlaneBuf<'_>, | 21155 | v: &PlaneBuf<'_>, |
| 21139 | fw: usize, | 21156 | fw: usize, |
| 21140 | fh: usize, | 21157 | fh: usize, |
| 21158 | + ss_x: usize, | ||
| 21159 | + ss_y: usize, | ||
| 21141 | ) { | 21160 | ) { |
| 21142 | use std::io::Write; | 21161 | use std::io::Write; |
| 21143 | // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by | 21162 | // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by |
| 21144 | // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed | 21163 | // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed |
| 21145 | // `.f0` name kept only the LAST frame, so a mid-sequence divergence could | 21164 | // `.f0` name kept only the LAST frame, so a mid-sequence divergence could |
| 21146 | - // not be read out at all. | 21165 | + // not be read at all. |
| 21166 | + // | ||
| 21167 | + // lane-unwritten-dep: the chroma extent is PER-AXIS subsampling, not | ||
| 21168 | + // `div_ceil(2)` on both. The hardcoded pair was a 4:2:0 assumption and it | ||
| 21169 | + // was load-bearing: on a 64x64 4:2:2 frame (ss_x = 1, ss_y = 0) it wrote | ||
| 21170 | + // 32x32 chroma per plane where the frame carries 32x64, so HALF of each | ||
| 21171 | + // chroma plane appeared in NO stage dump at all. A stage bisect that reads | ||
| 21172 | + // "identical pre-deblock, differs post-deblock" off these dumps is then | ||
| 21173 | + // measuring the dump's blind spot, not the pipeline's: the samples it could | ||
| 21174 | + // not see are exactly the region where the 4:2:2 witness's output diverges | ||
| 21175 | + // (chroma rows 32..63 -- the old `fh.div_ceil(2)` crop wrote 32 of 64 rows, | ||
| 21176 | + // so everything from row 32 up was invisible; 2048 samples). `round_ss` is | ||
| 21177 | + // the same rounding the | ||
| 21178 | + // decoder's own plane extents use, and it matches the oracle's | ||
| 21179 | + // `uv_crop_width` / `uv_crop_height` per axis. | ||
| 21180 | + // ONE file per frame: `dump_stage_idx` advances on every call, so creating | ||
| 21181 | + // the file inside the plane loop would write three files per frame and | ||
| 21182 | + // shift every later frame's index. | ||
| 21147 | if let Ok(path) = crate::envflags::var(var) | 21183 | if let Ok(path) = crate::envflags::var(var) |
| 21148 | && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) | 21184 | && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) |
| 21149 | { | 21185 | { |
| 21150 | for (p, w, h) in [ | 21186 | for (p, w, h) in [ |
| 21151 | (y, fw, fh), | 21187 | (y, fw, fh), |
| 21152 | - (u, fw.div_ceil(2), fh.div_ceil(2)), | 21188 | + (u, round_ss(fw, ss_x), round_ss(fh, ss_y)), |
| 21153 | - (v, fw.div_ceil(2), fh.div_ceil(2)), | 21189 | + (v, round_ss(fw, ss_x), round_ss(fh, ss_y)), |
| 21154 | ] { | 21190 | ] { |
| 21155 | for row in 0..h { | 21191 | for row in 0..h { |
| 21156 | let mut bytes = Vec::with_capacity(w * 2); | 21192 | let mut bytes = Vec::with_capacity(w * 2); |
| @@ -21618,25 +21654,163 @@ fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::Fra | |||
| 21618 | /// the output does not depend on the plane buffer's initial content. | 21654 | /// the output does not depend on the plane buffer's initial content. |
| 21619 | const PLANE_SENTINEL: u16 = 0xDEAD; | 21655 | const PLANE_SENTINEL: u16 = 0xDEAD; |
| 21620 | 21656 | ||
| 21657 | +/// lane-unwritten-dep: the census count at the LAST point of the pipeline, on the | ||
| 21658 | +/// exact bytes `EC_AV1_FINAL_DUMP` writes. | ||
| 21659 | +/// | ||
| 21660 | +/// WHY A SECOND COUNT, and what it is actually for -- the justification this | ||
| 21661 | +/// comment originally carried was WRONG and is corrected here, because a reader | ||
| 21662 | +/// would otherwise re-derive the wrong conclusion. An earlier revision of this | ||
| 21663 | +/// lane claimed the pre-deblock plane was byte-identical plain-vs-sentinel and | ||
| 21664 | +/// that "deblock creates the dependence". That reading came from | ||
| 21665 | +/// [`dump_stage16`], which cropped chroma as `(fw/2, fh/2)` -- a 4:2:0 | ||
| 21666 | +/// assumption. On a 64x64 4:2:2 frame (ss_x=1, ss_y=0) that wrote 32x32 chroma | ||
| 21667 | +/// where the frame carries 32x64, so 2048 chroma samples appeared in NO stage | ||
| 21668 | +/// dump, and they are exactly the region where the difference lives. | ||
| 21669 | +/// | ||
| 21670 | +/// With per-axis extents the corrected measurement on `440_request_is_422` is: | ||
| 21671 | +/// the PRE-DEBLOCK dump already DIFFERS by 2158 bytes plain-vs-sentinel, and an | ||
| 21672 | +/// exact u16 whole-plane census finds 224 unwritten samples (U 112, V 112, | ||
| 21673 | +/// rows 36..63, whole 4x4 groups) -- the same number | ||
| 21674 | +/// `lanes/av1unwritten.report.md` reports. **The hole is present before any | ||
| 21675 | +/// filter runs, and the pre-deblock census sees it.** This comment previously | ||
| 21676 | +/// said the opposite; that was the instrument's blind spot read as a property of | ||
| 21677 | +/// the pipeline. | ||
| 21678 | +/// | ||
| 21679 | +/// So what this second count is FOR, stated honestly: it is not there because the | ||
| 21680 | +/// pre-deblock census misses holes. It is there because it is the measurement | ||
| 21681 | +/// taken where the OUTPUT is taken -- the bytes stored into the reference slots | ||
| 21682 | +/// and handed to the caller. A hole can be created after reconstruction (a | ||
| 21683 | +/// filter stage, a superres step, a second pass) and be invisible to a scan taken | ||
| 21684 | +/// before it; this one cannot. It is a check on the whole span from the tile walk | ||
| 21685 | +/// to the caller's frame, not a claim that the pre-deblock scan is insufficient. | ||
| 21686 | +static FINAL_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = | ||
| 21687 | + std::sync::atomic::AtomicUsize::new(0); | ||
| 21688 | + | ||
| 21689 | +/// Samples [`census_unwritten_final`] has looked at since the last | ||
| 21690 | +/// [`take_final_census_scanned`]. A gate that only asserts | ||
| 21691 | +/// [`take_final_unwritten_samples`] == 0 passes on a build whose census call was | ||
| 21692 | +/// deleted, so it reads THIS too -- the same pairing | ||
| 21693 | +/// [`CENSUS_SCANNED`] documents for the pre-deblock census. | ||
| 21694 | +static FINAL_CENSUS_SCANNED: std::sync::atomic::AtomicUsize = | ||
| 21695 | + std::sync::atomic::AtomicUsize::new(0); | ||
| 21696 | + | ||
| 21697 | +/// lane-unwritten-dep: reads and clears [`FINAL_UNWRITTEN_SAMPLES`] -- unwritten | ||
| 21698 | +/// samples still present in the frame as handed to the caller, summed over every | ||
| 21699 | +/// frame and plane. Process-global, like the pre-deblock census's counter, so a | ||
| 21700 | +/// gate can read it after the decode from a different thread than the one that | ||
| 21701 | +/// scanned. | ||
| 21702 | +pub fn take_final_unwritten_samples() -> usize { | ||
| 21703 | + FINAL_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21704 | +} | ||
| 21705 | + | ||
| 21706 | +/// Reads and clears [`FINAL_CENSUS_SCANNED`]; the pairing is the reason it | ||
| 21707 | +/// exists, exactly as for [`take_census_scanned`]. | ||
| 21708 | +pub fn take_final_census_scanned() -> usize { | ||
| 21709 | + FINAL_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21710 | +} | ||
| 21711 | + | ||
| 21712 | +/// lane-unwritten-dep: the census at the pipeline's last point. Counts, over each | ||
| 21713 | +/// plane, how many samples still hold [`PLANE_SENTINEL`] once every filter has | ||
| 21714 | +/// run, and records how many samples it LOOKED at in [`FINAL_CENSUS_SCANNED`]. | ||
| 21715 | +/// | ||
| 21716 | +/// Gated on [`plane_sentinel_on`] -- the SAME predicate as [`fresh_plane`] and as | ||
| 21717 | +/// the pre-deblock [`census_unwritten`]: the env flag OR the thread-local | ||
| 21718 | +/// [`set_plane_sentinel`] override. An earlier revision gated this on the raw env | ||
| 21719 | +/// var alone, which made the census silently inert for any in-process test using | ||
| 21720 | +/// the thread-local switch that the rest of the crate honours. The fill and both | ||
| 21721 | +/// censuses must agree on when they are live, or a "0" means nothing. | ||
| 21722 | +pub(crate) fn census_unwritten_final(y: &[u16], u: &[u16], v: &[u16]) { | ||
| 21723 | + if !plane_sentinel_on() { | ||
| 21724 | + return; | ||
| 21725 | + } | ||
| 21726 | + // The caller passes the frame's planes exactly as they are about to be | ||
| 21727 | + // stored into the reference slots, which are already cropped to the true | ||
| 21728 | + // extent (no padding past it reaches this point), so a flat count over | ||
| 21729 | + // each plane IS the true-extent count. | ||
| 21730 | + let (scanned, total): (usize, usize) = [y, u, v] | ||
| 21731 | + .iter() | ||
| 21732 | + .map(|p| (p.len(), p.iter().filter(|&&s| s == PLANE_SENTINEL).count())) | ||
| 21733 | + .fold((0, 0), |(a, b), (c, d)| (a + c, b + d)); | ||
| 21734 | + FINAL_CENSUS_SCANNED.fetch_add(scanned, std::sync::atomic::Ordering::SeqCst); | ||
| 21735 | + FINAL_UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst); | ||
| 21736 | +} | ||
| 21737 | + | ||
| 21621 | /// A frame plane's own backing store, `n` samples, UNINITIALISED. | 21738 | /// A frame plane's own backing store, `n` samples, UNINITIALISED. |
| 21622 | /// | 21739 | /// |
| 21623 | -/// (lane-picalloc) The SB-padded coding surface is written sample-for-sample | 21740 | +/// (lane-picalloc) Replaced a `vec![0u16; n]` that zeroed the whole plane |
| 21624 | -/// by the tile walk's reconstruction before anything reads it, so the | 21741 | +/// buffer: ~3% of the frame thread's cycles at 4K, serially at the frame's head, |
| 21625 | -/// `vec![0u16; n]` this replaces spent ~3% of the frame thread's cycles | 21742 | +/// to initialise 25 MB the next pass overwrites. |
| 21626 | -/// zeroing 25 MB (at 4K) that the very next pass overwrites -- serially, at | 21743 | +/// |
| 21627 | -/// the frame's head, on the critical path. `EC_AV1_PLANE_SENTINEL=1` swaps the | 21744 | +/// # THE `unsafe` BELOW IS NOT FULLY JUSTIFIED -- read this before approving it |
| 21628 | -/// uninitialised buffer for a [`PLANE_SENTINEL`] fill; the gate hashes both | 21745 | +/// |
| 21629 | -/// ways (see the lane report) and the two agree, which is the proof that no | 21746 | +/// This comment previously claimed the SB-padded surface "is written |
| 21630 | -/// unwritten sample reaches the output. | 21747 | +/// sample-for-sample by the tile walk's reconstruction before anything reads |
| 21748 | +/// it", and cited the sentinel gate as proof. **That claim is RETRACTED by | ||
| 21749 | +/// measurement.** The basis for the retraction is THIS LANE's own, not | ||
| 21750 | +/// second-hand: on `440_request_is_422` an exact u16 whole-plane census at the | ||
| 21751 | +/// pre-deblock point finds **112 unwritten samples per chroma plane, 224 total** | ||
| 21752 | +/// (U and V, 28 whole 4x4 groups each, rows 36..63) in a frame that is SHOWN | ||
| 21753 | +/// (`Key show=true`) and whose samples the caller receives. Uninitialised memory | ||
| 21754 | +/// that reaches the caller was read, or the read that produced it was. That is | ||
| 21755 | +/// the UB, and it needs no hash-variation claim to stand. | ||
| 21756 | +/// | ||
| 21757 | +/// A hash-variation observation also exists -- five plain runs of the same | ||
| 21758 | +/// witness giving two different output hashes (`lanes/av1unwritten.report.md`), | ||
| 21759 | +/// which would point the same way -- but it is SECOND-HAND and was NOT | ||
| 21760 | +/// reproduced here: five plain runs on `8d6998d7` gave one hash | ||
| 21761 | +/// (`a761118c8dd5c8d0`, `lanes/unwritten-dep.report.md` §10). It is not relied | ||
| 21762 | +/// on, and the ambient content a run happens to receive is machine-dependent, | ||
| 21763 | +/// so a stable value on one host and a varying one on another would be the same | ||
| 21764 | +/// defect either way. The 224-sample census is the basis; the hashes are aside. | ||
| 21765 | +/// | ||
| 21766 | +/// WHAT IS ACTUALLY ESTABLISHED, and it is weaker: | ||
| 21767 | +/// | ||
| 21768 | +/// * The sentinel gate ([`census_unwritten_final`], | ||
| 21769 | +/// `the_frame_the_caller_receives_carries_no_unwritten_plane_sample`) proves | ||
| 21770 | +/// that no sample the tile walk never wrote SURVIVES into the frame the caller | ||
| 21771 | +/// receives, on the corpus measured. **It counts at the OUTPUT POINT ONLY -- | ||
| 21772 | +/// one census, one scan.** The pre-deblock census ([`census_unwritten`], | ||
| 21773 | +/// `take_unwritten_samples` / `take_census_scanned`) is a DIFFERENT instrument | ||
| 21774 | +/// and has NO committed reader anywhere in the crate on `main`, so it backs | ||
| 21775 | +/// nothing here; an earlier revision of this comment credited the gate with | ||
| 21776 | +/// both, which would have told a reviewer the premise is covered by two scans | ||
| 21777 | +/// when only one exists. It is measured SURVIVAL, not reads. | ||
| 21778 | +/// * It does NOT prove "every sample is written before it is read". A sample read | ||
| 21779 | +/// as a prediction or filter neighbour and overwritten a moment later is | ||
| 21780 | +/// invisible to that count. **No such read has been observed, and no | ||
| 21781 | +/// instrument here measures for one.** | ||
| 21782 | +/// * On `main` = `e45cc748` the one path where a read was demonstrated is | ||
| 21783 | +/// UNREACHABLE: lane/av1unwritten refuses the subsize before descending. | ||
| 21784 | +/// | ||
| 21785 | +/// Honest status: a read-before-write is DEMONSTRATED on a path that is now | ||
| 21786 | +/// refused, UNMEASURED on every other path, and this `unsafe` is sound only under | ||
| 21787 | +/// the unproven "written before read" premise. Filed as an open UB-class item | ||
| 21788 | +/// (`lanes/unwritten-dep.report.md` §12) with two closures: (a) zero the | ||
| 21789 | +/// allocation -- the safe default, at the ~3% this removed; or (b) an instrument | ||
| 21790 | +/// counting reads-before-write per sample, so the premise can be proved rather | ||
| 21791 | +/// than assumed. | ||
| 21631 | fn fresh_plane(n: usize) -> Vec<u16> { | 21792 | fn fresh_plane(n: usize) -> Vec<u16> { |
| 21632 | if plane_sentinel_on() { | 21793 | if plane_sentinel_on() { |
| 21633 | return vec![PLANE_SENTINEL; n]; | 21794 | return vec![PLANE_SENTINEL; n]; |
| 21634 | } | 21795 | } |
| 21635 | let mut v: Vec<u16> = Vec::with_capacity(n); | 21796 | let mut v: Vec<u16> = Vec::with_capacity(n); |
| 21636 | - // SAFETY: `u16` has no invalid bit patterns and no `Drop`, and the | 21797 | + // SAFETY, PARTIAL -- the premise is NOT established; see the block comment |
| 21637 | - // capacity was just reserved, so the vector owns `n` initialised-or-not | 21798 | + // above ("THE `unsafe` BELOW IS NOT FULLY JUSTIFIED"). |
| 21638 | - // `u16` slots. Every one is written by reconstruction before it is read | 21799 | + // |
| 21639 | - // (proven by the sentinel gate above). | 21800 | + // What IS sound: `u16` has no invalid bit patterns and no `Drop`, and the |
| 21801 | + // capacity was just reserved, so the vector owns `n` slots that are valid to | ||
| 21802 | + // OWN. Creating a `Vec` over uninitialised memory is not itself UB. | ||
| 21803 | + // | ||
| 21804 | + // What is NOT sound, and is the reason this is a filed item rather than a | ||
| 21805 | + // settled one: reading an uninitialised `u16` IS UB, and the only thing that | ||
| 21806 | + // makes the reads sound is the premise that reconstruction writes every | ||
| 21807 | + // sample before any read. That premise was RETRACTED by measurement (224 | ||
| 21808 | + // unwritten samples, output varying with initial content) on a path that is | ||
| 21809 | + // now refused, and is UNMEASURED everywhere else. The sentinel gate measures | ||
| 21810 | + // survival at the output point, not reads. The pre-deblock census is a | ||
| 21811 | + // separate instrument with no committed reader on main, so it adds nothing | ||
| 21812 | + // here. So this `unsafe` is sound under a premise no current instrument | ||
| 21813 | + // proves. | ||
| 21640 | #[allow(unsafe_code)] | 21814 | #[allow(unsafe_code)] |
| 21641 | unsafe { | 21815 | unsafe { |
| 21642 | v.set_len(n); | 21816 | v.set_len(n); |
| @@ -37958,6 +38132,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37958 | &v, | 38132 | &v, |
| 37959 | frame_width as usize, | 38133 | frame_width as usize, |
| 37960 | frame_height as usize, | 38134 | frame_height as usize, |
| 38135 | + ss_x(fctx), | ||
| 38136 | + ss_y(fctx), | ||
| 37961 | ); | 38137 | ); |
| 37962 | census_unwritten(&y, &u, &v); | 38138 | census_unwritten(&y, &u, &v); |
| 37963 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 38139 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| @@ -38041,6 +38217,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 38041 | &v, | 38217 | &v, |
| 38042 | frame_width as usize, | 38218 | frame_width as usize, |
| 38043 | frame_height as usize, | 38219 | frame_height as usize, |
| 38220 | + ss_x(fctx), | ||
| 38221 | + ss_y(fctx), | ||
| 38044 | ); | 38222 | ); |
| 38045 | apply_cdef( | 38223 | apply_cdef( |
| 38046 | &mut y, | 38224 | &mut y, |
| @@ -38061,6 +38239,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 38061 | &v, | 38239 | &v, |
| 38062 | frame_width as usize, | 38240 | frame_width as usize, |
| 38063 | frame_height as usize, | 38241 | frame_height as usize, |
| 38242 | + ss_x(fctx), | ||
| 38243 | + ss_y(fctx), | ||
| 38064 | ); | 38244 | ); |
| 38065 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); | 38245 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); |
| 38066 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called | 38246 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called |
| @@ -56320,6 +56500,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 56320 | &v, | 56500 | &v, |
| 56321 | frame_width as usize, | 56501 | frame_width as usize, |
| 56322 | frame_height as usize, | 56502 | frame_height as usize, |
| 56503 | + ss_x(fctx), | ||
| 56504 | + ss_y(fctx), | ||
| 56323 | ); | 56505 | ); |
| 56324 | census_unwritten(&y, &u, &v); | 56506 | census_unwritten(&y, &u, &v); |
| 56325 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 56507 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| @@ -56423,6 +56605,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 56423 | &v, | 56605 | &v, |
| 56424 | frame_width as usize, | 56606 | frame_width as usize, |
| 56425 | frame_height as usize, | 56607 | frame_height as usize, |
| 56608 | + ss_x(fctx), | ||
| 56609 | + ss_y(fctx), | ||
| 56426 | ); | 56610 | ); |
| 56427 | if !pipelined { | 56611 | if !pipelined { |
| 56428 | apply_cdef( | 56612 | apply_cdef( |
| @@ -56445,6 +56629,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 56445 | &v, | 56629 | &v, |
| 56446 | frame_width as usize, | 56630 | frame_width as usize, |
| 56447 | frame_height as usize, | 56631 | frame_height as usize, |
| 56632 | + ss_x(fctx), | ||
| 56633 | + ss_y(fctx), | ||
| 56448 | ); | 56634 | ); |
| 56449 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); | 56635 | capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); |
| 56450 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called | 56636 | // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called |
crates/ec-av1/src/stream.rsmodified+260 -0
| @@ -2220,6 +2220,30 @@ fn decode_frame( | |||
| 2220 | // aomdec's own `EC_AV1_FINAL_DUMP` rung byte for byte | 2220 | // aomdec's own `EC_AV1_FINAL_DUMP` rung byte for byte |
| 2221 | // (scripts/instrument-aom-oracle.sh rung 12), which is what makes a | 2221 | // (scripts/instrument-aom-oracle.sh rung 12), which is what makes a |
| 2222 | // hidden frame's pixels comparable at all. | 2222 | // hidden frame's pixels comparable at all. |
| 2223 | + // lane-unwritten-dep: the census AT the output point, beside the dump that | ||
| 2224 | + // defines "the output" -- the same bytes, so the claim is about the frame the | ||
| 2225 | + // caller receives rather than about an intermediate stage. | ||
| 2226 | + // | ||
| 2227 | + // WHAT THIS IS FOR, corrected: an earlier revision of this comment said the | ||
| 2228 | + // pre-deblock plane was byte-identical plain-vs-sentinel and that deblock | ||
| 2229 | + // creates the dependence. That was wrong, and it was `dump_stage16`'s fault: | ||
| 2230 | + // it cropped chroma as `(fw/2, fh/2)`, a 4:2:0 assumption, so on a 64x64 | ||
| 2231 | + // 4:2:2 frame 2048 chroma samples appeared in no stage dump at all -- exactly | ||
| 2232 | + // the region the difference lives in. With per-axis extents the corrected | ||
| 2233 | + // measurement on `440_request_is_422` is that the PRE-DEBLOCK dump already | ||
| 2234 | + // differs by 2158 bytes and an exact u16 census finds 224 unwritten samples | ||
| 2235 | + // (U 112, V 112, rows 36..63) -- the same count `lanes/av1unwritten.report.md` | ||
| 2236 | + // reports. The hole is present before any filter runs, and the pre-deblock | ||
| 2237 | + // census SEES it. | ||
| 2238 | + // | ||
| 2239 | + // So this second census is not a patch for a blind pre-deblock scan. It is | ||
| 2240 | + // the measurement taken where the output is taken, which covers the whole span | ||
| 2241 | + // from the tile walk to the caller's frame: anything a later stage could | ||
| 2242 | + // introduce (a filter, superres, a second pass) is inside its extent, where | ||
| 2243 | + // a scan taken before it would not be. It also runs before `apply_grain`, so | ||
| 2244 | + // the claim is over the PRE-GRAIN planes -- the bytes the reference bank | ||
| 2245 | + // stores and every later frame predicts from. | ||
| 2246 | + decode::census_unwritten_final(&picture.y, &picture.u, &picture.v); | ||
| 2223 | if let Some(prefix) = final_dump { | 2247 | if let Some(prefix) = final_dump { |
| 2224 | use std::io::Write; | 2248 | use std::io::Write; |
| 2225 | if let Ok(mut f) = std::fs::File::create(format!("{prefix}.f{decode_idx}")) { | 2249 | if let Ok(mut f) = std::fs::File::create(format!("{prefix}.f{decode_idx}")) { |
| @@ -48206,6 +48230,242 @@ exit 0 | |||
| 48206 | ); | 48230 | ); |
| 48207 | } | 48231 | } |
| 48208 | 48232 | ||
| 48233 | + /// lane-unwritten-dep: the UNWRITTEN-SAMPLE census at the point the output is | ||
| 48234 | + /// taken, over the real film fixtures that carry hidden alt-refs. | ||
| 48235 | + /// | ||
| 48236 | + /// SCOPE, stated rather than implied: the census is taken where | ||
| 48237 | + /// `EC_AV1_FINAL_DUMP` writes, which is BEFORE `apply_grain`. The claim is | ||
| 48238 | + /// therefore over the PRE-GRAIN planes -- which are also the bytes the | ||
| 48239 | + /// reference bank stores and every later frame predicts from, the dependency | ||
| 48240 | + /// that matters. Whether `apply_grain` can itself introduce a hole is NOT | ||
| 48241 | + /// measured: the census never sees the planes `apply_grain` allocates. So the | ||
| 48242 | + /// claim is NOT "the caller's final grained picture has no hole", and nothing | ||
| 48243 | + /// here asserts that grain cannot introduce one. | ||
| 48244 | + /// | ||
| 48245 | + /// NON-VACUITY, the part that makes this gate worth having: a census is only a | ||
| 48246 | + /// measurement if it CAN report non-zero. The control is a SYNTHETIC positive | ||
| 48247 | + /// -- the census is handed planes with a known number of sentinel samples and | ||
| 48248 | + /// must report exactly that number. It deliberately does NOT use a fixture: | ||
| 48249 | + /// the corpus's one witness with a real hole (`440_request_is_422`) is REFUSED | ||
| 48250 | + /// by lane/av1unwritten, so a fixture-carried control goes red on merge for a | ||
| 48251 | + /// reason unrelated to this gate. A synthetic control cannot be refused and | ||
| 48252 | + /// cannot change behaviour when a lane lands. It is proven by mutation in the | ||
| 48253 | + /// same run: neutering `census_unwritten_final` reds it (lane report §5). | ||
| 48254 | + /// | ||
| 48255 | + /// WHAT THIS IS NOT, corrected from an earlier revision of this comment: it | ||
| 48256 | + /// does NOT rest on a claim that the pre-deblock census is blind. That claim | ||
| 48257 | + /// was wrong. It came from `dump_stage16` cropping chroma as `(fw/2, fh/2)` -- | ||
| 48258 | + /// a 4:2:0 assumption -- so on a 64x64 4:2:2 frame 2048 chroma samples were in | ||
| 48259 | + /// no stage dump at all, and an earlier revision read that blind spot as | ||
| 48260 | + /// "identical pre-deblock, so deblock creates the dependence". With per-axis | ||
| 48261 | + /// extents the corrected measurement is the opposite: the pre-deblock dump on | ||
| 48262 | + /// `440_request_is_422` already DIFFERS by 2158 bytes and the exact u16 census | ||
| 48263 | + /// finds 224 unwritten samples (U 112, V 112, rows 36..63, whole 4x4 groups) -- | ||
| 48264 | + /// the same count `lanes/av1unwritten.report.md` reports. The hole is present | ||
| 48265 | + /// before any filter runs and the pre-deblock census SEES it. This census is | ||
| 48266 | + /// here because it is the measurement taken where the OUTPUT is taken, which | ||
| 48267 | + /// spans the whole route from the tile walk to the caller. | ||
| 48268 | + /// | ||
| 48269 | + /// The four film fixtures are the corpus's real 10-bit streams with hidden | ||
| 48270 | + /// alt-refs -- the shapes where a hidden frame's unwritten region would feed | ||
| 48271 | + /// a later DISPLAYED frame through the reference bank, which is the only way | ||
| 48272 | + /// an unwritten sample could reach output on a stream that decodes correctly. | ||
| 48273 | + /// All four measure 0 here AND 0 on the pre-deblock census. | ||
| 48274 | + /// | ||
| 48275 | + /// Measured on `8d6998d7` with a provenance-verified probe (`strings` on the | ||
| 48276 | + /// binary names only this worktree; reelb_arf sha256 `7f3b060da5aa9c53`, | ||
| 48277 | + /// reelb_rect64 `c9e721088766163b`): | ||
| 48278 | + /// | ||
| 48279 | + /// ```text | ||
| 48280 | + /// pre-deblock census (u16, whole plane, 0xDEAD counted per frame) | ||
| 48281 | + /// 440_request_is_422 224 <- also lane/av1unwritten's own number | ||
| 48282 | + /// reelb_arf_witness 0 | ||
| 48283 | + /// reelb_rect64_intra16x4_witness 0 | ||
| 48284 | + /// this gate (pre-grain, at the output point) | ||
| 48285 | + /// reelb_arf_witness 0 | ||
| 48286 | + /// reelb_rect64_intra16x4_witness 0 | ||
| 48287 | + /// gm_small_side_witness 0 | ||
| 48288 | + /// reelc_sb128_inter_witness 0 | ||
| 48289 | + /// ``` | ||
| 48290 | + #[test] | ||
| 48291 | + fn the_frame_the_caller_receives_carries_no_unwritten_plane_sample() { | ||
| 48292 | + const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample"; | ||
| 48293 | + let _gate_lock = lock_gate_counters(); | ||
| 48294 | + | ||
| 48295 | + // The census needs the sentinel FILL, which is env-gated (see | ||
| 48296 | + // `fresh_plane`), and this crate forbids `set_var` (see `envflags`), so | ||
| 48297 | + // the fill cannot be switched from inside a test process. The child | ||
| 48298 | + // process below is therefore how the measurement is taken; what the | ||
| 48299 | + // parent asserts is the CHILD's reported count. | ||
| 48300 | + let census = |fixture: &str| -> (usize, usize) { | ||
| 48301 | + let exe = std::env::current_exe().expect("test binary path"); | ||
| 48302 | + let out = std::process::Command::new(exe) | ||
| 48303 | + .args([ | ||
| 48304 | + "--exact", | ||
| 48305 | + "stream::tests::uwdep_child_unwritten_census", | ||
| 48306 | + "--nocapture", | ||
| 48307 | + ]) | ||
| 48308 | + .env("UWDEP_CENSUS_FIXTURE", fixture) | ||
| 48309 | + .env("EC_AV1_PLANE_SENTINEL", "1") | ||
| 48310 | + .output() | ||
| 48311 | + .expect("running the census child"); | ||
| 48312 | + // `--nocapture` puts the child's `println!` on its stderr, so both | ||
| 48313 | + // streams are searched. | ||
| 48314 | + let text = format!( | ||
| 48315 | + "{}{}", | ||
| 48316 | + String::from_utf8_lossy(&out.stdout), | ||
| 48317 | + String::from_utf8_lossy(&out.stderr), | ||
| 48318 | + ); | ||
| 48319 | + text.lines() | ||
| 48320 | + .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) | ||
| 48321 | + .and_then(parse_census_line) | ||
| 48322 | + .unwrap_or_else(|| { | ||
| 48323 | + panic!( | ||
| 48324 | + "{NAME}: the census child reported no count for {fixture} \ | ||
| 48325 | + (child said: {:?})", | ||
| 48326 | + text.trim() | ||
| 48327 | + ) | ||
| 48328 | + }) | ||
| 48329 | + }; | ||
| 48330 | + | ||
| 48331 | + // Non-vacuity FIRST, and SYNTHETIC on purpose (see the doc comment): the | ||
| 48332 | + // census is handed planes with a known number of sentinel samples and must | ||
| 48333 | + // report exactly that number. No fixture is involved, so this cannot be | ||
| 48334 | + // affected by lane/av1unwritten refusing `440_request_is_422` on merge. | ||
| 48335 | + // The fill is env-gated, so even this runs in the child. | ||
| 48336 | + let (synthetic, synthetic_scanned) = census_synthetic(); | ||
| 48337 | + assert_eq!( | ||
| 48338 | + synthetic_scanned, 40, | ||
| 48339 | + "{NAME}: the synthetic control scanned {synthetic_scanned} samples, expected 40 \ | ||
| 48340 | + (16 + 16 + 8) -- the census did not look at what it was handed" | ||
| 48341 | + ); | ||
| 48342 | + assert_eq!( | ||
| 48343 | + synthetic, 7, | ||
| 48344 | + "{NAME}: the census reported {synthetic} for planes carrying exactly 7 sentinel \ | ||
| 48345 | + samples -- the census is not measuring what it claims, so every zero below is \ | ||
| 48346 | + meaningless (class: census-silently-blind)" | ||
| 48347 | + ); | ||
| 48348 | + | ||
| 48349 | + for fixture in [ | ||
| 48350 | + "reelb_arf_witness", | ||
| 48351 | + "reelb_rect64_intra16x4_witness", | ||
| 48352 | + "gm_small_side_witness", | ||
| 48353 | + "reelc_sb128_inter_witness", | ||
| 48354 | + ] { | ||
| 48355 | + let (n, scanned) = census(fixture); | ||
| 48356 | + assert!( | ||
| 48357 | + scanned > 0, | ||
| 48358 | + "{NAME}: the census scanned 0 samples on {fixture} -- the call at the output \ | ||
| 48359 | + point is not running, so the {n} below proves nothing (class: \ | ||
| 48360 | + census-never-ran). Deleting the call site reproduces this." | ||
| 48361 | + ); | ||
| 48362 | + assert_eq!( | ||
| 48363 | + n, 0, | ||
| 48364 | + "{NAME}: {fixture} hands the caller {n} samples the tile walk never wrote" | ||
| 48365 | + ); | ||
| 48366 | + } | ||
| 48367 | + } | ||
| 48368 | + | ||
| 48369 | + /// Parses the child's `UWDEP_CENSUS <unwritten> frames=<n> scanned=<n>` line | ||
| 48370 | + /// into `(unwritten, scanned)`. The scanned count is what makes the fixture | ||
| 48371 | + /// arms meaningful: `unwritten == 0` is also what a build with the census call | ||
| 48372 | + /// deleted reports, and only a non-zero scanned count distinguishes "scanned | ||
| 48373 | + /// and found nothing" from "never scanned". | ||
| 48374 | + fn parse_census_line(v: &str) -> Option<(usize, usize)> { | ||
| 48375 | + let mut parts = v.split_whitespace(); | ||
| 48376 | + let unwritten = parts.next()?.parse().ok()?; | ||
| 48377 | + let scanned = parts | ||
| 48378 | + .find_map(|p| p.strip_prefix("scanned="))? | ||
| 48379 | + .parse() | ||
| 48380 | + .ok()?; | ||
| 48381 | + Some((unwritten, scanned)) | ||
| 48382 | + } | ||
| 48383 | + | ||
| 48384 | + /// Runs the census child with `UWDEP_CENSUS_FIXTURE` UNSET, which makes it | ||
| 48385 | + /// take the synthetic-positive path: hand [`census_unwritten_final`] planes | ||
| 48386 | + /// with a known number of `PLANE_SENTINEL` values and report what it counted. | ||
| 48387 | + /// This is the non-vacuity control, and it is a direct function-level check | ||
| 48388 | + /// rather than a decode, so no fixture's decode behaviour can change it. | ||
| 48389 | + fn census_synthetic() -> (usize, usize) { | ||
| 48390 | + const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample"; | ||
| 48391 | + let exe = std::env::current_exe().expect("test binary path"); | ||
| 48392 | + let out = std::process::Command::new(exe) | ||
| 48393 | + .args([ | ||
| 48394 | + "--exact", | ||
| 48395 | + "stream::tests::uwdep_child_unwritten_census", | ||
| 48396 | + "--nocapture", | ||
| 48397 | + ]) | ||
| 48398 | + .env("EC_AV1_PLANE_SENTINEL", "1") | ||
| 48399 | + .env("UWDEP_CENSUS_SYNTHETIC", "1") | ||
| 48400 | + .env_remove("UWDEP_CENSUS_FIXTURE") | ||
| 48401 | + .output() | ||
| 48402 | + .expect("running the census child"); | ||
| 48403 | + let text = format!( | ||
| 48404 | + "{}{}", | ||
| 48405 | + String::from_utf8_lossy(&out.stdout), | ||
| 48406 | + String::from_utf8_lossy(&out.stderr), | ||
| 48407 | + ); | ||
| 48408 | + text.lines() | ||
| 48409 | + .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) | ||
| 48410 | + .and_then(parse_census_line) | ||
| 48411 | + .unwrap_or_else(|| { | ||
| 48412 | + panic!( | ||
| 48413 | + "{NAME}: the census child reported no synthetic count (child said: {:?})", | ||
| 48414 | + text.trim() | ||
| 48415 | + ) | ||
| 48416 | + }) | ||
| 48417 | + } | ||
| 48418 | + | ||
| 48419 | + /// The child half of | ||
| 48420 | + /// [`the_frame_the_caller_receives_carries_no_unwritten_plane_sample`]: decodes | ||
| 48421 | + /// the fixture named in `UWDEP_CENSUS_FIXTURE` with the sentinel fill live and | ||
| 48422 | + /// prints `UWDEP_CENSUS <n> frames=<n>` plus a frame-count assertion. | ||
| 48423 | + /// | ||
| 48424 | + /// A `#[test]` rather than an example because it needs the crate's own | ||
| 48425 | + /// in-process counter -- which no external binary could read. | ||
| 48426 | + #[test] | ||
| 48427 | + fn uwdep_child_unwritten_census() { | ||
| 48428 | + assert!( | ||
| 48429 | + std::env::var_os("EC_AV1_PLANE_SENTINEL").is_some(), | ||
| 48430 | + "the census child ran without EC_AV1_PLANE_SENTINEL, so the fill was never live \ | ||
| 48431 | + and the count is meaningless" | ||
| 48432 | + ); | ||
| 48433 | + // The non-vacuity control: no decode, no fixture, just the census over | ||
| 48434 | + // planes with a KNOWN number of sentinel samples. 3 + 4 + 0 = 7. | ||
| 48435 | + if std::env::var_os("UWDEP_CENSUS_SYNTHETIC").is_some() { | ||
| 48436 | + const S: u16 = 0xDEAD; | ||
| 48437 | + let mut a = vec![7u16; 16]; | ||
| 48438 | + let mut b = vec![7u16; 16]; | ||
| 48439 | + let c = vec![7u16; 8]; | ||
| 48440 | + for s in a.iter_mut().take(3) { | ||
| 48441 | + *s = S; | ||
| 48442 | + } | ||
| 48443 | + for s in b.iter_mut().take(4) { | ||
| 48444 | + *s = S; | ||
| 48445 | + } | ||
| 48446 | + let _ = decode::take_final_unwritten_samples(); | ||
| 48447 | + decode::census_unwritten_final(&a, &b, &c); | ||
| 48448 | + let n = decode::take_final_unwritten_samples(); | ||
| 48449 | + let scanned = decode::take_final_census_scanned(); | ||
| 48450 | + println!("UWDEP_CENSUS {n} synthetic=1 scanned={scanned}"); | ||
| 48451 | + return; | ||
| 48452 | + } | ||
| 48453 | + let Ok(fixture) = std::env::var("UWDEP_CENSUS_FIXTURE") else { | ||
| 48454 | + // Not a census run: the parent invokes this test by name, so being | ||
| 48455 | + // reached without the variable means a normal suite run. | ||
| 48456 | + return; | ||
| 48457 | + }; | ||
| 48458 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 48459 | + .join(format!("fixtures/{fixture}.obu")); | ||
| 48460 | + let stream = | ||
| 48461 | + std::fs::read(&path).unwrap_or_else(|e| panic!("reading {}: {e}", path.display())); | ||
| 48462 | + let _ = decode::take_final_unwritten_samples(); | ||
| 48463 | + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{fixture} refused: {e}")); | ||
| 48464 | + let n = decode::take_final_unwritten_samples(); | ||
| 48465 | + let scanned = decode::take_final_census_scanned(); | ||
| 48466 | + println!("UWDEP_CENSUS {n} frames={} scanned={scanned}", frames.len()); | ||
| 48467 | + } | ||
| 48468 | + | ||
| 48209 | /// lane-t900 r6: the 128-superblock INTER witness. | 48469 | /// lane-t900 r6: the 128-superblock INTER witness. |
| 48210 | /// `crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 177773 bytes, | 48470 | /// `crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 177773 bytes, |
| 48211 | /// sha256 `09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc`: | 48471 | /// sha256 `09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc`: |
lanes/unwritten-dep.report.mdadded+445 -0
| @@ -0,0 +1,445 @@ | |||
| 1 | +# lane/unwritten-dep — the reelb_* rows are not decoder defects; the instrument that lied is `dump_stage16` | ||
| 2 | + | ||
| 3 | +**Outcome in one line: neither `reelb_rect64_intra16x4_witness.obu` nor | ||
| 4 | +`reelb_arf_witness.obu` output depends on unwritten plane content; the census was | ||
| 5 | +never blind — `dump_stage16` was, because it hardcoded a 4:2:0 chroma extent and | ||
| 6 | +on a 4:2:2 frame wrote half of each chroma plane into no dump at all, which | ||
| 7 | +fabricated the "identical pre-deblock, differs post-deblock" attribution; with | ||
| 8 | +per-axis extents the 4:2:2 witness shows 224 unwritten samples pre-deblock | ||
| 9 | +(exactly lane/av1unwritten's own number), so the difference is present BEFORE any | ||
| 10 | +filter runs. The gate's non-vacuity control is now synthetic and survives | ||
| 11 | +`main`'s refusal of the only fixture that had one.** | ||
| 12 | + | ||
| 13 | +Branch `lane/unwritten-dep`. Base `8d6998d7`, **rebased by merging | ||
| 14 | +`main` = `e45cc748` locally** (commit `c62eeda9`) — the merge proof the | ||
| 15 | +acceptance asked for is this lane's own tree; no rebase onto a different base, | ||
| 16 | +the merge keeps `8d6998d7` as the branch point. | ||
| 17 | + | ||
| 18 | +> **r3 correction, on top of r2.** r2 named the census as the blind instrument and | ||
| 19 | +> attributed the 4:2:2 witness's divergence to deblock. Both were wrong, and r2's | ||
| 20 | +> own numbers refuted them: its `EC_AV1_DEBUG_SKIP_DEBLOCK` result did not remove | ||
| 21 | +> the difference, and 32 surviving sentinel samples cannot explain 1986 | ||
| 22 | +> differing bytes. The cause is r2's own unexamined instrument. | ||
| 23 | +> `dump_stage16` (`decode.rs`) cropped chroma as `(fw/2, fh/2)` — a 4:2:0 | ||
| 24 | +> assumption — so on a 64×64 **4:2:2** frame (ss_x=1, ss_y=0) it wrote 32×32 | ||
| 25 | +> chroma where the frame carries 32×64. **2048 chroma samples appeared in no | ||
| 26 | +> stage dump at all**, and they are exactly the region where the difference | ||
| 27 | +> lives. r2 read the dump's blind spot as a pipeline property. With per-axis | ||
| 28 | +> extents the pre-deblock dump is where the difference *starts*. | ||
| 29 | + | ||
| 30 | +## 1. Provenance | ||
| 31 | + | ||
| 32 | +Built in this lane's worktree with its own target dir; the binary's embedded | ||
| 33 | +paths name only this worktree. | ||
| 34 | + | ||
| 35 | +``` | ||
| 36 | +$ CARGO_TARGET_DIR=/home/user/.cache/tgt/uwdep-merge cargo build -p ec-av1 --example decode_probe | ||
| 37 | +$ strings .../decode_probe | grep -o 'wt/[a-zA-Z0-9_-]*' | sort -u | ||
| 38 | +wt/unwrittendep | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +Two live traps, both of which produce a *silent* wrong reading: this lane's first | ||
| 42 | +target dir was deleted underneath it mid-run (hence `uwdep-k9` → `uwdep-merge`), | ||
| 43 | +and `/tmp` is a 16 GB tmpfs that filled during the first sweep and produced | ||
| 44 | +short/zero-length dump files. Every retained run asserts the exact expected | ||
| 45 | +frame size; the 10-bit fixtures' frame is 18 524 160 bytes. | ||
| 46 | + | ||
| 47 | +Fixtures: `reelb_arf_witness.obu` 32 126 B sha256 `7f3b060da5aa9c53…`, | ||
| 48 | +`reelb_rect64_intra16x4_witness.obu` 23 472 B sha256 `c9e721088766163b…`. | ||
| 49 | + | ||
| 50 | +## 2. Reproduction | ||
| 51 | + | ||
| 52 | +Hash shape `cat dir/frame.f*` (lexicographic), 3 plain + 2 sentinel runs: | ||
| 53 | + | ||
| 54 | +| fixture | plain | sentinel | campaign plain | campaign sentinel | | ||
| 55 | +|---|---|---|---|---| | ||
| 56 | +| `reelb_rect64_intra16x4_witness` (34 frames) | `a26438168c` ×3 | `a26438168c` ×2 | `a26438168c` | `0ee1edf403` | | ||
| 57 | +| `reelb_arf_witness` (40 frames) | `8d7a43bc5f` ×3 | `8d7a43bc5f` ×2 | `8d7a43bc5f` | `97ef82c0ce` | | ||
| 58 | + | ||
| 59 | +**Both campaign PLAIN values are reproduced exactly by this build; neither | ||
| 60 | +SENTINEL value is.** The decode output is byte-identical plain vs sentinel, and | ||
| 61 | +under every other ambient content available: glibc `MALLOC_PERTURB_` ∈ {0, 1, 85, | ||
| 62 | +170, 254}, `EC_AV1_THREADS` ∈ {1, 2, 4, 8}, and in-process poisoning of the | ||
| 63 | +allocator's free list with 16 MiB dirty-then-freed blocks. | ||
| 64 | + | ||
| 65 | +The in-process test is the strongest of these because there is no filesystem in | ||
| 66 | +the measurement at all, and it has teeth — on the 4:2:2 witness it reports | ||
| 67 | +differences under 4 of 4 poison patterns (667–715 differing U samples, | ||
| 68 | +673–690 differing V, 0 in luma), while reporting **0 differing frames under 4 | ||
| 69 | +of 4 patterns on both hg fixtures**. | ||
| 70 | + | ||
| 71 | +## 3. `97ef82c0ce` — consistent with a truncated dump, not proven to be one | ||
| 72 | + | ||
| 73 | +Sweeping (frames-complete, tail-truncated) shapes against the campaign's value: | ||
| 74 | + | ||
| 75 | +``` | ||
| 76 | +$ python3 /tmp/unwritten/partial.py reelb_arf_witness | ||
| 77 | + MATCH: frames 0..4 + f5 truncated to 13320192 bytes, lex-hashed | ||
| 78 | +``` | ||
| 79 | + | ||
| 80 | +The campaign's value is reproduced **bit-for-bit** by a byte stream that is frames | ||
| 81 | +0–4 complete plus 13 320 192 bytes of frame 5 (71.8% of one frame), frames 6–39 | ||
| 82 | +absent. `EC_AV1_FINAL_DUMP` does `let _ = f.write_all(&buf)`, so a full filesystem | ||
| 83 | +leaves a prefix of the true stream and nothing reports it. | ||
| 84 | + | ||
| 85 | +**This pins the byte content and the shape, not the mechanism.** An unlived | ||
| 86 | +sentinel, a timeout-killed process, and a full filesystem all leave the same | ||
| 87 | +bytes. The wording is therefore *consistent with* a truncated dump, and the | ||
| 88 | +converse — that the decode is innocent — rests on §2's invariance, not on this | ||
| 89 | +match. Corroborating but likewise non-conclusive: `RLIMIT_FSIZE` at a 4 MiB cap | ||
| 90 | +gives `788d3be08ae5112e` for both fills vs `5350cd5569d226eb` uncapped; a reused | ||
| 91 | +dump directory leaves a longer fixture's tail (`9ca5c4d7af`); hashing the | ||
| 92 | +`sha256sum` listing embeds the directory path. | ||
| 93 | + | ||
| 94 | +`0ee1edf403` is **not** reproduced by any shape swept (every numeric prefix; | ||
| 95 | +every prefix + page-truncated tail at 4 KiB and 512 B; prefixes from either | ||
| 96 | +fixture, since rect64 is a 34-frame prefix of arf's 40 with byte-identical frames | ||
| 97 | +0–33; hole shapes; zero-length-frame shapes; stale cross-fixture mixes both | ||
| 98 | +orders; the listing shape). It remains an **open instrument-hygiene question**, | ||
| 99 | +not a decode question — the decode is invariant (§2). | ||
| 100 | + | ||
| 101 | +## 4. The instrument defect, and the corrected measurement | ||
| 102 | + | ||
| 103 | +**Class: `diagnostic-dump-assumes-one-subsampling`** — a debug/instrumental dump | ||
| 104 | +that derives a plane's extent from an assumed subsampling rather than the | ||
| 105 | +sequence's, so part of the plane is absent from the measurement and conclusions | ||
| 106 | +drawn from that measurement are about the dump. Same per-axis family as the | ||
| 107 | +decoder's own `round_ss(dim, ss)` rule. | ||
| 108 | + | ||
| 109 | +`decode.rs`, `dump_stage16`, cropped chroma as `(fw.div_ceil(2), fh.div_ceil(2))` | ||
| 110 | +— the 4:2:0 assumption on both axes. The oracle's rung 1 uses libaom's | ||
| 111 | +`uv_crop_width` / `uv_crop_height`, which are per-axis. Fixed to | ||
| 112 | +`(round_ss(fw, ss_x), round_ss(fh, ss_y))`, with all six call sites passing | ||
| 113 | +`ss_x(fctx)` / `ss_y(fctx)`. | ||
| 114 | + | ||
| 115 | +**Corrected stage bisect on `440_request_is_422`** (8-bit, 64×64, 4:2:2 header | ||
| 116 | +over a 4:2:0 tile; `main` = `e45cc748` refuses it, so this is measured on the | ||
| 117 | +branch point `8d6998d7`): | ||
| 118 | + | ||
| 119 | +| stage dump | before the fix | after the fix | | ||
| 120 | +|---|---|---| | ||
| 121 | +| `EC_AV1_PREFILT_DUMP16` (pre-deblock) | 12 288 B, **IDENTICAL** | 16 384 B, **DIFFERS (2158 B)** | | ||
| 122 | +| `EC_AV1_POSTDEBLOCK_DUMP16` | 12 288 B, DIFFERS (26 B) | 16 384 B, DIFFERS (2017 B) | | ||
| 123 | +| `EC_AV1_POSTCDEF_DUMP16` | 12 288 B, DIFFERS (26 B) | 16 384 B, DIFFERS (1948 B) | | ||
| 124 | +| `EC_AV1_DECODE_ORDER_DUMP` | 8 192 B, DIFFERS (1985 B) | 8 192 B, DIFFERS (1917 B) | | ||
| 125 | +| `EC_AV1_FINAL_DUMP` | 8 192 B, DIFFERS (1986 B) | 8 192 B, DIFFERS (1986 B) | | ||
| 126 | + | ||
| 127 | +12 288 B = 6144 samples = 4096 luma + 2×1024: only chroma rows 0–31. The frame the | ||
| 128 | +caller receives is 8192 samples. **The 2048 missing chroma samples are the | ||
| 129 | +region r2's conclusion was drawn from.** | ||
| 130 | + | ||
| 131 | +**Coordinates, from the corrected pre-deblock dump** (8192 samples, u16, whole | ||
| 132 | +plane, `0xDEAD` counted): | ||
| 133 | + | ||
| 134 | +* unwritten samples, sentinel run: **U 112, V 112, Y 0** — U and V, 28 whole | ||
| 135 | + 4×4 groups each, spanning rows 36–63 (12 rows carrying 8 samples + 4 rows | ||
| 136 | + carrying 4 = 96 + 16 = 112). The column span runs 0–15 but is NOT filled: | ||
| 137 | + every row has cols 0–3 and 12–15. **224 total, exactly lane/av1unwritten's own | ||
| 138 | + census number** (`lanes/av1unwritten.report.md:152-156`). | ||
| 139 | +* plain vs sentinel differing samples, pre-deblock: **U 1004 of 2048, V 1004 of | ||
| 140 | + 2048, Y 0**, rows 32–63 — the hole plus everything predicted from it. | ||
| 141 | + | ||
| 142 | +So the corrected conclusion is the opposite of r2's: the difference is **already | ||
| 143 | +present before deblock**; no filter creates it. r2's "Deblock creates it" was an | ||
| 144 | +artefact of the dump it could not see past. | ||
| 145 | + | ||
| 146 | +**And the census was never blind.** It runs at pre-deblock and it reports the | ||
| 147 | +hole — 224 samples, in whole 4×4 chroma blocks. What could not see it was the | ||
| 148 | +stage dump. On the hg fixtures both report 0. | ||
| 149 | + | ||
| 150 | +## 5. Displayed vs hidden, per fixture | ||
| 151 | + | ||
| 152 | +`reelb_arf_witness`: 40 decode-order frames — 19 shown, 21 hidden alt-refs, plus 18 | ||
| 153 | +`show_existing_frame` headers. `reelb_rect64_intra16x4_witness`: 34 — 17 shown, 17 | ||
| 154 | +hidden, plus 16 `show_existing_frame`. (From `EC_PROBE_HDR=1`; the split is over | ||
| 155 | +non-`show_existing` headers.) | ||
| 156 | + | ||
| 157 | +**No unwritten sample reaches a DISPLAYED frame on either fixture — or a hidden | ||
| 158 | +one.** Every one of the 34/40 frames hashes identically under plain, sentinel, | ||
| 159 | +five ambient fills, four thread counts and in-process poisoning, and both the | ||
| 160 | +pre-deblock census and the new output-point census report 0. The hidden frames | ||
| 161 | +were measured specifically because they are the route by which a hole would reach | ||
| 162 | +a later displayed frame through the reference bank; they are clean. | ||
| 163 | + | ||
| 164 | +The one fixture where a hole does reach output is the 4:2:2 witness, whose single | ||
| 165 | +frame is **SHOWN** (`Key show=true`), with 224 unwritten chroma samples. Its | ||
| 166 | +cause is the invalid subsize `main` now refuses; that lane owns it and is | ||
| 167 | +untouched here. | ||
| 168 | + | ||
| 169 | +## 6. The fix and the gate | ||
| 170 | + | ||
| 171 | +`decode.rs`: `census_unwritten_final` + `take_final_unwritten_samples` — a census | ||
| 172 | +over the three planes at the point they are stored into the reference slots, with | ||
| 173 | +`dump_stage16`'s chroma extent made per-axis. | ||
| 174 | + | ||
| 175 | +`stream.rs`: the census is called beside the `EC_AV1_FINAL_DUMP` site. | ||
| 176 | + | ||
| 177 | +**SCOPE, stated not implied:** that point is **before `apply_grain`**, so the | ||
| 178 | +claim is over the **pre-grain** planes only. Those are also the bytes the | ||
| 179 | +reference bank stores and every later frame predicts from, which is the | ||
| 180 | +dependency that matters. Whether `apply_grain` can itself introduce a hole is | ||
| 181 | +**not measured here** -- the census never sees the planes `apply_grain` | ||
| 182 | +allocates -- so "the caller's final grained picture has no hole" is **not | ||
| 183 | +claimed**, and no sentence asserts that grain cannot introduce one. | ||
| 184 | + | ||
| 185 | +Gate `the_frame_the_caller_receives_carries_no_unwritten_plane_sample`: | ||
| 186 | + | ||
| 187 | +1. **non-vacuity first, and SYNTHETIC**: the census is handed planes carrying | ||
| 188 | + exactly 7 sentinel samples and must report exactly 7. No fixture is involved, | ||
| 189 | + so it cannot be affected by `main` refusing `440_request_is_422` — which is | ||
| 190 | + what r2's fixture-carried control would have done on merge; | ||
| 191 | +2. **0** on `reelb_arf_witness`, `reelb_rect64_intra16x4_witness`, `gm_small_side_witness`, | ||
| 192 | + `reelc_sb128_inter_witness` — the real 10-bit streams with hidden alt-refs. | ||
| 193 | + | ||
| 194 | +The fill is env-gated and this crate forbids `set_var`, so the measurement runs | ||
| 195 | +in a child process the parent invokes by name; the child asserts | ||
| 196 | +`EC_AV1_PLANE_SENTINEL` is set, so a non-live fill fails rather than reporting a | ||
| 197 | +meaningless zero. | ||
| 198 | + | ||
| 199 | +**Merge proof — green on a tree containing both lanes.** `main` = `e45cc748` | ||
| 200 | +merged into this branch (`c62eeda9`), then: | ||
| 201 | + | ||
| 202 | +``` | ||
| 203 | +$ cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample | ||
| 204 | +test result: ok. 1 passed; 0 failed; 0 ignored; 816 filtered out; finished in 71.59s | ||
| 205 | +``` | ||
| 206 | + | ||
| 207 | +The proof that this tree really carries `av1unwritten`'s content is behavioural, | ||
| 208 | +not a test count (a filtered-test count is a count of names, and a merge that | ||
| 209 | +dropped hunks would print the same number): | ||
| 210 | + | ||
| 211 | +``` | ||
| 212 | +$ decode_probe crates/ec-av1/fixtures/440_request_is_422.obu | ||
| 213 | +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no | ||
| 214 | +chroma plane block at this frame's subsampling mode ... | ||
| 215 | +``` | ||
| 216 | + | ||
| 217 | +**0 frames, refused** — only reachable with the refusal present. On the branch | ||
| 218 | +point `8d6998d7` the same fixture decodes to `OK: 1 frames decoded`. That is the | ||
| 219 | +merge proof. (It is also why the fixture-carried control had to go: the census | ||
| 220 | +child could not run at all here.) | ||
| 221 | + | ||
| 222 | +### Mutations | ||
| 223 | + | ||
| 224 | +| mutation | result | | ||
| 225 | +|---|---| | ||
| 226 | +| `census_unwritten_final` neutered (`if true { return; }`) | **RED** at the synthetic control: "the census reported 0 for planes carrying exactly 7 sentinel samples … (class: census-silently-blind)" | | ||
| 227 | +| **the call at `stream.rs` DELETED** (the whole line replaced by a `let _ =`) | **RED**: "the census scanned 0 samples on reelb_arf_witness -- the call at the output point is not running, so the 0 below proves nothing (class: census-never-ran). Deleting the call site reproduces this." | | ||
| 228 | +| one sentinel sample forced into a film frame's output (`p.y[0] = 0xDEAD`) | RED on the fixture: "reelb_arf_witness hands the caller N samples the tile walk never wrote" | | ||
| 229 | + | ||
| 230 | +The second row was **false as stated in r3** and is the substantive fix here: r3's | ||
| 231 | +control called `census_unwritten_final` directly, so deleting the pipeline call | ||
| 232 | +left every assertion passing and the gate pinned nothing about the decode. The | ||
| 233 | +gate now reads `take_final_census_scanned()` alongside | ||
| 234 | +`take_final_unwritten_samples()` — the same pairing the merged pre-deblock census | ||
| 235 | +already documents ("a gate that only asserts `take_unwritten_samples() == 0` | ||
| 236 | +passes on a decode that never scanned anything, so it reads THIS too"). The | ||
| 237 | +fixture arms require `scanned > 0`, the synthetic arm requires `scanned == 40` | ||
| 238 | +(16 + 16 + 8), so "scanned and found nothing" is now distinguishable from | ||
| 239 | +"never scanned". | ||
| 240 | + | ||
| 241 | +## 7. Commands | ||
| 242 | + | ||
| 243 | +```bash | ||
| 244 | +cd /home/user/.cache/wt/unwrittendep | ||
| 245 | +git merge e45cc748 # merge proof tree | ||
| 246 | +CARGO_TARGET_DIR=... cargo build -p ec-av1 --example decode_probe | ||
| 247 | +strings .../decode_probe | grep -o 'wt/[a-z]*' # provenance | ||
| 248 | + | ||
| 249 | +python3 /tmp/unwritten/coords.py # corrected coordinates (§4) | ||
| 250 | +bash /tmp/unwritten/determinism.sh "440_request_is_422 reelb_rect64_intra16x4_witness reelb_arf_witness" 5 | ||
| 251 | +python3 /tmp/unwritten/partial.py reelb_arf_witness # the 97ef82c0ce shape | ||
| 252 | +cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample | ||
| 253 | +``` | ||
| 254 | + | ||
| 255 | +## 8. Disposition | ||
| 256 | + | ||
| 257 | +* **`reelb_arf_witness` — closed, not a decoder defect.** Output invariant under | ||
| 258 | + every ambient content tested (§2); the campaign's divergence is *consistent | ||
| 259 | + with* a truncated dump (§3), and the decode is innocent on the invariance | ||
| 260 | + evidence, not on the hash match. | ||
| 261 | +* **`reelb_rect64_intra16x4_witness` — closed, not a decoder defect; its campaign | ||
| 262 | + sentinel value `0ee1edf403` remains an OPEN instrument-hygiene question** (§3). | ||
| 263 | +* **`440_request_is_422` — measured and gated, not fixed here.** 224 unwritten | ||
| 264 | + chroma samples, pre-deblock, whole 4×4 blocks; cause is the invalid subsize | ||
| 265 | + `main` refuses (lane/av1unwritten, untouched). | ||
| 266 | +* **The `dump_stage16` per-axis extent is fixed** (§4) — the class is | ||
| 267 | + `diagnostic-dump-assumes-one-subsampling`. | ||
| 268 | + | ||
| 269 | +## 9. What this lane did not do | ||
| 270 | + | ||
| 271 | +* **The unswept family, now swept**: r2 did not run-to-run content | ||
| 272 | + nondeterminism with uninitialised planes — the family | ||
| 273 | + `lanes/av1unwritten.report.md:118-124` records as three different plain hashes | ||
| 274 | + of 440 from three identical invocations. A sentinel run structurally cannot | ||
| 275 | + detect it (it pins content to one value), and r2's in-process test could not | ||
| 276 | + (one process, one heap). N separate processes are required; the result is in | ||
| 277 | + §10. **I had not swept it in r2 and said nothing about it — that was a gap, not | ||
| 278 | + a negative result.** | ||
| 279 | +* The dump sites still swallow their write errors, so a short dump remains | ||
| 280 | + possible — the artefact behind §3. Making a partial write loud is an | ||
| 281 | + instrument change touching every dump in the crate; named, not done. | ||
| 282 | +* No pixel claim is made or unmade for any fixture. | ||
| 283 | +* Untouched per instructions: `film_grain.rs`, the reserved 4:2:0 group-tail | ||
| 284 | + chroma SKIP arm, `decode_rect4_16_intrabc`, and `lane/av1unwritten`'s content | ||
| 285 | + (read-only). | ||
| 286 | + | ||
| 287 | +## 10. The run-to-run nondeterminism family, swept | ||
| 288 | + | ||
| 289 | +N separate PROCESSES (not one process -- an in-process test cannot see this, it | ||
| 290 | +has one heap), uninitialised planes, per-run decode-order concatenation hashed, | ||
| 291 | +exact frame size asserted: | ||
| 292 | + | ||
| 293 | +``` | ||
| 294 | +=== 440_request_is_422 frames=0 (main = e45cc748 REFUSES it; not sweepable on the merge tree) | ||
| 295 | +=== reelb_rect64_intra16x4_witness | ||
| 296 | +5350cd5569d226eb frames=34 sizes=[18524160] | ||
| 297 | +5350cd5569d226eb frames=34 sizes=[18524160] | ||
| 298 | +5350cd5569d226eb frames=34 sizes=[18524160] | ||
| 299 | +5350cd5569d226eb frames=34 sizes=[18524160] | ||
| 300 | +=== reelb_arf_witness | ||
| 301 | +dca5b3d9d2d56f30 frames=40 sizes=[18524160] | ||
| 302 | +dca5b3d9d2d56f30 frames=40 sizes=[18524160] | ||
| 303 | +dca5b3d9d2d56f30 frames=40 sizes=[18524160] | ||
| 304 | +dca5b3d9d2d56f30 frames=40 sizes=[18524160] | ||
| 305 | +``` | ||
| 306 | + | ||
| 307 | +**Negative for both hg fixtures: 4/4 identical, correct size, no spread.** This | ||
| 308 | +is the family a sentinel run structurally cannot detect (it pins content to one | ||
| 309 | +value), and it is independent of the sentinel evidence in section 2. | ||
| 310 | + | ||
| 311 | +`440_request_is_422` **could not be swept on the merge tree** -- `main` = `e45cc748` | ||
| 312 | +refuses it, which is the refusal working as intended. On the branch point | ||
| 313 | +`8d6998d7` I measured 3 identical plain hashes (`a761118c8dd5c8d0`), i.e. I did | ||
| 314 | +**not** reproduce the three-distinct-hashes observation at | ||
| 315 | +`lanes/av1unwritten.report.md:118-124`. That is consistent rather than | ||
| 316 | +contradictory: the witness's output depends on ambient memory, and what the | ||
| 317 | +allocator hands back is machine- and run-dependent, so a fixed value on one host | ||
| 318 | +and a varying one on another are the same defect. **Stated as measured: 3/3 | ||
| 319 | +identical here, and no claim about reproducing their observation.** | ||
| 320 | + | ||
| 321 | +## 11. What the per-axis extent change invalidated in published work | ||
| 322 | + | ||
| 323 | +`round_ss(dim, 1)` is bit-identical to `dim.div_ceil(2)`, so **every 4:2:0 dump is | ||
| 324 | +byte-for-byte unchanged** by the `dump_stage16` fix. The change only affects 4:2:2 | ||
| 325 | +and 4:4:0 frames. | ||
| 326 | + | ||
| 327 | +21 lane files reference the `*_DUMP16` dumps. Of those, exactly one, | ||
| 328 | +`lanes/av1422luma.report.md`, uses non-4:2:0 fixtures (`s422_416x250_10b`). Its | ||
| 329 | +stage table (line 77 onward) is a **Y-only** conclusion — every row reads | ||
| 330 | +"frame 0 Y wrong vs ffmpeg", and the reported numbers are luma sample counts and | ||
| 331 | +a luma first-differing coordinate — so that conclusion **survives** the extent | ||
| 332 | +change unchanged. What the change invalidates is only that report's **label**: | ||
| 333 | +"depth-correct `*_DUMP16`" is no longer accurate for the **chroma half** of those | ||
| 334 | +files, which the 4:2:0 crop had truncated to the top half-height. No published | ||
| 335 | +number moves. | ||
| 336 | + | ||
| 337 | +`lanes/unwritten-dep.report.md` (this file) is the only other DUMP16 reference | ||
| 338 | +touching a non-4:2:0 frame, and its numbers are the corrected ones above. | ||
| 339 | + | ||
| 340 | +## 12. OPEN, filed: the `unsafe { v.set_len(n) }` in `fresh_plane` is not fully justified | ||
| 341 | + | ||
| 342 | +**This is the highest-risk item this lane found, and it is NOT closed here.** It | ||
| 343 | +is filed rather than fixed because closing it means either restoring a ~3% frame- | ||
| 344 | +head cost or building a reads-before-write instrument, and both are decisions | ||
| 345 | +that belong to a lane chartered for them. The comments in `decode.rs` now say | ||
| 346 | +this, so a reviewer can no longer approve the `unsafe` on a withdrawn proof. | ||
| 347 | + | ||
| 348 | +**The retracted claim.** `fresh_plane`'s doc asserted the SB-padded surface "is | ||
| 349 | +written sample-for-sample by the tile walk's reconstruction before anything reads | ||
| 350 | +it", and cited the sentinel gate as proof ("proven by the sentinel gate above"). | ||
| 351 | +**The same file retracts it.** The basis is **this lane's own measurement**, not | ||
| 352 | +second-hand: on `440_request_is_422` an exact u16 whole-plane census at the | ||
| 353 | +pre-deblock point finds **112 unwritten samples per chroma plane, 224 total** (U | ||
| 354 | +and V, 28 whole 4×4 groups each, rows 36–63) in a frame that is **SHOWN** | ||
| 355 | +(`Key show=true`) and whose samples the caller receives (§4, §5). Uninitialised | ||
| 356 | +memory that reaches the caller was read, or the read that produced it was. That | ||
| 357 | +is the UB, and it stands without any hash-variation claim. | ||
| 358 | + | ||
| 359 | +A hash-variation observation also exists — five plain runs of the witness giving | ||
| 360 | +two different output hashes (`lanes/av1unwritten.report.md:118-124`) — but it is | ||
| 361 | +**second-hand and NOT reproduced here**: five plain runs on `8d6998d7` gave one | ||
| 362 | +hash, `a761118c8dd5c8d0` (§10). It is therefore not relied on, and it should not | ||
| 363 | +have been stated flatly in the `decode.rs` comment, where it did read as this | ||
| 364 | +lane's measurement. Ambient content is machine-dependent, so a stable value on one | ||
| 365 | +host and a varying one on another would be the same defect either way; the | ||
| 366 | +224-sample census is the basis, the hashes are an aside. | ||
| 367 | + | ||
| 368 | +**What the gate actually proves — the weaker claim.** The gate counts at the | ||
| 369 | +**output point only**: one census, one scan. The pre-deblock census | ||
| 370 | +(`census_unwritten`, `take_unwritten_samples` / `take_census_scanned`) is a | ||
| 371 | +**different instrument with no committed reader anywhere in the crate on `main`** | ||
| 372 | +(§13), so it backs nothing here. An earlier revision of this section credited | ||
| 373 | +the gate with both, which would have told a reviewer auditing the `unsafe` that | ||
| 374 | +the premise is covered by two scans when only one exists — and the missing one is | ||
| 375 | +exactly the scan that would catch a hole before the filters. What the gate | ||
| 376 | +measures is **survival, not reads**: | ||
| 377 | + | ||
| 378 | +* PROVEN: no sample the tile walk never wrote **survives into the frame the | ||
| 379 | + caller receives**, on the corpus measured. | ||
| 380 | +* NOT PROVEN: "every sample is written before it is read". A sample read as a | ||
| 381 | + prediction or filter neighbour and overwritten a moment later is invisible to | ||
| 382 | + that count. **No such read has been observed, and no instrument in this crate | ||
| 383 | + measures for one.** | ||
| 384 | +* On `main` = `e45cc748` the one path where a read was **demonstrated** is now | ||
| 385 | + unreachable — lane/av1unwritten refuses the subsize before descending. | ||
| 386 | + | ||
| 387 | +**Why this is UB-class and not a style issue.** `Vec::set_len` over | ||
| 388 | +uninitialised memory is not itself UB: `u16` has no invalid bit patterns and no | ||
| 389 | +`Drop`, so the vector validly *owns* `n` slots. The UB is in **reading** an | ||
| 390 | +uninitialised `u16`. `set_len` is therefore sound only under the "written before | ||
| 391 | +read" premise, and that premise is the one the measurement withdrew. | ||
| 392 | + | ||
| 393 | +**The withdrawn premise was doing double duty, which is why one retraction | ||
| 394 | +untangles two findings.** It justified *this* `unsafe`, AND it was the reason the | ||
| 395 | +census's original story — a pre-deblock scan that is blind to a hole the loop | ||
| 396 | +filter later reads — looked plausible in the first place. The same measurement | ||
| 397 | +that withdrew the safety argument (output varying with initial content) is what | ||
| 398 | +made the blind-census reading wrong: there was never a blind pre-deblock scan, | ||
| 399 | +only a `dump_stage16` that could not see half the chroma plane. So §12 and the | ||
| 400 | +corrected stage bisect in §4 are the same fact read twice, and a later reader who | ||
| 401 | +fixes one without the other will re-derive the error. | ||
| 402 | + | ||
| 403 | +**Three closures, none taken here:** | ||
| 404 | + | ||
| 405 | +1. **Explicit zero-fill** — restore `vec![0u16; n]`. Sound unconditionally, at | ||
| 406 | + the ~3% of frame-thread cycles at 4K that lane-picalloc removed. This is the | ||
| 407 | + safe default and the honest cost of the optimisation. | ||
| 408 | +2. **Allocator-zeroed allocation** — a zeroed allocation can come from the | ||
| 409 | + allocator rather than a loop: `alloc_zeroed` / anonymous mmap hands back zero | ||
| 410 | + pages on first touch, which for plane-sized buffers costs a page fault rather | ||
| 411 | + than a per-sample store. **This is an option that needs its own measurement, | ||
| 412 | + not a claim that it is free** — the cost at 4K is unmeasured in this lane, and | ||
| 413 | + "a page fault per page" is a mechanism, not a benchmark. Whoever takes it must | ||
| 414 | + measure it before calling it cheaper than (1). | ||
| 415 | +3. **Instrument reads-before-write** — a per-sample read/write map, so the premise | ||
| 416 | + can be proved rather than assumed. That is a real instrument, not a comment, | ||
| 417 | + and it is the only route that keeps the optimisation as-is. | ||
| 418 | + | ||
| 419 | +**Reachability evidence** (what makes this fileable rather than theoretical), | ||
| 420 | +**this lane's own measurement**: on `440_request_is_422` at `8d6998d7`, an exact | ||
| 421 | +u16 whole-plane census finds **224 unwritten chroma samples** (U 112, V 112, | ||
| 422 | +whole 4×4 groups, rows 36–63) in a frame that is **SHOWN** and whose samples the | ||
| 423 | +caller receives — uninitialised memory reaching the caller IS the UB, and it | ||
| 424 | +needs no hash claim. That path is refused on `main`, so the corpus contains no | ||
| 425 | +*currently reachable* instance; the hash-variation observation that also exists is | ||
| 426 | +second-hand and was not reproduced here (§10), so it is not part of the basis. | ||
| 427 | +The claim that needs proving is universal ("every sample is written before it is | ||
| 428 | +read"), and one refused witness cannot establish it for the other 126 fixtures. | ||
| 429 | + | ||
| 430 | +## 13. Does this lane's gate supply the reader `take_unwritten_samples` lacked? — NO | ||
| 431 | + | ||
| 432 | +Checked, and the answer is the unflattering one. `take_unwritten_samples` and | ||
| 433 | +`take_census_scanned` (lane/av1unwritten's pre-deblock census API) still have | ||
| 434 | +**no committed reader** on `main` = `e45cc748`: the only references to them | ||
| 435 | +anywhere in `crates/ec-av1/src` are in their own doc comments. `grep` over | ||
| 436 | +`stream.rs` and the rest finds no call site. | ||
| 437 | + | ||
| 438 | +My gate reads only its OWN pair, `take_final_unwritten_samples` / | ||
| 439 | +`take_final_census_scanned`. So the r4 pairing is a **template** for how a census | ||
| 440 | +gate should be written (count AND scanned, so "scanned and found nothing" is | ||
| 441 | +distinguishable from "never scanned") — it is **not** a committed gate over the | ||
| 442 | +pre-deblock census, and this report does not claim one. Closing that gap means | ||
| 443 | +either adding the pre-deblock pair to an existing gate's assertions or giving it | ||
| 444 | +its own; that is a decision for the lane that owns the instrument, and it is named | ||
| 445 | +here rather than assumed done. | ||