d3d12: page mappings done behind the call (LEONIDA_ALIAS_LATER) can reach submissions queued before them #3329

Open
opened 2026-12-03 12:38:19 +00:00 by x2Tweek · 0 comments
x2Tweek commented 2026-12-03 12:38:19 +00:00 (Migrated from github.com)
Contributor

Imported from ubiquitarianism/leonida. Originally posted by x2Tweek on 2026-12-03T12:38:19Z.


queue.rs documents alias_behind (LEONIDA_ALIAS_LATER, on by default with the line of submissions) as: "Submissions already in the line run before it, as on the console's queue." The code orders only one direction.

What the code does (main ba9e65cec, paths under crates/leonida-gpu/src/):

  1. queue.rs copy_page_mappings resolves the source pages in the title's call, then calls behind::alias_later(this, later(&gathered)).
  2. queue/behind.rs alias_later pushes the work onto the leonida-alias thread's own deque and notifies it, then appends Job::Alias(number) to the queue's lane.
  3. alias_worker pops the work and runs it at once. Nothing there looks at the lane, so the unmap and remap can happen while older jobs of the same queue are still in the lane.
  4. Job::Alias (Ask::Alias, alias_wait) makes the jobs after it wait for ALIAS_DONE >= number. The jobs before it are not held back from seeing the new mapping.
  5. An older Run / Joined job held at the head of its queue, for example by a fence wait, prepares later: deferred operations, copy refreshes and texture upload preludes read title memory then (host.rs execute_parts / send_late and the refresh paths). A read that starts after the remap sees the new pages.

Interleaving: the title queues a wait on a fence, then a submission whose texture refresh reads page P. While the fence is pending, it asks for P to show other physical pages. The alias thread remaps P. The fence is signalled, and the older submission uploads from the new pages, not the ones it was recorded against. On the console the mapping is a queue operation and that submission would read the old pages.

Expected effect: rare one-frame wrong texture or buffer contents during heavy streaming (driving), only when a submission sits behind an unmet wait while the title remaps. I have not reproduced a visible case yet; this is from reading the code. LEONIDA_ALIAS_LATER=0 gives the in-call ordering.

Possible fix: keep the resolved closure in the lane entry and hand it to the worker only when Job::Alias reaches the head of its queue (the worker keeps the call's cost off the title's thread; the lane already waits for it). The fallbacks that run it in place (no worker thread) should go through the same point.

AI-assisted: found by Codex (GPT) in a read-only audit and checked against the source with Claude Opus 5.5 (Claude Code); no runtime change made.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:6768669336 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/3329). Originally posted by [x2Tweek](https://github.com/x2Tweek) on 2026-12-03T12:38:19Z. --- `queue.rs` documents `alias_behind` (`LEONIDA_ALIAS_LATER`, on by default with the line of submissions) as: "Submissions already in the line run before it, as on the console's queue." The code orders only one direction. **What the code does** (main `ba9e65cec`, paths under `crates/leonida-gpu/src/`): 1. `queue.rs` `copy_page_mappings` resolves the source pages in the title's call, then calls `behind::alias_later(this, later(&gathered))`. 2. `queue/behind.rs` `alias_later` pushes the work onto the `leonida-alias` thread's own deque and notifies it, then appends `Job::Alias(number)` to the queue's lane. 3. `alias_worker` pops the work and runs it at once. Nothing there looks at the lane, so the unmap and remap can happen while older jobs of the same queue are still in the lane. 4. `Job::Alias` (`Ask::Alias`, `alias_wait`) makes the jobs **after** it wait for `ALIAS_DONE >= number`. The jobs **before** it are not held back from seeing the new mapping. 5. An older `Run` / `Joined` job held at the head of its queue, for example by a fence wait, prepares later: deferred operations, copy refreshes and texture upload preludes read title memory then (`host.rs` `execute_parts` / `send_late` and the refresh paths). A read that starts after the remap sees the new pages. **Interleaving:** the title queues a wait on a fence, then a submission whose texture refresh reads page P. While the fence is pending, it asks for P to show other physical pages. The alias thread remaps P. The fence is signalled, and the older submission uploads from the new pages, not the ones it was recorded against. On the console the mapping is a queue operation and that submission would read the old pages. **Expected effect:** rare one-frame wrong texture or buffer contents during heavy streaming (driving), only when a submission sits behind an unmet wait while the title remaps. I have not reproduced a visible case yet; this is from reading the code. `LEONIDA_ALIAS_LATER=0` gives the in-call ordering. **Possible fix:** keep the resolved closure in the lane entry and hand it to the worker only when `Job::Alias` reaches the head of its queue (the worker keeps the call's cost off the title's thread; the lane already waits for it). The fallbacks that run it in place (no worker thread) should go through the same point. AI-assisted: found by Codex (GPT) in a read-only audit and checked against the source with Claude Opus 5.5 (Claude Code); no runtime change made.
Sign in to join this conversation.
No labels
No milestone
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#3329
No description provided.