Skip to content

GPU: ask for directly indexed SRVs' written pages once per span of title memory - #600

Closed
desplmfao wants to merge 6 commits into
Marvisak:mainfrom
desplmfao:perf/direct-srv-by-address
Closed

desplmfao wants to merge 6 commits into
Marvisak:mainfrom
desplmfao:perf/direct-srv-by-address

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown

Status (2026-11-24): measured on the reworked #185; not pushed yet. This branch is built on #185's first two commits and #462 (closed). Ported locally onto #185 as it is now (head 1efd438), the same idea (ranges of several host copies in one private reservation share one write-watch question) needs a Wine fix in watch::allocation first (aycow#1); with both, same machine and world window (26 lines, medians):

per world frame new #185 + Wine fix + Wine fix + this, ported
write-watch questions 144,058 110,864 4,112
time in them 776 ms 662 ms 22 ms
frame time 2.90 s 2.87 s 2.73 s (within run-to-run spread)

So the questions are nearly gone but frame time does not follow; what remains of a world frame is elsewhere. I'll either replace this branch with the port (about 120 lines on top of #185) or close it, depending on whether that remaining time turns out to need it. The description below is for the old base.

Problem

#185's refresh_direct_srvs brings each merged range up to date with its own question for written pages. The ranges are mostly in different, small host copies (one title buffer each) that lie close together in title memory, so merging per host copy does not reduce them: in the world here about 170,000 questions per frame, 1.5–2.7 s of it, and under Wine each question is a round trip. That is also what the measurement on #462 shows during loading (about 6,100 questions per frame).

Change

  • refresh_direct_srvs collects the merged ranges of every host copy and refresh_by_address sorts them by address, groups those less than 1 MiB apart into spans, and asks once per span.
  • watch::writes_split answers a span: once if the kernel takes it, else allocation by allocation, with the parts it cannot answer for listed separately. The written pages go to the shared journal as before.
  • Shadow::update_answered brings a range up to date from that answer (pending GPU writes left out, as in update).
  • Spans are asked without guarding view memory: guarding makes blocks read-only on the promise that the caller copies them now, and a span covers memory between ranges that nobody copies here. A first version did guard them, and the title showed no UI at all. A range in memory the kernel cannot answer for (views) goes through Shadow::update as before.
  • VICTORY_NO_SPAN_QUESTIONS=1 (diagnostics builds) goes back to one question per range, for comparing the two; the per-frame shadow traffic line gains span_questions and span_partial.

Measured

RTX 5080, Linux (proton-cachyos, vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of main d2a4bae + #185 + #436, #462, #440, #515, #514, #493 (+#336), #431, #259, #177, #151, story mode by VICTORY_KEYS. Before: the same stack without this change.

write-watch questions per frame before with this
menus about 3,500 (90–380 ms) 223 (0.4–0.6 ms)
loading 3,500–6,400 900–3,600
world 165,000–184,000 80,000–162,000
world frame time, median 2.6–3.6 s 2.9 s

In the world, 90 % of spans (about 21,000 of 23,000 per frame) reach view memory (the title's big GPU heap of physical-page views, which cannot be write-watched), so most ranges there still ask one by one. Guarding view memory per span, but only the blocks the ranges cover, is the next step. Bytes copied whole (not watched) were 0.85–1.0 GB per world frame in this run against 1–81 MB in the run before; not explained yet.

Tests

New directly_indexed_srvs_of_neighbouring_buffers_ask_once_per_submission: 8 title buffers side by side in one write-watched allocation, each with its own host copy and a view; one question per submission with this change, 8 without it (fails on #185 alone), and each view reads the title's latest value. #185's other coherency tests pass on the GPU (vkd3d-proton, VICTORY_PC_DXC set). cargo clippy reports nothing new.

Related

AI-assisted (Claude Code).

🤖 Generated with Claude Code

aycow and others added 5 commits November 23, 2026 20:11
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 <noreply@anthropic.com>
…tle memory

refresh_direct_srvs brought each merged range up to date with its own
question for written pages, and the ranges are mostly in different, small
host copies: one title buffer each, close together in title memory. That
made hundreds of thousands of system calls per world frame, and under
Wine each is a round trip.

Sort the merged ranges of every host copy by address, group those less
than 1 MiB apart into spans, and ask once per span (watch::writes_split,
allocation by allocation where the kernel refuses the whole span). Each
range is then brought up to date from that answer
(Shadow::update_answered); the written pages also go to the shared
journal. Spans are asked without guarding view memory, since a span covers
memory between ranges that nobody copies now; a range in memory the kernel
cannot answer for goes through Shadow::update as before.

VICTORY_NO_SPAN_QUESTIONS=1 (diagnostics builds) goes back to one question
per range, for comparing the two.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the overlap in refresh_direct_srvs: Marvisak#462's page-sharing merge
condition in this branch's loop, and both PRs' tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown

@desplmfao Thanks for porting the cross-shadow batching and splitting out the Wine fix. Your matched report shows 110,864 → 4,112 write-watch questions and 662 → 22 ms per world frame from batching on top of the Wine fix. The 2.87 → 2.73 s frame interval is within the reported run spread.

If you push the port, please point me to its exact head. I can review the shared reservation proof, clipped ranges, per-shadow journal observations, remaps and pending GPU writes, and test it independently on Windows. For the remaining frame cost, could we hold the scene, stack and presentation window fixed and add aggregate timings for direct-SRV range construction, actual fill and fallback bytes, total submit preparation, queue wait/GPU intervals and post-fence copyback? Separate runs for timing and for attribution would make the comparison easier to interpret.

@desplmfao

desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Thanks. The port is up as a PR against your branch: aycow#2 (head 9131c10, branch desplmfao:perf/shared-spans). It sits on your 1efd438 plus the Wine fix (9e94c21, aycow#1), since without that fix no reservation is private under Wine and the sharing never triggers. The port itself is the one commit 9131c10:

  • Shadow::update_ranges split into ready (clip + pending GPU writes excluded) and update_ready, plus floor (your watch_floor) and answered (update_watched after a shared answer).
  • refresh_direct_srvs collects every copy's ready ranges; refresh_across sorts them by address and lets ranges of several copies inside one live private reservation, less than 1 MiB apart, share one grouped_writes question with the oldest floor among them. Everything else goes through each copy's update_ready unchanged. The last reservation lookup is reused while ranges stay inside it.
  • New directly_indexed_srvs_of_neighbouring_copies_share_a_question (8 copies in one watched reservation): passes, and fails with VICTORY_NO_SHARED_SPANS=1; all 12 coherency tests pass here on vkd3d-proton with VICTORY_PC_DXC set.

On the remaining frame cost: agreed, and the first timing run already narrows it. With the port, per world frame the copies themselves (Shadow::copy, ~7,800 calls) take ~22 ms and all of copy_stale ~20 ms, while the direct-SRV refresh as a whole takes 2.8–4.0 s of a ~3.3 s frame, so nearly all of it is range construction and planning before any fill. I've added per-phase timers (snapshot, visit/uncovered, ready, refresh_across, update_ready, allocation lookups) and will post timing-only runs separately from attribution runs, same scene, input and window.

AI-assisted (Claude Code).

@desplmfao

Copy link
Copy Markdown
Author

Closing: this was built on #185's first two commits and #462 (closed). The same idea, ported onto #185 as it is now, is aycow#2 against #185's branch (stacked on the Wine fix aycow#1). Discussion and timing follow-ups continue there.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants