d3d12: write the pipeline book before a GPU failure or the title's end terminates the process (D3D12-PIPELINE-BOOK-FLUSH-ON-GPU-FAILURE) #3146
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3146"
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?
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T13:57:49Z.
Claimed in the coordination issue as: D3D12-PIPELINE-BOOK-FLUSH-ON-GPU-FAILURE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7278399665, status update https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7278452388)
What and why
The pipeline book (
LEONIDA_PIPELINE_BOOK=1,d3d12/crates/leonida-gpu/src/pipeline/known.rs) is written only by its own thread, which wakes every two seconds. Two places end the process without waiting for it:host_gpu_failedind3d12/crates/leonida-hle/src/modules/d3d12x.rslogs the failure and callsTerminateProcessat once. The pipelines noted in the last seconds before a device loss are lost, and those are the ones the next run needs most.end()ind3d12/crates/leonida-hle/src/modules/lifecycle.rssaves the pipeline cache and then terminates, again leaving the book to its two-second timer.The change: the book's thread now also takes requests (a small
writermodule inknown.rs).known::flush_on_gpu_failure()asks it to write and waits 250 ms at most;known::flush_on_exit()does the same with a 2 s limit. The calling thread takes no lock of the book itself, since a failing thread may hold one the write needs, so a stalled write can't keep the process from ending. The writer starts with the book itself, so withoutLEONIDA_PIPELINE_BOOK(or before the book is first used) both calls do nothing.It only touches the writer thread of the book (RT-GRAPHICS-PIPELINE-BOOK), not what the book records. #2957 also edits
known.rs(other lines); whichever lands second needs a trivial rebase.This ports Yoshi-233's fix from the sibling VIctory tree (TaynanGT/Vice-Tay
33439c8, GPL-3.0, suggested by sharan104), credited as co-author.Tested
pipeline::known::writer::tests::a_request_returns_after_the_writer_wrote(a request returns only after the write ran) anda_stalled_write_does_not_hold_the_failing_thread(a write that never finishes still lets the request return after its timeout).mainhas no request path, so there is no red side for these. Onmain(09fbadec8) neitherhost_gpu_failednorend()reaches the book at all.main;cargo test -p leonida-gpu --lib: 693 passed, 0 failed, 59 ignored.cargo test -p leonida-hle --lib: 248 passed, 0 failed, 2 ignored.cargo clippy -p leonida-gpu -p leonida-hle --lib --tests: no warning in the changed files.GPUs tested: n/a (CPU unit tests)
AI-assisted: yes
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
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T14:17:43Z.
Review: COMMENTED
Independent CPU-only test of
c98f12833on current main69cd4106c. I compiled the exactwritermodule andflushfunction from the merged source with a small synthetic book in a temporary directory on Linux. Both stock writer tests passed. A third check staged bytes for both files and verified the explicit exit request and the two-second periodic write each appended both batches as expected.One detail worth making explicit in the new request contract: the acknowledgement means the write attempt returned. I made the pipeline output path a directory in the same fixture. The request completed after the attempted append, the in-memory batch was drained, and removing the obstacle and requesting another flush did not recover that batch. This behavior comes from the existing
flushimplementation (identical on main); the new request adds a bounded wait around it. Describing the request as best-effort would make that limit clear to readers. Synthetic files only. AI-assisted with OpenAI Codex.Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T14:33:54Z.
Thanks, agreed. The batch is taken out of the book before the write, so a failed append drops it, on
mainas well.ebc0253ffnow says so in the doc comments:flush_on_gpu_failureis best effort, and the writer's answer means the write was tried, not that it succeeded. Comments only;pipeline::knowntests pass (4/4).AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T14:55:33Z.
Verified PR #3146 (
ebc0253ff) merged cleanly ontomain(acc350745) on Windows 10 x64 (Rust 1.98.1):python -I scripts/check_no_game_data.pyPASS.cargo test -p leonida-gpu --features diagnostics --lib --locked pipeline::known::-- 4 passed, 0 failed (includinga_request_returns_after_the_writer_wroteanda_stalled_write_does_not_hold_the_failing_thread).cargo test -p leonida-hle --lib --locked-- 248 passed, 0 failed, 2 ignored.250 msonhost_gpu_failed,2 sonlifecycle::end),OnceLock<Writer>avoids spawning a second thread, and the updated doc comments accurately state that the flush acknowledgement is best-effort. Note for maintainers: #3151 also toucheshost_gpu_failedind3d12/crates/leonida-hle/src/modules/d3d12x.rs, so whichever merges second will have a small 2-line merge ind3d12x.rs.Verdict: PASS (CPU/unit tests only; no game launch).
AI-assisted: yes (Antigravity).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T16:19:24Z.
Verified here: the change applies and its tests pass, including the two new ones about the writer.
The two
writertests are the ones this pull request exists for, and they say what matters: a request returns once the writer wrote, and a stalled write does not hold the failing thread - the second is precisely the property that makes this work on the path whereTerminateProcessfollows.And this is the pull request I would merge for a reason outside itself: the book is only written by its own thread at the end, so a run that ends with a GPU failure loses it - and a run of this title has a GPU timeout in it. A real log from this week (RTX 4090, driver 621.24,
-SeriesX -Resolution 1440) shows frame times flat at 35.7 ms until 22:03:50, then three and a half minutes of medians between 145 and 1,899 ms - a device timeout, after which the log notes the recovery. On that path the book was not written, and the next run pays for it again. That is exactly what this changes.What I did not test: an actual GPU failure. That needs the title and a timeout induced on purpose, and this machine cannot run it; the writer's tests are the closest thing, and they pass.
One detail for the merge: the branch's merge base is
128648cfe, so it is some way behindmain- a rebase before merging is worth it.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:13:52Z.
Read against current
main; not built here (leonida-gpu/leonida-hleare Windows-only). The head is unchanged since lixonik's (14:55) and fiestorra's (16:19) green Windows runs, and it still merges cleanly.python -I tests/test_d3d12_switches.pypython -I scripts/check_no_game_data.pyon the 3 filesRead in the diff
known.rs: the two-second sleep loop becomes aWriterthread that waits onrecv_timeout(2 s), so a flush request is served at once and the periodic write stays the same.request_flushwaits with a bound (250 ms on a GPU failure, 2 s at the title's end), and the failing thread takes no lock itself. That is the right shape for a call made just beforeTerminateProcess.lifecycle.rsflushes aftersave_pipeline_cache()and beforeTerminateProcess(…, 0).d3d12x.rsflushes afterlog_crash.Note (not blocking):
flush()appends shaders and then pipelines with plainwrite_all. If the 250 ms bound passes while a write is in progress,TerminateProcesscan cut the append short, which is the same risk the periodic writer already has onmain. If the book's reader does not yet tolerate a truncated last record, that is worth a follow-up, since this PR makes writes right before termination more likely.Verdict: ready.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T18:35:40Z.
Thanks for the review. On the note about a cut-short append: the reader already handles it, and this PR is where that was added (head
ebc0253ff,known.rs).book()walks both files, andwalk_shaders/walk_pipelinesstop at the last whole record and return its end. If the file is longer than that, it is cut back to that end withset_len(end)before anything new is appended. So a torn record from a run killed mid-append is dropped once, and the next append starts on a record boundary.a_torn_end_is_not_readcovers it: three pipeline records with the last 5 bytes cut off read back as 2 records (48 bytes), and a shader file with a partial second record reads back as the first record only.So the worst case after
TerminateProcesscuts the flush short is losing the record being written, not the book.AI-assisted: yes (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-02T21:01:24Z.
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
ebc0253ff944ca9dab30a41b7f1a5ef6a519448f.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; workspace test targets compiled).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,scripts/game-gate.ps1(301.3 sin world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (GATE CONTROL moved=2.51 m,max_from_ctrl=5,053.9 m).c47eeb717f761d9d)mainb41763227baseline (cf499737bf684f6a)clean,0reasons,0warnings)clean,0reasons,0warnings)301.3 s(4,504frames)305.6 s0/0/00/0/020.10 FPS/69.76 ms19.13 FPS/74.01 mscache_saved0x00000000/true0x00000000/trueVerdict: PASS for the 300 s in-game stability gate on
ebc0253ff. (Confirms normal run + clean title shutdown withcache_saved = true; does not simulate a GPU device-loss path.)(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T23:55:45Z.
VERIFY-3146 — Windows nativo: documentación, y la documentación es correcta
ebc0253ff—pipeline/known.rs, docs only (6 insertions, 3 deletions of///and//!)Ran at the head
There is nothing to make red — no behaviour changes — so the only verification worth doing is whether the sentences are true. They are:
The claim: "Best effort: it returns once the write was tried, and a write that fails drops what it was writing, as the periodic write does." The code (
known.rs:179):recv_timeout's result is thrown away — so on a timeout, or a writer that failed, the caller cannot tell, exactly as the doc now says. Andflush_on_gpu_failurewaits 250 ms whileflush_on_exitwaits 2 s, which the surrounding docs point at.Why this kind of change is worth a review rather than a shrug: the old text implied a flush that happened, and every caller of
flush_on_gpu_failure()now reads a sentence that says it may not have. A doc line that under-promises is how the next person stops treating a timeout as success — and the fact that the previous text was also describing this code is the reason nobody had noticed.What I could not test: the writer thread against a real failure (a failing write is what the sentence is about), and no title.
Written with an AI assistant.