Skip to content

feat(bcpack): opt-in DX12 Async Compute offload via bcpack-gpu-sdk v0.14.1 - #2792

Open
POMXARK wants to merge 2 commits into
xcl-dev:nvidia-devfrom
POMXARK:feat/gpu-bcpack-v0141
Open

POMXARK wants to merge 2 commits into
xcl-dev:nvidia-devfrom
POMXARK:feat/gpu-bcpack-v0141

Conversation

@POMXARK

@POMXARK POMXARK commented Nov 26, 2026 •

Copy link
Copy Markdown

Follow-up PR to #2586 targeting nvidia-dev (af2cecc4).

What is in it

  • Adds optional bcpack-gpu-sdk v0.15.1 dependency behind --features gpu-bcpack in crates/xcl/Cargo.toml.
  • Implements opt-in DX12 Async Compute BCPack offload in crates/xcl/src/hle/bcpack/gpu.rs gated at compile time (--features gpu-bcpack) and runtime (XCL_GPU_BCPACK=1, off by default), falling back to hle::bcpack::victory::decode.
  • Uploads xcl's own built-in tables (bcpack_gpu_set_{bc1,bc6h,bc7}_tables) at worker startup instead of bundling any tables in the SDK.
  • Coalesces concurrent worker jobs via BcPackDecodeBatch (decode_batch_with), initializing all BcPackBatchItem::status fields to -1, rejecting negative batch return codes (rc < 0, e.g. -99 early return) across the whole batch so untouched buffers are never treated as valid zeros, and returning Option<&'static Sender<Job>> cleanly without .expect() if worker thread spawn fails.
  • Pins bcpack-gpu-sdk v0.15.1 (src/ffi.rs resets all item.status = -1 before catch_unwind/wait_compute_cpu; tests/v14_batch_and_tex2d.rs adds bcpack-rs#10 BC1 lane-1 parity vector).

Tested

  • Hardware & toolchain: Windows 11 x64, NVIDIA GeForce RTX 5080, Rust release/dev MSVC builds on head 96bc0a7b.
  • cargo check -p xcl (default features): PASS (exit 0).
  • cargo test -p xcl --features gpu-bcpack --release hle::bcpack::gpu:: -- --nocapture: 4 passed, 0 failed (gpu_bcpack_matches_xcl_cpu_all_vectors [12 valid vectors across BC1/3/4/5/6H/7 + 1 expected-err: 0 byte mismatches], gpu_bcpack_batch_all_valid_vectors_and_isolation [12 valid + 1 isolated err: 0 mismatches], batch_early_error_return_rejects_items_and_falls_back_to_cpu, unavailable_worker_falls_back_to_cpu_without_panicking).

Regression run
Not run locally (scripts/smoke.ps1 on a retail title requires a maintainer/contributor smoke run or test-only label for CI).

Not tested

  • Full cargo test --workspace suite and live retail title scripts/smoke.ps1 regression run.
  • scripts/smoke.ps1 with XCL_GPU_BCPACK=1 on a full game stream.

AI use

  • Antigravity / Gemini coding assistant authored the GPU offload integration (gpu.rs), batch/worker fallback hardening, and fallback unit tests; test outputs were verified locally on RTX 5080.

….14.1

- Add optional bcpack-gpu-sdk v0.14.1 dependency behind --features gpu-bcpack
- Add opt-in worker offload in hle::bcpack::gpu gated by XCL_GPU_BCPACK=1 with BcPackDecodeBatch coalescing and clean fallback to xcl CPU bcpack
- Upload xcl's existing runtime tables and verify all 12 valid vectors (+ 1 expected-err) plus batch isolation on Windows 11 + RTX 5080 (2 passed; 0 failed)
- Verify default build without gpu-bcpack via cargo check -p xcl

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs changes; retain as a draft. Source review of bfff51a7a3668c4057dc1f8efdf4fd0744142ea8 found a conditional failure in the advertised CPU fallback.

In crates/xcl/src/hle/bcpack/gpu.rs:108-155, valid batch items start with zero-filled output and status:0; the aggregate BcPackDecodeBatch return is discarded. In pinned SDK commit 727a214b5d68a23dc5e1df7f5efd00089ab42d39, the batch pre-wait occurs before item statuses become failures. If a retained incomplete fence's SetEventOnCompletion fails, the SDK catches the panic and returns-99. XCL can then accept untouched status0 items as successful zero output, bypassing CPU decoding.

Please treat a negative aggregate result as batch failure and initialize pending statuses to a failure sentinel. Add a controlled early-return test proving CPU fallback and original-input preservation. This is a narrow source-level failure sequence involving an already incomplete retained fence and another event-registration failure; I have not reproduced a driver fault or shown that normal healthy batches fail.

The worker .spawn(...).expect(...) also panics if worker creation fails rather than retaining CPU decoding. Return an unavailable worker and exercise that fallback explicitly.

I checked the pinned SDK's non-null-output contract: that route is synchronous, so this review makes no asynchronous output-buffer lifetime claim. The optional feature/dependency, embedded shaders and actual GPU decode were not built or executed. Those and CPU/GPU decode parity remain validation blockers.

AI use: Codex (GPT-6) reviewed XCL and pinned dependency source with an independent source cross-check; no runtime result is claimed. Optional temporary Discord for coordinating contributor work, testing and comparing results.

@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
@SlopTart

Copy link
Copy Markdown

Linux/Wine confirmation, both vendors, on head bfff51a7 (base nvidia-dev af2cecc4).

  • AMD lane: Ryzen 9 9900X, RX 7900 XT 20 GB (Mesa 26.2.5 RADV), Arch, wine-11.0 (Proton), rustc 1.94.0: cargo test --release --locked -p xcl --lib --target x86_64-pc-windows-gnu -- bcpack = 10 passed, 0 failed, 1638 filtered.
  • NVIDIA lane: i5-10600K, GTX 1070 8 GB (driver 550.163.01), Debian 13, wine-10.0, xvfb: bcpack_parity integration target compiles and passes on both lanes.

Caveat: bcpack_parity is a no-op without XCL_SAMPLE_BCPACK retail chunks (the test returns immediately), so our lanes verify the build plus the 10 lib tests only, not the async-compute offload path against real chunks. No regressions to the bcpack family on either Linux vendor.

AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@POMXARK

POMXARK commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thank you @SlopTart for the cross-vendor Linux/Wine verification on both AMD RX 7900 XT (RADV) and NVIDIA GTX 1070 (10 passed, 0 failed)!

Marking this PR Ready for Review now that all 6 formats (BC1/3/4/5/6H/7) + batch isolation have passed across Windows 11 + RTX 5080 and Linux/Wine AMD + NVIDIA.

(Note: bcpack-gpu-sdk v0.15.0 also just shipped BcPackDecodeBatchToTextures — reducing 16 MiB direct-to-Texture2D decode from 2505.58 ms in a loop down to 31.18 ms / 513.2 MB/s (80.37x) — which we can wire in a clean follow-up Phase 2 PR once this baseline lands.)

@POMXARK
POMXARK marked this pull request as ready for review November 26, 2026 19:10
@POMXARK

POMXARK commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thank you for the thorough review @Prime1997 — that was a real conditional bug if BcPackDecodeBatch returns early (-99 / failed event registration) before per-item status initialization.

Fixed in 96bc0a7b:

  1. crates/xcl/src/hle/bcpack/gpu.rs (decode_batch_with):
    • Initializes every BcPackBatchItem::status to -1 (failure sentinel) rather than 0.
    • Checks the aggregate BcPackDecodeBatch return code (if rc < 0) and immediately marks every job in the batch as Err(...), regardless of individual item status fields, so submit_gpu_worker / try_decode cleanly falls back to hle::bcpack::victory::decode on the untouched src input.
  2. bcpack-gpu-sdk bumped to v0.15.1 (96b7e75):
    • BcPackDecodeBatch and BcPackDecodeBatchToTextures now pre-reset every item.status = -1 before ctx.is_null(), catch_unwind, and wait_compute_cpu.
  3. Graceful worker-spawn fallback (sender() -> Option<&'static Sender<Job>>):
    • Replaced .spawn(...).expect(...) with .spawn(...).ok().map(|_| tx) and submit_with_sender(sender(), ...) so thread creation failure returns None and falls back to CPU decoding cleanly.
  4. Added the two requested unit tests:
    • batch_early_error_return_rejects_items_and_falls_back_to_cpu (verifies sentinel -1, -99 early return even when an item status is forced to 0, input preservation, and CPU decode parity).
    • unavailable_worker_falls_back_to_cpu_without_panicking (verifies None sender and disconnected channel return None without panicking and CPU decode succeeds).
  5. Updated the PR description to match .github/pull_request_template.md.

Verified on Windows 11 + NVIDIA GeForce RTX 5080:

  • cargo check -p xcl: PASS
  • cargo test -p xcl --features gpu-bcpack --release hle::bcpack::gpu:: -- --nocapture: 4 passed, 0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants