Repository navigation
d3d12: one compile job per pipeline at a time, so a released PSO is not deleted under its other build (RT-COMPILE-OWNER-RACE) - #2361
Conversation
…ot deleted under its other build PipelineCompiler runs a general worker and a graphics-only worker, and next_locked previously ignored Job::owner, allowing two jobs for the same graphics PSO to run concurrently. PipelineState::last_release calls after_running(owner, ...) to defer deletion, which attaches to the first Running entry of that owner; when that worker finishes, it can delete the PSO while the other worker is still building another variant on the same object. Skip queued jobs in next_locked when their owner already has an unfinished Running entry (for both workers), and call wake_.notify_all() in run() after erasing a finished job from running_ so held-back jobs can start. Add standalone CPU test d3d12_compile_owner_test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
left a comment
There was a problem hiding this comment.
MSVC/Windows 11: d3d12_compile_owner passed 10 consecutive runs. The suite covers same-owner graphics and compute serialization, pending work waking up, and different graphics owners still running concurrently. This checks the exact PR head. The open #2233 stack was outside these runs.
AI-assisted.
|
@qhukz13 thank you for finding this race and for fixing it on #2233's change for this (9b8760d) is the same owner check in the single-worker branch of AI-assisted (Claude Code) |
qhukz13 claimed and fixed the same race for main in ubiquitarianism#2361 (RT-COMPILE-OWNER-RACE). The single-worker branch of next_locked now uses their code line for line, so whichever of the two lands second merges trivially. The pool branch is as before 9b8760d. No behaviour change; d3d12_compile_pool_test passes 5 of 5 repeats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Closing as superseded by #2233, which landed on Thank you for catching the race and writing the fix and reproducer. If you want to add Case 4 (a non-graphics job waking after a same-owner graphics job on the graphics-only worker under AI-assisted review (Antigravity, Gemini 4 Neon). |
Claimed in the coordination issue as: RT-COMPILE-OWNER-RACE (#1608 (comment))
Conflicts with: #2233. It changes the same
next_locked; whichever lands second keeps the owner check in its single-worker branch.What and why
PipelineCompiler(runtime/shims/d3d12_pipeline_compile.h) runs a general worker and, by default, a graphics-only worker.next_lockedgives each worker a job without looking atJob::owner:jobs_.begin(), graphics jobs included;So two jobs of one PSO, for example two variants of one graphics pipeline, could be built at the same time, one on each worker.
If the title released that PSO meanwhile,
PipelineState::last_releasecalledafter_running(owner, [this] { delete this; ... }).after_runninghandslastto the first running job of that owner and returns. That worker deleted the PSO when its own build returned, while the other worker was still in a build of the same object, or waiting on itsvariants_mutex_. That is a use-after-free.The change
next_lockedskips a queued job whose owner has a running entry, for both workers. A running entry still counts after its job has finished, while it runs what comes after the job (the PSO's deletion). So one job per PSO runs at a time.wake_.notify_all()), because a job held back by the first point can run now.last_releaseruns, andafter_runningdrops it. Its deletion then runs after the only build of it.This is the rule #2233's pool already uses (
next_lockedthere skips a job whose owner has a running job). This PR applies it to the current two-worker scheme on main.Tested
Windows 10 Pro 19045, MSVC 14.44 RelWithDebInfo, on main
73516a290. No GPU needed, no game files.New
d3d12_compile_owner_test: CPU only, the realPipelineCompiler, four cases, every wait bounded.after_runningruns once, after it, with no job of that owner running. The queued second job is dropped.Passes, 4 repeats, and with
LEONIDA_VK_VALIDATION=1.d3d12_compile_teardown_testpasses beside it.It fails without the change:
next_lockedwake_.notify_all()tests/test_ctest_registration.pyandscripts/check_no_game_data.pypass on the changed files, andgit diff --checkis clean.GPUs tested: none needed (CPU-only test); host GTX 1050 Ti, Windows 10.
AI-assisted: yes. Antigravity (Gemini 4 Neon) wrote the first version of the change and the test; Claude Code reviewed it, tightened the owner check and ran the tests and mutants.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code