Skip to content

Stubs: record R8/R9 argument registers of stub calls in the report - #2722

Open
amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/stubs-record-r8-r9-argument-registers-081516
Open

amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/stubs-record-r8-r9-argument-registers-081516

Conversation

@amazedturnip

@amazedturnip amazedturnip commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Record the 3rd/4th Win64 argument registers (R8/R9) at stub-thunk call time and surface them in report.json as first_args/last_args per called stub, to diagnose which console slots actually receive which values. Args are kept in a side table keyed by the StubInfo pointer so no StubInfo fields or thunk bytes change (avoids overlap with open #936/#1155). Tests pin first/last/call-count and serde on/off; verified on the AMD Radeon iGPU retail build.

What is in it

  • crates/xcl/src/stubs.rs: stub_report now takes (r8, r9) and records first/last R8/R9 per stub in a side-table keyed by the StubInfo pointer (no StubInfo field changes, no thunk-bytes changes).
  • crates/xcl/src/report.rs: StubCall gains optional first_args/last_args (hex, serde default + skip_serializing_if empty); build() emits them from stub_args.
  • crates/xcl/src/stubs_args_tests.rs (new sibling test module): thunk call records first/last R8/R9 and call count; argless record_call leaves the side table empty; StubCall with args serializes them, without args omits them.

Tested

Regression run
main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 60 44 0
device removals: 0
crashes: 0
peak commit: 13978 MB

PR:

xcl-smoke v1
commit: 315e3f85e2eb51a490643560fca3e91c52d3c6be
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1552 (PresentX 1552)
presents per 2 s (last 3): 4 59 60
device removals: 0
crashes: 0
peak commit: 14106 MB

Not tested

  • NVIDIA wave32 GPU (verified on AMD Radeon native wave64)

AI use

  • Local AI (thinkingmachines_inkling-2-mini) assisted with diagnosis, implementation, tests, review, and description; all tests executed locally on AMD Radeon (native wave64).
  • Claude Code (Claude Opus 5.5) edited this description: removed an internal note, and put in the test counts and both smoke blocks rerun on the current head.

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a concurrency issue in the new R8/R9 diagnostics at head 77158b0 (base b49be18). This is a source-derived review; I did not run a native concurrent title test.

record_call_with_args assigns the call ordinal with fetch_add and stores first_caller before taking the ARGS mutex. If call A gets ordinal 0 and pauses during first-call logging, call B can get ordinal 1 and insert B's arguments into the empty side table. A then acquires the mutex and overwrites the last arguments. After both calls, the report can say first_caller=A, first_args=B, and last_args=A. Neither argument pair matches the ordinal implied by its label.

Could the side table record the first/last ordinal alongside the arguments and update each field only when the incoming ordinal is earlier/later, or otherwise serialize ordinal assignment with the table update? A two-thread fixture that forces the first caller to enter the table second would cover the first and last fields. Logging and hooks can remain outside the mutex.

AI assistance: GPT-6.2 Sol identified the interleaving; GPT-6.2 Astra independently checked the exact-head source and wording.

@amazedturnip

Copy link
Copy Markdown
Contributor Author

Fixed per the review: the ARGS side table now records (first_ord, last_ord, first_r8, first_r9, last_r8, last_r9) per info and updates each field only when the incoming ordinal is strictly earlier/later. Ordinal assignment still happens via fetch_add before the ARGS mutex (logging/hooks remain outside), but no field is overwritten by an out-of-order caller now. A two-thread fixture (ordinal_first_caller_arriving_late_still_records_as_first_and_last) forces caller A (ordinal 0) into the table second via a test-only pause hook; the test asserts A's args land as first_args and B's as last_args. All stubs tests pass (9/9).

@amazedturnip
amazedturnip force-pushed the xcl/stubs-record-r8-r9-argument-registers-081516 branch from 77158b0 to 315e3f8 Compare November 26, 2026 09:54
@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2722 at 315e3f85e2eb51a490643560fca3e91c52d3c6be (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted Win11 / RTX 4060 release unit tests (315e3f85)

  • cargo test --release -p xcl --lib stubs_args_tests:: -- --nocapture: 4 passed, 0 failed, 0 ignored (0.00 s, exit 0), covering ordinal_first_caller_arriving_late_still_records_as_first_and_last, thunk_records_first_and_last_r8_r9_args, record_call_without_args_leaves_side_table_empty, and stub_call_serializes_args_only_when_present.
  • cargo test --release -p xcl --lib stubs_args_tests:: -- --test-threads=4 (3 consecutive parallel stress passes): 4 passed, 0 failed, 0 ignored × 3 (0.00 s each, exit 0).
  • cargo test --release -p xcl --lib stubs:: -- --test-threads=4: 7 passed, 0 failed, 0 ignored (0.02 s, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib report:: -- --test-threads=4: 1 passed, 0 failed, 0 ignored (0.10 s, 0 skipped, exit 0).

Observations

  • The updated ARGS side-table ordering fix (ordinal_first_caller_arriving_late_still_records_as_first_and_last) and all stubs_args_tests::, stubs::, and report:: tests passed cleanly in --release on native Windows 11 26200, including 3 consecutive parallel --test-threads=4 stress runs with zero flake.
  • Live report.json verification on the 60 s retail smoke: called_stubs recorded 9 entries total, with 1 thunk-captured entry cleanly serializing both first_args and last_args (two hex R8/R9 values each) and the other 8 entries omitting both fields as expected.
  • Quiet 60 s retail smoke ran cleanly (exit: 0x0, 1545 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 14014 MB peak commit vs parent b49be183's 14018 MB / 1518 frames).

Paired 60 s RTX 4060 smoke (b49be183 vs 315e3f85)

Parent origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2722 head (315e3f85):

xcl-smoke v1
commit: 315e3f85e2eb51a490643560fca3e91c52d3c6be
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1545 (PresentX 1545)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14014 MB

Limits of coverage

  • Full workspace test suite was not re-run on 315e3f85 (only targeted stubs_args_tests::, stubs::, and report:: release tests plus paired quiet 60 s smoke).
  • Native Windows 11 (26200) / x86-64 RTX 4060 only; no Wine/Linux run on this host.

AI use

Ran the targeted release unit tests, paired quiet 60 s smoke runs, and report.json field check with assistance from Google Antigravity (Gemini 4 Neon); all test counts, report.json statistics, and smoke blocks were taken directly from cargo test, report.json, and scripts/smoke.ps1 outputs.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
@futurepro62

futurepro62 commented Nov 30, 2026 •

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by Decodere, since none of them covers AMD. Tested exact head 315e3f85 (on its base b49be18).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace --no-fail-fast -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::bridged_dpp_agrees_with_hlsl_on_the_gpu --skip hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap --skip gpu::dxil::fuzz_tests: 1427 passed, 0 failed, 45 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: ordinal_first_caller_arriving_late_still_records_as_first_and_last, thunk_records_first_and_last_r8_r9_args, record_call_without_args_leaves_side_table_empty, stub_call_serializes_args_only_when_present.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace --no-fail-fast -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 --skip two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs: 1438 passed, 0 failed, 47 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 53e85fb1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, bridged_dpp_agrees_with_hlsl_on_the_gpu (no wave64 on this card) and two_pass_binds_set_the_shared_view_heap (heap windows are opt-in, XCL_HEAP_WINDOWS=1) fail the same way; gpu::dxil::fuzz_tests stays skipped as in earlier runs (seeds 70, 545, 1019 and 1507 failed CreateComputePipelineState with E_OUTOFMEMORY on this card; they passed on this main's baseline). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs fails on main too, since Tests: compare benchmark regression thresholds #2959 (Tests: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs fails on an AMD RDNA2 iGPU since #2959: one two-pass state outlives its PSOs #3441). (Edited: this line first named the wrong merge.) The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check claim
head: 315e3f8

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:tests Unit, integration, e2e tests, or testtitle needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 315e3f8

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 315e3f8
merge: clean (trial merge b0147c63cae4de8bd882ebd89340fbb7e1371533; git diff --check clean; +188/-7 in crates/xcl/src/report.rs, stubs.rs, new stubs_args_tests.rs)
build: cargo build --workspace -> ok (pre-existing warnings only, none from the PR's lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2889 passed, 1 failed, 51 ignored (base + 4 new tests); SKIPPED: 27, the standard set for this card (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"). Failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 — pre-existing on this machine, identical on base 9dfbe3e. All four new tests pass here, including the forced-race ordinal fixture.
review: read the whole diff and the surrounding code. The change records the R8/R9 registers (3rd/4th Win64 arguments) of each stub call — first and most recent per stub — into report.json as first_args / last_args, so a stubbed function's callers can be identified by the objects they pass. I checked the ABI: the generated thunk (stubs.rs:164-174) only touches RCX/RDX/RAX/RSP before call rax, so R8/R9 at stub_report entry are the guest call's original 3rd/4th arguments, and its 0x28 shadow reservation already covers four arguments; the thunk machine code itself is unchanged, and the only call site that needs the new parameters is the thunk itself (the Rust-side record_call path for D3D12.X guards and real.rs:11744 is untouched and leaves the side table empty, so the report fields are omitted there). The first/last labeling uses the fetch_add ordinal taken before the table update, with strictly-earlier/later updates under the ARGS mutex, so a caller that grabs ordinal 0 but enters the table later still records its args as first; the test-only pause hook (consumed on use, None in release) forces exactly that race in a two-thread fixture, and the first-call log and hook run outside the mutex. The serde fields are additive with default + skip_serializing_if, so old report.json files still deserialize and unthunked stubs serialize as before; only report.rs:240 constructs StubCall. I verified all four new tests' assertions by hand (thunk first/last capture, the late-ordinal fixture's 0x0A01/0x0B01 expectations, the empty-side-table case, and the serialize-only-when-present JSON check). Thread: Decodere's RTX 4060 release run passed the targeted tests (with three consecutive parallel stress passes) and a paired 60 s retail xcl-smoke (1545 vs 1518 frames, no crashes, peak commit 14014 vs 14018 MB) with a live report.json check (1 thunk entry carrying first_args/last_args, the other 8 stub entries omitting both); futurepro62's full workspace runs on an RTX 5070 Ti (1427/0/45) and the RDNA2 iGPU of a 9800X3D (1438/0/47) pass with only that rig's known skips. No duplicates; only the three listed files, no unsafe added beyond the pre-existing transmute of the hook pointer, no new dependencies, no stop-criteria files.
performance: none; one extra mutex section per stub call for thunks, the first-call log and hook stay outside it.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@brainhay5

Copy link
Copy Markdown

merge-check
base: 9dfbe3e
head: 315e3f8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2888 passed, 2 failed, 51 ignored; 29 SKIPPED lines; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, test_title_runs_and_game_folder_is_untouched — both fail on the base alone (each re-run on 9dfbe3e and reported FAILED there), so neither is this PR's
review: one logical change in 3 files (+188/-7), well inside the size target. The subtle part is the race between ordinal and arrival: a caller can take ordinal 0 and reach the side table after a caller that took ordinal 1, so "first" cannot mean "first to insert". This handles it correctly — record_call_with_args takes the ordinal first, then holds the side-table mutex across the update and replaces first/last by ordinal comparison — and the new test forces exactly that interleaving through a #[cfg(test)]-only hook, so it cannot fire in a release build. Storing args in a side table keyed by the StubInfo pointer rather than adding fields keeps the thunk bytes and StubInfo layout untouched, which is what lets it avoid the overlap with #936/#1155 the description mentions. report.json stays backward compatible: first_args/last_args are Option<String> with serde(default, skip_serializing_if), so stubs with no recorded args serialize exactly as before. The four-argument stub_report matches Win64 (RCX/RDX/R8/R9), so R8/R9 are the 3rd/4th console arguments without any thunk change — consistent with the description. Tests cover first/last/call-count, the argless path leaving the table empty, and serde with and without args. No duplicate: searched open and merged PRs for the same subject and only this PR matches. Nothing to stop it.
performance: one global mutex acquisition plus a map lookup per stub call, in release builds, whether or not a report is ever built. Stub calls are console API calls rather than per-draw work, so this is very likely negligible — but it is on a shared path, and if a title turns out to be stub-heavy under many threads it would show up as contention. An env-gate would remove even that doubt; I would not hold the PR for it.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 315e3f8

No open or merged PR records stub arguments in the report. The thunk in stubs.rs only sets rcx/rdx before calling stub_report, so r8/r9 still hold the title's 3rd/4th arguments, as the PR relies on.
One cost to check: record_call_with_args now takes the global ARGS mutex and does a HashMap lookup on every stub call. Before, a call was only an atomic fetch_add. That may matter for stubs a title calls many times per frame.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:tests Unit, integration, e2e tests, or testtitle ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants