gpu: refresh the submission's buffer copies on several threads #3305

Open
github-bot wants to merge 1 commit from github-bot/gh-3305 into main AGit
Owner

@⁠borosf on GitHub · 2026-11-26 16:38 UTC · original
borosf:vibe/parallel-flush-copies-842ca5 → main · +107 −10 · 1 files · 1 commits · open

What

Batch::flush ran each pending copy's Shadow::update on the submitting thread, one after another. A world frame asks for ~80 copies moving ~265 MB through a single ReadProcessMemory thread.

Each copy appears at most once in the batch (pending is keyed by the shadow's pointer), so the updates touch disjoint state — Shadow is Send + Sync (shadow.rs:137-139) and holds its own locks; the copy itself is ReadProcessMemory, which is thread-safe. The flush now drains the refreshes and runs the updates through the existing texture::in_parallel (up to 4 threads, same helper the texture refresh uses). The current-range merge stays serial afterwards, in the original order, so its result is unchanged. copystat/PREPARING accounting is atomic and per-item, unchanged in meaning.

Claimed on #1633 (parallelize serial submission-prep buffer copies). Implemented at the Batch::flush level, across shadows — not inside Shadow::update — to stay clear of NEW-… partial-page-granularity work on that function.

Measurement (Windows 11, Intel Arc B580 host, 12 cores, synthetic only — no game data)

New test host::batch::many_copies_refresh_in_parallel_and_copy_the_same_bytes: 16 write-watched pools x 64 pages (64 MiB), all pages dirty, one Batch holding all 16 copies:

cargo test -p victory-gpu --lib --locked -- --test-threads=1 --exact host::batch::many_copies_refresh_in_parallel_and_copy_the_same_bytes --nocapture
flush of 16 copies x 64 pages (64 MiB): parallel 6.547ms, serial 8.043ms
flush of 16 copies x 64 pages (64 MiB): parallel 7.117ms, serial 8.079ms
flush of 16 copies x 64 pages (64 MiB): parallel 6.514ms, serial 8.214ms

~1.2-1.3x on the pure copy path (same-process RPM already saturates ~8 GB/s single-thread on this host, so the synthetic ceiling is low); the test asserts the host copies hold exactly the title's bytes after both passes. On the real frame the per-copy kernel work that dominates (write-watch queries, soft faults on fresh snapshot buffers, the unmapped-page fallback walks) also runs inside update, so the ~927 ms copy phase of the 1,842 ms world frame is what this parallelizes across up to 4 threads — title-side number to be taken by whoever can run it.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings — clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — clean
  • cargo test -p victory-gpu --lib --locked --no-fail-fast — 230 passed, 2 failed: the known B580 baseline failures pristine main also fails (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744/#1829)
  • fmt gate: rustfmt --config-path rustfmt.toml --edition 2024 --check crates/victory-gpu/src/host.rs — 85 diff hunks, identical to the origin/main baseline of the same file (repo is deliberately not default-fmt clean; no new hunks)
  • cargo xtask policy — 193 files ok

No game data used anywhere; synthetic pools only.

**@⁠borosf** on GitHub · 2026-11-26 16:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/3305) `borosf:vibe/parallel-flush-copies-842ca5` → `main` · +107 −10 · 1 files · 1 commits · open ## What `Batch::flush` ran each pending copy's `Shadow::update` on the submitting thread, one after another. A world frame asks for ~80 copies moving ~265 MB through a single `ReadProcessMemory` thread. Each copy appears at most once in the batch (`pending` is keyed by the shadow's pointer), so the updates touch disjoint state — `Shadow` is `Send + Sync` (shadow.rs:137-139) and holds its own locks; the copy itself is `ReadProcessMemory`, which is thread-safe. The flush now drains the refreshes and runs the updates through the existing `texture::in_parallel` (up to 4 threads, same helper the texture refresh uses). The `current`-range merge stays serial afterwards, in the original order, so its result is unchanged. `copystat`/`PREPARING` accounting is atomic and per-item, unchanged in meaning. Claimed on #1633 (parallelize serial submission-prep buffer copies). Implemented at the `Batch::flush` level, across shadows — not inside `Shadow::update` — to stay clear of NEW-… partial-page-granularity work on that function. ## Measurement (Windows 11, Intel Arc B580 host, 12 cores, synthetic only — no game data) New test `host::batch::many_copies_refresh_in_parallel_and_copy_the_same_bytes`: 16 write-watched pools x 64 pages (64 MiB), all pages dirty, one `Batch` holding all 16 copies: ``` cargo test -p victory-gpu --lib --locked -- --test-threads=1 --exact host::batch::many_copies_refresh_in_parallel_and_copy_the_same_bytes --nocapture ``` ``` flush of 16 copies x 64 pages (64 MiB): parallel 6.547ms, serial 8.043ms flush of 16 copies x 64 pages (64 MiB): parallel 7.117ms, serial 8.079ms flush of 16 copies x 64 pages (64 MiB): parallel 6.514ms, serial 8.214ms ``` ~1.2-1.3x on the pure copy path (same-process RPM already saturates ~8 GB/s single-thread on this host, so the synthetic ceiling is low); the test asserts the host copies hold exactly the title's bytes after both passes. On the real frame the per-copy kernel work that dominates (write-watch queries, soft faults on fresh snapshot buffers, the unmapped-page fallback walks) also runs inside `update`, so the ~927 ms copy phase of the 1,842 ms world frame is what this parallelizes across up to 4 threads — title-side number to be taken by whoever can run it. ## Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings` — clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — clean - `cargo test -p victory-gpu --lib --locked --no-fail-fast` — 230 passed, 2 failed: the known B580 baseline failures pristine main also fails (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`, #1744/#1829) - fmt gate: `rustfmt --config-path rustfmt.toml --edition 2024 --check crates/victory-gpu/src/host.rs` — 85 diff hunks, identical to the origin/main baseline of the same file (repo is deliberately not default-fmt clean; no new hunks) - `cargo xtask policy` — 193 files ok No game data used anywhere; synthetic pools only.
Batch::flush ran each copy's Shadow::update on the submitting thread:
a world frame's ~80 copies move ~265 MB through one ReadProcessMemory
thread. Each copy appears once in the batch (pending is keyed by its
shadow), so the updates touch disjoint state and run via the existing
texture::in_parallel (up to 4 threads); the current-range merge stays
serial and in the original order. Synthetic test: 16 copies x 64 pages
(64 MiB) flush in ~6.5 ms parallel vs ~7.9 ms serial on a 12-core B580
host, same bytes copied. No game data; synthetic pools only.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:39:21 +00:00
Author
Owner

@⁠borosf on GitHub · 2026-11-26 16:40 UTC · original

Claimed on #1633 in comment 7195935695 (parallelize the serial submission-prep buffer copies). Head 4ed54fc. Will post done: NEW-n -> #3305 once the ledger bot assigns the id.

**@⁠borosf** on GitHub · 2026-11-26 16:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3305#issuecomment-7197943753) Claimed on #1633 in [comment 7195935695](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) (parallelize the serial submission-prep buffer copies). Head 4ed54fc. Will post `done: NEW-n -> #3305` once the ledger bot assigns the id.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 16:47 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Parallelizing disjoint Shadow::update calls in Batch::flush via texture::in_parallel (deduplicated per Shadow in pending, re-ordered by index before updating self.current) is clean and sound.
  • cargo test -p victory-gpu --lib host::batch:: -- --test-threads=1 (RTX 5090): 2 passed, 0 failed (including many_copies_refresh_in_parallel_and_copy_the_same_bytes).
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1 (RTX 5090): 10 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 16:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3305#pullrequestreview-6077789237) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090): - Parallelizing disjoint `Shadow::update` calls in `Batch::flush` via `texture::in_parallel` (deduplicated per `Shadow` in `pending`, re-ordered by index before updating `self.current`) is clean and sound. - `cargo test -p victory-gpu --lib host::batch:: -- --test-threads=1` (RTX 5090): 2 passed, 0 failed (including `many_copies_refresh_in_parallel_and_copy_the_same_bytes`). - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1` (RTX 5090): 10 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3305/head:github-bot/gh-3305'
git switch 'github-bot/gh-3305'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3305'
git switch 'github-bot/gh-3305'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3305'
git switch 'github-bot/gh-3305'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3305'
git switch 'main'
git merge --squash 'github-bot/gh-3305'
git switch 'main'
git merge --ff-only 'github-bot/gh-3305'
git switch 'main'
git merge 'github-bot/gh-3305'
git push origin 'main'
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!3305
No description provided.