d3d12-gpu: LEONIDA_ALIAS_LATER mappings wait for what their queue had before them (D3D12-ALIAS-LATER-QUEUE-ORDER) #3352
Open
MoonEyes wants to merge 2 commits from
upstream-pr/3352 into main
pull from: upstream-pr/3352
merge into: ProjectLeonida:main
ProjectLeonida:main
ProjectLeonida:claude/loop-total
ProjectLeonida:claude/pops-collision-seed
ProjectLeonida:claude/dstorage-hold-page-reads
ProjectLeonida:claude/host-image-copy-switch
ProjectLeonida:feat/gdk-lifecycle-window-hook
ProjectLeonida:claude/d16s8-uav-nvidia-fallback
ProjectLeonida:feat/mfplat-offline-shim
ProjectLeonida:claude/gameinput-slow-reader
ProjectLeonida:fix/rt-null-barrier-clear
ProjectLeonida:claude/depth-resolve-sample-positions
ProjectLeonida:integration/palmetto-parity
ProjectLeonida:claude/valu-literal-sext
ProjectLeonida:claude/slot74-pool-handle
ProjectLeonida:claude/rgb9e5-uint-alias-view
ProjectLeonida:claude/fssm-root-layout-tables
ProjectLeonida:feat/gdk-speech-display-lifecycle
ProjectLeonida:asset-audio-skip-current
ProjectLeonida:qemmhd/old-9940-rectangle-quad-lists
ProjectLeonida:feat/ws2-offline-shim
ProjectLeonida:qemmhd/rt-d16-unorm-uav
ProjectLeonida:feat/xs-device-stops-7-9
ProjectLeonida:qemmhd/rt-depth-same-base-shapes
ProjectLeonida:qemmhd/rt-lazy-attachment-variant
ProjectLeonida:feat/acphal-xma2-decoder
ProjectLeonida:asset-audio-skip
ProjectLeonida:codex/coord-claim-check-20261124-7e48
ProjectLeonida:feat/xs-frame-pacing-presentx
ProjectLeonida:feat/xs-device-vm-options
ProjectLeonida:old-pr/9844
ProjectLeonida:old-pr/9978
ProjectLeonida:old-pr/9815
ProjectLeonida:old-pr/10057
ProjectLeonida:old-pr/9874
ProjectLeonida:old-pr/9965
ProjectLeonida:old-pr/9863
ProjectLeonida:old-pr/10068
ProjectLeonida:old-pr/10066
ProjectLeonida:old-pr/10067
ProjectLeonida:old-pr/10007
ProjectLeonida:old-pr/10061
ProjectLeonida:old-pr/10065
ProjectLeonida:old-pr/10059
ProjectLeonida:old-pr/10063
ProjectLeonida:old-pr/10055
ProjectLeonida:old-pr/10062
ProjectLeonida:old-pr/10042
ProjectLeonida:old-pr/10041
ProjectLeonida:old-pr/10049
ProjectLeonida:old-pr/10047
ProjectLeonida:old-pr/10046
ProjectLeonida:old-pr/10045
ProjectLeonida:old-pr/10056
ProjectLeonida:old-pr/10043
ProjectLeonida:old-pr/10036
ProjectLeonida:old-pr/10034
ProjectLeonida:old-pr/9984
ProjectLeonida:old-pr/10052
ProjectLeonida:old-pr/10038
ProjectLeonida:old-pr/10033
ProjectLeonida:old-pr/10028
ProjectLeonida:old-pr/10050
ProjectLeonida:old-pr/9891
ProjectLeonida:old-pr/9889
ProjectLeonida:old-pr/10051
ProjectLeonida:old-pr/10019
ProjectLeonida:old-pr/10027
ProjectLeonida:old-pr/10029
ProjectLeonida:old-pr/10031
ProjectLeonida:old-pr/10026
ProjectLeonida:old-pr/9941
ProjectLeonida:old-pr/10030
ProjectLeonida:old-pr/10040
ProjectLeonida:old-pr/9990
ProjectLeonida:old-pr/10021
ProjectLeonida:old-pr/9962
ProjectLeonida:old-pr/10022
ProjectLeonida:old-pr/10020
ProjectLeonida:old-pr/10015
ProjectLeonida:old-pr/10025
ProjectLeonida:old-pr/9886
ProjectLeonida:old-pr/10048
ProjectLeonida:old-pr/10014
ProjectLeonida:old-pr/10011
ProjectLeonida:old-pr/9861
ProjectLeonida:old-pr/10010
ProjectLeonida:old-pr/10008
ProjectLeonida:old-pr/9860
ProjectLeonida:old-pr/10006
ProjectLeonida:old-pr/9920
ProjectLeonida:old-pr/9995
ProjectLeonida:old-pr/10000
ProjectLeonida:old-pr/10016
ProjectLeonida:old-pr/10004
ProjectLeonida:old-pr/10023
ProjectLeonida:old-pr/9982
ProjectLeonida:old-pr/9981
ProjectLeonida:old-pr/9983
ProjectLeonida:old-pr/9970
ProjectLeonida:old-pr/9969
ProjectLeonida:old-pr/9968
ProjectLeonida:old-pr/9971
ProjectLeonida:old-pr/9972
ProjectLeonida:old-pr/9942
ProjectLeonida:old-pr/9963
ProjectLeonida:old-pr/9960
ProjectLeonida:old-pr/9964
ProjectLeonida:old-pr/9985
ProjectLeonida:old-pr/9973
ProjectLeonida:old-pr/9862
ProjectLeonida:old-pr/9953
ProjectLeonida:old-pr/10017
ProjectLeonida:old-pr/9952
ProjectLeonida:old-pr/9955
ProjectLeonida:old-pr/9946
ProjectLeonida:old-pr/9954
ProjectLeonida:old-pr/9938
ProjectLeonida:old-pr/9956
ProjectLeonida:old-pr/9856
ProjectLeonida:old-pr/9947
ProjectLeonida:old-pr/9924
ProjectLeonida:old-pr/9961
ProjectLeonida:old-pr/9927
ProjectLeonida:old-pr/9979
ProjectLeonida:old-pr/10032
ProjectLeonida:old-pr/9926
ProjectLeonida:old-pr/5237
ProjectLeonida:old-pr/9951
ProjectLeonida:old-pr/9931
ProjectLeonida:old-pr/9902
ProjectLeonida:old-pr/9921
ProjectLeonida:old-pr/9994
ProjectLeonida:old-pr/9775
ProjectLeonida:old-pr/9768
ProjectLeonida:old-pr/9905
ProjectLeonida:old-pr/9936
ProjectLeonida:old-pr/9901
ProjectLeonida:old-pr/9904
ProjectLeonida:old-pr/9906
ProjectLeonida:old-pr/9988
ProjectLeonida:old-pr/9908
ProjectLeonida:old-pr/9909
ProjectLeonida:old-pr/9911
ProjectLeonida:old-pr/9912
ProjectLeonida:old-pr/9913
ProjectLeonida:old-pr/9887
ProjectLeonida:old-pr/9916
ProjectLeonida:old-pr/9919
ProjectLeonida:old-pr/9925
ProjectLeonida:old-pr/9933
ProjectLeonida:old-pr/9935
ProjectLeonida:old-pr/9918
ProjectLeonida:old-pr/9879
ProjectLeonida:old-pr/9880
ProjectLeonida:old-pr/9881
ProjectLeonida:old-pr/9996
ProjectLeonida:old-pr/9876
ProjectLeonida:old-pr/9892
ProjectLeonida:old-pr/9899
ProjectLeonida:old-pr/9915
ProjectLeonida:old-pr/9914
ProjectLeonida:old-pr/9872
ProjectLeonida:old-pr/9869
ProjectLeonida:old-pr/9866
ProjectLeonida:old-pr/9819
ProjectLeonida:old-pr/10012
ProjectLeonida:old-pr/9857
ProjectLeonida:old-pr/9893
ProjectLeonida:old-pr/9897
ProjectLeonida:old-pr/9928
ProjectLeonida:old-pr/9868
ProjectLeonida:old-pr/9917
ProjectLeonida:old-pr/9940
ProjectLeonida:old-pr/9873
ProjectLeonida:old-pr/9816
ProjectLeonida:old-pr/10009
ProjectLeonida:old-pr/9900
ProjectLeonida:old-pr/9966
ProjectLeonida:old-pr/9859
ProjectLeonida:old-pr/9843
ProjectLeonida:old-pr/9991
ProjectLeonida:old-pr/10058
ProjectLeonida:old-pr/9883
ProjectLeonida:old-pr/9838
ProjectLeonida:old-pr/9835
ProjectLeonida:old-pr/9959
ProjectLeonida:old-pr/9895
ProjectLeonida:old-pr/9837
ProjectLeonida:old-pr/9858
ProjectLeonida:old-pr/9865
ProjectLeonida:old-pr/9864
ProjectLeonida:old-pr/9840
ProjectLeonida:old-pr/9820
ProjectLeonida:old-pr/4669
ProjectLeonida:old-pr/9848
ProjectLeonida:old-pr/9850
ProjectLeonida:old-pr/9810
ProjectLeonida:old-pr/9799
ProjectLeonida:old-pr/9853
ProjectLeonida:old-pr/9875
ProjectLeonida:old-pr/9831
ProjectLeonida:old-pr/9796
ProjectLeonida:old-pr/9801
ProjectLeonida:old-pr/9813
ProjectLeonida:old-pr/9794
ProjectLeonida:old-pr/7417
ProjectLeonida:old-pr/9781
ProjectLeonida:old-pr/9806
ProjectLeonida:old-pr/9958
ProjectLeonida:old-pr/9809
ProjectLeonida:old-pr/9791
ProjectLeonida:old-pr/9792
ProjectLeonida:old-pr/10053
ProjectLeonida:old-pr/9784
ProjectLeonida:old-pr/9789
ProjectLeonida:old-pr/9849
ProjectLeonida:old-pr/9846
ProjectLeonida:old-pr/9773
ProjectLeonida:old-pr/9785
ProjectLeonida:old-pr/9803
ProjectLeonida:old-pr/9826
ProjectLeonida:old-pr/9839
ProjectLeonida:old-pr/9922
ProjectLeonida:old-pr/9948
ProjectLeonida:old-pr/7189
ProjectLeonida:old-pr/9957
ProjectLeonida:old-pr/9823
ProjectLeonida:old-pr/9807
ProjectLeonida:old-pr/9851
ProjectLeonida:old-pr/9774
ProjectLeonida:old-pr/9830
ProjectLeonida:old-pr/9836
ProjectLeonida:old-pr/9822
ProjectLeonida:old-pr/9783
ProjectLeonida:old-pr/9833
ProjectLeonida:old-pr/9890
ProjectLeonida:old-pr/9770
ProjectLeonida:old-pr/9769
ProjectLeonida:old-pr/9772
ProjectLeonida:old-pr/9787
ProjectLeonida:old-pr/9852
ProjectLeonida:old-pr/9834
ProjectLeonida:old-pr/9845
ProjectLeonida:old-pr/9871
ProjectLeonida:old-pr/9771
ProjectLeonida:old-pr/9776
ProjectLeonida:old-pr/10005
ProjectLeonida:old-pr/9949
ProjectLeonida:old-pr/9923
ProjectLeonida:old-pr/9805
ProjectLeonida:old-pr/9829
ProjectLeonida:old-pr/9790
ProjectLeonida:old-pr/9827
ProjectLeonida:old-pr/9929
ProjectLeonida:old-pr/9855
ProjectLeonida:old-pr/9934
ProjectLeonida:old-pr/9907
ProjectLeonida:old-pr/9910
ProjectLeonida:old-pr/9779
ProjectLeonida:old-pr/9780
ProjectLeonida:old-pr/9885
ProjectLeonida:old-pr/9882
ProjectLeonida:old-pr/9877
ProjectLeonida:old-pr/9998
ProjectLeonida:old-pr/4251
ProjectLeonida:old-pr/9987
ProjectLeonida:old-pr/9989
ProjectLeonida:old-pr/9950
ProjectLeonida:old-pr/9777
ProjectLeonida:old-pr/10044
ProjectLeonida:old-pr/9884
ProjectLeonida:old-pr/2906
ProjectLeonida:old-pr/5076
ProjectLeonida:old-pr/9937
ProjectLeonida:old-pr/9986
ProjectLeonida:old-pr/3014
ProjectLeonida:old-pr/9943
ProjectLeonida:old-pr/9939
ProjectLeonida:old-pr/4682
ProjectLeonida:old-pr/4765
No reviewers
Labels
Clear labels
No items
No labels
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.
Reference
ProjectLeonida/mandy!3352
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-03T15:31:37Z.
Claimed in the coordination issue as: D3D12-ALIAS-LATER-QUEUE-ORDER (https://github.com/ProjectLeonida/mandy/issues/3312#issuecomment-7383293227)
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
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-03T16:10:03Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by x2Tweek on 2026-12-03T16:17:05Z.
Review: COMMENTED
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.