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