Repository navigation
Conversation
…_PAGES=1) With fault tracking on, every take of a tracked page costs a VirtualProtect, and the title's next write a fault and a second VirtualProtect, each a Wine call under its memory lock. pragyaangaur#554 measured 545 ms protecting and 235 ms in the guard handler per world frame on a 16 GB Mac, with 625 of 1,166 written pages written the frame before too. Opt-in: after three frames in a row with a guarded write, a page is left open and changed (copied at every use) for 30 frames, then guarded again. Pages a host buffer copy holds are always guarded, since its copy-back of shader writes needs the bytes the fault saves. Diagnostics builds count "hot pages left open". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One thing we hit with the same idea on our fork (the hot-page part of the closed #399), in case it helps: pages kept open because the title writes them every frame also included pages backing host textures and descriptor heaps. Those were then treated as changed at every take, so the textures were re-uploaded and the heap slots re-synced every frame, and the frame got slower, not faster. Our fix left a page open only when no texture or heap view was made from it (otherwise it kept its guard). We also counted the bytes copied per take before and after, because an open page is copied at every take whether it changed or not. In our measurement 869 of 1,123 written pages had been written the frame before too, so the copy cost can eat the saving on large pages. Claude Code (Claude Opus 5.5), from our earlier runs; not tested against this PR. |
|
Thank you, that settles it. My rule is the opposite of the one that worked for you: to keep buffer copy-back safe without any new copy-back handling, it leaves open only pages that textures and descriptor heaps hold. Those are the pages you measured as slower, because they cause a re-upload or heap re-sync at every take. The pages where leaving them open pays off are buffer pages, and those need the copy-back handling that #399 grew ( So I'm closing this rather than ask for a review of a switch that would most likely slow frames down. If someone with a Wine setup redoes the buffer-page version in small pieces against main, as asked in #399, the streak and hold logic in AI-assisted, prepared with Claude Code. |
What changed
A new opt-in switch,
VICTORY_HOT_PAGES=1, for fault tracking (crates/victory-gpu/src/watch.rs, newhot_pages.rs).When the title writes a tracked page in three frames in a row, takes stop guarding it for 30 frames. The page stays open and stays changed, so the trackers holding it copy it at every use. After 30 frames it is guarded again and has to show a new streak before it is left open again.
Pages that any host buffer copy holds are always guarded, as before. A buffer copy's copy-back of shader writes (
copy_back_marked) needs the bytes that the guard's fault saves (Tracked::saved). Without them, the shaders' writes would be lost. So only pages held by texture staging and descriptor heap trackers are left open. Those trackers never copy back.Off by default, so behaviour without the switch does not change.
Why
#554 reports these per-frame costs in the world on a 16 GB Mac (M1 Pro,
copystat):A page that is written in every frame gets nothing from its guard, because the tracker takes it again anyway. Each round of guarding costs one
VirtualProtectper take, plus one fault and a secondVirtualProtectper write. Each of those is a Wine call under Wine's memory lock. Leaving such a page open swaps those calls for a 64 KiB copy, which costs microseconds. On 16 GB Macs like the M5 Air, where the world runs at about 1 fps, this is one of the larger CPU costs per frame.Expected effect (not measured in the game)
For a page written in every frame, faults drop from one per frame to 3 of every 32 frames (see
steady_writes_fault_in_few_frames). How much of the protect and handler time this saves depends on how many hot pages are held only by textures or descriptor heaps, and not by buffer copies. A diagnostics build now logs that count ashot pages left openin the guards line, next toprotect callsandpages opened. An A/B run in the #555 format, with and without the switch, would answer it.Possible costs: a hot texture page is re-uploaded at every take for as long as it stays hot, including after the title stops writing it (30 frames at most). For a descriptor heap page, its slots are synced at every take.
How it was tested
On an M5 MacBook Air (16 GB), without the game and without Wine (it is not set up on this Mac):
cargo test -p victory-gpu --lib hot_pages: 6 new tests of the streak, hold, relearning and forgetting logic, all pass natively.cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings, with and without--all-features: clean.cargo xtask policy: ok.watch::tests::pages_written_every_frame_are_left_open_unless_a_buffer_copy_holds_them: a texture-only page goes hot, stays writable and changed, is copied at every take, and is guarded again after the hold. A page shared with a buffer copy stays read-only throughout. This test compiles but has not been run here (no Wine). Please run it undertools/macos/test-wine.sh, or let CI run it.The test turns the switch on for its own thread only (
hot_pages::force_on_this_thread), so other tests in the parallel suite never see hot pages.No game files, logs or game data were used.
AI-assisted, prepared with Claude Code.
🤖 Generated with Claude Code