perf(gpu): use runtime-dispatched AVX2 non-temporal stores for large snapshot copies #552

Closed
Glory-star wants to merge 1 commit from upstream-pr/552 into main
Glory-star commented 2026-11-28 00:40:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Glory-star on 2026-11-28T00:40:19Z.


Problem

take_snapshots() copies large write-watched buffer snapshots on worker threads using std::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

  • Add a runtime-dispatched copy_snapshot_avx2 (#[target_feature(enable = "avx2")] gated by std::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.
  • Works on standard generic x86_64-pc-windows-msvc release builds (no -C target-cpu=native required) and falls back to copy_nonoverlapping on non-AVX2 CPUs or copies < 64 KiB.

Verification

  • Tested on Intel Core i7-12700K + 64 GB RAM + RTX 3060 Ti 8 GB (Windows 10 19045): snapshots time in the preparing per frame breakdown dropped from ~28.6 ms spikes to 0.0–0.3 ms across 20-minute gameplay sessions (0 errors).
  • Verified clean cargo check -p victory-gpu without RUSTFLAGS (generic x86-64 target).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5535017229 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/552). Originally posted by [Glory-star](https://github.com/Glory-star) on 2026-11-28T00:40:19Z. --- ### Problem `take_snapshots()` copies large write-watched buffer snapshots on worker threads using `std::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 - Add a runtime-dispatched `copy_snapshot_avx2` (`#[target_feature(enable = "avx2")]` gated by `std::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. - Works on standard generic `x86_64-pc-windows-msvc` release builds (no `-C target-cpu=native` required) and falls back to `copy_nonoverlapping` on non-AVX2 CPUs or copies < 64 KiB. ### Verification - Tested on Intel Core i7-12700K + 64 GB RAM + RTX 3060 Ti 8 GB (Windows 10 19045): `snapshots` time in the `preparing per frame` breakdown dropped from ~`28.6 ms` spikes to `0.0–0.3 ms` across 20-minute gameplay sessions (`0` errors). - Verified clean `cargo check -p victory-gpu` without `RUSTFLAGS` (generic x86-64 target).
Machad3x commented 2026-11-28 01:56:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Machad3x on 2026-11-28T01:56:50Z.


Tested in a batch on an RTX 3080 Ti + Ryzen 7 5700X, 1440p, DLSS Quality, title ray tracing on (VICTORY_BVH_BUILDER=1), 240 s runs into the prison cell scene. Batch: #552, #550, #548, #547, #544.
Result without #550: alive for the whole run, 67-70 ms/frame, no shader or pipeline refused, picture unchanged. No problem found in this PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232023508 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/552#issuecomment-7232023508). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-28T01:56:50Z. --- Tested in a batch on an RTX 3080 Ti + Ryzen 7 5700X, 1440p, DLSS Quality, title ray tracing on (VICTORY_BVH_BUILDER=1), 240 s runs into the prison cell scene. Batch: #552, #550, #548, #547, #544. Result without #550: alive for the whole run, 67-70 ms/frame, no shader or pipeline refused, picture unchanged. No problem found in this PR.

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