d3d12-hle: terminating a composite task queue cancels only its own tasks (D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE) #2824
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2824"
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-01T03:12:00Z.
Claimed in the coordination issue as: D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7277115631)
What and why
A composite task queue (
XTaskQueueCreateComposite) shares its ports with the queue they came from.XTaskQueueTerminate(d3d12/crates/leonida-hle/src/modules/xasync.rs) drained every task on each of the terminated queue's ports. Terminating the composite therefore also took the other queue's pending tasks and ran them as canceled, while that queue was still open. The comment next to the drain already said the other queues' dispatches wait on; the code didn't do it for their tasks.The change:
Queue::id, from a counter, never reused).This ports ahmetbagci's fix from the sibling VIctory tree (TaynanGT/Vice-Tay
fa10fa3, GPL-3.0), credited as co-author.Tested
modules::xasync::tests::terminating_a_composite_queue_leaves_other_queues_tasks_queued: queue A and a composite B on A's ports each queue a task; terminating B cancels B's task and leaves A's queued, and A's then runs uncanceled. Onmain(90c514437) it fails (the other queue's task stays queued,left: 2,right: 0); with the change it passes.cargo test -p leonida-hle --lib: 241 passed, 0 failed, 2 ignored.cargo clippy -p leonida-hle --lib --tests: no warning in the changed lines.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 fiestorra on 2026-12-01T03:17:57Z.
Verified on Windows with a mutation at the line the change exists for, and it fails in both directions - cancel your own, spare the others.
main90c514437, cherry-picked (the branch is atmain),cargo 1.98.1:The test arriving with the code is not the interesting part, so I made the change it names in
xasync.rs:415and watched both halves:So the tests pin the property from both sides:
truebreaks only the "spare the others" case,falsebreaks that one and the "cancel your own" case. That is the shape a fix like this needs - a one-sided test would pass withfalsein place and the queue would never cancel anything.What the change is, from the code: each queued task carries the id of the queue that queued it (
submit(owner, task)), and terminating partitions the queue by that id instead of draining it. A staticNEXT_QUEUE: AtomicU64hands out the ids; the comment says never reused.What I did not test: the real
XTaskQueueTerminatepath against a title's composite queue - that needs the game. The mock'srecordcallback and the two states it stores are what the tests drive, and they are green.AI-assisted: yes - DeepSeek v4.1 (flash), two mutations and three runs.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T04:57:13Z.
Review: COMMENTED
Verified, and the direction is pinned both ways. The new test fails on the base
90c514437(left: 2, right: 0, "the other queue's task stays queued") and passes on the head;cargo test --locked -p leonida-hle --libis 241 passed / 0 failed / 2 ignored on the head, and main plus the new test is 240/1/2 with only that test failing. Mutation check: draining withpartition(|_| true)reproduces the old bug and is caught atxasync.rs:1703;partition(|_| false)is caught by the new test (:1702) and byterminate_cancels_what_is_queued, so the ownership predicate is pinned both ways, not just one.The mechanism reads right: the queue id is per queue and shared by duplicated handles (
:197-218), every enqueue goes throughQueue::deliverwithself.id(:254-255,:121-130), a completion already queued is drained withcanceled=trueand one arriving after termination runs canceled throughsubmit'sE_ABORT(:704-709), the drain is under the port lock and scoped to that id (:408-426), and the sibling's dispatcher still pops its own tasks (:375).terminate_ends_a_waiting_dispatchstill passes, so a wait across queues is not short-circuited.One follow-up, pre-existing and not introduced here:
submitchecksterminatedoutside the port lock, and the delayed timer delivers after its own check, so a task can still land on a port after a composite's drain — the terminated queue's dispatch will never run it and the sibling's will run it uncanceled. Re-checkingterminatedunder the port lock insidedeliverwould close that. Also note_waitis still ignored, sowait=truereturns before in-flight work finishes.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T20:54:01Z.
Merging as part of a group. Head
156827c18; the group branch main1e3e316c5+ #2862 + #2824 + #2873 (7988c1c89, merged in that order) passed the full CI (https://github.com/OreoFR/leonida/actions/runs/46740411028, the same workflow file as here, run on that branch) and No Game Data (https://github.com/OreoFR/leonida/actions/runs/46740416586); main was1e3e316c5with its CI green when the group merged. Claim: D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7277115631). Red/green: fiestorra (Windows, mutation fails both ways), KelboLive review on this head (test fails on base, passes here). I ran: the five PRs #2860-#2862, #2824 and #2873 merged together onto mainab374c7d5(main since gained only #2935, a CI workflow change, and #2860 and #2861, both part of that test), with the shader (418 passed, 0 failed), gpu (644/0) and hle (247/0) cargo tests. In-game run: RTX 4070 Laptop 8 GB, NVIDIA 621.40, a cold start to the world then a 330 s warm walking run, 0 device lost, no panic. CI: green on head, main and the group branch. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR.Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T23:45:14Z.
VERIFY-2824 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS. The repository's own red/green idea holds under Wine: the new test fails on the merge base and passes with the pull request, and nothing that worked before is broken.
Head
156827c1, base the currentmain, merge base90c51443, 1 file, +54/−7:d3d12/crates/leonida-hle/src/modules/xasync.rs.1. What it changes
A composite task queue shares its ports with the queue it came from.
XTaskQueueTerminatedrained the port's whole task queue:so terminating a composite queue also cancelled the parent queue's tasks that were still queued on the shared port. The pull request gives every queue an id that is never reused, tags each queued task with the queue that queued it, and drains only that queue's own tasks:
2. Red and green, run under Wine
leonida-hledoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21:modules::xasync::tests::terminating_a_composite_queue_leaves_other_queues_tasks_queued— fails on the base, passes with the pull requestmodules::net::tests::only_loopback_is_reachable("ws2_32.dll lacks WSAConnectByList") andmodules::xgamesave::tests::a_kept_blob_past_the_link_limit_is_copied("the temp folder must be on NTFS"). Both are the environment, not this changeThe new test is the right shape for the change: it queues one task on the parent queue and one on the composite, terminates the composite, and checks that the composite's own task was canceled while the parent's stays queued and later runs uncanceled — which is what the old
drain(..)made impossible.3. The ids are never reused
A queue's id is taken once, when the queue is made, from a counter that only goes up — so a task tagged with a dead queue's id can never be mistaken for a later queue's task, which is what makes the partition by owner safe.
Relaxedis enough for it: the id is only ever compared with another id taken from the same counter.4. What I did not check
XTaskQueue*is documented elsewhere in the runtime; I did not compare the composite-queue behaviour with the console's.WSAConnectByListand its filesystem, not this change.AI-assisted: MiniMax M3.1 Flash.