GPU: keep a title guard page inside a range; change guards in runs #68

Open
github-bot wants to merge 2 commits from github-bot/gh-68 into main AGit
Owner

@⁠zocram4cc on GitHub · 2026-11-26 01:28 UTC · original
zocram4cc:up/guard-runs → main · +585 −49 · 3 files · 2 commits · open

Promised to @⁠itsonewi on #14 (review of "copies of title memory"): a separate PR for this bug, with its own test. It does not depend on #14: this branch is cut from avatarmanz/VIctory-7900XTX main and contains none of #14's code.

Bug: a title guard page inside a protected block loses its guard

protect_here (a range) and protect_alias (another view of a guarded page) made PAGE_READONLY over a whole 64 KiB block, or over a whole range, after looking at the first page's old protection only. A page the title guards itself (PAGE_GUARD) further on in that block lost its guard: nothing faulted and nothing was seen written, so the title's own guard never fired.

Now a change of protection covers only blocks that Windows says are alike (committed, one region, read-only or read-write throughout). A block that is not gets no call and stays as it is, with VICTORY_GUARD_RUNS on or off.

Tests (the two bug tests run with the switch off and on):

  • watch::tests::a_page_the_title_guards_inside_a_range_keeps_its_guard: on v7900/main the guarded page reads PAGE_READONLY (left: 2) instead of PAGE_READWRITE | PAGE_GUARD (right: 260).
  • watch::tests::a_page_the_title_guards_in_another_view_keeps_its_guard: left: 2, right: 260 before the protect_alias check; green with it.

Change guards in runs (VICTORY_GUARD_RUNS, on by default)

Each change of protection is a kernel call; under Wine it is an mprotect and a flush of every processor's address cache. The guards changed protection one block at a call, after asking for a whole range first where it could be refused across views. With the switch on:

  • giving write access back: blocks that follow one another in one view are opened with one call;
  • making read-only: one call per run of alike blocks within each view the runtime told of (a call across two views is refused, so runs are cut there);
  • the other views of a run of guarded pages are made read-only with one call per run.

With VICTORY_GUARD_RUNS=0 a range is asked for whole only when it is one alike region; otherwise each block gets its own call. The refused call across views is no longer made: runs_of_guarded_blocks_are_cut_where_views_meet expects 6 calls there, not 7.

In-game counter (Proton Experimental, v7900 base, one scripted run)

Frame-line counter (diagnostics builds), two steady windows, per frame:

window giving write access back: calls / blocks making read-only: calls / blocks
54 frames 428.7 / 428.7 316.0 / 430.9
55 frames 425.3 / 425.3 309.4 / 424.8
  • Read-only: 316 calls for 431 blocks, 27 % fewer calls than blocks (309 for 425 in the second window, also 27 %). This is calls against blocks in one run, not a before/after figure: that run did not include VICTORY_GUARD_RUNS=0.
  • Giving access back: no runs formed in this run (428.7 calls for 428.7 blocks), so this change did not batch that path there. Why the opens come one block at a time was not investigated.
  • Refused calls: 0.00 per frame in both windows.

No frame-time change measured. The only two frame-time runs (98.0 ms/frame median in an earlier run without the bug fix or the runs, 100.9 ms in the run with both) are not an A/B: they differ in more than this change. I make no frame-time claim either way.

Credits

  • Marvisak/VIctory PR #2849 (Therecalloftheonion): one VirtualProtect per run of guarded pages, the idea behind the runs.
  • Marvisak/VIctory PR #2848 item 6 (pes7): guarded pages given back in runs.

As we read their code, their runs ignore view boundaries and the call's result, so it does not fit this tree; this is a new implementation.

Testing

  • Build: cargo xwin build --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc passes.
  • Clippy -D warnings (cargo xwin clippy -p victory-gpu --all-targets, default and --all-features): every diagnostic it reports is on a line this PR does not change.
  • Red before green: on v7900/main, with the six tests of the first batch added and the protection calls counted (behaviour unchanged), five fail (the run-count tests and the range bug test); other_memory_inside_a_run_keeps_its_protection passes there too, since the old code already kept other memory's protection. The other-view test fails on the port before the protect_alias check and passes after it.
  • watch:: module under Proton: the same three tests fail on the unchanged base and here (holes_are_known_until_the_runtime_tells, no_mapping_is_lost_between_askers, what_is_left_alone_is_no_known_hole). No new failures.
  • Windows untested: every run was under Proton (Wine) on Linux; nothing ran on native Windows.

AI-assisted: yes. Drafted with an AI coding assistant; the tests were run under Proton; the counter numbers come from the in-game run above.

**@⁠zocram4cc** on GitHub · 2026-11-26 01:28 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/68) `zocram4cc:up/guard-runs` → `main` · +585 −49 · 3 files · 2 commits · open Promised to @⁠itsonewi on #14 (review of "copies of title memory"): a separate PR for this bug, with its own test. It does not depend on #14: this branch is cut from `avatarmanz/VIctory-7900XTX` `main` and contains none of #14's code. ## Bug: a title guard page inside a protected block loses its guard `protect_here` (a range) and `protect_alias` (another view of a guarded page) made `PAGE_READONLY` over a whole 64 KiB block, or over a whole range, after looking at the first page's old protection only. A page the title guards itself (`PAGE_GUARD`) further on in that block lost its guard: nothing faulted and nothing was seen written, so the title's own guard never fired. Now a change of protection covers only blocks that Windows says are alike (committed, one region, read-only or read-write throughout). A block that is not gets no call and stays as it is, with `VICTORY_GUARD_RUNS` on or off. Tests (the two bug tests run with the switch off and on): - `watch::tests::a_page_the_title_guards_inside_a_range_keeps_its_guard`: on v7900/main the guarded page reads `PAGE_READONLY` (`left: 2`) instead of `PAGE_READWRITE | PAGE_GUARD` (`right: 260`). - `watch::tests::a_page_the_title_guards_in_another_view_keeps_its_guard`: `left: 2`, `right: 260` before the `protect_alias` check; green with it. ## Change guards in runs (`VICTORY_GUARD_RUNS`, on by default) Each change of protection is a kernel call; under Wine it is an `mprotect` and a flush of every processor's address cache. The guards changed protection one block at a call, after asking for a whole range first where it could be refused across views. With the switch on: - giving write access back: blocks that follow one another in one view are opened with one call; - making read-only: one call per run of alike blocks within each view the runtime told of (a call across two views is refused, so runs are cut there); - the other views of a run of guarded pages are made read-only with one call per run. With `VICTORY_GUARD_RUNS=0` a range is asked for whole only when it is one alike region; otherwise each block gets its own call. The refused call across views is no longer made: `runs_of_guarded_blocks_are_cut_where_views_meet` expects 6 calls there, not 7. ### In-game counter (Proton Experimental, v7900 base, one scripted run) Frame-line counter (diagnostics builds), two steady windows, per frame: | window | giving write access back: calls / blocks | making read-only: calls / blocks | |---|---|---| | 54 frames | 428.7 / 428.7 | 316.0 / 430.9 | | 55 frames | 425.3 / 425.3 | 309.4 / 424.8 | - Read-only: 316 calls for 431 blocks, 27 % fewer calls than blocks (309 for 425 in the second window, also 27 %). This is calls against blocks in one run, not a before/after figure: that run did not include `VICTORY_GUARD_RUNS=0`. - Giving access back: no runs formed in this run (428.7 calls for 428.7 blocks), so this change did not batch that path there. Why the opens come one block at a time was not investigated. - Refused calls: 0.00 per frame in both windows. **No frame-time change measured.** The only two frame-time runs (98.0 ms/frame median in an earlier run without the bug fix or the runs, 100.9 ms in the run with both) are not an A/B: they differ in more than this change. I make no frame-time claim either way. ## Credits - Marvisak/VIctory PR #2849 (Therecalloftheonion): one `VirtualProtect` per run of guarded pages, the idea behind the runs. - Marvisak/VIctory PR #2848 item 6 (pes7): guarded pages given back in runs. As we read their code, their runs ignore view boundaries and the call's result, so it does not fit this tree; this is a new implementation. ## Testing - Build: `cargo xwin build --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvc` passes. - Clippy `-D warnings` (`cargo xwin clippy -p victory-gpu --all-targets`, default and `--all-features`): every diagnostic it reports is on a line this PR does not change. - Red before green: on v7900/main, with the six tests of the first batch added and the protection calls counted (behaviour unchanged), five fail (the run-count tests and the range bug test); `other_memory_inside_a_run_keeps_its_protection` passes there too, since the old code already kept other memory's protection. The other-view test fails on the port before the `protect_alias` check and passes after it. - `watch::` module under Proton: the same three tests fail on the unchanged base and here (`holes_are_known_until_the_runtime_tells`, `no_mapping_is_lost_between_askers`, `what_is_left_alone_is_no_known_hole`). No new failures. - Windows untested: every run was under Proton (Wine) on Linux; nothing ran on native Windows. AI-assisted: yes. Drafted with an AI coding assistant; the tests were run under Proton; the counter numbers come from the in-game run above.
protect_here and protect_alias made PAGE_READONLY over a whole 64 KiB block,
or over a whole range, after looking at the first page's old protection
only. A PAGE_GUARD page the title set further on in that block lost its guard
with no fault and no write seen. Now a change of protection covers only
blocks that Windows says are alike (committed, one region, read-only or
read-write throughout). A block that is not gets no call and stays as it is,
with VICTORY_GUARD_RUNS on or off.

Runs (VICTORY_GUARD_RUNS, on; =0 keeps one call per block where a range is
not one alike region):
- unguard: blocks that follow one another in one view are opened with one
  call.
- protect_here: one call per run of alike blocks within each view the runtime
  told of. A call across two views is refused, so runs are cut there.
- cover: the other views of a run of guarded pages are made read-only with
  one call per run (protect_alias_runs); protect_alias takes what is left.

With =0 a range is asked for whole only when it is one alike region, so the
call across views that was refused is no longer made.

Counter on victory_gpu::host (diagnostics builds), on the 5 s lines: calls and
blocks per frame for giving write access back and for making read-only, and
the refused ones ("the guards' changes of protection per frame").

Tests (watch::tests): a_write_over_guarded_blocks_opens_them_with_one_call,
a_write_inside_guarded_blocks_opens_its_own_and_no_others,
runs_of_guarded_blocks_are_cut_where_views_meet,
other_memory_inside_a_run_keeps_its_protection,
the_other_views_of_a_guarded_run_are_guarded_with_one_call,
a_page_the_title_guards_inside_a_range_keeps_its_guard,
a_page_the_title_guards_in_another_view_keeps_its_guard.

Credits: Marvisak/VIctory PR #2849 (Therecalloftheonion) for the idea of one
change of protection per run of guarded pages; PR #2848 item 6 (pes7) for
giving guarded pages back in runs. As we read them, their runs ignore view
boundaries and the call's result, so their code does not fit this tree; this
is a new implementation for it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:43 +00:00
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:33 UTC · original

Left open: conflicts with main (host.rs), and VICTORY_GUARD_RUNS is on by default; needs a rebase and an in-game check.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/68#issuecomment-7185591145) Left open: conflicts with main (host.rs), and VICTORY_GUARD_RUNS is on by default; needs a rebase and an in-game check.
github-bot force-pushed github-bot/gh-68 from 8b8da9b06f to c56e299e23 2026-11-26 08:15:13 +00:00 Compare
Author
Owner

@⁠zocram4cc on GitHub · 2026-11-26 08:12 UTC · original

Rebased onto current main (the 5 s lines moved into meter_lines; the guard counter line is called there now) and VICTORY_GUARD_RUNS is off by default now (=1 turns the batching on). The guard-page fix does not depend on the switch: with it off, a range is asked for whole only when it is one alike region, and a block that is not alike is left as it is.

In-game check on main + this branch (Proton, RX 6900 XT) follows; I will post the numbers here.

**@⁠zocram4cc** on GitHub · 2026-11-26 08:12 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/68#issuecomment-7186325244) Rebased onto current `main` (the 5 s lines moved into `meter_lines`; the guard counter line is called there now) and `VICTORY_GUARD_RUNS` is **off by default** now (`=1` turns the batching on). The guard-page fix does not depend on the switch: with it off, a range is asked for whole only when it is one alike region, and a block that is not alike is left as it is. In-game check on `main` + this branch (Proton, RX 6900 XT) follows; I will post the numbers here.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/watch.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/68/head:github-bot/gh-68'
git switch 'github-bot/gh-68'

Merge

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