Remove the deferred-work lock from host command lists #162

Open
github-bot wants to merge 2 commits from github-bot/gh-162 into main AGit
Owner

@⁠Adika713 on GitHub · 2026-11-25 18:01 UTC · original
Adika713:perf/host-deferred-no-lock → main · +61 −16 · 1 files · 2 commits · open

STATUS: pending publication.

Remove the per-access deferred-work lock from host command lists.

Every HostList::defer_* call and every submission-time read took the same
global-to-the-list mutex. crate::list already records one list on one thread
and submits it only after recording ended; a reset moves recording to a new
list. Deferred now lives in an UnsafeCell under that same invariant, and
deferred() returns &mut Deferred directly.

What is in it

  • HostList::deferred is UnsafeCell<Deferred>; deferred() documents and
    performs the single-thread access.
  • The Send/Sync safety comment now states that deferred work follows the
    list-lifetime rule.
  • An ignored CPU-only A/B benchmark of a mutex access versus the direct cell.

Tested

AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11,
rustc/cargo 1.98.1. No game data; the game was not run. Isolated
CARGO_TARGET_DIR.

cargo test --release -p victory-gpu --lib deferred_access_without_lock -- --ignored --nocapture --test-threads=1,
3 runs, median of 5 samples:

  • mutex access: 10.2 / 10.2 / 10.1 ns
  • direct cell: 0.3 / 0.5 / 0.3 ns

Correctness:

  • cargo check -p victory-gpu --lib --tests --locked: exit 0.
  • cargo test -p victory-gpu --lib host:: -- --test-threads=1: 20 passed, 0 failed, 2 ignored, 94 filtered; 10 repeated runs, 0 failed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 1 passed, 0 failed, 116 filtered.
  • Full victory-gpu lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 110 passed, 0 failed, 5 ignored, 1 filtered.
  • cargo test --workspace --no-fail-fast --locked: no new failures; known xmem, shader and policy failures remain. victory-gpu 111 passed, 0 failed, 5 ignored.

Not tested

  • In-game FPS. No game files or paths were supplied, so this makes no claim
    about frame rate.
  • NVIDIA hardware.
  • Concurrent recording and submission of the same list; the change relies on
    the existing crate::list invariant that this does not happen.
  • Open PR #139 adds fields to Deferred and a drop(deferred) after a lock
    release; if both land, that hunk needs rebasing.

AI use

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 18:01 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/162) `Adika713:perf/host-deferred-no-lock` → `main` · +61 −16 · 1 files · 2 commits · open STATUS: pending publication. Remove the per-access deferred-work lock from host command lists. Every `HostList::defer_*` call and every submission-time read took the same global-to-the-list mutex. `crate::list` already records one list on one thread and submits it only after recording ended; a reset moves recording to a new list. `Deferred` now lives in an `UnsafeCell` under that same invariant, and `deferred()` returns `&mut Deferred` directly. **What is in it** - `HostList::deferred` is `UnsafeCell<Deferred>`; `deferred()` documents and performs the single-thread access. - The `Send`/`Sync` safety comment now states that deferred work follows the list-lifetime rule. - An ignored CPU-only A/B benchmark of a mutex access versus the direct cell. **Tested** AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, rustc/cargo 1.98.1. No game data; the game was not run. Isolated `CARGO_TARGET_DIR`. `cargo test --release -p victory-gpu --lib deferred_access_without_lock -- --ignored --nocapture --test-threads=1`, 3 runs, median of 5 samples: - mutex access: **10.2 / 10.2 / 10.1 ns** - direct cell: **0.3 / 0.5 / 0.3 ns** Correctness: - `cargo check -p victory-gpu --lib --tests --locked`: exit 0. - `cargo test -p victory-gpu --lib host:: -- --test-threads=1`: 20 passed, 0 failed, 2 ignored, 94 filtered; 10 repeated runs, 0 failed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 1 passed, 0 failed, 116 filtered. - Full `victory-gpu` lib, 20 serial runs with the pre-existing #102 flake skipped: 0 failed; each 110 passed, 0 failed, 5 ignored, 1 filtered. - `cargo test --workspace --no-fail-fast --locked`: no new failures; known xmem, shader and policy failures remain. `victory-gpu` 111 passed, 0 failed, 5 ignored. **Not tested** - In-game FPS. No game files or paths were supplied, so this makes no claim about frame rate. - NVIDIA hardware. - Concurrent recording and submission of the same list; the change relies on the existing `crate::list` invariant that this does not happen. - Open PR #139 adds fields to `Deferred` and a `drop(deferred)` after a lock release; if both land, that hunk needs rebasing. **AI use** AI-assisted: OpenCode, model Big Pickle. No game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:58 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-25 19:29 UTC · original

Independent verification on PR head 3f3764f (Bazzite Linux 45 x86_64, Intel Core i9-11900K, NVIDIA RTX 3090 driver 620.73.04, Rust 1.98.1, x86_64-pc-windows-gnu under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0):

Release benchmark (deferred_access_without_lock, 3 runs, median of 5 samples)

  • mutex access: 8.8 / 8.7 / 8.7 ns
  • direct cell: 0.2 / 0.2 / 0.2 ns

Build & review notes

  1. 9 new unused_mut warnings in crates/victory-gpu/src/host.rs (lines 1628, 2268, 2292, 2316, 2328, 2448, 2576, 2632, 2645: let mut deferred = ... no longer needs mut since deferred() returns &mut Deferred), which will fail cargo clippy -- -D warnings.
  2. Aliasing safety: fn deferred(&self) -> &mut Deferred is currently a safe function returning &mut from &self via UnsafeCell. Marking it unsafe fn (or exposing a closure helper with a debug re-entrancy guard and &Deferred for read-only callers such as prewarm / run_deferred) prevents accidentally creating overlapping &mut Deferred borrows in future edits.
  3. Verified reap_completed() runs finish_submission() before advancing FINISHED_FENCE, so HostList::reset() waiting on last_fence remains synchronized under VICTORY_ASYNC_SUBMIT=1 (now default on main).

In-game FPS was not measured here.

**@⁠KernelSmoker** on GitHub · 2026-11-25 19:29 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/162#issuecomment-7172368783) Independent verification on PR head `3f3764f` (Bazzite Linux 45 x86_64, Intel Core i9-11900K, NVIDIA RTX 3090 driver 620.73.04, Rust 1.98.1, `x86_64-pc-windows-gnu` under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0): ### Release benchmark (`deferred_access_without_lock`, 3 runs, median of 5 samples) - mutex access: **8.8 / 8.7 / 8.7 ns** - direct cell: **0.2 / 0.2 / 0.2 ns** ### Build & review notes 1. **9 new `unused_mut` warnings** in `crates/victory-gpu/src/host.rs` (lines 1628, 2268, 2292, 2316, 2328, 2448, 2576, 2632, 2645: `let mut deferred = ...` no longer needs `mut` since `deferred()` returns `&mut Deferred`), which will fail `cargo clippy -- -D warnings`. 2. **Aliasing safety**: `fn deferred(&self) -> &mut Deferred` is currently a safe function returning `&mut` from `&self` via `UnsafeCell`. Marking it `unsafe fn` (or exposing a closure helper with a debug re-entrancy guard and `&Deferred` for read-only callers such as `prewarm` / `run_deferred`) prevents accidentally creating overlapping `&mut Deferred` borrows in future edits. 3. Verified `reap_completed()` runs `finish_submission()` before advancing `FINISHED_FENCE`, so `HostList::reset()` waiting on `last_fence` remains synchronized under `VICTORY_ASYNC_SUBMIT=1` (now default on `main`). In-game FPS was not measured here.
Author
Owner

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

Concurrency check on Windows/RDNA2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1). I merged this PR (3f3764f) onto main 4f62c2a plus #210, which fixes list::tests::lists_are_cut_at_waits_that_follow_work, a test that fails in every release run on main. Then I ran the release victory-gpu lib test binary 10 times, with the default thread count:

  • This PR: 10 of 10 runs passed (113 passed, 5 ignored).
  • The same base without the PR: 1 run failed on the known flake watch::tests::written_pages_are_reported_to_every_asker (#102), and 1 run died without a result line.

No new failure, deadlock or hang showed up in these runs. Ten runs are a small sample for races. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

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

**@⁠MamaLeVrai** on GitHub · 2026-11-26 05:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/162#issuecomment-7183256070) Concurrency check on Windows/RDNA2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1). I merged this PR (`3f3764f`) onto `main` `4f62c2a` plus #210, which fixes `list::tests::lists_are_cut_at_waits_that_follow_work`, a test that fails in every release run on `main`. Then I ran the release `victory-gpu` lib test binary 10 times, with the default thread count: - This PR: 10 of 10 runs passed (113 passed, 5 ignored). - The same base without the PR: 1 run failed on the known flake `watch::tests::written_pages_are_reported_to_every_asker` (#102), and 1 run died without a result line. No new failure, deadlock or hang showed up in these runs. Ten runs are a small sample for races. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
Address review note: deferred() returns &mut Deferred so local bindings no longer need mut. No behavior change.

Prepared with AI assistance (OpenCode, gpt-5.4) on behalf of @Adika713.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/162/head:github-bot/gh-162'
git switch 'github-bot/gh-162'

Merge

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