perf(gpu): use runtime-dispatched AVX2 non-temporal stores for large snapshot copies #1003
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1003"
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 adwen-007 on 2026-11-28T10:57:45Z.
Problem
take_snapshots()copies large write-watched buffer snapshots on worker threads usingstd::ptr::copy_nonoverlapping. For large ranges (>= 64 KiB), regular stores allocate destination cache lines (read-for-ownership DRAM traffic) and evict hot CPU state from L2/L3 cache.Fix
copy_snapshot_avx2(#[target_feature(enable = "avx2")]gated bystd::arch::is_x86_feature_detected!("avx2")) using 4x unrolled_mm256_loadu_si256+_mm256_stream_si256(VMOVNTDQ) with 32-byte destination alignment and_mm_sfence()for copies >= 64 KiB.x86_64-pc-windows-msvcrelease builds (no-C target-cpu=nativerequired) and falls back tocopy_nonoverlappingon non-AVX2 CPUs or copies < 64 KiB.Verification
snapshotstime in thepreparing per framebreakdown dropped from ~28.6 msspikes to0.0–0.3 msacross 20-minute gameplay sessions (0errors).cargo check -p victory-gpuwithoutRUSTFLAGS(generic x86-64 target) and zero warnings onv2026.11.28.01.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T11:49:01Z.
Review: APPROVED
Tested locally merged onto
main(63b902f).crates/victory-gpu/src/shadow.rs;cargo xtask policypassed (294 files ok).len >= 64 KiB+is_x86_feature_detected!("avx2")) properly alignsdstto 32 bytes before unrolled_mm256_stream_si256, copies the tail safely, and issues_mm_sfence()before returning.cargo test -p victory-gpu --lib shadow::passed (36 passed; 0 failed; 2 ignored, includingcopies_cut_into_jobs_copy_the_same_bytes) with 0 compiler warnings.Clean cache-friendly snapshot copy optimization. LGTM.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).