forge
Explore
Log in

Don't you dare go Hollow

doc(av1): the frame-table price becomes the default on non-screen frames

Browse files at this commit

0b17e82345ac8953281169bdbe0a8a45a7898252Ahmet Kaan GümüşParent: 7639e56
Both BD tables measured on one build (mode 0 vs mode 2) go in the doc comment,
including the one regression -- the 2160p film at the downscaled 640x384 gate.
The screen capture is byte-identical to base in both gates, which is what a
per-frame gate should be. The census on the real clips says why screen needs
the gate: real tables flatten the inter luma rows and leave the chroma and
all-zero rows exactly where they were, so the search's tradeoff between them
is skewed rather than corrected. The all-zero row's own cause (the pricer's
skip_ctx 0) is recorded at coeff_bits with the numbers and what closing it
would need.
crates/ec-av1/src/tile.rsmodified+62 -13
@@ -3966,6 +3966,21 @@ pub(crate) fn luma_32_coeff_bits(grid: &[i32]) -> f64 {
3966 /// the four points of the BD ladder were priced against another quantizer's3966 /// the four points of the BD ladder were priced against another quantizer's
3967 /// tables), and against the contexts a block whose neighbours coded nothing3967 /// tables), and against the contexts a block whose neighbours coded nothing
3968 /// reads.3968 /// reads.
3969+///
3970+/// That last assumption -- `skip_ctx` 0, `sign_ctx` 0 -- is the largest
3971+/// remaining row of the census and lane-av1price2 did NOT close it: every
3972+/// all-zero block is priced at the `txb_skip` cost of a block whose
3973+/// neighbours coded nothing, which is the most expensive context there is, so
3974+/// an all-zero chroma block is UNDER-priced by 41-81% on film and 51-73% on
3975+/// the screen capture (`pricer_error_census_on_clips`), and an all-zero
3976+/// Luma4 is over-priced by 400%+. Arming the frame's real tables does not
3977+/// touch those rows (Chroma8 nz=0 reads -73.0% in both modes). Pricing them
3978+/// right needs the real neighbour context, which needs something the search
3979+/// does not have: a per-plane non-zero context map committed in coding order.
3980+/// The search ranks partition TREES, so it prices candidates whose neighbours
3981+/// are not yet decided; the map would have to be built per trial, not per
3982+/// block. Deferred with the numbers above rather than approximated by a
3983+/// fitted constant.
3969 pub(crate) fn coeff_bits(grid: &[i32], set: TxbSet, q_ctx: usize) -> f64 {3984 pub(crate) fn coeff_bits(grid: &[i32], set: TxbSet, q_ctx: usize) -> f64 {
3970 /// Built once per size: the search prices thirteen modes for every block,3985 /// Built once per size: the search prices thirteen modes for every block,
3971 /// and the scan is the same table every time.3986 /// and the scan is the same table every time.
@@ -4045,27 +4060,61 @@ thread_local! {
4045 4060
4046 /// Arms the tables [`coeff_bits`] prices against on this thread: the state4061 /// Arms the tables [`coeff_bits`] prices against on this thread: the state
4047 /// this frame's tile writer starts from. `None` goes back to the per-q-context4062 /// this frame's tile writer starts from. `None` goes back to the per-q-context
4048-/// defaults (a key frame, whose writer really does start there).4063+/// defaults (a key frame, whose writer really does start there), and so does
4064+/// any frame the screen detector said yes to (`screen`).
4065+///
4066+/// ON by default for non-screen frames since lane-av1price2;
4067+/// `EC_AV1_PRICE_FRAME_CDFS` selects 0 = never (the pre-lane behaviour),
4068+/// 1 = always, unset/2 = the screen-gated default.
4049 ///4069 ///
4050-/// OFF by default (`EC_AV1_PRICE_FRAME_CDFS=1`). It is the more accurate4070+/// Pricing against the frame's REAL starting tables is the more accurate
4051 /// estimate by measurement -- the pricer census4071 /// estimate by measurement -- the pricer census
4052 /// (`pricer_error_census_by_block_class`) goes from +7.6% to +4.8% over every4072 /// (`pricer_error_census_by_block_class`) goes from +7.6% to +4.8% over every
4053 /// transform block, and the one- and two-coefficient inter blocks the search4073 /// transform block, and the one- and two-coefficient inter blocks the search
4054-/// lives on from +31.4%/+22.3% to +3.1%/+3.6% -- but the accuracy does not4074+/// lives on from +31.4%/+22.3% to +3.1%/+3.6% -- but the accuracy only
4055-/// convert into ladder bytes on every clip: on the 640x384 gate it scores4075+/// converts into ladder bytes on camera content. Measured on ONE build
4056-/// +78.8/+95.1/+54.5 vs libaom and +36.1/+56.4/+1.4 vs rav1e against the4076+/// (lane-av1price2, mode 0 vs mode 2), BD-rate vs libaom / vs rav1e:
4057-/// +79.9/+94.6/+54.5 and +37.3/+55.7/+1.1 the defaults score (film 1080p4077+///
4058-/// down 1.1, film 2160p up 0.5, screen flat), and on the native crops4078+/// | clip | 640x384 base | 640x384 gated | native base | native gated |
4059-/// +18.0/+47.3/+60.7 and +0.7/+19.2/-7.3 against +18.9/+48.2/+59.3 and4079+/// |---|---|---|---|---|
4060-/// +1.5/+19.8/-10.0 (both film clips down against both references, screen up4080+/// | film 1080p | +79.9 / +37.3 | +78.8 / +36.1 | +18.7 / +1.4 | +18.0 / +0.7 |
4061-/// 1.4/2.7). Two clips better, one worse: it does not meet this lane's keep4081+/// | film 2160p | +94.6 / +55.7 | +95.1 / +56.4 | +48.1 / +19.8 | +47.3 / +19.2 |
4062-/// rule, so it ships as a knob rather than as the default.4082+/// | screen | +54.5 / +1.1 | +54.5 / +1.1 | +59.4 / -10.0 | +59.4 / -10.0 |
4083+///
4084+/// The screen rows are not merely close, they are byte-identical (the ladders
4085+/// print 8832/13507/18772/24754 and 39312/52829/70719/92134 in both modes):
4086+/// the gate is per frame and the detector fires on 48 of 48 screen frames, so
4087+/// no screen frame is ever armed with anything but the defaults. At native
4088+/// resolution -- the resolution his library is in -- both films come down
4089+/// against both references and the screen capture is flat, which is this
4090+/// lane's keep rule. At the downscaled 640x384 gate the 2160p film goes the
4091+/// other way (+0.5/+0.7) while the 1080p one comes down further (-1.1/-1.2);
4092+/// the downscale is the same recipe that exaggerated the frame pyramid's loss
4093+/// sixfold, so the native table decides and the 640x384 2160p regression is
4094+/// recorded here rather than argued away.
4095+///
4096+/// Why the screen capture needs the gate at all is in the census
4097+/// (`pricer_error_census_on_clips`, 6 frames of each clip at 640x384, q=100).
4098+/// Real tables take the film clip's total pricer error from +7.8% to +5.3%
4099+/// and flatten its inter classes outright (Luma8Inter/Luma16Inter/Luma32Inter
4100+/// 1-coefficient rows from +11.7%/+17.4%/+24.9% to -0.3%/-5.5%/+8.8%). On the
4101+/// screen capture the total only moves +12.8% -> +10.3%, because the classes
4102+/// that dominate a screen frame are not the ones the tables fix: its chroma
4103+/// stays over-priced (Chroma8 nz=1 +32.2% -> +31.8%, nz=2 +26.2% -> +26.2%,
4104+/// unmoved) and its all-zero blocks stay hugely UNDER-priced (Chroma8 nz=0
4105+/// -73.0% -> -73.0%, Luma4 nz=0 +464% -> +467% -- both a pricer that assumes
4106+/// `skip_ctx` 0, not a table set). So on screen the change makes the inter
4107+/// luma price accurate while leaving the bigger chroma and all-zero errors
4108+/// exactly where they were, which SKEWS the search's tradeoffs between them
4109+/// instead of correcting them -- and the bytes get worse. The fix for that
4110+/// row is the neighbour skip context, not another table set (see
4111+/// [`coeff_bits`]).
4063 pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {4112 pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
4064 static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();4113 static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
4065 let mode = *MODE.get_or_init(|| match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {4114 let mode = *MODE.get_or_init(|| match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {
4115+ Ok("0") => 0,
4066 Ok("1") => 1,4116 Ok("1") => 1,
4067- Ok("2") => 2,4117+ _ => 2,
4068- _ => 0,
4069 });4118 });
4070 let on = match mode {4119 let on = match mode {
4071 0 => false,4120 0 => false,