GPU: experiment with allocation-level write-watch classification (FIND-44) #3485

Open
srijann07 wants to merge 7 commits from upstream-pr/3485 into main
srijann07 commented 2026-11-27 07:50:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by srijann07 on 2026-11-27T07:50:19Z.


Summary

Experimental opt-in write-watch classification optimization for FIND-44.

  • Uses allocation-level metadata instead of expensive region scanning.
  • Preserves existing fallback classification.
  • No persistent address cache or write-watch reset.
  • Enable using VICTORY_WATCH_REGION_PROBE=1.
  • Disabled by default.

Benchmark results

Windows release build, synthetic allocations only:

Allocation Clean-memory speedup Dirty-memory overhead
16 MiB 5.2x 74%
64 MiB 15.4x 55%
256 MiB 43.5x 30%

Validation

  • 236 GPU tests passed.
  • Five new regression tests passed.
  • Workspace tests passed.
  • Both Clippy configurations passed.
  • No game assets used.
  • No workflow changes in the final diff.

CI: https://github.com/srijann07/VIctory/actions/runs/45959646990

Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7210997201

Limitations

Dirty-memory overhead remains. Windows/Wine compatibility
and actual gameplay performance require further validation.
No overall FPS improvement is claimed.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5523122240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3485). Originally posted by [srijann07](https://github.com/srijann07) on 2026-11-27T07:50:19Z. --- ## Summary Experimental opt-in write-watch classification optimization for FIND-44. - Uses allocation-level metadata instead of expensive region scanning. - Preserves existing fallback classification. - No persistent address cache or write-watch reset. - Enable using `VICTORY_WATCH_REGION_PROBE=1`. - Disabled by default. ## Benchmark results Windows release build, synthetic allocations only: | Allocation | Clean-memory speedup | Dirty-memory overhead | |---|---:|---:| | 16 MiB | 5.2x | 74% | | 64 MiB | 15.4x | 55% | | 256 MiB | 43.5x | 30% | ## Validation - 236 GPU tests passed. - Five new regression tests passed. - Workspace tests passed. - Both Clippy configurations passed. - No game assets used. - No workflow changes in the final diff. CI: https://github.com/srijann07/VIctory/actions/runs/45959646990 Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7210997201 ## Limitations Dirty-memory overhead remains. Windows/Wine compatibility and actual gameplay performance require further validation. No overall FPS improvement is claimed.
oni-swr commented 2026-11-27 08:35:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T08:35:57Z.


Independent WARP verification of #3485 (head 475dd48e)

Setup. Windows 11 Pro 10.0.26200, AMD Ryzen 7 5700X3D, rustc 1.98.1. No physical GPU used: VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, with --features diagnostics on victory-gpu (without that feature VICTORY_D3D12_WARP is compiled out in host.rs and the default adapter would be used). VICTORY_DXIL = Windows SDK 10.0.26100.0 dxil.dll (1.8.2502.11). Command: cargo test -j 4 -p victory-gpu --features diagnostics --locked. The PR's merge-base is ffe310e, so base is main 63bcca43 and head is a clean test merge of 475dd48e onto 63bcca43 (only watch.rs differs). watch.rs has changed a lot on main since the merge-base, so the review below is of the merged file.

Tests

passed failed ignored
base 63bcca43 246 0 1
head, probe off 251 0 2
head, VICTORY_WATCH_REGION_PROBE=1 251 0 2

The +5 passes are the five new region_probe_* tests; the +1 ignored is region_probe_benchmark. Note for anyone repeating this: with one target dir shared by several worktrees, cargo's mtime fingerprints can reuse the other tree's binary. I touched the sources before every run and checked that each run recompiled victory-gpu.

Benchmark. The author's region_probe_benchmark (--release --ignored), repeated on this host. PAGE is 64 KiB, so 256 pages = 16 MiB. Clean memory, per 100 calls:

range slow fast speedup
16 MiB 585 µs 121 µs 4.8x
64 MiB 2.26 ms 133 µs 17x
256 MiB 8.85 ms 177 µs 50x

Dirty memory (every page written): 16 MiB 62 → 104 µs (+67%), 64 MiB about 72-91 → 116 µs, 256 MiB 118 → 161 µs (+37%). Below 16 MiB both paths are identical, as designed. This reproduces the PR's table: the clean-memory speedup and the dirty-memory overhead (about 40 µs per call) are both real.

Review of the fast path

  • AllocationBase + RegionSize does bound the allocation. I checked QueryVirtualMemoryInformation(MemoryRegionInfo) on this host with a standalone probe. For a 32 MiB private allocation, queries at the base, at +8 MiB, at a PAGE_NOACCESS page and at a guard page all return the same AllocationBase, RegionSize = 32 MiB (the whole allocation, not "from the queried address") and CommitSize = committed bytes. For a 32 MiB reservation with 8 MiB committed, CommitSize is 8 MiB. So CommitSize == RegionSize means no uncommitted page anywhere in the allocation, and end <= base + RegionSize is an exact bound.
  • The 4 KiB watched() probe is enough. MEM_WRITE_WATCH is set for the whole reservation, so if the first page is watched, every page of that private allocation is.
  • It cannot return pages the slow path would exclude. The slow path's first shortcut (watched(aligned, end - aligned)) already returns every page whenever the whole range is write-watched, and it ignores protection, guard/no-access pages, mixed protections and type. The fast path only answers (first..last) where that shortcut would succeed too, so the result is identical. Images and mapped views fail the private-flag check. Partly committed, non-watched and foreign ranges fall through to the unchanged slow path (a plain 32 MiB MEM_COMMIT allocation reports flags 0x1, and a write-watch one 0x401). Nothing is cached, and the PR's test confirms GetWriteWatch is not reset.
  • Risks, none blocking for an opt-in, default-off change:
    1. QueryVirtualMemoryInformation is imported at load time (windows-sys links it from api-ms-win-core-memory-l1-1-4.dll), even with the probe off. It is not exported by kernel32.dll: my probe that imported it from kernel32 failed with STATUS_ENTRYPOINT_NOT_FOUND. On a host whose loader or Wine/Proton build lacks the export, the binary may fail to start at all. I could not test Wine. A GetProcAddress lookup would remove the risk.
    2. For a private, fully committed 16 MiB+ allocation that is not write-watched (for example a heap segment), each call pays the extra query plus a small GetWriteWatch before falling back, with no gain.
    3. The speedup applies only to clean pools. Whether it helps in the game depends on how often big pools are clean at classification time, which a synthetic test cannot show.

Blocking findings: none for an opt-in change. Risk 1 should be checked on Wine/Proton before this is ever made the default.

No game files, dumps, install paths, shader names or hashes were used. AI-assisted: Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7213710029 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3485#issuecomment-7213710029). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T08:35:57Z. --- ## Independent WARP verification of #3485 (head 475dd48e) **Setup.** Windows 11 Pro 10.0.26200, AMD Ryzen 7 5700X3D, rustc 1.98.1. No physical GPU used: `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1`, with `--features diagnostics` on `victory-gpu` (without that feature `VICTORY_D3D12_WARP` is compiled out in `host.rs` and the default adapter would be used). `VICTORY_DXIL` = Windows SDK 10.0.26100.0 `dxil.dll` (1.8.2502.11). Command: `cargo test -j 4 -p victory-gpu --features diagnostics --locked`. The PR's merge-base is `ffe310e`, so base is `main` 63bcca43 and head is a clean test merge of `475dd48e` onto 63bcca43 (only `watch.rs` differs). `watch.rs` has changed a lot on main since the merge-base, so the review below is of the merged file. **Tests** | | passed | failed | ignored | |---|---:|---:|---:| | base 63bcca43 | 246 | 0 | 1 | | head, probe off | 251 | 0 | 2 | | head, `VICTORY_WATCH_REGION_PROBE=1` | 251 | 0 | 2 | The +5 passes are the five new `region_probe_*` tests; the +1 ignored is `region_probe_benchmark`. Note for anyone repeating this: with one target dir shared by several worktrees, cargo's mtime fingerprints can reuse the other tree's binary. I touched the sources before every run and checked that each run recompiled `victory-gpu`. **Benchmark.** The author's `region_probe_benchmark` (`--release --ignored`), repeated on this host. `PAGE` is 64 KiB, so 256 pages = 16 MiB. Clean memory, per 100 calls: | range | slow | fast | speedup | |---:|---:|---:|---:| | 16 MiB | 585 µs | 121 µs | 4.8x | | 64 MiB | 2.26 ms | 133 µs | 17x | | 256 MiB | 8.85 ms | 177 µs | 50x | Dirty memory (every page written): 16 MiB 62 → 104 µs (+67%), 64 MiB about 72-91 → 116 µs, 256 MiB 118 → 161 µs (+37%). Below 16 MiB both paths are identical, as designed. This reproduces the PR's table: the clean-memory speedup and the dirty-memory overhead (about 40 µs per call) are both real. **Review of the fast path** - `AllocationBase + RegionSize` does bound the allocation. I checked `QueryVirtualMemoryInformation(MemoryRegionInfo)` on this host with a standalone probe. For a 32 MiB private allocation, queries at the base, at +8 MiB, at a PAGE_NOACCESS page and at a guard page all return the same `AllocationBase`, `RegionSize` = 32 MiB (the whole allocation, not "from the queried address") and `CommitSize` = committed bytes. For a 32 MiB reservation with 8 MiB committed, `CommitSize` is 8 MiB. So `CommitSize == RegionSize` means no uncommitted page anywhere in the allocation, and `end <= base + RegionSize` is an exact bound. - The 4 KiB `watched()` probe is enough. `MEM_WRITE_WATCH` is set for the whole reservation, so if the first page is watched, every page of that private allocation is. - It cannot return pages the slow path would exclude. The slow path's first shortcut (`watched(aligned, end - aligned)`) already returns every page whenever the whole range is write-watched, and it ignores protection, guard/no-access pages, mixed protections and type. The fast path only answers `(first..last)` where that shortcut would succeed too, so the result is identical. Images and mapped views fail the private-flag check. Partly committed, non-watched and foreign ranges fall through to the unchanged slow path (a plain 32 MiB `MEM_COMMIT` allocation reports flags 0x1, and a write-watch one 0x401). Nothing is cached, and the PR's test confirms `GetWriteWatch` is not reset. - Risks, none blocking for an opt-in, default-off change: 1. `QueryVirtualMemoryInformation` is imported at load time (windows-sys links it from `api-ms-win-core-memory-l1-1-4.dll`), even with the probe off. It is not exported by `kernel32.dll`: my probe that imported it from kernel32 failed with `STATUS_ENTRYPOINT_NOT_FOUND`. On a host whose loader or Wine/Proton build lacks the export, the binary may fail to start at all. I could not test Wine. A `GetProcAddress` lookup would remove the risk. 2. For a private, fully committed 16 MiB+ allocation that is not write-watched (for example a heap segment), each call pays the extra query plus a small `GetWriteWatch` before falling back, with no gain. 3. The speedup applies only to clean pools. Whether it helps in the game depends on how often big pools are clean at classification time, which a synthetic test cannot show. **Blocking findings:** none for an opt-in change. Risk 1 should be checked on Wine/Proton before this is ever made the default. No game files, dumps, install paths, shader names or hashes were used. AI-assisted: Claude Code (Claude Sonnet 5.5).
cloph-dsp commented 2026-11-27 09:30:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T09:30:54Z.


Independent verification of PR #3485 (CPU-only, synthetic inputs, no game data).

Windows / Rust 1.100.0 / MSVC, per-worktree CARGO_TARGET_DIR=D:\Victory-Contrib\target-3485-verify, CARGO_BUILD_JOBS=2.

Head 475dd48, base/merge base 63bcca4.

Commands and results:

  • cargo test --locked -p victory-gpu --lib -- watch::tests::region_probe_matches_baseline_after_address_reuse --exact --test-threads=1 --quiet -> 1 passed, 0 failed, 237 filtered, exit 0.
  • git grep -F region_probe_matches_baseline_after_address_reuse 63bcca4 -- crates/victory-gpu/src/watch.rs -> no hits (test new on this PR).
  • git diff --check 63bcca4 HEAD -> clean.

Notes: only the named synthetic test was replayed; full crate suite not run. Only pre-existing fetch_update deprecation warnings. GPU/driver N/A for this CPU-only test. AI-assisted (Hy4 flash). No game data or extracted assets used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7214771175 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3485#issuecomment-7214771175). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T09:30:54Z. --- Independent verification of PR #3485 (CPU-only, synthetic inputs, no game data). Windows / Rust 1.100.0 / MSVC, per-worktree CARGO_TARGET_DIR=D:\Victory-Contrib\target-3485-verify, CARGO_BUILD_JOBS=2. Head 475dd48, base/merge base 63bcca4. Commands and results: - `cargo test --locked -p victory-gpu --lib -- watch::tests::region_probe_matches_baseline_after_address_reuse --exact --test-threads=1 --quiet` -> 1 passed, 0 failed, 237 filtered, exit 0. - `git grep -F region_probe_matches_baseline_after_address_reuse 63bcca4 -- crates/victory-gpu/src/watch.rs` -> no hits (test new on this PR). - `git diff --check 63bcca4 HEAD` -> clean. Notes: only the named synthetic test was replayed; full crate suite not run. Only pre-existing `fetch_update` deprecation warnings. GPU/driver N/A for this CPU-only test. AI-assisted (Hy4 flash). No game data or extracted assets used.
futurepro62 commented 2026-11-27 18:56:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T18:56:03Z.


NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head 475dd48 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 871 passed, 0 failed, 11 ignored.
  • The new tests ran and passed: region_probe_matches_baseline_after_address_reuse, region_probe_matches_baseline_across_protections, region_probe_matches_baseline_for_dirty_and_partial_ranges, region_probe_matches_baseline_for_mixed_commit_states, region_probe_does_not_reset_write_watch.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7226019630 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3485#issuecomment-7226019630). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T18:56:03Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head `475dd48` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **871 passed, 0 failed, 11 ignored**. - The new tests ran and passed: `region_probe_matches_baseline_after_address_reuse`, `region_probe_matches_baseline_across_protections`, `region_probe_matches_baseline_for_dirty_and_partial_ranges`, `region_probe_matches_baseline_for_mixed_commit_states`, `region_probe_does_not_reset_write_watch`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/3485:upstream-pr/3485'
git switch 'upstream-pr/3485'

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