d3d12_device_calls: forget a slot a store or a call may have replaced (carry of #2343) #3093

Manually merged
github merged 3 commits from github-bot/gh-3093 into gh-pr/3093/base 2026-12-02 13:09:29 +00:00 AGit
Owner

@⁠MoonEyes on GitHub · 2026-12-02 10:31 UTC · original
MoonEyes:carry/2343 → main · +61 −3 · 2 files · 3 commits · merged 2026-12-02 13:05 UTC

Claimed in the coordination issue as: D3D12-DEVICE-CALLS-STALE-SLOT (the original author's item ID, claimed at #1608)

What and why

Carry of #2343 (syfyra), unchanged since 2026-11-26. Branch = main + the author's head (commit kept, merged without conflicts) + one commit of mine.

tools/d3d12_device_calls.py followed a [reg+disp] slot that held the device and dropped it only on a plain store to the slot's exact address. #2343 also forgets the slot when a call is given its address (an out-pointer) and when any store, SSE/AVX stores and partial stores included, touches its bytes, so a later call through the slot is not reported as a device slot.

Review defect fixed in my commit: the reviewers (lixonik, aslan2142) showed that an EVEX 64-byte store such as vmovups [rsp+20h],zmm0 covers the device spill at [rsp+40h], but VEX/EVEX stores were sized 32 bytes, so slot 6 was still reported. The decoder keeps neither VEX.L nor EVEX.L'L, so every VEX/EVEX store now takes 64 bytes (forgetting a slot only loses a site). A ZMM case is added to the existing store table in tests/test_d3d12_device_calls.py.

The other review remarks (mark Ready for Review, fresh CI) need no code. This carry does not change how the decoder reads EVEX compressed disp8 displacements; the new test uses a disp32 form.

Tested

Windows 11, Python 3.14.0, no GPU, no game files, on main 80910637f plus this branch:

  • python -I tests/test_d3d12_device_calls.py: 21 tests OK.
  • python -I tests/test_gdk_runtime_calls.py: 25 tests OK.
  • python -m compileall -q on both changed files: OK.
  • Red: with main's tools/d3d12_device_calls.py restored, the same test file gives 6 failures in the two new tests (the call-given-the-slot case, and the movups, vmovdqu, ZMM and 4-byte-store cases). With the PR's original source, the ZMM subtest fails, as the reviewers reported (that run also shows 3 other failures from main's newer CLI tests, which the original source predates).
  • python -I scripts/check_no_game_data.py on both changed files: clean.

Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

Supersedes #2343 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

**@⁠MoonEyes** on GitHub · 2026-12-02 10:31 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3093) `MoonEyes:carry/2343` → `main` · +61 −3 · 2 files · 3 commits · merged 2026-12-02 13:05 UTC Claimed in the coordination issue as: D3D12-DEVICE-CALLS-STALE-SLOT (the original author's item ID, claimed at https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Carry of #2343 (syfyra), unchanged since 2026-11-26. Branch = `main` + the author's head (commit kept, merged without conflicts) + one commit of mine. `tools/d3d12_device_calls.py` followed a `[reg+disp]` slot that held the device and dropped it only on a plain store to the slot's exact address. #2343 also forgets the slot when a call is given its address (an out-pointer) and when any store, SSE/AVX stores and partial stores included, touches its bytes, so a later call through the slot is not reported as a device slot. Review defect fixed in my commit: the reviewers (lixonik, aslan2142) showed that an EVEX 64-byte store such as `vmovups [rsp+20h],zmm0` covers the device spill at `[rsp+40h]`, but VEX/EVEX stores were sized 32 bytes, so slot 6 was still reported. The decoder keeps neither VEX.L nor EVEX.L'L, so every VEX/EVEX store now takes 64 bytes (forgetting a slot only loses a site). A ZMM case is added to the existing store table in `tests/test_d3d12_device_calls.py`. The other review remarks (mark Ready for Review, fresh CI) need no code. This carry does not change how the decoder reads EVEX compressed disp8 displacements; the new test uses a disp32 form. ### Tested Windows 11, Python 3.14.0, no GPU, no game files, on main 80910637f plus this branch: - `python -I tests/test_d3d12_device_calls.py`: 21 tests OK. - `python -I tests/test_gdk_runtime_calls.py`: 25 tests OK. - `python -m compileall -q` on both changed files: OK. - Red: with `main`'s `tools/d3d12_device_calls.py` restored, the same test file gives 6 failures in the two new tests (the call-given-the-slot case, and the movups, vmovdqu, ZMM and 4-byte-store cases). With the PR's original source, the ZMM subtest fails, as the reviewers reported (that run also shows 3 other failures from main's newer CLI tests, which the original source predates). - `python -I scripts/check_no_game_data.py` on both changed files: clean. Not run: the full suite, CI. GPUs tested: n/a (unit tests only) AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: Claude Opus 5.5. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) Supersedes #2343 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The walk keeps a stack slot that held the device across calls and drops
it only on a plain store to its exact address. Two ways a slot gets
another object were missed, and a call through it was then reported as
a device slot, the guess the report promises not to make:

- A call given the slot's address. device->CreateCommandQueue(&desc,
  riid, &out) with out in the slot the device was spilled to (frame
  slots are reused) leaves the queue there; queue->SetName was counted
  as device slot 6. The slots passed in rcx/rdx/r8/r9 are now forgotten
  at the call (a creator's out slot is still added back after it).
- An SSE/AVX store (movups/movaps/movdqu/movq/... and their VEX forms)
  over the slot, as struct copies are compiled, and any store that
  covers only part of it. Every store now ends the slots whose bytes it
  touches; the vector stores take their widest form (16 bytes, 32 under
  VEX), since the decoder keeps neither the prefix nor VEX.L.

Tested: two new tests in tests/test_d3d12_device_calls.py (the five
overwriting cases fail before the change; the stores and out-pointer
that miss the slot keep it, before and after).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of the carried change (lixonik, aslan2142): an EVEX 64-byte store such as
vmovups [rsp+20h],zmm0 covers the device spill at [rsp+40h], but the vector
stores were sized 32 bytes under VEX/EVEX, so the slot was kept and queue->SetName
was counted as device slot 6. The decoder keeps neither VEX.L nor EVEX.L'L, so
every VEX/EVEX store now takes 64 bytes (forgetting a slot only loses a site).
A regression test with the EVEX ZMM store is added to the existing store table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 10:35:56 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-12-02 12:18 UTC · original

Verified by OreoFR (oreofr-agent, AI-assisted; third-party red/green). Head 9b9e6f3c843bdadc91e40c2181a617f0ec2cd807 merged into main f6dd2242e02b5f579d245f1c19dd5150d42e00a1 with no conflicts. Windows 11, Python 3.12, CPU only.

  • Green: tests/test_d3d12_device_calls.py OK; tests/test_gdk_runtime_calls.py OK.
  • Red, with main's tools/d3d12_device_calls.py restored and this PR's tests kept: test_d3d12_device_calls.py FAILED (failures=6), as the description says; test_gdk_runtime_calls.py still OK.
    Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
**@⁠OreoFR** on GitHub · 2026-12-02 12:18 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3093#issuecomment-7345156827) **Verified by OreoFR** (oreofr-agent, AI-assisted; third-party red/green). Head `9b9e6f3c843bdadc91e40c2181a617f0ec2cd807` merged into main `f6dd2242e02b5f579d245f1c19dd5150d42e00a1` with no conflicts. Windows 11, Python 3.12, CPU only. - Green: `tests/test_d3d12_device_calls.py` OK; `tests/test_gdk_runtime_calls.py` OK. - Red, with main's `tools/d3d12_device_calls.py` restored and this PR's tests kept: `test_d3d12_device_calls.py` FAILED (failures=6), as the description says; `test_gdk_runtime_calls.py` still OK. Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
Author
Owner

@⁠MoonEyes on GitHub · 2026-12-02 12:49 UTC · original

Merging. Head 9b9e6f3c8 merges cleanly with main 23a51c494 and does not force a rebase of #2566. Moon's own pull request, merged on green CI at his instruction. An independent read-only check by a separate agent on head 9b9e6f3c8 found every CI check green including no-game-data, no conflict with current main, no open review or unanswered question, and for a carry the original author's commits kept as ancestors. Merged by MoonEyes.

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-12-02 12:49 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3093#issuecomment-7345926094) Merging. Head `9b9e6f3c8` merges cleanly with `main` `23a51c494` and does not force a rebase of #2566. Moon's own pull request, merged on green CI at his instruction. An independent read-only check by a separate agent on head 9b9e6f3c8 found every CI check green including no-game-data, no conflict with current main, no open review or unanswered question, and for a carry the original author's commits kept as ancestors. Merged by MoonEyes. AI-assisted (Claude Code).
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-02 12:55 UTC · original

Ran natively on Windows 11, Python 3.13, head 9b9e6f3c8 merged into current main (23a51c494, no conflicts). py -3.13 -I tests/test_d3d12_device_calls.py OK; red/green already shown above, so I only probed which other writes to the slot end it.

Throwaway probe (not committed) reusing the PR's spilled_device helper: spill the device to [rsp+0x40], run one instruction, reload, call slot 6. "kept" = slot 6 still reported.

instruction between spill and reload this PR main
nop (baseline) kept kept
mov qword [rsp+0x40],0 ends ends
mov word [rsp+0x40],dx ends ends
mov byte [rsp+0x47],0 ends kept
xchg [rsp+0x40],rdx ends ends
vmovups [rsp+0x40],zmm0 (EVEX, disp8) ends kept
and qword [rsp+0x40],0 (48 83 64 24 40 00) kept kept
or qword [rsp+0x40],-1 kept kept
xor [rsp+0x40],rdx kept kept
setz byte [rsp+0x40] kept kept
cmpxchg [rsp+0x40],rdx kept kept
pop qword [rsp+0x40] kept kept
lea r9,[rsp+0x38] + call (out struct that covers 0x40) kept kept

Not a regression, main keeps all of them too, but the new docstring line ("any store over a slot's bytes ends it") reads wider than the code. Read-modify-write forms (and/or/xor/add/sub [m], 0x80/0x81/0x83 with a memory operand, setcc [m], cmpxchg, xadd) never reach overwrite(). and qword ptr [rsp+N],0 is the short form MSVC often emits for p = nullptr with a stack slot, so it is the one most likely to show up in a real image. Either widening the doc wording to "plain and SSE/AVX stores" or sending memory-destination ALU ops through overwrite() would do; the latter only loses sites, in line with the PR's own rule. The out-pointer check also matches only a slot at exactly the address passed, not a buffer that covers it (last row); that one is rarer.

Not checked: real images, EVEX compressed disp8 (stated as out of scope in the body), Linux.

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

**@⁠Kal0s-design** on GitHub · 2026-12-02 12:55 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3093#issuecomment-7346087755) Ran natively on Windows 11, Python 3.13, head `9b9e6f3c8` merged into current `main` (`23a51c494`, no conflicts). `py -3.13 -I tests/test_d3d12_device_calls.py` OK; red/green already shown above, so I only probed which other writes to the slot end it. Throwaway probe (not committed) reusing the PR's `spilled_device` helper: spill the device to `[rsp+0x40]`, run one instruction, reload, call slot 6. "kept" = slot 6 still reported. | instruction between spill and reload | this PR | `main` | |---|---|---| | `nop` (baseline) | kept | kept | | `mov qword [rsp+0x40],0` | ends | ends | | `mov word [rsp+0x40],dx` | ends | ends | | `mov byte [rsp+0x47],0` | ends | kept | | `xchg [rsp+0x40],rdx` | ends | ends | | `vmovups [rsp+0x40],zmm0` (EVEX, disp8) | ends | kept | | `and qword [rsp+0x40],0` (`48 83 64 24 40 00`) | **kept** | kept | | `or qword [rsp+0x40],-1` | **kept** | kept | | `xor [rsp+0x40],rdx` | **kept** | kept | | `setz byte [rsp+0x40]` | **kept** | kept | | `cmpxchg [rsp+0x40],rdx` | **kept** | kept | | `pop qword [rsp+0x40]` | **kept** | kept | | `lea r9,[rsp+0x38]` + call (out struct that covers `0x40`) | **kept** | kept | Not a regression, `main` keeps all of them too, but the new docstring line ("any store over a slot's bytes ends it") reads wider than the code. Read-modify-write forms (`and/or/xor/add/sub [m]`, `0x80/0x81/0x83` with a memory operand, `setcc [m]`, `cmpxchg`, `xadd`) never reach `overwrite()`. `and qword ptr [rsp+N],0` is the short form MSVC often emits for `p = nullptr` with a stack slot, so it is the one most likely to show up in a real image. Either widening the doc wording to "plain and SSE/AVX stores" or sending memory-destination ALU ops through `overwrite()` would do; the latter only loses sites, in line with the PR's own rule. The out-pointer check also matches only a slot at exactly the address passed, not a buffer that covers it (last row); that one is rarer. Not checked: real images, EVEX compressed disp8 (stated as out of scope in the body), Linux. GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
github-bot changed target branch from main to gh-pr/3093/base 2026-12-02 13:09:28 +00:00
github manually merged commit 9b9e6f3c84 into gh-pr/3093/base 2026-12-02 13:09:29 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!3093
No description provided.