Files
VIctory-NVIDIA/docs/bcpack.md

5.6 KiB

BCPack BC1-BC7 decoding

victory_formats::bcpack::decode reconstructs BC1, BC2, BC3, BC4, BC5, BC6H and BC7 blocks. The DirectStorage path in victory-hle already routes the BC format option to this function, including zlib followed by BCPack. No developer SDK, runtime calibration or fitted predictor profile is needed.

Correctness change

The submission base is 829188e969ffd2907e5867c5d9aca29bd91cb1b6. Its production BC7 dictionary parser already reads all 32 signed indices in each 116-byte record (fixed in f9de61c5); this change preserves that fix and updates the scalar test oracle, which still skipped the first index.

BC2 was unsupported. It now uses its fifteen-lane layout, fixed initial dictionary and rank table. Explicit 4-bit alpha follows the endpoint reference; colour indices follow their separate reference.

The lane scheduler tracks each lane's output budget for the entire request. It grants up to eight input bytes, publishes pending symbols with output-slot backpressure, and then advances the lanes. Finished lanes stop taking bytes while their neighbours drain. Flushed fragments can omit up to two zero bytes; these restore the lane state without consuming input from another lane. Reserved entropy slots, invalid terminal states, truncated input and nonzero trailing bytes are errors. Zero padding is accepted.

The current NVIDIA packed model lookup, packed index arithmetic, BC6H/BC7 reconstruction and 256-block strips are retained. Interior payload rounds fuse input/output grants and lane stepping while preserving the two-phase schedule. Only one strip of records is staged; reconstructed blocks go directly into the caller's destination and the 256-entry history carries across strips. There is no full-request record allocation or additional output copy. On error, earlier strips may already have written destination bytes, as before.

Provenance

The scheduler and BC2 reconstruction are adapted from the standalone Rust fix in Mandy #2567, revision cb947eac0d1b46ac8a5938d06a17fe7bd95cfe12. The source is GPL-3.0-or-later, as is this repository. Implementation and review were AI-assisted with Codex.

The public MIT BC2 format constants and reconstruction originate in Xbox2Windows #3293, revision d049001ab9a906588f47868277b77e9a00e27053. Only the BC2 companion constants are added as Rust text; the existing bcpack-tables.bin is unchanged. Third-party notices accompany the port.

Research included developer implementation inspection and synthetic API queries; this is not described as a strict clean-room implementation. No SDK binary, private header, disassembly, title input, title-derived output or fitted data is included. The SDK was only a local synthetic test oracle; users and CI do not need it.

Independent synthetic regressions

The 1,076 cases imported from Mandy's synthetic fixture consist of 950 streams from an independent symbol encoder, with expected bytes from GDK BCPackDecompress, and 126 GDK compressor/decompressor roundtrips of synthetic BC blocks. They cover all fourteen BC6H modes, 285 valid BC7 controls, separate endpoint/index dictionary references, history wrap, fragment resets, omitted flush zeros and requests up to 1,024 blocks.

Tests store synthetic packed inputs and independent output length/hash pairs, not decoded texture snapshots. The importer computes FNV-1a over the original oracle output without invoking the implementation under test. The cases are split by format so every generated source file stays below the asset-policy size limit. There are no title inputs or images.

Format Base exact / rejected Fixed exact / rejected
BC1 24 / 25 49 / 0
BC2 0 / 49 49 / 0
BC3 49 / 0 49 / 0
BC4 24 / 25 49 / 0
BC5 49 / 0 49 / 0
BC6H 497 / 0 497 / 0
BC7 334 / 0 334 / 0
Total 977 / 99 1,076 / 0

The initial local audit compared complete output bytes, independently of the committed hash checks. Additional checks exercise truncated requests, zero padding, nonzero tails, output canaries and malformed input. The scalar test oracle uses division and full-request records; it is separate from the packed strip path. The former test encoder's filler fragments are removed because a finished lane now stops requesting bytes.

Run the SDK-free checks with:

cargo test -p victory-formats --locked
cargo test -p victory-hle --locked modules::dstorage::tests -- --test-threads=1
cargo clippy -p victory-formats --all-targets --locked -- -D warnings

To reproduce the generated cases, obtain tests/fixtures/bcpack-standalone.txt from the Mandy revision above into a directory outside this repository, then:

python tools/gen_bcpack_goldens.py --fixture <outside-repo-fixture> --check

Omit --check to regenerate the Rust test inputs. The source fixture's expected outputs must not be replaced with output from this decoder.

Scope and overlap

Open #623 also changes BCPack scheduling for performance. This is a correctness fix against current main; any alternate C scheduler should satisfy these independent cases before being selected. The changes in #614 and #1633 concern other CPU/memory paths.

This work verifies packed-block decoding and synthetic DirectStorage requests. It does not establish a game frame-rate improvement or a fix for the multiple distinct loading failures reported in #1272. GPU sampling, detiling and shader translation are separate stages.