Complete BC2 BCPack decoding and fix terminal lane scheduling #2092

Merged
wish131400 merged 1 commit from upstream-pr/2092 into main 2026-11-30 14:12:04 +00:00
wish131400 commented 2026-11-29 09:20:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wish131400 on 2026-11-29T09:20:09Z.


Fixes #2085

What it changes

Current main rejects 99 of 1,076 independent synthetic BCPack cases: 25 BC1, 49 BC2 and 25 BC4. This patch reconstructs all 1,076 byte for byte, using the existing DirectStorage decoder entry point and without a developer SDK or calibration profile at runtime.

  • Add BC2's fifteen-lane layout, fixed initial dictionary/rank constants, explicit-alpha predictor and independent colour-index predictor.
  • Give each lane a request-wide output budget, apply output-slot backpressure, stop finished lanes taking bytes, and handle terminal draining and omitted flush zeros. Reject invalid terminal/reserved states and nonzero tails; accept zero padding.
  • Retain main's packed model lookup, packed block reconstruction and 256-block strips. Interior payload rounds fuse the two scheduling phases safely. Blocks write directly into the supplied destination, with bounded strip/history scratch and no full-request record buffer or extra output copy.
  • Preserve the production BC7 parser fixed in f9de61c5, correct the still-stale scalar test oracle, and check every dictionary index at its independent binary offset. The old test encoder's filler fragments are removed because finished lanes now stop asking for bytes.
  • Add 1,076 synthetic packed inputs with independent output length/hash pairs, plus DirectStorage BC2 regressions for file/memory input and zlib-before-BCPack. Expected outputs are never generated by the decoder under test. No game data or decoded texture snapshots are included.

Adapted from Mandy #2567, revision cb947eac0d1b46ac8a5938d06a17fe7bd95cfe12, while retaining the newer NVIDIA optimizations. The BC2 constants originate in the public MIT Xbox2Windows #3293. The existing binary tables are unchanged. docs/bcpack.md records provenance and regression reproduction; third-party notices accompany the port. Research included implementation inspection and synthetic API queries; no strict clean-room claim is made, and no SDK binaries/private headers/disassembly are shipped. Implementation and review were AI-assisted with Codex.

How it was tested

  • GPU and profile: not applicable to the CPU format/DirectStorage reproducer. No game restart, release-package replacement, GPU sampling or gameplay/FPS validation was performed.
  • Before, at 829188e969ffd2907e5867c5d9aca29bd91cb1b6: 977 exact matches, 99 rejected, zero differing successful outputs. Three existing format tests fail because the scalar BC7 oracle still skips a word.
  • After: 1,076/1,076 full-byte matches in the local independent audit; committed SDK-free hash regressions cover BC1-BC7, all fourteen BC6H modes, 285 valid BC7 controls, dictionary/history references, flush/reset cases and requests up to 1,024 blocks. Truncation, padding, nonzero tails and canaries are checked too.
  • cargo test -p victory-formats -p victory-hle --locked -- --test-threads=1: passed, 84 format tests, 424 HLE unit tests and 2 HLE integration tests; 7/5 existing ignored tests respectively.
  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings: passed.
  • cargo xtask policy --staged: passed, all 14 changed/new files. Importer --check and git diff --cached --check: passed.
  • A local optimized microbenchmark on identical 1,024-block synthetic random inputs retained approximately the base throughput across the six previously supported formats (about -1.3% to +3.6% in that run). This is a small CPU measurement on a shared machine, not a frame-rate claim.
  • Shader wave sizes: not applicable.

Broader checks have existing limitations, left visible here:

  • The default parallel HLE suite hit xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it once; the complete serial run above passed. That file is unchanged by this PR.
  • HLE Clippy with -D warnings is blocked in unchanged main code: unused PAIR_MEETINGS / analysis::lane_regions, while_immutable_condition in shader lowering, and unused unwind_copy in the loader.
  • Whole-tree cargo xtask policy is blocked by the unchanged crates/victory-loader/src/heap_sites/frame_users.rs (2,022 hex digits in a literal run). The staged patch passes independently.

Checked for overlap

  • Searched open issues/PRs for BCPack, BC2 and BC7 and inspected the overlapping files. #623 changes BCPack scheduling for performance; its alternate C lane path must satisfy these independent cases before selection. #614 and #1633 mention BCPack but concern other CPU/memory paths.
  • Related: #1272 reports multiple storage/loading failure types. This PR does not claim to fix that entire crash report.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549357221 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2092). Originally posted by [wish131400](https://github.com/wish131400) on 2026-11-29T09:20:09Z. --- Fixes #2085 ## What it changes Current main rejects 99 of 1,076 independent synthetic BCPack cases: 25 BC1, 49 BC2 and 25 BC4. This patch reconstructs all 1,076 byte for byte, using the existing DirectStorage decoder entry point and without a developer SDK or calibration profile at runtime. - Add BC2's fifteen-lane layout, fixed initial dictionary/rank constants, explicit-alpha predictor and independent colour-index predictor. - Give each lane a request-wide output budget, apply output-slot backpressure, stop finished lanes taking bytes, and handle terminal draining and omitted flush zeros. Reject invalid terminal/reserved states and nonzero tails; accept zero padding. - Retain main's packed model lookup, packed block reconstruction and 256-block strips. Interior payload rounds fuse the two scheduling phases safely. Blocks write directly into the supplied destination, with bounded strip/history scratch and no full-request record buffer or extra output copy. - Preserve the production BC7 parser fixed in `f9de61c5`, correct the still-stale scalar test oracle, and check every dictionary index at its independent binary offset. The old test encoder's filler fragments are removed because finished lanes now stop asking for bytes. - Add 1,076 synthetic packed inputs with independent output length/hash pairs, plus DirectStorage BC2 regressions for file/memory input and zlib-before-BCPack. Expected outputs are never generated by the decoder under test. No game data or decoded texture snapshots are included. Adapted from [Mandy #2567](https://github.com/ProjectLeonida/mandy/pull/2567), revision `cb947eac0d1b46ac8a5938d06a17fe7bd95cfe12`, while retaining the newer NVIDIA optimizations. The BC2 constants originate in the public MIT [Xbox2Windows #3293](https://github.com/R0Y00/Xbox2Windows/pull/3293). The existing binary tables are unchanged. `docs/bcpack.md` records provenance and regression reproduction; third-party notices accompany the port. Research included implementation inspection and synthetic API queries; no strict clean-room claim is made, and no SDK binaries/private headers/disassembly are shipped. Implementation and review were AI-assisted with Codex. ## How it was tested - GPU and profile: not applicable to the CPU format/DirectStorage reproducer. No game restart, release-package replacement, GPU sampling or gameplay/FPS validation was performed. - Before, at `829188e969ffd2907e5867c5d9aca29bd91cb1b6`: 977 exact matches, 99 rejected, zero differing successful outputs. Three existing format tests fail because the scalar BC7 oracle still skips a word. - After: 1,076/1,076 full-byte matches in the local independent audit; committed SDK-free hash regressions cover BC1-BC7, all fourteen BC6H modes, 285 valid BC7 controls, dictionary/history references, flush/reset cases and requests up to 1,024 blocks. Truncation, padding, nonzero tails and canaries are checked too. - `cargo test -p victory-formats -p victory-hle --locked -- --test-threads=1`: **passed**, 84 format tests, 424 HLE unit tests and 2 HLE integration tests; 7/5 existing ignored tests respectively. - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings`: **passed**. - `cargo xtask policy --staged`: **passed**, all 14 changed/new files. Importer `--check` and `git diff --cached --check`: **passed**. - A local optimized microbenchmark on identical 1,024-block synthetic random inputs retained approximately the base throughput across the six previously supported formats (about -1.3% to +3.6% in that run). This is a small CPU measurement on a shared machine, not a frame-rate claim. - Shader wave sizes: not applicable. Broader checks have existing limitations, left visible here: - The default parallel HLE suite hit `xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it` once; the complete serial run above passed. That file is unchanged by this PR. - HLE Clippy with `-D warnings` is blocked in unchanged main code: unused `PAIR_MEETINGS` / `analysis::lane_regions`, `while_immutable_condition` in shader lowering, and unused `unwind_copy` in the loader. - Whole-tree `cargo xtask policy` is blocked by the unchanged `crates/victory-loader/src/heap_sites/frame_users.rs` (2,022 hex digits in a literal run). The staged patch passes independently. ## Checked for overlap - [x] Searched open issues/PRs for BCPack, BC2 and BC7 and inspected the overlapping files. **#623** changes BCPack scheduling for performance; its alternate C lane path must satisfy these independent cases before selection. #614 and #1633 mention BCPack but concern other CPU/memory paths. - Related: #1272 reports multiple storage/loading failure types. This PR does not claim to fix that entire crash report.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!2092
No description provided.