D3D12-GPU-REPLAY-WORKER-DROP-AND-PACE: close Worker event handle on drop and guard pace duration #2994
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
3 participants
Due date
No due date set.
Reference
leonida/mandy!2994
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/2994"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Addresses claim in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7327924046.
Changes
Verification
eplay::gpu::tests::worker_drop_closes_event_handle\ (exit 101); restoring \CloseHandle\ passes.
eplay::play::tests::pace_until_rejects_non_finite_and_overflowing_values\ (exit 101); guarded conversion passes.
AI-assisted: Gemini 4 Neon (including an independent read-only review pass, APPROVE).
All 26 replay unit tests passed on NVIDIA and RADV through Wine.
I built
fccce448on main002bd88f8, with #2975 and #2995 layered in. The replay source files match the isolated #2994 integration. A Windows MSVC-targetleonida-gpulibtest build with--features diagnosticsranreplay:: --nocapture --test-threads=1on the RTX 4070 SUPER (620.73.4) and Radeon Raphael (RADV 26.3.1). On both GPUs it passed 26/26, including the worker event-handle child on a live D3D12 device and the pacing boundary unit test. Environment: Wine 11.22, VKD3D-Proton 3.1.0, one Vulkan ICD visible per run.I separately built
--features diagnostics --test replayand ran--exact a_frame_is_recorded_and_replayedon both GPUs, using the same setup and a #2975-only build as control. Both trees on both GPUs hit the same Wine read fault after the synthetic scene was created under recording, before the new infinity playback step. All four integration runs exited 5. The paired control shows that this local Wine run stops at the same point without #2994. Synthetic capture only. MEASURED, AI-assisted with OpenAI Codex and independent raw-log verification.The unmodified a_frame_is_recorded_and_replayed integration test at fccce4485 passed on native Windows. It recorded the synthetic scene (3 submissions, 4 lists, 18 resources, 6 pipelines), completed the added player.run with pace=f64::INFINITY, and reached the final replay assertions. The reported final picture hash matched the recording, 4aaec8b6026567d0. One test passed in 1.42 s.
Command: cargo test --locked --profile diag --features diagnostics -p leonida-gpu --test replay -- --exact a_frame_is_recorded_and_replayed --nocapture
This supplies a native result for the integration path that stopped before playback in the Wine run. No game data used. Codex-assisted.
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
Ran natively on Windows 11, head
fccce4485merged into currentmain(2fc7383b9, clean merge). Below are handle counts for the Worker fix and timing for the pace change, each onmainand on the PR.Standard checks on the merge
cargo test --locked -p leonida-gpu --lib --features diagnostics -- replay::(WARP)cargo test --locked -p leonida-gpu --lib --features diagnostics(WARP)--features diagnostics --test replay -- --exact a_frame_is_recorded_and_replayedcargo clippy -p leonida-gpu --all-targets --features diagnostics -- -D warningsHandle counts (
GetProcessHandleCount, throwaway tests, not committed)The Worker rows use the crate's host device. The
Playerrows run insidea_frame_is_recorded_and_replayedon the recorded synthetic capture, which always uses the default hardware adapter. Each loop ran after one warm-up.maindeltaWorker::new+ drop, x1000Worker::new+ drop, x1000run+idle+ drop, x200send(no wait) + drop, x200player.run(&plain), x20Player::load+ drop, x20The +1 to +3 left in the run/idle row appears on both sides, so it is noise.
By handle type, 30
Player::load+ drop cycles onmainleft 120 Event, 30 Mutant and 30 Section handles. On the PR they left 30 Mutant and 30 Section. So each load leaked four events (four Workers per load for this capture), and the PR removes all four. The remaining +2 per load is not from Worker and I did not trace its source. Creating and releasing a DXGI factory, adapter and device in a loop adds 0, while creating and releasing a bareID3D12CommandQueueadds +2 per cycle by count. So it may come from queue creation inPlayer::load, but I did not check the type of those handles.Double close / use after close
Dropis the onlyCloseHandlesite forWorker::event,Workeris notClone, andDropclears the field after closing it.Player::uploadusesstd::mem::replaceto swap Workers. I reproduced that pattern 300 times: each pass created a temporary Worker, swapped it in, sent work on the original, swapped back, and dropped the temporary. It finished without error, and no delta went negative.waitregistersSetEventOnCompletionand then blocks inWaitForSingleObjecton the same thread. BecauseWorkerisSendbut notSync, it cannot be dropped while another thread is waiting on it, and no fence registration is left pending at drop.Pace
For finite positive values,
pace_untilgives exactly the sameInstantas the oldInstant::now() + Duration::from_secs_f64(pace / 1e3). I checked 90 values from 1e-9 to 8e9 ms. Timing ofplayer.runon the synthetic capture, hardware adapter, median of 11 runs after one warm-up, both sides run back to back on an otherwise quiet machine:pace(ms)mainmedian (ms)time.rs,from_secs_f64)Both sides add about 12.5 ms of run time per 1 ms of pace, so pacing of valid values is unchanged. The gaps between the two columns are run-to-run noise: an earlier pair of runs on a loaded machine had the PR slower at pace 20. The only behaviour change is that inf and overflowing values now run unpaced instead of panicking. NaN never panicked on
main, becauseNaN > 0.0is false, so the old code already skipped it. The PR description lists NaN among the panics it prevents. A large finite value is still accepted:pace_until(now, 1e15)returns a 1e12 s deadline, which spins in practice forever, as onmain.CI coverage
replayis compiled only withdiagnostics. CI runscargo test --workspacewithout that feature, and its only diagnostics step is--test replay. Soworker_drop_closes_event_handleandpace_until_rejects_non_finite_and_overflowing_valuesdo not run in CI, the same as the otherreplay::unit tests. Thepace: f64::INFINITYline added to the integration test does run in CI.Not checked: an in-game run (the gate MoonEyes asked for), recording through
Capture(thesnap.rsWorkers), and the debug layer.GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
RUN (in game, batch of five render-path pull requests), each head merged with
git merge --no-ffonto main3c106eb2f, in one build: #2993ddc10507d, #2889bc390c26f, #2851cf8f7be78, #298012c14a999, #2994fccce4485. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.For reference, the same machine and route rendered 13.3 to 16.7 fps today on main with single pull requests or other batches. These fps are a check that nothing fell over, not a measurement of a gain.
Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; free system memory median 2.5 GB; arrival in the world was driven by keys and not checked on pictures.
AI-assisted (Claude Code).
Verification of #2994 (third party, code review on Linux; not built: Windows-only
leonida-gpu)fccce4485ef385508135837bd45a1127d17a2148(3 files, +74/-4).66c79286f.git merge-tree --write-tree origin/main pr/2994againstmain45dc41f95is clean.CI on the head: 6/6 success.
python -I scripts/check_no_game_data.pyon the 3 files: exit 0.3c106eb2fincludesfccce4485(PASS, no device loss).Review
replay/gpu.rs:26-34Drop for Workercloses the event made inWorker::new.Workeris neitherClonenor
Copy, andeventis only used inwait(gpu.rs:88-89), which waitsINFINITEright afterSetEventOnCompletion. No registration outlives a drop, so there is no double close and no late signal.replay/play.rs:3504-3510pace_until: onmain,Duration::from_secs_f64(o.pace / 1e3)panics for NaN,infinity or overflow. The new function returns
Nonefor non-finite, zero, negative and overflowing values.This is the right guard. The unit test (
play.rs:3558-3568) covers each case. The integration test runsplayer.runwithpace: f64::INFINITY(tests/replay.rs:1810-1814), which panics onmain's code, so thatis a real red.
worker_drop_closes_event_handle(gpu.rs:480-513) returns without asserting whenhost()isNone, in both parent and child, and prints nothing. On a machine with no device it passessilently. Print a skip line, as the crate's other device tests do.
shown::saver. OneOwnedEventhelper would serve both. Not blocking.
Process
Verdict: ready (not built here). There are two small nits (silent skip, duplication) and the model names
are missing from the body.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@MoonEyes Thank you for the review, and thank you
@Kal0s-design,@andrew-ai, and@merzleckeierfor the independent handle-count, native replay, and Wine verifications.Gemini 4 Neonand the independent review pass.fccce4485untouched so@MoonEyes's16:10:24Zin-game batch PASS remains valid; the non-blocking nits (printing on child skip and deduplicatingEventHandlewith#2980/#3003) can be cleaned up in a follow-up once these land.AI-assisted: Gemini 4 Neon
VERIFY-2994 — cherry-pick limpio y 715/1: no añade ningún test numerado, y eso es lo que quiero señalar
715 es exactamente el número de
main, y el 1 es la falla de la iGPU — o sea que el cambio no añade ningún test.Y el título dice que cierra un
Workeren sudrop— la misma clase de arreglo que#3003(elEventHandle), que revisé hace un rato. Dos PRs distintos, dos handles distintos, y en los dos el patrón es el mismo: un objeto que envuelve unHANDLEy no lo cierra. Si los dos entran,shown.rsy este tendrán el mismoDropescrito dos veces — y la tercera vez será copiar y pegar otra vez. UnOwnedHandlecompartido en el crate es lo que falta, y ninguno de los dos PRs lo propone porque cada autor estaba mirando su fichero.Lo que verifiqué y lo que no: que aplica limpio y no rompe los 715, y que no trae test nuevo — la primera mitad es buena, la segunda es lo que le falta. La guarda de
ppque menciona el título (guard p…) es justo lo que un test puede ejercitar sin el título, a diferencia delDropde un handle, que necesita un proceso (como demostró#3003).Así que le pediría lo mismo que a
#3003: una prueba que corra en CI de lo que se pueda probar, y una línea diciendo qué no se puede.The unchanged
fccce4485adds two unit tests:worker_drop_closes_event_handleandpace_until_rejects_non_finite_and_overflowing_values.cargo test -p leonida-gpu --libwithoutdiagnosticsleaves the entire replay module out, which explains the unchanged count in the latest run.I checked the hosted Windows job for this head. Its diagnostic step selected
--test replayand reporteda_frame_is_recorded_and_replayedas passed. That binary contains the new infinite-pace case. The step does not select either unit test, and the integration test can return early when there is no adapter. The loggedokalone does not establish that it reached the new case.On Linux I compiled the exact
pace_untilfunction and unit test from the merged tree. The test passes, and it fails at the duration conversion with the old implementation. A CI follow-up can addcargo test -p leonida-gpu --features diagnostics --lib --locked -- replay::alongside the existing integration step. This would select the pacing unit test even when the device-dependent tests skip. AI-assisted with OpenAI Codex.Bundle gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): #2994
73db06099, #29805c2ecc541, #2896baca58934and #28921d3e1a1b5(the current heads) merged together intomain04a838fc4without conflict, diag profile withdiagnostics,dlss,mimalloc, msvc target. These four were judged to have no effect on the picture, so they share one run. Reference:main04a838fc4built the same way, run the same day with the same frame-timing capture on. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.main(-0.65, inside the run-to-run spread of this recipe); median frame 29.22 ms (+0.5), p99 48.1 against 48.9 ms. No frame over 100 ms.Verdict: PASS, no cost, for the four PRs together.
GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).
a9361504ainto #2994 (tree tested by local CI) 1f1d751561Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it, and it is part of enlighted's G2 pack, which passed a 300 s run on an RTX 3090: no cost, 0 lost, 0 crash, 0 ERROR.
Local CI (normal mode) on head
73db06099merged into maina9361504a: PASS.make_game.py --help.leonida,leonida-gpu,leonida-hle) 162 s; Rust replay test 91 s; Clippy-D warnings49 s.The forge refused the merge while the head was behind main.
main(a9361504a) was then merged into the head as1f1d75156, which has the same tree the CI tested. Merged ase274c903f.