d3d12: the other views' blocks of a guarded range are made read-only by one change a run (D3D12-ALIAS-PROTECT-RUNS) #2701

Closed
TheGeogeo wants to merge 3 commits from upstream-pr/2701 into main
TheGeogeo commented 2026-11-30 07:51:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T07:51:48Z.


Claimed in the coordination issue as: D3D12-ALIAS-PROTECT-RUNS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7272204787)

What and why

When a range of title memory is guarded together with the other views of its pages (protect, protect_claimed), cover makes every block of those other views read-only. On main, each block gets its own VirtualProtect (protect_alias): one call per 64 KiB block, and each call tells every core to forget the page. MoonEyes measured this at 232 blocks and 6.7 ms a frame on an RTX 4060 (about 29 us a block). OreoFR found the cause by reading the code.

A view shows the range's pages in a row, so the blocks wanted in one view follow each other. This change:

  • in cover, first decides for every other view's block (alias): read-only already, to be made read-only, or not now (the claim is held elsewhere, or the block is left alone or resting); these are the same tests as before;
  • then makes the wanted blocks read-only by runs of blocks that follow each other, one change per run (protect_aliases, protect_alias_run);
  • does a run whose change fails (for example one across two views) block by block with the old protect_alias;
  • when the first block of a run is not as we left it, restores that block's protection and leaves it uncovered, as before;
  • LEONIDA_ALIAS_RUNS=0 keeps one change per block. The switch also works by turns under LEONIDA_AB in diagnostics builds (toggled!).

This takes the same thing for granted as protect_here and unguard_runs: the first block's protection speaks for the run. A guarded block whose other view could not be covered is not clean, as before.

With diagnostics, the guards line now also counts the runs made read-only by one change and the runs where that change failed, next to the existing LEONIDA_UNGUARD_RUNS counts.

Tested

On Windows 11, from d3d12\:

  • New test watch::tests::another_views_blocks_are_guarded_by_one_change. It maps two views of one section, guards four blocks of the first, and checks two things:
    • the other view's four blocks become read-only through one run;
    • when the other view's first block was set to PAGE_NOACCESS, that block keeps its protection, the other three are guarded, and the guarded block it covers is told as written again.
  • With LEONIDA_ALIAS_RUNS=0 (block by block, as on main) the test fails ("the other view's four blocks were not made read-only by one change"). With the change it passes.
  • cargo test -p leonida-gpu --locked: 560 passed, 50 ignored. The watch tests also pass with --features diagnostics (56 passed).
  • cargo clippy -p leonida-gpu --all-targets --locked --features diagnostics: nothing in the changed lines. git diff --check and check_no_game_data.py are clean.
  • It merges cleanly with #2569 on watch.rs (git merge-tree); #2569 rewrites protect_here and unguard right next to it. The conflicts that git merge-tree reports against #2569 (host.rs, texture.rs and others) and #2682 (resource.rs) are the ones those pull requests already have with main.
  • In game: not measured on my machine. MoonEyes offered to run the A/B on the RTX 4060 where the 6.7 ms were measured. The new counts on the guards line, and the existing protection time in the frame line, give the before and after directly.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300 (unit tests only).

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (also with #2569 on watch.rs).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5561236808 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T07:51:48Z. --- Claimed in the coordination issue as: D3D12-ALIAS-PROTECT-RUNS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7272204787) ### What and why When a range of title memory is guarded together with the other views of its pages (`protect`, `protect_claimed`), `cover` makes every block of those other views read-only. On `main`, each block gets its own `VirtualProtect` (`protect_alias`): one call per 64 KiB block, and each call tells every core to forget the page. MoonEyes measured this at 232 blocks and 6.7 ms a frame on an RTX 4060 (about 29 us a block). OreoFR found the cause by reading the code. A view shows the range's pages in a row, so the blocks wanted in one view follow each other. This change: - in `cover`, first decides for every other view's block (`alias`): read-only already, to be made read-only, or not now (the claim is held elsewhere, or the block is left alone or resting); these are the same tests as before; - then makes the wanted blocks read-only by runs of blocks that follow each other, one change per run (`protect_aliases`, `protect_alias_run`); - does a run whose change fails (for example one across two views) block by block with the old `protect_alias`; - when the first block of a run is not as we left it, restores that block's protection and leaves it uncovered, as before; - `LEONIDA_ALIAS_RUNS=0` keeps one change per block. The switch also works by turns under `LEONIDA_AB` in diagnostics builds (`toggled!`). This takes the same thing for granted as `protect_here` and `unguard_runs`: the first block's protection speaks for the run. A guarded block whose other view could not be covered is not clean, as before. With diagnostics, the guards line now also counts the runs made read-only by one change and the runs where that change failed, next to the existing `LEONIDA_UNGUARD_RUNS` counts. ### Tested On Windows 11, from `d3d12\`: - New test `watch::tests::another_views_blocks_are_guarded_by_one_change`. It maps two views of one section, guards four blocks of the first, and checks two things: - the other view's four blocks become read-only through one run; - when the other view's first block was set to `PAGE_NOACCESS`, that block keeps its protection, the other three are guarded, and the guarded block it covers is told as written again. - With `LEONIDA_ALIAS_RUNS=0` (block by block, as on `main`) the test fails ("the other view's four blocks were not made read-only by one change"). With the change it passes. - `cargo test -p leonida-gpu --locked`: 560 passed, 50 ignored. The `watch` tests also pass with `--features diagnostics` (56 passed). - `cargo clippy -p leonida-gpu --all-targets --locked --features diagnostics`: nothing in the changed lines. `git diff --check` and `check_no_game_data.py` are clean. - It merges cleanly with #2569 on `watch.rs` (`git merge-tree`); #2569 rewrites `protect_here` and `unguard` right next to it. The conflicts that `git merge-tree` reports against #2569 (`host.rs`, `texture.rs` and others) and #2682 (`resource.rs`) are the ones those pull requests already have with `main`. - In game: not measured on my machine. MoonEyes offered to run the A/B on the RTX 4060 where the 6.7 ms were measured. The new counts on the guards line, and the existing protection time in the frame line, give the before and after directly. GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300 (unit tests only). AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (also with #2569 on `watch.rs`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not applicable: no translator change.)
OreoFR commented 2026-11-30 08:02:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T08:02:01Z.


Reviewed by OreoFR (code read and merge checks only: leonida-gpu does not build on macOS, so no cargo test here), main e1fe82f63, PR head 90aaade09.

Merges: clean with main, #2566, #2692 and #2693 (git merge-tree). Against #2569 there are conflicts in host.rs, texture.rs, leonida-hle/src/modules/xmem.rs and d3d12/docs/findings.md, none in watch.rs; #2569 already conflicts with main on those files, so that is not this PR's.

Read in code, looks right:

  • cover now only classifies (alias → ReadOnly / Wanted / Not) and protects afterwards. The claim of each alias block is still taken in alias, before the deferred protection, and held until cover returns, so a fault cannot slip in between the decision and the VirtualProtect.
  • A failed block maps back to the block it covers (w.1), which loses clean as before. The same block wanted twice stays in one run (wanted[k].0 == wanted[k - 1].0).
  • A failed range call clears PROTECTED and falls back to block by block, and LEONIDA_ALIAS_RUNS=0 keeps one call a block.

One thing to look at: the run takes the first block's protection for all of it. VirtualProtect over [from, to) returns in old the protection of the first page only. The code checks old and gives the first block back if it was not ours, but every middle block is set PAGE_READONLY and noted g.protected whatever it was before. On main, protect_alias checked each block's own old.

  • If a view can have a middle block in another state (left PAGE_NOACCESS or PAGE_GUARD by the title, or PAGE_EXECUTE_*), this PR changes and forgets it, where main gave it back.
  • The doc says the same assumption is already made by protect_here and unguard_runs. If that is known to hold for xmem views, fine. If not, a cheap guard would be one VirtualQuery before the range call, using the range call only when the region it returns has one protection and covers the whole run.
  • The new test exercises a different first block only; a different block in the middle would show it.

Not covered: the A/B in the title (mooneyes-agent has it queued on the 4060).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7272404414 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7272404414). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T08:02:01Z. --- Reviewed by OreoFR (code read and merge checks only: `leonida-gpu` does not build on macOS, so no `cargo test` here), main e1fe82f63, PR head 90aaade09. **Merges:** clean with main, #2566, #2692 and #2693 (`git merge-tree`). Against #2569 there are conflicts in `host.rs`, `texture.rs`, `leonida-hle/src/modules/xmem.rs` and `d3d12/docs/findings.md`, none in `watch.rs`; #2569 already conflicts with main on those files, so that is not this PR's. **Read in code, looks right:** - `cover` now only classifies (`alias` → `ReadOnly` / `Wanted` / `Not`) and protects afterwards. The claim of each alias block is still taken in `alias`, before the deferred protection, and held until `cover` returns, so a fault cannot slip in between the decision and the `VirtualProtect`. - A failed block maps back to the block it covers (`w.1`), which loses `clean` as before. The same block wanted twice stays in one run (`wanted[k].0 == wanted[k - 1].0`). - A failed range call clears `PROTECTED` and falls back to block by block, and `LEONIDA_ALIAS_RUNS=0` keeps one call a block. **One thing to look at: the run takes the first block's protection for all of it.** `VirtualProtect` over `[from, to)` returns in `old` the protection of the **first** page only. The code checks `old` and gives the first block back if it was not ours, but every **middle** block is set `PAGE_READONLY` and noted `g.protected` whatever it was before. On main, `protect_alias` checked each block's own `old`. - If a view can have a middle block in another state (left `PAGE_NOACCESS` or `PAGE_GUARD` by the title, or `PAGE_EXECUTE_*`), this PR changes and forgets it, where main gave it back. - The doc says the same assumption is already made by `protect_here` and `unguard_runs`. If that is known to hold for xmem views, fine. If not, a cheap guard would be one `VirtualQuery` before the range call, using the range call only when the region it returns has one protection and covers the whole run. - The new test exercises a different **first** block only; a different block in the middle would show it. Not covered: the A/B in the title (mooneyes-agent has it queued on the 4060). AI-assisted: Claude Code
TheGeogeo commented 2026-11-30 08:05:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T08:05:50Z.


Thanks, OreoFR. Fixed in aa3a0328b.

You were right. One VirtualProtect over a run reports the old protection of the first block only. A block in the middle that was not read-write or read-only (no access, a guard page) became read-only anyway. On main, each block was checked and kept its own protection.

Now a run asks VirtualQuery first, and changes at once only the blocks that form one region of committed read-write or read-only memory (one_protection). Any other block is done on its own with the old protect_alias, as before. The query does not change protections, so it does not tell every core to forget the pages; the saving from one change per run stays.

The test now also covers a block in the middle (PAGE_NOACCESS on the other view's third block). On 90aaade09 that case fails: the block becomes read-only. With the fix it keeps PAGE_NOACCESS, the other three are guarded, and the guarded block it covers is told as written again.

  • cargo test -p leonida-gpu --locked: 560 passed.
  • The watch tests also pass with --features diagnostics.
  • The test still fails with LEONIDA_ALIAS_RUNS=0.
  • clippy: nothing in the changed lines.
  • watch.rs still merges cleanly with #2569.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7272477272 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7272477272). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T08:05:50Z. --- Thanks, OreoFR. Fixed in aa3a0328b. You were right. One `VirtualProtect` over a run reports the old protection of the first block only. A block in the middle that was not read-write or read-only (no access, a guard page) became read-only anyway. On `main`, each block was checked and kept its own protection. Now a run asks `VirtualQuery` first, and changes at once only the blocks that form one region of committed read-write or read-only memory (`one_protection`). Any other block is done on its own with the old `protect_alias`, as before. The query does not change protections, so it does not tell every core to forget the pages; the saving from one change per run stays. The test now also covers a block in the middle (`PAGE_NOACCESS` on the other view's third block). On 90aaade09 that case fails: the block becomes read-only. With the fix it keeps `PAGE_NOACCESS`, the other three are guarded, and the guarded block it covers is told as written again. - `cargo test -p leonida-gpu --locked`: 560 passed. - The `watch` tests also pass with `--features diagnostics`. - The test still fails with `LEONIDA_ALIAS_RUNS=0`. - clippy: nothing in the changed lines. - `watch.rs` still merges cleanly with #2569.
OreoFR commented 2026-11-30 08:08:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T08:08:38Z.


Re-read by OreoFR on aa3a0328b (code only, no Windows build here): my point is addressed. one_protection asks VirtualQuery first and only lets a span go in one change up to the end of a single committed region that is PAGE_READWRITE or PAGE_READONLY. Windows ends a region where the attributes change, so a middle block in another state ends the span there. The end is floored to a whole block (/ BLOCK), so a block that is only partly in the region goes alone through protect_alias, as on main. The added middle-block PAGE_NOACCESS case in the test is the one I was missing. No further remarks from the code side; the A/B is with mooneyes-agent.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7272535440 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7272535440). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T08:08:38Z. --- Re-read by OreoFR on aa3a0328b (code only, no Windows build here): my point is addressed. `one_protection` asks `VirtualQuery` first and only lets a span go in one change up to the end of a single committed region that is `PAGE_READWRITE` or `PAGE_READONLY`. Windows ends a region where the attributes change, so a middle block in another state ends the span there. The end is floored to a whole block (`/ BLOCK`), so a block that is only partly in the region goes alone through `protect_alias`, as on main. The added middle-block `PAGE_NOACCESS` case in the test is the one I was missing. No further remarks from the code side; the A/B is with mooneyes-agent. AI-assisted: Claude Code
MoonEyes commented 2026-11-30 13:42:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T13:42:53Z.


Verified by MoonEyes on head 6ce567d0b (a merge of main on top of aa3a0328b; the pull request's own change is the same), on main f9f3ec4c6. Windows 11, Rust toolchain of d3d12/rust-toolchain.toml.

  • cargo test -p leonida-gpu --lib --locked: main 563 passed, 52 ignored; with this pull request 564 passed, 0 failed. Red: not tried.
  • In game, RTX 4060 8 GB, -SeriesS -FrameGen 2, standing, 600 s, main + #2692 + #2693 + #2701 in one build: no device loss, no unhandled exception, median 17.8 fps in the world. One run, the three together, so it says nothing of this one's gain; the picture was not looked at.
  • LEONIDA_AB=4,LEONIDA_ALIAS_RUNS in that run, 72 pairs at a steady draw count: on minus off, frame mean -0.01 ms (+-0.19), median +0.10 (+-0.17), submitting thread -0.00 (+-0.13). No effect on the frame here; the thread time it saves was not measured.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280246525 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7280246525). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T13:42:53Z. --- Verified by MoonEyes on head `6ce567d0b` (a merge of `main` on top of `aa3a0328b`; the pull request's own change is the same), on `main` `f9f3ec4c6`. Windows 11, Rust toolchain of `d3d12/rust-toolchain.toml`. - `cargo test -p leonida-gpu --lib --locked`: `main` 563 passed, 52 ignored; with this pull request 564 passed, 0 failed. Red: not tried. - In game, RTX 4060 8 GB, `-SeriesS -FrameGen 2`, standing, 600 s, `main` + #2692 + #2693 + #2701 in one build: no device loss, no unhandled exception, median 17.8 fps in the world. One run, the three together, so it says nothing of this one's gain; the picture was not looked at. - `LEONIDA_AB=4,LEONIDA_ALIAS_RUNS` in that run, 72 pairs at a steady draw count: on minus off, frame mean -0.01 ms (+-0.19), median +0.10 (+-0.17), submitting thread -0.00 (+-0.13). No effect on the frame here; the thread time it saves was not measured. AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 13:46:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T13:46:04Z.


@TheGeogeo holding this one for now, not refusing it: on an RTX 4060 the A/B above shows no effect on the frame (-0.01 ms +-0.19, 72 pairs). If you can show the thread time it saves (the 6.7 ms you counted, with the switch by turns, or on a PC whose threads are busier), it can go in: cargo, a 600 s in-game run and CI are fine on this head.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280325799 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7280325799). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T13:46:04Z. --- @TheGeogeo holding this one for now, not refusing it: on an RTX 4060 the A/B above shows no effect on the frame (-0.01 ms +-0.19, 72 pairs). If you can show the thread time it saves (the 6.7 ms you counted, with the switch by turns, or on a PC whose threads are busier), it can go in: cargo, a 600 s in-game run and CI are fine on this head. AI-assisted (Claude Code).
KelboLive commented 2026-11-30 15:43:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:43:38Z.


Independent check on Windows (not the author), at 6ce567d0b.

  • Under heavy parallel load (four cargo test suites at once), one run had 563 passed, 1 failed: descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync, descriptor.rs:2260: assertion failed: host.made(5).
  • Isolated rerun of that test: pass.
  • Full rerun: 564 passed, 0 failed, 52 ignored (14.7 s).
  • main b17b22d33 under the same conditions: 570 passed, 0 failed.

So this is not a consistent regression from the branch; it looks like a load-sensitive flake in that descriptor test (the diff itself is copystat.rs/watch.rs). Worth a separate look only if it recurs without the four-way load.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283477063 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7283477063). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:43:38Z. --- Independent check on Windows (not the author), at `6ce567d0b`. - Under heavy parallel load (four `cargo test` suites at once), one run had **563 passed, 1 failed**: `descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync`, `descriptor.rs:2260: assertion failed: host.made(5)`. - Isolated rerun of that test: **pass**. - Full rerun: **564 passed, 0 failed, 52 ignored** (14.7 s). - `main` `b17b22d33` under the same conditions: **570 passed, 0 failed**. So this is not a consistent regression from the branch; it looks like a load-sensitive flake in that descriptor test (the diff itself is `copystat.rs`/`watch.rs`). Worth a separate look only if it recurs without the four-way load. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. AI-assisted: yes (opencode).
TheGeogeo commented 2026-11-30 17:12:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T17:12:49Z.


Measured the thread time, as MoonEyes asked: no gain. With alias runs on, the time spent changing protections stays the same within noise.

Setup: RTX 3080 10 GB, driver 32.0.16.2140, Windows 11. One diag build of head 6ce567d0b, the Series S preset, menus to world, then a 150 s scripted cutscene. The switch was alternated in A B B A order with warm caches (LEONIDA_ALIAS_RUNS on, off, off, on). I dropped the first two runs after the update to main: they were still paying the one-time shader retranslation.

run alias runs (by one change) blocks made read-only, a frame ms changing protections, a frame (all threads) ms waiting for the guards, a frame fps p99 ms
on 17,529 495 8.2 10.0 17.9 154
off 0 505 8.2 9.9 18.9 131
off 0 446 7.0 7.8 21.0 126
on 14,745 426 7.4 6.9 20.7 121

The numbers per frame are the means of the frame lines over the cutscene.

What this says:

  • The path does run: about 270,000 to 390,000 guarded blocks with other views in each run. With the switch on, about 15,000 to 17,500 runs went in one change each, and none failed.
  • The time changing protections does not drop: 7.8 ms a frame with runs against 7.6 ms without. The blocks made read-only per frame are the same in both arms. So the cost here is not per call. The kernel seems to pay per page or per block whatever the call groups, so fewer calls save nothing.
  • The frame times agree with MoonEyes' result on the RTX 4060: no effect.

So the premise of this pull request, that the cost is the number of VirtualProtect calls, does not hold on these two machines. I suggest closing it rather than adding code that saves nothing. I am leaving the decision to the maintainers and will close it unless someone sees a reason to keep the switch.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285898401 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7285898401). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T17:12:49Z. --- Measured the thread time, as MoonEyes asked: **no gain**. With alias runs on, the time spent changing protections stays the same within noise. Setup: RTX 3080 10 GB, driver 32.0.16.2140, Windows 11. One diag build of head 6ce567d0b, the Series S preset, menus to world, then a 150 s scripted cutscene. The switch was alternated in A B B A order with warm caches (`LEONIDA_ALIAS_RUNS` on, off, off, on). I dropped the first two runs after the update to `main`: they were still paying the one-time shader retranslation. | run | alias runs (by one change) | blocks made read-only, a frame | ms changing protections, a frame (all threads) | ms waiting for the guards, a frame | fps | p99 ms | | --- | --- | --- | --- | --- | --- | --- | | on | 17,529 | 495 | 8.2 | 10.0 | 17.9 | 154 | | off | 0 | 505 | 8.2 | 9.9 | 18.9 | 131 | | off | 0 | 446 | 7.0 | 7.8 | 21.0 | 126 | | on | 14,745 | 426 | 7.4 | 6.9 | 20.7 | 121 | The numbers per frame are the means of the frame lines over the cutscene. What this says: - The path does run: about 270,000 to 390,000 guarded blocks with other views in each run. With the switch on, about 15,000 to 17,500 runs went in one change each, and none failed. - The time changing protections does not drop: 7.8 ms a frame with runs against 7.6 ms without. The blocks made read-only per frame are the same in both arms. So the cost here is not per call. The kernel seems to pay per page or per block whatever the call groups, so fewer calls save nothing. - The frame times agree with MoonEyes' result on the RTX 4060: no effect. So the premise of this pull request, that the cost is the number of `VirtualProtect` calls, does not hold on these two machines. I suggest closing it rather than adding code that saves nothing. I am leaving the decision to the maintainers and will close it unless someone sees a reason to keep the switch.
TheGeogeo commented 2026-11-30 17:15:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T17:15:02Z.


Closing: the measurements show no gain. On an RTX 3080 (A B B A with the switch) and on an RTX 4060 (MoonEyes), batching the alias VirtualProtect calls leaves the time spent changing protections and the frame times unchanged: https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7285898401. The kernel's cost here is not per call, so the extra code would save nothing. Thanks to OreoFR for the finding and the review, and to MoonEyes for the A/B.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285960797 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7285960797). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-30T17:15:02Z. --- Closing: the measurements show no gain. On an RTX 3080 (A B B A with the switch) and on an RTX 4060 (MoonEyes), batching the alias `VirtualProtect` calls leaves the time spent changing protections and the frame times unchanged: https://github.com/ProjectLeonida/mandy/pull/2701#issuecomment-7285898401. The kernel's cost here is not per call, so the extra code would save nothing. Thanks to OreoFR for the finding and the review, and to MoonEyes for the A/B.

Pull request closed

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
ProjectLeonida/mandy!2701
No description provided.