GPU: refresh directly indexed SRVs that share a page as one range #462

Closed
github-bot wants to merge 3 commits from gh-pr/462/head into gh-pr/462/base
Owner

@⁠desplmfao on GitHub · 2026-11-24 03:43 UTC · original
desplmfao:fix/direct-srv-merge → main · +1569 −92 · 9 files · 3 commits · closed without merging

Stacked on #185 (its two commits come first); review that first.

GPU hangs: not tied to this change. Xid 109 (CTX SWITCH TIMEOUT) ended runs both with and without it, 3–4 min after start, as it does on this machine without any of these changes (#71). Last pair, same build, #436 and #462 switched off and on together: off hung about 4 min after start; on had not hung when stopped at 4.5 min. Too few runs to say whether either makes it come sooner or later. With #493 (+#336) added, four runs with these changes on went 7.5–10 min without a hang, so the hangs were most likely what #493 fixes (reads past the end of root SRVs); see the comment there.

Same pair, last frames in the world: off 5.0–6.2 s per frame (862,000–929,000 direct SRV ranges), on with #436 and #462 2.4–4.2 s (280,000–290,000 ranges).

Unwatched copies: most of them came from write-watch questions over ranges spanning several allocations, which the kernel refuses as a whole; that is #515. With #436, #462, #515 and #464/#514 together, unwatched copies fell to 1–81 MB per world frame, and the median world frame from 6.0 s (none of these) to 3.0 s; what is left is bound by CPU time per range rather than bytes.

Problem

#185 refreshes the live directly indexed SRV ranges before each submission, merging only ranges that overlap. In the world most of them are small and close together but do not overlap, so each becomes its own Shadow::update, with its own write-watch query: about 900,000 updates per world frame here, which took 7–8 s of each frame to prepare.

Change

refresh_direct_srvs also merges a range of the same buffer that starts in the page where the previous one ends (or at its end). The bytes between them are under a page; update still leaves out ranges shaders may be writing.

Measured

RTX 5080, Linux (proton-cachyos, vkd3d-proton 3.2.0), Series X 1.0.2.1. Diagnostics build of main d2a4bae + #185 + #436 + #440 + #259, #177, #151 (needed to reach the world here), one run with and one without this change, Enter into story mode at about 35 s, first 1–2 min in the world:

per world frame without with
direct SRV ranges 862,000–920,000 267,000–288,000
direct SRV preparation 7.0–8.2 s 4.5–5.5 s
frame time 7.2–9.6 s 5.1–7.6 s
direct SRV bytes copied 2.5–3.8 GB 4.2–6.4 GB
bytes copied unwatched 2.4 GB 3.1–4.8 GB

More bytes are copied: a merged range also covers the gaps between views, and a merged range whose write-watch query fails (it reaches uncommitted private memory) is copied whole. That case is a follow-up: the failing ranges start in reserved, uncommitted pages of otherwise watched buffers.

  • #600 (draft): asks for written pages once per span of title memory across host copies, instead of once per range. It is stacked on this PR, with the one line where the two overlap in refresh_direct_srvs resolved there.
  • #436: copies a partly covered edge page whole once, so later ranges in it copy nothing. Independent of this change; either can go first.
  • #440 / #435: register each GPU write range once per submission, which shortens the pending list update checks.
  • #464: unmapped guarded view blocks were re-copied every submission, the view-memory counterpart of the unwatched copies above.
  • #400: measurements of the copy path on main.

Tests

New directly_indexed_srvs_in_one_page_refresh_as_one_range in #185's coherency tests: 16 small SRVs in one page refresh as one range and each still reads its own value; it fails without the change (16 ranges). All 9 coherency tests pass on the GPU (vkd3d-proton, VICTORY_PC_DXC set).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠desplmfao** on GitHub · 2026-11-24 03:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/462) `desplmfao:fix/direct-srv-merge` → `main` · +1569 −92 · 9 files · 3 commits · closed without merging Stacked on #185 (its two commits come first); review that first. > **GPU hangs: not tied to this change.** `Xid 109` (CTX SWITCH TIMEOUT) ended runs both with and without it, 3–4 min after start, as it does on this machine without any of these changes (#71). Last pair, same build, #436 and #462 switched off and on together: off hung about 4 min after start; on had not hung when stopped at 4.5 min. Too few runs to say whether either makes it come sooner or later. With #493 (+#336) added, four runs with these changes on went 7.5–10 min without a hang, so the hangs were most likely what #493 fixes (reads past the end of root SRVs); see the comment there. > > Same pair, last frames in the world: off 5.0–6.2 s per frame (862,000–929,000 direct SRV ranges), on with #436 and #462 2.4–4.2 s (280,000–290,000 ranges). > > **Unwatched copies:** most of them came from write-watch questions over ranges spanning several allocations, which the kernel refuses as a whole; that is #515. With #436, #462, #515 and #464/#514 together, unwatched copies fell to 1–81 MB per world frame, and the median world frame from 6.0 s (none of these) to 3.0 s; what is left is bound by CPU time per range rather than bytes. ## Problem #185 refreshes the live directly indexed SRV ranges before each submission, merging only ranges that overlap. In the world most of them are small and close together but do not overlap, so each becomes its own `Shadow::update`, with its own write-watch query: about 900,000 updates per world frame here, which took 7–8 s of each frame to prepare. ## Change `refresh_direct_srvs` also merges a range of the same buffer that starts in the page where the previous one ends (or at its end). The bytes between them are under a page; `update` still leaves out ranges shaders may be writing. ## Measured RTX 5080, Linux (proton-cachyos, vkd3d-proton 3.2.0), Series X 1.0.2.1. Diagnostics build of `main` `d2a4bae` + #185 + #436 + #440 + #259, #177, #151 (needed to reach the world here), one run with and one without this change, Enter into story mode at about 35 s, first 1–2 min in the world: | per world frame | without | with | |---|---|---| | direct SRV ranges | 862,000–920,000 | 267,000–288,000 | | direct SRV preparation | 7.0–8.2 s | 4.5–5.5 s | | frame time | 7.2–9.6 s | 5.1–7.6 s | | direct SRV bytes copied | 2.5–3.8 GB | 4.2–6.4 GB | | bytes copied unwatched | 2.4 GB | 3.1–4.8 GB | More bytes are copied: a merged range also covers the gaps between views, and a merged range whose write-watch query fails (it reaches uncommitted private memory) is copied whole. That case is a follow-up: the failing ranges start in reserved, uncommitted pages of otherwise watched buffers. ## Related - #600 (draft): asks for written pages once per span of title memory across host copies, instead of once per range. It is stacked on this PR, with the one line where the two overlap in `refresh_direct_srvs` resolved there. - #436: copies a partly covered edge page whole once, so later ranges in it copy nothing. Independent of this change; either can go first. - #440 / #435: register each GPU write range once per submission, which shortens the pending list `update` checks. - #464: unmapped guarded view blocks were re-copied every submission, the view-memory counterpart of the unwatched copies above. - #400: measurements of the copy path on `main`. ## Tests New `directly_indexed_srvs_in_one_page_refresh_as_one_range` in #185's coherency tests: 16 small SRVs in one page refresh as one range and each still reads its own value; it fails without the change (16 ranges). All 9 coherency tests pass on the GPU (vkd3d-proton, `VICTORY_PC_DXC` set). AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
refresh_direct_srvs merged only overlapping ranges. In the world most
directly indexed SRVs are small and close together without overlapping,
so each became its own Shadow::update with its own write-watch query:
about 900,000 per world frame.

Also merge a range of the same buffer that starts in the page where the
previous one ends, or at its end. The bytes between them are under a
page, and update still leaves out ranges shaders may be writing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:56 +00:00
github-bot closed this pull request 2026-11-26 04:04:56 +00:00
Author
Owner

@⁠desplmfao on GitHub · 2026-11-24 05:04 UTC · original

Thanks for measuring. One thing to separate: your comparison is #185 + this PR against neither, since this one is stacked on #185. The per-view watches you see come from #185's refresh of directly indexed SRVs, one write-watch question per range before every submission; this PR merges ranges that share a page, so it lowers that count rather than adding it.

With #185 in both builds (RTX 5080, proton-cachyos / vkd3d-proton 3.2.0, Series X, world frames), this PR took direct SRV ranges from 862,000–929,000 to 280,000–290,000 per frame and frames from 5.0–6.2 s to 2.4–4.2 s, as in the description.

What you measured is still real: under Wine each of those questions is expensive, so #185 makes loading and world frames much slower there. I'm working on that next: asking once per buffer and submission for the written pages over the span its ranges cover, instead of once per range. In a synthetic test (8 views into one watched buffer) that is 1 question per submission instead of 8, and #185's coherency tests still pass. It is being measured in the world now; I'll link it here with numbers once it holds up. Over several allocations it relies on #515 (asking per allocation when a span covers several).

AI-assisted (Claude Code).

**@⁠desplmfao** on GitHub · 2026-11-24 05:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/462#issuecomment-7122597080) Thanks for measuring. One thing to separate: your comparison is #185 + this PR against neither, since this one is stacked on #185. The per-view watches you see come from #185's refresh of directly indexed SRVs, one write-watch question per range before every submission; this PR merges ranges that share a page, so it lowers that count rather than adding it. With #185 in both builds (RTX 5080, proton-cachyos / vkd3d-proton 3.2.0, Series X, world frames), this PR took direct SRV ranges from 862,000–929,000 to 280,000–290,000 per frame and frames from 5.0–6.2 s to 2.4–4.2 s, as in the description. What you measured is still real: under Wine each of those questions is expensive, so #185 makes loading and world frames much slower there. I'm working on that next: asking once per buffer and submission for the written pages over the span its ranges cover, instead of once per range. In a synthetic test (8 views into one watched buffer) that is 1 question per submission instead of 8, and #185's coherency tests still pass. It is being measured in the world now; I'll link it here with numbers once it holds up. Over several allocations it relies on #515 (asking per allocation when a span covers several). AI-assisted (Claude Code).
Author
Owner

@⁠desplmfao on GitHub · 2026-11-24 05:21 UTC · original

Follow-up to the above: the per-range questions you measured are in draft #600 now. It asks once per span of title memory instead of once per range, across host copies (most ranges are in different small buffers, so per-buffer grouping alone did not help).

Same stack with and without it, write-watch questions per frame: menus about 3,500 → 223, loading 3,500–6,400 → 900–3,600, world 165,000–184,000 → 80,000–162,000. The world gains little so far because most of its ranges reach the title's GPU heap of physical-page views, which cannot be write-watched and still go one by one; that is the next step, described in the PR.

AI-assisted (Claude Code).

**@⁠desplmfao** on GitHub · 2026-11-24 05:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/462#issuecomment-7122865605) Follow-up to the above: the per-range questions you measured are in draft #600 now. It asks once per span of title memory instead of once per range, across host copies (most ranges are in different small buffers, so per-buffer grouping alone did not help). Same stack with and without it, write-watch questions per frame: menus about 3,500 → 223, loading 3,500–6,400 → 900–3,600, world 165,000–184,000 → 80,000–162,000. The world gains little so far because most of its ranges reach the title's GPU heap of physical-page views, which cannot be write-watched and still go one by one; that is the next step, described in the PR. AI-assisted (Claude Code).
Author
Owner

@⁠desplmfao on GitHub · 2026-11-24 05:47 UTC · original

Closing in favour of #185 as it is now: its later commit 53e36e7 builds the uncovered ranges per host copy and hands them over together, and skips ranges unchanged since the last submission, which covers what this PR did and more. Measured here (RTX 5080, Linux / proton-cachyos, world frames): old #185 + this and three other PRs 4.3 s per frame, new #185 alone 2.9 s.

AI-assisted (Claude Code).

**@⁠desplmfao** on GitHub · 2026-11-24 05:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/462#issuecomment-7123281486) Closing in favour of #185 as it is now: its later commit `53e36e7` builds the uncovered ranges per host copy and hands them over together, and skips ranges unchanged since the last submission, which covers what this PR did and more. Measured here (RTX 5080, Linux / proton-cachyos, world frames): old #185 + this and three other PRs 4.3 s per frame, new #185 alone 2.9 s. AI-assisted (Claude Code).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!462
No description provided.