Repository navigation
d3d12-hle: terminating a composite task queue cancels only its own tasks (D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE) - #2824
Conversation
A composite queue (XTaskQueueCreateComposite) shares its ports with the queue they came from. XTaskQueueTerminate drained every task on each of the queue's ports, so terminating the composite also took the other queue's pending tasks and ran them as canceled, while that queue was still open. Each queued task now carries the id of the queue that queued it, and termination drains only those of the terminated queue; the others stay queued and run uncanceled on the next dispatch. Ported from ahmetbagci's fix in Vice-Tay (fa10fa3). Co-Authored-By: ahmetbagci <6625856+ahmetbagci@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
The test arriving with the code is not the interesting part, so I made the change it names in tasks.drain(..).partition(|(owner, _)| *owner == queue.id); // as this branch has it
with `true` (cancel every task): FAILED terminating_a_composite_queue_leaves_other_queues_tasks_queued
assertion `left == right` failed: the other queue's task stays queued left: 2
with `false` (cancel none): FAILED terminate_cancels_what_is_queued
FAILED terminating_a_composite_queue_leaves_other_queues_tasks_queuedSo the tests pin the property from both sides: What the change is, from the code: each queued task carries the id of the queue that queued it ( What I did not test: the real AI-assisted: yes - DeepSeek v4.1 (flash), two mutations and three runs. Written with an AI assistant. |
KelboLive
left a comment
There was a problem hiding this comment.
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 --lib is 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 with partition(|_| true) reproduces the old bug and is caught at xasync.rs:1703; partition(|_| false) is caught by the new test (:1702) and by terminate_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 through Queue::deliver with self.id (:254-255, :121-130), a completion already queued is drained with canceled=true and one arriving after termination runs canceled through submit's E_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_dispatch still passes, so a wait across queues is not short-circuited.
One follow-up, pre-existing and not introduced here: submit checks terminated outside 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-checking terminated under the port lock inside deliver would close that. Also note _wait is still ignored, so wait=true returns before in-flight work finishes.
|
Merging as part of a group. Head 156827c; the group branch main 1e3e316 + #2862 + #2824 + #2873 (7988c1c, 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 was 1e3e316 with its CI green when the group merged. Claim: D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE (#2570 (comment)). 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 main ab374c7 (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. |
VERIFY-2824 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game filesVerdict: 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 1. What it changesA composite task queue shares its ports with the queue it came from. let pending: Vec<Task> = lock(&port.tasks).drain(..).collect();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: // Only this queue's tasks: a composite queue shares the port with
// the queue it came from, whose tasks stay queued.
let pending: Vec<Task> = {
let mut tasks = lock(&port.tasks);
let (mine, others): (VecDeque<_>, VecDeque<_>) =
tasks.drain(..).partition(|(owner, _)| *owner == queue.id);
*tasks = others;
mine.into_iter().map(|(_, task)| task).collect()
};2. Red and green, run under Wine
The 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 3. The ids are never reusedstatic NEXT_QUEUE: AtomicU64 = AtomicU64::new(1);
...
id: NEXT_QUEUE.fetch_add(1, Ordering::Relaxed),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. 4. What I did not check
AI-assisted: MiniMax M3.1 Flash. |
Claimed in the coordination issue as: D3D12-HLE-XTASKQUEUE-COMPOSITE-TERMINATE (#2570 (comment))
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