BCPack: lanes_strip rounds with AVX-512 (3x faster unpacking) #3798

Closed
fl4rion wants to merge 1 commit from upstream-pr/3798 into main
fl4rion commented 2026-11-30 07:26:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fl4rion on 2026-11-30T07:26:38Z.


What it changes

Texture streaming is limited by BCPack unpacking on the CPU. In a play log, DirectStorage requests holding 1–4 MiB BC1 and BC7 textures took 75–136 ms each to unpack. All 24 DirectStorage workers were busy with it, so new requests waited up to 208 ms for one. Textures show blurry or late while they wait.

Most of that time goes to the rANS lanes, not to rebuilding the blocks. A stream's 12 or 16 lanes advance in rounds. In each round every lane takes at most one step, and the lanes that need input share at most 8 bytes, handed out in lane order. On real data a block needs about 2.5 rounds, and most lane visits in a round do nothing but bookkeeping. One lane at a time, that bookkeeping is the cost.

This PR runs a whole round for all lanes at once with AVX-512, on processors that have AVX-512 F/BW/VL/VBMI2 and BMI2 (Zen 4 and later, Intel server parts and some client parts):

  • Bytes: the lanes that take a byte are the first 8 that want one (pdep). Their bytes are the next ones in the stream, in lane order (vpexpandb). A lane after the eighth taker that needed a byte waits, as before.
  • Steps: reading a byte, decoding a symbol and ending a fragment are done for every lane at once, with masks. Header and length bytes, once per fragment, still go through scalar code.
  • Buckets: each lane keeps its model's bucket starts, frequencies and reciprocals in vector registers, refreshed when a fragment header changes its model. A decode picks its bucket with compares, with no table lookups in the round. An earlier version gathered them from the tables, which put three dependent gathers in every round and was half as fast.

It plugs in at lanes_strip. Lane state still carries over between 256-block strips, and the block reconstruction is untouched. The rounds are exactly the scalar ones, so the bytes each lane takes and the symbols it decodes are identical. Processors without AVX-512 run the existing scalar code unchanged.

victory-formats now declares Rust 1.89, where the AVX-512 intrinsics became stable. The toolchain is pinned at 1.98.1, and the rest of the workspace keeps 1.88.

How it was tested

  • GPU and profile: not applicable; this is CPU-only format code. Measured on a Ryzen 9 7900X (Zen 4), one core, release build.

  • Before / after: five real chunks that a play log flagged as slow (BC1 and BC7, 1–4 MiB of output). Best of 7 runs each, whole decode:

    chunk before (main) after
    BC7, 4 MiB 73.0 ms (57 MB/s) 23.3 ms (180 MB/s)
    BC1, 4 MiB (two chunks) 45.9–47.4 ms (88–91 MB/s) 13.7–13.9 ms (301–307 MB/s)
    BC7, 1 MiB (two chunks) 15.9–19.1 ms (55–66 MB/s) 5.8–5.9 ms (179–182 MB/s)

    The output is byte for byte the same as main's on all five chunks. No game data is included.

  • New test the_vector_rounds_decode_what_the_scalar_ones_do: runs both paths on every format and compares results and output byte for byte, including failures. A test-only switch forces the scalar rounds. Inputs:

    • valid multi-fragment streams across strip boundaries;
    • the same streams cut short;
    • noise on the shipped and synthetic tables;
    • noise on "skewed" tables, which give bucket 0 a single slot (its quotient must stay 0) and frequency 1 to buckets 2 and up (the quotient is the offset). Those are also checked against the oracle.

    Two deliberate bugs are each caught: dropping the bucket-0 guard on the frequency-1 shortcut, and losing a lane's stall flag between strips.

  • Oracle-parity tests: on an AVX-512 machine, upstream's existing parity tests now run the vector path.

    • Three of them, oracle_parity_all_formats_and_strip_boundaries, oracle_parity_all_bc7_modes_rotations_subsets and oracle_parity_errors_and_noise, fail on main already, with or without this PR. The test oracle still reads BC7 dictionary indices the old way, so the mismatches are BC7 index bytes.
    • With the one-line oracle fix from #2419 applied locally (not part of this PR), all 16 BCPack tests pass, both with the vector rounds and with the scalar ones forced.
  • cargo test -p victory-formats --lib --locked: 81 passed. The only 3 failures are the oracle tests above, in release and debug builds.

  • cargo clippy -p victory-formats --all-targets --locked -- -D warnings, and the same with --all-features: clean.

  • cargo xtask policy --staged: ok.

  • cargo test passed for the crates it touches: yes, apart from the 3 tests that already fail on main.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    • #2092 changes the lane rounds near the end of a stream: per-lane output budgets, finished lanes no longer taking bytes, terminal draining. Whichever of the two lands second has to bring the other's rules along. For these rounds that means a mask of finished lanes kept out of the byte hand-out, plus #2092's other terminal rules.
    • #623 (conflicting) rewrites the lanes in Rust and in C for AVX2. This PR does not overlap its other changes.
    • #2419, #2236, #3263 and #3061 fix the stale BC7 oracle that makes the three tests above fail. This PR leaves the oracle alone.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5560930661 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3798). Originally posted by [fl4rion](https://github.com/fl4rion) on 2026-11-30T07:26:38Z. --- ## What it changes Texture streaming is limited by BCPack unpacking on the CPU. In a play log, DirectStorage requests holding 1–4 MiB BC1 and BC7 textures took 75–136 ms each to unpack. All 24 DirectStorage workers were busy with it, so new requests waited up to 208 ms for one. Textures show blurry or late while they wait. Most of that time goes to the rANS lanes, not to rebuilding the blocks. A stream's 12 or 16 lanes advance in rounds. In each round every lane takes at most one step, and the lanes that need input share at most 8 bytes, handed out in lane order. On real data a block needs about 2.5 rounds, and most lane visits in a round do nothing but bookkeeping. One lane at a time, that bookkeeping is the cost. This PR runs a whole round for all lanes at once with AVX-512, on processors that have AVX-512 F/BW/VL/VBMI2 and BMI2 (Zen 4 and later, Intel server parts and some client parts): - **Bytes:** the lanes that take a byte are the first 8 that want one (`pdep`). Their bytes are the next ones in the stream, in lane order (`vpexpandb`). A lane after the eighth taker that needed a byte waits, as before. - **Steps:** reading a byte, decoding a symbol and ending a fragment are done for every lane at once, with masks. Header and length bytes, once per fragment, still go through scalar code. - **Buckets:** each lane keeps its model's bucket starts, frequencies and reciprocals in vector registers, refreshed when a fragment header changes its model. A decode picks its bucket with compares, with no table lookups in the round. An earlier version gathered them from the tables, which put three dependent gathers in every round and was half as fast. It plugs in at `lanes_strip`. Lane state still carries over between 256-block strips, and the block reconstruction is untouched. The rounds are exactly the scalar ones, so the bytes each lane takes and the symbols it decodes are identical. Processors without AVX-512 run the existing scalar code unchanged. `victory-formats` now declares Rust 1.89, where the AVX-512 intrinsics became stable. The toolchain is pinned at 1.98.1, and the rest of the workspace keeps 1.88. ## How it was tested - **GPU and profile:** not applicable; this is CPU-only format code. Measured on a Ryzen 9 7900X (Zen 4), one core, release build. - **Before / after:** five real chunks that a play log flagged as slow (BC1 and BC7, 1–4 MiB of output). Best of 7 runs each, whole `decode`: | chunk | before (main) | after | |---|---|---| | BC7, 4 MiB | 73.0 ms (57 MB/s) | 23.3 ms (180 MB/s) | | BC1, 4 MiB (two chunks) | 45.9–47.4 ms (88–91 MB/s) | 13.7–13.9 ms (301–307 MB/s) | | BC7, 1 MiB (two chunks) | 15.9–19.1 ms (55–66 MB/s) | 5.8–5.9 ms (179–182 MB/s) | The output is byte for byte the same as main's on all five chunks. No game data is included. - **New test `the_vector_rounds_decode_what_the_scalar_ones_do`:** runs both paths on every format and compares results and output byte for byte, including failures. A test-only switch forces the scalar rounds. Inputs: - valid multi-fragment streams across strip boundaries; - the same streams cut short; - noise on the shipped and synthetic tables; - noise on "skewed" tables, which give bucket 0 a single slot (its quotient must stay 0) and frequency 1 to buckets 2 and up (the quotient is the offset). Those are also checked against the oracle. Two deliberate bugs are each caught: dropping the bucket-0 guard on the frequency-1 shortcut, and losing a lane's stall flag between strips. - **Oracle-parity tests:** on an AVX-512 machine, upstream's existing parity tests now run the vector path. - Three of them, `oracle_parity_all_formats_and_strip_boundaries`, `oracle_parity_all_bc7_modes_rotations_subsets` and `oracle_parity_errors_and_noise`, **fail on main already**, with or without this PR. The test oracle still reads BC7 dictionary indices the old way, so the mismatches are BC7 index bytes. - With the one-line oracle fix from #2419 applied locally (not part of this PR), all 16 BCPack tests pass, both with the vector rounds and with the scalar ones forced. - `cargo test -p victory-formats --lib --locked`: 81 passed. The only 3 failures are the oracle tests above, in release and debug builds. - `cargo clippy -p victory-formats --all-targets --locked -- -D warnings`, and the same with `--all-features`: clean. - `cargo xtask policy --staged`: ok. - `cargo test` passed for the crates it touches: yes, apart from the 3 tests that already fail on main. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - **#2092** changes the lane rounds near the end of a stream: per-lane output budgets, finished lanes no longer taking bytes, terminal draining. Whichever of the two lands second has to bring the other's rules along. For these rounds that means a mask of finished lanes kept out of the byte hand-out, plus #2092's other terminal rules. - **#623** (conflicting) rewrites the lanes in Rust and in C for AVX2. This PR does not overlap its other changes. - **#2419, #2236, #3263 and #3061** fix the stale BC7 oracle that makes the three tests above fail. This PR leaves the oracle alone.
ColorC commented 2026-11-30 08:58:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ColorC on 2026-11-30T08:58:53Z.


AI Disclosure: This hardware benchmark, log analysis, and report were automated and posted by an AI assistant on behalf of the hardware owner (Ryzen 7 9800X3D, 32 GB DDR5, RTX 5070 Ti 16 GB, Windows 11 26200). No game screenshots or title assets are included.

Verification on AMD Ryzen 7 9800X3D (Zen 5, full-width AVX-512) (-C target-cpu=znver5, ThinLTO release build):

  • Unit & parity tests: cargo test -p victory-formats --lib --locked passed 86 passed; 0 failed (with the BC7 oracle fix applied in our branch), including bcpack::tests::the_vector_rounds_decode_what_the_scalar_ones_do ... ok.
  • In-game streaming stability: Ran 8+ minutes of automated open-world walking tours (4 min raster + 4 min DXR 1.1 HW RT) at Series X 1440p DLSS Quality + 3x MFG on 9800X3D + RTX 5070 Ti.
    • Raster 4-min walk: Avg 30.1 FPS (33.9 ms), Max 43.0 ms, 0/48 windows > 50 ms, 0 texture/decode errors, no blurry/missing streamed textures observed.

Test Setup

  • Hardware: AMD Ryzen 7 9800X3D (Zen 5, 8C/16T), 32 GB DDR5, NVIDIA RTX 5070 Ti 16 GB (ReBAR ON), Windows 11 26200
  • Profile: Series X, 2560x1440, DLSS Quality, 3x MFG (--res 1440 --dlss quality --framegen 3 --fps 1000)
  • Build: Release ThinLTO (-C target-cpu=znver5) rebased on main (41adb551) with a curated local PR stack; all A/B numbers below are same-binary toggle ablations from the exact same restored save (~10.0k–10.4k draws/frame standing scene) after official 1-time warmup.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273585238 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3798#issuecomment-7273585238). Originally posted by [ColorC](https://github.com/ColorC) on 2026-11-30T08:58:53Z. --- > **AI Disclosure:** This hardware benchmark, log analysis, and report were automated and posted by an AI assistant on behalf of the hardware owner (Ryzen 7 9800X3D, 32 GB DDR5, RTX 5070 Ti 16 GB, Windows 11 26200). No game screenshots or title assets are included. Verification on **AMD Ryzen 7 9800X3D (Zen 5, full-width AVX-512)** (`-C target-cpu=znver5`, ThinLTO release build): - **Unit & parity tests:** `cargo test -p victory-formats --lib --locked` passed **`86 passed; 0 failed`** (with the BC7 oracle fix applied in our branch), including `bcpack::tests::the_vector_rounds_decode_what_the_scalar_ones_do ... ok`. - **In-game streaming stability:** Ran 8+ minutes of automated open-world walking tours (4 min raster + 4 min DXR 1.1 HW RT) at Series X 1440p DLSS Quality + 3x MFG on 9800X3D + RTX 5070 Ti. - Raster 4-min walk: **Avg `30.1 FPS` (`33.9 ms`)**, **Max `43.0 ms`**, **`0/48` windows > 50 ms**, `0` texture/decode errors, no blurry/missing streamed textures observed. ### Test Setup - **Hardware:** AMD Ryzen 7 9800X3D (Zen 5, 8C/16T), 32 GB DDR5, NVIDIA RTX 5070 Ti 16 GB (ReBAR ON), Windows 11 26200 - **Profile:** Series X, 2560x1440, DLSS Quality, 3x MFG (`--res 1440 --dlss quality --framegen 3 --fps 1000`) - **Build:** Release ThinLTO (`-C target-cpu=znver5`) rebased on `main` (`41adb551`) with a curated local PR stack; all A/B numbers below are **same-binary toggle ablations** from the exact same restored save (~10.0k–10.4k draws/frame standing scene) after official 1-time warmup.
mstrmoos commented 2026-12-01 09:39:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-12-01T09:39:21Z.


This no longer applies to main: #2092 landed and changed the lane rounds under it. Lanes now have per-lane output budgets and drain and finished phases, and the need/stalled flags that wide.rs reads and writes are gone. I wanted it in my build, so I've rebased it. In case it saves you time, it's here: mstrmoos:rebase/3798-on-main, one commit (7d1b12dc) on main 5fabb46e, with you as co-author.

What I changed, and why:

  • Your vector decode is kept as it is. Each lane's buckets stay in vectors and are picked by compares. The first 8 lanes that want a byte are found by pdep, and their bytes are fetched by vpexpandb.
  • It now runs only in the payload burst. On main, lanes_strip has a burst of min(left, remaining) - 1 rounds in which every lane is inside a payload, and that's where the time goes. The vector rounds run that burst. Headers, the drain at a fragment's end and the stream's end stay in the scalar rounds, so #2092's rules live in one place, not two.
  • The bucket vectors are kept for the whole strip. They're refreshed only for a lane whose model changed, so a short burst doesn't pay the setup.

Tests:

  • Your the_vector_rounds_decode_what_the_scalar_ones_do, with BC2 added to the noise part. The record generator doesn't make valid BC2 streams yet.
  • A new the_vector_rounds_step_the_lanes_as_the_scalar_ones_do. It covers every lane layout, including BC2's 15 lanes. Inputs are one-fragment and multi-fragment streams across strip boundaries, the same cut short, and noise. It compares the lanes' full state, the records, the stream position and the result.
  • every_layout_round_trips_through_the_lanes now covers BC2's layout too.
  • Planted bugs are caught:
    • taking 7 bytes a round instead of 8 fails 6 tests;
    • dropping the frequency-1 quotient fails 5.
    • Dropping the bucket-0 guard on that shortcut isn't caught, and can't be: when bucket 0's frequency is 1 it holds a single slot, so its offset is always 0.
  • All 18 BCPack tests pass. The oracle-parity tests now pass on main without #2419.
  • cargo clippy -p victory-formats --all-targets -- -D warnings and cargo xtask policy --staged are clean.
  • No rust-version bump is needed any more: the workspace is at 1.89 now.

bcpack_throughput_builtin (shipped tables, 16,384 blocks), release build, Ryzen 7 9800X3D, two runs each, main 5fabb46e against the rebase:

format main rebased
BC1 58.8 MB/s 173.8 MB/s 3.0x
BC3 57.7 179.2 3.1x
BC4 57.8 167.3 2.9x
BC5 57.9 183.9 3.2x
BC6 37.0 110.2 3.0x
BC7 37.7 115.5 3.1x

That's in line with what you measured on the 7900X. These are CPU benchmark numbers only. I haven't put it in a play session yet, and I'll post that separately once I have.

Feel free to take the commit as it is, rework it, or ignore it.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7307013879 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3798#issuecomment-7307013879). Originally posted by [mstrmoos](https://github.com/mstrmoos) on 2026-12-01T09:39:21Z. --- This no longer applies to `main`: #2092 landed and changed the lane rounds under it. Lanes now have per-lane output budgets and drain and finished phases, and the `need`/`stalled` flags that `wide.rs` reads and writes are gone. I wanted it in my build, so I've rebased it. In case it saves you time, it's here: [`mstrmoos:rebase/3798-on-main`](https://github.com/mstrmoos/VIctory-NVIDIA/compare/main...mstrmoos:VIctory-NVIDIA:rebase/3798-on-main), one commit (7d1b12dc) on `main` 5fabb46e, with you as co-author. What I changed, and why: - **Your vector decode is kept as it is.** Each lane's buckets stay in vectors and are picked by compares. The first 8 lanes that want a byte are found by `pdep`, and their bytes are fetched by `vpexpandb`. - **It now runs only in the payload burst.** On `main`, `lanes_strip` has a burst of `min(left, remaining) - 1` rounds in which every lane is inside a payload, and that's where the time goes. The vector rounds run that burst. Headers, the drain at a fragment's end and the stream's end stay in the scalar rounds, so #2092's rules live in one place, not two. - **The bucket vectors are kept for the whole strip.** They're refreshed only for a lane whose model changed, so a short burst doesn't pay the setup. Tests: - **Your `the_vector_rounds_decode_what_the_scalar_ones_do`, with BC2 added to the noise part.** The record generator doesn't make valid BC2 streams yet. - **A new `the_vector_rounds_step_the_lanes_as_the_scalar_ones_do`.** It covers every lane layout, including BC2's 15 lanes. Inputs are one-fragment and multi-fragment streams across strip boundaries, the same cut short, and noise. It compares the lanes' full state, the records, the stream position and the result. - **`every_layout_round_trips_through_the_lanes` now covers BC2's layout too.** - **Planted bugs are caught:** - taking 7 bytes a round instead of 8 fails 6 tests; - dropping the frequency-1 quotient fails 5. - Dropping the bucket-0 guard on that shortcut isn't caught, and can't be: when bucket 0's frequency is 1 it holds a single slot, so its offset is always 0. - **All 18 BCPack tests pass.** The oracle-parity tests now pass on `main` without #2419. - **`cargo clippy -p victory-formats --all-targets -- -D warnings` and `cargo xtask policy --staged` are clean.** - **No `rust-version` bump is needed any more:** the workspace is at 1.89 now. `bcpack_throughput_builtin` (shipped tables, 16,384 blocks), release build, Ryzen 7 9800X3D, two runs each, `main` 5fabb46e against the rebase: | format | main | rebased | | | --- | --- | --- | --- | | BC1 | 58.8 MB/s | 173.8 MB/s | 3.0x | | BC3 | 57.7 | 179.2 | 3.1x | | BC4 | 57.8 | 167.3 | 2.9x | | BC5 | 57.9 | 183.9 | 3.2x | | BC6 | 37.0 | 110.2 | 3.0x | | BC7 | 37.7 | 115.5 | 3.1x | That's in line with what you measured on the 7900X. These are CPU benchmark numbers only. I haven't put it in a play session yet, and I'll post that separately once I have. Feel free to take the commit as it is, rework it, or ignore it.
trustno1-coder commented 2026-12-01 18:48:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:48:36Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321586706 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3798#issuecomment-7321586706). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:48:36Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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!3798
No description provided.