Skip to content

xcl run: scripted XCL_PRESS_* times count from guest entry, not host start - #2933

Open
3L1A5-1 wants to merge 2 commits into
xcl-dev:mainfrom
3L1A5-1:fix/scripted-input-from-guest-entry
Open

3L1A5-1 wants to merge 2 commits into
xcl-dev:mainfrom
3L1A5-1:fix/scripted-input-from-guest-entry

Conversation

@3L1A5-1

@3L1A5-1 3L1A5-1 commented Nov 27, 2026 •

Copy link
Copy Markdown

XCL_PRESS_AT / XCL_PRESS_A_AT compared their schedule with the host's uptime (log::uptime(), the log's clock). The startup shader preparation runs before the guest is entered (host.rs, preparation::before_guest) and can take longer than the whole script, so on a cold preparation (about 38 minutes on the machine below) every scheduled press was already in the past when the title first polled its input: the title then stayed on its first screen for the whole run.

The schedule now counts from the moment the title's entry point is called (after preparation and loading); before that nothing is pressed. The log's times are unchanged.

What is in it

  • crates/xcl/src/log.rs: mark_guest_entry() records the instant, guest_uptime() returns the seconds since it (None before).
  • crates/xcl/src/loader.rs: one call to mark_guest_entry() in main_thread, immediately before the mapped entry point is called (moved there from host_main after review: ettehn measured that the earlier marker still lost ~0.4 s of the schedule to runtime init and loading).
  • crates/xcl/src/hle/gameinput.rs: scripted() uses guest_uptime() through a pure press_held(at, t); the doc comments for XCL_PRESS_* now say the schedule counts from the title's entry point. New unit test scripted_presses_count_from_guest_entry. (README does not mention XCL_PRESS_*; HANDOFF.md line about XCL_PRESS_A_AT=s1,s2… ("at those seconds") is still right if read as "of the run", not edited.)

Tested

  • Hardware: NVIDIA RTX 2060 SUPER 8 GB, driver 617.14; Intel i5-9400F, 16 GB RAM; Windows 11 (26300); rustc 1.100.0; debug build for the tests, release for the smoke runs.
  • cargo check -p xcl: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on this head 2a318283 (after cargo build --workspace): 1446 passed, 1 failed, 47 ignored. SKIPPED lines: 29 (21 no wave64, 3 no D3D12 debug layer, 3 f16 per-lane form refused (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 1 cannot disable the driver cache, 1 no heap windows). The one failure is hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit (segment count 199 vs 421). It passes when run alone, 2 of 2 on this head and 2 of 2 on main 8b957bec, so it looks like a parallel-run flake in code this PR doesn't touch. The first commit 1286ef91 had 1447 passed, 0 failed.
  • The new test fails without the fix: with press_held treating "guest not entered" as a time inside the schedule (the old behaviour: the preparation time counts) it fails with left: 4, right: 0 (an A press fires during preparation); with the fix it passes.
  • Where it showed up: a scripted 300 s run on nvidia-dev eff3bcab (same code in gameinput.rs) after a 38.5-minute cold preparation. All XCL_PRESS_A_AT presses had fired before guest entry, and the title stayed on its first screen (0 DirectStorage reads, flat draw count). The same script with a warm cache (preparation ~1 min) reached the world. That run was not repeated with this fix.

Regression run
Two 60 s scripts/smoke.ps1 runs on the same title, back to back, warm shader cache, on the machine under Tested (RTX 2060 SUPER 8 GB). Both runs had the same environment set in the calling shell (our usual 8 GB recipe; it keeps the shader cache warm on this PC):

XCL_COHERENT_MB=2048
XCL_DEVICE_TYPE=lockhart
XCL_DIRECT_DXIL=1
XCL_GFX_PSO_WAIT_MS=200
XCL_HEAP_WINDOWS=1
XCL_PRESS_A_AT=40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,140,160,180,200,220,240,260,280,300,360,440,520,600,680,760,840,920
XCL_PSO_IMAGE_SKIP=1
XCL_PSO_WAIT_MS=50
XCL_TEXTURE_LEVEL_PAGES=1
XCL_TEXTURE_SAFE_READ=1
XCL_TWO_PASS_MB=1024
XCL_UMA_WINDOWS=16
XCL_WATCH_HOT_MS=60000

main 8b957bec:

xcl-smoke v1
commit: 8b957bec6f82495aec940944c6bf47faa02db590
gpu: NVIDIA GeForce RTX 2060 SUPER
title: 5c554abc
seconds: 60
exit: 0x0
frames shown: 865 (PresentX 866)
presents per 2 s (last 3): 56 50 28
device removals: 0
crashes: 0
peak commit: 17179 MB

This PR's head 2a318283:

xcl-smoke v1
commit: 2a3182839a42201d9ec4f2229c9f205b696832be
gpu: NVIDIA GeForce RTX 2060 SUPER
title: 5c554abc
seconds: 60
exit: 0x0
frames shown: 886 (PresentX 886)
presents per 2 s (last 3): 51 54 49
device removals: 0
crashes: 0
peak commit: 17034 MB

Head: 0 device removals, 0 crashes, 102 % of main's frames, 99 % of main's peak commit. XCL_PRESS_A_AT is in that environment. In the main run its early presses fired during the preparation, and in the head run they land after the title starts (the change itself). So the frame counts are a pass/fail check, not a measurement of the fix.

Not tested

  • A full game run with XCL_PRESS_A_AT set across a long cold preparation; the mechanism follows from the code and the unit test. scripts/smoke.ps1 sets no press schedule, so the smoke runs only show that nothing else changed.
  • AMD GPUs, other drivers.

AI use

  • Claude Code with Claude Sonnet 5.5 wrote the change, the test and this description; Claude Opus 5.5 reviewed and orchestrated.

🤖 Generated with Claude Code

…start

The scripted presses (XCL_PRESS_AT / XCL_PRESS_A_AT) compared the schedule
with the host's uptime. The startup shader preparation runs before the
guest and can take longer than the whole script, so every press was
already past when the title first polled its input: a cold preparation
consumed the schedule and the title then stayed on its first screen.

Record the moment preparation returns (log::mark_guest_entry) and count
the schedule from it; before it nothing is pressed. The decision is a pure
function (press_held) with a unit test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Paired native Windows test of actual guest-visible GameInput readings after startup preparation. Clean release 8b957bec6f82495aec940944c6bf47faa02db590 vs 1286ef910ba0c482d3f6f7e71d4cd1a105f584f1, RTX 5070 Ti Laptop / 621.24, Windows 11 26200.9974, Rust 1.97.1 MSVC, DXC/DXIL 1.8.2502.11. A synthetic test executable polled the XCL GameInput HLE for 750 ms from its own main; each launch built 1,120 PSOs from 160 synthetic shader records with a fresh XCL cache. All exited 0.

  • XCL_PRESS_A_AT=0.3, XCL_PRESS_AT=0.4:B: base missed A and B in all three runs; head saw both in all three. Guest entry on the host clock was 1.349–8.236 s across these runs. This verifies the preparation-time fix through xcl run, not just the helper.
  • The clock still starts slightly before the mapped guest runs. On the head, A and B were already held at the first guest reading with the schedule above. With XCL_PRESS_A_AT=0.01, XCL_PRESS_AT=0.55:B, three more head runs missed A every time and saw B begin 138–149 ms into guest main (roughly 0.40 s had already elapsed on the schedule clock at guest entry). The marker precedes runtime initialization and loading. If the intended origin is the actual guest entry point, I would move the marker to loader::main_thread just before calling the mapped entry point. If the intended origin is the end of preparation, the docs could name that directly.

No retail title in this test. OpenAI Codex (6.2sol) assisted with verification.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Follow-up tested on top of 1286ef9: I moved the single crate::log::mark_guest_entry() call from host_main to loader::main_thread, immediately before the call to the mapped PE entry point. This leaves the host log clock unchanged.

Same native Windows / RTX 5070 Ti Laptop setup and synthetic GameInput guest as above, clean XCL caches, XCL_PRESS_A_AT=0.01 and XCL_PRESS_AT=0.55:B. The original head missed A 3/3 and delivered B at 138–149 ms from the fixture's Rust main. With the marker moved, all three runs delivered A at 13.1–13.7 ms and B at 555.6–557.3 ms. Every run exited 0 and prepared 1,120 PSOs with 0 refusals. This verifies the mapped-entry origin for the two scripted input options. It does not cover input polled from TLS callbacks or a retail title. OpenAI Codex (6.2sol) assisted with the patch and verification.

The marker moves from host_main (right after shader preparation) to
loader::main_thread, immediately before the call to the mapped PE entry
point, so runtime init and loading are not counted either (about 0.4 s
of the schedule was lost before).

Suggested and verified by ettehn in review.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@3L1A5-1

3L1A5-1 commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks @ettehn, that's a clear measurement. The entry point is the right origin. Adopted as 2a318283: the single mark_guest_entry() call moved from host_main to loader::main_thread, immediately before the mapped entry point is called. The docs now say the schedule counts from the title's entry point. cargo check -p xcl passes, and the gameinput, log and loader unit tests pass (16/0). The PR description is updated. The smoke blocks for the new head are still pending on our side, so this stays a draft until they're in.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
@3L1A5-1
3L1A5-1 marked this pull request as ready for review November 27, 2026 05:52
@KDenKC

KDenKC commented Nov 27, 2026

Copy link
Copy Markdown

Heads-up on an overlap, so the two don't conflict: #2637 (frame-matched input rules) carries a fix for the same press clock in da59a507. It adds gameinput::start_script_clock() with its own INPUT_EPOCH, started in host_main just before loader::run_main.

@ettehn's measurement here applies to ours as well. That marker still sits before the TLS callbacks, log::flush() and the CreateThread of main_thread, so it loses part of the schedule the same way. Yours, in main_thread immediately before the entry point, is the better origin, and keeping log::guest_uptime() in log.rs makes it usable outside GameInput too.

So our plan is to drop INPUT_EPOCH/start_script_clock() from #2637 and drive both the XCL_PRESS_* schedule and the frame-rule timestamps from your guest_uptime(), rebasing once this lands. If it helps, we can also run this head in the retail title on an RTX 5090. There, startup shader preparation takes about 60 s on a warm cache, and on main scripted presses are lost during it.

AI use: Gemini (Antigravity) compared the two diffs; Claude Code (Claude Opus 5.5) checked it against 2a318283, da59a507 and this thread, and wrote this comment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants