From 7881dbc946267a170be810ae4df5e69892f93209 Mon Sep 17 00:00:00 2001 From: raylitebull <287713799+raylitebull@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:19:34 +0100 Subject: [PATCH] bcpack: preserve all 32 indices in BC7 dictionary entry 0 In bcpack-tables.bin, BC7 dictionary entry 0 stores all 32 signed i16 indices directly after its two width bytes, while entries 1..254 repeat the two width bytes before 31 i16 indices. Skipping a u16 on entry 0 dropped its leading index (2) and shifted its remaining indices left by one ([1, 0, ...] instead of [2, 1, 0, ...]). Keep the repeated-width skip only for entries 1..254, regenerate crates/xcl/src/hle/bcpack/tables.rs, and verify BC7[0] in tests. --- crates/xcl/src/hle/bcpack/tables.rs | 2 +- crates/xcl/src/hle/bcpack/tests.rs | 8 +++++++- scripts/gen_bcpack_victory_tables.py | 13 ++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/xcl/src/hle/bcpack/tables.rs b/crates/xcl/src/hle/bcpack/tables.rs index cd1ced830..5b5cd3d87 100644 --- a/crates/xcl/src/hle/bcpack/tables.rs +++ b/crates/xcl/src/hle/bcpack/tables.rs @@ -1438,7 +1438,7 @@ pub static BC6: [(Bc6Ep, Bc6Ix); DICTIONARY] = [ (Bc6Ep { e: [[45056, 40960, 38400], [0, 38912, 45056], [29696, 37888, 36864], [12288, 26624, 45056]] }, Bc6Ix { mode: 8, ix: [-4, 3, -2, -3, -2, 0, -3, -3, 1, -2, -4, -3, 2, -3, -3, -3] }), ]; pub static BC7: [(Bc7Ep, Bc7Ix); DICTIONARY] = [ - (Bc7Ep { ctrl: 0, rows: [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] }, Bc7Ix { bits: [4, 0], ix: [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] }), + (Bc7Ep { ctrl: 0, rows: [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] }, Bc7Ix { bits: [4, 0], ix: [[2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] }), (Bc7Ep { ctrl: 1, rows: [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] }, Bc7Ix { bits: [3, 0], ix: [[1, 0, 0, 0, 0, 0, -1, -1, 0, -1, 0, 0, 0, -1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] }), (Bc7Ep { ctrl: 4, rows: [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] }, Bc7Ix { bits: [4, 0], ix: [[4, 5, 3, 4, 4, 4, 4, 3, 4, 4, 5, 4, 5, 4, 4, 4], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] }), (Bc7Ep { ctrl: 5, rows: [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]] }, Bc7Ix { bits: [4, 0], ix: [[2, -2, -4, -2, 3, -2, -4, -2, -2, 1, -4, -3, -2, -1, -4, -3], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] }), diff --git a/crates/xcl/src/hle/bcpack/tests.rs b/crates/xcl/src/hle/bcpack/tests.rs index 396c0f438..70c425a95 100644 --- a/crates/xcl/src/hle/bcpack/tests.rs +++ b/crates/xcl/src/hle/bcpack/tests.rs @@ -103,9 +103,15 @@ fn junk_streams_do_not_panic() { } /// The BC7 dictionary indices follow VIctory PR #658: a set with 0 bits holds no -/// indices, and pixel 0 is the anchor (top bit clear). +/// indices, and pixel 0 is the anchor (top bit clear). Entry 0 stores all 32 indices +/// directly without the repeated width word, keeping its leading `[2, 1, 0, ...]` values. #[test] fn bc7_dictionary_indices_line_up() { + let (ep0, ix0) = super::tables::BC7[0]; + assert_eq!(ep0.ctrl, 0); + assert_eq!(ix0.bits, [4, 0]); + assert_eq!(ix0.ix[0], [2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + assert_eq!(ix0.ix[1], [0; 16]); for (k, (_, ix)) in super::tables::BC7.iter().enumerate() { assert!(ix.bits[0] > 0, "entry {k}: the first index set has no bits"); let hi = 1i16 << (ix.bits[0] - 1); diff --git a/scripts/gen_bcpack_victory_tables.py b/scripts/gen_bcpack_victory_tables.py index 83073c746..46d62cd72 100644 --- a/scripts/gen_bcpack_victory_tables.py +++ b/scripts/gen_bcpack_victory_tables.py @@ -5,8 +5,8 @@ Layout is that of the format's constant tables: 128 x 9 u16 model frequencies, the rank tables, 512 u16 BC7 control words, then 255 dictionary entries per format. -BC7 entries follow VIctory PR #658: after the two index widths, two bytes repeat -them and there are 16 + 15 signed indices, not 32. +BC7 entry 0 stores all 32 signed indices directly after its two index widths; entries +1..254 repeat the two width bytes first and store 16 + 15 signed indices (VIctory PR #658). python -I scripts/gen_bcpack_victory_tables.py """ @@ -74,12 +74,15 @@ def plain(ep, ix): ix = [r.i16() for _ in range(16)] bc6.append((e, mode, ix)) bc7 = [] - for _ in range(DICTIONARY): + for entry in range(DICTIONARY): ctrl = r.u16() ep = [r.u16() for _ in range(24)] bits = [r.u8(), r.u8()] - r.u16() # the widths again; not indices - ix = [r.i16() for _ in range(31)] + [0] # set 1 has 15 slots, unused + if entry == 0: + ix = [r.i16() for _ in range(32)] + else: + r.u16() # the widths again; not indices + ix = [r.i16() for _ in range(31)] + [0] # set 1 has 15 slots, unused bc7.append((ctrl, ep, bits, ix)) assert r.i == len(r.b), (r.i, len(r.b))