fix(gpu): serialize SetPipelineState against pipeline creation and library calls #3345

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

@⁠rdj415 on GitHub · 2026-12-03 14:58 UTC · original
rdj415:pr/pipeline-state-lock → main · +484 −105 · 19 files · 2 commits · open

Claimed in the coordination issue as: D3D12-PIPELINE-STATE-LOCK (#3312)

Fixes: #3327

What and why

Serializes ID3D12GraphicsCommandList::SetPipelineState (and external FrameGen passes: dlss::record, fsr::before_present, fsr::generate) against concurrent SetPipelineState calls and parallel Create*PipelineState / Load*Pipeline / StorePipeline / ffx.create work via a writer-preferring PipelineLock (LEONIDA_SERIAL_SET_PIPELINE, enabled unless 0). Prevents nvwgf2umx.dll concurrent pipeline-cache heap corruption (0xC0000374) without starving render threads behind background shader compiles, and regenerates d3d12/docs/switches.md.

Tested

  • python -I scripts/check_no_game_data.py (pass)
  • python -I tests/test_d3d12_switches.py (21 passed)
  • cargo clippy -p leonida-gpu -p leonida --all-targets --locked and --features diagnostics,mimalloc --locked
  • cargo test -p leonida-gpu --locked (720 passed, 59 ignored)
  • cargo test -p leonida-gpu --features diagnostics --locked --lib host::tests (73 passed, 1 ignored)
  • cargo test -p leonida-gpu --features diagnostics --test replay --locked (1 passed)

GPUs tested: NVIDIA GeForce RTX 5060 Ti 16 GB, driver 616.64, Windows 11 (runtime), plus WARP/DX12 test suite

AI-assisted: yes (implementation and independent read-only reviewer subagent audit)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
**@⁠rdj415** on GitHub · 2026-12-03 14:58 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3345) `rdj415:pr/pipeline-state-lock` → `main` · +484 −105 · 19 files · 2 commits · open Claimed in the coordination issue as: D3D12-PIPELINE-STATE-LOCK (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/3312) Fixes: #3327 ### What and why Serializes `ID3D12GraphicsCommandList::SetPipelineState` (and external FrameGen passes: `dlss::record`, `fsr::before_present`, `fsr::generate`) against concurrent `SetPipelineState` calls and parallel `Create*PipelineState` / `Load*Pipeline` / `StorePipeline` / `ffx.create` work via a writer-preferring `PipelineLock` (`LEONIDA_SERIAL_SET_PIPELINE`, enabled unless `0`). Prevents `nvwgf2umx.dll` concurrent pipeline-cache heap corruption (`0xC0000374`) without starving render threads behind background shader compiles, and regenerates `d3d12/docs/switches.md`. ### Tested - `python -I scripts/check_no_game_data.py` (pass) - `python -I tests/test_d3d12_switches.py` (21 passed) - `cargo clippy -p leonida-gpu -p leonida --all-targets --locked` and `--features diagnostics,mimalloc --locked` - `cargo test -p leonida-gpu --locked` (720 passed, 59 ignored) - `cargo test -p leonida-gpu --features diagnostics --locked --lib host::tests` (73 passed, 1 ignored) - `cargo test -p leonida-gpu --features diagnostics --test replay --locked` (1 passed) GPUs tested: NVIDIA GeForce RTX 5060 Ti 16 GB, driver 616.64, Windows 11 (runtime), plus WARP/DX12 test suite AI-assisted: yes (implementation and independent read-only reviewer subagent audit) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 15:00:07 +00:00
Author
Owner

@⁠merzleckeier on GitHub · 2026-12-03 15:01 UTC · original

I checked the lock tests at d4a8d3a7 with synthetic Rust threads. The current lock passes. Two test changes would make the regressions visible and keep CI from hanging.

  • In pipeline_lock_prefers_waiting_set_over_new_creates, spawning h_c2 does not prove that the second reader reached the lock before the first reader was released. I removed the pending-writer check in a local test fixture and confirmed that the test still passed when the second reader was scheduled after the writer. With a signal at the second reader’s first lock decision while the first reader is still held, the current lock passes and the no-priority variant fails.
  • In pipeline_lock_excludes_create_during_set_and_allows_parallel_creates, the barrier inside both readers hangs if a regression makes reads exclusive. A local exclusive-reader fixture reached the process timeout. A bounded channel wait inside the first reader would release the lock when the second reader fails to enter and turn this into an assertion failure.

AI-assisted with OpenAI Codex.

**@⁠merzleckeier** on GitHub · 2026-12-03 15:01 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3345#issuecomment-7382432872) I checked the lock tests at `d4a8d3a7` with synthetic Rust threads. The current lock passes. Two test changes would make the regressions visible and keep CI from hanging. - In `pipeline_lock_prefers_waiting_set_over_new_creates`, spawning `h_c2` does not prove that the second reader reached the lock before the first reader was released. I removed the pending-writer check in a local test fixture and confirmed that the test still passed when the second reader was scheduled after the writer. With a signal at the second reader’s first lock decision while the first reader is still held, the current lock passes and the no-priority variant fails. - In `pipeline_lock_excludes_create_during_set_and_allows_parallel_creates`, the barrier inside both readers hangs if a regression makes reads exclusive. A local exclusive-reader fixture reached the process timeout. A bounded channel wait inside the first reader would release the lock when the second reader fails to enter and turn this into an assertion failure. AI-assisted with OpenAI Codex.
Author
Owner

@⁠rdj415 on GitHub · 2026-12-03 15:07 UTC · original

Thanks for the sharp review! Addressed both test points in c5f911bb5: replaced Barrier::new(2) with a bounded mpsc::recv_timeout(2s) check so exclusive-read regressions fail instead of hanging, and gated h1 release on waiting_readers > 0 || create2_entered so create2 is verified to hit the lock decision while h1 is held.

**@⁠rdj415** on GitHub · 2026-12-03 15:07 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3345#issuecomment-7382609250) Thanks for the sharp review! Addressed both test points in c5f911bb5: replaced Barrier::new(2) with a bounded mpsc::recv_timeout(2s) check so exclusive-read regressions fail instead of hanging, and gated h1 release on waiting_readers > 0 || create2_entered so create2 is verified to hit the lock decision while h1 is held.
Author
Owner

@⁠merzleckeier on GitHub · 2026-12-03 15:12 UTC · original

Re-tested c5f911bb with the exact lock and its three synthetic concurrency tests. All three passed. An exclusive-read variant now fails with “second read() blocked while first read() was held” in two seconds. The writer-priority test passed 100/100 on this head and failed 100/100 with the pending_writers check removed. Both of my test findings are addressed. AI-assisted with OpenAI Codex.

**@⁠merzleckeier** on GitHub · 2026-12-03 15:12 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3345#issuecomment-7382737166) Re-tested `c5f911bb` with the exact lock and its three synthetic concurrency tests. All three passed. An exclusive-read variant now fails with “second read() blocked while first read() was held” in two seconds. The writer-priority test passed 100/100 on this head and failed 100/100 with the `pending_writers` check removed. Both of my test findings are addressed. AI-assisted with OpenAI Codex.
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/3345/head:github-bot/gh-3345'
git switch 'github-bot/gh-3345'

Merge

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