forge
Explore
Log in

Don't you dare go Hollow

Wire the COMPOUND_WEDGE blend (comp_group_idx==1, compound_type==0)

Browse files at this commit

2803580d98ec1334d0e35987b4b9dcffaa839112Ahmet Kaan GümüşParent: 99ff391
  • feat
    • wire the COMPOUND_WEDGE blend (comp_group_idx==1, compound_type==0)
    • gate fires wedge live (mandelbrot diagonal content, dist-wtd-comp=0), 20/20 pixel-exact, 475 wedge hits
Show full message
feat(av1): wire the COMPOUND_WEDGE blend (comp_group_idx==1, compound_type==0); gate fires wedge live (mandelbrot diagonal content, dist-wtd-comp=0), 20/20 pixel-exact, 475 wedge hits
crates/ec-av1/src/decode.rsmodified+72 -57
@@ -215,6 +215,17 @@ pub(crate) fn masked_compound_hits() -> usize {
215215 MASKED_COMPOUND_HITS.load(std::sync::atomic::Ordering::Relaxed)
216216 }
217217
218+/// How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==
219+/// 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture
220+/// actually exercised the wedge blend, not just the DIFFWTD half of
221+/// `MASKED_COMPOUND_HITS`.
222+static WEDGE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
223+
224+/// Current value of [`WEDGE_HITS`].
225+pub(crate) fn wedge_hits() -> usize {
226+ WEDGE_HITS.load(std::sync::atomic::Ordering::Relaxed)
227+}
228+
218229 /// Current value of [`OBMC_HITS_8`].
219230 pub(crate) fn obmc_hits_8() -> usize {
220231 OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)
@@ -5327,12 +5338,12 @@ fn decode_inter_block(
53275338 } else {
53285339 0
53295340 };
5330- // lane-maskcomp r2: `Some(mask_type)` only for a real
5331- // `COMPOUND_DIFFWTD` block (`comp_group_idx == 1`, `compound_type
5332- // == 1`) -- wedge (`compound_type == 0`) still refuses by name,
5333- // its mask codebook unported (charter's mergeable-partial
5334- // fallback).
5341+ // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
5342+ // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
5343+ // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
5344+ // when `comp_group_idx == 1`.
53355345 let mut diffwtd_mask_type: Option<u8> = None;
5346+ let mut wedge_mask: Option<&'static [u8]> = None;
53365347 if comp_group_idx == 1 {
53375348 // lane-maskcomp r1: `read_compound_type` (spec 5.11.25,
53385349 // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used
@@ -5350,20 +5361,21 @@ fn decode_inter_block(
53505361 };
53515362 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);
53525363 if compound_type == 0 {
5353- // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
5354- let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
5355- let _wedge_sign = dec.literal(1);
5356- MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5357- return Err(unsupported(
5358- "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, \
5359- COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\
5360- wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \
5361- not ported (lane-maskcomp r2 scope: DIFFWTD only)",
5362- ));
5364+ // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
5365+ // verified vs independent C dump (wedge.rs).
5366+ let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
5367+ let wedge_sign = dec.literal(1);
5368+ WEDGE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5369+ wedge_mask = Some(
5370+ crate::wedge::wedge_masks()
5371+ .codebook(side)
5372+ .mask(wedge_sign as usize, wedge_index as usize),
5373+ );
5374+ } else {
5375+ // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
5376+ let mask_type = dec.literal(1);
5377+ diffwtd_mask_type = Some(mask_type as u8);
53635378 }
5364- // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
5365- let mask_type = dec.literal(1);
5366- diffwtd_mask_type = Some(mask_type as u8);
53675379 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
53685380 }
53695381 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
@@ -5653,18 +5665,20 @@ fn decode_inter_block(
56535665 );
56545666 let mut pred_y = vec![0u8; side * side];
56555667 let mut diffwtd_mask_y = Vec::new();
5656- if let Some(mask_type) = diffwtd_mask_type {
5668+ // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR
5669+ // the wedge codebook lookup (comp_group_idx==1's two mutually
5670+ // exclusive branches) -- same [`mc::blend_masked_compound`] call
5671+ // either way, only the mask source differs.
5672+ let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
56575673 diffwtd_mask_y = vec![0u8; side * side];
56585674 mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y);
5675+ Some(diffwtd_mask_y.as_slice())
5676+ } else {
5677+ wedge_mask
5678+ };
5679+ if let Some(mask_y) = mask_y {
56595680 mc::blend_masked_compound(
5660- &inter0_y,
5661- &inter1_y,
5662- &diffwtd_mask_y,
5663- side,
5664- side,
5665- side,
5666- false,
5667- &mut pred_y,
5681+ &inter0_y, &inter1_y, mask_y, side, side, side, false, &mut pred_y,
56685682 );
56695683 } else {
56705684 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y);
@@ -5699,11 +5713,11 @@ fn decode_inter_block(
56995713 &mut inter1_u,
57005714 );
57015715 let mut pred_u = vec![0u8; chroma_side * chroma_side];
5702- if diffwtd_mask_type.is_some() {
5716+ if let Some(mask_y) = mask_y {
57035717 mc::blend_masked_compound(
57045718 &inter0_u,
57055719 &inter1_u,
5706- &diffwtd_mask_y,
5720+ mask_y,
57075721 side,
57085722 chroma_side,
57095723 chroma_side,
@@ -5743,11 +5757,11 @@ fn decode_inter_block(
57435757 &mut inter1_v,
57445758 );
57455759 let mut pred_v = vec![0u8; chroma_side * chroma_side];
5746- if diffwtd_mask_type.is_some() {
5760+ if let Some(mask_y) = mask_y {
57475761 mc::blend_masked_compound(
57485762 &inter0_v,
57495763 &inter1_v,
5750- &diffwtd_mask_y,
5764+ mask_y,
57515765 side,
57525766 chroma_side,
57535767 chroma_side,
@@ -6823,27 +6837,30 @@ fn decode_inter_block8(
68236837 } else {
68246838 0
68256839 };
6826- // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment.
6840+ // lane-maskcomp r2 / lane-wedge r3: see the 16x16/32x32
6841+ // leaf's own comment.
68276842 let mut diffwtd_mask_type: Option<u8> = None;
6843+ let mut wedge_mask: Option<&'static [u8]> = None;
68286844 if comp_group_idx == 1 {
68296845 // lane-maskcomp r1: see the 16x16 leaf's own comment
68306846 // above -- SIDE==8 here, `wedge_bsize` index 3
68316847 // (BLOCK_8X8, `wedge_types > 0`).
68326848 let compound_type = dec.symbol(&mut cdfs.compound_type[3]);
68336849 if compound_type == 0 {
6834- // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
6835- let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
6836- let _wedge_sign = dec.literal(1);
6837- MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6838- return Err(unsupported(
6839- "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, \
6840- COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\
6841- wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \
6842- not ported (lane-maskcomp r2 scope: DIFFWTD only)",
6843- ));
6850+ // COMPOUND_WEDGE: lane-wedge r3, see the 16x16/32x32
6851+ // leaf's own comment.
6852+ let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
6853+ let wedge_sign = dec.literal(1);
6854+ WEDGE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6855+ wedge_mask = Some(
6856+ crate::wedge::wedge_masks()
6857+ .codebook(SIDE)
6858+ .mask(wedge_sign as usize, wedge_index as usize),
6859+ );
6860+ } else {
6861+ let mask_type = dec.literal(1);
6862+ diffwtd_mask_type = Some(mask_type as u8);
68446863 }
6845- let mask_type = dec.literal(1);
6846- diffwtd_mask_type = Some(mask_type as u8);
68476864 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
68486865 }
68496866 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
@@ -6952,18 +6969,16 @@ fn decode_inter_block8(
69526969 );
69536970 let mut pred_y = vec![0u8; SIDE * SIDE];
69546971 let mut diffwtd_mask_y = Vec::new();
6955- if let Some(mask_type) = diffwtd_mask_type {
6972+ let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
69566973 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
69576974 mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y);
6975+ Some(diffwtd_mask_y.as_slice())
6976+ } else {
6977+ wedge_mask
6978+ };
6979+ if let Some(mask_y) = mask_y {
69586980 mc::blend_masked_compound(
6959- &inter0_y,
6960- &inter1_y,
6961- &diffwtd_mask_y,
6962- SIDE,
6963- SIDE,
6964- SIDE,
6965- false,
6966- &mut pred_y,
6981+ &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, false, &mut pred_y,
69676982 );
69686983 } else {
69696984 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y);
@@ -6998,11 +7013,11 @@ fn decode_inter_block8(
69987013 &mut inter1_u,
69997014 );
70007015 let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
7001- if diffwtd_mask_type.is_some() {
7016+ if let Some(mask_y) = mask_y {
70027017 mc::blend_masked_compound(
70037018 &inter0_u,
70047019 &inter1_u,
7005- &diffwtd_mask_y,
7020+ mask_y,
70067021 SIDE,
70077022 CHROMA_SIDE,
70087023 CHROMA_SIDE,
@@ -7042,11 +7057,11 @@ fn decode_inter_block8(
70427057 &mut inter1_v,
70437058 );
70447059 let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
7045- if diffwtd_mask_type.is_some() {
7060+ if let Some(mask_y) = mask_y {
70467061 mc::blend_masked_compound(
70477062 &inter0_v,
70487063 &inter1_v,
7049- &diffwtd_mask_y,
7064+ mask_y,
70507065 SIDE,
70517066 CHROMA_SIDE,
70527067 CHROMA_SIDE,
crates/ec-av1/src/stream.rsmodified+60 -34
@@ -3847,14 +3847,18 @@ mod tests {
38473847 );
38483848 }
38493849
3850- /// lane-maskcomp r2: `--enable-masked-comp=1 --enable-dist-wtd-comp=1`
3851- /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/
3852- /// `mask_type` entropy-exact AND build the real DIFFWTD blend --
3853- /// `masked_compound_hits() > 0` is now a hard assert, and a
3854- /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own
3855- /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope:
3856- /// wedge mask codebook not ported, charter's mergeable-partial
3857- /// fallback) -- counted separately, never asserted against.
3850+ /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
3851+ /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
3852+ /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --
3853+ /// `masked_compound_hits() > 0` is a hard assert and BOTH
3854+ /// `COMPOUND_DIFFWTD` and `COMPOUND_WEDGE` refusals are now FORBIDDEN
3855+ /// (matches interintra's own gate). r3: `--enable-dist-wtd-comp=0`
3856+ /// (forces the masked choice toward wedge when comp_group_idx==1) plus
3857+ /// a hard-diagonal-edge `geq` source (wedge's OBLIQUE directions favor
3858+ /// a real diagonal edge over the r2 gradients content) to fire
3859+ /// COMPOUND_WEDGE live; `wedge_hits()` is soft-skipped (not hard
3860+ /// asserted) on a zero-hit run -- the recipe search is not proven to
3861+ /// converge every run, see charter's "if no recipe fires" fallback.
38583862 #[test]
38593863 fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() {
38603864 const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact";
@@ -3869,7 +3873,6 @@ mod tests {
38693873 }
38703874 let (width, height, frame_count) = (64usize, 64usize, 24usize);
38713875 let mut named_refusals = 0u32;
3872- let mut masked_refusals = 0u32;
38733876 let mut matched = 0u32;
38743877 let n_attempts: u32 = std::env::var("EC_MASKCOMP_GATE_ATTEMPTS")
38753878 .ok()
@@ -3878,8 +3881,15 @@ mod tests {
38783881 for attempt in 0..n_attempts {
38793882 let seed = 42 + attempt;
38803883 let duration = frame_count as f64 / 25.0;
3881- let source =
3882- format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25");
3884+ // lane-wedge r3: a hard diagonal edge (not a smooth gradient)
3885+ // is the content wedge's OBLIQUE master masks are shaped for --
3886+ // `mandelbrot`'s pan position varies the edge angle/position
3887+ // across attempts the way the r2 gradients seed did.
3888+ let source = format!(
3889+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
3890+ sx = -0.6 + 0.005 * (attempt as f64),
3891+ sy = -0.4 + 0.005 * (attempt as f64)
3892+ );
38833893 let y4m = Command::new("ffmpeg")
38843894 .args([
38853895 "-v",
@@ -3888,6 +3898,8 @@ mod tests {
38883898 "lavfi",
38893899 "-i",
38903900 &source,
3901+ "-t",
3902+ &duration.to_string(),
38913903 "-pix_fmt",
38923904 "yuv420p",
38933905 "-f",
@@ -3918,10 +3930,18 @@ mod tests {
39183930 "--enable-fwd-kf=0",
39193931 "--enable-order-hint=1",
39203932 "--enable-warped-motion=1",
3933+ // r3: mandelbrot's pan/zoom triggers aomenc's single-ref
3934+ // GLOBALMV global-motion search (a capability distinct from
3935+ // and outside this lane's scope) -- off, matching this
3936+ // gate's own goal of exercising masked compound, not GM.
3937+ "--enable-global-motion=0",
39213938 "--enable-obmc=1",
39223939 "--tune-content=default",
39233940 "--enable-masked-comp=1",
3924- "--enable-dist-wtd-comp=1",
3941+ // r3: force the masked choice toward wedge (r2 always set
3942+ // this =1; distance-weighted compound competes with the
3943+ // wedge/diffwtd choice for the same comp_group_idx==1 slot).
3944+ "--enable-dist-wtd-comp=0",
39253945 "--enable-interintra-comp=1",
39263946 "--enable-onesided-comp=0",
39273947 "--enable-interintra-wedge=0",
@@ -3979,21 +3999,17 @@ mod tests {
39793999 !msg.contains("warp"),
39804000 "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}"
39814001 );
3982- if msg.contains("masked COMPOUND_REFERENCE") {
3983- assert!(
3984- msg.contains("COMPOUND_WEDGE"),
3985- "{NAME} refused a non-wedge masked-compound block (seed {seed}) \
3986- -- DIFFWTD blend is ported, this refusal is forbidden: {msg}"
3987- );
3988- masked_refusals += 1;
3989- } else {
3990- assert!(
3991- !msg.contains("interintra"),
3992- "{NAME} refused on interintra (seed {seed}) -- non-wedge \
3993- interintra is ported: {msg}"
3994- );
3995- named_refusals += 1;
3996- }
4002+ assert!(
4003+ !msg.contains("masked COMPOUND_REFERENCE"),
4004+ "{NAME} refused a masked-compound block (seed {seed}) -- both DIFFWTD \
4005+ and WEDGE blends are ported, this refusal is forbidden: {msg}"
4006+ );
4007+ assert!(
4008+ !msg.contains("interintra"),
4009+ "{NAME} refused on interintra (seed {seed}) -- non-wedge \
4010+ interintra is ported: {msg}"
4011+ );
4012+ named_refusals += 1;
39974013 eprintln!("seed {seed} refusal: {msg}");
39984014 if std::env::var_os("EC_AV1_GATE_DUMP").is_some() {
39994015 // r1's self-pin is armed via EC_AV1_GATE_DUMP=<path>
@@ -4034,15 +4050,25 @@ mod tests {
40344050 // soft-skipped -- hard assert, matching the interintra gate.
40354051 assert!(
40364052 crate::decode::masked_compound_hits() > 0,
4037- "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \
4038- {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \
4039- proved nothing this run"
4053+ "{NAME}: zero masked-compound blocks fired ({matched} matches, {named_refusals} \
4054+ other refusals out of {n_attempts}) -- gate proved nothing this run"
40404055 );
4056+ // r3: wedge_hits() is soft-skipped, not hard-asserted -- the recipe
4057+ // search (dist-wtd-comp=0 + diagonal mandelbrot content) is not
4058+ // proven to fire wedge on every run; charter's fallback is to land
4059+ // the checksum-verified codebook + blend with this soft path.
4060+ if crate::decode::wedge_hits() == 0 {
4061+ eprintln!(
4062+ "{NAME}: WARNING wedge_hits()==0 this run -- COMPOUND_WEDGE never fired \
4063+ ({matched} matches, {named_refusals} refusals out of {n_attempts}); codebook \
4064+ is checksum-verified but unexercised live this run"
4065+ );
4066+ }
40414067 eprintln!(
4042- "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \
4043- COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \
4044- out of {n_attempts}, masked_compound_hits={}",
4045- crate::decode::masked_compound_hits()
4068+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
4069+ out of {n_attempts}, masked_compound_hits={} wedge_hits={}",
4070+ crate::decode::masked_compound_hits(),
4071+ crate::decode::wedge_hits()
40464072 );
40474073 }
40484074
lanes/wedge_dumpadded+0 -0

Binary file changed