GPU: add AVX2 changed_runs, persistent wide_each pool, and async heap_buffers offload #95

Open
Biewlhenrique wants to merge 1 commit from upstream-pr/95 into main
Biewlhenrique commented 2026-11-26 18:20:07 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Biewlhenrique on 2026-11-26T18:20:07Z.


Exact, non-visual CPU/memory optimizations ported from our VIctory-lnx fork onto DexNom/VIctory (64bd58f5), preserving BufferPass incremental tracking, device_removed diagnostics, Ray Tracing, and SparseTexture handling intact.

Tested PC

Component System
CPU Intel Core i5-14600KF (14C / 20T)
GPU NVIDIA GeForce RTX 5060 Ti 8 GB (Driver 32.0.16.2140)
System memory 32 GB RAM
OS Microsoft Windows 11 Pro x64 (Build 26200)
Toolchain rustc 1.98.1 (48a229cea 2026-09-01)

Changes

  1. Async heap_buffers pass offload (VICTORY_HEAP_PASS_ASIDE=0 runs inline for A/B comparison):
    • Converts SHADER_HEAPS in crates/victory-gpu/src/descriptor.rs to RwLock and adds with_heap.
    • Adds host::aside worker and HostList::{refreshes_coming, finish_coming} in crates/victory-gpu/src/host.rs so heap_buffer_pass resolves buffer views off recording threads and splices Step::Refresh steps on HostList::close.
  2. AVX2 changed_runs + persistent wide_each helper (crates/victory-gpu/src/shadow.rs):
    • Adds runtime-detected AVX2 (_mm256_cmpeq_epi8) path for changed_runs, keeping changed_runs_scalar as fallback.
    • Adds wide_each backed by the persistent workers() thread pool to avoid per-call thread creation overhead.

Verification on this DexNom/VIctory branch (166ad43)

  • cargo xtask policy → asset policy: 210 files ok
  • cargo test -p victory-gpu -- --test-threads=1 → 222 passed; 0 failed; 4 ignored (including host::aside::tests::what_is_found_is_waited_for_and_a_panic_lets_the_list_go_on, shadow::merge_tests::changed_runs_avx2_matches_scalar, and shadow::merge_tests::wide_each_preserves_order_and_sums_chunks)

Before / After Benchmark Evidence (on our VIctory-lnx diagnostics build)

Note: Measured on the test system above (1280×720, RT off, 240 s automated runs, 0 device-removed errors). Since we do not have an RX 7900 XTX to benchmark the 4K FSR+RT profile directly, VICTORY_HEAP_PASS_ASIDE=0 is kept available for direct A/B validation on Radeon.

Controlled 240 s run (draws >= 500) Mean Median P95 LAST10 heap buffers Card / Shared memory Private working set Errors
Before (fps18d, n=27, inline heap_buffers) 196.6 ms 190.0 ms 289.9 ms 26.2 ms 6,068 MB card / 5,331 MB shared 20,873 MB private (15,913 MB in RAM) 0
After (fps19d, n=29, VICTORY_HEAP_PASS_ASIDE=1) 175.5 ms 185.1 ms 298.2 ms 2.5 ms 6,337 MB card / 5,785 MB shared 21,666 MB private (16,553 MB in RAM) 0

Representative log lines (heavy ~5k-draw scene)

Before (fps18d):

2026-11-26T16:11:04.957862Z INFO victory_gpu::host: 5.4 fps, 185.1 ms/frame (98.2 preparing: copies 65.1 ms 175.1 MB, textures 3.9 ms 10.8 MB; 45.5 on the GPU; 62.3 copying back 70.4 MB), 4752 draws/frame, dropped 338 without a host pipeline (0 being made) and 1 indirect; heap buffers 1.0 passes 22.0 ms
2026-11-26T16:11:10.469513Z INFO victory_gpu::copystat: memory of textures: ... the card: 6068 MB in use of a budget of 5546 MB, 5331 MB of the PC's memory shared with it in use

After (fps19d):

2026-11-26T16:25:12.884664Z INFO victory_gpu::host: 5.3 fps, 189.4 ms/frame (83.1 preparing: copies 53.6 ms 166.4 MB, textures 2.3 ms 3.8 MB; 82.6 on the GPU; 60.4 copying back 71.5 MB), 5233 draws/frame, dropped 406 without a host pipeline (0 being made) and 1 indirect; heap buffers 1.0 passes 2.0 ms
2026-11-26T16:25:18.578616Z INFO victory_gpu::copystat: memory of textures: ... the card: 6337 MB in use of a budget of 5712 MB, 5785 MB of the PC's memory shared with it in use
<!-- greyfinch-sync:DexNom/VIctory:issue:5515180612 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/95). Originally posted by [Biewlhenrique](https://github.com/Biewlhenrique) on 2026-11-26T18:20:07Z. --- Exact, non-visual CPU/memory optimizations ported from our `VIctory-lnx` fork onto `DexNom/VIctory` (`64bd58f5`), preserving `BufferPass` incremental tracking, `device_removed` diagnostics, Ray Tracing, and SparseTexture handling intact. ### Tested PC | Component | System | | --- | --- | | CPU | Intel Core i5-14600KF (14C / 20T) | | GPU | NVIDIA GeForce RTX 5060 Ti 8 GB (Driver `32.0.16.2140`) | | System memory | 32 GB RAM | | OS | Microsoft Windows 11 Pro x64 (Build 26200) | | Toolchain | `rustc 1.98.1 (48a229cea 2026-09-01)` | ### Changes 1. **Async `heap_buffers` pass offload (`VICTORY_HEAP_PASS_ASIDE=0` runs inline for A/B comparison):** - Converts `SHADER_HEAPS` in `crates/victory-gpu/src/descriptor.rs` to `RwLock` and adds `with_heap`. - Adds `host::aside` worker and `HostList::{refreshes_coming, finish_coming}` in `crates/victory-gpu/src/host.rs` so `heap_buffer_pass` resolves buffer views off recording threads and splices `Step::Refresh` steps on `HostList::close`. 2. **AVX2 `changed_runs` + persistent `wide_each` helper (`crates/victory-gpu/src/shadow.rs`):** - Adds runtime-detected AVX2 (`_mm256_cmpeq_epi8`) path for `changed_runs`, keeping `changed_runs_scalar` as fallback. - Adds `wide_each` backed by the persistent `workers()` thread pool to avoid per-call thread creation overhead. ### Verification on this `DexNom/VIctory` branch (`166ad43`) - `cargo xtask policy` → `asset policy: 210 files ok` - `cargo test -p victory-gpu -- --test-threads=1` → `222 passed; 0 failed; 4 ignored` (including `host::aside::tests::what_is_found_is_waited_for_and_a_panic_lets_the_list_go_on`, `shadow::merge_tests::changed_runs_avx2_matches_scalar`, and `shadow::merge_tests::wide_each_preserves_order_and_sums_chunks`) ### Before / After Benchmark Evidence (on our `VIctory-lnx` diagnostics build) > Note: Measured on the test system above (`1280×720`, RT off, 240 s automated runs, `0` device-removed errors). Since we do not have an RX 7900 XTX to benchmark the 4K FSR+RT profile directly, `VICTORY_HEAP_PASS_ASIDE=0` is kept available for direct A/B validation on Radeon. | Controlled 240 s run (`draws >= 500`) | Mean | Median | P95 | `LAST10` `heap buffers` | Card / Shared memory | Private working set | Errors | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | Before (`fps18d`, `n=27`, inline `heap_buffers`) | 196.6 ms | 190.0 ms | 289.9 ms | 26.2 ms | 6,068 MB card / 5,331 MB shared | 20,873 MB private (15,913 MB in RAM) | 0 | | After (`fps19d`, `n=29`, `VICTORY_HEAP_PASS_ASIDE=1`) | **175.5 ms** | **185.1 ms** | 298.2 ms | **2.5 ms** | 6,337 MB card / 5,785 MB shared | 21,666 MB private (16,553 MB in RAM) | 0 | #### Representative log lines (heavy ~5k-draw scene) Before (`fps18d`): ```text 2026-11-26T16:11:04.957862Z INFO victory_gpu::host: 5.4 fps, 185.1 ms/frame (98.2 preparing: copies 65.1 ms 175.1 MB, textures 3.9 ms 10.8 MB; 45.5 on the GPU; 62.3 copying back 70.4 MB), 4752 draws/frame, dropped 338 without a host pipeline (0 being made) and 1 indirect; heap buffers 1.0 passes 22.0 ms 2026-11-26T16:11:10.469513Z INFO victory_gpu::copystat: memory of textures: ... the card: 6068 MB in use of a budget of 5546 MB, 5331 MB of the PC's memory shared with it in use ``` After (`fps19d`): ```text 2026-11-26T16:25:12.884664Z INFO victory_gpu::host: 5.3 fps, 189.4 ms/frame (83.1 preparing: copies 53.6 ms 166.4 MB, textures 2.3 ms 3.8 MB; 82.6 on the GPU; 60.4 copying back 71.5 MB), 5233 draws/frame, dropped 406 without a host pipeline (0 being made) and 1 indirect; heap buffers 1.0 passes 2.0 ms 2026-11-26T16:25:18.578616Z INFO victory_gpu::copystat: memory of textures: ... the card: 6337 MB in use of a budget of 5712 MB, 5785 MB of the PC's memory shared with it in use ```
andrewDoing commented 2026-11-26 22:43:40 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T22:43:40Z.


At the exact PR head tested:

At 166ad43, the extracted AVX2 changed-runs function matched scalar across 135,520 synthetic alignment, length and run-boundary cases. On 1 MiB buffers, scalar/AVX2 medians were 0.044/0.029 ms unchanged, 0.053/0.034 ms with 64 dirty bytes per 4 KiB, and 0.273/0.067 ms all changed. One static review concern: the new generic wide_each appears unused outside its test, and its borrowed raw-pointer safety relies on wide always joining; a caller-run job can unwind before the completion counter is decremented. I did not trigger unsafe behavior, and did not assess asynchronous heap offload.

Verification was AI-assisted with GPT-6.2 Astra.

<!-- greyfinch-sync:DexNom/VIctory:comment:7204932983 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/95#issuecomment-7204932983). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T22:43:40Z. --- At the exact PR head tested: At `166ad43`, the extracted AVX2 changed-runs function matched scalar across 135,520 synthetic alignment, length and run-boundary cases. On 1 MiB buffers, scalar/AVX2 medians were 0.044/0.029 ms unchanged, 0.053/0.034 ms with 64 dirty bytes per 4 KiB, and 0.273/0.067 ms all changed. One static review concern: the new generic `wide_each` appears unused outside its test, and its borrowed raw-pointer safety relies on `wide` always joining; a caller-run job can unwind before the completion counter is decremented. I did not trigger unsafe behavior, and did not assess asynchronous heap offload. Verification was AI-assisted with GPT-6.2 Astra.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/95:upstream-pr/95'
git switch 'upstream-pr/95'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/95'
git switch 'upstream-pr/95'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/95'
git switch 'upstream-pr/95'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/95'
git switch 'main'
git merge --squash 'upstream-pr/95'
git switch 'main'
git merge --ff-only 'upstream-pr/95'
git switch 'main'
git merge 'upstream-pr/95'
git push origin 'main'
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
DexNom/VIctory!95
No description provided.