Skip to content

GPU: share one write-watch question across host copies in a reservation - #2

Merged
aycow merged 2 commits into
aycow:fix/direct-indexed-buffer-coherencyfrom
desplmfao:perf/shared-spans
Nov 24, 2026
Merged

aycow merged 2 commits into
aycow:fix/direct-indexed-buffer-coherencyfrom
desplmfao:perf/shared-spans

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #1 (the Wine fix, 9e94c21, comes first; without it no reservation is private under Wine and this never triggers). The change here is 9131c10. Follow-up to the discussion on Marvisak#600, which this replaces.

Change

Directly indexed SRV ranges are mostly in different, small host copies placed side by side in one private reservation, and update_ready groups only within one copy.

  • Shadow::update_ranges is split into ready (clip, pending GPU writes excluded) and update_ready; new floor (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 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.
  • VICTORY_NO_SHARED_SPANS=1 (diagnostics builds) turns it off; shadow traffic gains shared_spans / shared_ranges.

Measured

RTX 5080, Linux (proton-cachyos, vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of main d2a4bae + this branch + Marvisak#493 (+Marvisak#336) + Marvisak#259, Marvisak#177, Marvisak#151, story mode by VICTORY_KEYS. Same world window, 26 lines, medians:

per world frame Marvisak#185 (1efd438) + #1 + #1 + this
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)

Questions are nearly gone; frame time does not follow.

Where the frame time goes

Same stack (the + #1 + this run after a warm-up run of its binary), 28 world lines from entry, medians of the existing statistics lines (no extra timers). The VICTORY_NO_SHARED_SPANS=1 column of the same binary follows in a comment.

per world frame Marvisak#185 (1efd438) + #1 + this
frames / submissions per frame 3.0 / 45.3 3.0 / 42.0
frame time 2,933 ms 2,767 ms
submission preparation 2,712 ms 2,350 ms
copies 2,621 ms 2,245 ms
textures 12.5 ms 12.5 ms
on the GPU (queue) 162 ms 188 ms
copy-back after the fence 33.7 ms 37.0 ms
direct SRV preparation 2,226 ms 2,052 ms
of which building ranges 43.2 ms 40.1 ms
direct SRV ranges 750,573 758,703
direct SRV bytes filled 127 MB 216 MB
conventional refresh 5.3 ms (6.5 MB filled) 7.6 ms (6.0 MB filled)
snapshots 1,307 MB, 70.8 ms 1,252 MB, 70.1 ms
copy-back compared / time 395 MB, 33.3 ms 376 MB, 34.0 ms
descriptor materialization 2.9 ms 3.4 ms
write-watch questions / time 144,058 / 758 ms 4,556 / 21 ms
shared spans / ranges – 1,901 / 130,395

Direct SRV preparation is still about 2 s of the frame, while range building, copying, snapshots and materialization are each under 75 ms. A separate diagnostic build with per-stage timers (not part of this PR) puts the rest in reservation lookups: 546,415 watch::allocation calls, 2,608 ms per world frame (about 4.8 µs each under Wine, two system calls with #1). Most come from refresh_across and update_ready asking per range. A cache of looked-up reservations, cleared by range on mapping changes, cut that to 152 ms (99.9 % hits), but its one run ended in the title's watchdog crash without a GPU fault, so it is not in this PR until that is understood. Keeping this as a draft until then.

Tests

New directly_indexed_srvs_of_neighbouring_copies_share_a_question: 8 title buffers side by side in one write-watched reservation, each its own host copy and view; at most one question per submission, and each view reads the latest value. Passes; fails with VICTORY_NO_SHARED_SPANS=1 ("one question for all copies"). All 12 coherency tests pass on vkd3d-proton with VICTORY_PC_DXC set.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

desplmfao and others added 2 commits November 24, 2026 01:08
watch::allocation reads the Private bit from the flags of
QueryVirtualMemoryInformation's region information. Wine fills no flags
for any region, so under Wine every reservation looked like a view: the
grouping by reservation in Shadow::update_ready never took the private
path, and each range was asked about on its own.

When the flags are all zero, take the allocation type from VirtualQuery
(MEM_PRIVATE) instead. On Windows the flags are set and nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Directly indexed SRV ranges are mostly in different, small host copies
placed side by side in one private reservation, and update_ready groups
only within one copy, so each copy still asked about its own ranges.

refresh_direct_srvs now collects every copy's ready ranges (Shadow::ready,
pending GPU writes already excluded) and refresh_across sorts them by
address: ranges of several copies inside one live private reservation,
less than 1 MiB apart, share one grouped_writes question, taken from the
oldest of their copies (Shadow::floor), and each copy brings its ranges up
to date from it (Shadow::answered). Anything else goes through each copy's
update_ready as before. The last reservation looked up is reused while the
next range is inside it.

VICTORY_NO_SHARED_SPANS=1 (diagnostics builds) turns it off for comparing.

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

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@desplmfao Thanks for porting Marvisak#600. I'm reviewing 9131c10 independently on AMD, NVIDIA and WARP, including overlapping shadows, limited read ranges, pending GPU writes, reservation changes and a write after the shared observation. The Windows test branch also includes the same-reservation check now on the Marvisak#185 base.

The reported 776 → 22 ms of write-watch time is useful, and the frame-time change is within your run spread. For the remaining cost, could we compare warm-cache windows on the same stack with only VICTORY_NO_SHARED_SPANS toggled? The aggregate fields I need are total submission preparation and queue time, direct SRV preparation and range building, filled bytes, conventional refresh, snapshots, copyback, descriptor materialization, and the frame and submission counts for the same reporting interval. I'm adding an opt-in split of ready-range collection, flatten/sort, reservation grouping, shared observation/application, and fallback on a separate diagnostic branch so we can compare those stages without changing the batching path.

@desplmfao

desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

On it: building exactly 9131c10 (on 1efd438 + 9e94c21) with only Marvisak#493 (+Marvisak#336), Marvisak#259, Marvisak#177 and Marvisak#151 added to reach the world, one warm-up run so shaders and pipelines are cached for that binary, then VICTORY_NO_SHARED_SPANS off and on in the same binary, same input and window. I'll post your fields (submission preparation and queue time, direct SRV preparation and range building, filled bytes, conventional refresh, snapshots, copy-back, descriptor materialization, frame and submission counts per interval) as a table here, in about 20 minutes. Separately from that A/B, the per-stage timers I added point at reservation lookups in refresh_across; I'll post those as their own note so they don't mix with the attribution runs.

AI-assisted (Claude Code).

@aycow
aycow merged commit a6367ba into aycow:fix/direct-indexed-buffer-coherency Nov 24, 2026
@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@desplmfao I merged your exact 9131c10 commit into Marvisak#185 at a6367ba, with your authorship intact. The combined tree and your original head both passed 16 selected tests per adapter on AMD, NVIDIA and WARP with the debug layer and full GBV. The separate review tests pass with sharing on and off, including overlapping shadows, cached generations, pending bytes, recommit and a late write visible to the next sample.

On AMD Windows, nine optimized batches per condition measured 3.061 → 1.344 ms of CPU preparation per 80 submissions for dense views. The 1 MiB-spaced layout went 3.205 → 4.119 ms even as calls fell from 5,120 to 80. Its profiled observation took 3.904 ms, including 3.702 ms in native watch calls. With 2 MiB spacing, the sorter and grouping did work before the same per-shadow fallback. All readbacks matched. These numbers characterize the synthetic layouts.

Thanks for starting the matched Proton run. Your reservation-lookup timing will complement the opt-in stage split and fixture. I kept the profiling changes separate from Marvisak#185 and left the draft open for exact-head title validation.

@desplmfao

desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Matched Proton run, as asked: one diagnostics binary (9131c10 on 1efd438 + 9e94c21, plus Marvisak#493 (+Marvisak#336), Marvisak#259, Marvisak#177, Marvisak#151 to reach the world), one warm-up run of that binary, then a fresh process each with only VICTORY_NO_SHARED_SPANS changed. RTX 5080, proton-cachyos, Series X 1.0.2.1, story mode by VICTORY_KEYS, same summary interval for all fields. Window: the first 40 summary lines after world entry; medians per line. Neither run had a GPU fault or a crash. This was taken before your profiling split, so it has no direct SRV preparation split line.

per world frame sharing on VICTORY_NO_SHARED_SPANS=1
frames per summary interval 3.0 2.0
submissions per frame 39.0 39.5
frame time 2,700 ms 2,800 ms
submission preparation 2,350 ms 2,439 ms
on the GPU, through fence completion 148 ms 120 ms
copy-back after the fence 37.0 ms 32.2 ms
direct SRV preparation 2,052 ms 2,391 ms
of which building ranges 37.6 ms 42.1 ms
direct SRV ranges 658,720 729,698
direct SRV bytes filled 155 MB 89 MB
conventional refresh 8.1 ms (6.5 MB filled) 9.4 ms (6.8 MB filled)
snapshots 891 MB, 62.0 ms 1,173 MB, 61.9 ms
copy-back compared / shadow time 337 MB, 30.9 ms 348 MB, 35.4 ms
descriptor materialization 2.7 ms 2.8 ms
write-watch questions / time 3,650 / 23.1 ms 111,891 / 684 ms
shared spans / ranges 1,783 / 121,148 0 / 0

The ranges per frame differ by about 10 % between the two processes even in the same window, so the frame-time difference (about 4 %) is within that. Write-watch drops from 684 to 23 ms, but direct SRV preparation stays about 2 s either way. Most of that is reservation lookups (watch::allocation), not write-watch. I'm measuring a fix for that now with your VICTORY_PROFILE_SHARED_PREP split: one binary, a per-refresh-pass reservation cache switchable off, and both runs fresh. It will come as its own PR on top of this branch, with your cross-shadow review tests passing on it.

AI-assisted (Claude Code).

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@desplmfao Thanks for the matched warm-cache run and for reporting the range-count difference. The 684 → 23.1 ms watch result is clear. Direct-SRV preparation still takes about two seconds, and overall frame time remains within the workload variation you observed. I added the matched data to Marvisak#185.

Your reservation cache addresses the next measured stage. I’ll review the separate PR against the current Marvisak#185 tree when it’s available. The remap/recommit and late-write controls will be useful for checking that a cache hit retains the reservation and journal proofs.

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