Rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the block
Browse files at this commit759e6884e21ccd52826fd7337646f2ac4a6aba4dParent: 51ce8e8- fix
- rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the block
3 changed files +240 -17
- crates/ec-av1/src/decode.rs +36 -12
- crates/ec-av1/src/mc.rs +117 -5
- lanes/rectchroma2-r1.report.md +87 -0
crates/ec-av1/src/decode.rsmodified+36 -12
| @@ -17419,7 +17419,7 @@ fn decode_inter_block( | |||
| 17419 | } | 17419 | } |
| 17420 | 17420 | ||
| 17421 | let mut inter0_y = vec![0i32; side * side]; | 17421 | let mut inter0_y = vec![0i32; side * side]; |
| 17422 | - mc::predict_compound_intermediate( | 17422 | + mc::predict_compound_intermediate_kern( |
| 17423 | &py0.data, | 17423 | &py0.data, |
| 17424 | py0.width, | 17424 | py0.width, |
| 17425 | py0.true_width, | 17425 | py0.true_width, |
| @@ -17429,6 +17429,8 @@ fn decode_inter_block( | |||
| 17429 | scale0, | 17429 | scale0, |
| 17430 | side, | 17430 | side, |
| 17431 | side, | 17431 | side, |
| 17432 | + write_w, | ||
| 17433 | + write_h, | ||
| 17432 | h_filter, | 17434 | h_filter, |
| 17433 | v_filter, | 17435 | v_filter, |
| 17434 | &mut inter0_y, | 17436 | &mut inter0_y, |
| @@ -17444,7 +17446,7 @@ fn decode_inter_block( | |||
| 17444 | ); | 17446 | ); |
| 17445 | } | 17447 | } |
| 17446 | let mut inter1_y = vec![0i32; side * side]; | 17448 | let mut inter1_y = vec![0i32; side * side]; |
| 17447 | - mc::predict_compound_intermediate( | 17449 | + mc::predict_compound_intermediate_kern( |
| 17448 | &py1.data, | 17450 | &py1.data, |
| 17449 | py1.width, | 17451 | py1.width, |
| 17450 | py1.true_width, | 17452 | py1.true_width, |
| @@ -17454,6 +17456,8 @@ fn decode_inter_block( | |||
| 17454 | scale1, | 17456 | scale1, |
| 17455 | side, | 17457 | side, |
| 17456 | side, | 17458 | side, |
| 17459 | + write_w, | ||
| 17460 | + write_h, | ||
| 17457 | h_filter, | 17461 | h_filter, |
| 17458 | v_filter, | 17462 | v_filter, |
| 17459 | &mut inter1_y, | 17463 | &mut inter1_y, |
| @@ -17491,7 +17495,7 @@ fn decode_inter_block( | |||
| 17491 | } | 17495 | } |
| 17492 | 17496 | ||
| 17493 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | 17497 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 17494 | - mc::predict_compound_intermediate( | 17498 | + mc::predict_compound_intermediate_kern( |
| 17495 | &pu0.data, | 17499 | &pu0.data, |
| 17496 | pu0.width, | 17500 | pu0.width, |
| 17497 | pu0.true_width, | 17501 | pu0.true_width, |
| @@ -17501,6 +17505,8 @@ fn decode_inter_block( | |||
| 17501 | scale0, | 17505 | scale0, |
| 17502 | chroma_side, | 17506 | chroma_side, |
| 17503 | chroma_side, | 17507 | chroma_side, |
| 17508 | + write_chroma_w, | ||
| 17509 | + write_chroma_h, | ||
| 17504 | h_filter, | 17510 | h_filter, |
| 17505 | v_filter, | 17511 | v_filter, |
| 17506 | &mut inter0_u, | 17512 | &mut inter0_u, |
| @@ -17518,7 +17524,7 @@ fn decode_inter_block( | |||
| 17518 | } | 17524 | } |
| 17519 | } | 17525 | } |
| 17520 | let mut inter1_u = vec![0i32; chroma_side * chroma_side]; | 17526 | let mut inter1_u = vec![0i32; chroma_side * chroma_side]; |
| 17521 | - mc::predict_compound_intermediate( | 17527 | + mc::predict_compound_intermediate_kern( |
| 17522 | &pu1.data, | 17528 | &pu1.data, |
| 17523 | pu1.width, | 17529 | pu1.width, |
| 17524 | pu1.true_width, | 17530 | pu1.true_width, |
| @@ -17528,6 +17534,8 @@ fn decode_inter_block( | |||
| 17528 | scale1, | 17534 | scale1, |
| 17529 | chroma_side, | 17535 | chroma_side, |
| 17530 | chroma_side, | 17536 | chroma_side, |
| 17537 | + write_chroma_w, | ||
| 17538 | + write_chroma_h, | ||
| 17531 | h_filter, | 17539 | h_filter, |
| 17532 | v_filter, | 17540 | v_filter, |
| 17533 | &mut inter1_u, | 17541 | &mut inter1_u, |
| @@ -17561,7 +17569,7 @@ fn decode_inter_block( | |||
| 17561 | } | 17569 | } |
| 17562 | 17570 | ||
| 17563 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; | 17571 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; |
| 17564 | - mc::predict_compound_intermediate( | 17572 | + mc::predict_compound_intermediate_kern( |
| 17565 | &pv0.data, | 17573 | &pv0.data, |
| 17566 | pv0.width, | 17574 | pv0.width, |
| 17567 | pv0.true_width, | 17575 | pv0.true_width, |
| @@ -17571,6 +17579,8 @@ fn decode_inter_block( | |||
| 17571 | scale0, | 17579 | scale0, |
| 17572 | chroma_side, | 17580 | chroma_side, |
| 17573 | chroma_side, | 17581 | chroma_side, |
| 17582 | + write_chroma_w, | ||
| 17583 | + write_chroma_h, | ||
| 17574 | h_filter, | 17584 | h_filter, |
| 17575 | v_filter, | 17585 | v_filter, |
| 17576 | &mut inter0_v, | 17586 | &mut inter0_v, |
| @@ -17588,7 +17598,7 @@ fn decode_inter_block( | |||
| 17588 | } | 17598 | } |
| 17589 | } | 17599 | } |
| 17590 | let mut inter1_v = vec![0i32; chroma_side * chroma_side]; | 17600 | let mut inter1_v = vec![0i32; chroma_side * chroma_side]; |
| 17591 | - mc::predict_compound_intermediate( | 17601 | + mc::predict_compound_intermediate_kern( |
| 17592 | &pv1.data, | 17602 | &pv1.data, |
| 17593 | pv1.width, | 17603 | pv1.width, |
| 17594 | pv1.true_width, | 17604 | pv1.true_width, |
| @@ -17598,6 +17608,8 @@ fn decode_inter_block( | |||
| 17598 | scale1, | 17608 | scale1, |
| 17599 | chroma_side, | 17609 | chroma_side, |
| 17600 | chroma_side, | 17610 | chroma_side, |
| 17611 | + write_chroma_w, | ||
| 17612 | + write_chroma_h, | ||
| 17601 | h_filter, | 17613 | h_filter, |
| 17602 | v_filter, | 17614 | v_filter, |
| 17603 | &mut inter1_v, | 17615 | &mut inter1_v, |
| @@ -18485,7 +18497,7 @@ fn decode_inter_block( | |||
| 18485 | let mut pred_u = vec![0u16; chroma_side * chroma_side]; | 18497 | let mut pred_u = vec![0u16; chroma_side * chroma_side]; |
| 18486 | let mut pred_v = vec![0u16; chroma_side * chroma_side]; | 18498 | let mut pred_v = vec![0u16; chroma_side * chroma_side]; |
| 18487 | if luma_scale == mc::REF_NO_SCALE { | 18499 | if luma_scale == mc::REF_NO_SCALE { |
| 18488 | - mc::predict_with_filters( | 18500 | + mc::predict_with_filters_kern( |
| 18489 | &py_ref.data, | 18501 | &py_ref.data, |
| 18490 | py_ref.width, | 18502 | py_ref.width, |
| 18491 | py_ref.true_width, | 18503 | py_ref.true_width, |
| @@ -18494,11 +18506,13 @@ fn decode_inter_block( | |||
| 18494 | mv_to_q4(py, mv.0, true), | 18506 | mv_to_q4(py, mv.0, true), |
| 18495 | side, | 18507 | side, |
| 18496 | side, | 18508 | side, |
| 18509 | + write_w, | ||
| 18510 | + write_h, | ||
| 18497 | h_filter, | 18511 | h_filter, |
| 18498 | v_filter, | 18512 | v_filter, |
| 18499 | &mut pred_y, | 18513 | &mut pred_y, |
| 18500 | ); | 18514 | ); |
| 18501 | - mc::predict_with_filters( | 18515 | + mc::predict_with_filters_kern( |
| 18502 | &pu_ref.data, | 18516 | &pu_ref.data, |
| 18503 | pu_ref.width, | 18517 | pu_ref.width, |
| 18504 | pu_ref.true_width, | 18518 | pu_ref.true_width, |
| @@ -18507,11 +18521,13 @@ fn decode_inter_block( | |||
| 18507 | mv_to_q4(cpy, mv.0, false), | 18521 | mv_to_q4(cpy, mv.0, false), |
| 18508 | chroma_side, | 18522 | chroma_side, |
| 18509 | chroma_side, | 18523 | chroma_side, |
| 18524 | + write_chroma_w, | ||
| 18525 | + write_chroma_h, | ||
| 18510 | h_filter, | 18526 | h_filter, |
| 18511 | v_filter, | 18527 | v_filter, |
| 18512 | &mut pred_u, | 18528 | &mut pred_u, |
| 18513 | ); | 18529 | ); |
| 18514 | - mc::predict_with_filters( | 18530 | + mc::predict_with_filters_kern( |
| 18515 | &pv_ref.data, | 18531 | &pv_ref.data, |
| 18516 | pv_ref.width, | 18532 | pv_ref.width, |
| 18517 | pv_ref.true_width, | 18533 | pv_ref.true_width, |
| @@ -18520,12 +18536,14 @@ fn decode_inter_block( | |||
| 18520 | mv_to_q4(cpy, mv.0, false), | 18536 | mv_to_q4(cpy, mv.0, false), |
| 18521 | chroma_side, | 18537 | chroma_side, |
| 18522 | chroma_side, | 18538 | chroma_side, |
| 18539 | + write_chroma_w, | ||
| 18540 | + write_chroma_h, | ||
| 18523 | h_filter, | 18541 | h_filter, |
| 18524 | v_filter, | 18542 | v_filter, |
| 18525 | &mut pred_v, | 18543 | &mut pred_v, |
| 18526 | ); | 18544 | ); |
| 18527 | } else { | 18545 | } else { |
| 18528 | - mc::predict_scaled( | 18546 | + mc::predict_scaled_kern( |
| 18529 | &py_ref.data, | 18547 | &py_ref.data, |
| 18530 | py_ref.width, | 18548 | py_ref.width, |
| 18531 | py_ref.true_width, | 18549 | py_ref.true_width, |
| @@ -18535,11 +18553,13 @@ fn decode_inter_block( | |||
| 18535 | luma_scale, | 18553 | luma_scale, |
| 18536 | side, | 18554 | side, |
| 18537 | side, | 18555 | side, |
| 18556 | + write_w, | ||
| 18557 | + write_h, | ||
| 18538 | h_filter, | 18558 | h_filter, |
| 18539 | v_filter, | 18559 | v_filter, |
| 18540 | &mut pred_y, | 18560 | &mut pred_y, |
| 18541 | ); | 18561 | ); |
| 18542 | - mc::predict_scaled( | 18562 | + mc::predict_scaled_kern( |
| 18543 | &pu_ref.data, | 18563 | &pu_ref.data, |
| 18544 | pu_ref.width, | 18564 | pu_ref.width, |
| 18545 | pu_ref.true_width, | 18565 | pu_ref.true_width, |
| @@ -18549,11 +18569,13 @@ fn decode_inter_block( | |||
| 18549 | luma_scale, | 18569 | luma_scale, |
| 18550 | chroma_side, | 18570 | chroma_side, |
| 18551 | chroma_side, | 18571 | chroma_side, |
| 18572 | + write_chroma_w, | ||
| 18573 | + write_chroma_h, | ||
| 18552 | h_filter, | 18574 | h_filter, |
| 18553 | v_filter, | 18575 | v_filter, |
| 18554 | &mut pred_u, | 18576 | &mut pred_u, |
| 18555 | ); | 18577 | ); |
| 18556 | - mc::predict_scaled( | 18578 | + mc::predict_scaled_kern( |
| 18557 | &pv_ref.data, | 18579 | &pv_ref.data, |
| 18558 | pv_ref.width, | 18580 | pv_ref.width, |
| 18559 | pv_ref.true_width, | 18581 | pv_ref.true_width, |
| @@ -18563,6 +18585,8 @@ fn decode_inter_block( | |||
| 18563 | luma_scale, | 18585 | luma_scale, |
| 18564 | chroma_side, | 18586 | chroma_side, |
| 18565 | chroma_side, | 18587 | chroma_side, |
| 18588 | + write_chroma_w, | ||
| 18589 | + write_chroma_h, | ||
| 18566 | h_filter, | 18590 | h_filter, |
| 18567 | v_filter, | 18591 | v_filter, |
| 18568 | &mut pred_v, | 18592 | &mut pred_v, |
crates/ec-av1/src/mc.rsmodified+117 -5
| @@ -333,6 +333,36 @@ pub fn predict_with_filters( | |||
| 333 | h_kind: InterpFilterKind, | 333 | h_kind: InterpFilterKind, |
| 334 | v_kind: InterpFilterKind, | 334 | v_kind: InterpFilterKind, |
| 335 | dst: &mut [u16], | 335 | dst: &mut [u16], |
| 336 | +) { | ||
| 337 | + predict_with_filters_kern( | ||
| 338 | + reference, stride, true_width, true_height, x_q4, y_q4, block_w, | ||
| 339 | + block_h, block_w, block_h, h_kind, v_kind, dst, | ||
| 340 | + ); | ||
| 341 | +} | ||
| 342 | + | ||
| 343 | +/// [`predict_with_filters`] with the 4-tap decision taken from the block's | ||
| 344 | +/// TRUE width/height (`kern_w`/`kern_h`) rather than the destination buffer's. | ||
| 345 | +/// libaom's `av1_get_interp_filter_params_with_block_size` (reconinter.h, | ||
| 346 | +/// called per axis from `inter_predictor` with `w` then `h`) picks the narrow | ||
| 347 | +/// kernel from the PREDICTION block's own dimensions; our inter path predicts | ||
| 348 | +/// a rectangular block over its enclosing square buffer, so a rect block whose | ||
| 349 | +/// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask | ||
| 350 | +/// for the 4-tap kernel on that axis -- lane-rectchroma2 r1. | ||
| 351 | +#[allow(clippy::too_many_arguments)] | ||
| 352 | +pub fn predict_with_filters_kern( | ||
| 353 | + reference: &[u16], | ||
| 354 | + stride: usize, | ||
| 355 | + true_width: usize, | ||
| 356 | + true_height: usize, | ||
| 357 | + x_q4: i32, | ||
| 358 | + y_q4: i32, | ||
| 359 | + block_w: usize, | ||
| 360 | + block_h: usize, | ||
| 361 | + kern_w: usize, | ||
| 362 | + kern_h: usize, | ||
| 363 | + h_kind: InterpFilterKind, | ||
| 364 | + v_kind: InterpFilterKind, | ||
| 365 | + dst: &mut [u16], | ||
| 336 | ) { | 366 | ) { |
| 337 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 367 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 338 | assert!(!reference.is_empty(), "a reference plane has samples"); | 368 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -374,12 +404,13 @@ pub fn predict_with_filters( | |||
| 374 | 404 | ||
| 375 | let (h_wide, h_narrow) = h_kind.tables(); | 405 | let (h_wide, h_narrow) = h_kind.tables(); |
| 376 | let (v_wide, v_narrow) = v_kind.tables(); | 406 | let (v_wide, v_narrow) = v_kind.tables(); |
| 377 | - let h_filter = if block_w <= 4 { | 407 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); |
| 408 | + let h_filter = if kern_w <= 4 { | ||
| 378 | &h_narrow[xfrac] | 409 | &h_narrow[xfrac] |
| 379 | } else { | 410 | } else { |
| 380 | &h_wide[xfrac] | 411 | &h_wide[xfrac] |
| 381 | }; | 412 | }; |
| 382 | - let v_filter = if block_h <= 4 { | 413 | + let v_filter = if kern_h <= 4 { |
| 383 | &v_narrow[yfrac] | 414 | &v_narrow[yfrac] |
| 384 | } else { | 415 | } else { |
| 385 | &v_wide[yfrac] | 416 | &v_wide[yfrac] |
| @@ -452,6 +483,32 @@ thread_local! { | |||
| 452 | /// only intra blocks cannot pass it by construction (class | 483 | /// only intra blocks cannot pass it by construction (class |
| 453 | /// `gate-blind-to-feature`). | 484 | /// `gate-blind-to-feature`). |
| 454 | static INTER_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 485 | static INTER_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 486 | + | ||
| 487 | + /// lane-rectchroma2 r1: how often the 4-tap decision came out DIFFERENT | ||
| 488 | + /// from what the destination buffer's own dimensions would have given -- | ||
| 489 | + /// i.e. how often a rectangular block predicted over its enclosing square | ||
| 490 | + /// buffer asked for libaom's narrow kernel on an axis. Zero means a gate | ||
| 491 | + /// never exercised the rect-chroma shape at all. | ||
| 492 | + static RECT_NARROW_KERN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 493 | +} | ||
| 494 | + | ||
| 495 | +/// Current value of [`RECT_NARROW_KERN_HITS`]. | ||
| 496 | +pub fn rect_narrow_kern_hits() -> usize { | ||
| 497 | + RECT_NARROW_KERN_HITS.with(|c| c.get()) | ||
| 498 | +} | ||
| 499 | + | ||
| 500 | +/// Resets [`RECT_NARROW_KERN_HITS`] (per-attempt counting, class | ||
| 501 | +/// `counter-from-refused-stream`). | ||
| 502 | +pub fn reset_rect_narrow_kern_hits() { | ||
| 503 | + RECT_NARROW_KERN_HITS.with(|c| c.set(0)); | ||
| 504 | +} | ||
| 505 | + | ||
| 506 | +/// Bumps [`RECT_NARROW_KERN_HITS`] when the block's true dims pick a kernel | ||
| 507 | +/// the destination buffer's dims would not have. | ||
| 508 | +fn note_narrow_kern(block_w: usize, block_h: usize, kern_w: usize, kern_h: usize) { | ||
| 509 | + if (kern_w <= 4) != (block_w <= 4) || (kern_h <= 4) != (block_h <= 4) { | ||
| 510 | + RECT_NARROW_KERN_HITS.with(|c| c.set(c.get() + 1)); | ||
| 511 | + } | ||
| 455 | } | 512 | } |
| 456 | 513 | ||
| 457 | /// Current value of [`INTER_PRED_HITS`]. | 514 | /// Current value of [`INTER_PRED_HITS`]. |
| @@ -498,6 +555,7 @@ fn horizontal_scaled_pass( | |||
| 498 | y0: i32, | 555 | y0: i32, |
| 499 | x_scale_fp: i64, | 556 | x_scale_fp: i64, |
| 500 | block_w: usize, | 557 | block_w: usize, |
| 558 | + kern_w: usize, | ||
| 501 | rows: usize, | 559 | rows: usize, |
| 502 | h_kind: InterpFilterKind, | 560 | h_kind: InterpFilterKind, |
| 503 | intermediate: &mut [i32], | 561 | intermediate: &mut [i32], |
| @@ -510,7 +568,7 @@ fn horizontal_scaled_pass( | |||
| 510 | let x_qn = pos_x_q10 + c as i64 * x_step_qn; | 568 | let x_qn = pos_x_q10 + c as i64 * x_step_qn; |
| 511 | let int_pel = (x_qn >> 10) as i32; | 569 | let int_pel = (x_qn >> 10) as i32; |
| 512 | let filter_idx = ((x_qn & 1023) >> 6) as usize; | 570 | let filter_idx = ((x_qn & 1023) >> 6) as usize; |
| 513 | - let h_filter = if block_w <= 4 { | 571 | + let h_filter = if kern_w <= 4 { |
| 514 | &h_narrow[filter_idx] | 572 | &h_narrow[filter_idx] |
| 515 | } else { | 573 | } else { |
| 516 | &h_wide[filter_idx] | 574 | &h_wide[filter_idx] |
| @@ -555,6 +613,31 @@ pub fn predict_scaled( | |||
| 555 | h_kind: InterpFilterKind, | 613 | h_kind: InterpFilterKind, |
| 556 | v_kind: InterpFilterKind, | 614 | v_kind: InterpFilterKind, |
| 557 | dst: &mut [u16], | 615 | dst: &mut [u16], |
| 616 | +) { | ||
| 617 | + predict_scaled_kern( | ||
| 618 | + reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp, | ||
| 619 | + block_w, block_h, block_w, block_h, h_kind, v_kind, dst, | ||
| 620 | + ); | ||
| 621 | +} | ||
| 622 | + | ||
| 623 | +/// [`predict_scaled`] with the 4-tap decision from the block's true dims | ||
| 624 | +/// (see [`predict_with_filters_kern`]). | ||
| 625 | +#[allow(clippy::too_many_arguments)] | ||
| 626 | +pub fn predict_scaled_kern( | ||
| 627 | + reference: &[u16], | ||
| 628 | + stride: usize, | ||
| 629 | + true_width: usize, | ||
| 630 | + true_height: usize, | ||
| 631 | + x_q4: i32, | ||
| 632 | + y_q4: i32, | ||
| 633 | + x_scale_fp: i64, | ||
| 634 | + block_w: usize, | ||
| 635 | + block_h: usize, | ||
| 636 | + kern_w: usize, | ||
| 637 | + kern_h: usize, | ||
| 638 | + h_kind: InterpFilterKind, | ||
| 639 | + v_kind: InterpFilterKind, | ||
| 640 | + dst: &mut [u16], | ||
| 558 | ) { | 641 | ) { |
| 559 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 642 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 560 | assert!(!reference.is_empty(), "a reference plane has samples"); | 643 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -568,7 +651,8 @@ pub fn predict_scaled( | |||
| 568 | // Q10; off/pos_x_q10 fold the block's own x_q4 (Q4) into that same Q10 | 651 | // Q10; off/pos_x_q10 fold the block's own x_q4 (Q4) into that same Q10 |
| 569 | // grid (spec 7.11.3.3's `dec_calc_subpel_params`). | 652 | // grid (spec 7.11.3.3's `dec_calc_subpel_params`). |
| 570 | let (v_wide, v_narrow) = v_kind.tables(); | 653 | let (v_wide, v_narrow) = v_kind.tables(); |
| 571 | - let v_filter = if block_h <= 4 { | 654 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); |
| 655 | + let v_filter = if kern_h <= 4 { | ||
| 572 | &v_narrow[yfrac] | 656 | &v_narrow[yfrac] |
| 573 | } else { | 657 | } else { |
| 574 | &v_wide[yfrac] | 658 | &v_wide[yfrac] |
| @@ -585,6 +669,7 @@ pub fn predict_scaled( | |||
| 585 | y0, | 669 | y0, |
| 586 | x_scale_fp, | 670 | x_scale_fp, |
| 587 | block_w, | 671 | block_w, |
| 672 | + kern_w, | ||
| 588 | rows, | 673 | rows, |
| 589 | h_kind, | 674 | h_kind, |
| 590 | &mut intermediate, | 675 | &mut intermediate, |
| @@ -648,6 +733,31 @@ pub fn predict_compound_intermediate( | |||
| 648 | h_kind: InterpFilterKind, | 733 | h_kind: InterpFilterKind, |
| 649 | v_kind: InterpFilterKind, | 734 | v_kind: InterpFilterKind, |
| 650 | dst: &mut [i32], | 735 | dst: &mut [i32], |
| 736 | +) { | ||
| 737 | + predict_compound_intermediate_kern( | ||
| 738 | + reference, stride, true_width, true_height, x_q4, y_q4, x_scale_fp, | ||
| 739 | + block_w, block_h, block_w, block_h, h_kind, v_kind, dst, | ||
| 740 | + ); | ||
| 741 | +} | ||
| 742 | + | ||
| 743 | +/// [`predict_compound_intermediate`] with the 4-tap decision from the block's | ||
| 744 | +/// true dims (see [`predict_with_filters_kern`]). | ||
| 745 | +#[allow(clippy::too_many_arguments)] | ||
| 746 | +pub fn predict_compound_intermediate_kern( | ||
| 747 | + reference: &[u16], | ||
| 748 | + stride: usize, | ||
| 749 | + true_width: usize, | ||
| 750 | + true_height: usize, | ||
| 751 | + x_q4: i32, | ||
| 752 | + y_q4: i32, | ||
| 753 | + x_scale_fp: i64, | ||
| 754 | + block_w: usize, | ||
| 755 | + block_h: usize, | ||
| 756 | + kern_w: usize, | ||
| 757 | + kern_h: usize, | ||
| 758 | + h_kind: InterpFilterKind, | ||
| 759 | + v_kind: InterpFilterKind, | ||
| 760 | + dst: &mut [i32], | ||
| 651 | ) { | 761 | ) { |
| 652 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); | 762 | assert_eq!(dst.len(), block_w * block_h, "the destination is the block"); |
| 653 | assert!(!reference.is_empty(), "a reference plane has samples"); | 763 | assert!(!reference.is_empty(), "a reference plane has samples"); |
| @@ -661,7 +771,8 @@ pub fn predict_compound_intermediate( | |||
| 661 | let yfrac = y_q4.rem_euclid(16) as usize; | 771 | let yfrac = y_q4.rem_euclid(16) as usize; |
| 662 | 772 | ||
| 663 | let (v_wide, v_narrow) = v_kind.tables(); | 773 | let (v_wide, v_narrow) = v_kind.tables(); |
| 664 | - let v_filter = if block_h <= 4 { | 774 | + note_narrow_kern(block_w, block_h, kern_w, kern_h); |
| 775 | + let v_filter = if kern_h <= 4 { | ||
| 665 | &v_narrow[yfrac] | 776 | &v_narrow[yfrac] |
| 666 | } else { | 777 | } else { |
| 667 | &v_wide[yfrac] | 778 | &v_wide[yfrac] |
| @@ -678,6 +789,7 @@ pub fn predict_compound_intermediate( | |||
| 678 | y0, | 789 | y0, |
| 679 | x_scale_fp, | 790 | x_scale_fp, |
| 680 | block_w, | 791 | block_w, |
| 792 | + kern_w, | ||
| 681 | rows, | 793 | rows, |
| 682 | h_kind, | 794 | h_kind, |
| 683 | &mut intermediate, | 795 | &mut intermediate, |
lanes/rectchroma2-r1.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | |||
| 1 | +# lane-rectchroma2 r1 -- rect INTER blocks predicted chroma with the WIDE kernel | ||
| 2 | + | ||
| 3 | +## Premise re-measured first | ||
| 4 | + | ||
| 5 | +lane-interedge r1's residue reproduced on this tree (main 2c04819 + lane-cdef + lane-golomb | ||
| 6 | +173b793): mandelbrot 192x128 (the CONTROL size -- zero frame-edge nodes), 6 frames, | ||
| 7 | +`--enable-rect-partitions=1 --min-partition-size=8 --enable-tx-size-search=0 --lag-in-frames=0`, | ||
| 8 | +intra tools off, cq 20/32/45, 8- and 10-bit: **luma exact, chroma differs on frames 2..5 in all | ||
| 9 | +six arms**. Streams hashed twice, identical. | ||
| 10 | + | ||
| 11 | +EVIDENCE: `~/.cache/rectchroma2-tmp/c192-128-{8,10}-{20,32,45}.obu` (each sha256 twice, equal) | ||
| 12 | +| `decode_probe` with `EC_AV1_FINAL_DUMP` vs `ffmpeg -pix_fmt yuv420p[10le]`, every decode-order | ||
| 13 | +frame, per plane | e.g. cq32 8-bit: `[(2,'chroma (0,32)..(1,40) n=17'), (4,...), (5,...)]`, luma | ||
| 14 | +exact in all 6 arms. | ||
| 15 | + | ||
| 16 | +## Stage bisect | ||
| 17 | + | ||
| 18 | +Regenerated the same recipe with `--loopfilter-control=0` (deblock off; CDEF/LR already off in | ||
| 19 | +that recipe): **the chroma mismatch survives unchanged** -> not a filter-stage defect, so the | ||
| 20 | +charter's suspect (d) (chroma deblock levels / uv tx grid for rect inter blocks) is exonerated. | ||
| 21 | +The surviving diffs are +-1 on scattered samples inside 4-wide-by-8-tall and 8-wide-by-4-tall | ||
| 22 | +CHROMA regions (e.g. frame 4: chroma x32..35 rows 26..39, and x48..55 rows 16..19) -- i.e. the | ||
| 23 | +chroma halves of 8x16 and 16x8 LUMA blocks. | ||
| 24 | + | ||
| 25 | +EVIDENCE: `~/.cache/rectchroma2-tmp/n192-128-8-32.obu` (`gen_nolf.sh`) | decode + full-plane | ||
| 26 | +compare | `MISMATCH [(2,'chroma ... n=15'), (4,...n=36), (5,...n=45)]`, luma exact. | ||
| 27 | + | ||
| 28 | +## Root cause (charter suspect (a), confirmed) | ||
| 29 | + | ||
| 30 | +`crates/ec-av1/src/decode.rs` `decode_inter_block` predicts a RECTANGULAR block over its | ||
| 31 | +enclosing SQUARE buffer (`side`x`side`, chroma `chroma_side`x`chroma_side`; `write_w`/`write_h` | ||
| 32 | +govern only the pixel write -- the lane-partitions r1 corner-cut). The 4-tap decision lived | ||
| 33 | +inside `mc::predict_with_filters` and read that BUFFER's dimensions. libaom | ||
| 34 | +`av1_get_interp_filter_params_with_block_size` (reconinter.h, called per axis from | ||
| 35 | +`inter_predictor` with `w` then `h`) reads the PREDICTION BLOCK's dimensions: `w <= 4` -> | ||
| 36 | +`av1_interp_4tap[0]` (SHARP and REGULAR both) / `[1]` (SMOOTH). Luma is never <= 4 wide on this | ||
| 37 | +path, so only chroma of a rect block (4x8 / 8x4 / 4x16 ...) was affected -- exactly the | ||
| 38 | +"luma exact, chroma wrong" signature. | ||
| 39 | + | ||
| 40 | +- `crates/ec-av1/src/mc.rs`: `predict_with_filters_kern` / `predict_scaled_kern` / | ||
| 41 | + `predict_compound_intermediate_kern` -- the existing three entry points keep their signatures | ||
| 42 | + and delegate with `kern = block dims`; `horizontal_scaled_pass` takes `kern_w`. | ||
| 43 | +- `crates/ec-av1/src/mc.rs`: `RECT_NARROW_KERN_HITS` + `rect_narrow_kern_hits()` / | ||
| 44 | + `reset_rect_narrow_kern_hits()` / `note_narrow_kern()` -- counts predictions whose kernel | ||
| 45 | + choice DIFFERS from what the square buffer would have given (one bump per prediction). | ||
| 46 | +- `crates/ec-av1/src/decode.rs`: the 12 prediction calls inside `decode_inter_block` now pass | ||
| 47 | + `write_w/write_h` (luma) and `write_chroma_w/write_chroma_h` (chroma) as the kernel dims. | ||
| 48 | + | ||
| 49 | +Class sweep: every other `mc::predict*` call site passes a buffer whose dims ARE the block's | ||
| 50 | +(`obmc_neighbour_pred` takes the neighbour's true w/h; the 8x8 leaf path is square, chroma 4x4; | ||
| 51 | +the CfL bilinear path is unrelated), so no sibling site needed the change. | ||
| 52 | + | ||
| 53 | +## Gate (GREEN) | ||
| 54 | + | ||
| 55 | +``` | ||
| 56 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rectchroma2 EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \ | ||
| 57 | +PATH="$HOME/.cache/aom-oracle/build:$PATH" cargo test -p ec-av1 --lib narrow_kernel -- --nocapture | ||
| 58 | +``` | ||
| 59 | +`a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact` | ||
| 60 | +(`crates/ec-av1/src/stream.rs`): real aomenc, mandelbrot 192x128 AND its transposed twin | ||
| 61 | +128x192 (so 4x8 and 8x4 chroma both fire), 8- and 10-bit, cq 20/32/45, 6 frames, | ||
| 62 | +`--lag-in-frames=0` so decode order == display order and EVERY frame is compared on Y, U AND V | ||
| 63 | +against ffmpeg. CDEF and loop restoration left ON. Streams encoded twice and asserted equal. | ||
| 64 | +`compared == 12` is a hard assert (a refusal fails the gate, never SKIPs), and the narrow-kernel | ||
| 65 | +counter -- reset per attempt, read only on compared attempts -- must be nonzero at BOTH depths | ||
| 66 | +and in BOTH orientations. | ||
| 67 | + | ||
| 68 | +EVIDENCE: gate stdout | 12 aomenc -> ec-av1 -> ffmpeg attempts, 6 frames each, all three planes | ||
| 69 | +| `12/12 arms 6 frames full-plane exact; narrow-kernel hits 24/4/16 (192x128 8-bit cq20/32/45), | ||
| 70 | +18/26/36 (10-bit), 42/20/18 and 36/36/34 for 128x192` -- 0 refusals, 0 out-of-scope mismatches. | ||
| 71 | + | ||
| 72 | +Before the fix the SAME recipe mismatched chroma in every arm (the premise sweep above), so the | ||
| 73 | +gate is not vacuous. | ||
| 74 | + | ||
| 75 | +## Refusals | ||
| 76 | +None lifted (no inventory string covers this defect -- it was a wrong-pixels defect behind an | ||
| 77 | +already-accepted path). `refusal_inventory.rs`/`gate_coverage.rs` untouched by intent, both green | ||
| 78 | +in the suite below. | ||
| 79 | + | ||
| 80 | +## Suite | ||
| 81 | +`$HOME/.cache/rectchroma2-suite-r1.log`: SUITE_RESULT | ||
| 82 | + | ||
| 83 | +## Residue | ||
| 84 | +- accepted: `predict_scaled_kern` (scaled reference / superres) got the same fix by construction | ||
| 85 | + but is not exercised by this gate -- superres rect-chroma has no aomenc recipe on this lane. | ||
| 86 | +- deferred(lane-interedge merge): that lane's frame-edge gate can now become a FULL-PLANE arm; | ||
| 87 | + its luma-only compare was a workaround for exactly this defect. | ||