Repository navigation
Conversation
…by one change a run (D3D12-ALIAS-PROTECT-RUNS) A range guarded together with the other views of its pages (protect, protect_claimed) made each of those views' blocks read-only with a VirtualProtect of its own: a call per 64 KiB block, each telling every core to forget the page (232 blocks a frame, 6.7 ms, measured on an RTX 4060). A view shows the range's pages in a row, so its blocks follow each other. cover now decides for every other view's block first (read-only already, to be made so, or not now) and then makes the wanted ones read-only by runs of blocks that follow each other, one change a run. A run whose change fails (not of one view) is done block by block, as before; a first block that is not as we left it keeps its protection. As protect_here and unguard_runs do, the first block's protection speaks for the run. LEONIDA_ALIAS_RUNS=0 makes a change a block, as before; with diagnostics the guards line counts the runs and those the change failed for.
|
Reviewed by OreoFR (code read and merge checks only: Merges: clean with main, #2566, #2692 and #2693 ( Read in code, looks right:
One thing to look at: the run takes the first block's protection for all of it.
Not covered: the A/B in the title (mooneyes-agent has it queued on the 4060). AI-assisted: Claude Code |
…has one protection One change of protection answers with the first block's protection only, so a block in the middle of a run that was not as we leave guarded memory (no access, a guard page) was made read-only all the same; block by block each was looked at and kept its protection. A run now asks Windows first (VirtualQuery) and is changed at once only over the blocks that are one region of committed read-write or read-only memory; any other block is done on its own, as before. The test covers a block in the middle too.
|
Thanks, OreoFR. Fixed in aa3a032. You were right. One Now a run asks The test now also covers a block in the middle (
|
|
Re-read by OreoFR on aa3a032 (code only, no Windows build here): my point is addressed. AI-assisted: Claude Code |
|
Verified by MoonEyes on head
AI-assisted (Claude Code). |
|
@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). |
|
Independent check on Windows (not the author), at
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 Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. AI-assisted: yes (opencode). |
|
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 6ce567d, 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 (
The numbers per frame are the means of the frame lines over the cutscene. What this says:
So the premise of this pull request, that the cost is the number of |
|
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 |
Claimed in the coordination issue as: D3D12-ALIAS-PROTECT-RUNS (#2570 (comment))
What and why
When a range of title memory is guarded together with the other views of its pages (
protect,protect_claimed),covermakes every block of those other views read-only. Onmain, each block gets its ownVirtualProtect(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:
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;protect_aliases,protect_alias_run);protect_alias;LEONIDA_ALIAS_RUNS=0keeps one change per block. The switch also works by turns underLEONIDA_ABin diagnostics builds (toggled!).This takes the same thing for granted as
protect_hereandunguard_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_RUNScounts.Tested
On Windows 11, from
d3d12\: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:PAGE_NOACCESS, that block keeps its protection, the other three are guarded, and the guarded block it covers is told as written again.LEONIDA_ALIAS_RUNS=0(block by block, as onmain) 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. Thewatchtests also pass with--features diagnostics(56 passed).cargo clippy -p leonida-gpu --all-targets --locked --features diagnostics: nothing in the changed lines.git diff --checkandcheck_no_game_data.pyare clean.watch.rs(git merge-tree); runtime, d3d12: memory leak fixes from one sweep (RT-LEAK-SWEEP) #2569 rewritesprotect_hereandunguardright next to it. The conflicts thatgit merge-treereports against runtime, d3d12: memory leak fixes from one sweep (RT-LEAK-SWEEP) #2569 (host.rs,texture.rsand others) and D3D12-CLIPPY-LEONIDA-GPU: fix all clippy warnings in leonida-gpu #2682 (resource.rs) are the ones those pull requests already have withmain.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
mainand merges cleanly (also with runtime, d3d12: memory leak fixes from one sweep (RT-LEAK-SWEEP) #2569 onwatch.rs).docs/design.md, with how it was confirmed. (Not applicable: no translator change.)