d3d12-gpu: LEONIDA_ALIAS_LATER mappings wait for what their queue had before them (D3D12-ALIAS-LATER-QUEUE-ORDER) #3352
Open
github-bot
wants to merge 2 commits from
github-bot/gh-3352 into main
AGit
pull from: github-bot/gh-3352
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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!3352
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3352"
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?
@MoonEyes on GitHub · 2026-12-03 15:31 UTC · original
ProjectLeonida:fix/alias-later-queued-submissions→main· +161 −47 · 2 files · 2 commits · draftClaimed in the coordination issue as: D3D12-ALIAS-LATER-QUEUE-ORDER (#3312)
Fixes: #3329
What and why
alias_laterput the mapping work on theleonida-aliasthread, which ran it at once. OnlyJob::Aliasheld back the jobs after it in its lane, not the ones before it, so an older submission blocked on a wait could read pages already remapped.The mapping work now stays queued in the title's order. Each entry has its own release flag:
met(Ask::Alias)releases a queue head's entry only, so a mapping behind an unfinished wait in another queue is not let go when a later one reaches the head of its own. The worker (or the lane, with no thread) takes only the front entry, and only when released. The forced path (a present, viaalias_wait) raisesforcedand releases up to that number, so the line cannot stay stuck at a present. The unreachableAsk::Aliasarm ofsettleis removed.Tested
queue/behind.rs:a_mapping_waits_for_what_its_queue_had_before_itanda_mapping_does_not_let_go_an_older_one_of_another_queue(waits go through alook_untilhelper with a 10 s bound; a static mutex serializes tests sharing the process-wide alias state).leonida-gpudoes not build on Linux. The mapping section (alias_queue, alias_release, alias_next, alias_do, alias_wait) was compiled alone with stubs and its two-mapping scenario passes; theJob/Laneintegration and both tests were only read. No red/green was executed: please runpython -I scripts/red_green.py <PR>andcargo test -p leonida-gpu --lockedon Windows (CI will compile it).python -I scripts/check_no_game_data.pypasses.Known risks (opt-in switch only)
[Wait(f), Alias(k)]with Q2[Alias(k+1), ..., Signal f]: the worker cannot finish k+1 before k, and k waits for the signal. Only a present unblocks it (not withLEONIDA_WAIT_FORCE=0). The old eager worker did not have this case. To confirm on Windows with a title run.alias_lateron the same queue could order Alias(n+1) before Alias(k): unlikely, as calls on one queue are normally serialized.GPUs tested: n/a
AI-assisted: yes (Claude Code, reviewed by a separate read-only reviewer agent)
Checklist
mainand merges cleanly.docs/design.md: n/aGenerated by Claude Code
@Kal0s-design on GitHub · 2026-12-03 16:10 UTC · original
Ran natively on Windows 11, head
309f2abf0merged into currentmain(9b9efd5cd, clean merge).It compiles. Both new tests are red on
mainand green on the merge, and the fullleonida-gpusuite has no new failures. There is one clippy error. I also measured the risks you listed and the cost of doing the mappings in ask order across queues (details below).Your asks (measured)
cargo test -p leonida-gpu --lib --lockedbuild (lib + tests)main: 723 passed, 0 failed, 59 ignored. The 2 extra are the new testscargo clippy -p leonida-gpu --all-targets -- -D warningsmain:clippy::single_matchinJob::settle(behind.rs:534). Removing theAsk::Aliasarm left a one-armmatch.if let Ask::Lists(recordings) = ask { ... }fixes it. With that lint allowed, nothing else comes up. CI runs clippy as a report only, so it won't blockcargo fmt --checkmaineither, and CI doesn't check it.behind.rsgets 6 more rustfmt hunks than onmain, all long lines in the PR's code, the same style as the rest of the file.queue.rshas no new onespython -I scripts/red_green.pycannot find function alias_queue. The tests callalias_queue, which the PR adds outside#[cfg(test)], so the test-only red side can't compile. On green, all 784 tests ran: 725 passed, 59 ignored, none failedRed/green done by hand. I put the two tests on
main'sbehind.rswith a test-onlyalias_queue. It ismain'salias_laterminus theLANE.push: it numbers the work, hands it to the worker and notifies it.main+ shim, 10 runsa_mapping_waits_for_what_its_queue_had_before_ita_mapping_does_not_let_go_an_older_one_of_another_queueThe whole
queue::behindmodule, 4 threads: 20/20 on the merge. No flakes seen. From reading the code: the alias line is process-global and the worker only takes the front entry. If one test fails with its entry still queued, later mappings in that process stand behind it, so the other test would time out after its 10 s too.Known risks, measured. These are throwaway tests with
Lane<Job>, real fences andJob::Present(None, None, ..)(withLEONIDA_PASSES_AHEAD=0). Each ran in a process of its own with a 5 s bound. "stuck" means nothing moved in 5 s.mainLEONIDA_WAIT_FORCE=0[Wait(f), Alias(k)], Q2[Alias(k+1), Signal(f)], no present[Wait(f), Alias(k)], Q2[Alias(k+1)], no cycle, f set by another thread at 300 ms[Alias(k+1)]oldest, Q1[Wait(f), Alias(k)], presentAlias(k+1)put in beforeAlias(k)(your third risk), no presentmaintakes about the same 250 ms as the merge in the rows with a present, so that time isn't from the PR.So the cycle is real. It holds until a present is in the line, and with
LEONIDA_WAIT_FORCE=0it never clears. From readingstep, what clears it in the cycle row is the line forcing Q1'sWaitat the present, which makesAlias(k)a head. It is not theforcedcounter. Only the fourth row reaches that counter, throughalias_wait.The third row is the cost of the ask order, which the PR intends (the
alias_laterdoc and the second test). Q2's mapping waits for Q1's fence even though nothing in Q2 depends on it: 302 ms against 0 ms onmain. With the default switches that holds Q2's later submissions until a present is in the line. Because the line is global, one entry stuck at a wait holds every later mapping of every queue. Is the cross-queue order needed? Doing released entries in release order, and keeping ask order only within a queue, would remove rows 1 and 3. It would also reverse whata_mapping_does_not_let_go_an_older_one_of_another_queueasserts, so it depends on why you wanted that order.Read, not run. No lost wakeups that I can see.
alias_nextchecks its predicate in a loop under theALIASmutex,alias_releasechanges the state under the same mutex before it notifies, andalias_waitloops onALIAS_DONEwith a 2 ms timeout. The lane's thread polls every 1 ms while it holds entries, so a missedLANE.wake()costs at most that.forcedis only raised withmaxunder the mutex and read under it. It's au64, so overflow isn't a concern.met(Ask::Alias)now has a side effect. That looks fine:stepcalls it only for a queue's head, andtake_alongnever takes anAlias. The removedsettlearm was unreachable, becausedrainsettles only folded entries (Lists).If
spawnfails once and works on a lateralias_queue, the lane thread's inline loop and the new worker can each pop an entry and run them at the same time.ALIAS_DONE.store(number)could then go backwards. That's unlikely, andfetch_maxwould close it.Shutdown: the worker is never joined, as on
main. Mappings still queued at exit are dropped, wheremainwould already have run them.drainonly waits for what is free to run, so it returns past a stuck alias. Outsidebehind.rs, the only users of the alias line arecopy_page_mappingsandalias_behindinqueue.rs. On a device losshost::failends the process (crash report orabort), so nothing drains the alias line there.Conflicts. Five other open PRs touch
queue.rs. #3039 also touchesbehind.rs: it adds timing aroundalias_waitingo. All five auto-merge on these two files on top of this merge. #3176, #3039 and #2958 already conflict withmainin files this PR doesn't touch (d3d12.yml,switches.md,play-nvidia.ps1,test_win_launchers.py). #3151 and #2833 merge cleanly. #2833 boundscopy_page_mappings, the caller ofalias_later. This PR adds no conflicts.Not checked: the title, so no visible effect either way. Whether the title reaches a present at all while it is in the cycle. If it waits for that fence on the CPU first, the default-switch case is a hang, not a hitch. The same-queue inversion with a present. Whether a submission's title-memory reads all happen inside its
go: I readsend_lateas far assubmit_forbut didn't trace the relay thread. The forced path with more than two queues.--release. Thediagnosticsfeature.GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).
@x2Tweek on GitHub · 2026-12-03 16:17 UTC · original · reviewed
Review of #3352 (claimed in #3312 as REVIEW-3352). I reported #3329.
Windows build and tests (PR merged onto current main, d0dc89ef9):
cargo test -p leonida-gpu --features diagnostics --locked: 806 passed, 0 failed. Both new tests pass.python -I scripts/red_green.py 3352 --remote upstream --crate leonida-gpu: verdict "red does not build". The new tests callalias_queue, which does not exist on main, so the red side does not show that they catch the old eager behaviour.Code review (with a second, read-only reviewer):
LEONIDA_ALIAS_LATERis on by default, not opt-in.queue.rs:1607usescrate::toggled!, so it is on unless set to0, whenever the submission line is on. The "Known risks (opt-in switch only)" section therefore applies to every player.queue/behind.rs:344-364,:940-950). This is the case listed under known risks: Q1[Wait(f), Alias(k)]and Q2[Alias(k+1), ..., Signal(f)]. The worker will not pass the unreleasedk, so Q2 never reachesSignal(f). WithLEONIDA_WAIT_FORCE=0it is a real deadlock. With forcing, only a present gets it moving again: a hitch, and the wait is dropped. Graphics plus async compute can plausibly interleave like this. Suggested fix: one FIFO per queue, or run any released queue head, with completion tracked per entry.alias_waitreleases every lower ticket. Tickets are handed out and lane entries are inserted in separate critical sections, so two concurrent calls can publish them in reverse order, and forcing can release a mapping that its own queue has not reached yet. Suggested fix: take the ticket and the lane slot under one lock, and force only the selected entry. Related path: the unaligned mapper fallback (leonida-hle/src/modules/xmem.rs:1632-1640) callsmap_aliasessynchronously, before its lane entry exists.queue/behind.rs:907-935,:953-973). After a spawn failure the lane can run a mapping inline while a later enqueue starts the worker. The worker then publishes a higherALIAS_DONE, which the inline completion overwrites with a lower value. Suggested fix: keep a single executor.LEONIDA_WAIT_FORCE=0, signalled through the lane, and replace the 50 ms sleeps with synchronization so that the eager-worker failure is deterministic.No lock inversion or missed wakeup found on the ordinary worker path.
I have not run it with the title yet. I can do an in-game run (RTX 5090, HW RT, walk + camera) comparing PR and main for hitches if that helps.
AI-assisted: yes (Claude Code + Codex, read-only)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.