GPU, HLE: opt-in guarded writes for title memcpy and memset #3375

Open
github-bot wants to merge 3 commits from github-bot/gh-3375 into main AGit
Owner

@⁠lhnizdo on GitHub · 2026-11-26 20:51 UTC · original
lhnizdo:pr/guard-crt-copy → main · +374 −5 · 4 files · 3 commits · open

On Windows, a title import of memcpy or memset from VCRUNTIME140.dll can write through a writable view of the same physical section while its title mapping stays read-only. Enable the experiment with VICTORY_COPY_BESIDE=1. The default keeps the host CRT bindings and the existing section layout.

The hook processes one 64 KiB destination page at a time. It pins the view registration, verifies protection, marks the page and its aliases dirty, and lets armed trackers save the old bytes before writing under the guard lock. Ordinary writes run after releasing those locks. A small bit table skips registry lookups for ordinary address regions. A stale bit only causes another lookup. Remapping unregisters the view before unmapping it. The resolver still checks the host allow-list and the presence of the actual export.

Measurements

On a Ryzen 7 2700X, the ignored guarded_crt_copy_benchmark alternates 3,200 native and redirected 4 KiB writes per sample on the same 32 freshly guarded pages, including the tracker take. Every round checks the dirty range, and every sample verifies the final bytes. On the standalone branch the three native samples measured 7.36, 9.17 and 9.37 µs/copy. The redirected samples measured 0.70, 0.70 and 0.75 µs/copy.

On a separate RTX 2080 integration stack, two five-minute runs used the same diagnostic executable with the BVH builder held back. The enabled run logged a redirected CRT write. Both runs reached the world and ended at the cutoff without device removal. Medians below use complete reporting intervals after world entry with at least 500 draws per frame.

World metric Off On
Reporting intervals 23 27
Draws/frame 4,696 3,329
Faults entering the opening path/frame 1,206 1,006
Handler time (ms/frame) 785 647
Time opening pages (ms/frame) 552 448
Total ms/frame 3,366 3,405

Streaming and draw counts differed. An earlier pair, before the region filter, also varied substantially. These runs establish that the title uses the path and show lower guard overhead in the final pair. They do not establish higher world FPS.

Verification against main

  • The Windows tests cover a write crossing from a guarded page into an ordinary page, alias dirty marking, preservation of armed bytes, unregistration, and the region filter. Four concurrent writers exercised both CRT calls while the tracker refreshed a mirror. Ten separate process runs produced the expected final bytes on every page.
  • The HLE import-resolution and physical map/alias/unmap tests passed with the switch both off and on.
  • RTX 2080, Windows 10 19045, release diagnostics GPU library suite: 245 passed, 5 failed, 2 ignored. The clean main control had the same five failures (descriptor dynamic slots, placed texture views, compute rebind after depth conversion, shared table/view lifetime, and depth bounds), with 241 passed and 1 ignored. The added ignored test is the microbenchmark.

Integration

#3069 targets marked GPU copy-back and has independent evidence about readers overlapping a write. This change targets title CRT calls. It holds the guard lock from the dirty mark through the page chunk's write. A refresh that already obtained its dirty ranges can still overlap title activity. A multi-page CRT copy has ordinary CRT visibility. If #3035 lands, its optimistic snapshot validation will need to account for writes through retained guards and their aliases.

The CRT interception idea follows avatarmanz's VIctory work.

AI-assisted (Codex).

**@⁠lhnizdo** on GitHub · 2026-11-26 20:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3375) `lhnizdo:pr/guard-crt-copy` → `main` · +374 −5 · 4 files · 3 commits · open On Windows, a title import of `memcpy` or `memset` from `VCRUNTIME140.dll` can write through a writable view of the same physical section while its title mapping stays read-only. Enable the experiment with `VICTORY_COPY_BESIDE=1`. The default keeps the host CRT bindings and the existing section layout. The hook processes one 64 KiB destination page at a time. It pins the view registration, verifies protection, marks the page and its aliases dirty, and lets armed trackers save the old bytes before writing under the guard lock. Ordinary writes run after releasing those locks. A small bit table skips registry lookups for ordinary address regions. A stale bit only causes another lookup. Remapping unregisters the view before unmapping it. The resolver still checks the host allow-list and the presence of the actual export. ### Measurements On a Ryzen 7 2700X, the ignored `guarded_crt_copy_benchmark` alternates 3,200 native and redirected 4 KiB writes per sample on the same 32 freshly guarded pages, including the tracker take. Every round checks the dirty range, and every sample verifies the final bytes. On the standalone branch the three native samples measured 7.36, 9.17 and 9.37 µs/copy. The redirected samples measured 0.70, 0.70 and 0.75 µs/copy. On a separate RTX 2080 integration stack, two five-minute runs used the same diagnostic executable with the BVH builder held back. The enabled run logged a redirected CRT write. Both runs reached the world and ended at the cutoff without device removal. Medians below use complete reporting intervals after world entry with at least 500 draws per frame. | World metric | Off | On | |---|---:|---:| | Reporting intervals | 23 | 27 | | Draws/frame | 4,696 | 3,329 | | Faults entering the opening path/frame | 1,206 | 1,006 | | Handler time (ms/frame) | 785 | 647 | | Time opening pages (ms/frame) | 552 | 448 | | Total ms/frame | 3,366 | 3,405 | Streaming and draw counts differed. An earlier pair, before the region filter, also varied substantially. These runs establish that the title uses the path and show lower guard overhead in the final pair. They do not establish higher world FPS. ### Verification against main - The Windows tests cover a write crossing from a guarded page into an ordinary page, alias dirty marking, preservation of armed bytes, unregistration, and the region filter. Four concurrent writers exercised both CRT calls while the tracker refreshed a mirror. Ten separate process runs produced the expected final bytes on every page. - The HLE import-resolution and physical map/alias/unmap tests passed with the switch both off and on. - RTX 2080, Windows 10 19045, release diagnostics GPU library suite: 245 passed, 5 failed, 2 ignored. The clean main control had the same five failures (descriptor dynamic slots, placed texture views, compute rebind after depth conversion, shared table/view lifetime, and depth bounds), with 241 passed and 1 ignored. The added ignored test is the microbenchmark. ### Integration #3069 targets marked GPU copy-back and has independent evidence about readers overlapping a write. This change targets title CRT calls. It holds the guard lock from the dirty mark through the page chunk's write. A refresh that already obtained its dirty ranges can still overlap title activity. A multi-page CRT copy has ordinary CRT visibility. If #3035 lands, its optimistic snapshot validation will need to account for writes through retained guards and their aliases. The CRT interception idea follows [avatarmanz's VIctory work](https://github.com/avatarmanz/VIctory-7900XTX). AI-assisted (Codex).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:55:02 +00:00
This pull request can be merged automatically.
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/3375/head:github-bot/gh-3375'
git switch 'github-bot/gh-3375'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3375'
git switch 'github-bot/gh-3375'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3375'
git switch 'github-bot/gh-3375'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3375'
git switch 'main'
git merge --squash 'github-bot/gh-3375'
git switch 'main'
git merge --ff-only 'github-bot/gh-3375'
git switch 'main'
git merge 'github-bot/gh-3375'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3375
No description provided.