WIP: d3d12-gpu: LEONIDA_ALIAS_LATER mappings wait for what their queue had before them (D3D12-ALIAS-LATER-QUEUE-ORDER) #3352
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/3352:github-pr/3352" git switch "github-pr/3352"
Draft
leonida/mandy
MoonEyes wants to merge 2 commits from
github-pr/3352 into main
pull from: github-pr/3352
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3352
Loading…
Reference in a new issue
No description provided.
Delete branch "github-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?
This pull request is marked as a work in progress.
This pull request cannot be merged because it is marked as being a work in progress.
Reviewers 0 approvals
Details
This pull request can be merged automatically.
This pull request is marked as a work in progress.
This pull request cannot be merged because it is marked as being a work in progress.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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
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).
Read-only audit of this PR against
main(no game run, no build). The race in #3329 is real and still present onmain, and this PR still applies cleanly (git merge-tree main origin/github-pr/3352, exit 0). But I do not think it is ready to ship as written.What is right:
alias_releaseis only called frommet(Ask::Alias), which is evaluated for a queue head (behind.rs:334-348), so a mapping no longer runs before an earlier entry of its own queue has been prepared. That addresses the CPU-prepare race.What holds it back:
alias_nextonly takes the front of one global deque. Q1[Wait(f), Alias(k)]and Q2[Alias(k+1), Signal(f)]is stuck; withLEONIDA_WAIT_FORCE=0it never clears. The queue is blocked by an entry that is only aWait, which cannot read title memory.Run/Lists) can read title memory; an unmetWait/Signalahead of the mapping cannot. The faithful minimum is 'no earlier submission of this queue is still in the line', not 'this entry is the head'. The first test asserts the over-block.alias_wait(n)usesalias_release(n, true), which releases every lower ticket, including mappings of other queues whose own queues have not reached them.alias_laterpushes the work under the ticket lock but callsLANE.pushafter it, soAlias(n+1)can be published beforeAlias(n); under this PR that is a permanent stall, wheremainrecovers.alias_releaseruns inline whenworker == false; if a lateralias_queuespawns the worker, both can pop, andALIAS_DONE.storecan go backwards (fetch_max).matchleft insettletripsclippy::single_match; and the tests callalias_queue, which does not exist onmain, so they do not give a real red.Minimal rework I would suggest: per-queue release keyed to earlier submissions (track each queue's lane entries and let a mapping go once no earlier
Run/Listsof that queue is still in the line); drop the cross-queue ordering requirement (mappings on different queues are unordered on the console too); force only the selected ticket; one executor;fetch_maxforALIAS_DONE.A device-free red is possible against
alias_later(it exists on both sides): pushJob::Wait(f,1)on queue 1, callalias_later(1, closure),lane.look(limit), assert the closure has not run within a short window, then set the fence. Onmainthe worker runs it immediately (red); with the corrected release it waits. The faithful version — an earlier submission whosegoreads the pages — still needs a device, becauseJob::Rungoes throughhost::host()/HostList.Unproven either way: #3352 holds mappings until earlier submissions are prepared and sent (
execute_late), not until the card has run them; whether the GPU can still DMA from pages remapped after the send has not been checked.