perf(gpu): vectorize texture::digest with VAES/AES-NI and fused zero check #507
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!507
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-507"
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?
@Not4Eric on GitHub · 2026-12-04 20:24 UTC · original
Not4Eric:perf/texture-vaes-digest→main· +281 −22 · 1 files · 1 commits · merged 2026-12-05 17:30 UTCWhat this does
Adds runtime-dispatched x86_64 VAES (
avx512f,vaes,aes) and AES-NI (aes,sse4.1) implementations ofvictory_gpu::texture::digest_and_zerowith scalar fallback, fusing the all-zero check into the same single pass over texture memory. This avoids scanning every staged/fingerprinted texture twice (once for hashing, once forall_zero) and accelerates hashing on CPUs with AES-NI or AVX-512 VAES.Checks
digestis an internal non-cryptographic in-memory change detector, never persisted on disk).digest/digest_and_zero, its callers (Staging,fingerprint_blank,print_of), and its unit test incrates/victory-gpu/src/texture.rs.texture::allocation_costs::digest_and_zero_across_tiersexercising all available runtime tiers (dispatch, scalar, AES-NI, VAES-512) for zero detection, single-bit flips, length sensitivity, and byte-swap sensitivity (cannot exist before this change).texture.rs, notdigest).cargo xtask policypassed (359 files ok); no fork-only files, configs, or build outputs.Verified
cargo xtask policy—359 files okPKG=victory-gpu ./build.sh test --lib -- texture:: --test-threads=1(Proton Wine on Linux, Ryzen 5 7600X with AVX-512/VAES + AES-NI) —12 passed; 0 failed; 3 ignored, 0 warnings (includesdigest_and_zero_across_tierstesting scalar, AES-NI, and VAES-512 tiers)Cost
None (runtime CPU feature detection selects VAES-512 / AES-NI / scalar safely on any x86_64 CPU; 0 new warnings).
AI-assisted: yes
@Kal0s-design on GitHub · 2026-12-04 21:23 UTC · original
Checked
9b9f78eon native Windows with MSVC (didn't run the game).Debug and release builds of victory-gpu are fine with the pinned toolchain, and the intrinsics and target_feature attributes compile cleanly.
digest_and_zero_across_tierspasses andtexture::is 12 passed, 3 ignored. On the full lib suite the only failures are the ones that already fail natively on main (the two indirect host_list tests, the two pipeline::host library loads, and a watch test that passes when rerun alone). All three tiers ran here, and the dispatch picks VAES-512.I also ran a throwaway test of my own, which I didn't push.
all_zeroon every tier for lengths 0 to about 8 KiB, start offsets 0..63, and a single non-zero byte at each position including the last partial lane. Non-zero canary bytes just outside the slice never leaked in, which fits the tail being copied into a zeroed stack array (texture.rs:1216, 1280).last.hash,level.hash,Heldin resource.rs:1191,blank_printagainstfingerprint_blankin draw.rs:3911, the replay page marks). It would bite once a digest gets written to disk or compared between machines, so maybe say in the doc comment that the value depends on the CPU.Release throughput on this machine, best of 5. The main row is main's
digest+all_zero, measured in a separate run.So the speedup comes from AES, while the fused zero check alone only helps on blank buffers.
all_zerostops at the first non-zero word, so main already scans non-blank data only once. The scalar tier looked a bit slower than main, possibly the extraor_accat texture.rs:1326, but I didn't isolate that and it hardly matters on x86_64.A few smaller things.
Staging(texture.rs:2101-2107) the blank flag now comes from the fused pass, butprint_of(read, Some(hash))still callsall_zeroon theSomepath (texture.rs:2291), and the callers throw.1away. So a blank texture of 48 KiB or less is still scanned twice there.incompatible_msrvwarnings, all on the AVX-512 intrinsics in texture.rs:1184-1238. They're stable since 1.89 and the workspace says rust-version 1.88. CI doesn't run clippy and the pinned toolchain is newer, so nothing fails, but it doesn't match the "0 new warnings". Bumping rust-version or an allow on the two functions would fix it. It's the same with--features diagnostics.is_x86_feature_detected!(texture.rs:1155-1162), which std caches and which already checks XCR0 for the AVX-512 state. I didn't build for aarch64, but everything new sits behindcfg(target_arch = "x86_64")with the old scalar path as the fallback.AI-assisted: yes
9b9f78e807tof0f595220f@Not4Eric on GitHub · 2026-12-05 00:00 UTC · original
Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this
Pushed updates addressing your review:
#[allow(clippy::incompatible_msrv)]ondigest_and_zero_vaes512(0incompatible_msrvclippy warnings across--all-targets).print_ofto takeOption<(Digest, bool)>and updated all 4 callers so blank textures on the<= 48 KiBpath reuse the fused all-zero check instead of scanning twice (all_zerokept fortexture::ledger).digest()'s doc comment that the hash depends on the runtime CPU feature tier.@Kal0s-design on GitHub · 2026-12-05 00:59 UTC · original
Re-checked
f0f5952on native Windows (didn't run the game).All three points are in. Clippy has no incompatible_msrv warnings left with --all-targets, with and without diagnostics, thanks to the allow at texture.rs:1180. print_of now takes the fused flag (texture.rs:2288-2293) and all four callers pass it (2108, 2135, 2158, 2414), so a blank texture of 48 KiB or less is scanned once. The CPU-tier note is on digest() at 1147. The digest code itself didn't change, so what I found last time about the tiers and the zero flag still holds. The full lib run shows only the four failures main already has natively, and it still merges cleanly onto current main.
One small thing I missed last time. rustfmt with the repo's max_width = 100 wants six changes in texture.rs, the DIGEST_SEEDS rows around 1173-1176, a few long lines in the AES functions (around 1235, 1242, 1298, 1348) and one in the test near 3250. main is fmt-clean for that file. A quick cargo fmt would fix it.
AI-assisted: yes
f0f595220ftof3dcf68e54