Lane-lr r6 -- rule out lr_sample, isolate dense-arm 1-LSB gap
Browse files at this commitc4474e0ad94b74b5d2276c6676dcbc41dea118b2Parent: 0a1c0e8- docs
- lane-lr r6 -- rule out lr_sample, isolate dense-arm 1-LSB gap
1 changed file +106 -0
- lanes/lr.report.md +106 -0
lanes/lr.report.mdmodified+106 -0
| @@ -334,3 +334,109 @@ loops, and confirming no regression (235/0). Did not reach the gate or | |||
| 334 | either pixel filter -- see "Next lever" above; r3 should start there | 334 | either pixel filter -- see "Next lever" above; r3 should start there |
| 335 | directly rather than re-reading libaom (this doc + `restoration.rs`'s own | 335 | directly rather than re-reading libaom (this doc + `restoration.rs`'s own |
| 336 | doc comments now carry every file:line needed). | 336 | doc comments now carry every file:line needed). |
| 337 | + | ||
| 338 | +## r6 -- VERDICT: not green, still one pixel. Real progress: the | ||
| 339 | +r5-reported divergence source is now DISPROVEN and a decisive, | ||
| 340 | +reusable ground-truth harness exists. Did not commit (no green step; | ||
| 341 | +all edits this round were temporary diagnostics, reverted with `git | ||
| 342 | +checkout --` before finishing -- tree is bit-identical to 02a08bf). | ||
| 343 | + | ||
| 344 | +**Decisive new evidence** (`/tmp/claude-*/scratchpad/lr_sgr_harness.c`, | ||
| 345 | +linked against the real `~/.cache/aom-oracle/build/libaom.a`, calling | ||
| 346 | +the actually-exported `av1_apply_selfguided_restoration_c` / | ||
| 347 | +`av1_selfguided_restoration_c` directly -- not a hand-transcribed | ||
| 348 | +reimplementation, the real compiled function): | ||
| 349 | +- Dumped the exact `lr_sample`-boundary-substituted 102x10 byte buffer | ||
| 350 | + our own `compute_ab`/`apply_sgrproj_stripe` uses for the failing | ||
| 351 | + pixel (V plane, seed 46, ep=6/xqd=[-16,-32], stripe [60,64) of the | ||
| 352 | + 96x64 chroma plane, row 61 col 6) to `/tmp/lr_full.bin`, via a temp | ||
| 353 | + `EC_LR_DUMP`-gated `eprintln!`/`std::fs::write` in | ||
| 354 | + `apply_sgrproj_stripe` (since reverted). | ||
| 355 | +- Fed that *exact same buffer* to the real libaom function (chunked to | ||
| 356 | + width=64 matching libaom's own `RESTORATION_PROC_UNIT_SIZE` | ||
| 357 | + splitting -- `av1_apply_selfguided_restoration_c`'s internal | ||
| 358 | + fixed-size arrays overflow above that, segfault first attempt, | ||
| 359 | + fixed by chunking like `sgrproj_filter_stripe` does). Real libaom, | ||
| 360 | + given identical input pixels, produces **194** (matches ffmpeg) -- | ||
| 361 | + proving the bug is not in `lr_sample`/stripe-boundary substitution | ||
| 362 | + at all (r5's suspicion), since both implementations read the same | ||
| 363 | + bytes and only ours is wrong. | ||
| 364 | +- Also called `av1_selfguided_restoration_c` directly to get the | ||
| 365 | + pre-combine `flt0`/`flt1`: real `flt0[1][6]=3097` (matches our | ||
| 366 | + Rust's fast/r0 arm exactly), real `flt1[1][6]=3109` vs our Rust's | ||
| 367 | + `3110` -- **the divergence is entirely in the dense/r1 arm**, not | ||
| 368 | + the fast arm r5 flagged as the unverified half. | ||
| 369 | +- Instrumented `compute_ab` directly (temp `eprintln!`, reverted) to | ||
| 370 | + dump the 9 individual A/B taps (`c,u,d,l,r,ul,ur,dl,dr`) the dense | ||
| 371 | + combine at (i=1,j=6) actually uses, and independently recomputed | ||
| 372 | + every one from the raw dumped bytes via a clean Python box-sum (not | ||
| 373 | + the earlier untrusted `/tmp/lr_ref.c`/`/tmp/lr_probe.c`) -- **all 9 | ||
| 374 | + match exactly** (`ab1: c=(251,922) u=(254,303) d=(224,6502) | ||
| 375 | + l=(252,700) r=(249,1344) ul=(253,422) ur=(253,486) dl=(241,2974) | ||
| 376 | + dr=(171,17543)`), and the combine formula (weight 4/3, `nb=5`, | ||
| 377 | + `SGRPROJ_SGR_BITS+5-SGRPROJ_RST_BITS` shift) reproduces `3110` | ||
| 378 | + exactly from those 9 values by hand -- so `compute_ab`'s per-cell | ||
| 379 | + math (box sum, `SGR_X_BY_XPLUS1`/`SGR_ONE_BY_X` lookup, rounding) is | ||
| 380 | + internally self-consistent with a naive centered-window recompute, | ||
| 381 | + AND matches the real libaom answer for 8 of 9 taps that a *separate* | ||
| 382 | + cross-check against `boxsum1`'s real sliding-window source | ||
| 383 | + (`restoration.c:418-483`) traced by hand this round confirms is | ||
| 384 | + mathematically equivalent to a naive per-position 3x3 sum for every | ||
| 385 | + physical row/col our grid needs (the sliding-window's own 2-tap | ||
| 386 | + boundary special cases only fire at `local index 0` / the far edge, | ||
| 387 | + both outside the `physical -1..h` range this stripe's grid touches). | ||
| 388 | +- Net: given all 9 A/B taps individually reproduce via a from-scratch | ||
| 389 | + box-sum recompute of the real bytes, but the combined `flt1` still | ||
| 390 | + disagrees with the real compiled function by exactly the 1 LSB that | ||
| 391 | + explains the whole defect, the remaining unaccounted gap is narrow | ||
| 392 | + but NOT yet pinned to a single line -- either one of the 9 taps | ||
| 393 | + itself differs from what real libaom's *compiled* `boxsum`/ | ||
| 394 | + `calculate_intermediate_result` computes (despite the hand-traced | ||
| 395 | + sliding-window algebra saying it shouldn't), or there is a rounding | ||
| 396 | + mode difference (`ROUND_POWER_OF_TWO` for negative/tie values, | ||
| 397 | + `2*(bit_depth-8)` pre-rounds that are no-ops at 8-bit but were not | ||
| 398 | + independently verified as no-ops in the compiled binary) not yet | ||
| 399 | + checked against the real function's per-tap output directly. | ||
| 400 | + | ||
| 401 | +**Ruled out this round** (do not redo): | ||
| 402 | +- `lr_sample`/stripe-boundary substitution as the cause -- disproven | ||
| 403 | + directly (see above), not just re-verified by hand. | ||
| 404 | +- The fast (`r0=2`) arm -- `flt0` matches the real compiled function | ||
| 405 | + bit-exact. r5's charter guess that this was the unverified half was | ||
| 406 | + wrong; it turned out to be already correct. | ||
| 407 | +- `compute_ab`'s formula/table lookup being *generically* wrong -- 8 | ||
| 408 | + of 9 taps match a from-scratch recompute of the real bytes exactly, | ||
| 409 | + and the combine weights/shift match libaom's source line-for-line. | ||
| 410 | +- The earlier `/tmp/lr_ref.c`/`/tmp/lr_probe.c` "194 vs self-inconsistent" | ||
| 411 | + claim from r5 -- irrelevant now; the new harness supersedes it with a | ||
| 412 | + real linked answer, not a hand transcription. | ||
| 413 | + | ||
| 414 | +**Start here (r7)**: get a per-tap ground-truth number directly out of | ||
| 415 | +the compiled libaom binary instead of hand-tracing `boxsum1` further -- | ||
| 416 | +`av1_selfguided_restoration_c` only returns the final `flt0`/`flt1`, | ||
| 417 | +not the intermediate `A`/`B` arrays (`calculate_intermediate_result` is | ||
| 418 | +`static`). Two ways to get them: (a) build a *second* aom-oracle copy | ||
| 419 | +with `calculate_intermediate_result` changed from `static` to | ||
| 420 | +exported-and-declared-in-a-header (rebuild is the `scripts/build-aom-oracle.sh` | ||
| 421 | +recipe, ~5min), then call it directly with the same 9 physical | ||
| 422 | +positions and diff against the 9 values dumped above; or (b) bisect by | ||
| 423 | +zeroing individual pixels in the dumped buffer one at a time and | ||
| 424 | +re-running the harness against both the real function and a | ||
| 425 | +from-scratch recompute to see which single input pixel's value moves | ||
| 426 | +the two answers apart. (a) is more direct. The harness itself | ||
| 427 | +(`av1_apply_selfguided_restoration_c` call pattern, chunked to | ||
| 428 | +width=64, `tmpbuf` sized `2*400*400` -- undersizing it segfaults, see | ||
| 429 | +`RESTORATION_UNITPELS_MAX`) is reusable as-is; a copy is in this | ||
| 430 | +worktree's scratchpad | ||
| 431 | +(`/tmp/claude-1000/.../scratchpad/lr_sgr_harness.c`, | ||
| 432 | +`lr_sgr_harness`), not committed (scratch, not source). | ||
| 433 | + | ||
| 434 | +## Turn budget (r6) | ||
| 435 | +Spent on: building + debugging the real-libaom-linked harness (one | ||
| 436 | +segfault from undersizing the internal tmpbuf, fixed), the input-buffer | ||
| 437 | +dump wiring in `restoration.rs`, and the 9-tap cross-check (including | ||
| 438 | +chasing down two of my own Python transcription bugs mid-round -- | ||
| 439 | +lesson: rerun a "found the bug" number at least once before trusting | ||
| 440 | +it, both false positives here were stale/mistyped variable state, not | ||
| 441 | +real). Ran out of budget before pinning the exact source-level cause; | ||
| 442 | +r7 should start at option (a) above, not redo any of the ruled-out list. | ||