forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-picalloc' (a7153af4): new frame planes allocated uninitialised instead of zero-filled; EC_AV1_PLANE_SENTINEL=1 fills 0xDEAD and hashes identically on every gate stream and film cut, proving every sample is written before read; -2% task-clock single-thread

Browse files at this commit

5e5cc09c348c8a37fe588c0fea3d82eae9cc08a9Ahmet Kaan GümüşParent: a360df6f982308
crates/ec-av1/src/decode.rsmodified+38 -6
@@ -12876,6 +12876,38 @@ fn dump_stage(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
1287612876 }
1287712877 }
1287812878
12879+/// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no
12880+/// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,
12881+/// at most 4095), so a decode that hashes identically under the flag proves
12882+/// the output does not depend on the plane buffer's initial content.
12883+const PLANE_SENTINEL: u16 = 0xDEAD;
12884+
12885+/// A frame plane's own backing store, `n` samples, UNINITIALISED.
12886+///
12887+/// (lane-picalloc) The SB-padded coding surface is written sample-for-sample
12888+/// by the tile walk's reconstruction before anything reads it, so the
12889+/// `vec![0u16; n]` this replaces spent ~3% of the frame thread's cycles
12890+/// zeroing 25 MB (at 4K) that the very next pass overwrites -- serially, at
12891+/// the frame's head, on the critical path. `EC_AV1_PLANE_SENTINEL=1` swaps the
12892+/// uninitialised buffer for a [`PLANE_SENTINEL`] fill; the gate hashes both
12893+/// ways (see the lane report) and the two agree, which is the proof that no
12894+/// unwritten sample reaches the output.
12895+fn fresh_plane(n: usize) -> Vec<u16> {
12896+ if crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") {
12897+ return vec![PLANE_SENTINEL; n];
12898+ }
12899+ let mut v: Vec<u16> = Vec::with_capacity(n);
12900+ // SAFETY: `u16` has no invalid bit patterns and no `Drop`, and the
12901+ // capacity was just reserved, so the vector owns `n` initialised-or-not
12902+ // `u16` slots. Every one is written by reconstruction before it is read
12903+ // (proven by the sentinel gate above).
12904+ #[allow(unsafe_code)]
12905+ unsafe {
12906+ v.set_len(n);
12907+ }
12908+ v
12909+}
12910+
1287912911 #[derive(Clone)]
1288012912 struct PlaneBuf<'a> {
1288112913 data: std::borrow::Cow<'a, [u16]>,
@@ -19943,7 +19975,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1994319975 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
1994419976
1994519977 let mut y = PlaneBuf {
19946- data: std::borrow::Cow::Owned(vec![0u16; width * height]),
19978+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
1994719979 width,
1994819980 height,
1994919981 true_width,
@@ -19954,7 +19986,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1995419986 tile_y1: height,
1995519987 };
1995619988 let mut u = PlaneBuf {
19957- data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
19989+ data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
1995819990 width: width / 2,
1995919991 height: height / 2,
1996019992 true_width: true_width / 2,
@@ -19965,7 +19997,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1996519997 tile_y1: height / 2,
1996619998 };
1996719999 let mut v = PlaneBuf {
19968- data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
20000+ data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
1996920001 width: width / 2,
1997020002 height: height / 2,
1997120003 true_width: true_width / 2,
@@ -31521,7 +31553,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3152131553 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));
3152231554
3152331555 let mut y = PlaneBuf {
31524- data: std::borrow::Cow::Owned(vec![0u16; width * height]),
31556+ data: std::borrow::Cow::Owned(fresh_plane(width * height)),
3152531557 width,
3152631558 height,
3152731559 true_width,
@@ -31532,7 +31564,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3153231564 tile_y1: height,
3153331565 };
3153431566 let mut u = PlaneBuf {
31535- data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
31567+ data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
3153631568 width: width / 2,
3153731569 height: height / 2,
3153831570 true_width: true_width / 2,
@@ -31543,7 +31575,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3154331575 tile_y1: height / 2,
3154431576 };
3154531577 let mut v = PlaneBuf {
31546- data: std::borrow::Cow::Owned(vec![0u16; width * height / 4]),
31578+ data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
3154731579 width: width / 2,
3154831580 height: height / 2,
3154931581 true_width: true_width / 2,