From c0a6d4471d05be17e713f668e0deb2e18b360b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 14:23:35 +0300 Subject: [PATCH] docs(lane): lossless report -- rules, fixtures, deferred --- lanes/lossless.report.md | 67 +++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/lanes/lossless.report.md b/lanes/lossless.report.md index 4198704e..595d44ca 100644 --- a/lanes/lossless.report.md +++ b/lanes/lossless.report.md @@ -1,42 +1,33 @@ # lane-lossless — AV1 lossless (qindex 0) decode -Branch `lane-lossless`, base `7ba28bcd`. Status: IN PROGRESS. +Branch `lane-lossless`, base `7ba28bcd`. Status: KEY-frame half SHIPPED, inter half refused by name. -## Done (commits b56bb30f, d26c55bb wip) -- `transform.rs::inverse_wht4x4` — libaom `av1_iwht4x4_16_add_c` - (`aom_dsp/inv_txfm.c:22`), inputs shifted by `UNIT_QUANT_SHIFT` (2). Test - `transform::lossless_tx_tests::the_walsh_hadamard_round_trip_is_exact` PASSES. -- `TxParams::lossless` + `dequant_and_inverse_wht4x4`: the residual of a - lossless unit comes off the WHT, not the DCT/ADST network - (`av1/common/idct.c` `inv_txfm_add`: `if (txfm_param->lossless) { assert(tx_type - == DCT_DCT); av1_iwht4x4_add(...); return; }`). -- Per-frame `CodedLossless` flag (`decode::set_lossless`/`lossless`), set in - `stream.rs` where the refusal used to be. A frame MIXING lossless and lossy - segments is still refused by name (all rules are per segment there). -- TX_4X4 forcing: `decode_block` (tables/scans/tx swapped to the 4x4 ones), - `decode_leaf8`, and `depth_to_tx_wh` (every HORZ/VERT strip reader) -- - libaom `read_tx_size` (`decodeframe.c`): `if (xd->lossless[segment_id]) - return TX_4X4;` before anything else. -- No `tx_type` symbol, DCT_DCT on every plane: libaom `read_tx_type` - (`decodetxb.c`) returns early at `qindex == 0`; `av1_get_tx_type` - (`blockd.h`) returns DCT_DCT for a lossless block. -- `is_cfl_allowed` narrowing (`blockd.h`): under lossless CfL is offered only - when the chroma plane block is BLOCK_4X4, i.e. a luma block <= 8x8 - (`decode::cfl_allowed_px`, the one point every intra reader routes through). -- `txb_skip_chroma_4` widened 3 -> 6 rows: `get_txb_ctx`'s `+10` rows - (chroma plane block larger than its transform) are reachable at TX_4X4 only - on a lossless frame -- `av1_default_txb_skip_cdfs[0][TX_4X4][10..13]` = - 9961/30242/32117 and are the neutral 16384 in every other q-context, which - is libaom's own confirmation of the rule. +## Rules implemented (each with its libaom reference) +| rule | libaom | where | +|---|---|---| +| TX_4X4 on every plane, no `tx_depth`/`txfm_split` symbol | `read_tx_size` (`av1/decoder/decodeframe.c`): `if (xd->lossless[..]) return TX_4X4;` before `max_txsize_rect_lookup` | `decode::lossless_tx`, `decode_block`, `decode_leaf8`, `depth_to_tx_wh`, `read_block_tx_size`(+`_rect`), `read_inter_luma8` | +| Walsh-Hadamard inverse instead of DCT/ADST | `inv_txfm_add` (`av1/common/idct.c`): `if (txfm_param->lossless) { assert(tx_type == DCT_DCT); av1_iwht4x4_add(...); }`; kernel `av1_highbd_iwht4x4_16_add_c` (`av1/common/av1_inv_txfm2d.c:20`), inputs `>> UNIT_QUANT_SHIFT` (2) | `transform::inverse_wht4x4` / `dequant_and_inverse_wht4x4`, `TxParams::lossless` | +| no `tx_type` symbol | `read_tx_type` (`av1/decoder/decodetxb.c`): "No need to read transform type for lossless mode(qindex==0)" | `read_plane`/`read_inter_plane`/`read_inter_plane_rect`: `coding.tx_type = None` | +| DCT_DCT on every plane (so the default scan) | `av1_get_tx_type` (`av1/common/blockd.h`): lossless returns DCT_DCT | same three readers' `default_tx_type` | +| `is_cfl_allowed` narrows to a BLOCK_4X4 chroma plane block (luma <= 8x8 at 4:2:0) | `is_cfl_allowed` (`av1/common/blockd.h`) | `decode::cfl_allowed_px`, used by every intra mode reader | +| chroma coded as 4x4 units, plane-major, with `get_txb_ctx`'s `+10` rows | `decode_token_recon_block` mu-chunk loop; `av1_default_txb_skip_cdfs[0][TX_4X4][10..13]` = 9961/30242/32117 (neutral 16384 in every other q-context) | `decode_rect_split` lossless chroma branch; `cdf_state::txb_skip_chroma_4` widened 3 -> 6 rows | +| loop filter / CDEF / LR off | header-level (`coded_lossless`/`all_lossless`), already handled by the frame-header parser | unchanged | +| a frame mixing lossless and lossy segments | every rule above is per segment | refused by name | -## Remaining -- The 64x64 synthetic key frame (`ffmpeg -c:v libaom-av1 -crf 0 -b:v 0`) now - parses the whole tile but still differs from ffmpeg at luma sample 0: - desync is inside the first block's coefficients (mode syntax of block 1 - matches aomdec's `EC_ISTEP`, block 2's range does not). -- Inter-frame readers (`decode_inter_block*`, sub8) not yet forced to TX_4X4. -- Filter-stage skips (deblock/CDEF/LR) are header-driven and believed already - handled by the header parser; unverified. -- Fixtures + gates: none added yet; the retired refusal gate - `a_lossless_libaom_stream_is_refused_by_name` still asserts the old refusal - and will FAIL until it is swapped for the decode-exact gate. +WHT orientation is pinned by MEASUREMENT: libaom's column-then-row-with-transpose +loop equals rows-then-columns in place on a raster grid; the other orientation +reconstructs sample 0 and DC-only units correctly and drifts +-1 elsewhere. + +## Fixtures and results (all `ffmpeg -c:v libaom-av1 -crf 0 -b:v 0`, synthetic source) +| fixture | result | +|---|---| +| 64x64, 1 key frame, 8-bit | EXACT vs ffmpeg (0/6144 samples differ); 6488 entropy steps identical to aomdec `EC_TRACE_COEFF` | +| 256x128, 2 key frames (`-g 1`), 8-bit | EXACT both frames — pinned as `stream::tests::a_lossless_libaom_key_frame_decodes_sample_exact` | +| 192x96, 2 key frames, 10-bit | EXACT both frames | +| 128x64, 4 frames (`-g 4`, inter) | refused by name — pinned as `stream::tests::a_lossless_inter_frame_is_refused_by_name` | + +## Deferred +- `deferred: lossless INTER frames — an inter block's chroma plane is still read as one transform per block (decode_inter_block's two chroma sites + the 128 mu-chunk loop); its luma leaves are already synthesized as TX_4X4 — unblocks: port the 4x4 chroma unit walk (the shape decode_rect_split's lossless branch already has) into decode_inter_block/decode_inter_block8/the sub8 readers.` +- `deferred: the 12-frame bd_rate_screen_native gate's libaom crf-5 point — that stream's inter frames now hit the named refusal instead of decoding, so the deciding gate cannot be green this round — unblocks: the inter chroma walk above.` +- `deferred: mixed lossless/lossy segments — refused by name; no libaom recipe emits one — unblocks: a segmentation fixture with per-segment qindex.` +- `deferred: 4:4:4 / monochrome lossless — the crate is 4:2:0 only.`