forge
Explore
Log in

Don't you dare go Hollow

NZ_MAP_CTX_OFFSET_32X64/_64X32 were transposed

Browse files at this commit

621d55b64f4bc0240141da01a83f665968b7cda3Ahmet Kaan GümüşParent: 4f7d6d1
  • fix
    • NZ_MAP_CTX_OFFSET_32X64/_64X32 were transposed
Show full message
fix(av1): NZ_MAP_CTX_OFFSET_32X64/_64X32 were transposed

Re-derived from libaom's own generating formula in
get_nz_map_ctx_from_stats (txb_common.h:199-210) and hand-verified
against the raw 1024-entry arrays in txb_common.c. lane-sbpart r8 landed
these tables transposed; VERT-64 (32x64) luma is now bit-exact against
the oracle trace for the pinned seed-42 block, all six ctx/pos/level
reads matching.

This also RETIRES round 2's diagnosis, which I had charted as fact:
there is no missing SCAN_32X64/SCAN_64X32 table. libaom's scan.c:1877
says both TX_32X64 and TX_64X32 use default_scan_32x32 outright ("Half
of the coefficients of tx64 at higher frequencies are set to zeros. So
tx32's scan order is used"), and our existing scan32 = default_scan(TX32)
at decode.rs:3559 matched the oracle's (row,col) walk exactly for every
scan step of the pinned block. The defect was one table over.

Committed by the orchestrator at the agent's turn cap.
crates/ec-av1/src/cdf.rsmodified+27 -10
@@ -770,22 +770,39 @@ pub const NZ_MAP_CTX_OFFSET_32: [[u8; 5]; 5] = [
770 /// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart770 /// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart
771 /// r8 root cause) is genuinely rectangular, not square. Distinct from771 /// r8 root cause) is genuinely rectangular, not square. Distinct from
772 /// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`.772 /// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`.
773+// lane-part32 r3: this table was TRANSPOSED (row/col swapped) as landed by
774+// lane-sbpart r8 -- caught by tracing a real aomenc pin against a patched
775+// aomdec (added per-symbol `EC_TRACE_COEFF` ctx prints to
776+// `read_coeffs_reverse{,_2d}` in `~/.cache/aom-oracle`), which showed our own
777+// `(row=2, col=0)` reading ctx-offset 11 where the real decoder's equivalent
778+// position read 6. Re-derived straight from libaom's own generating
779+// comment in `get_nz_map_ctx_from_stats` (`txb_common.h:199-210`): for
780+// `width < height` (this table, `TX_32X64`), ctx is `11 +` for `row < 2`
781+// *regardless of col* -- the old table instead special-cased `col < 2`,
782+// which is the `width > height` (`TX_64X32`) branch. Confirmed against the
783+// real `av1_nz_map_ctx_offset_32x64`/`_64x32` C arrays in
784+// `av1/common/txb_common.c`, decoded through libaom's own col-major
785+// `pos = col*32+row` raster (same convention [`SCAN_32X16`]'s doc comment
786+// already documents this decoder transcribes out of).
773 pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [787 pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [
774- [0, 11, 6, 6, 21],788+ [0, 11, 11, 11, 11],
775- [11, 11, 6, 21, 21],789+ [11, 11, 11, 11, 11],
776- [11, 11, 21, 21, 21],790+ [6, 6, 21, 21, 21],
777- [11, 11, 21, 21, 21],791+ [6, 21, 21, 21, 21],
778- [11, 11, 21, 21, 21],792+ [21, 21, 21, 21, 21],
779 ];793 ];
780 794
781 /// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom795 /// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom
782 /// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner.796 /// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner.
797+/// `width > height` here, so the `col < 2` branch (offset 16) fires
798+/// regardless of row -- transpose of [`NZ_MAP_CTX_OFFSET_32X64`]'s `row < 2`
799+/// branch, same r3 fix (see that table's doc comment).
783 pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [800 pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [
784- [0, 16, 16, 16, 16],801+ [0, 16, 6, 6, 21],
785- [16, 16, 16, 16, 16],802+ [16, 16, 6, 21, 21],
786- [6, 6, 21, 21, 21],803+ [16, 16, 21, 21, 21],
787- [6, 21, 21, 21, 21],804+ [16, 16, 21, 21, 21],
788- [21, 21, 21, 21, 21],805+ [16, 16, 21, 21, 21],
789 ];806 ];
790 807
791 /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a808 /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a