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

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "github-pr/3345:github-pr/3345"
git switch "github-pr/3345"
Open
leonida/mandy
rdj415 wants to merge 2 commits from github-pr/3345 into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
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 'github-pr/3345:github-pr/3345'
git switch 'github-pr/3345'
rdj415 commented 2026-12-03 14:58:45 +00:00

Claimed in the coordination issue as: D3D12-PIPELINE-STATE-LOCK (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7382304892)

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.
Claimed in the coordination issue as: D3D12-PIPELINE-STATE-LOCK (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7382304892) 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.
merzleckeier commented 2026-12-03 15:01:30 +00:00

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.

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.
rdj415 commented 2026-12-03 15:07:42 +00:00

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.

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.
merzleckeier commented 2026-12-03 15:12:08 +00:00

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.

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.
Sign in to join this conversation.
No description provided.