Single-ref mvstack scan votes a compound neighbour's second slot
Browse files at this commit2b9615f044172bd80b6242f1466fff409db8a4e9Parent: d0ddce6- fix
- single-ref mvstack scan votes a compound neighbour's second slot
4 changed files +182 -35
- crates/ec-av1/src/decode.rs +114 -4
- crates/ec-av1/src/msac.rs +9 -1
- crates/ec-av1/src/mvstack.rs +56 -29
- crates/ec-av1/src/stream.rs +3 -1
crates/ec-av1/src/decode.rsmodified+114 -4
| @@ -521,6 +521,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) -> | ||
| 521 | 521 | (TxClass::TwoD, _) | (_, None) => coding.eob_pt, |
| 522 | 522 | (_, Some(class1)) => class1, |
| 523 | 523 | }; |
| 524 | + crate::msac::CURRENT_OP.with(|c| c.set("L524")); | |
| 524 | 525 | let group = dec.symbol(eob_pt) + 1; |
| 525 | 526 | if trace { |
| 526 | 527 | eprintln!("TRACE eob_pt value={group}"); |
| @@ -528,6 +529,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) -> | ||
| 528 | 529 | let bits = OFFSET_BITS[group]; |
| 529 | 530 | let mut offset = 0u32; |
| 530 | 531 | if bits > 0 { |
| 532 | + crate::msac::CURRENT_OP.with(|c| c.set("L531")); | |
| 531 | 533 | let top = dec.symbol(&mut coding.eob_extra[group - 3]) as u32; |
| 532 | 534 | if trace { |
| 533 | 535 | eprintln!("TRACE eob_extra ctx={} value={top}", group - 3); |
| @@ -590,6 +592,7 @@ fn read_coeffs( | ||
| 590 | 592 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 591 | 593 | let side = coding.side; |
| 592 | 594 | let mut grid = vec![0i32; side * side]; |
| 595 | + crate::msac::CURRENT_OP.with(|c| c.set("L593")); | |
| 593 | 596 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 594 | 597 | if trace { |
| 595 | 598 | eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32); |
| @@ -603,6 +606,7 @@ fn read_coeffs( | ||
| 603 | 606 | // `TX_SET_INTRA_1`, 5 (6 slots) the reduced `TX_SET_INTRA_2` (the |
| 604 | 607 | // inter sets we read share set 2's symbol order). |
| 605 | 608 | let set1 = tx_type_cdf.len() == 8; |
| 609 | + crate::msac::CURRENT_OP.with(|c| c.set("L606")); | |
| 606 | 610 | let t = dec.symbol(tx_type_cdf); |
| 607 | 611 | if trace { |
| 608 | 612 | eprintln!("TRACE tx_type value={t} set1={set1}"); |
| @@ -636,6 +640,7 @@ fn read_coeffs( | ||
| 636 | 640 | let (row, col) = (pos / side, pos % side); |
| 637 | 641 | let level = if scan_idx == eob - 1 { |
| 638 | 642 | let ctx = eob_coeff_ctx(scan_idx, side * side); |
| 643 | + crate::msac::CURRENT_OP.with(|c| c.set("L639")); | |
| 639 | 644 | let v = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; |
| 640 | 645 | if trace { |
| 641 | 646 | eprintln!( |
| @@ -645,6 +650,7 @@ fn read_coeffs( | ||
| 645 | 650 | v |
| 646 | 651 | } else { |
| 647 | 652 | let ctx = base_ctx(&levels, side, row, col, class); |
| 653 | + crate::msac::CURRENT_OP.with(|c| c.set("L648")); | |
| 648 | 654 | let v = dec.symbol(&mut coding.base[ctx]) as i32; |
| 649 | 655 | if trace { |
| 650 | 656 | eprintln!( |
| @@ -658,6 +664,7 @@ fn read_coeffs( | ||
| 658 | 664 | let mut level = level; |
| 659 | 665 | let mut sent = 0; |
| 660 | 666 | loop { |
| 667 | + crate::msac::CURRENT_OP.with(|c| c.set("L661")); | |
| 661 | 668 | let k = dec.symbol(&mut coding.br[ctx]) as i32; |
| 662 | 669 | if trace { |
| 663 | 670 | eprintln!( |
| @@ -683,6 +690,7 @@ fn read_coeffs( | ||
| 683 | 690 | continue; |
| 684 | 691 | } |
| 685 | 692 | let negative = if pos == 0 { |
| 693 | + crate::msac::CURRENT_OP.with(|c| c.set("L686")); | |
| 686 | 694 | let v = dec.symbol(&mut coding.dc_sign[sign_ctx]) == 1; |
| 687 | 695 | if trace { |
| 688 | 696 | eprintln!("TRACE dc_sign ctx={sign_ctx} value={}", v as i32); |
| @@ -1257,6 +1265,7 @@ fn filter_intra_size_class(side: usize) -> Option<usize> { | ||
| 1257 | 1265 | /// delta [`crate::intra::predict`] wants; bumps [`ANGLE_DELTA_HITS`] whenever |
| 1258 | 1266 | /// it lands away from zero, for gate tests to prove a real stream fired one. |
| 1259 | 1267 | fn read_angle_delta(dec: &mut SymbolDecoder, cdf: &mut [u16]) -> i32 { |
| 1268 | + crate::msac::CURRENT_OP.with(|c| c.set("L1260")); | |
| 1260 | 1269 | let symbol = dec.symbol(cdf); |
| 1261 | 1270 | if symbol != ANGLE_DELTA_ZERO { |
| 1262 | 1271 | ANGLE_DELTA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| @@ -1282,12 +1291,14 @@ fn read_intra_mode( | ||
| 1282 | 1291 | Option<usize>, |
| 1283 | 1292 | )> { |
| 1284 | 1293 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 1294 | + crate::msac::CURRENT_OP.with(|c| c.set("L1285")); | |
| 1285 | 1295 | let skip = dec.symbol(&mut cdfs.skip[0]) != 0; |
| 1286 | 1296 | if trace { |
| 1287 | 1297 | eprintln!("TRACE skip value={}", skip as i32); |
| 1288 | 1298 | } |
| 1289 | 1299 | let above_ctx = INTRA_MODE_CTX[above_mode]; |
| 1290 | 1300 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 1301 | + crate::msac::CURRENT_OP.with(|c| c.set("L1291")); | |
| 1291 | 1302 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| 1292 | 1303 | if trace { |
| 1293 | 1304 | eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}"); |
| @@ -1305,8 +1316,10 @@ fn read_intra_mode( | ||
| 1305 | 1316 | 0 |
| 1306 | 1317 | }; |
| 1307 | 1318 | let uv_mode = if cfl { |
| 1319 | + crate::msac::CURRENT_OP.with(|c| c.set("L1308")); | |
| 1308 | 1320 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 1309 | 1321 | } else { |
| 1322 | + crate::msac::CURRENT_OP.with(|c| c.set("L1310")); | |
| 1310 | 1323 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 1311 | 1324 | }; |
| 1312 | 1325 | if trace { |
| @@ -1350,6 +1363,7 @@ fn read_intra_mode( | ||
| 1350 | 1363 | && enable_filter_intra |
| 1351 | 1364 | && let Some(class) = filter_intra_size_class(side) |
| 1352 | 1365 | { |
| 1366 | + crate::msac::CURRENT_OP.with(|c| c.set("L1353")); | |
| 1353 | 1367 | let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; |
| 1354 | 1368 | if trace { |
| 1355 | 1369 | eprintln!( |
| @@ -1359,6 +1373,7 @@ fn read_intra_mode( | ||
| 1359 | 1373 | } |
| 1360 | 1374 | if use_filter_intra { |
| 1361 | 1375 | FILTER_INTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 1376 | + crate::msac::CURRENT_OP.with(|c| c.set("L1362")); | |
| 1362 | 1377 | let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); |
| 1363 | 1378 | if trace { |
| 1364 | 1379 | eprintln!("TRACE filter_intra_mode value={fi_mode}"); |
| @@ -1389,6 +1404,7 @@ const UV_CFL_PRED: usize = 13; | ||
| 1389 | 1404 | /// joint sign the same way. Returns each plane's final signed `alpha_q3` |
| 1390 | 1405 | /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0. |
| 1391 | 1406 | fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { |
| 1407 | + crate::msac::CURRENT_OP.with(|c| c.set("L1392")); | |
| 1392 | 1408 | let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32; |
| 1393 | 1409 | let sign_u = ((joint_sign + 1) * 11) >> 5; |
| 1394 | 1410 | let sign_v = (joint_sign + 1) - 3 * sign_u; |
| @@ -1396,6 +1412,7 @@ fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { | ||
| 1396 | 1412 | 0 |
| 1397 | 1413 | } else { |
| 1398 | 1414 | let ctx_u = (joint_sign + 1 - 3) as usize; |
| 1415 | + crate::msac::CURRENT_OP.with(|c| c.set("L1399")); | |
| 1399 | 1416 | let mag = dec.symbol(&mut cdfs.cfl_alpha[ctx_u]) as i32 + 1; |
| 1400 | 1417 | if sign_u == 2 { mag } else { -mag } |
| 1401 | 1418 | }; |
| @@ -1403,6 +1420,7 @@ fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { | ||
| 1403 | 1420 | 0 |
| 1404 | 1421 | } else { |
| 1405 | 1422 | let ctx_v = (sign_v * 3 + sign_u - 3) as usize; |
| 1423 | + crate::msac::CURRENT_OP.with(|c| c.set("L1406")); | |
| 1406 | 1424 | let mag = dec.symbol(&mut cdfs.cfl_alpha[ctx_v]) as i32 + 1; |
| 1407 | 1425 | if sign_v == 2 { mag } else { -mag } |
| 1408 | 1426 | }; |
| @@ -2588,10 +2606,22 @@ fn read_tx_size( | ||
| 2588 | 2606 | ) -> usize { |
| 2589 | 2607 | let ctx = tx_size_context(n, at_mi, side); |
| 2590 | 2608 | let depth = match side { |
| 2591 | - 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), | |
| 2592 | - 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), | |
| 2593 | - 32 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), | |
| 2594 | - 64 => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), | |
| 2609 | + 8 => { | |
| 2610 | + crate::msac::CURRENT_OP.with(|c| c.set("L2591")); | |
| 2611 | + dec.symbol(&mut cdfs.tx_size_cat0[ctx]) | |
| 2612 | + } | |
| 2613 | + 16 => { | |
| 2614 | + crate::msac::CURRENT_OP.with(|c| c.set("L2592")); | |
| 2615 | + dec.symbol(&mut cdfs.tx_size_cat1[ctx]) | |
| 2616 | + } | |
| 2617 | + 32 => { | |
| 2618 | + crate::msac::CURRENT_OP.with(|c| c.set("L2593")); | |
| 2619 | + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) | |
| 2620 | + } | |
| 2621 | + 64 => { | |
| 2622 | + crate::msac::CURRENT_OP.with(|c| c.set("L2594")); | |
| 2623 | + dec.symbol(&mut cdfs.tx_size_cat3[ctx]) | |
| 2624 | + } | |
| 2595 | 2625 | _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), |
| 2596 | 2626 | }; |
| 2597 | 2627 | if depth != 0 { |
| @@ -3300,6 +3330,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3300 | 3330 | // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own |
| 3301 | 3331 | // three-way write exactly. |
| 3302 | 3332 | let part = if has_cols && has_rows { |
| 3333 | + crate::msac::CURRENT_OP.with(|c| c.set("L3303")); | |
| 3303 | 3334 | let p = dec.symbol(&mut cdfs.partition_w64[ctx]); |
| 3304 | 3335 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3305 | 3336 | eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); |
| @@ -3308,9 +3339,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3308 | 3339 | } else { |
| 3309 | 3340 | match (has_cols, has_rows) { |
| 3310 | 3341 | (true, false) => { |
| 3342 | + crate::msac::CURRENT_OP.with(|c| c.set("L3311")); | |
| 3311 | 3343 | dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); |
| 3312 | 3344 | } |
| 3313 | 3345 | (false, true) => { |
| 3346 | + crate::msac::CURRENT_OP.with(|c| c.set("L3314")); | |
| 3314 | 3347 | dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); |
| 3315 | 3348 | } |
| 3316 | 3349 | _ => {} |
| @@ -3357,6 +3390,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3357 | 3390 | has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), |
| 3358 | 3391 | ); |
| 3359 | 3392 | let part32 = if has_cols32 && has_rows32 { |
| 3393 | + crate::msac::CURRENT_OP.with(|c| c.set("L3360")); | |
| 3360 | 3394 | let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); |
| 3361 | 3395 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3362 | 3396 | eprintln!( |
| @@ -3369,12 +3403,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3369 | 3403 | } else { |
| 3370 | 3404 | match (has_cols32, has_rows32) { |
| 3371 | 3405 | (true, false) => { |
| 3406 | + crate::msac::CURRENT_OP.with(|c| c.set("L3372")); | |
| 3372 | 3407 | dec.symbol_fixed(&gather( |
| 3373 | 3408 | &cdfs.partition_w32[ctx32], |
| 3374 | 3409 | VERT_ALIKE, |
| 3375 | 3410 | )); |
| 3376 | 3411 | } |
| 3377 | 3412 | (false, true) => { |
| 3413 | + crate::msac::CURRENT_OP.with(|c| c.set("L3378")); | |
| 3378 | 3414 | dec.symbol_fixed(&gather( |
| 3379 | 3415 | &cdfs.partition_w32[ctx32], |
| 3380 | 3416 | HORZ_ALIKE, |
| @@ -3427,6 +3463,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3427 | 3463 | let at16 = (sr, sc); |
| 3428 | 3464 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| 3429 | 3465 | if has_cols16 && has_rows16 { |
| 3466 | + crate::msac::CURRENT_OP.with(|c| c.set("L3430")); | |
| 3430 | 3467 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 3431 | 3468 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3432 | 3469 | eprintln!( |
| @@ -3481,6 +3518,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3481 | 3518 | (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); |
| 3482 | 3519 | let leaf_mi = (mr as usize, mc as usize); |
| 3483 | 3520 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 3521 | + crate::msac::CURRENT_OP.with(|c| c.set("L3485")); | |
| 3484 | 3522 | let part8 = |
| 3485 | 3523 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 3486 | 3524 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| @@ -3531,11 +3569,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3531 | 3569 | )); |
| 3532 | 3570 | } |
| 3533 | 3571 | if has_cols16 { |
| 3572 | + crate::msac::CURRENT_OP.with(|c| c.set("L3534")); | |
| 3534 | 3573 | dec.symbol_fixed(&gather( |
| 3535 | 3574 | &cdfs.partition_w16[ctx16], |
| 3536 | 3575 | VERT_ALIKE, |
| 3537 | 3576 | )); |
| 3538 | 3577 | } else { |
| 3578 | + crate::msac::CURRENT_OP.with(|c| c.set("L3539")); | |
| 3539 | 3579 | dec.symbol_fixed(&gather( |
| 3540 | 3580 | &cdfs.partition_w16[ctx16], |
| 3541 | 3581 | HORZ_ALIKE, |
| @@ -3551,6 +3591,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3551 | 3591 | for (mr, mc) in leaf_positions { |
| 3552 | 3592 | let leaf_mi = (mr as usize, mc as usize); |
| 3553 | 3593 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 3594 | + crate::msac::CURRENT_OP.with(|c| c.set("L3554")); | |
| 3554 | 3595 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 3555 | 3596 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3556 | 3597 | eprintln!( |
| @@ -3710,6 +3751,7 @@ fn resolve_interp_filter( | ||
| 3710 | 3751 | &cdfs.switchable_interp[ctx0][..3] |
| 3711 | 3752 | ); |
| 3712 | 3753 | } |
| 3754 | + crate::msac::CURRENT_OP.with(|c| c.set("L3713")); | |
| 3713 | 3755 | let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8; |
| 3714 | 3756 | let sym1 = if enable_dual_filter { |
| 3715 | 3757 | let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound); |
| @@ -3719,6 +3761,7 @@ fn resolve_interp_filter( | ||
| 3719 | 3761 | &cdfs.switchable_interp[ctx1][..3] |
| 3720 | 3762 | ); |
| 3721 | 3763 | } |
| 3764 | + crate::msac::CURRENT_OP.with(|c| c.set("L3722")); | |
| 3722 | 3765 | dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8 |
| 3723 | 3766 | } else { |
| 3724 | 3767 | sym0 |
| @@ -3768,16 +3811,21 @@ fn read_mv_component( | ||
| 3768 | 3811 | c: &mut MvComponentCdfs, |
| 3769 | 3812 | allow_high_precision_mv: bool, |
| 3770 | 3813 | ) -> i32 { |
| 3814 | + crate::msac::CURRENT_OP.with(|c| c.set("L3771")); | |
| 3771 | 3815 | let sign = dec.symbol(&mut c.sign); |
| 3816 | + crate::msac::CURRENT_OP.with(|c| c.set("L3772")); | |
| 3772 | 3817 | let class = dec.symbol(&mut c.class); |
| 3773 | 3818 | let local = if class == 0 { |
| 3819 | + crate::msac::CURRENT_OP.with(|c| c.set("L3774")); | |
| 3774 | 3820 | let bit = dec.symbol(&mut c.class0_bit); |
| 3821 | + crate::msac::CURRENT_OP.with(|c| c.set("L3775")); | |
| 3775 | 3822 | let fr = dec.symbol(&mut c.class0_fr[bit]); |
| 3776 | 3823 | // spec 5.11.32 `mv_class0_hp`: read only when the frame allows |
| 3777 | 3824 | // high-precision motion vectors, else implicitly 1 (the low bit |
| 3778 | 3825 | // stays at half-pel precision) -- this crate's own writer always |
| 3779 | 3826 | // leaves the flag off, but a foreign stream can set it per frame. |
| 3780 | 3827 | let hp = if allow_high_precision_mv { |
| 3828 | + crate::msac::CURRENT_OP.with(|c| c.set("L3781")); | |
| 3781 | 3829 | dec.symbol(&mut c.class0_hp) |
| 3782 | 3830 | } else { |
| 3783 | 3831 | 1 |
| @@ -3786,10 +3834,13 @@ fn read_mv_component( | ||
| 3786 | 3834 | } else { |
| 3787 | 3835 | let mut d = 0; |
| 3788 | 3836 | for i in 0..class { |
| 3837 | + crate::msac::CURRENT_OP.with(|c| c.set("L3789")); | |
| 3789 | 3838 | d |= dec.symbol(&mut c.bit[i]) << i; |
| 3790 | 3839 | } |
| 3840 | + crate::msac::CURRENT_OP.with(|c| c.set("L3791")); | |
| 3791 | 3841 | let fr = dec.symbol(&mut c.fr); |
| 3792 | 3842 | let hp = if allow_high_precision_mv { |
| 3843 | + crate::msac::CURRENT_OP.with(|c| c.set("L3793")); | |
| 3793 | 3844 | dec.symbol(&mut c.hp) |
| 3794 | 3845 | } else { |
| 3795 | 3846 | 1 |
| @@ -3809,6 +3860,7 @@ fn read_mv( | ||
| 3809 | 3860 | pred: (i32, i32), |
| 3810 | 3861 | allow_high_precision_mv: bool, |
| 3811 | 3862 | ) -> (i32, i32) { |
| 3863 | + crate::msac::CURRENT_OP.with(|c| c.set("L3812")); | |
| 3812 | 3864 | let joint = dec.symbol(mv_joint); |
| 3813 | 3865 | let mut diff = (0, 0); |
| 3814 | 3866 | if joint == 2 || joint == 3 { |
| @@ -3912,21 +3964,27 @@ fn read_single_ref( | ||
| 3912 | 3964 | ) -> i8 { |
| 3913 | 3965 | let above = (above_ref > 0).then_some(above_ref); |
| 3914 | 3966 | let left = (left_ref > 0).then_some(left_ref); |
| 3967 | + crate::msac::CURRENT_OP.with(|c| c.set("L3915")); | |
| 3915 | 3968 | let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); |
| 3916 | 3969 | let ref_frame = if p1 == 1 { |
| 3970 | + crate::msac::CURRENT_OP.with(|c| c.set("L3917")); | |
| 3917 | 3971 | let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); |
| 3918 | 3972 | if p2 == 1 { |
| 3919 | 3973 | ALTREF_FRAME |
| 3920 | 3974 | } else { |
| 3975 | + crate::msac::CURRENT_OP.with(|c| c.set("L3921")); | |
| 3921 | 3976 | let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5]); |
| 3922 | 3977 | if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } |
| 3923 | 3978 | } |
| 3924 | 3979 | } else { |
| 3980 | + crate::msac::CURRENT_OP.with(|c| c.set("L3925")); | |
| 3925 | 3981 | let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); |
| 3926 | 3982 | if p3 == 1 { |
| 3983 | + crate::msac::CURRENT_OP.with(|c| c.set("L3927")); | |
| 3927 | 3984 | let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4]); |
| 3928 | 3985 | if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } |
| 3929 | 3986 | } else { |
| 3987 | + crate::msac::CURRENT_OP.with(|c| c.set("L3930")); | |
| 3930 | 3988 | let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3]); |
| 3931 | 3989 | if p4 == 1 { LAST2_FRAME } else { LAST_FRAME } |
| 3932 | 3990 | } |
| @@ -4048,6 +4106,7 @@ fn read_comp_mode( | ||
| 4048 | 4106 | left: Option<NeighbourRef>, |
| 4049 | 4107 | ) -> bool { |
| 4050 | 4108 | let ctx = reference_mode_ctx(above, left); |
| 4109 | + crate::msac::CURRENT_OP.with(|c| c.set("L4051")); | |
| 4051 | 4110 | let compound = dec.symbol(&mut cdfs.comp_mode[ctx]) == 1; |
| 4052 | 4111 | if compound { |
| 4053 | 4112 | COMP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| @@ -4091,17 +4150,21 @@ fn read_compound_ref_frames( | ||
| 4091 | 4150 | let a1 = above.and_then(|n| n.ref1); |
| 4092 | 4151 | let l1 = left.and_then(|n| n.ref1); |
| 4093 | 4152 | let type_ctx = comp_reference_type_ctx(above, left); |
| 4153 | + crate::msac::CURRENT_OP.with(|c| c.set("L4094")); | |
| 4094 | 4154 | let unidir = dec.symbol(&mut cdfs.comp_ref_type[type_ctx]) == 0; |
| 4095 | 4155 | if unidir { |
| 4096 | 4156 | // uni_comp_ref (p0): forward vs. backward -- av1_get_pred_context_- |
| 4097 | 4157 | // uni_comp_ref_p is single_ref_p1's own forward/backward vote. |
| 4158 | + crate::msac::CURRENT_OP.with(|c| c.set("L4098")); | |
| 4098 | 4159 | let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, a1, l, l1)][0]); |
| 4099 | 4160 | if bit == 1 { |
| 4100 | 4161 | (BWDREF_FRAME, ALTREF_FRAME) |
| 4101 | 4162 | } else { |
| 4163 | + crate::msac::CURRENT_OP.with(|c| c.set("L4102")); | |
| 4102 | 4164 | let p1 = dec.symbol(&mut cdfs.uni_comp_ref[uni_comp_ref_p1_ctx(a, a1, l, l1)][1]); |
| 4103 | 4165 | if p1 == 1 { |
| 4104 | 4166 | // uni_comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. |
| 4167 | + crate::msac::CURRENT_OP.with(|c| c.set("L4105")); | |
| 4105 | 4168 | let p2 = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]); |
| 4106 | 4169 | if p2 == 1 { |
| 4107 | 4170 | (LAST_FRAME, GOLDEN_FRAME) |
| @@ -4114,20 +4177,25 @@ fn read_compound_ref_frames( | ||
| 4114 | 4177 | } |
| 4115 | 4178 | } else { |
| 4116 | 4179 | // comp_ref (p0): LAST/LAST2 vs. LAST3/GOLDEN, same vote as single_ref_p3. |
| 4180 | + crate::msac::CURRENT_OP.with(|c| c.set("L4117")); | |
| 4117 | 4181 | let bit0 = dec.symbol(&mut cdfs.comp_ref[single_ref_p3_ctx(a, a1, l, l1)][0]); |
| 4118 | 4182 | let ref0 = if bit0 == 0 { |
| 4119 | 4183 | // comp_ref_p1: LAST vs. LAST2, same vote as single_ref_p4. |
| 4184 | + crate::msac::CURRENT_OP.with(|c| c.set("L4120")); | |
| 4120 | 4185 | let p1 = dec.symbol(&mut cdfs.comp_ref[single_ref_p4_ctx(a, a1, l, l1)][1]); |
| 4121 | 4186 | if p1 == 1 { LAST2_FRAME } else { LAST_FRAME } |
| 4122 | 4187 | } else { |
| 4123 | 4188 | // comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. |
| 4189 | + crate::msac::CURRENT_OP.with(|c| c.set("L4124")); | |
| 4124 | 4190 | let p2 = dec.symbol(&mut cdfs.comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]); |
| 4125 | 4191 | if p2 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } |
| 4126 | 4192 | }; |
| 4127 | 4193 | // comp_bwdref (p0): BWDREF/ALTREF2 vs. ALTREF, same vote as single_ref_p2. |
| 4194 | + crate::msac::CURRENT_OP.with(|c| c.set("L4128")); | |
| 4128 | 4195 | let bit1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p2_ctx(a, a1, l, l1)][0]); |
| 4129 | 4196 | let ref1 = if bit1 == 0 { |
| 4130 | 4197 | // comp_bwdref_p1: BWDREF vs. ALTREF2, same vote as single_ref_p6. |
| 4198 | + crate::msac::CURRENT_OP.with(|c| c.set("L4131")); | |
| 4131 | 4199 | let p1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p6_ctx(a, a1, l, l1)][1]); |
| 4132 | 4200 | if p1 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } |
| 4133 | 4201 | } else { |
| @@ -4155,6 +4223,7 @@ fn read_inter_compound_mode( | ||
| 4155 | 4223 | ) -> u8 { |
| 4156 | 4224 | let ctx = cdf::COMPOUND_MODE_CTX_MAP[ref_mv_ctx >> 1][new_mv_ctx.min(4)]; |
| 4157 | 4225 | COMPOUND_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 4226 | + crate::msac::CURRENT_OP.with(|c| c.set("L4158")); | |
| 4158 | 4227 | dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u8 |
| 4159 | 4228 | } |
| 4160 | 4229 | |
| @@ -4190,6 +4259,7 @@ fn assign_compound_mv( | ||
| 4190 | 4259 | if mode == NEW_NEWMV { |
| 4191 | 4260 | let mut idx = 0usize; |
| 4192 | 4261 | while idx < 2 && comp_stack.entries.len() > idx + 1 { |
| 4262 | + crate::msac::CURRENT_OP.with(|c| c.set("L4193")); | |
| 4193 | 4263 | if dec.symbol(&mut cdfs.drl_mode[comp_stack.drl_ctx[idx]]) == 0 { |
| 4194 | 4264 | break; |
| 4195 | 4265 | } |
| @@ -4199,6 +4269,7 @@ fn assign_compound_mv( | ||
| 4199 | 4269 | } else if matches!(mode, NEAR_NEARMV | NEAR_NEWMV | NEW_NEARMV) { |
| 4200 | 4270 | let mut idx = 1usize; |
| 4201 | 4271 | while idx < 3 && comp_stack.entries.len() > idx + 1 { |
| 4272 | + crate::msac::CURRENT_OP.with(|c| c.set("L4202")); | |
| 4202 | 4273 | if dec.symbol(&mut cdfs.drl_mode[comp_stack.drl_ctx[idx]]) == 0 { |
| 4203 | 4274 | break; |
| 4204 | 4275 | } |
| @@ -4342,17 +4413,20 @@ fn decode_inter_block( | ||
| 4342 | 4413 | } |
| 4343 | 4414 | let skip_mode_ctx = |
| 4344 | 4415 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); |
| 4416 | + crate::msac::CURRENT_OP.with(|c| c.set("L4345")); | |
| 4345 | 4417 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| 4346 | 4418 | if skip_mode { |
| 4347 | 4419 | SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 4348 | 4420 | } |
| 4349 | 4421 | |
| 4350 | 4422 | let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]); |
| 4423 | + crate::msac::CURRENT_OP.with(|c| c.set("L4351")); | |
| 4351 | 4424 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 4352 | 4425 | |
| 4353 | 4426 | let (has_above, has_left) = (r > 0, c > 0); |
| 4354 | 4427 | let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); |
| 4355 | 4428 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 4429 | + crate::msac::CURRENT_OP.with(|c| c.set("L4356")); | |
| 4356 | 4430 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 4357 | 4431 | |
| 4358 | 4432 | let mode_for_tx; |
| @@ -4504,6 +4578,7 @@ fn decode_inter_block( | ||
| 4504 | 4578 | && enable_masked_compound |
| 4505 | 4579 | && is_any_masked_compound_used_here(side) |
| 4506 | 4580 | { |
| 4581 | + crate::msac::CURRENT_OP.with(|c| c.set("L4507")); | |
| 4507 | 4582 | dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) |
| 4508 | 4583 | } else { |
| 4509 | 4584 | 0 |
| @@ -4728,6 +4803,7 @@ fn decode_inter_block( | ||
| 4728 | 4803 | cdfs.compound_idx[idx_ctx][0] |
| 4729 | 4804 | ); |
| 4730 | 4805 | } |
| 4806 | + crate::msac::CURRENT_OP.with(|c| c.set("L4731")); | |
| 4731 | 4807 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); |
| 4732 | 4808 | if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { |
| 4733 | 4809 | eprintln!( |
| @@ -5036,6 +5112,7 @@ fn decode_inter_block( | ||
| 5036 | 5112 | sign_bias_table, |
| 5037 | 5113 | tpl, |
| 5038 | 5114 | ); |
| 5115 | + crate::msac::CURRENT_OP.with(|c| c.set("L5039")); | |
| 5039 | 5116 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 5040 | 5117 | let mut is_globalmv = false; |
| 5041 | 5118 | let (mv, is_new_mv) = if !not_new { |
| @@ -5047,6 +5124,7 @@ fn decode_inter_block( | ||
| 5047 | 5124 | // -- entry 0 (`stack.pred_mv`) only when the loop never advances. |
| 5048 | 5125 | let mut idx = 0usize; |
| 5049 | 5126 | while idx < 2 && stack.entries.len() > idx + 1 { |
| 5127 | + crate::msac::CURRENT_OP.with(|c| c.set("L5050")); | |
| 5050 | 5128 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 5051 | 5129 | break; |
| 5052 | 5130 | } |
| @@ -5064,6 +5142,7 @@ fn decode_inter_block( | ||
| 5064 | 5142 | true, |
| 5065 | 5143 | ) |
| 5066 | 5144 | } else { |
| 5145 | + crate::msac::CURRENT_OP.with(|c| c.set("L5067")); | |
| 5067 | 5146 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; |
| 5068 | 5147 | is_globalmv = !not_zero; |
| 5069 | 5148 | let mv = if !not_zero { |
| @@ -5073,6 +5152,7 @@ fn decode_inter_block( | ||
| 5073 | 5152 | // model is refused before the tile decoder is ever called). |
| 5074 | 5153 | (0, 0) |
| 5075 | 5154 | } else { |
| 5155 | + crate::msac::CURRENT_OP.with(|c| c.set("L5076")); | |
| 5076 | 5156 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 5077 | 5157 | if nearest { |
| 5078 | 5158 | stack.nearest_mv |
| @@ -5085,6 +5165,7 @@ fn decode_inter_block( | ||
| 5085 | 5165 | // exactly the pair this index is choosing between. |
| 5086 | 5166 | let mut idx = 1usize; |
| 5087 | 5167 | while idx < 3 && stack.entries.len() > idx + 1 { |
| 5168 | + crate::msac::CURRENT_OP.with(|c| c.set("L5088")); | |
| 5088 | 5169 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 5089 | 5170 | break; |
| 5090 | 5171 | } |
| @@ -5291,6 +5372,7 @@ fn decode_inter_block( | ||
| 5291 | 5372 | } |
| 5292 | 5373 | } |
| 5293 | 5374 | } else { |
| 5375 | + crate::msac::CURRENT_OP.with(|c| c.set("L5294")); | |
| 5294 | 5376 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); |
| 5295 | 5377 | if mode >= 13 { |
| 5296 | 5378 | return Err(unsupported( |
| @@ -5298,6 +5380,7 @@ fn decode_inter_block( | ||
| 5298 | 5380 | )); |
| 5299 | 5381 | } |
| 5300 | 5382 | if (V_PRED..=D67_PRED).contains(&mode) { |
| 5383 | + crate::msac::CURRENT_OP.with(|c| c.set("L5301")); | |
| 5301 | 5384 | let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]); |
| 5302 | 5385 | if angle != ANGLE_DELTA_ZERO { |
| 5303 | 5386 | return Err(unsupported( |
| @@ -5305,6 +5388,7 @@ fn decode_inter_block( | ||
| 5305 | 5388 | )); |
| 5306 | 5389 | } |
| 5307 | 5390 | } |
| 5391 | + crate::msac::CURRENT_OP.with(|c| c.set("L5308")); | |
| 5308 | 5392 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 5309 | 5393 | let alpha = if uv_mode == DC_PRED { |
| 5310 | 5394 | None |
| @@ -5550,16 +5634,19 @@ fn decode_inter_block8( | ||
| 5550 | 5634 | } |
| 5551 | 5635 | let skip_mode_ctx = |
| 5552 | 5636 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); |
| 5637 | + crate::msac::CURRENT_OP.with(|c| c.set("L5553")); | |
| 5553 | 5638 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| 5554 | 5639 | if skip_mode { |
| 5555 | 5640 | SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 5556 | 5641 | } |
| 5557 | 5642 | |
| 5558 | 5643 | let skip_ctx = usize::from(above_skip) + usize::from(left_skip); |
| 5644 | + crate::msac::CURRENT_OP.with(|c| c.set("L5559")); | |
| 5559 | 5645 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 5560 | 5646 | |
| 5561 | 5647 | let (has_above, has_left) = (leaf_mi.0 > 0, leaf_mi.1 > 0); |
| 5562 | 5648 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 5649 | + crate::msac::CURRENT_OP.with(|c| c.set("L5563")); | |
| 5563 | 5650 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 5564 | 5651 | |
| 5565 | 5652 | let mode_for_tx; |
| @@ -5646,6 +5733,7 @@ fn decode_inter_block8( | ||
| 5646 | 5733 | && enable_masked_compound |
| 5647 | 5734 | && is_any_masked_compound_used_here(SIDE) |
| 5648 | 5735 | { |
| 5736 | + crate::msac::CURRENT_OP.with(|c| c.set("L5649")); | |
| 5649 | 5737 | dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) |
| 5650 | 5738 | } else { |
| 5651 | 5739 | 0 |
| @@ -5680,6 +5768,7 @@ fn decode_inter_block8( | ||
| 5680 | 5768 | ref_order_hints[(ref0 - LAST_FRAME) as usize], |
| 5681 | 5769 | ref_order_hints[(ref1 - LAST_FRAME) as usize], |
| 5682 | 5770 | ); |
| 5771 | + crate::msac::CURRENT_OP.with(|c| c.set("L5683")); | |
| 5683 | 5772 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); |
| 5684 | 5773 | if idx == 1 { |
| 5685 | 5774 | (8, 8, 1u8) |
| @@ -5897,8 +5986,11 @@ fn decode_inter_block8( | ||
| 5897 | 5986 | } |
| 5898 | 5987 | } |
| 5899 | 5988 | let sr_ctx = single_ref_ctx(above_inter || left_inter); |
| 5989 | + crate::msac::CURRENT_OP.with(|c| c.set("L5900")); | |
| 5900 | 5990 | let p1 = dec.symbol(&mut cdfs.single_ref[sr_ctx][0]); |
| 5991 | + crate::msac::CURRENT_OP.with(|c| c.set("L5901")); | |
| 5901 | 5992 | let p3 = dec.symbol(&mut cdfs.single_ref[sr_ctx][2]); |
| 5993 | + crate::msac::CURRENT_OP.with(|c| c.set("L5902")); | |
| 5902 | 5994 | let p4 = dec.symbol(&mut cdfs.single_ref[sr_ctx][3]); |
| 5903 | 5995 | if (p1, p3, p4) != (0, 0, 0) { |
| 5904 | 5996 | return Err(unsupported( |
| @@ -5918,6 +6010,7 @@ fn decode_inter_block8( | ||
| 5918 | 6010 | mi_rows as usize, |
| 5919 | 6011 | ); |
| 5920 | 6012 | |
| 6013 | + crate::msac::CURRENT_OP.with(|c| c.set("L5921")); | |
| 5921 | 6014 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 5922 | 6015 | let (mv, is_new_mv) = if !not_new { |
| 5923 | 6016 | // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): |
| @@ -5928,6 +6021,7 @@ fn decode_inter_block8( | ||
| 5928 | 6021 | // -- entry 0 (`stack.pred_mv`) only when the loop never advances. |
| 5929 | 6022 | let mut idx = 0usize; |
| 5930 | 6023 | while idx < 2 && stack.entries.len() > idx + 1 { |
| 6024 | + crate::msac::CURRENT_OP.with(|c| c.set("L5931")); | |
| 5931 | 6025 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 5932 | 6026 | break; |
| 5933 | 6027 | } |
| @@ -5945,16 +6039,19 @@ fn decode_inter_block8( | ||
| 5945 | 6039 | true, |
| 5946 | 6040 | ) |
| 5947 | 6041 | } else { |
| 6042 | + crate::msac::CURRENT_OP.with(|c| c.set("L5948")); | |
| 5948 | 6043 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; |
| 5949 | 6044 | if !not_zero { |
| 5950 | 6045 | return Err(unsupported("GLOBALMV (round 3)")); |
| 5951 | 6046 | } |
| 6047 | + crate::msac::CURRENT_OP.with(|c| c.set("L5952")); | |
| 5952 | 6048 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 5953 | 6049 | let mv = if nearest { |
| 5954 | 6050 | stack.nearest_mv |
| 5955 | 6051 | } else { |
| 5956 | 6052 | let mut idx = 1usize; |
| 5957 | 6053 | while idx < 3 && stack.entries.len() > idx + 1 { |
| 6054 | + crate::msac::CURRENT_OP.with(|c| c.set("L5958")); | |
| 5958 | 6055 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 5959 | 6056 | break; |
| 5960 | 6057 | } |
| @@ -6088,6 +6185,7 @@ fn decode_inter_block8( | ||
| 6088 | 6185 | )?; |
| 6089 | 6186 | } |
| 6090 | 6187 | } else { |
| 6188 | + crate::msac::CURRENT_OP.with(|c| c.set("L6091")); | |
| 6091 | 6189 | let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]); |
| 6092 | 6190 | if mode >= 13 { |
| 6093 | 6191 | return Err(unsupported( |
| @@ -6095,6 +6193,7 @@ fn decode_inter_block8( | ||
| 6095 | 6193 | )); |
| 6096 | 6194 | } |
| 6097 | 6195 | if (V_PRED..=D67_PRED).contains(&mode) { |
| 6196 | + crate::msac::CURRENT_OP.with(|c| c.set("L6098")); | |
| 6098 | 6197 | let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]); |
| 6099 | 6198 | if angle != ANGLE_DELTA_ZERO { |
| 6100 | 6199 | return Err(unsupported( |
| @@ -6102,6 +6201,7 @@ fn decode_inter_block8( | ||
| 6102 | 6201 | )); |
| 6103 | 6202 | } |
| 6104 | 6203 | } |
| 6204 | + crate::msac::CURRENT_OP.with(|c| c.set("L6105")); | |
| 6105 | 6205 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 6106 | 6206 | if uv_mode != DC_PRED { |
| 6107 | 6207 | return Err(unsupported( |
| @@ -6473,12 +6573,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6473 | 6573 | ); |
| 6474 | 6574 | match (has_cols, has_rows) { |
| 6475 | 6575 | (true, true) => { |
| 6576 | + crate::msac::CURRENT_OP.with(|c| c.set("L6476")); | |
| 6476 | 6577 | dec.symbol(&mut cdfs.partition_w64[sb_ctx]); |
| 6477 | 6578 | } |
| 6478 | 6579 | (true, false) => { |
| 6580 | + crate::msac::CURRENT_OP.with(|c| c.set("L6479")); | |
| 6479 | 6581 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); |
| 6480 | 6582 | } |
| 6481 | 6583 | (false, true) => { |
| 6584 | + crate::msac::CURRENT_OP.with(|c| c.set("L6482")); | |
| 6482 | 6585 | dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); |
| 6483 | 6586 | } |
| 6484 | 6587 | (false, false) => {} |
| @@ -6496,13 +6599,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6496 | 6599 | has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), |
| 6497 | 6600 | ); |
| 6498 | 6601 | let part32 = if has_cols32 && has_rows32 { |
| 6602 | + crate::msac::CURRENT_OP.with(|c| c.set("L6499")); | |
| 6499 | 6603 | dec.symbol(&mut cdfs.partition_w32[ctx32]) |
| 6500 | 6604 | } else { |
| 6501 | 6605 | match (has_cols32, has_rows32) { |
| 6502 | 6606 | (true, false) => { |
| 6607 | + crate::msac::CURRENT_OP.with(|c| c.set("L6503")); | |
| 6503 | 6608 | dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); |
| 6504 | 6609 | } |
| 6505 | 6610 | (false, true) => { |
| 6611 | + crate::msac::CURRENT_OP.with(|c| c.set("L6506")); | |
| 6506 | 6612 | dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); |
| 6507 | 6613 | } |
| 6508 | 6614 | _ => {} |
| @@ -6571,6 +6677,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6571 | 6677 | let at16 = (sr, sc); |
| 6572 | 6678 | if has_cols16 && has_rows16 { |
| 6573 | 6679 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| 6680 | + crate::msac::CURRENT_OP.with(|c| c.set("L6574")); | |
| 6574 | 6681 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 6575 | 6682 | if part16 != PARTITION_NONE { |
| 6576 | 6683 | return Err(unsupported( |
| @@ -6619,11 +6726,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6619 | 6726 | } else { |
| 6620 | 6727 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| 6621 | 6728 | if has_cols16 { |
| 6729 | + crate::msac::CURRENT_OP.with(|c| c.set("L6622")); | |
| 6622 | 6730 | dec.symbol_fixed(&gather( |
| 6623 | 6731 | &cdfs.partition_w16[ctx16], |
| 6624 | 6732 | VERT_ALIKE, |
| 6625 | 6733 | )); |
| 6626 | 6734 | } else { |
| 6735 | + crate::msac::CURRENT_OP.with(|c| c.set("L6627")); | |
| 6627 | 6736 | dec.symbol_fixed(&gather( |
| 6628 | 6737 | &cdfs.partition_w16[ctx16], |
| 6629 | 6738 | HORZ_ALIKE, |
| @@ -6640,6 +6749,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 6640 | 6749 | for (mr, mc) in leaf_positions { |
| 6641 | 6750 | let leaf_mi = (mr as usize, mc as usize); |
| 6642 | 6751 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 6752 | + crate::msac::CURRENT_OP.with(|c| c.set("L6643")); | |
| 6643 | 6753 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 6644 | 6754 | if part8 != PARTITION_NONE { |
| 6645 | 6755 | return Err(unsupported( |
crates/ec-av1/src/msac.rsmodified+9 -1
| @@ -18,6 +18,13 @@ | ||
| 18 | 18 | |
| 19 | 19 | /// Probability precision dropped before the range multiply (spec `EC_PROB_SHIFT`). |
| 20 | 20 | const EC_PROB_SHIFT: u32 = 6; |
| 21 | + | |
| 22 | +thread_local! { | |
| 23 | + /// Debug-only tag naming the call site of the in-flight `symbol()` read, | |
| 24 | + /// for the `EC_RNG=1` trace (r5 scratch instrumentation). Set immediately | |
| 25 | + /// before each `dec.symbol()`/`symbol_fixed()` call in decode.rs. | |
| 26 | + pub static CURRENT_OP: std::cell::Cell<&'static str> = const { std::cell::Cell::new("?") }; | |
| 27 | +} | |
| 21 | 28 | /// Minimum interval width reserved for every symbol (spec `EC_MIN_PROB`). |
| 22 | 29 | const EC_MIN_PROB: u32 = 4; |
| 23 | 30 | /// Total probability mass of a CDF (spec `1 << 15`). |
| @@ -319,8 +326,9 @@ impl<'a> SymbolDecoder<'a> { | ||
| 319 | 326 | use std::sync::atomic::{AtomicU64, Ordering}; |
| 320 | 327 | static EC_RNG_N: AtomicU64 = AtomicU64::new(0); |
| 321 | 328 | let n = EC_RNG_N.fetch_add(1, Ordering::Relaxed); |
| 329 | + let op = CURRENT_OP.with(|c| c.get()); | |
| 322 | 330 | eprintln!( |
| 323 | - "EC_RNG n={n} rng_before={rng_before} rng_after={} nsyms={nsyms} symbol={symbol}", | |
| 331 | + "EC_RNG n={n} op={op} rng_before={rng_before} rng_after={} nsyms={nsyms} symbol={symbol}", | |
| 324 | 332 | self.range |
| 325 | 333 | ); |
| 326 | 334 | } |
crates/ec-av1/src/mvstack.rsmodified+56 -29
| @@ -123,19 +123,18 @@ pub struct MiInfo { | ||
| 123 | 123 | pub ref_frame: i8, |
| 124 | 124 | /// The unit's *second* reference frame when it was coded compound |
| 125 | 125 | /// (spec `RefFrames[1]`), `None` for a single-reference/intra unit -- |
| 126 | - /// lane-av1comp: today's callers (single-ref decode/encode) never set | |
| 127 | - /// this, so it exists only so [`MiGrid`] can carry compound state once | |
| 128 | - /// `read_ref_frames` (spec 5.11.25) lands; nothing reads it yet, and | |
| 129 | - /// [`find_mv_stack`]'s scan still matches candidates on `ref_frame` | |
| 130 | - /// alone (its own compound dual-ref scan is unported -- see the ledger). | |
| 126 | + /// compound-coded decode leaves set this. lane-av1idx r5: | |
| 127 | + /// [`find_mv_stack`]'s single-ref row/col/corner scans (via | |
| 128 | + /// `single_ref_match`) now also match a compound neighbour on this | |
| 129 | + /// second field, donating that side's own MV -- the real read #538 | |
| 130 | + /// desync (a `new_mv_ctx` fed by a `newmv_count`/`nearest_match` that | |
| 131 | + /// silently dropped a compound neighbour's vote whenever its match sat | |
| 132 | + /// in this slot). | |
| 131 | 133 | pub ref_frame1: Option<i8>, |
| 132 | 134 | /// The unit's motion vector, `(row, col)`, in the spec's 1/8-pel units. |
| 133 | 135 | pub mv: (i32, i32), |
| 134 | 136 | /// The unit's second motion vector, matching `ref_frame1` (spec |
| 135 | 137 | /// `Mvs[1]`) — `Some` only for a compound-coded unit, `None` otherwise. |
| 136 | - /// lane-av1comp step 4: exists so the compound mvstack scan below can | |
| 137 | - /// read a compound neighbour's second MV; no caller sets it yet (same | |
| 138 | - /// unwired state `ref_frame1` landed in for r3). | |
| 139 | 138 | pub mv1: Option<(i32, i32)>, |
| 140 | 139 | /// Whether this unit's own mode was `NEWMV` (spec's |
| 141 | 140 | /// `have_newmv_in_inter_mode`, compound modes excluded since this module |
| @@ -311,9 +310,9 @@ pub const NO_SIGN_BIAS: SignBiasTable = [false; 7]; | ||
| 311 | 310 | /// |
| 312 | 311 | /// libaom's real signature loops `rf_idx` over the candidate's up to two |
| 313 | 312 | /// coded reference-frame slots (a compound-coded neighbour donates two |
| 314 | -/// candidates, one per slot); this crate's [`MiInfo`] carries a single | |
| 315 | -/// `ref_frame`, since no coded neighbour here is ever compound — ported as | |
| 316 | -/// that loop's `rf_idx == 0` iteration alone. | |
| 313 | +/// candidates, one per slot) -- now ported in full: a compound `candidate` | |
| 314 | +/// (`ref_frame1`/`mv1` both `Some`) donates a second entry from its second | |
| 315 | +/// slot too, each sign-flipped against its own reference frame independently. | |
| 317 | 316 | fn process_single_ref_mv_candidate( |
| 318 | 317 | candidate: &MiInfo, |
| 319 | 318 | ref_frame: i8, |
| @@ -323,15 +322,23 @@ fn process_single_ref_mv_candidate( | ||
| 323 | 322 | if !candidate.is_inter { |
| 324 | 323 | return; |
| 325 | 324 | } |
| 326 | - let mut this_mv = candidate.mv; | |
| 327 | - if sign_bias(sign_bias_table, candidate.ref_frame) != sign_bias(sign_bias_table, ref_frame) { | |
| 328 | - this_mv = (-this_mv.0, -this_mv.1); | |
| 325 | + let mut slots = [(candidate.ref_frame, candidate.mv); 2]; | |
| 326 | + let mut n_slots = 1; | |
| 327 | + if let (Some(rf1), Some(mv1)) = (candidate.ref_frame1, candidate.mv1) { | |
| 328 | + slots[1] = (rf1, mv1); | |
| 329 | + n_slots = 2; | |
| 329 | 330 | } |
| 330 | - if !candidates.iter().any(|e| e.mv == this_mv) { | |
| 331 | - candidates.push(StackEntry { | |
| 332 | - mv: this_mv, | |
| 333 | - weight: 2, | |
| 334 | - }); | |
| 331 | + for &(rf, mv) in &slots[..n_slots] { | |
| 332 | + let mut this_mv = mv; | |
| 333 | + if sign_bias(sign_bias_table, rf) != sign_bias(sign_bias_table, ref_frame) { | |
| 334 | + this_mv = (-this_mv.0, -this_mv.1); | |
| 335 | + } | |
| 336 | + if !candidates.iter().any(|e| e.mv == this_mv) { | |
| 337 | + candidates.push(StackEntry { | |
| 338 | + mv: this_mv, | |
| 339 | + weight: 2, | |
| 340 | + }); | |
| 341 | + } | |
| 335 | 342 | } |
| 336 | 343 | } |
| 337 | 344 | |
| @@ -405,9 +412,9 @@ fn scan_row( | ||
| 405 | 412 | weight = weight.max(inc as u32); |
| 406 | 413 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; |
| 407 | 414 | } |
| 408 | - if info.is_inter && info.ref_frame == ref_frame { | |
| 415 | + if let Some(mv) = single_ref_match(info, ref_frame) { | |
| 409 | 416 | found = true; |
| 410 | - add_candidate(candidates, info.mv, len as u32 * weight); | |
| 417 | + add_candidate(candidates, mv, len as u32 * weight); | |
| 411 | 418 | *newmv_count += u32::from(info.is_new_mv); |
| 412 | 419 | } |
| 413 | 420 | i += len.max(1); |
| @@ -415,6 +422,28 @@ fn scan_row( | ||
| 415 | 422 | found |
| 416 | 423 | } |
| 417 | 424 | |
| 425 | +/// libaom's `add_ref_mv_candidate` (mvref_common.c) for a single-reference | |
| 426 | +/// query: a compound-coded neighbour still votes when *either* of its two | |
| 427 | +/// coded reference frames matches `ref_frame`, contributing that side's own | |
| 428 | +/// MV -- checked first slot then second, matching libaom's `for (ref = 0; | |
| 429 | +/// ref < 1 + is_compound; ++ref)` loop order. The row/col/corner scans below | |
| 430 | +/// used to check `info.ref_frame == ref_frame` alone, silently dropping a | |
| 431 | +/// compound neighbour's vote whenever the match sat in its *second* slot | |
| 432 | +/// (the class this crate's own compound-stack scan already had to close for | |
| 433 | +/// [`find_mv_stack_compound`] -- see the module doc). | |
| 434 | +fn single_ref_match(info: &MiInfo, ref_frame: i8) -> Option<(i32, i32)> { | |
| 435 | + if !info.is_inter { | |
| 436 | + return None; | |
| 437 | + } | |
| 438 | + if info.ref_frame == ref_frame { | |
| 439 | + Some(info.mv) | |
| 440 | + } else if info.ref_frame1 == Some(ref_frame) { | |
| 441 | + info.mv1 | |
| 442 | + } else { | |
| 443 | + None | |
| 444 | + } | |
| 445 | +} | |
| 446 | + | |
| 418 | 447 | /// The col scan (spec 7.10.2.3, libaom `scan_col_mbmi`): `scan_row`, |
| 419 | 448 | /// transposed. |
| 420 | 449 | #[allow(clippy::too_many_arguments)] |
| @@ -456,9 +485,9 @@ fn scan_col( | ||
| 456 | 485 | weight = weight.max(inc as u32); |
| 457 | 486 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; |
| 458 | 487 | } |
| 459 | - if info.is_inter && info.ref_frame == ref_frame { | |
| 488 | + if let Some(mv) = single_ref_match(info, ref_frame) { | |
| 460 | 489 | found = true; |
| 461 | - add_candidate(candidates, info.mv, len as u32 * weight); | |
| 490 | + add_candidate(candidates, mv, len as u32 * weight); | |
| 462 | 491 | *newmv_count += u32::from(info.is_new_mv); |
| 463 | 492 | } |
| 464 | 493 | i += len.max(1); |
| @@ -486,10 +515,9 @@ fn scan_top_right( | ||
| 486 | 515 | }; |
| 487 | 516 | let col = mi_col + bw4; |
| 488 | 517 | if let Some(info) = grid.get(row, col) |
| 489 | - && info.is_inter | |
| 490 | - && info.ref_frame == ref_frame | |
| 518 | + && let Some(mv) = single_ref_match(info, ref_frame) | |
| 491 | 519 | { |
| 492 | - add_candidate(candidates, info.mv, CORNER_WEIGHT); | |
| 520 | + add_candidate(candidates, mv, CORNER_WEIGHT); | |
| 493 | 521 | *newmv_count += u32::from(info.is_new_mv); |
| 494 | 522 | return true; |
| 495 | 523 | } |
| @@ -514,10 +542,9 @@ fn scan_corner( | ||
| 514 | 542 | return false; |
| 515 | 543 | }; |
| 516 | 544 | if let Some(info) = grid.get(row, col) |
| 517 | - && info.is_inter | |
| 518 | - && info.ref_frame == ref_frame | |
| 545 | + && let Some(mv) = single_ref_match(info, ref_frame) | |
| 519 | 546 | { |
| 520 | - add_candidate(candidates, info.mv, CORNER_WEIGHT); | |
| 547 | + add_candidate(candidates, mv, CORNER_WEIGHT); | |
| 521 | 548 | *newmv_count += u32::from(info.is_new_mv); |
| 522 | 549 | return true; |
| 523 | 550 | } |
crates/ec-av1/src/stream.rsmodified+3 -1
| @@ -268,12 +268,14 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 268 | 268 | }; |
| 269 | 269 | if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { |
| 270 | 270 | eprintln!( |
| 271 | - "STREAM_HEADER r17_before={} interpolation_filter={:?} interp_fixed={interp_fixed:?} is_motion_mode_switchable={} enable_interintra_compound={:?} allow_warped_motion={}", | |
| 271 | + "STREAM_HEADER r17_before={} interpolation_filter={:?} interp_fixed={interp_fixed:?} is_motion_mode_switchable={} enable_interintra_compound={:?} allow_warped_motion={} reference_select={} primary_ref_frame={}", | |
| 272 | 272 | crate::decode::r17_dump_frame_idx(), |
| 273 | 273 | header.interpolation_filter, |
| 274 | 274 | header.is_motion_mode_switchable, |
| 275 | 275 | parser.sequence_header().map(|s| s.enable_interintra_compound), |
| 276 | 276 | header.allow_warped_motion, |
| 277 | + header.reference_select, | |
| 278 | + header.primary_ref_frame, | |
| 277 | 279 | ); |
| 278 | 280 | } |
| 279 | 281 |