GPU: guarded in-process copy-back writes into title memory (VICTORY_WRITE_PLAIN=1) #1225

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

@⁠RealAzemed on GitHub · 2026-11-26 00:41 UTC · original
RealAzemed:perf/plaincopy-guarded-writes → main · +170 −21 · 2 files · 1 commits · open

Summary

Adds the symmetric write counterpart to VICTORY_COPY_PLAIN=1 / VICTORY_FILLS_PLAIN=1 for shader copy-back writes into title memory (host::write_mapped), gated opt-in behind VICTORY_WRITE_PLAIN=1 (off by default, cleanly based on main 006c353).

What Changed

  • crates/victory-gpu/src/plaincopy.rs:
    • Adds victory_write_guarded (rep movsb with no stack usage, preserving callee-saved rsi/rdi in r9/r10, identical to victory_copy_guarded).
    • Extends plaincopy::install()'s first-chance VEH handler to catch write access violations / in-page / guard-page faults strictly at victory_write_guarded_at and redirect RIP to victory_write_guarded_fault (returning false).
    • Adds a 2-second 64 KiB block fault-cooldown table (WRITE_RECENT) so blocks that fault fall straight through to NtWriteVirtualMemory / WriteProcessMemory, plus per-frame telemetry in plaincopy::line().
    • Adds unit test guarded_write_copies_writable_and_falls_back_on_unwritable_pages covering writable pages, reserved holes, PAGE_READONLY pages, and register preservation.
  • crates/victory-gpu/src/host.rs:
    • Fast-paths write_mapped() through crate::plaincopy::write(dst, src, len), falling back to existing NtWriteVirtualMemory / WriteProcessMemory (and 64 KiB piece fallback) whenever off or on any unwritable page.

Why

write_mapped's callers already open write guards beforehand (watch::writing), yet every copy-back chunk still crosses into the kernel via NtWriteVirtualMemory (and crosses wineserver IPC under Wine/Proton). On Linux/Proton (RTX 3070 8 GB, Proton Experimental), VICTORY_WRITE_PLAIN=1 handled 100% of copy-back writes in-process (~200–275 writes/frame, 4.5–8.6 MB/frame, 0.0 unwritable faults), helping bring copy-back down from ~180–206 ms to ~18–49 ms alongside relay/queue2.

Verification

  • All 6 plaincopy::tests:: unit tests pass under Proton (0.01s), including the new guarded_write_copies_writable_and_falls_back_on_unwritable_pages test.
  • Zero new compiler warnings in victory-gpu (lib + test).
**@⁠RealAzemed** on GitHub · 2026-11-26 00:41 UTC · [original](https://github.com/fxceless/victory-fork/pull/1225) `RealAzemed:perf/plaincopy-guarded-writes` → `main` · +170 −21 · 2 files · 1 commits · open ## Summary Adds the symmetric write counterpart to `VICTORY_COPY_PLAIN=1` / `VICTORY_FILLS_PLAIN=1` for shader copy-back writes into title memory (`host::write_mapped`), gated opt-in behind `VICTORY_WRITE_PLAIN=1` (off by default, cleanly based on `main` `006c353`). ### What Changed - `crates/victory-gpu/src/plaincopy.rs`: - Adds `victory_write_guarded` (`rep movsb` with no stack usage, preserving callee-saved `rsi`/`rdi` in `r9`/`r10`, identical to `victory_copy_guarded`). - Extends `plaincopy::install()`'s first-chance VEH handler to catch write access violations / in-page / guard-page faults strictly at `victory_write_guarded_at` and redirect RIP to `victory_write_guarded_fault` (returning `false`). - Adds a 2-second 64 KiB block fault-cooldown table (`WRITE_RECENT`) so blocks that fault fall straight through to `NtWriteVirtualMemory` / `WriteProcessMemory`, plus per-frame telemetry in `plaincopy::line()`. - Adds unit test `guarded_write_copies_writable_and_falls_back_on_unwritable_pages` covering writable pages, reserved holes, `PAGE_READONLY` pages, and register preservation. - `crates/victory-gpu/src/host.rs`: - Fast-paths `write_mapped()` through `crate::plaincopy::write(dst, src, len)`, falling back to existing `NtWriteVirtualMemory` / `WriteProcessMemory` (and 64 KiB piece fallback) whenever off or on any unwritable page. ### Why `write_mapped`'s callers already open write guards beforehand (`watch::writing`), yet every copy-back chunk still crosses into the kernel via `NtWriteVirtualMemory` (and crosses wineserver IPC under Wine/Proton). On Linux/Proton (RTX 3070 8 GB, Proton Experimental), `VICTORY_WRITE_PLAIN=1` handled **100% of copy-back writes in-process (~200–275 writes/frame, 4.5–8.6 MB/frame, 0.0 unwritable faults)**, helping bring `copy-back` down from ~180–206 ms to ~18–49 ms alongside relay/queue2. ### Verification - All 6 `plaincopy::tests::` unit tests pass under Proton (`0.01s`), including the new `guarded_write_copies_writable_and_falls_back_on_unwritable_pages` test. - Zero new compiler warnings in `victory-gpu` (lib + test).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:53 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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