gpu: opt-in trim of mapped driver shader-cache pages (review fixes) #159

Open
github-bot wants to merge 1 commit from github-bot/gh-158 into main AGit
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 18:27 UTC · original
SovietBearz0r:minivi-drivercache-trim → main · +948 −1 · 6 files · 1 commits · open

Replaces the closed #112 with the review fixed: strictly opt-in, every step revalidated immediately before VirtualUnlock, a conservative driver-cache allow-list + vendor gate, and a VirtualLock guard.

Maintainer points addressed

  • Default-ON → strictly OFF: only VICTORY_DRIVER_TRIM=1 arms it (unset/0/other off), documented in README as opt-in; the launcher does not set it.
  • TOCTOU: the stale cached validation is gone; before each 64 MiB step mapping_now() re-runs VirtualQuery + K32GetMappedFileNameW; the pure chunk_still_ours() requires same allocation base/region base+size, MEM_COMMIT/MEM_MAPPED, step inside the region, and the same normalized driver-cache path/vendor — any mismatch or query failure skips the step and stops the pass. No lock is held across the 1 ms sleeps.
  • Brittle globs replaced: conservative path-shape allow-list (NVIDIA …\DXCache\…, AMD …\DxCache\…/…\AmdDx…, Intel …\ShaderCache\…) and host-vendor match via a non-creating host::adapter_identity() (PCI id, name fallback). Anything else = no-op + one log line. No files edited.
  • Driver VirtualLock: a K32QueryWorkingSetEx probe skips any step containing a Locked page (query failure aborts the step).
  • Bounded pass (64 steps), quiet_ms() gating and the 30 s back-off kept; pipeline/library.rs re-arms its mapped-file trim on pipeline creations (needed for the quiet signal).

Verification

  • cargo test -p victory-gpu --lib: 728 passed, 0 failed, 21 ignored — 12 drivercache tests (off-unless-1, allow-list/vendor, filtering/chunking/quiet floor, revalidation predicate for unchanged/unmapped/private/other-path/moved/resized/other-view/out-of-region, real private allocation refusal, real non-vendor file-mapping refusal, vendor-by-name fallback); cargo check -p victory; policy 443 files; clippy -D warnings (default + all-features) clean.
  • Still needed: in-game confirmation that a real driver maps its cache with an allowed path shape in this process and that unlocking returns working set without hitching. Tests prove the predicate/allow-list/gate/lock probe/bounds only.
  • Risk: VirtualUnlock on driver-owned pages remains undocumented-but-real Windows behaviour; the residual query→call race cannot be fully eliminated from user mode — hence opt-in only.

Supersedes #112 (closed); branch force-pushed c84a7ea4.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 18:27 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/158) `SovietBearz0r:minivi-drivercache-trim` → `main` · +948 −1 · 6 files · 1 commits · open Replaces the closed #112 with the review fixed: strictly opt-in, every step revalidated immediately before `VirtualUnlock`, a conservative driver-cache allow-list + vendor gate, and a `VirtualLock` guard. ## Maintainer points addressed - **Default-ON → strictly OFF:** only `VICTORY_DRIVER_TRIM=1` arms it (unset/`0`/other off), documented in README as opt-in; the launcher does not set it. - **TOCTOU:** the stale cached validation is gone; before each 64 MiB step `mapping_now()` re-runs `VirtualQuery` + `K32GetMappedFileNameW`; the pure `chunk_still_ours()` requires same allocation base/region base+size, `MEM_COMMIT`/`MEM_MAPPED`, step inside the region, and the same normalized driver-cache path/vendor — any mismatch or query failure skips the step and stops the pass. No lock is held across the 1 ms sleeps. - **Brittle globs replaced:** conservative path-shape allow-list (NVIDIA `…\DXCache\…`, AMD `…\DxCache\…`/`…\AmdDx…`, Intel `…\ShaderCache\…`) **and** host-vendor match via a non-creating `host::adapter_identity()` (PCI id, name fallback). Anything else = no-op + one log line. No files edited. - **Driver `VirtualLock`:** a `K32QueryWorkingSetEx` probe skips any step containing a `Locked` page (query failure aborts the step). - Bounded pass (64 steps), `quiet_ms()` gating and the 30 s back-off kept; `pipeline/library.rs` re-arms its mapped-file trim on pipeline creations (needed for the quiet signal). ## Verification - `cargo test -p victory-gpu --lib`: **728 passed, 0 failed, 21 ignored** — 12 drivercache tests (off-unless-1, allow-list/vendor, filtering/chunking/quiet floor, revalidation predicate for unchanged/unmapped/private/other-path/moved/resized/other-view/out-of-region, real private allocation refusal, real non-vendor file-mapping refusal, vendor-by-name fallback); `cargo check -p victory`; policy 443 files; clippy `-D warnings` (default + all-features) clean. - **Still needed:** in-game confirmation that a real driver maps its cache with an allowed path shape in this process and that unlocking returns working set without hitching. Tests prove the predicate/allow-list/gate/lock probe/bounds only. - Risk: `VirtualUnlock` on driver-owned pages remains undocumented-but-real Windows behaviour; the residual query→call race cannot be fully eliminated from user mode — hence opt-in only. Supersedes #112 (closed); branch force-pushed `c84a7ea4`.
VICTORY_DRIVER_TRIM is now off unless it is set to 1 (unset and 0 leave
the driver's mappings alone), and the README documents it as opt-in; the
launcher never sets it. The first version (PR #111) was closed for a
TOCTOU race between found() and the 64 MiB VirtualUnlock loop, for
trusting filename heuristics, and for VirtualUnlock on driver-owned
memory that may be VirtualLocked. Reworked:

- Before every 64 MiB VirtualUnlock, VirtualQuery and
  K32GetMappedFileNameW are asked again for that exact range: the step is
  skipped and the pass stops unless the region is still MEM_COMMIT and
  MEM_MAPPED, covers the step, starts and ends where the scan saw it, is
  the same allocation, and names the same normalized driver-cache path.
  The same checks run after every sleep, so no pages are touched on a
  mapping that changed while the thread slept. No lock is held across a
  sleep (the KNOWN cache that let a stale mapping be reused is gone).
- Path matching is a conservative allow-list by path shape - NVIDIA
  ...\DXCache\..., AMD ...\AMD\...\DxCache\... or ...\AmdDx..., Intel
  ...\Intel\...\ShaderCache\... - and the path's vendor must be the
  vendor of the adapter the host device runs on (adapter PCI id, or its
  name when the id is generic). A *.bin/*.db/*.cache file anywhere else
  is never touched; nothing eligible is a no-op with one log line.
- A step with any page K32QueryWorkingSetEx reports VirtualLocked is left
  alone, so a driver's own VirtualLock is not silently broken.
- Each pass is bounded to MAX_CHUNKS_PER_PASS (64) steps; the quiet_ms
  gating and the 30 s empty-walk back-off stay.

The pure predicates (allow-list, vendor match, re-validation given two
region descriptions, chunking, the quiet floor) and the refusals of a
private range and of a non-vendor mapped file are unit-tested. What still
needs a real driver in game: that it maps its cache with one of these
path shapes, and that unlocking its pages returns memory without hitching
when it reads them back.

Verification: cargo test -p victory-gpu --lib: 728 passed, 21 ignored
(12 in drivercache, all passing); cargo check -p victory; cargo xtask
policy (443 files ok); clippy -p victory-gpu --all-targets, default and
--all-features, clean.

Port of MiniVI c7d3102b, reworked after the review of PR #111.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 18:30:01 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pipeline/library.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/159/head:github-bot/gh-158'
git switch 'github-bot/gh-158'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-158'
git switch 'github-bot/gh-158'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-158'
git switch 'github-bot/gh-158'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-158'
git switch 'main'
git merge --squash 'github-bot/gh-158'
git switch 'main'
git merge --ff-only 'github-bot/gh-158'
git switch 'main'
git merge 'github-bot/gh-158'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.