Skip to content

GPU: parallelize host-copy refreshes on multicore systems - #38

Open
space-de wants to merge 2 commits into
fxceless:mainfrom
space-de:perf/adaptive-wide-refresh
Open

space-de wants to merge 2 commits into
fxceless:mainfrom
space-de:perf/adaptive-wide-refresh

Conversation

@space-de

@space-de space-de commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

  • Automatically parallelize independent host-copy refreshes when the system reports at least four logical CPUs.
  • Preserve VICTORY_WIDE_REFRESH=0 as an opt-out and =1 as an override; flushes still need at least four independent copies before using the worker pool.
  • This targets the serial CPU memory reads the code measures at roughly 45–50 ms per frame. It should reduce CPU preparation time on multicore systems; no in-game FPS result is claimed here.

Validation

  • cargo test --workspace --no-fail-fast --quiet — passed (497 passed, 7 ignored).
  • cargo clippy --workspace -- -D warnings — passed.
  • cargo clippy --workspace --all-features -- -D warnings — passed.
  • The workspace formatter check reports existing formatting differences in unrelated files; the changed host.rs lines had no formatter diff.

The existing setting was opt-in and no open PR was found changing its default.

@ryotdev

ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

I found a race in the copy timer this change enables by default. On 05ee438, each parallel refresh adds its worker time to PREPARING[0]. After joining, the submission reads the total and subtracts the excess over wall time. The presenter can reset the counter with swap(0) between that last read and subtraction. Subtracting 300 µs from the reset counter leaves 18446744073709551316 µs for the next sample. This affects the reported “copies” time used to judge the speedup. Batch::flush · Presenter counter reset

I tested a small fix on Windows. Let Batch::update return its elapsed µs and keep recording bytes and per-range diagnostics there. The serial callers add the returned time as before. For the parallel path, add the wall time once after wide_run joins. This removes the read/subtract correction entirely.

In a CPU-only test using the PR's Batch::flush and four synthetic 4 KiB copies, a second thread sampled after three workers finished and before the batch joined. It saw 6,975 µs of worker time on this head and 0 µs with the fix. The fixed batch published 5,303 µs on return and counted all 16,384 bytes. The one-to-three-copy serial cases and flush_one also passed. This was an AI-assisted accounting test, with no game data or FPS measurement.

Korsuma added a commit to RicerBoy/DropItLikeItsHot that referenced this pull request Nov 24, 2026
… (#82), core/VRAM scaling (#49/#38/#42/#45/#47), scatter batching (#108), prelude textures (#80), and shader/UAV fixes

Integrates 15 upstream PRs orthogonal to Issue #2's default speed-switch measurements:
- GPU culling & compute cap:
  - Marvisak/VIctory#1731: real host D3D12 occlusion queries (wired into read_backs for both sync execute and async VICTORY_RELAY/LATE_WAIT flights)
  - fxceless/victory-fork#82: hardware depth-bounds test pass-through in pipelines and command lists
  - fxceless/victory-fork#66: lower default compute shader loop cap (4096 -> 256)
- CPU multicore, streaming & memory/VRAM scaling:
  - fxceless/victory-fork#49: scale shadow, pipeline (keeping VICTORY_PIPELINE_THREADS override), and DirectStorage workers with CPU cores
  - fxceless/victory-fork#38: default-on parallel host-copy refreshes on >=4 logical CPUs (VICTORY_WIDE_REFRESH=0 opts out)
  - fxceless/victory-fork#108: batch adjacent zero-page unmaps in XMemMapPhysicalPagesScatter
  - fxceless/victory-fork#67: release directly indexed buffer ranges with their heap
  - fxceless/victory-fork#42, #45, #47: auto-scale card buffers, texture staging/floor, and snapshot/scratch/list pools from VRAM and RAM
- Rendering smoothness & correctness:
  - fxceless/victory-fork#80: upload dirty title textures in HostList::prelude
  - fxceless/victory-fork#114: mirror placed unordered texture views onto host textures
  - fxceless/victory-fork#121: preserve VGPR slots observed by relative reads
  - fxceless/victory-fork#122: recompute ISG1 input usage and barycentrics flag after bitcode opt
  - fxceless/victory-fork#112: fix DXIL signature ordering for packed semantics

Verified:
- cargo xtask policy --staged: 21 files ok
- cargo clippy --workspace --all-features --lib --tests -- -D warnings: 0 warnings
- cargo test --workspace: 0 failures (140 victory-gpu incl. host occlusion query + depth-bounds tests; 226/226 victory-shader)
- Live 2560x1440 run (RTX 4080, VICTORY_RELAY=2 + VICTORY_INPLACE=1): reached 3D world (frame 1285), 77 in-place windows (364 MB, 0 refused), 0.0 ms texture remap waits, 0 crashes, 0 D3D12 errors

Fixes #10
@rocobalt1

Copy link
Copy Markdown

Measured on Windows with the same build this PR was measured on (this tree plus the shader PRs; the only difference between the two runs below is this merge).

Setup: RTX 4060 Ti 8 GB, Ryzen 9 5900X, Windows 11; --console series-x, VICTORY_DISPLAY_MODE=1920x1080, VICTORY_SHADER_LOOP_LIMIT=256, VICTORY_NO_WATCHDOG=1, fresh data dir per run, 3 - 4 minutes each, frames with more than 800 draws only. TdrDelay=60, so both columns are upper bounds.

without this PR with this PR
copies, median 94.6 ms 81.5 ms
copies, min 48.9 ms 17.3 ms
copies, max 154.2 ms 96.6 ms
frame, median 1 036 ms 767 ms
shader refusals 4 4
device removal no no

The frame median moved too, but I would not claim it for this PR: the two runs saw different amounts of streaming (10 against 15 world frames), and the copy lane is the only thing measured identically in both. The part that is clean is the tail - the worst copies halve - which is what I would expect from refreshing across threads rather than one after another.

No game data; counts only.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

One more data point, on an RTX 4070 12 GB (Ryzen 7 5800X3D, 32 GB, Windows 11), same executable for both runs (4e17478 + #63 + #71 + #147, the watchdog hooks of #28 and a local profiling commit that is off unless asked for), only VICTORY_WIDE_REFRESH differing. VICTORY_RELAY=2, VICTORY_PIPELINE_WAIT_MS=24, VICTORY_CARD_BUFFERS_MIN_MB=1, VICTORY_CARD_BUFFERS_MB=2048, VICTORY_CARD_REHASH_RUNS=1, VICTORY_WIDE_BACK=1, VICTORY_WIDE_MERGE=1, VICTORY_LATE_WAIT_LISTS=256, no DRED, warm shader cache and pipeline library.

Measured over a settled window of the prologue's first scene: 12 statistics lines (about 60 s) starting at the first of three lines with the heap-buffer pass under 100 ms and at least 3,000 draws a frame, so the texture streaming of the first minute in the world is left out.

per frame, median off VICTORY_WIDE_REFRESH=1
frame 220.8 ms 195.1 ms
last 30 s of the window 224.1 ms 191.0 ms
copies 71.8 ms 58.2 ms
copying back 75.4 ms 57.8 ms
on the GPU 59.2 ms 60.8 ms
draws 4,979 4,977

No device removal, and the world's picture is there in both. One run each, the second after the first (its cache one run warmer), so the ranges overlap (198.8–303.0 against 175.7–232.0); I did not run the reverse order. The frame time here comes from the frame line, not from the "copies" counter, so the timer race @ryotdev describes does not touch the first two rows; it may touch the "copies" row.

AI-assisted.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

A correction to my numbers above. Two runs with identical settings turned out to differ by 20–25 ms here (the driver is still compiling new pipelines in the "settled" window), so one run per setting could not resolve a gain of this size, and the −25.7 ms I reported was mostly that.

Measured again inside one run: once the world settles, VICTORY_WIDE_REFRESH is switched off (A) and on (B) every 4 statistics lines (about 20 s), the first line of each block is dropped, and each B block is compared with the mean of its neighbouring A blocks. Same scene, cache and machine state for both arms. RTX 4070, same recipe as above, plus #154, #255 and #270 in the build.

per frame, median A (off) B (on)
frame 177.6 ms 168.1 ms
copies 46.7 ms 43.9 ms
heap-buffer pass 35.9 ms 14.8 ms
on the GPU 56.0 ms 62.6 ms

Paired B − A: median −7.0 ms over 4 pairs (+0.4, −6.2, −7.8, −13.1); the sign agrees in 3 of 4. Blocks in order: A176 B179 A182 B170 A171 B166 A177 B164.

So on this machine the change helps by roughly 7 ms a frame, not 26. Small, consistent in sign, 4 pairs in one run.

AI-assisted.

@YeokiNoewChi

Copy link
Copy Markdown

RTX 3070 Ti 8 GB, Ryzen 5 5600X (6 cores, 12 threads), Windows 11, Series X profile, fork main 4e17478 plus several open PRs. VICTORY_WIDE_REFRESH=1 (the switch this PR turns on by default) makes geometry go missing in the prologue: from the barracks doorway the yard's inmates and picnic tables are not drawn and a wall beside the door shows sky. Restarting the same build and warm cache with only that switch removed brings them all back (checked by eye, same camera position). Frame time is about the same either way on this 6-core CPU (Ryzen 5 5600X), so on this machine the parallel refresh costs picture and gains nothing measurable.

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.

5 participants