BCPack: decode BC7 dictionary blocks correctly; run unfilled indirect records empty #218

Manually merged
github merged 2 commits from github-bot/gh-218 into gh-pr/218/base 2026-12-05 22:43:34 +00:00 AGit
Owner

@⁠ambrosia-works on GitHub · 2026-12-05 21:37 UTC · original
ambrosia-works:fix/bc7-dictionary-indirect-bounds → main · +93 −12 · 4 files · 2 commits · merged 2026-12-05 21:40 UTC

Summary

Two correctness fixes ported from the cool_fox fork. Neither is GPU-vendor specific.

1. BCPack: BC7 dictionary indices were read one pixel early

Each BC7 dictionary entry stores two index widths, then 32 index words. The decoder treated the first word as padding and read only 31 indices. That shifted every stored index one pixel early. The console's decoder (GDK BCPackDecompress) reads the first word as pixel 0's index.

On the title's own streams, the old reading gave wrong output for 3.85 M of 4.70 M BC7 blocks (measured in cool_fox across 5,270 logged streams). Textures decoded through the dictionary came out subtly wrong, character textures included.

  • Tables::parse now reads all 32 words. LARP_BCPACK_OLD_BC7=1 keeps the old reading for A/B.
  • The switch is added to the dstorage decoded-bytes store's identity, so cached entries from one reading are never served under the other. Editing bcpack.rs already invalidates the store through bcpack::IDENTITY, so existing caches rebuild by themselves.
  • New unit test bc7_dictionary_indices_line_up.

2. Indirect: unfilled records run empty instead of running clamped

The title leaves all ones in indirect argument slots it has not filled. Until now these were clamped and then run anyway:

  • Draw records: a slot became 2^24 vertices an instance and used up the list's budget. Records of 2^23 or more vertices or indices an instance now run empty and charge nothing.
  • Mesh records: a slot became 65,535 groups whose meshlets read the garbage beside it, past every buffer. Mesh records over 65,535 groups now run empty and are not counted as asked.
  • Direct DispatchMesh: dispatches over 65,535 groups (D3D12's limit; above it the behaviour is undefined) are cut to 65,535 and logged once.

Verification

  • cargo test --release --locked -p larp-formats bcpack: passes.
  • Byte-for-byte check against the console decoder: a captured 64-block BC7 stream from a character texture, decoded with the fix, equals GDK BCPackDecompress output, and the old reading does not. I ran this as a local-only test, not committed because the fixture is game data.
  • The indirect clamp HLSL compiles with fxc /T cs_5_1, the profile the layer uses at run time.
  • cargo check --release --locked -p larp: no new warnings.
  • Not yet A/B'd in-game on this branch.

Ported from cool_fox 7243ed8f and a9c2e911 / ef556e42, the latter after victory-fork f85101b6.

**@⁠ambrosia-works** on GitHub · 2026-12-05 21:37 UTC · [original](https://github.com/gamingwithhomie/larp/pull/218) `ambrosia-works:fix/bc7-dictionary-indirect-bounds` → `main` · +93 −12 · 4 files · 2 commits · merged 2026-12-05 21:40 UTC ## Summary Two correctness fixes ported from the cool_fox fork. Neither is GPU-vendor specific. ### 1. BCPack: BC7 dictionary indices were read one pixel early Each BC7 dictionary entry stores two index widths, then 32 index words. The decoder treated the first word as padding and read only 31 indices. That shifted every stored index one pixel early. The console's decoder (GDK `BCPackDecompress`) reads the first word as pixel 0's index. On the title's own streams, the old reading gave wrong output for **3.85 M of 4.70 M BC7 blocks** (measured in cool_fox across 5,270 logged streams). Textures decoded through the dictionary came out subtly wrong, character textures included. - `Tables::parse` now reads all 32 words. `LARP_BCPACK_OLD_BC7=1` keeps the old reading for A/B. - The switch is added to the dstorage decoded-bytes store's identity, so cached entries from one reading are never served under the other. Editing `bcpack.rs` already invalidates the store through `bcpack::IDENTITY`, so existing caches rebuild by themselves. - New unit test `bc7_dictionary_indices_line_up`. ### 2. Indirect: unfilled records run empty instead of running clamped The title leaves all ones in indirect argument slots it has not filled. Until now these were clamped and then run anyway: - **Draw records:** a slot became 2^24 vertices an instance and used up the list's budget. Records of 2^23 or more vertices or indices an instance now run empty and charge nothing. - **Mesh records:** a slot became 65,535 groups whose meshlets read the garbage beside it, past every buffer. Mesh records over 65,535 groups now run empty and are not counted as asked. - **Direct `DispatchMesh`:** dispatches over 65,535 groups (D3D12's limit; above it the behaviour is undefined) are cut to 65,535 and logged once. ## Verification - `cargo test --release --locked -p larp-formats bcpack`: passes. - Byte-for-byte check against the console decoder: a captured 64-block BC7 stream from a character texture, decoded with the fix, equals GDK `BCPackDecompress` output, and the old reading does not. I ran this as a local-only test, not committed because the fixture is game data. - The indirect clamp HLSL compiles with `fxc /T cs_5_1`, the profile the layer uses at run time. - `cargo check --release --locked -p larp`: no new warnings. - Not yet A/B'd in-game on this branch. Ported from cool_fox `7243ed8f` and `a9c2e911` / `ef556e42`, the latter after victory-fork `f85101b6`.
The word after a BC7 dictionary entry's index widths is pixel 0's index,
not padding: the console's decoder (GDK BCPackDecompress) reads 32
indices starting there. Skipping it put every stored index one pixel
early, so BC7 blocks built from the dictionary decoded wrong (in the
origin fork's capture, 3.85 M of 4.70 M BC7 blocks of the title's
streams differed). With this reading, the decoder matches
BCPackDecompress byte for byte on a captured character-texture stream.

LARP_BCPACK_OLD_BC7=1 keeps the old reading for A/B. The switch is part
of the decoded-bytes store's identity, so cached entries of one reading
are never served to the other; the source change itself already
invalidates the store.

Ported from cool_fox 7243ed8f.
The title leaves all ones in indirect slots it has not filled. Such
records were clamped and then run: a draw record became 2^24 vertices
an instance, and a mesh record became 65,535 groups whose meshlets read
the garbage beside it, past every buffer.

- A draw record of 2^23 or more vertices or indices an instance is no
  draw of the title's: it runs empty and charges nothing to the list's
  budget.
- A mesh record over 65,535 groups runs empty and is not counted as
  asked.
- A direct DispatchMesh over 65,535 groups (D3D12's limit; more is
  undefined) is cut to 65,535, said once in the log.

The clamp shader is compiled with fxc cs_5_1, as the layer compiles it at
run time.

Ported from cool_fox a9c2e911 / ef556e42 (after victory-fork f85101b6).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 21:39:58 +00:00
github-bot changed target branch from main to gh-pr/218/base 2026-12-05 21:48:34 +00:00
github-bot referenced this pull request from a commit 2026-12-05 22:43:29 +00:00
github manually merged commit 037e2b7a75 into gh-pr/218/base 2026-12-05 22:43:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.