RFC: Opt-in DX12 Async Compute BCPack (All 6 Formats: BC1/BC3/BC4/BC5/BC6H/BC7) + AMD Gfx10 Detile via bcpack-gpu-sdk v0.13.0 #15

Open
opened 2026-11-26 03:31:18 +00:00 by github-bot · 1 comment
Owner

@⁠POMXARK on GitHub · 2026-11-25 23:34 UTC · original

Hi! We built POMXARK/bcpack-gpu-sdk (v0.13.0, dual-licensed MIT OR Apache-2.0, clean-room HLSL SM 6.6 + DXIL + Vulkan 1.3 SPIR-V, compatible with VIctory's GPL-3.0-or-later) and verified a minimal opt-in prototype patch hooking victory-hle/src/modules/dstorage.rs across all 6 BCPack formats (BC1, BC3, BC4, BC5, BC6H, BC7).

1. Where This Helps (and Where It Does Not)

  • Helps:
    • Offloads DirectStorage BCPack decompression from CPU worker threads onto DX12 Async Compute (bcpack_gpu::ffi::BcPackDecodeAsync), freeing CPU cores during heavy texture streaming and helping reduce late texture pop-in in city chases.
    • Also includes a standalone AMD Gfx10 micro-tile / 64KB_D / 4KB_S compute detiler (gfx10_detile.hlsl) and an SM 6.6 ResourceDescriptorHeap[] virtual pager (VirtualDescriptorPager, bindless_paging.hlsl) relevant to NVIDIA's PORTABLE_VIEWS = 1_000_000 descriptor heap ceiling.
  • Does not solve on its own:
    • The main 48 ms single-thread prepare / 36k–67k draw-call CPU bottleneck or card (41 ms) submission time.
    • The custom compute BVH ray-tracing shaders (XboxBvhBuilder.dll / native 64B & 128B BVH nodes; there is no DXR API call to intercept).

2. Verified Bit-Exact Parity Against victory_formats::bcpack::decode (12/12 PASS)

Tested via victory_hle::modules::dstorage::gpu_bcpack::tests::gpu_bcpack_matches_victory_cpu against POMXARK/bcpack-gpu-sdk tag v0.13.0 (7b79cbd) on Windows 11 + NVIDIA RTX 5080 (cargo test --release -p victory-hle --features gpu-bcpack gpu_bcpack_matches_victory_cpu -- --nocapture, TEST_RC=0, 1 passed; 0 failed, 0 warnings in victory-hle, victory, and bcpack-gpu-sdk):

Format Chunk Mode Scope Covered Result vs victory_formats::bcpack::decode
BC1 (32 KiB, 4096 blocks) no-ref & full-ref+dict rank1, ep_ref, ix_ref, 255-entry dict, 256-hist 0 byte mismatches
BC3 (32 KiB, 2048 blocks) no-ref & full-ref+dict Alpha+colour pairs/quads, 255-entry dict, 256-hist 0 byte mismatches
BC4 (32 KiB, 4096 blocks) no-ref & full-ref+dict 1-channel pairs, 255-entry dict, 256-hist 0 byte mismatches
BC5 (32 KiB, 2048 blocks) no-ref & full-ref+dict 2-channel pairs, 255-entry dict, 256-hist 0 byte mismatches
BC6H (32 KiB, 2048 blocks) no-ref & full-ref+dict All Modes 1–14 (incl. ascending Modes 13–14), 255-entry dict, 256-hist 0 byte mismatches
BC7 (32 KiB, 2048 blocks) no-ref & full-ref+dict All Modes 0–7, rotations, sel, p-bits, ctrl7, 255-entry dict, 256-hist 0 byte mismatches

Why runtime table setters (bcpack_gpu_set_{bc1,bc6h,bc7}_tables)?

  • In bcpack-rs's data/bc7.json, all 255 BC7 dictionary ix arrays are shifted 1 pixel (2 bytes) early into the u16 width field compared to victory-formats/src/bcpack-tables.bin, and its default BC1 path omits ix_ref/dict prediction.
  • Adding runtime table setters in bcpack-gpu-sdk v0.13.0 lets VIctory upload rank1, ctrl7, and its bc1/bc6h/bc7 dictionaries at worker init from victory-formats's bcpack-tables.bin while keeping bcpack-gpu-sdk 100% clean-room (MIT OR Apache-2.0, zero proprietary tables embedded).

3. Phase 1: Ready & Verified Today (--features gpu-bcpack + VICTORY_GPU_BCPACK=1)

  • Feature-gated at compile time: --features gpu-bcpack (Cargo.toml, crates/victory-hle/Cargo.toml, apps/victory/Cargo.toml). Default builds omit bcpack-gpu-sdk completely (0 changes to default dependencies).
  • Env-gated at runtime: VICTORY_GPU_BCPACK=1 (off by default) and VICTORY_GPU_BCPACK_MIN_KB (default 32 KiB).
  • Hook point (crates/victory-hle/src/modules/dstorage.rs): inside into_destination(request, size, |out| ...) via BcPackDecodeAsync just before bcpack::decode(...). Preserves full guest memory compatibility (safe when guest CPU reads back decoded buffers) with transparent fallback to victory_formats::bcpack::decode on disabled/small chunks (< VICTORY_GPU_BCPACK_MIN_KB, verified in test) or adapter errors.

4. Proposed Next Steps (Phase 2 & NVIDIA Support — Seeking Feedback First)

  1. Zero-copy ID3D12Device path (victory-gpu / VICTORY_LAND):
    • Attach bcpack_gpu_create_from_device directly to victory-gpu's ID3D12Device / ID3D12CommandQueue and route VRAM-bound textures (VICTORY_LAND / copy queue) through BcPackDecodeToBuffer / BcPackDecodeToTexture2D + inline gfx10_detile, eliminating CPU readback for texture streaming while keeping BcPackDecodeAsync for CPU-readable guest buffers.
  2. NVIDIA Support (PORTABLE_VIEWS = 1_000_000 vs 2^22 with RAW_TWINS = 1 << 21):
    • Currently on NVIDIA DX12 (crates/victory-gpu/src/descriptor/host.rs), probe_view_limit() sees the PORTABLE_VIEWS = 1_000_000 cap and clamps retail views >= 1,000,000 to the null slot, whereas UNCAPPED_VIEWS + RAW_TWINS (1 << 21) expects a 2^22-slot heap.
    • We can pair a 2^22-slot non-shader-visible staging descriptor heap in descriptor/host.rs with dynamic VirtualDescriptorPager (g_VirtToPhys[]) indirection in victory-shader (ResourceDescriptorHeap[g_VirtToPhys[idx]], preserving RAW_TWINS pairs) to run cleanly within NVIDIA's < 1M shader-visible limit.

Questions before opening a PR / touching victory-shader:

  1. Would you accept an optional feature-gated bcpack-gpu-sdk (MIT OR Apache-2.0) dependency behind --features gpu-bcpack?
  2. Are you planning any near-term refactors to crates/victory-gpu/src/descriptor/host.rs or victory-shader before we prototype and benchmark the NVIDIA descriptor pager on RTX 5080?
**@⁠POMXARK** on GitHub · 2026-11-25 23:34 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/15) Hi! We built [`POMXARK/bcpack-gpu-sdk`](https://github.com/POMXARK/bcpack-gpu-sdk) (`v0.13.0`, dual-licensed `MIT OR Apache-2.0`, clean-room HLSL SM 6.6 + DXIL + Vulkan 1.3 SPIR-V, compatible with `VIctory`'s `GPL-3.0-or-later`) and verified a minimal opt-in prototype patch hooking `victory-hle/src/modules/dstorage.rs` across **all 6 BCPack formats (`BC1`, `BC3`, `BC4`, `BC5`, `BC6H`, `BC7`)**. - **Prototype patch Gist (clean UTF-8 diff, 5 files, opt-in behind `--features gpu-bcpack`):** https://gist.github.com/POMXARK/f72b3f0f503f63e57cf54c3240f8c5f6 - **SDK release (`v0.13.0`):** https://github.com/POMXARK/bcpack-gpu-sdk/releases/tag/v0.13.0 (`bcpack_gpu.dll`, `bcpack_gpu.dll.lib`, `bcpack_gpu.h`) ### 1. Where This Helps (and Where It Does Not) - **Helps:** - Offloads DirectStorage BCPack decompression from CPU worker threads onto DX12 Async Compute (`bcpack_gpu::ffi::BcPackDecodeAsync`), freeing CPU cores during heavy texture streaming and helping reduce late texture pop-in in city chases. - Also includes a standalone **AMD Gfx10 micro-tile / `64KB_D` / `4KB_S` compute detiler** (`gfx10_detile.hlsl`) and an SM 6.6 `ResourceDescriptorHeap[]` virtual pager (`VirtualDescriptorPager`, `bindless_paging.hlsl`) relevant to NVIDIA's `PORTABLE_VIEWS = 1_000_000` descriptor heap ceiling. - **Does not solve on its own:** - The main `48 ms` single-thread `prepare` / `36k–67k` draw-call CPU bottleneck or `card` (`41 ms`) submission time. - The custom compute BVH ray-tracing shaders (`XboxBvhBuilder.dll` / native 64B & 128B BVH nodes; there is no DXR API call to intercept). ### 2. Verified Bit-Exact Parity Against `victory_formats::bcpack::decode` (12/12 PASS) Tested via `victory_hle::modules::dstorage::gpu_bcpack::tests::gpu_bcpack_matches_victory_cpu` against `POMXARK/bcpack-gpu-sdk` tag `v0.13.0` (`7b79cbd`) on **Windows 11 + NVIDIA RTX 5080** (`cargo test --release -p victory-hle --features gpu-bcpack gpu_bcpack_matches_victory_cpu -- --nocapture`, `TEST_RC=0`, `1 passed; 0 failed`, `0` warnings in `victory-hle`, `victory`, and `bcpack-gpu-sdk`): | Format | Chunk Mode | Scope Covered | Result vs `victory_formats::bcpack::decode` | |---|---|---|---| | **BC1** (`32 KiB`, `4096` blocks) | `no-ref` & `full-ref+dict` | `rank1`, `ep_ref`, `ix_ref`, 255-entry dict, 256-hist | **0 byte mismatches** | | **BC3** (`32 KiB`, `2048` blocks) | `no-ref` & `full-ref+dict` | Alpha+colour pairs/quads, 255-entry dict, 256-hist | **0 byte mismatches** | | **BC4** (`32 KiB`, `4096` blocks) | `no-ref` & `full-ref+dict` | 1-channel pairs, 255-entry dict, 256-hist | **0 byte mismatches** | | **BC5** (`32 KiB`, `2048` blocks) | `no-ref` & `full-ref+dict` | 2-channel pairs, 255-entry dict, 256-hist | **0 byte mismatches** | | **BC6H** (`32 KiB`, `2048` blocks) | `no-ref` & `full-ref+dict` | All **Modes 1–14** (incl. ascending Modes 13–14), 255-entry dict, 256-hist | **0 byte mismatches** | | **BC7** (`32 KiB`, `2048` blocks) | `no-ref` & `full-ref+dict` | All **Modes 0–7**, rotations, sel, p-bits, `ctrl7`, 255-entry dict, 256-hist | **0 byte mismatches** | > **Why runtime table setters (`bcpack_gpu_set_{bc1,bc6h,bc7}_tables`)?** > - In `bcpack-rs`'s `data/bc7.json`, all 255 BC7 dictionary `ix` arrays are shifted 1 pixel (2 bytes) early into the `u16` width field compared to `victory-formats/src/bcpack-tables.bin`, and its default `BC1` path omits `ix_ref`/dict prediction. > - Adding runtime table setters in `bcpack-gpu-sdk v0.13.0` lets `VIctory` upload `rank1`, `ctrl7`, and its `bc1`/`bc6h`/`bc7` dictionaries at worker init from `victory-formats`'s `bcpack-tables.bin` while keeping `bcpack-gpu-sdk` 100% clean-room (`MIT OR Apache-2.0`, zero proprietary tables embedded). ### 3. Phase 1: Ready & Verified Today (`--features gpu-bcpack` + `VICTORY_GPU_BCPACK=1`) - **Feature-gated at compile time:** `--features gpu-bcpack` (`Cargo.toml`, `crates/victory-hle/Cargo.toml`, `apps/victory/Cargo.toml`). Default builds omit `bcpack-gpu-sdk` completely (`0` changes to default dependencies). - **Env-gated at runtime:** `VICTORY_GPU_BCPACK=1` (off by default) and `VICTORY_GPU_BCPACK_MIN_KB` (default `32` KiB). - **Hook point (`crates/victory-hle/src/modules/dstorage.rs`):** inside `into_destination(request, size, |out| ...)` via `BcPackDecodeAsync` just before `bcpack::decode(...)`. Preserves full guest memory compatibility (safe when guest CPU reads back decoded buffers) with transparent fallback to `victory_formats::bcpack::decode` on disabled/small chunks (`< VICTORY_GPU_BCPACK_MIN_KB`, verified in test) or adapter errors. ### 4. Proposed Next Steps (Phase 2 & NVIDIA Support — Seeking Feedback First) 1. **Zero-copy `ID3D12Device` path (`victory-gpu` / `VICTORY_LAND`):** - Attach `bcpack_gpu_create_from_device` directly to `victory-gpu`'s `ID3D12Device` / `ID3D12CommandQueue` and route VRAM-bound textures (`VICTORY_LAND` / copy queue) through `BcPackDecodeToBuffer` / `BcPackDecodeToTexture2D` + inline `gfx10_detile`, eliminating CPU readback for texture streaming while keeping `BcPackDecodeAsync` for CPU-readable guest buffers. 2. **NVIDIA Support (`PORTABLE_VIEWS = 1_000_000` vs `2^22` with `RAW_TWINS = 1 << 21`):** - Currently on NVIDIA DX12 (`crates/victory-gpu/src/descriptor/host.rs`), `probe_view_limit()` sees the `PORTABLE_VIEWS = 1_000_000` cap and clamps retail views `>= 1,000,000` to the null slot, whereas `UNCAPPED_VIEWS` + `RAW_TWINS` (`1 << 21`) expects a `2^22`-slot heap. - We can pair a `2^22`-slot non-shader-visible staging descriptor heap in `descriptor/host.rs` with dynamic `VirtualDescriptorPager` (`g_VirtToPhys[]`) indirection in `victory-shader` (`ResourceDescriptorHeap[g_VirtToPhys[idx]]`, preserving `RAW_TWINS` pairs) to run cleanly within NVIDIA's `< 1M` shader-visible limit. **Questions before opening a PR / touching `victory-shader`:** 1. Would you accept an optional feature-gated `bcpack-gpu-sdk` (`MIT OR Apache-2.0`) dependency behind `--features gpu-bcpack`? 2. Are you planning any near-term refactors to `crates/victory-gpu/src/descriptor/host.rs` or `victory-shader` before we prototype and benchmark the NVIDIA descriptor pager on RTX 5080?
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:18 +00:00
Author
Owner

@⁠lorddie on GitHub · 2026-11-26 12:54 UTC · original

+1 from an RX 9070 XT + Ryzen 5 5600X (6 cores) machine; I would gladly test this.

On this machine the frame is set by the CPU, not the card. In my runs on Belobug's fork (about 152 ms a frame, about 6.6 fps), the breakdown per frame was:

  • about 25 ms copying title data up (about 82 MB);
  • about 11 ms on bindless plans;
  • about 5.5 ms on textures;
  • about 18.5 ms copying back.

The card was busy only 20–60% of the time. In action scenes the copy-back alone rose to 120–220 ms, and the frame rate fell to 0.5–2 fps. Texture streaming is also visibly late here. Moving BCPack decoding and detiling to the card looks like exactly the right trade for a 6-core CPU paired with a fast card.

I don't have much time to develop it myself, but I can build any branch or patch you post, run it on RDNA4, and report frame times, texture lag and stability, compared with the same scene without it.

**@⁠lorddie** on GitHub · 2026-11-26 12:54 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/15#issuecomment-7192620524) +1 from an RX 9070 XT + Ryzen 5 5600X (6 cores) machine; I would gladly test this. On this machine the frame is set by the CPU, not the card. In my runs on Belobug's fork (about 152 ms a frame, about 6.6 fps), the breakdown per frame was: - about 25 ms copying title data up (about 82 MB); - about 11 ms on bindless plans; - about 5.5 ms on textures; - about 18.5 ms copying back. The card was busy only 20–60% of the time. In action scenes the copy-back alone rose to 120–220 ms, and the frame rate fell to 0.5–2 fps. Texture streaming is also visibly late here. Moving BCPack decoding and detiling to the card looks like exactly the right trade for a 6-core CPU paired with a fast card. I don't have much time to develop it myself, but I can build any branch or patch you post, run it on RDNA4, and report frame times, texture lag and stability, compared with the same scene without it.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#15
No description provided.