Repository navigation
runtime, d3d12: both runtimes write an import call trace, and a tool compares two (RT-CALL-TRACE, D3D12-CALL-TRACE) - #2807
ubiquitarianism wants to merge 9 commits into
Conversation
Rules both runtimes read (gta6rt includes it, leonida-loader parses it) so their LEONIDA_CALL_TRACE traces are comparable. Not run in game.
Reads the LEONIDA_CALL_TRACE v1 traces of gta6rt and leonida.exe, pairs threads (main; then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only, and the calls still open at the end of each thread. Streams the input (about 150 bytes per call). Tested: python -I tests/test_call_trace_diff.py (Ran 76 tests, OK); tests/test_text_write_line_endings.py OK; two synthetic 1M-call traces: 14.0 s / 336 MB peak. Not run in game.
…ALL_TRACE) Every IAT slot of the title image and its DLLs (normal and delay) is traced by import identity when LEONIDA_CALL_TRACE=<new file> is set (size cap LEONIDA_CALL_TRACE_MAX_MB, default 4096); unset, wrap returns the address unchanged and no thunk block is allocated. Per-import 24-byte thunk into the common stub (entry-only E / wrapped C+R), writer and rules as in tools/call_trace_rules.def (hash in the header). New leonida-loader call_trace module with 23 tests (stub bytes against their assembler source, 20 integer args, floats, struct return, last error, panic through the stubs, nesting, classes, 4 threads across a view boundary, killed child, size cap). Tested: cargo test -p leonida-loader: 96 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
LEONIDA_CALL_TRACE=<path> (cap LEONIDA_CALL_TRACE_MAX_MB, default 4096) records every call through the import tables of the main image and the title DLLs in the shared v1 format, with the rules of tools/call_trace_rules.def. Each import slot gets a 24-byte thunk to one of two common stubs (entry-only: jump, real return address; wrap: frame, C and R lines), registered with RtlAddFunctionTable. The file is created new, written through 4 MiB mapped views. Shims read their caller through RT_CALLER(), which sees through the wrap frame; unset, wrap() returns its target. runtime/test/call_trace_test.cpp (ctest call_trace) and tests/test_call_trace_rules.py cover it. Tested: full runtime build (RelWithDebInfo) passes; ctest on the 149 non-GPU tests that cannot open a Vulkan device or window: 100% tests passed, 0 tests failed out of 149; python tests of the rules, line endings, docs env vars pass. Not run in game.
…s, unset-switch no-ops) Tested: cargo test -p leonida-loader: 99 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
…skip __vdecl math From the second review: a wrap frame would end the title's stack walks at the stub and SVML vector math passes arguments in YMM registers the stubs do not keep. Not run in game.
Tested: Ran 79 tests in 22.512s ... OK (test_call_trace_diff.py); Ran 3 tests in 15.268s ... OK (test_text_write_line_endings.py). Not run in game.
…ed writer lock) Tested: cargo test -p leonida-loader: 102 + 2 + 1 passed; cargo test -p leonida-hle: 211 passed, 2 ignored; build -p leonida --profile diag --features diagnostics,mimalloc ok. Not run in game.
…lock, caller in helpers) The entry stub's RUNTIME_FUNCTION now ends before its final jmp [r10], so a stack walk there finds the return address. The writer lock is taken with a 10 ms bound: a dropped record is counted and the next one writes `# dropped <count>`. The next view is mapped ahead so a failed remap still ends the file in `# truncated`. title_free_impl and create_file_w take the caller from the exported shim; a failed VirtualProtect deletes the function table; pe_loader builds the module name only when tracing. Rules: 205, hash 873cd3bb78a70bc5. Tested: full runtime build passes; ctest on the 149 non-GPU tests: 100% tests passed, 0 tests failed out of 149; xmem alone: 1/1 passed; xs_proxy_mock|xmem_: 100% tests passed, 0 tests failed out of 13; python -I tests/test_call_trace_rules.py OK. Not run in game.
|
Verified by OreoFR on macOS 27.2.1, Apple M5, head MEASURED
READ IN CODE
ASSUMED
AI-assisted: Claude Code |
|
Verified in all three layers it touches, on Windows, and none of them fails.
Python (the two suites it adds): C++: Those three error lines are the test doing its job - it drives the refusal paths and prints them - and Rust (six files under That failure is not this pull request's: it is What I could not test: a real import call trace from a title - that needs the game and the two runtimes the note describes, and this is a 24 GB desktop, not the 8 GB laptop the trace was written for. The diff tool and its rules are what the 88 Python tests cover, and they are green. One thing worth saying about the size: +6,558 across 23 files is a lot to review, and the shape helps - 795 lines of C++ test, 1,189 of Python tests, 731 of tool, 236 of rules, and the rest is the runtime hooks the notes describe. The tests are two thirds of it, which is the right ratio for a diagnostic that has to be trusted. AI-assisted: yes - DeepSeek v4.1 (flash), which ran all three layers on the machine above. Written with an AI assistant. |
KelboLive
left a comment
There was a problem hiding this comment.
The tracer is sound. Off costs nothing — wrap returns the target and allocates no thunk (call_trace.h:700) — and on is one atomic per call plus a bounded writer lock, with the line formatted and sequenced inside the lock (:442-520), so lines cannot interleave. The stream is capped (:361, call_trace.rs:796) and goes through 4 MiB mapped views, so RAM does not grow with the trace. Every test I ran passes: call_trace ctest, 79 test_call_trace_diff tests, 9 test_call_trace_rules, 29 Rust call_trace tests. Mutation: removing the return comparison in compare_thread (tools/call_trace_diff.py:519) fails 12 tests, so the diff's core is genuinely pinned.
One unbounded path, and it is a real inconsistency between the two runtimes:
call_trace.rs:865treats an unparsable or0LEONIDA_CALL_TRACE_MAX_MBas 4096 silently, andmb.saturating_mul(1 << 20)turns a parseable but huge value into no cap at all.gta6rtrefuses both cases with a message and exit 2, and its test asserts that (call_trace.h:577-590). Make the Rust parser match the C++ one, and never let a value saturate to "unbounded".
Two more, in the tool:
rules differ,truncated=yesand a missing header only warn and can still exit 0 (test_differing_rules_print_a_warningasserts exactly that). A script reads 0 as "identical", so give those a distinct exit code — a rules mismatch means the traces are not comparable at all. A warning when both sides report the samestack=would also help.case_dropped_record's wall-clock< 100 msis load-dependent (the body already saw it fail under-j8); assert the drop count and the# droppedordering, keep the timing as a print.
Documentation worth one line in the README: the trace records identity and the return class, no arguments and no strings — so a divergence that lives only in an argument is invisible to the diff (a hash of the first argument qwords would be safe, unlike strings). And RT_CALLER's 0x140 duplicates the stub's 0x138 frame by hand — a static_assert against the blob would keep them tied.
|
A heads-up for this pull request: the page of D3D12 switches ( Nothing checks that today, so the page has drifted before (it was a name behind when this was measured). A test that checks it is waiting to be opened (DOCS-SWITCHES-PAGE-CHECK), and it would make this pull request's CI red until the page is written again. One command does that: It writes the page with the names in it and nothing else; the diff is the new rows. |
|
Confirmed the Rust/C++ trace-cap mismatch under Wine on AI-assisted with OpenAI Codex. |
|
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the current head merged onto current
Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code). |
|
Ran natively on Windows 11, head Stock tests (measured)
1. The two runtimes write different names for the same import (reading, then measured)
I ran the same calls through both writers with throwaway children: a 200-character import name, a title module with a 40-character name, and an unimplemented import in
To see what the tool makes of each one, I built three pairs of synthetic traces. In each pair, everything is the same except that one field, written the way each runtime writes it:
So each mismatch shows up as a divergence on every call it touches. As an illustration of how long decorated names get (this is not a claim about what the title imports): the system 2. Cost per call (measured, release build, one thread, 10^6 calls each, a trivial target)
With these short names, a wrapped call writes about 72 bytes (115.1 MB for 1.6 M calls) and an entry-only call about 51. At that rate the default 4096 MiB cap holds roughly 60 million wrapped calls. 3. Contention (measured, Rust, production 10 ms lock bound) There were 1.6 million wrapped calls in total, split over 1 to 64 threads that do nothing but call:
In every run there were no open C records, and the file had exactly two records per call plus one T line per thread. Throughput levels off at about 1.6 M calls/s for the whole process, and no record was dropped at any thread count. 4. Kill under load (measured, Rust) A child ran 4 threads calling a wrapped import in a loop, then called 5. Size on disk (measured, both writers) The file grows in whole 4 MiB views and is never cut back to its content:
This is harmless for the tool, which strips the NULs. But a 1 MiB cap gives a 4 MiB file, so the README could say the cap counts content, not size on disk. 6. The tool on malformed input (measured,
The last row is the only crash I found. It is artificial, but it exits with 1, the code the tool documents for "divergences". A Not checked: whether the title's real module or import names reach these limits, the full CMake build and GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code). |
|
Checked the Python side on Linux against current
Defects
Not checked here: the C++ Verdict: defects. Regenerate the switches page on current AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. Generated by Claude Code |
|
RUN (independent run on Windows, head The merge is clean (no conflict). Windows 11, release profile, one shared target directory. No game files, no GPU run, no What the PR is. An opt-in import call trace ( Green
The Red
Review
Not covered
VerdictPARTIAL. The new tests and the diff tool pass and the mutations are caught, and the switch is off by default. But the merge with current AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge. |
|
RUN (in game, batch of five pull requests), each head merged with
For reference, the same machine and route rendered 13.3 to 17.2 fps on other batches today. These fps are a check that nothing fell over, not a measurement of a gain. Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. #3247 has since moved to Limits: one run; arrival in the world was driven by keys and not checked on pictures; AI-assisted (Claude Code). |
Claimed in the coordination issue as: RT-CALL-TRACE and D3D12-CALL-TRACE (#2570 (comment))
What and why
When gta6rt and leonida.exe stop at different places in the boot, there is no record of which import call they first handled differently. With
LEONIDA_CALL_TRACE=<new file>set, both runtimes now record every call through the import tables of the title's image and its DLLs (normal and delay-load) in one shared v1 text format. Unset, nothing changes:wrapreturns the import's address and no thunk block is allocated.tools/call_trace_rules.def: the rules both runtimes read (gta6rt includes it, leonida-loader parses it), so the two traces are comparable. Stack walks andRtlCaptureContext2are entry-only (a wrap frame would end the title's stack walk at the stub), and__vdeclvector math is skipped (its YMM arguments are not kept by the stubs).Eline, real return address) or wrapped (CandRlines with the return class). The stubs are registered for unwinding; the entry stub's unwind range ends before its final jump.LEONIDA_CALL_TRACE_MAX_MB(default 4096). The writer lock is taken with a bound of about 10 ms; a record that cannot get it is dropped and the next one writes# dropped N.RT_CALLER(), which sees through the wrap frame.tools/call_trace_diff.pypairs the two traces' threads (main first, then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only and calls still open at the end. It streams its input (two synthetic 1M-call traces: 14.0 s, 336 MB peak).Not run in game.
Tested
Windows 11 (26200), Visual Studio 18 (2026) MSVC, AMD Radeon RX 6800 (driver 32.0.21030.2001), rebased on
mainat66b5d0433:cargo test --profile diag -p leonida-loader --lib -- call_trace: 29 passedctest: 205 of 205 passed, 2 disabled (gameinput,gameinput_script, no SDL3 here)python -I tests/test_call_trace_diff.py,tests/test_call_trace_rules.py: OK;python -m compileall -q tools tests: OKscripts/check_no_game_data.pyon the changed files: OKOne full
ctest -j 8run failedcall_trace(and the unrelatedwindows_crash_monitor); both passed alone and in the next full-j 8run.case_dropped_recordchecks that a dropped call takes under 100 ms of wall time, which a machine running eight test jobs can exceed. The failing run's output was not kept, so that cause is likely, not confirmed.