forge
Explore
Log in

Don't you dare go Hollow

U3: drop the plane poison sentinel and its census statics (set_plane_sentinel, take_*_unwritten, PLANE_SENTINEL, EC_AV1_PLANE_SENTINEL reads were gone; nothing set the flag). fresh_plane and uninit_plane always zero-fill, the unused geometry args are removed. Output unchanged (unset branch kept). cargo check -p ec-av1 --all-targets clean

Browse files at this commit

4c53cca67fa941ef89520321ba0cd02a77c8cef5Ahmet Kaan GümüşParent: 9f35dca
crates/ec-av1/src/decode/block.rsmodified+1 -182
@@ -418,111 +418,6 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
418 }418 }
419 }419 }
420 420
421-/// One plane's reconstruction buffer, `width * height` samples, and the
422-/// prediction/residual reads and writes into it — the decode-side twin of
423-/// [`crate::encode`]'s private `Plane`, whose `edges` this mirrors exactly
424-/// (own-edge and reach clamps both), passing what it gathers straight to
425-/// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
426-/// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written
427-/// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`.
428-/// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of
429-/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects).
430-/// lane-unwritten-dep: this doc previously said the dump "matches aomdec's own
431-/// `ec_dump16` rung byte for byte (crop dims, u16 LE)", which was true only of
432-/// the 4:2:0 crop it then used. The crop is now PER-AXIS, which is what the
433-/// oracle's rung 1 actually does -- it writes `y_crop_width` x `y_crop_height`,
434-/// `uv_crop_width` x `uv_crop_height`, `uv_crop_width` x `uv_crop_height` (the
435-/// libaom `YV12_BUFFER_CONFIG` fields, each already per-axis). Byte shape per
436-/// subsampling, `fw x fh` luma then both chroma planes, u16 LE, so:
437-///
438-/// ```text
439-/// ss_x ss_y format luma chroma (each)
440-/// 0 0 4:4:4 fw x fh fw x fh fw*fh*3 samples
441-/// 1 1 4:2:0 fw x fh fw/2 x fh/2 fw*fh*3/2 samples
442-/// 1 0 4:2:2 fw x fh fw/2 x fh fw*fh*2 samples
443-/// 0 1 4:4:0 fw x fh fw x fh/2 fw*fh*3/2 samples
444-/// ```
445-///
446-/// (`round_ss` is the rounding the decoder's own plane extents use; at ss = 1 it
447-/// is `div_ceil(2)`, so every 4:2:0 dump is byte-for-byte unchanged by this.)
448-/// lane-mc64 r1: the file name is keyed on [`dump_stage_idx`], a per-var
449-/// decode-order counter -- both dumps used to write `.f0` unconditionally, so
450-/// every frame overwrote the previous one and only the LAST frame survived,
451-/// which silently defeats any per-frame filter-stage bisection (ledger, class
452-/// stale-output-faked-measurement). A sibling accessor `stage_dump_idx()`, which
453-/// derived the same number from `PREFILT_PICTURE_IDX`, had no caller and was
454-/// deleted: `PREFILT_PICTURE_IDX` is bumped after this point, not before it, so
455-/// the counter that names these files is the per-var map.
456-// Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
457-/// Unwritten samples [`census_unwritten`] has counted since the last
458-/// [`take_unwritten_samples`] -- process-global (not thread-local) because the
459-/// gate reads it after the decode, from a different thread than the one that
460-/// scanned the plane.
461-pub(super) static UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
462- std::sync::atomic::AtomicUsize::new(0);
463-
464-/// Turns [`PLANE_SENTINEL`] filling on for the CALLING thread, independently
465-/// of `EC_AV1_PLANE_SENTINEL`. A gate cannot set a process-constant env var
466-/// (see [`crate::envflags`]), and the census is the only honest way to ask
467-/// "did the tile walk write every sample it was handed" -- a wrong-sample diff
468-/// cannot tell an unwritten sample from a mis-predicted one.
469-pub fn set_plane_sentinel(on: bool) {
470- PLANE_SENTINEL_ON.with(|c| c.set(on));
471-}
472-
473-/// Reads and clears [`UNWRITTEN_SAMPLES`]: the number of samples the decode
474-/// just handed to the tile walk never wrote, summed over every frame and
475-/// plane. Zero is the only acceptable answer for a decoder whose output must
476-/// not depend on its allocator.
477-pub fn take_unwritten_samples() -> usize {
478- UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
479-}
480-
481-/// Samples in the PADDED TAIL -- every sample of each plane outside its own
482-/// `true_width` x `true_height` extent -- that still holds [`plane_poison`] at
483-/// the pre-deblock point. [`census_unwritten`] scans that region too, because
484-/// "past the true extent nothing is ever read" was an ASSUMPTION the tail's
485-/// census was built to avoid checking; this counter is the measurement.
486-pub(super) static PAD_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
487- std::sync::atomic::AtomicUsize::new(0);
488-
489-/// Reads and clears [`PAD_UNWRITTEN_SAMPLES`].
490-pub fn take_pad_unwritten_samples() -> usize {
491- PAD_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
492-}
493-
494-/// The value [`fresh_plane`] fills with when the sentinel is on.
495-///
496-/// [`PLANE_SENTINEL`] unless `EC_AV1_PLANE_SENTINEL` names a different one in
497-/// hex. Two different poisons are what turns the sentinel from "did a hole
498-/// survive into the output" into "did the output depend on the buffer's
499-/// initial content": a hole whose value reaches the picture changes the hash
500-/// when the poison changes, and one that does not cannot have influenced
501-/// anything. A value at or below [`MAX_LEGAL_SAMPLE`] is REFUSED (falls back
502-/// to [`PLANE_SENTINEL`]) because the census's soundness rests on the sentinel
503-/// being impossible. `EC_AV1_PLANE_SENTINEL=1` -- the spelling every existing
504-/// caller and gate uses, and `env_flag!`'s mere presence test -- keeps
505-/// [`PLANE_SENTINEL`].
506-/// `pub(crate)` for lane-av1graincensus: `film_grain::uninit_plane` fills its
507-/// destination with the SAME poison `fresh_plane` does, and
508-/// [`census_unwritten_grained`] counts the same value. The fill and the census
509-/// must agree on both the value and the predicate, or a "0" means nothing.
510-pub(crate) fn plane_poison() -> u16 {
511- PLANE_SENTINEL
512-}
513-
514-thread_local! {
515- /// The [`set_plane_sentinel`] override; `EC_AV1_PLANE_SENTINEL` is the
516- /// process-wide default.
517- static PLANE_SENTINEL_ON: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
518-}
519-
520-/// Whether freshly allocated planes are [`PLANE_SENTINEL`]-filled.
521-/// `pub(crate)` for the same reason as [`plane_poison`].
522-pub(crate) fn plane_sentinel_on() -> bool {
523- PLANE_SENTINEL_ON.with(std::cell::Cell::get)
524-}
525-
526 /// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this421 /// lane-av1unwritten: whether a subsize has a chroma PLANE BLOCK at this
527 /// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] !=422 /// frame's subsampling -- libaom `av1_ss_size_lookup[bsize][ss_x][ss_y] !=
528 /// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every423 /// BLOCK_INVALID` (`common_data.c`), which `decode_partition` checks on every
@@ -717,84 +612,8 @@ pub(super) fn refuse_invalid_plane_block(
717 )612 )
718 }613 }
719 614
720-/// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no
721-/// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,
722-/// at most 4095), so a decode that hashes identically under the flag proves
723-/// the output does not depend on the plane buffer's initial content.
724-pub(super) const PLANE_SENTINEL: u16 = 0xDEAD;
725-
726-/// lane-unwritten-dep: the census count at the LAST point of the pipeline, on the
727-/// exact bytes `EC_AV1_FINAL_DUMP` writes.
728-///
729-/// WHY A SECOND COUNT, and what it is actually for -- the justification this
730-/// comment originally carried was WRONG and is corrected here, because a reader
731-/// would otherwise re-derive the wrong conclusion. An earlier revision of this
732-/// lane claimed the pre-deblock plane was byte-identical plain-vs-sentinel and
733-/// that "deblock creates the dependence". That reading came from
734-/// [`dump_stage16`], which cropped chroma as `(fw/2, fh/2)` -- a 4:2:0
735-/// assumption. On a 64x64 4:2:2 frame (ss_x=1, ss_y=0) that wrote 32x32 chroma
736-/// where the frame carries 32x64, so 2048 chroma samples appeared in NO stage
737-/// dump, and they are exactly the region where the difference lives.
738-///
739-/// With per-axis extents the corrected measurement on `440_request_is_422` is:
740-/// the PRE-DEBLOCK dump already DIFFERS by 2158 bytes plain-vs-sentinel, and an
741-/// exact u16 whole-plane census finds 224 unwritten samples (U 112, V 112,
742-/// rows 36..63, whole 4x4 groups) -- the same number
743-/// `lanes/av1unwritten.report.md` reports. **The hole is present before any
744-/// filter runs, and the pre-deblock census sees it.** This comment previously
745-/// said the opposite; that was the instrument's blind spot read as a property of
746-/// the pipeline.
747-///
748-/// So what this second count is FOR, stated honestly: it is not there because the
749-/// pre-deblock census misses holes. It is there because it is the measurement
750-/// taken where the OUTPUT is taken -- the bytes stored into the reference slots
751-/// and handed to the caller. A hole can be created after reconstruction (a
752-/// filter stage, a superres step, a second pass) and be invisible to a scan taken
753-/// before it; this one cannot. It is a check on the whole span from the tile walk
754-/// to the caller's frame, not a claim that the pre-deblock scan is insufficient.
755-pub(super) static FINAL_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
756- std::sync::atomic::AtomicUsize::new(0);
757-
758-/// lane-unwritten-dep: reads and clears [`FINAL_UNWRITTEN_SAMPLES`] -- unwritten
759-/// samples still present in the frame as handed to the caller, summed over every
760-/// frame and plane. Process-global, like the pre-deblock census's counter, so a
761-/// gate can read it after the decode from a different thread than the one that
762-/// scanned.
763-pub fn take_final_unwritten_samples() -> usize {
764- FINAL_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
765-}
766-
767-/// lane-av1graincensus: samples still holding the poison after film grain, over
768-/// the picture [`crate::film_grain::apply_grain`] RETURNS -- i.e. the picture the
769-/// caller receives on a grained frame.
770-pub(super) static GRAINED_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize =
771- std::sync::atomic::AtomicUsize::new(0);
772-
773-/// Reads and clears [`GRAINED_UNWRITTEN_SAMPLES`].
774-pub fn take_grained_unwritten_samples() -> usize {
775- GRAINED_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst)
776-}
777-
778 /// A frame plane's own backing store, `n` samples, zero-filled.615 /// A frame plane's own backing store, `n` samples, zero-filled.
779-///616+pub(super) fn fresh_plane(n: usize) -> Vec<u16> {
780-/// The `true_width`/`true_height`/`width`/`height` arguments are kept for the
781-/// call sites' shape and the sentinel's poison fill; the zero fill itself reads
782-/// none of them. The former `EC_AV1_PLANE_ALLOC=uninit|padzero|extzero` arms
783-/// (uninitialised allocation for memcheck census) are gone: they needed
784-/// `set_len` over uninitialised memory, which the crate no longer contains. The
785-/// shipped default was already the zeroed arm (`lanes/av1uballoc.report.md` §1);
786-/// the poison sentinel (`EC_AV1_PLANE_SENTINEL`) still catches any read of the
787-/// initial content.
788-pub(super) fn fresh_plane(
789- n: usize,
790- _true_width: usize,
791- _true_height: usize,
792- _width: usize,
793- _height: usize,
794-) -> Vec<u16> {
795- if plane_sentinel_on() {
796- return vec![plane_poison(); n];
797- }
798 vec![0u16; n]617 vec![0u16; n]
799 }618 }
800 619
crates/ec-av1/src/decode/frame_tile.rsmodified+3 -9
@@ -417,13 +417,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
417 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);417 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
418 418
419 let mut y = PlaneBuf {419 let mut y = PlaneBuf {
420- data: std::borrow::Cow::Owned(fresh_plane(420+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
421- width * height,
422- true_width,
423- true_height,
424- width,
425- height,
426- )),
427 width,421 width,
428 height,422 height,
429 true_width,423 true_width,
@@ -437,7 +431,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
437 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));431 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
438 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));432 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
439 let mut u = PlaneBuf {433 let mut u = PlaneBuf {
440- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),434+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
441 width: cw,435 width: cw,
442 height: ch,436 height: ch,
443 true_width: ctw,437 true_width: ctw,
@@ -449,7 +443,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
449 plane: 1,443 plane: 1,
450 };444 };
451 let mut v = PlaneBuf {445 let mut v = PlaneBuf {
452- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),446+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
453 width: cw,447 width: cw,
454 height: ch,448 height: ch,
455 true_width: ctw,449 true_width: ctw,
crates/ec-av1/src/decode/key_tile.rsmodified+3 -9
@@ -410,13 +410,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
410 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);410 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
411 411
412 let mut y = PlaneBuf {412 let mut y = PlaneBuf {
413- data: std::borrow::Cow::Owned(fresh_plane(413+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
414- width * height,
415- true_width,
416- true_height,
417- width,
418- height,
419- )),
420 width,414 width,
421 height,415 height,
422 true_width,416 true_width,
@@ -430,7 +424,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
430 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));424 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
431 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));425 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
432 let mut u = PlaneBuf {426 let mut u = PlaneBuf {
433- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),427+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
434 width: cw,428 width: cw,
435 height: ch,429 height: ch,
436 true_width: ctw,430 true_width: ctw,
@@ -442,7 +436,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
442 plane: 1,436 plane: 1,
443 };437 };
444 let mut v = PlaneBuf {438 let mut v = PlaneBuf {
445- data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),439+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
446 width: cw,440 width: cw,
447 height: ch,441 height: ch,
448 true_width: ctw,442 true_width: ctw,
crates/ec-av1/src/decode/mod.rsmodified+1 -1
@@ -67,7 +67,7 @@ use rect4::*;
67 67
68 mod block;68 mod block;
69 mod wave;69 mod wave;
70-pub use block::*;70+pub(crate) use block::*;
71 71
72 mod leaf8;72 mod leaf8;
73 use leaf8::*;73 use leaf8::*;
crates/ec-av1/src/film_grain.rsmodified+1 -21
@@ -1348,28 +1348,8 @@ struct GrainBand<'a> {
1348 /// the disjoint band slices' split does; the byte-exact 1-vs-4-thread1348 /// the disjoint band slices' split does; the byte-exact 1-vs-4-thread
1349 /// gate is what checks it. Upgrade path: `Box<[MaybeUninit<u16>]>` plumbed1349 /// gate is what checks it. Upgrade path: `Box<[MaybeUninit<u16>]>` plumbed
1350 /// through the kernels.1350 /// through the kernels.
1351-///
1352-/// # lane-av1graincensus: the fill under the census arm
1353-///
1354-/// That corner-cut is also why the buffer must be POISONED, not merely
1355-/// uninitialised, whenever the sentinel is live. Counting `== plane_poison()`
1356-/// over ambient garbage is a census that can only ever report ~0: a hole
1357-/// survives with probability ~1/65536 rather than always, so
1358-/// [`crate::decode::census_unwritten_grained`] would report 0 whether or not
1359-/// the band copy covered every row. Filling here makes "the band copy wrote
1360-/// every sample" a measurement. It is the same predicate
1361-/// [`crate::decode::fresh_plane`] honours, and with the sentinel off -- every
1362-/// shipped build -- this is the same zeroed buffer, so nothing changes where it
1363-/// is paid for.
1364 fn uninit_plane(n: usize) -> Vec<u16> {1351 fn uninit_plane(n: usize) -> Vec<u16> {
1365- // `vec![0; n]` is `alloc_zeroed`, which for a plane-sized buffer is a1352+ vec![0; n]
1366- // fresh `calloc`/mmap: the zero pages are not touched until the band copy
1367- // writes them, so no extra full-buffer pass is paid. Safe, and no `set_len`.
1368- let mut v: Vec<u16> = vec![0; n];
1369- if crate::decode::plane_sentinel_on() {
1370- v.fill(crate::decode::plane_poison());
1371- }
1372- v
1373 }1353 }
1374 1354
1375 /// `av1_add_film_grain`/`add_film_grain_run` (spec 7.18.3.5): synthesize and1355 /// `av1_add_film_grain`/`add_film_grain_run` (spec 7.18.3.5): synthesize and