BCPack: lanes_strip rounds with AVX-512 (3x faster unpacking) #3798
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3798"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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):
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.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-formatsnow 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: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: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.
oracle_parity_all_formats_and_strip_boundaries,oracle_parity_all_bc7_modes_rotations_subsetsandoracle_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.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 testpassed for the crates it touches: yes, apart from the 3 tests that already fail on main.Checked for overlap
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ColorC on 2026-11-30T08:58:53Z.
Verification on AMD Ryzen 7 9800X3D (Zen 5, full-width AVX-512) (
-C target-cpu=znver5, ThinLTO release build):cargo test -p victory-formats --lib --lockedpassed86 passed; 0 failed(with the BC7 oracle fix applied in our branch), includingbcpack::tests::the_vector_rounds_decode_what_the_scalar_ones_do ... ok.30.1 FPS(33.9 ms), Max43.0 ms,0/48windows > 50 ms,0texture/decode errors, no blurry/missing streamed textures observed.Test Setup
--res 1440 --dlss quality --framegen 3 --fps 1000)-C target-cpu=znver5) rebased onmain(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.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 theneed/stalledflags thatwide.rsreads 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) onmain5fabb46e, with you as co-author.What I changed, and why:
pdep, and their bytes are fetched byvpexpandb.main,lanes_striphas a burst ofmin(left, remaining) - 1rounds 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.Tests:
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.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_lanesnow covers BC2's layout too.mainwithout #2419.cargo clippy -p victory-formats --all-targets -- -D warningsandcargo xtask policy --stagedare clean.rust-versionbump 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,main5fabb46eagainst the rebase: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.
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.
Pull request closed