GPU: write-watch askings repeat over nested buffers (120-180 ms a world frame); a fix is on a branch #776

Open
opened 2026-11-26 04:13:57 +00:00 by github-bot · 18 comments
Owner

@⁠schmiticle on GitHub · 2026-11-24 10:25 UTC · original

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 main ffe310e, watch.rs and host.rs, merges cleanly)

The problem

In the world, nested buffers (several views into one 174 MB block at 0x35030000, among others) each ask GetWriteWatch about largely the same pages. In the opening cutscene on an RX 9070 XT, the copystat line 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::execute prepares 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 after title_written). cargo test -p victory-gpu --lib, both clippy configurations from CI, and cargo xtask policy pass.

No game data used.

**@⁠schmiticle** on GitHub · 2026-11-24 10:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/776) *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 `main` ffe310e, `watch.rs` and `host.rs`, merges cleanly) ## The problem In the world, nested buffers (several views into one 174 MB block at `0x35030000`, among others) each ask `GetWriteWatch` about largely the same pages. In the opening cutscene on an RX 9070 XT, the `copystat` line 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::execute` prepares 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 after `title_written`). `cargo test -p victory-gpu --lib`, both clippy configurations from CI, and `cargo xtask policy` pass. No game data used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:57 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 10:35 UTC · original

Found a mixed-range write-watch regression on c326bfa on 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.

**@⁠DrDarkDK** on GitHub · 2026-11-24 10:35 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7128991732) Found a mixed-range write-watch regression on `c326bfa` on 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.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 10:51 UTC · original

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 ffe310e with 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 0xa0a00001 followed by the rewritten 0xb0b00003. The registrations stayed fixed throughout. We haven’t measured any change in your watch-query timings or linked this to a particular world draw.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 10:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7129342137) 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 `ffe310e` with 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](https://github.com/MichaelSmithAI/VIctory/tree/fix/nested-buffer-view-refresh) 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 `0xa0a00001` followed by the rewritten `0xb0b00003`. The registrations stayed fixed throughout. We haven’t measured any change in your watch-query timings or linked this to a particular world draw.
Author
Owner

@⁠lucaseddd on GitHub · 2026-11-24 11:09 UTC · original

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 c326bfa and 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@32ec0f4d

GitHub currently denies opening a PR from this account. A collaborator can use the branch for review. This work was AI-assisted.

**@⁠lucaseddd** on GitHub · 2026-11-24 11:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7129733005) 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 c326bfa and 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: https://github.com/lucaseddd/VIctory/commit/32ec0f4d GitHub currently denies opening a PR from this account. A collaborator can use the branch for review. This work was AI-assisted.
Author
Owner

@⁠rocobalt1 on GitHub · 2026-11-24 11:59 UTC · original

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 commit c326bfa cherry-picked on top (the branch as a whole is based on a newer main and 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 with VICTORY_KEYS, 10 frames each arm once in the world. RTX 4060 Ti, driver 32.0.16.1656; TdrDelay=60 set machine-wide.

without c326bfa with it
draws/frame 2 542 2 518
frame 2 236 ms 2 747 ms
copies 1 209 ms 1 476 ms
watch askings/frame 5 498 3 502
bytes checked 34 489 MB 22 508 MB

So 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:

  1. The frame has 36-57 submissions here. watch::Sweep is 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.
  2. GetWriteWatch costs 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_written already marks), across submissions. If you want, I can test a patch that lifts your Sweep to 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.

**@⁠rocobalt1** on GitHub · 2026-11-24 11:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7130806659) 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 commit `c326bfa`** cherry-picked on top (the branch as a whole is based on a newer `main` and 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 with `VICTORY_KEYS`, 10 frames each arm once in the world. RTX 4060 Ti, driver 32.0.16.1656; `TdrDelay=60` set machine-wide. | | without `c326bfa` | with it | |---|---:|---:| | draws/frame | 2 542 | 2 518 | | **frame** | **2 236 ms** | **2 747 ms** | | copies | 1 209 ms | 1 476 ms | | watch askings/frame | 5 498 | **3 502** | | bytes checked | 34 489 MB | 22 508 MB | So 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: 1. **The frame has 36-57 submissions here.** `watch::Sweep` is 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. 2. **`GetWriteWatch` costs 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_written` already marks), across submissions. If you want, I can test a patch that lifts your `Sweep` to 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.
Author
Owner

@⁠lucaseddd on GitHub · 2026-11-24 12:21 UTC · original

On the question about filtering, c326bfa computes 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-up 32ec0f4d preserves dirty pages from successful gaps when a later gap fails.

**@⁠lucaseddd** on GitHub · 2026-11-24 12:21 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7131317060) On the question about filtering, c326bfa computes 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-up 32ec0f4d preserves dirty pages from successful gaps when a later gap fails.
Author
Owner

@⁠ChruutvoLuzi on GitHub · 2026-11-24 13:05 UTC · original

A clean A/B on main, since that was the missing piece. RTX 4090 (driver 621.01, Windows 11), diag build, main ffe310e + #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 88 copystat lines per run:

without (2 runs) with
submissions per frame 19.6 / 20.8 19.5
askings per frame 1,263 / 1,276 1,262
asking time per frame 344 / 316 ms 266 ms
bytes checked per frame 7,598 / 7,582 MB 7,732 MB
copies (frame line) 532 / 494 ms 463 ms
frame 941 / 985 ms 868 ms

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 (+0xae00000 here 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).

**@⁠ChruutvoLuzi** on GitHub · 2026-11-24 13:05 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7132332885) A clean A/B on `main`, since that was the missing piece. RTX 4090 (driver 621.01, Windows 11), diag build, `main` `ffe310e` + #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 88 `copystat` lines per run: | | without (2 runs) | with | |---|---:|---:| | submissions per frame | 19.6 / 20.8 | 19.5 | | askings per frame | 1,263 / 1,276 | 1,262 | | asking time per frame | 344 / 316 ms | 266 ms | | bytes checked per frame | 7,598 / 7,582 MB | 7,732 MB | | copies (frame line) | 532 / 494 ms | 463 ms | | frame | 941 / 985 ms | 868 ms | 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 (`+0xae00000` here 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).
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 13:30 UTC · original

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/testers 92bc27b (+ #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 + 32ec0f4 cherry-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.

per frame without with
copystat lines 21 69
submissions 26.0 33.8
write-watch askings 2,384 3,135
asking time 4,002 ms 3,880 ms
time per asking 1.68 ms 1.24 ms
bytes checked (unchanged) 14.4 GB (98.3 %) 20.6 GB (98.3 %)
copies (frame line) 2,912 ms 2,016 ms
on the GPU 338 ms 377 ms
frame 6,052 ms 4,248 ms
  • On this CPU the askings alone are 60-90 % of the frame: about 1.2-1.7 ms each, against roughly 0.25 ms in the RTX 4090 A/B above.
  • The frame is faster with the sweep, but the asking time barely moves (4.0 → 3.9 s) while the "with" run had more submissions and checked more bytes, so I would not credit the frame difference to the sweep from one run each; the scenes differ.
  • As in the other two A/Bs, the 174 MB block is asked about about once per submission, so most of the repetition here is across submissions. That points to the per-frame sweep suggested above as the change that would matter on a machine like this.

AI-assisted.

**@⁠EduAzevedo** on GitHub · 2026-11-24 13:30 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7132928274) 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/testers` `92bc27b` (+ #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` + `32ec0f4` cherry-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. | per frame | without | with | |---|---:|---:| | `copystat` lines | 21 | 69 | | submissions | 26.0 | 33.8 | | write-watch askings | 2,384 | 3,135 | | **asking time** | **4,002 ms** | **3,880 ms** | | time per asking | 1.68 ms | 1.24 ms | | bytes checked (unchanged) | 14.4 GB (98.3 %) | 20.6 GB (98.3 %) | | copies (frame line) | 2,912 ms | 2,016 ms | | on the GPU | 338 ms | 377 ms | | **frame** | **6,052 ms** | **4,248 ms** | - On this CPU the askings alone are 60-90 % of the frame: about 1.2-1.7 ms each, against roughly 0.25 ms in the RTX 4090 A/B above. - The frame is faster with the sweep, but the asking time barely moves (4.0 → 3.9 s) while the "with" run had more submissions and checked more bytes, so I would not credit the frame difference to the sweep from one run each; the scenes differ. - As in the other two A/Bs, the 174 MB block is asked about about once per submission, so most of the repetition here is across submissions. That points to the per-frame sweep suggested above as the change that would matter on a machine like this. AI-assisted.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 13:37 UTC · original · edited 2026-11-24 13:38 UTC

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 Sweep says so), apart from the preparing thread's own steps, which title_written covers. Across submissions that no longer holds: the title's threads keep writing between two ExecuteCommandLists, 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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 13:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7133095193) · edited 2026-11-24 13:38 UTC 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 `Sweep` says so), apart from the preparing thread's own steps, which `title_written` covers. Across submissions that no longer holds: the title's threads keep writing between two `ExecuteCommandLists`, 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.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 13:53 UTC · original

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 with c326bfa + 32ec0f4, plus a local, uncommitted counter around the GetWriteWatch call in watch::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:

range per asking askings share time share per asking
< 1 MB 86,030 64.9 % 108.0 s 76.8 % 1.26 ms
1-16 MB (avg 2.4 MB) 38,859 29.3 % 30.5 s 21.7 % 0.78 ms
16-64 MB (avg 36 MB) 2,400 1.8 % 0.1 s 0.1 % 0.06 ms
64-128 MB (avg 86 MB) 3,029 2.3 % 1.9 s 1.3 % 0.62 ms
≥ 128 MB (avg 166 MB) 2,153 1.6 % 0.1 s 0.1 % 0.04 ms

(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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 13:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7133484088) 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 with `c326bfa` + `32ec0f4`, plus a local, uncommitted counter around the `GetWriteWatch` call in `watch::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: | range per asking | askings | share | time | share | per asking | |---|---:|---:|---:|---:|---:| | < 1 MB | 86,030 | 64.9 % | 108.0 s | **76.8 %** | **1.26 ms** | | 1-16 MB (avg 2.4 MB) | 38,859 | 29.3 % | 30.5 s | 21.7 % | 0.78 ms | | 16-64 MB (avg 36 MB) | 2,400 | 1.8 % | 0.1 s | 0.1 % | 0.06 ms | | 64-128 MB (avg 86 MB) | 3,029 | 2.3 % | 1.9 s | 1.3 % | 0.62 ms | | ≥ 128 MB (avg 166 MB) | 2,153 | 1.6 % | 0.1 s | 0.1 % | **0.04 ms** | (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.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 14:18 UTC · original

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 VirtualQuery for each asking's AllocationBase and walks that allocation's regions for its reserved size. 4.5 minutes of the world, the costliest allocations every 30 s, summed:

allocation base reserved askings time share per asking avg range
0xd49400000 2,199 MB 30,856 68.7 s 99.8 % 2.23 ms 2.25 MB
0x1ba60000 27 MB 10,168 0.11 s 0.2 % 0.01 ms 37 MB
0x20460000 100 MB 2,702 0.05 s 0.1 % 0.02 ms 4.6 MB
0x1d560000 47 MB 1,120 0.01 s 0.0 % 0.01 ms 35 MB
0xd00000000 1,172 MB 825 < 0.01 s 0.0 % < 0.01 ms 0.15 MB
five more 1,307 < 0.01 s

So 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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 14:18 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7134153530) 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 `VirtualQuery` for each asking's `AllocationBase` and walks that allocation's regions for its reserved size. 4.5 minutes of the world, the costliest allocations every 30 s, summed: | allocation base | reserved | askings | time | share | per asking | avg range | |---|---:|---:|---:|---:|---:|---:| | `0xd49400000` | **2,199 MB** | 30,856 | 68.7 s | **99.8 %** | **2.23 ms** | 2.25 MB | | `0x1ba60000` | 27 MB | 10,168 | 0.11 s | 0.2 % | 0.01 ms | 37 MB | | `0x20460000` | 100 MB | 2,702 | 0.05 s | 0.1 % | 0.02 ms | 4.6 MB | | `0x1d560000` | 47 MB | 1,120 | 0.01 s | 0.0 % | 0.01 ms | 35 MB | | `0xd00000000` | 1,172 MB | 825 | < 0.01 s | 0.0 % | < 0.01 ms | 0.15 MB | | five more | | 1,307 | < 0.01 s | | | | So 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.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-24 14:29 UTC · original

RTX 3080 Ti data point for the per-page asking change (forks schmiticle c326bfa + lucaseddd 32ec0f4, 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.

**@⁠Machad3x** on GitHub · 2026-11-24 14:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7134456836) RTX 3080 Ti data point for the per-page asking change (forks schmiticle c326bfa + lucaseddd 32ec0f4, 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.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 14:36 UTC · original

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 in swept and 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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 14:36 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7134641761) 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 in `swept` and 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.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 16:31 UTC · original

The change I said I'd try above is done: EduAzevedo/VIctory@perf/sweep-whole-allocation, one commit (3284f19) on top of c326bfa + 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 VirtualQuery once per allocation and are forgotten on title_memory_remapped.

In the title (same machine and settings as my tables above, integration/testers 92bc27b + the sweep, without and with the commit, averages over the world, one run each):

per frame without with
asking time 3,880 ms 562 ms
copies (frame line) 2,016 ms 995 ms
VIctory's work (preparing + GPU + copying back) 3,252 ms 2,195 ms
frame 4,248 ms 4,163 ms

But the frame is not faster. The time outside VIctory's work grows from ~1.0 s to ~2.0 s. Six VICTORY_STACKS snapshots 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. On ffe310e + #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_fails runs with whole-allocation askings off so it keeps testing the per-range path; cargo test -p victory-gpu --lib 56 passed, Clippy clean in both configurations, asset policy ok.

AI-assisted.

**@⁠EduAzevedo** on GitHub · 2026-11-24 16:31 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7137805077) The change I said I'd try above is done: [EduAzevedo/VIctory@perf/sweep-whole-allocation](https://github.com/EduAzevedo/VIctory/tree/perf/sweep-whole-allocation), one commit (`3284f19`) on top of `c326bfa` + `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 `VirtualQuery` once per allocation and are forgotten on `title_memory_remapped`. **In the title** (same machine and settings as my tables above, `integration/testers` `92bc27b` + the sweep, without and with the commit, averages over the world, one run each): | per frame | without | with | |---|---:|---:| | asking time | 3,880 ms | **562 ms** | | copies (frame line) | 2,016 ms | 995 ms | | VIctory's work (preparing + GPU + copying back) | 3,252 ms | 2,195 ms | | **frame** | **4,248 ms** | **4,163 ms** | **But the frame is not faster.** The time outside VIctory's work grows from ~1.0 s to ~2.0 s. Six `VICTORY_STACKS` snapshots 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. On `ffe310e` + #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_fails` runs with whole-allocation askings off so it keeps testing the per-range path; `cargo test -p victory-gpu --lib` 56 passed, Clippy clean in both configurations, asset policy ok. AI-assisted.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:45 UTC · original

@⁠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 main ffe310e. Clippy (both runs) and cargo test --workspace pass 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.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7142544952) @⁠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 `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass 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.
Author
Owner

@⁠lucaseddd on GitHub · 2026-11-24 20:32 UTC · original

Thanks for testing the sweep and for keeping 32ec0f4 in 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?

**@⁠lucaseddd** on GitHub · 2026-11-24 20:32 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7143692375) Thanks for testing the sweep and for keeping 32ec0f4 in 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?
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 20:49 UTC · original

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 your 32ec0f4 on top, as it is (your authorship and your test intact); the head of #1610 is now 47a4387. Clippy (both runs) and cargo test --workspace pass 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.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 20:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7144102876) 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 your `32ec0f4` on top, as it is (your authorship and your test intact); the head of #1610 is now `47a4387`. Clippy (both runs) and `cargo test --workspace` pass 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.
Author
Owner

@⁠lucaseddd on GitHub · 2026-11-24 20:53 UTC · original

Thanks for adding 32ec0f4 with the original authorship and regression test, and for running the workspace checks. That resolves my question about partial results in #1610.

**@⁠lucaseddd** on GitHub · 2026-11-24 20:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7144195024) Thanks for adding 32ec0f4 with the original authorship and regression test, and for running the workspace checks. That resolves my question about partial results in #1610.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:51 UTC · original

Automated triage for the maintainers.

Superseded on main after this report: commit c75fdba ("one change journal for title memory") replaced the per-range GetWriteWatch askings in crates/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. GetWriteWatch is left only as a one-page probe in runtime_memory. The repeated askings over nested buffers measured here, and the sweep and partial-result fixes, apply to code that is no longer on main.

If copy or refresh time in the world is still high on current main, please post fresh copystat numbers in a new issue. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/776#issuecomment-7152312905) <!-- victory-issue-triage v1 verdict=proposed-close seen=2026-11-24T20:53:32Z at=2026-11-25T03:51:58Z --> Automated triage for the maintainers. Superseded on `main` after this report: commit `c75fdba` ("one change journal for title memory") replaced the per-range `GetWriteWatch` askings in `crates/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. `GetWriteWatch` is left only as a one-page probe in `runtime_memory`. The repeated askings over nested buffers measured here, and the sweep and partial-result fixes, apply to code that is no longer on `main`. If copy or refresh time in the world is still high on current `main`, please post fresh `copystat` numbers in a new issue. This issue will be closed in 48 hours unless the reporter replies or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#776
No description provided.