[pr-performance][rendering] gpu: speed up copy_runs, pieces::take, write-watch journal, and preparing hot paths #712

Open
ggwp wants to merge 1 commit from ggwp/Darner:perf/gpu-hot-paths into post-merge
Contributor

Contributor role (optional)

  • Fluxer ID: FomalhautCusimanse#7381

What it changes

Port of gamingwithhomie/larp commit 7d96eac3 (originally by talfour, adapted cleanly to Darner post-merge):

  • The problem on post-merge: Per-submission CPU overhead in copy_runs, pieces::take, watch::JOURNAL, and host::preparing:

    • copy_runs allocated a places vector and HashMap<usize, Spans> twice per batch and allocated Vec<u64> on every Spans::add (~3.0–4.1 ms/frame in gamingwithhomie/larp profiles).
    • pieces::take acquired STATE unconditionally even when no copies/rests were pending and dropped settled D3D12 buffers while holding STATE.
    • watch::JOURNAL serialized parallel submission refresh readers behind a Mutex and ran redundant ask_ahead/ask_ahead_done work while ask_once was active, inserting every 4 KiB page into the 64 KiB BTreeMap without deduplicating consecutive 4 KiB addresses in the same 64 KiB page.
    • Hot-path maps/sets in host::preparing, pieces, shadow, and texevents used SipHash HashMap/HashSet instead of FastMap/FastSet.
  • Fix:

    • Rewrites copy_runs with a sort-and-cluster fast path, thread-local scratch reuse, generation-tagged run map, zero-alloc Spans::add, and a 2,000-case fuzz test (copy_runs_matches_reference_fuzz) against the reference implementation.
    • Adds lock-free HAS_COPIES/NEXT_REST fast path in pieces::take and drops settled objects outside STATE via host::reap_now.
    • Switches watch::JOURNAL to RwLock with an atomic KEPT short-circuit and 4 KiB -> 64 KiB page deduplication.
    • Uses FastMap/FastSet and thread-local scratch reuse across host::preparing, pieces, shadow, and texevents.

How it was tested

  • Tested revision: ea01533 (based on post-merge 28a9b42; also run in-game in a combined build with #676, #684, and the loop-reg / audio ports)
  • Commands and results:
    • cargo test --offline -p darner-gpu copy_runs_tests — 1 passed (copy_runs_matches_reference_fuzz, 2,000 randomized + fixed cases), 0 failed
    • cargo clippy --offline -p darner-gpu --tests — passed
    • cargo build --offline --release -p darner — succeeded
  • Changes a default: yes (internal hot-path algorithms; exact same semantics pinned by the 2,000-case fuzz test).
  • A/B result: Tested in-game on AMD Radeon 8060S (RDNA 3.5) and AMD Radeon RX 9070 XT (RDNA 4) inside a combined test build (with #676 and #684 required for AMD rendering/startup). Upstream gamingwithhomie/larp (7d96eac3) measured copy_runs dropping from ~3.0–4.1 ms/frame to ~0.05–0.50 ms/frame. No isolated standalone A/B FPS table recorded on post-merge alone.
  • Checks run on ea01533: cargo test, cargo clippy (passed).
  • Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build.
  • Hardware dependence: general (CPU submission/preparation hot paths across all GPUs).
  • Coverage gaps: Standalone isolated A/B timing table on post-merge not separately measured outside the combined AMD build.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on post-merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found.
  • Replaces or overlaps: none found.
## Contributor role (optional) - Fluxer ID: FomalhautCusimanse#7381 ## What it changes Port of `gamingwithhomie/larp` commit `7d96eac3` (originally by `talfour`, adapted cleanly to Darner `post-merge`): - **The problem on `post-merge`:** Per-submission CPU overhead in `copy_runs`, `pieces::take`, `watch::JOURNAL`, and `host::preparing`: - `copy_runs` allocated a `places` vector and `HashMap<usize, Spans>` twice per batch and allocated `Vec<u64>` on every `Spans::add` (~3.0–4.1 ms/frame in `gamingwithhomie/larp` profiles). - `pieces::take` acquired `STATE` unconditionally even when no copies/rests were pending and dropped settled D3D12 buffers while holding `STATE`. - `watch::JOURNAL` serialized parallel submission refresh readers behind a `Mutex` and ran redundant `ask_ahead`/`ask_ahead_done` work while `ask_once` was active, inserting every 4 KiB page into the 64 KiB `BTreeMap` without deduplicating consecutive 4 KiB addresses in the same 64 KiB page. - Hot-path maps/sets in `host::preparing`, `pieces`, `shadow`, and `texevents` used SipHash `HashMap`/`HashSet` instead of `FastMap`/`FastSet`. - **Fix:** - Rewrites `copy_runs` with a sort-and-cluster fast path, thread-local scratch reuse, generation-tagged run map, zero-alloc `Spans::add`, and a 2,000-case fuzz test (`copy_runs_matches_reference_fuzz`) against the reference implementation. - Adds lock-free `HAS_COPIES`/`NEXT_REST` fast path in `pieces::take` and drops settled objects outside `STATE` via `host::reap_now`. - Switches `watch::JOURNAL` to `RwLock` with an atomic `KEPT` short-circuit and 4 KiB -> 64 KiB page deduplication. - Uses `FastMap`/`FastSet` and thread-local scratch reuse across `host::preparing`, `pieces`, `shadow`, and `texevents`. ## How it was tested - Tested revision: `ea01533` (based on `post-merge` `28a9b42`; also run in-game in a combined build with #676, #684, and the loop-reg / audio ports) - Commands and results: - `cargo test --offline -p darner-gpu copy_runs_tests` — 1 passed (`copy_runs_matches_reference_fuzz`, 2,000 randomized + fixed cases), 0 failed - `cargo clippy --offline -p darner-gpu --tests` — passed - `cargo build --offline --release -p darner` — succeeded - Changes a default: yes (internal hot-path algorithms; exact same semantics pinned by the 2,000-case fuzz test). - A/B result: Tested in-game on AMD Radeon 8060S (RDNA 3.5) and AMD Radeon RX 9070 XT (RDNA 4) inside a combined test build (with #676 and #684 required for AMD rendering/startup). Upstream `gamingwithhomie/larp` (`7d96eac3`) measured `copy_runs` dropping from ~3.0–4.1 ms/frame to ~0.05–0.50 ms/frame. No isolated standalone A/B FPS table recorded on `post-merge` alone. - Checks run on `ea01533`: `cargo test`, `cargo clippy` (passed). - Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build. - Hardware dependence: general (CPU submission/preparation hot paths across all GPUs). - Coverage gaps: Standalone isolated A/B timing table on `post-merge` not separately measured outside the combined AMD build. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `post-merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. - Replaces or overlaps: none found.
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 'perf/gpu-hot-paths:ggwp-perf/gpu-hot-paths'
git switch 'ggwp-perf/gpu-hot-paths'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'post-merge'
git merge --no-ff 'ggwp-perf/gpu-hot-paths'
git switch 'ggwp-perf/gpu-hot-paths'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'ggwp-perf/gpu-hot-paths'
git switch 'ggwp-perf/gpu-hot-paths'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'ggwp-perf/gpu-hot-paths'
git switch 'post-merge'
git merge --squash 'ggwp-perf/gpu-hot-paths'
git switch 'post-merge'
git merge --ff-only 'ggwp-perf/gpu-hot-paths'
git switch 'post-merge'
git merge 'ggwp-perf/gpu-hot-paths'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!712
No description provided.