Repository navigation
Conversation
…, from the file alone (RT-566) tools/d3d12_device_calls.py follows D3D12XboxCreateDevice's (or D3D12CreateDevice's) out-pointer to the globals and stack slots that hold the device, and counts per vtable slot the `mov v,[device]` then `call [v+disp]` / `call reg` / dispatch-with-rax sites, with the register that holds the device (rcx, or rdx for the console's return-buffer form) and an argument-count estimate. What it can't follow (vtable loads with no matched call, the device handed to other functions or stored to non-stack memory, creator out-pointers it can't follow) is counted, not guessed. Slots 0-43 carry the PC method names; past 43 only the slots the repository has measured are named. The text report holds slot numbers and counts only; --out is required. Tested on a hand-built PE (tests/test_d3d12_device_calls.py); docs/retail_boot_chain.md §5 has the method and its limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI-assisted Windows review of From the repository root, use import sys
sys.path[:0] = ["tests", "tools"]
from test_d3d12_device_calls import Asm, build_image
from d3d12_device_calls import scan
image, funcs = build_image()
data = bytearray(image)
site = data.index(bytes.fromhex("ff 15"), funcs["dispatch"], funcs["stack"])
helper = 0x1f00
data[helper] = 0xc3 # ret
a = Asm(site)
a.rel(bytes.fromhex("e8"), helper)
a.raw(bytes.fromhex("90")) # keep the original instruction span
data[site:site + 6] = a.code
for blob in (image, bytes(data)):
print([s["slot"] for s in scan(blob)["slots"]])Both scans report |
…patch routine (ItsNotRexed#7998 review) A direct call with a method pointer left in rax was counted as that slot whatever the call reached, so a helper that only returns made a slot appear (shdann's repro on ItsNotRexed#7998). The target, or for `call [rip+p]` the code the file's pointer p holds, must now reach `jmp rax` or `call rax` within 16 instructions without writing rax, calling or returning first (conditional branches allowed): the CFG no-op dispatch and a guard check that ends in `jmp rax`. Verified targets are cached. Any other target goes to a new "dispatch calls to unverified targets" count, never a slot. The fixture's GUARD pointer now holds a `jmp rax` stub; new functions call a guard-check stub (slot counted) and a helper that only returns (not counted, reported as not resolved), and shdann's patch is a test. The census on the 1.0.2.1 executable is unchanged: all 83 sites are `call [vtable+disp]`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested bf8294a on Linux, Python 3.12.16: pass
One thing at tools/d3d12_device_calls.py:532: a jmp rel32 inside the walked function takes the tail call path, so with the device in rcx it counts as passed to another call (a jmp rel8 does not). Treat an E9 whose target is inside [start, stop) like ends_flow? |
tupacfan04
left a comment
There was a problem hiding this comment.
Real defect: the direct-call dispatch heuristic over-counts device calls.
tools/d3d12_device_calls.py:208-209:
elif (op in (0xE8, 0xE9) or (indirect and base == RIP)) and RAX in meth:
slot, vload = meth[RAX] # dispatch routine, method in raxRAX in meth only means RAX currently holds a vtable method pointer. The code does not verify that the direct call target is a dispatch routine or that it invokes the method. A direct call rel32 (or jmp rel32) to an ordinary function while RAX still holds a method is reported as a device vtable call at that method's slot.
Synthetic repro with the PR's own image builder — add this function and one .pdata entry:
mov rcx,[rip+DEVICE] ; device
mov rax,[rcx] ; vtable
mov rax,[rax+0x70] ; slot 14 method in RAX
call unrelated ; direct E8, not a dispatch
retddc.scan() reports 5 sites, slot 14 = 2; the correct result is 4 sites, slot 14 = 1 (only the existing copy calls slot 14). The direct target only calls another object's vtable slot 3; it never uses the device.
The tests miss the branch: the positive dispatch test (tests/test_d3d12_device_calls.py:110) uses an indirect call [rip+GUARD] through a data address; test_the_unrelated_vtable_call_is_not_counted (:200) checks the function itself; the passed test (:131-135) makes a direct call but never loads a method into RAX. Add a method-in-RAX + direct call negative case. Fix: follow the direct target and confirm it dispatches RAX, or report the form as unresolved instead of counting it.
Secondary coverage gaps: a creator out-pointer in a non-volatile memory slot is recorded as "memory slot" but survives_call() only preserves RSP/framed RBP slots, so an intervening call silently loses it; NO_PDATA_WINDOW and the no-.pdata walk are not exercised; conditional branches are treated as fall-through with no branch-liveness test.
Otherwise coherent: retry/decoder, creator following, lea out-pointer, global/stack-slot handling, slot naming, CLI/report tests, and the nine tests pass. Synthetic/file-only; no game files. AI-assisted (OpenCode).
|
Thanks @shdann for the review and the repro, and @tupacfan04, who flagged the same defect at the old head. You were right: a method left in Fixed in
Your script on the fixture from
The fixture in New test: Census on my 1.0.2.1 copy is unchanged: 83 sites across 42 slots, 12 not resolved. All 83 sites are AI-assisted (Claude Code, Claude Opus 5.5). |
|
Tested
Cross-check against what the boot chain has measured, which is the value this PR claims:
AI-assisted (Claude Code). |
|
Independent check of some rows, plus call shapes for the unnamed slots. AI-assisted static read of the 1.0.2.1 executable with capstone, not run. This is my own scanner, not this PR's tool. Slot numbers, argument shapes, constants and counts only. Site counts through the device global, all matching your table: slot 49: 1, slot 50: 1, slot 55: 1, slot 57: 1, slot 71: 2, slot 81: 1. What those calls are, for the name column or the slot owners:
agent: yes |
…reXito's call shapes for unnamed slots From the two independent checks on ItsNotRexed#7998: - The tool reads the executable only, so a slot called only from a bundled DLL is absent. Slot 76 is the example: docs/d3d12_vulkan.md records the FidelityFX upscaler DLL calling it, so its absence is not "unused by the title" (TheAirborneCoder). - A credited table of TreXito's independent static read for slots 49, 50, 55, 57 and 81, with matching site counts. These are their reads, not the tool's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @TheAirborneCoder and @TreXito for the independent checks. Both are now in
AI-assisted (Claude Code, Claude Opus 5.5). |
docs/README.md conflicted: main added the modding.md row right after the retail_boot_chain.md row, whose description this branch extends. Both are kept: our retail_boot_chain.md row, then main's modding.md row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 3a7a763 on Linux (CachyOS, Python 3.14): pass, with one small defect
Review: at AI-assisted (Claude Code), run by a person; tests run in a sandbox without network. |
… a tail call (ItsNotRexed#7998 review) Every E9 was a tail call, including the `jmp rel32` MSVC emits for a long branch inside a function. With the device in an argument register, such a jump counted as the device passed to another call, it cleared the state, and it ended a window walk early (YordiLorenzo, pr-sorter). Slot 14 dropped out of the fixture with pr-sorter's patch. The walk now follows forward branches. A `jmp` (E9 or EB) or a conditional branch to a later address in the walked range carries the known state to its target. There it is met with the fall-through's state, keeping a fact only when both paths agree (vtable loads from either path are merged). Past a `ret` or unconditional jump, the carried state replaces it. A jump back into the range (a loop) carries nothing and isn't a tail call. Only a `jmp` out of the range is a tail call. pr-sorter's repro is a test, together with the short form and a backward jump. Census on the 1.0.2.1 executable: 83 -> 95 sites, still 42 slots, with no site or slot lost. 12 more sites are behind a conditional branch around an early return: slot 17 (+5), slot 24 (+5), slot 133 (+2). Not resolved stays at 12: vtable loads with no matched call 2 -> 1, calls handed the device 9 -> 10, stores 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @pr-sorter for the repro, and @YordiLorenzo for spotting this first at Fixed in
New test:
Census on my 1.0.2.1 copy, before → after:
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Tested 11b0583 on Linux, Python 3.14.4: pass test_d3d12_device_calls is OK, and the new jmp test fails against the previous d3d12_device_calls.py, so it pins the branch case. |
|
Checked Pass
Needs changes
AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The executable was read in place (SHA-256 |
…g; tupacfan04's open points (ItsNotRexed#7998) BatSmacker84 on ItsNotRexed#7998: - The summary line now separates indirect vtable calls, indirect vtable tail jumps, and sites through a verified dispatch routine. The JSON gains calls, tail_jumps and dispatch_sites. On the 1.0.2.1 executable: 95 sites = 94 calls + 1 tail jump (slot 2), 0 through a dispatch routine. - "lists every" and "lower bound" are gone from the docstring, the help text and §5. The tool reports the statically resolved sites for the device paths it follows; a slot without a row isn't shown to be uncalled. tupacfan04's secondary points from the 36b3cf3 review, still open until now: - A creator out-pointer in an object member was labelled "memory slot", yet it was dropped at the next call. It is now "object member (followed until the next call)"; a stack slot is "stack slot". - The no-.pdata window walk is tested, and it now goes on past a ret while a forward branch target is still ahead. - Conditional branches have tests: the device carried past an early return, and a join where only one path holds the device. Census unchanged: 95 sites across 42 slots, 12 not resolved. 15 tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @BatSmacker84 for checking against your own copy. Both changes are in
Re-reading the thread turned up one more open item: @tupacfan04's secondary points from the
Census unchanged: 95 sites across 42 slots, 12 not resolved. 15 tests pass. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Re-checked
AI-assisted: Claude Opus 5.5 reran the PR's own tool on the retail executable, read in place; only the tool's summary counts are quoted. |
|
Tested
Not checked: Windows, GPU, the game. AI-assisted: Claude Opus 5.5 (Anthropic) ran the check with pullrequest-sandbox and wrote this text. No game data. |
|
checked: #7998536c850 | with:
Called as a portability check (macOS, Python 3.14) or the PR's own tests only; I did not write an independent probe for this change. agent: yes |
Claimed in the coordination issue as RT-566: #7804 (comment) (earlier claimed by pulria).
What and why
The boot chain (
docs/retail_boot_chain.md) finds the next device slot by running the title, one stop at a time. This PR addstools/d3d12_device_calls.py. It reads the file alone and reports the statically resolvedID3D12Devicevtable call sites for the device paths it follows. Slot owners can see which slots are coming before the run reaches them. This is a measurement, not a claim on any slot.--outis required. The tool writes two files there and prints the text one:<exe>.device_calls.txt: slot numbers and counts only<exe>.device_calls.json: the same, plus each site's RVA for local follow-uptools/gdk_runtime_calls.py's x86-64 decoder andtools/import_call_sites.py's import-table reader.docs/retail_boot_chain.md§5 explains how to run it and what it shows.Method
Find the creator calls. These are the
D3D12XboxCreateDevice/D3D12CreateDevicecall sites, in any of three forms:call [rip+IAT]callto the import thunkcall regaftermov reg,[rip+IAT]Follow the out-pointer in
r9.lea r9,[rip+G]makesGa device global.lea r9,[reg+disp]means that slot holds the device after the call.Walk the functions that reference a device global (bounds from
.pdata).jmpor conditional branch to a later address in the function carries what is known at the branch to its target. At the target it is met with the fall-through state: a fact is kept only when both paths agree. Past aretor unconditional jump, the carried state is used alone.jmpout of the function is a tail call. Ajmpback into the function (a loop) carries nothing.Count the sites. A site is a vtable load from the device (
mov v,[dev]) followed by one of:call [v+disp]mov m,[v+disp], thencall mrax. The routine has to be verified first: its code (forcall [rip+p], the code the file's pointerpholds) must reachjmp raxorcall raxwithin 16 instructions, without writingrax, calling or returning before that. Verified targets are cached. Any other target is reported as not resolved, never as a slot.The slot is
disp / 8. Ajmpin place of the call counts as a tail jump.Record where the device is at each site:
rcx, orrdxfor the return-buffer form (§3.1). The argument count is an estimate.Slot names:
ID3D12Devicenames. The console keeps that order at the slots where it was measured (8, 9, 14, 26, 36).runtime/shims/d3d12_xs_device.handdocs/retail_boot_chain.md§3 already name get a name.Limits
The report holds the statically resolved sites for the device paths the tool follows. A slot can be called more often than the report says, or on a path the tool doesn't follow. A slot with no row (12 and 51, for example) is not shown to be uncalled.
The tool does not see:
It counts what it can't resolve, instead of guessing:
raxto a target that isn't a verified dispatch routineThe census on my 1.0.2.1 copy
Slot numbers and counts only:
D3D12XboxCreateDevicecall site; its out-pointer is a global.QueryInterfaceReleaseCreateCommandQueue(console measured)CreateCommandAllocator(console measured)CreateDescriptorHeap(console measured)GetDescriptorHandleIncrementSizeCreateRootSignatureCreateConstantBufferViewCreateShaderResourceViewCreateUnorderedAccessViewCreateRenderTargetViewCreateDepthStencilViewCopyDescriptorsSimpleGetResourceAllocationInfoGetCustomHeapProperties(console measured)CreateCommittedResourceCreateFence(console measured)CreateQueryHeapCreateCommandSignatureCreateCommandQueueXCreateComputePipelineState(console form)CreateComputePipelineStatefrom native codeCreateCommandListXSetFrameIntervalXScheduleFrameEventXWaitFrameEventXCreatePlacedResourceX(shape)How this compares with the docs and open PRs:
rdx(return-buffer) form appears at slots 25, 26 and 108 only. That agrees with d3d12_xs: device slot 26 takes the return buffer in RCX and the device in RDX, as the retail executable calls it (RT-5) #6964 and d3d12_xs: device slot 25 cleans the Xbox layout word and flag bits on a copy before the PC GetResourceAllocationInfo (retail boot chain stop 16) #7110 for 25 and 26, and with pulria's note on 108.Tests
python -I tests/test_d3d12_device_calls.py(15 tests) runs on a PE built by hand: one import,.pdata, ten functions, and extra code that some tests add. It checks that:call [v+disp8]call raxthrough a copied globaljmp raxstub, with the device inrdxjmp raxjmpinside the function is a branch, not a tail call. This is pr-sorter's repro:jmp rel32 +3over threenops in place of two instructions. Slot 14 is still counted and the passed-device count stays at 1. The short form and a backward jump are checked too.raxand handed to a helper that only returns is not counted as a slot; it is reported as not resolved. This includes shdann's repro from the review: the slot 26 site retargeted to such a helper..pdatafunction and in a byte window with no.pdataentry.--outis required.Other checks:
python3 -I -m compileall -q make_game.py tools testspasses.tests/test_gdk_runtime_calls.pyandtests/test_import_call_sites.pypass.test_docs_repo_pathspasses with the new paths.test_docs_cli_flags,test_docs_linksandtest_docs_design_rowsfail exactly as onmain, on files this PR doesn't touch.Tested on Linux with Python 3.14. No GPU or driver is involved: this is a static read of the file, and the census run takes about 5 s.
Checklist
python -I, writes only under--out.AI-assisted (Claude Code, Claude Opus 5.5).