lane/av1422rect4dead: close decode_rect4_16_intrabc else arm at ss (1,0)
Browse files at this commit2cfb795a7a7c339cccd3076be8c8083853b6293cParent: e4011141 changed file +192 -0
- crates/ec-av1/src/decode.rs +192 -0
crates/ec-av1/src/decode.rsmodified+192 -0
| @@ -18500,6 +18500,26 @@ fn decode_rect4_16_intrabc( | ||
| 18500 | 18500 | let (cw, ch) = if own_chroma { |
| 18501 | 18501 | (bw >> ss_x(fctx), bh >> ss_y(fctx)) |
| 18502 | 18502 | } else { |
| 18503 | + // lane/av1422rect4dead: this arm is the 4:2:0 PAIR geometry, and at ss | |
| 18504 | + // (1, 0) it cannot run. The sole caller is `decode_rect4_16_strip`, | |
| 18505 | + // reached only through the two 16x16-level 1:4 arms; both sit under | |
| 18506 | + // `refuse_invalid_subsize((16, 16), part16)`, and at ss (1, 0) that | |
| 18507 | + // guard refuses exactly the shape that would land here: | |
| 18508 | + // `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`, | |
| 18509 | + // which is in `PLANE_BLOCK_INVALID_422`. The surviving 16x4 HORZ_4 | |
| 18510 | + // strip takes `own422` above, not this arm. At ss (1, 1) the arm is | |
| 18511 | + // live and correct (the pair IS the geometry), and at ss (0, 0) | |
| 18512 | + // `own444` already won, so this assert never fires there. The | |
| 18513 | + // assertion is the closure the repo rule asks for; the census test | |
| 18514 | + // `decode_rect4_16_intrabc_else_arm_stays_closed_at_422` below reds if | |
| 18515 | + // either this assert or its guard chain is removed. | |
| 18516 | + assert!( | |
| 18517 | + !(ss_x(fctx) == 1 && ss_y(fctx) == 0), | |
| 18518 | + "decode_rect4_16_intrabc else arm entered at ss (1, 0) with a 4x16 \ | |
| 18519 | + VERT_4 strip: (4, 16) is BLOCK_INVALID at 4:2:2 and the 16x16-level \ | |
| 18520 | + refuse_invalid_subsize above both callers must have refused this \ | |
| 18521 | + before the dispatch -- the closure is gone" | |
| 18522 | + ); | |
| 18503 | 18523 | (pw / 2, ph / 2) |
| 18504 | 18524 | }; |
| 18505 | 18525 | let pair_mi = if has_chroma { |
| @@ -58728,6 +58748,178 @@ mod tests { | ||
| 58728 | 58748 | } |
| 58729 | 58749 | } |
| 58730 | 58750 | |
| 58751 | + /// lane/av1422rect4dead: the `(pw / 2, ph / 2)` / `MI / 2` origin `else` | |
| 58752 | + /// arm of [`decode_rect4_16_intrabc`] is the 4:2:0 PAIR geometry. It is | |
| 58753 | + /// still LIVE at ss (1, 1) -- a 1:4 strip's chroma lies inside its | |
| 58754 | + /// 4:2:0 pair there -- so the arm is not deleted; it is CLOSED at ss | |
| 58755 | + /// (1, 0), where it would run on a 4x16 VERT_4 strip whose chroma plane | |
| 58756 | + /// block is BLOCK_INVALID, and where libaom's own | |
| 58757 | + /// `is_chroma_reference` (av1_common_int.h:1454, `|| !subsampling_y`) | |
| 58758 | + /// makes every strip its own chroma reference anyway (the `own422` arm | |
| 58759 | + /// handles that). The proof: the sole caller `decode_rect4_16_strip` is | |
| 58760 | + /// reached only via the two 16x16-level 1:4 arms, each under | |
| 58761 | + /// `refuse_invalid_subsize((16, 16), part16)` -- at ss (1, 0) that guard | |
| 58762 | + /// refuses `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)` | |
| 58763 | + /// (in `PLANE_BLOCK_INVALID_422`), and the surviving HORZ_4 16x4 strip | |
| 58764 | + /// takes `own422`. This test re-derives that chain from the file so it | |
| 58765 | + /// REDS when any half stops holding: deleting the in-arm assertion, a | |
| 58766 | + /// caller moving under a level whose guard does not refuse (4, 16) at | |
| 58767 | + /// ss (1, 0), or the `(pw / 2, ph / 2)` form drifting. 4:2:0 and 4:4:4 | |
| 58768 | + /// behaviour are unchanged: the gate runs only the file scan and the | |
| 58769 | + /// closed cell's arithmetic, no decode. | |
| 58770 | + #[test] | |
| 58771 | + fn decode_rect4_16_intrabc_else_arm_stays_closed_at_422() { | |
| 58772 | + let src = include_str!("decode.rs"); | |
| 58773 | + let decode_body = match src.find("\n#[cfg(test)]\nmod tests {") { | |
| 58774 | + Some(i) => &src[..i], | |
| 58775 | + None => src, | |
| 58776 | + }; | |
| 58777 | + | |
| 58778 | + // (a) The closure assertion must exist INSIDE the function, in the | |
| 58779 | + // `else` arm of the `(cw, ch)` select, naming the shape and the | |
| 58780 | + // subsampling. Deleting it -- or re-adding the bare halving without | |
| 58781 | + // it -- reds here. | |
| 58782 | + let fstart = decode_body | |
| 58783 | + .find("\nfn decode_rect4_16_intrabc(") | |
| 58784 | + .expect("decode_rect4_16_intrabc is gone -- this gate guards its else arm"); | |
| 58785 | + let fend = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | |
| 58786 | + .iter() | |
| 58787 | + .filter_map(|pat| decode_body[fstart + 1..].find(pat).map(|i| fstart + 1 + i)) | |
| 58788 | + .min() | |
| 58789 | + .unwrap_or(decode_body.len()); | |
| 58790 | + let body = &decode_body[fstart..fend]; | |
| 58791 | + let else_arm = body | |
| 58792 | + .find(" let (cw, ch) = if own_chroma {") | |
| 58793 | + .expect("the (cw, ch) select moved out of decode_rect4_16_intrabc"); | |
| 58794 | + let closure = &body[else_arm..]; | |
| 58795 | + assert!( | |
| 58796 | + closure.contains("assert!(") && closure.contains("ss_x(fctx) == 1 && ss_y(fctx) == 0"), | |
| 58797 | + "the decode_rect4_16_intrabc else arm's ss (1, 0) closure assertion is \ | |
| 58798 | + GONE -- the 4:2:0 pair geometry is unreachable at ss (1, 0) only while \ | |
| 58799 | + that assert (and the guards below) stand; re-add it" | |
| 58800 | + ); | |
| 58801 | + | |
| 58802 | + // (b) The sole-caller chain, re-derived from the file: exactly one | |
| 58803 | + // call to `decode_rect4_16_intrabc(` outside its own definition, in | |
| 58804 | + // `decode_rect4_16_strip`; exactly two calls to | |
| 58805 | + // `decode_rect4_16_strip(` from the two 1:4 routes. | |
| 58806 | + let code_lines: String = decode_body | |
| 58807 | + .lines() | |
| 58808 | + .filter(|l| !l.trim_start().starts_with("//")) | |
| 58809 | + .collect::<Vec<_>>() | |
| 58810 | + .join("\n"); | |
| 58811 | + let count_calls = |name: &str| -> usize { | |
| 58812 | + code_lines.matches(&format!("{name}(")).count() | |
| 58813 | + - usize::from(code_lines.contains(&format!("fn {name}("))) | |
| 58814 | + }; | |
| 58815 | + assert_eq!( | |
| 58816 | + count_calls("decode_rect4_16_intrabc"), | |
| 58817 | + 1, | |
| 58818 | + "decode_rect4_16_intrabc gained a caller -- re-derive whether the new route \ | |
| 58819 | + sits under a guard that refuses (4, 16) at ss (1, 0) before this gate \ | |
| 58820 | + stays green" | |
| 58821 | + ); | |
| 58822 | + assert_eq!( | |
| 58823 | + count_calls("decode_rect4_16_strip"), | |
| 58824 | + 2, | |
| 58825 | + "decode_rect4_16_strip's caller set moved -- both routes must be \ | |
| 58826 | + 16x16-level 1:4 arms under a (16, 16) guard that refuses (4, 16) at \ | |
| 58827 | + ss (1, 0)" | |
| 58828 | + ); | |
| 58829 | + | |
| 58830 | + // (c) Both routes sit under a `refuse_invalid_subsize((16, 16), ...)`: | |
| 58831 | + // the key-frame arm's guard ordered above the arm test, the inter | |
| 58832 | + // arm's guard in the inter decoder above its own 1:4 test. Scoped to | |
| 58833 | + // the enclosing function so the other decoder's guard cannot stand in | |
| 58834 | + // (the r2 class this file already fixed once). | |
| 58835 | + let fn_scope = |at: usize| -> std::ops::Range<usize> { | |
| 58836 | + let head = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | |
| 58837 | + .iter() | |
| 58838 | + .filter_map(|pat| decode_body[..at].rfind(pat)) | |
| 58839 | + .max() | |
| 58840 | + .unwrap_or(0); | |
| 58841 | + let tail = ["\nfn ", "\npub fn ", "\npub(crate) fn "] | |
| 58842 | + .iter() | |
| 58843 | + .filter_map(|pat| decode_body[at..].find(pat).map(|i| at + i)) | |
| 58844 | + .min() | |
| 58845 | + .unwrap_or(decode_body.len()); | |
| 58846 | + head..tail | |
| 58847 | + }; | |
| 58848 | + let kf_test = decode_body | |
| 58849 | + .find("if part16 == PARTITION_HORZ_4") | |
| 58850 | + .expect("the key-frame 16-level 1:4 arm test is gone"); | |
| 58851 | + let kf_scope = fn_scope(kf_test); | |
| 58852 | + let kf_guard = decode_body[kf_scope.clone()] | |
| 58853 | + .find("refuse_invalid_subsize((16, 16)") | |
| 58854 | + .map(|i| kf_scope.start + i) | |
| 58855 | + .unwrap_or_else(|| { | |
| 58856 | + panic!( | |
| 58857 | + "the key-frame 16-level 1:4 arm has NO \ | |
| 58858 | + refuse_invalid_subsize((16, 16)) above it in its own \ | |
| 58859 | + function -- the VERT_4 (4, 16) refusal that closed \ | |
| 58860 | + decode_rect4_16_intrabc's else arm at ss (1, 0) is gone" | |
| 58861 | + ) | |
| 58862 | + }); | |
| 58863 | + assert!( | |
| 58864 | + kf_guard < kf_test, | |
| 58865 | + "the key-frame (16, 16) guard sits below the 1:4 arm test -- it can never \ | |
| 58866 | + observe the VERT_4 symbol that must be refused before \ | |
| 58867 | + decode_rect4_16_intrabc's else arm can run at ss (1, 0)" | |
| 58868 | + ); | |
| 58869 | + let inter_writer = decode_body | |
| 58870 | + .find("let horz = part16 == PARTITION_HORZ_4;") | |
| 58871 | + .expect("the inter 16-level 1:4 arm is gone"); | |
| 58872 | + let inter_scope = fn_scope(inter_writer); | |
| 58873 | + let inter_guard = decode_body[inter_scope.clone()] | |
| 58874 | + .find("refuse_invalid_subsize((16, 16)") | |
| 58875 | + .map(|i| inter_scope.start + i) | |
| 58876 | + .unwrap_or_else(|| { | |
| 58877 | + panic!( | |
| 58878 | + "the inter-frame 16-level 1:4 arm has NO \ | |
| 58879 | + refuse_invalid_subsize((16, 16)) in its function -- the VERT_4 \ | |
| 58880 | + (4, 16) refusal that closed decode_rect4_16_intrabc's else arm \ | |
| 58881 | + at ss (1, 0) is gone" | |
| 58882 | + ) | |
| 58883 | + }); | |
| 58884 | + assert!( | |
| 58885 | + inter_guard < inter_writer, | |
| 58886 | + "the inter (16, 16) guard sits below the 1:4 arm test -- it can never \ | |
| 58887 | + observe the VERT_4 symbol that must be refused before \ | |
| 58888 | + decode_rect4_16_intrabc's else arm can run at ss (1, 0)" | |
| 58889 | + ); | |
| 58890 | + | |
| 58891 | + // (d) The shape/subsampling cells the closure is written against, | |
| 58892 | + // re-executed: (4, 16) must still be BLOCK_INVALID at ss (1, 0) while | |
| 58893 | + // (16, 4) stays codable there, and at ss (1, 1) BOTH are codable -- | |
| 58894 | + // which is what keeps the arm live at 4:2:0 and the assertion inert | |
| 58895 | + // there. At ss (0, 0) everything is codable, so `own444` (and the | |
| 58896 | + // assertion) never see the else arm. | |
| 58897 | + assert!( | |
| 58898 | + !chroma_plane_block_codable(4, 16, 1, 0), | |
| 58899 | + "(4, 16) left PLANE_BLOCK_INVALID_422 -- the else arm is now REACHABLE at \ | |
| 58900 | + ss (1, 0) with the halved pair geometry, which is a real defect, not a \ | |
| 58901 | + closure: re-derive the whole chain, then fix the halving instead of the \ | |
| 58902 | + assert" | |
| 58903 | + ); | |
| 58904 | + assert!( | |
| 58905 | + chroma_plane_block_codable(16, 4, 1, 0), | |
| 58906 | + "(16, 4) became BLOCK_INVALID at ss (1, 0) -- the surviving HORZ_4 strip \ | |
| 58907 | + takes own422, and the closure assert would fire on a legal shape; \ | |
| 58908 | + re-derive" | |
| 58909 | + ); | |
| 58910 | + assert!( | |
| 58911 | + chroma_plane_block_codable(4, 16, 1, 1) && chroma_plane_block_codable(16, 4, 1, 1), | |
| 58912 | + "a 1:4 strip's plane block moved at ss (1, 1) -- the else arm is LIVE there \ | |
| 58913 | + and the pair geometry is what decodes it; the assertion must stay inert at \ | |
| 58914 | + 4:2:0" | |
| 58915 | + ); | |
| 58916 | + assert!( | |
| 58917 | + chroma_plane_block_codable(4, 16, 0, 0) && chroma_plane_block_codable(16, 4, 0, 0), | |
| 58918 | + "a 1:4 strip's plane block became invalid at ss (0, 0) -- the assertion sits \ | |
| 58919 | + after the own444 arm and must never fire at 4:4:4; re-derive" | |
| 58920 | + ); | |
| 58921 | + } | |
| 58922 | + | |
| 58731 | 58923 | /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's |
| 58732 | 58924 | /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and |
| 58733 | 58925 | /// reports "no leaf there" as `None` so the caller can fall back to the |