Skip to content

GameInput: match presented frames to scripted input rules - #2637

Open
KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:frame-input-rules
Open

KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:frame-input-rules

Conversation

@KDenKC

@KDenKC KDenKC commented Nov 26, 2026 •

Copy link
Copy Markdown

Head: de2292ead5eebcae972a967d697d8e4dbbe84173, based on main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7. Includes eager host-path loading before VFS initialization, a 6.5-second warning countdown wait, and a three-second terms-screen transition wait in the local-reference example.

Test runs of the retail title get through first-run and legal screens by timed presses. Cache state changes load time, so agents lose runs to stuck screens or toggled checkboxes. This adds frame-matched virtual-pad rules and JSON events that automated launch scripts can wait on.

What is in it

  • XCL_INPUT_RULES=<local TOML file>, with references resolved beside that file. Rules and reference thumbnails load once at host startup before VFS hooks remap host drive paths. Requires XCL_FRAME_DUMP (use 2 for responsive matching). Uses the existing presented-frame readback and existing TOML/JSON dependencies.

  • A 64×36 grayscale matcher, normalized region and mean absolute difference threshold. One active sequence; ordered rules; once or repeat with cooldown. Missing references disable their rule and fallback. No game image ships in the repository.

  • examples/retail-input-rules.toml and the README recipe: timed A through 54 seconds; fallback A from 57 seconds until the legal-screen match; DOWN, wait 6.5 seconds, DOWN, A, then privacy/terms/confirmation. The README also describes an optional second terms-frame rule to gate that transition. References and thresholds must be calibrated locally.

Related: #609 (hold duration), #1765 (retain presses until read), #2449 (live input file); #42 supplied the test-report workflow. This retains the existing 200 ms pulse semantics and does not implement input acknowledgement.

Schema (TOML):

[fallback]                     # optional, stops permanently on first match

button = "A"                   # required string

start = 57.0                   # required nonnegative seconds

interval = 3.0                 # required seconds > 0.2



[[rules]]                      # 1–32 rules

name = "legal-notices"          # required unique string

reference = "references/legal-notices.bmp" # required local 24-bit BMP

region = [0.0, 0.0, 0.421875, 0.3888888888888889] # required normalized x,y,w,h

threshold = 5.0                # required finite number, 0–255

sequence = "DOWN, wait 6.5, DOWN, A, wait 3, A, DOWN, A, DOWN, A"

once = true                    # optional, default true

cooldown = 3.0                 # optional seconds >= 0.2, default 3

Automated use:

  1. Capture with XCL_FRAME_DUMP=2; keep your own Legal Notices frame with Copyright selected as references/legal-notices.bmp. Never commit game output.

  2. Copy the example rules file beside references/. Check target/non-target distances locally; threshold 5 is a starting point, not a measurement of the new matcher on the title.

  3. Set XCL_NETWORK=0, XCL_FRAME_DUMP=2, XCL_INPUT_RULES=<rules file> and XCL_PRESS_AT=6:A,9:A,12:A,15:A,18:A,21:A,24:A,27:A,30:A,33:A,36:A,39:A,42:A,45:A,48:A,51:A,54:A. Run with the usual timeout; parse JSON after GameInput: input_rule and wait for event=completed, rule=legal-notices.

Example event (illustrative, not a measured run):


GameInput: input_rule {"event":"matched","rule":"legal-notices","frame":180,"t":63.5,"diff":0.0}

Other events are pressed (button), completed, and disabled (reason). Pulses last 200 ms. An unmatched reference never starts a rule. Config errors disable all rules; an unreadable reference disables its rule and fallback. Frame dumping adds overhead, so comparison arms need identical settings.

Tested
cargo +stable-x86_64-pc-windows-msvc build --workspace passed. cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib input_rules: 7 passed, 0 failed, 0 ignored, 0 skipped, 1336 filtered out. Tests were written before implementation; the first execution was deferred until the rig build window. No red test run has been claimed.

cargo +stable-x86_64-pc-windows-msvc test --workspace --no-fail-fast -- --test-threads=4, with XCL_NETWORK=0: 1,438 passed, 4 failed, 47 ignored across 37 result blocks; 26 explicit SKIPPED diagnostics (subchecks, not additional test cases). Exit 101. Library: 1,312 passed, 4 failed, 27 ignored. Every other target passed. The four failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3, seeds 70/545/1019/1507, CreateComputePipelineState out of memory (0x8007000E). They also fail on main b49be18 on this rig, tracked by #1905. Skips include unavailable wave64, unsupported f16 variants, no heap windows, and driver-cache disabling requiring Windows Developer Mode. Skipped checks are not coverage.

Hardware available: Windows 11, Ryzen 7 9800X3D, 62 GB RAM, RTX 5090. Targeted tests use only synthetic data and do not initialize the GPU.

The workspace build, seven filtered tests and whole suite were repeated after the eager-load change: identical totals and the same four fuzz failures. Current head changes only the example TOML and README after that tested runtime revision.

Functional check (Claude Code, Claude Opus 5.5), run 3 with this head's example: passed. Frame dumps show Privacy checked at 101.6 s, Terms checked at 103.4 s, Confirm pressed at 104.8 s, and the title proceeding into loading. Host-path loading and frame matching worked. The 6.5-second wait accounts for Next becoming enabled only about 5.0–5.3 seconds after the first DOWN on this rig. TOML parsing and the exact sequence were checked without rebuilding (runtime unchanged). This is one successful functional run, not a guarantee across machines or frame rates.

Match differences in runs 1–3 were 0.76, 0.68 and 4.29, against threshold 5 (checked in each run's log). Earlier local-screen measurements put other screens at 26 or more; these are calibration observations, not synthetic-test results or a bound for all machines.

Tested by others (thank you):

Not tested
AMD/Intel, other resolutions/HDR, repeat-rule behavior in-title and the optional second frame-gated terms rule have not been tested. No references or output dumped from a title are included. Input still must be polled during the pulse, as with XCL_PRESS_AT; the example's countdown timing can need adjustment on other rigs.

Run 3 matched at 4.29, close to the threshold; if the rule does not fire on your machine, raise threshold toward 10 (other screens measured 26 or more in earlier local measurements). Check your own target and non-target screens before adopting that threshold.

Regression run
main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 2037 (PresentX 2037)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 30959 MB

This PR (de2292e):

xcl-smoke v1
commit: de2292ead5eebcae972a967d697d8e4dbbe84173
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 2091 (PresentX 2091)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31150 MB

Both: the retail title, -Seconds 200, the same scripted input, RTX 5090. These runs don't set XCL_INPUT_RULES, so they are a regression check of the default path; the rules were checked in the functional run under Tested.

Edge cases we would like tested
Use a copy of the example rules file and your normal launcher with XCL_NETWORK=0.

| Scenario | Configuration / command before launching | What to look for |

| --- | --- | --- |

| Missing reference | Set reference='missing.bmp' in the local rules file. | event=disabled for that rule; no rule or fallback presses. Existing XCL_PRESS_AT is independent. |

| Two rules match one frame | Duplicate a matching rule with a different name, both once=true. | First rule in file starts alone. The second can start only on a later sampled frame after the first completes. |

| Never matches, fallback active | Use a valid reference from a different screen and threshold=0.0. | $fallback pressed events at start + n×interval, no rule completion; launcher timeout still applies. |

| Frame dumps off | Remove-Item Env:XCL_FRAME_DUMP -ErrorAction SilentlyContinue | $config disabled warning; no rule or fallback presses. |

| Different resolution / HDR | Capture references using the same launcher settings; compare with and without XCL_FRAME_DUMP_FULL=1. | Matching on intended screens only; check diff and unsupported decoded formats. Recalibrate threshold if needed. |

| Slower or faster load | Repeat the same launcher/env recipe with different cache warmth and a suitable run timeout. | Match follows the intended screen rather than a fixed start time; all checkboxes and Confirm must be verified in frames. If the match occurs before 54 s, remaining independent XCL_PRESS_AT presses can overlap the sequence: shorten/remove that setup schedule for the faster run. A slower warning countdown may need a longer wait or further frame gating. |

These are requested title-level checks, not results. Synthetic tests cover ordering, missing-reference fail-safe, cooldown, sequence timing, JSON events and BMP orientation/padding.

AI use

  • Codex (GPT-6.1-Sol) wrote the implementation, the tests, the docs and the description, and ran the workspace build, the filtered tests and the whole suite.

  • Claude Code (Claude Opus 5.5) reviewed the diff, ran the functional runs in the retail title and the regression runs, and checked the logs. No code was imported from another project.

🤖 Generated with Claude Code

Add local-reference TOML rules, synthetic matching and sequence tests, presented-frame wiring, structured events and an automated retail-title input example.

Assisted-by: Codex (GPT-6.1-Sol)
@KDenKC
KDenKC marked this pull request as ready for review November 26, 2026 03:50
@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown
Author

Just a simple testing framework to help with automation on test runs 🙂

@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.

A, wait 0.2, A is accepted, but each A pulse occupies a 0.2-second window, so the two windows touch: [0, 0.2) and [0.2, 0.4). Engine::buttons returns A across the boundary and can emit two pressed events, while GameInput's callback poller sees no button-up state and therefore one continuous hold. Could the parser reject or coalesce consecutive same-button presses with no release interval (or document that this sequence is a hold)? A small synthetic test polling at 0.19, 0.20, and 0.21 seconds would show the missing release. This is source review only; the default 0.8-second spacing and the supplied example are unaffected.

@sage-sage

Copy link
Copy Markdown

Test report: passes on NVIDIA. Exact head de2292ea (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1442 passed, 0 failed, 47 ignored; the 7 new tests pass
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)

Not tested

  • No game, so no scripted input on presented frames.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

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