perf(gpu): cut per-draw and title-memory sync CPU overhead #127

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

@⁠matheusfrta on GitHub · 2026-11-25 15:02 UTC · original
matheusfrta:patch-1795618938 → main · +842 −372 · 10 files · 1 commits · open

The world frame rate is mostly CPU-bound across title recording and submission prep, so this targets the biggest hotspots there. Fixed sparse 2 GiB shadows losing write-watching after touching a mapped view, stopped synchronous copy-backs from pinning guarded blocks for two seconds, replaced per-batch thread spawning in in_parallel with a worker pool to avoid firing title TLS callbacks every submission, and trimmed per-draw locks and heap allocations.

**@⁠matheusfrta** on GitHub · 2026-11-25 15:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/127) `matheusfrta:patch-1795618938` → `main` · +842 −372 · 10 files · 1 commits · open The world frame rate is mostly CPU-bound across title recording and submission prep, so this targets the biggest hotspots there. Fixed sparse 2 GiB shadows losing write-watching after touching a mapped view, stopped synchronous copy-backs from pinning guarded blocks for two seconds, replaced per-batch thread spawning in `in_parallel` with a worker pool to avoid firing title TLS callbacks every submission, and trimmed per-draw locks and heap allocations.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:18 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 18:44 UTC · original

Compile check on PR head c9e45b4 (cargo check --workspace --all-targets --locked --offline --target x86_64-pc-windows-gnu, Rust 1.98.1) fails in crates/victory-gpu/src/host.rs:

error[E0425]: cannot find type `F` in this scope
    --> crates/victory-gpu/src/host.rs:3134:36
     |
3134 |         s.run = Some((run_job::<T, F>, (&raw const job) as usize));
     |                                    ^
error[E0425]: cannot find type `F` in this scope
    --> crates/victory-gpu/src/host.rs:3138:27
     |
3138 |     unsafe { run_job::<T, F>((&raw const job) as usize) };
     |                           ^

in_parallel takes f: impl Fn(&[T]) + Sync (line 3017) rather than a named generic F: Fn(&[T]) + Sync, so run_job::<T, F> cannot name F.

**@⁠KernelSmoker** on GitHub · 2026-11-25 18:44 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/127#issuecomment-7171339317) Compile check on PR head `c9e45b4` (`cargo check --workspace --all-targets --locked --offline --target x86_64-pc-windows-gnu`, Rust 1.98.1) fails in `crates/victory-gpu/src/host.rs`: ``` error[E0425]: cannot find type `F` in this scope --> crates/victory-gpu/src/host.rs:3134:36 | 3134 | s.run = Some((run_job::<T, F>, (&raw const job) as usize)); | ^ error[E0425]: cannot find type `F` in this scope --> crates/victory-gpu/src/host.rs:3138:27 | 3138 | unsafe { run_job::<T, F>((&raw const job) as usize) }; | ^ ``` `in_parallel` takes `f: impl Fn(&[T]) + Sync` (line 3017) rather than a named generic `F: Fn(&[T]) + Sync`, so `run_job::<T, F>` cannot name `F`.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 05:10 UTC · original

One deadlock to look at when this is rebased. It comes from reading the code; I have not seen it happen.

readable_at runs readable(list, u, view) inside crate::descriptor::with_view, so the VIEWS read lock is held for the whole of readable. Before this PR, view() cloned the view and dropped the lock first. Inside readable there is a path to VIEWS.write() on the same thread:

  • readable → crate::descriptor::host::placed_texture(view) → crate::resource::texture_at(...).
  • texture_at releases the resource it has just made in two cases: when the host copy could not be made (resource(out).host.is_none()), and when another thread put the same (address, desc) in PLACED_TEXTURES first. In both it calls resource_release(out).
  • That is the last reference, so Resource's Drop runs and calls crate::descriptor::forget(...), which takes VIEWS.write().

Taking the write lock while this thread holds the read lock never returns: std::sync::RwLock is not re-entrant. The second case needs two recording threads to meet the same placed texture for the first time, which titles that record on several threads can do. Cloning the view before readable, as main does, or releasing those resources after the lock is gone, would avoid it.

Separately, the PR currently conflicts with main (descriptor.rs, draw.rs, indirect.rs). main already made VIEWS an RwLock.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 05:10 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/127#issuecomment-7183245397) One deadlock to look at when this is rebased. It comes from reading the code; I have not seen it happen. `readable_at` runs `readable(list, u, view)` inside `crate::descriptor::with_view`, so the `VIEWS` read lock is held for the whole of `readable`. Before this PR, `view()` cloned the view and dropped the lock first. Inside `readable` there is a path to `VIEWS.write()` on the same thread: - `readable` → `crate::descriptor::host::placed_texture(view)` → `crate::resource::texture_at(...)`. - `texture_at` releases the resource it has just made in two cases: when the host copy could not be made (`resource(out).host.is_none()`), and when another thread put the same `(address, desc)` in `PLACED_TEXTURES` first. In both it calls `resource_release(out)`. - That is the last reference, so `Resource`'s `Drop` runs and calls `crate::descriptor::forget(...)`, which takes `VIEWS.write()`. Taking the write lock while this thread holds the read lock never returns: `std::sync::RwLock` is not re-entrant. The second case needs two recording threads to meet the same placed texture for the first time, which titles that record on several threads can do. Cloning the view before `readable`, as `main` does, or releasing those resources after the lock is gone, would avoid it. Separately, the PR currently conflicts with `main` (`descriptor.rs`, `draw.rs`, `indirect.rs`). `main` already made `VIEWS` an `RwLock`. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:05 UTC · original · reviewed

AI-assisted review. I inspected the changed worker-pool initialization and accounting; I did not run tests or a game.

**@⁠gut0to** on GitHub · 2026-11-26 16:05 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/127#pullrequestreview-6077250410) · **reviewed** AI-assisted review. I inspected the changed worker-pool initialization and accounting; I did not run tests or a game.
@ -2983,0 +3082,4 @@
}
// Only expose workers that actually spawned; if fewer spawned, threads < THREADS
// still leaves them idle only when id >= s.threads - 1, which is true for spawned.
let _ = spawned;
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:05 UTC · original

AI-assisted static review: I traced pool initialization and active-worker accounting; I did not run tests or a game. spawned is counted but discarded, while Pool.workers stays at THREADS - 1 and each run sets active from that fixed count. If even one thread creation fails, fewer workers can decrement active than WaitPool awaits, so in_parallel can hang. Could the pool use the actual spawned count (or fail initialization and fall back before publishing the pool)?

**@⁠gut0to** on GitHub · 2026-11-26 16:05 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/127#discussion_r4710856503) AI-assisted static review: I traced pool initialization and active-worker accounting; I did not run tests or a game. `spawned` is counted but discarded, while `Pool.workers` stays at `THREADS - 1` and each run sets `active` from that fixed count. If even one thread creation fails, fewer workers can decrement `active` than `WaitPool` awaits, so `in_parallel` can hang. Could the pool use the actual spawned count (or fail initialization and fall back before publishing the pool)?
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor.rs
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/indirect.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-127'
git switch 'github-bot/gh-127'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-127'
git switch 'github-bot/gh-127'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-127'
git switch 'main'
git merge --squash 'github-bot/gh-127'
git switch 'main'
git merge --ff-only 'github-bot/gh-127'
git switch 'main'
git merge 'github-bot/gh-127'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.