Skip to content

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

Open
KDenKC wants to merge 3 commits into
xcl-dev:mainfrom
KDenKC:frame-input-rules
Open

KDenKC wants to merge 3 commits 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
Second review fix 0eb8005a (luckyteagirl's handoff review): when a matching rule's first press is the button the fallback is holding, the rule waits until the fallback pulse ends plus the same 0.1 s release margin; a different first button still starts at once. The extended sequence_timing_once_and_fallback_handoff test failed on the previous head at 57.11 s (A instead of neutral; 9 passed, 1 failed) and passes with the fix (10 passed, 0 failed, including neutral polls through 57.29 s and the rule's A at 57.31 s). cargo build --workspace passed.

Review fix 70bc71a8 (luckyteagirl's review: repeated presses of one button with no release gap). The parser now rejects a repeated press of the same button that starts less than 0.3 s after the previous one (a 0.2 s pulse plus a 0.1 s release margin). cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib input_rules: on the previous head, with the new tests, 8 passed, 2 failed (the two new regressions: the 0.19/0.20/0.21 s poll shows no button-up, and the parser accepts A, wait 0.2, A); with the fix, 10 passed, 0 failed. cargo build --workspace passed. The whole suite and the functional in-title runs below are from de2292ea; the fix only adds the parser check, its tests and a README line. The regression smoke pair below is main against this head 0eb8005a (200 s each, same recipe). The shipped example (presses 0.8 s apart) is unaffected.

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: 0eb8005a923ad8ee5b29c451297488ce95396ae2
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 2031 (PresentX 2031)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31381 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.

@Gevroska

Copy link
Copy Markdown

I tested the two matching once-only rules on de2292ea with a synthetic frame and a different button assigned to each rule. I ran the same test in both file orders. In each case, the first rule in the file produced the first button press.

Frame 17 started the first sequence. Frame 18 arrived while that sequence was active. After the sequence completed and the button mask returned to neutral, presenting frame 18 again produced no action. Fresh frame 19 triggered the second rule. Once both rules had completed, another matching frame triggered neither.

I added this case locally alongside the seven existing input-rule tests. All eight passed on Windows, with zero failures, ignores, or skips. This verifies rule ordering and the fresh-frame requirement in the CPU engine. Live frame capture and in-game button delivery remain untested.

I used Codex GPT-6.2 Sol for the fixture and a separate GPT-6.2 Sol agent to review it and rerun the compiled tests.

I reviewed and approved this comment before posting.

Require 0.3 seconds between consecutive presses of the same button so the 0.2-second holds leave a release interval. Add boundary polling and parser regressions for touching pulses.

Assisted-by: Codex (GPT-6.1-Sol)
@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thanks @luckyteagirl, good catch. Fixed in 70bc71a8: the parser now rejects a repeated press of the same button that starts less than 0.3 s after the previous one (the 0.2 s pulse plus a 0.1 s release margin), with an error that names the 0.3 s. A, wait 0.3, A is accepted and shows button-up at 0.20 s. Tests, written first:

  • the 0.19 / 0.20 / 0.21 s poll you suggested;
  • parser rejection, including A, wait 0.299, a;
  • the spaced case.

On the previous head they gave 8 passed, 2 failed (the two regressions); with the fix, 10 passed. The README notes the rule, and the example file is unchanged.

AI use: Codex (GPT-6.1-Sol) wrote the fix and tests and ran them; Claude Code (Claude Opus 5.5) checked the diff and logs and wrote this reply.

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

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

On 70bc71a, the new release-margin check covers repeated presses inside a rule, but a matching rule can still start the same button while the fallback is holding it. With fallback A at start=57, interval=3, buttons(57.05) returns A and logs the fallback press. If a frame matches sequence='A' at 57.10, frame sets claimed and starts the rule immediately; buttons(57.11) returns A and logs the rule press. Every poll through the handoff sees A, then neutral after the rule pulse. GameInput sees one rising edge, so the matched A action can be lost even though both pressed events are logged.

Could the handoff insert a button-up interval when the first rule press matches an active fallback pulse, while preserving immediate starts for different buttons? Extending sequence_timing_once_and_fallback_handoff with fallback A → first-rule A at 57.10 would cover it. This is exact-head source review; I did not run the synthetic case or a title.

@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown
Author

Thanks @luckyteagirl, right again: the release check covers presses inside a rule, but not the handoff from a fallback pulse of the same button. We will add a button-up gap when a rule's first press is the button the fallback is holding (other buttons still start at once), and extend sequence_timing_once_and_fallback_handoff with fallback A to rule A at 57.10 as you suggest. I will post here when it is pushed.

AI use: Claude Code (Claude Opus 5.5) wrote this.

If a matched rule begins with the active fallback button, delay its sequence until the fallback pulse has ended plus the shared release margin. Different-button handoffs remain immediate. Extend the synthetic handoff regression requested by luckyteagirl in review 6071420335.

Assisted-by: Codex (GPT-6.1-Sol)
@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown
Author

@luckyteagirl fixed in 0eb8005a. When a matching rule starts with the button the fallback is holding, its sequence now waits until the fallback pulse ends, plus the same 0.1 s release margin. A different first button still starts at once.

  • The extended handoff test (fallback A, then rule A at 57.10) failed on the previous head at 57.11 s: A instead of neutral.
  • With the fix, all 10 input_rules tests pass: neutral through 57.29 s, then the rule's A at 57.31 s.
  • The README describes the handoff. A fresh smoke pair on this head is in the description.

AI use: Codex (GPT-6.1-Sol) wrote the change and test and ran them. Claude Code (Claude Opus 5.5) checked the diff and wrote this reply.

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.

4 participants