GPU/draw: create D3D12 command signatures outside cache mutex #1393

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

@⁠n-romanovich on GitHub · 2026-11-26 22:36 UTC · original
n-romanovich:perf/1370-unlock-command-signature → main · +107 −64 · 1 files · 1 commits · open

Addresses side finding 1 in #1370.

Problem

Both host_spread_signature and host_signature held their global MADE cache Mutex across ID3D12Device::CreateCommandSignature. During recording in execute_indirect, a slow driver CreateCommandSignature call (observed taking seconds on Intel Arc and causing Mutex::lock_contended stalls across worker threads) blocked every other recording thread from looking up even already-cached command signatures.

Changes (crates/victory-gpu/src/draw.rs)

  • Extract a shared cached_command_signature helper and use it in both host_spread_signature and host_signature:
    1. Lock MADE briefly for lookup and return immediately on cache hit.
    2. Drop the lock before calling ID3D12Device::CreateCommandSignature.
    3. Re-lock MADE and re-check for the key before inserting, returning the existing entry if another thread created it concurrently.

Verification

  • Added multithreaded unit test draw::tests::command_signature_cache_creates_outside_lock using barriers to verify that an in-flight create callback does not block concurrent cache lookups on other threads.
  • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 224 passed; 0 failed; 6 ignored (note: an unpinned parallel run hit the pre-existing test-harness 0xc0000005 tracked in #850)
  • cargo build --release --locked -p victory
**@⁠n-romanovich** on GitHub · 2026-11-26 22:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/1393) `n-romanovich:perf/1370-unlock-command-signature` → `main` · +107 −64 · 1 files · 1 commits · open Addresses side finding 1 in #1370. ### Problem Both `host_spread_signature` and `host_signature` held their global `MADE` cache `Mutex` across `ID3D12Device::CreateCommandSignature`. During recording in `execute_indirect`, a slow driver `CreateCommandSignature` call (observed taking seconds on Intel Arc and causing `Mutex::lock_contended` stalls across worker threads) blocked every other recording thread from looking up even already-cached command signatures. ### Changes (`crates/victory-gpu/src/draw.rs`) - Extract a shared `cached_command_signature` helper and use it in both `host_spread_signature` and `host_signature`: 1. Lock `MADE` briefly for lookup and return immediately on cache hit. 2. Drop the lock before calling `ID3D12Device::CreateCommandSignature`. 3. Re-lock `MADE` and re-check for the key before inserting, returning the existing entry if another thread created it concurrently. ### Verification - Added multithreaded unit test `draw::tests::command_signature_cache_creates_outside_lock` using barriers to verify that an in-flight `create` callback does not block concurrent cache lookups on other threads. - `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: `224 passed; 0 failed; 6 ignored` (note: an unpinned parallel run hit the pre-existing test-harness `0xc0000005` tracked in #850) - `cargo build --release --locked -p victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:03:11 +00:00
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 22:58 UTC · original · edited 2026-11-26 23:43 UTC

The new cache helper can return None even after a concurrent caller publishes a valid signature for the same key. I ran a deterministic two-thread test on the helper from 0a7ee02. A starts creating and waits. B creates and publishes the same key. A resumes with None, and the early ? bypasses the recheck. The extracted original failed (A returned None); moving ? after the locked recheck passed (A returned B's result).

One small follow-up: hold the result of create() as an Option until after the second lookup, and add this interleaving to the existing test. The driver call still runs outside the lock. This was a CPU test of the helper, with the driver error simulated. PortBridge · AI-assisted review.

Update: UwUCammie's AMD backport uses the recheck before propagating an error. I ran the same two-thread test on the exact helper at 2936e0c; it passed. UwUCammie separately tested the backport under Wine. Pinned backport test return.

UwUCammie then added the ordered failure case as a regression and reported a pass under Wine 11.22.

**@⁠akimfomin** on GitHub · 2026-11-26 22:58 UTC · [original](https://github.com/fxceless/victory-fork/pull/1393#issuecomment-7205145118) · edited 2026-11-26 23:43 UTC The new cache helper can return `None` even after a concurrent caller publishes a valid signature for the same key. I ran a deterministic two-thread test on the [helper from `0a7ee02`](https://github.com/fxceless/victory-fork/blob/0a7ee02e8b2f3e27e7df5ef07c094f148d15a788/crates/victory-gpu/src/draw.rs#L4829-L4848). A starts creating and waits. B creates and publishes the same key. A resumes with `None`, and the early `?` bypasses the recheck. The extracted original failed (A returned `None`); moving `?` after the locked recheck passed (A returned B's result). One small follow-up: hold the result of `create()` as an Option until after the second lookup, and add this interleaving to the existing test. The driver call still runs outside the lock. This was a CPU test of the helper, with the driver error simulated. [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted review. Update: [UwUCammie's AMD backport](https://github.com/jtrudeau1530/VIctory-7900XTX/pull/27) uses the recheck before propagating an error. I ran the same two-thread test on the exact helper at `2936e0c`; it passed. UwUCammie separately tested the backport under Wine. [Pinned backport test return](https://github.com/jtrudeau1530/VIctory-7900XTX/pull/27#issuecomment-7205556913). UwUCammie then [added the ordered failure case as a regression and reported a pass under Wine 11.22](https://github.com/jtrudeau1530/VIctory-7900XTX/pull/27#issuecomment-7205708084).
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-26 23:19 UTC · original

I ported the single command-signature cache on linux-amd-best. The Windows MSVC regression passed under Wine 11.22. It checks that creation runs outside the mutex, that another caller’s published result wins, and that a failed creation can be retried. I haven't isolated CreateCommandSignature time in a RADV game profile. AMD backport

**@⁠UwUCammie** on GitHub · 2026-11-26 23:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/1393#issuecomment-7205439168) I ported the single command-signature cache on `linux-amd-best`. The Windows MSVC regression passed under Wine 11.22. It checks that creation runs outside the mutex, that another caller’s published result wins, and that a failed creation can be retried. I haven't isolated `CreateCommandSignature` time in a RADV game profile. [AMD backport](https://github.com/jtrudeau1530/VIctory-7900XTX/pull/27)
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/1393/head:github-bot/gh-1393'
git switch 'github-bot/gh-1393'

Merge

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