GPU: write-watch askings repeat over nested buffers (120-180 ms a world frame); a fix is on a branch #776
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by schmiticle on 2026-11-24T10:25:57Z.
From a tester working with Claude (AI-assisted); measured on my own machine.
Pull requests here are limited to collaborators, so I'm offering this as a branch. If it's useful, a collaborator is welcome to open a PR from it:
https://github.com/schmiticle/VIctory/tree/gpu/write-watch-once-per-submission (one commit on
mainffe310e,watch.rsandhost.rs, merges cleanly)The problem
In the world, nested buffers (several views into one 174 MB block at
0x35030000, among others) each askGetWriteWatchabout largely the same pages. In the opening cutscene on an RX 9070 XT, thecopystatline showed 816-1,811 askings a frame taking 119-179 ms, with over 99% of the bytes checked unchanged. That one block was asked about ~23 times a frame.The change
While
Host::executeprepares a submission, the title's writes that submission must see are already made. So the preparing thread asks the kernel only about pages it has not asked about in that submission (watch::Sweep). It still answers from the journal, so a nested buffer sees what the outer asking found. A step that writes title memory during the preparation (Batch::title_written) clears what was asked, so later askings see that write. Other threads, and askings outside a submission, are unchanged.With it, the askings took 31-47 ms a frame. These were local builds with other open PRs stacked, so the numbers are indicative rather than a clean A/B on
main.Tests: three new ones in
watch.rs(interval helpers; a nested range sharing the outer answer; a write by the sweeping thread seen aftertitle_written).cargo test -p victory-gpu --lib, both clippy configurations from CI, andcargo xtask policypass.No game data used.
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-24T10:35:51Z.
Found a mixed-range write-watch regression on
c326bfaon native Windows.The fixture has two adjacent watched pages, A and B, followed by an unwatched page C. It queries B first, writes to A, then queries A–C. With the sweep enabled, the kernel query for A succeeds and resets its dirty bit. The query for C then fails, and
found.clear()discards the result for A. A subsequent query of A alone misses the write. The same fixture preserves the write with the sweep disabled.I tested a local fix that journals the successful answers even when the overall mixed-range query returns
None. Both regression cases pass, all 8 write-watch tests pass, and the WARP diagnostics library suite reports 58 passed and 1 ignored benchmark.Synthetic tests only. World-frame performance was not measured. AI-assisted investigation and testing.
Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T10:51:43Z.
Your 174 MB example raised a separate correctness question. Does the existing trace show distinct registered buffer resources nested inside that block, or several descriptor views of a single registered resource? If the log only has byte ranges, that distinction can stay open.
We reproduced the first layout on
ffe310ewith a registered 128 KiB parent and a child at +64 KiB. An SRV of the parent began at the child’s address. Descriptor creation chose the parent’s host copy, while refresh chose the child’s. Two dispatches read zero from the parent view, including after a CPU rewrite. A second, independent SRV returned its expected nonzero value in both dispatches.Agnes’s fix and Donald’s regression test use the same resource extent when choosing the host copy for the view and its refresh. On an RTX 4090 under Wine/vkd3d-proton, the parent view then returned
0xa0a00001followed by the rewritten0xb0b00003. The registrations stayed fixed throughout. We haven’t measured any change in your watch-query timings or linked this to a particular world draw.Imported from Marvisak/VIctory. Originally posted by lucaseddd on 2026-11-24T11:09:33Z.
I independently reproduced the partial-query regression on native Windows 10 and prepared a source-only branch with the original sweep commit followed by the journal fix and a synthetic regression test.
The test fails on
c326bfaand passes with the fix, including when the guarded fallback is requested. All seven write-watch tests pass. A failed range still returns no answer, while pages already reported and reset by the kernel remain visible to later queries.Branch: https://github.com/lucaseddd/VIctory/tree/gpu/write-watch-preserve-partial-results
Fix:
github.com/lucaseddd/VIctory@32ec0f4dGitHub currently denies opening a PR from this account. A collaborator can use the branch for review. This work was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by rocobalt1 on 2026-11-24T11:59:10Z.
Tried it on a tree where the askings are spread over many submissions per frame, and it did not move the frame - which may be the useful part of this report.
Build: integration tree
2b1a569(about 50 PRs) + #431 + the copy-fallback change in #783 + your commitc326bfacherry-picked on top (the branch as a whole is based on a newermainand conflicts across the translator, so I took the one commit; it compiles and the sweep is clearly active). Diag builds,VICTORY_NO_WATCHDOG=1,VICTORY_D3D12_DRED=1,VICTORY_SHADER_LOOP_LIMIT=32, same save, driven withVICTORY_KEYS, 10 frames each arm once in the world. RTX 4060 Ti, driver 32.0.16.1656;TdrDelay=60set machine-wide.c326bfaSo the sweep does what it says - askings fall by 36 % and checked bytes by 35 % - but the frame is about 500 ms slower and the copy line is slower too.
Two hypotheses, both from the same numbers:
watch::Sweepis scoped to a submission, so with that many submissions the same pages are asked again 36-57 times a frame anyway; the saving is only the overlap inside each submission. Your own runs had far fewer submissions, which is where 120-180 ms -> 31-47 ms would come from.GetWriteWatchcosts by range, not by "pages not yet asked". If the sweep still passes large ranges to the kernel and only filters the answer, the kernel's page-table walk is unchanged; the reduction in the counter then comes from fewer small askings, not from cheaper large ones.Either way, the shape that would help here is a sweep per frame (or per wait between submissions), not per submission: ask each page once until the title has actually written (which is what
Batch::title_writtenalready marks), across submissions. If you want, I can test a patch that lifts yourSweepto the host and clears it on the same event - the tree and the harness are already set up here, and the A/B is 10 frames in the same save.No game data used. AI-assisted: an agent working with the tester built and ran this.
Imported from Marvisak/VIctory. Originally posted by lucaseddd on 2026-11-24T12:21:06Z.
On the question about filtering,
c326bfacomputes gaps in the page intervals already swept and calls GetWriteWatch separately on each uncovered gap. It still performs the query again in the next submission. So the range passed to the kernel can shrink, and the code alone cannot establish a frame-time gain. The follow-up32ec0f4dpreserves dirty pages from successful gaps when a later gap fails.Imported from Marvisak/VIctory. Originally posted by ChruutvoLuzi on 2026-11-24T13:05:23Z.
A clean A/B on
main, since that was the missing piece. RTX 4090 (driver 621.01, Windows 11), diag build,mainffe310e+ #493 (so the world doesn't hang on NVIDIA), with and without lucaseddd's branch (c326bfa+32ec0f4), which merges cleanly. Same save and input,VICTORY_SHADER_LOOP_LIMIT=1024. Averages over the world from its first frame to 9.5 min after launch, about 88copystatlines per run:So here it is a small gain, about 50 to 80 ms a frame, and no slowdown like the one on the 4060 Ti above. The number of askings doesn't move, though; the patch counts each kernel call, gaps included. Little of the repetition on this tree is inside one submission. The 174 MB block (
+0xae00000here too) is asked 15.5 times a frame over 19.5 submissions, about once per submission, which the per-submission sweep can't remove. That matches the per-frame sweep suggestion above.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T13:30:27Z.
A data point where the askings dominate the frame far more than above, and an A/B of the per-submission sweep on it.
Setup: RTX 2070 SUPER, Ryzen 7 5700G (8C/16T), 32 GB, Windows 11 26200. Diag build of
integration/testers92bc27b(+ #638's diagnostics),VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_NO_WATCHDOG=1,VICTORY_SHOW_TARGET=busiest,VICTORY_PRODUCERS=1, same pipeline cache, first playable section. "With" = the same tree +c326bfa+32ec0f4cherry-picked (clean;cargo test -p victory-gpu --lib watch: 6 passed). Averages over the world from 2 minutes after entering it. One run each, not the same moment of the section.copystatlinesAI-assisted.
Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T13:37:22Z.
A correction to the last point of my A/B above: after reading
watch.rs, I don't think the per-frame sweep can be made correct for write-watched memory, so I would not recommend it and I'm not going to write it.The per-submission sweep is safe because, while a submission is prepared, every title write it must see has already happened (the comment on
Sweepsays so), apart from the preparing thread's own steps, whichtitle_writtencovers. Across submissions that no longer holds: the title's threads keep writing between twoExecuteCommandLists, and for write-watched memory the only way to see those writes is to ask the kernel again. A sweep kept for the whole frame would skip that asking and could give the GPU a page the title rewrote after the previous submission, with no error anywhere. Only guarded view memory has its own write signal, and the 174 MB block is not guarded memory.So the safe room left looks like fewer or cheaper askings inside one submission. On this machine I can measure where the ~2,300 askings a frame come from (range sizes and time per size) if that helps whoever picks it up.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T13:53:14Z.
The measurement I offered above: where the askings and their time go, by the size of the range passed to
GetWriteWatch. Same machine (RTX 2070 SUPER, Ryzen 7 5700G), same tree withc326bfa+32ec0f4, plus a local, uncommitted counter around theGetWriteWatchcall inwatch::writes(count, microseconds and MB per size bucket, logged every 5 s). First playable section, 320 s of the world from 90 s after entering it, frames ~4.6 s:(98 % of all askings came from the sweeping thread.)
The surprise is that the cost is not in the big block: an asking about the 166 MB block takes 0.04 ms, while one about less than 1 MB takes 1.26 ms, 30 times more. About 1,800 small askings a frame make ~2 s of a ~4.6 s frame. So on this machine the time is per call, not per byte, and it is the small ranges. Coalescing the small ranges a submission asks about into fewer kernel calls (or answering them from one larger asking of the allocation they sit in) looks like where the time is, more than skipping the big one. I have not looked at why a small asking costs that much here; the allocation it sits in may matter more than its length.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T14:18:05Z.
Follow-up to the size table above, on why a small asking costs so much here: it is one allocation. Same machine and tree, with a local counter that also asks
VirtualQueryfor each asking'sAllocationBaseand walks that allocation's regions for its reserved size. 4.5 minutes of the world, the costliest allocations every 30 s, summed:0xd494000000x1ba600000x204600000x1d5600000xd00000000So practically all of the asking time is askings inside a single 2.2 GB allocation, at about 2.2 ms each whatever their length; askings of the same or larger length elsewhere cost 0.01-0.02 ms. Size alone does not explain it: another 1.2 GB allocation is cheap. I have not checked what makes that allocation expensive (how much of it is committed, how many pages are dirty at a time, or whether it is the one xmem reserves with write watching for the title's GPU heap). For anyone working on this: answering askings inside that allocation from one asking per submission, instead of one per range, looks like it would remove most of the ~2 s per frame on this machine.
Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-24T14:29:21Z.
RTX 3080 Ti data point for the per-page asking change (forks schmiticle
c326bfa+ lucaseddd32ec0f4, integrated on https://github.com/Machad3x/VIctory/tree/claude/gta6-shader-translation-crashes-705550): 3347 watch askings, 839 ms per 20 submissions in the world, against 4281 askings and 723 ms before it (with #322, #230, #124, #783, #916 added at the same time, so not isolated). No lost write seen in 4 minutes. Not an improvement on this GPU; other numbers in this thread are on AMD.Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T14:36:03Z.
Following the per-allocation table above, I'm trying one change on top of
c326bfa+32ec0f4, unless someone already is: inside a sweep, the first asking that falls in an allocation asks the kernel about that whole allocation once, so the later small askings of the same submission land insweptand make no kernel call. It stays per submission (so it keeps the guarantee the sweep relies on), every page the kernel reports is put in the journal as today (so nested and other copies still see it), and an allocation whose whole-range asking fails falls back to the current per-range askings. On this machine that allocation takes ~30,000 askings of ~2.2 ms each in 4.5 minutes; I'll post the branch with tests and an in-game A/B.Imported from Marvisak/VIctory. Originally posted by EduAzevedo on 2026-11-24T16:31:41Z.
The change I said I'd try above is done: EduAzevedo/VIctory@perf/sweep-whole-allocation, one commit (
3284f19) on top ofc326bfa+32ec0f4, which the branch carries unchanged.What it does: inside a sweep, the first asking that falls in an allocation asks the kernel about the whole allocation once; every reported page goes into the journal as today, the whole range is marked swept, so later askings there in the same submission make no kernel call. It stays per submission, so it keeps the guarantee the sweep relies on. An allocation whose whole-range asking fails goes back to per-range askings; bounds come from
VirtualQueryonce per allocation and are forgotten ontitle_memory_remapped.In the title (same machine and settings as my tables above,
integration/testers92bc27b+ the sweep, without and with the commit, averages over the world, one run each):But the frame is not faster. The time outside VIctory's work grows from ~1.0 s to ~2.0 s. Six
VICTORY_STACKSsnapshots in the world show almost every thread waiting and the title's main thread waiting at the same place each time, so the frame is held by a wait elsewhere. Onffe310e+ #493 + #189 + #206 + the sweep, where that allocation is not expensive, asking time went from 134 to 91 ms.So this only matters once that wait is gone, and only together with the sweep; I'm leaving it here for whoever takes the sweep in, rather than proposing it on its own. Tests: two new ones in
watch.rs;partial_sweep_keeps_writes_when_a_later_query_failsruns with whole-allocation askings off so it keeps testing the per-range path;cargo test -p victory-gpu --lib56 passed, Clippy clean in both configurations, asset policy ok.AI-assisted.
Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T19:45:24Z.
@schmiticle your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto
mainffe310e. Clippy (both runs) andcargo test --workspacepass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.Imported from Marvisak/VIctory. Originally posted by lucaseddd on 2026-11-24T20:32:03Z.
Thanks for testing the sweep and for keeping
32ec0f4in the follow-up. The allocation-wide query is worth comparing with the existing range sweep under the same workload, using checked bytes and frame time alongside call count. Does #1610 include the partial-results follow-up as well?Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T20:49:22Z.
lucaseddd: it does now, thank you for asking. Until now #1610 carried only
c326bfa, so it had the lost-write case that DrDarkDK and you reproduced on it. I have added your32ec0f4on top, as it is (your authorship and your test intact); the head of #1610 is now47a4387. Clippy (both runs) andcargo test --workspacepass here, 361 tests twice (360 before).EduAzevedo's
3284f19(one query for a whole allocation) is not in it: its author reports that the frame is not faster with it and leaves it for whoever takes the sweep in. I have not measured either in the title.AI-assisted (Claude Code); no game data.
Imported from Marvisak/VIctory. Originally posted by lucaseddd on 2026-11-24T20:53:32Z.
Thanks for adding
32ec0f4with the original authorship and regression test, and for running the workspace checks. That resolves my question about partial results in #1610.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:51:59Z.
Automated triage for the maintainers.
Superseded on
mainafter this report: commitc75fdba("one change journal for title memory") replaced the per-rangeGetWriteWatchaskings incrates/victory-gpu/src/watch.rs. Host copies now track 64 KiB pages with guards: the first write to a taken block faults and marks it changed in every copy that holds it, so bringing a copy up to date makes no system call for memory nobody wrote.GetWriteWatchis left only as a one-page probe inruntime_memory. The repeated askings over nested buffers measured here, and the sweep and partial-result fixes, apply to code that is no longer onmain.If copy or refresh time in the world is still high on current
main, please post freshcopystatnumbers in a new issue. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes thetriage: proposed closelabel.Generated by Claude Code