startup: input script waits for the presented picture, marks, relative times and groups #1970

Merged
rasptum merged 3 commits from upstream-pr/1977 into main 2026-11-24 23:29:31 +00:00
rasptum commented 2026-11-24 22:28:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T22:28:31Z.


Depends on the input-script holds/axes PR (startup/input-script-holds-axes); this branch is stacked on it.

Fixed script times drift when a run gets slower or faster, so presses land on the wrong screen. This adds:

  • wait[=<settle>[/<timeout>[/stop|/go]]] waits until the presented picture changes and then stays unchanged
    for <settle> s (default 1). After <timeout> s (default 120) it logs a timeout and goes on or stops.
  • mark[=<label>] logs the script time and the present number.
  • @+<s> on any timed item: <s> seconds after the previous timed item started, or after a wait completed.
  • Per-wait sensitivity after ;: cells=<n> (default 16), level=<n> (default 12),
    region=<x0>:<y0>:<x1>:<y1> (fractions of the picture), and fine (a 64 x 72 grid instead of 32 x 18).
  • group[=<label>] ... end: when a wait inside a group times out, the rest of the group is skipped and the
    script goes on after end, timed from the timeout.

Example: wait,80@+2,4@+0.5 waits for a new screen, pauses 2 s, presses down, pauses 0.5 s and presses accept.

The signal comes from the D3D12 stand-in in render mode. Every 4 presents it copies 18 one-texel rows of the
presented surface without waiting, reduces them to 32 x 18 cells of mean luma, and publishes them in
Local\x2w_present_signature_<pid>. On request it also copies 72 more rows for the 64 x 72 grid. There is no
full-resolution readback per frame. Measured on WARP at 3840 x 2160, release, CPU side: 0.16 ms per sampled
present with the default grid and 0.56 ms with the fine one. A 1 % bar between two default rows changes 0
default cells and 40 fine cells. Without a presenter, waits time out and the log says so. Waits and marks
count toward the 256-entry limit with presses; base, group and end do not.

Scripts without the new items play exactly as before.

Test:

ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries|syntax)|keys|history|contracts_check)$|^startup_present_signature_warp$|^d3d12x_device_(create|negative|struct_return)_warp$' -V

Result in dev and release: 10/10 passed, 0 skipped. Negative controls, applied locally, each fail their
checks: entries released before their wait resolves; unstable cells from the sampler; the region ignored;
per-wait cells ignored; group skips disabled; fine rows never copied.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6592680282 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1977). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T22:28:31Z. --- **Depends on the input-script holds/axes PR (`startup/input-script-holds-axes`); this branch is stacked on it.** Fixed script times drift when a run gets slower or faster, so presses land on the wrong screen. This adds: - `wait[=<settle>[/<timeout>[/stop|/go]]]` waits until the presented picture changes and then stays unchanged for `<settle>` s (default 1). After `<timeout>` s (default 120) it logs a timeout and goes on or stops. - `mark[=<label>]` logs the script time and the present number. - `@+<s>` on any timed item: `<s>` seconds after the previous timed item started, or after a wait completed. - Per-wait sensitivity after `;`: `cells=<n>` (default 16), `level=<n>` (default 12), `region=<x0>:<y0>:<x1>:<y1>` (fractions of the picture), and `fine` (a 64 x 72 grid instead of 32 x 18). - `group[=<label>] ... end`: when a wait inside a group times out, the rest of the group is skipped and the script goes on after `end`, timed from the timeout. Example: `wait,80@+2,4@+0.5` waits for a new screen, pauses 2 s, presses down, pauses 0.5 s and presses accept. The signal comes from the D3D12 stand-in in render mode. Every 4 presents it copies 18 one-texel rows of the presented surface without waiting, reduces them to 32 x 18 cells of mean luma, and publishes them in `Local\x2w_present_signature_<pid>`. On request it also copies 72 more rows for the 64 x 72 grid. There is no full-resolution readback per frame. Measured on WARP at 3840 x 2160, release, CPU side: 0.16 ms per sampled present with the default grid and 0.56 ms with the fine one. A 1 % bar between two default rows changes 0 default cells and 40 fine cells. Without a presenter, waits time out and the log says so. Waits and marks count toward the 256-entry limit with presses; `base`, `group` and `end` do not. Scripts without the new items play exactly as before. Test: ```powershell ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries|syntax)|keys|history|contracts_check)$|^startup_present_signature_warp$|^d3d12x_device_(create|negative|struct_return)_warp$' -V ``` Result in dev and release: 10/10 passed, 0 skipped. Negative controls, applied locally, each fail their checks: entries released before their wait resolves; unstable cells from the sampler; the region ignored; per-wait cells ignored; group skips disabled; fine rows never copied. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-11-24 23:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T22:42:58Z.

Review: CHANGES_REQUESTED


The sampler records a copy using the raw source surface and returns before the copy fence. It holds the allocator, list and readback buffer, but never holds the surface. A guest can release or replace the surface immediately after Present. D3D12 command-list calls do not retain resources. Hold the source through completion, and define how it is retired if Signal fails after submission. Add a source-built control which stalls the GPU queue, releases the caller's reference after Present, then unblocks the queue and verifies the signature with the debug layer enabled. Also keep signature sampling opt-in for runs without a picture wait, since the current default records extra GPU submissions on ordinary render runs. D3D12 command-list reference counting

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048556427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1977#pullrequestreview-6048556427). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T22:42:58Z. **Review:** CHANGES_REQUESTED --- The sampler records a copy using the raw source surface and returns before the copy fence. It holds the allocator, list and readback buffer, but never holds the surface. A guest can release or replace the surface immediately after Present. D3D12 command-list calls do not retain resources. Hold the source through completion, and define how it is retired if Signal fails after submission. Add a source-built control which stalls the GPU queue, releases the caller's reference after Present, then unblocks the queue and verifies the signature with the debug layer enabled. Also keep signature sampling opt-in for runs without a picture wait, since the current default records extra GPU submissions on ordinary render runs. [D3D12 command-list reference counting](https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#reference-counting)
upstream-sync closed this pull request 2026-11-25 00:04:46 +00:00
R0Y00 commented 2026-11-25 00:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:29:18Z.

Review: APPROVED


The revised sampler retains the source through the copy fence and stops safely if a submitted copy cannot be fenced. Ordinary runs do not sample until requested. Release passed the six GameInput and WARP checks, including the held-source and unheld-source controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049066503 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1977#pullrequestreview-6049066503). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T23:29:18Z. **Review:** APPROVED --- The revised sampler retains the source through the copy fence and stops safely if a submitted copy cannot be fenced. Ordinary runs do not sample until requested. Release passed the six GameInput and WARP checks, including the held-source and unheld-source controls.
rasptum commented 2026-11-25 01:01:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T23:04:14Z.


Thanks, all three points are addressed in 2a898640, which is rebased on current main.

1. Source lifetime.

  • The sampler now AddRefs the presented surface just before ExecuteCommandLists and releases
    it once the copy's fence has passed.
  • If Signal fails after submission, there is no fence that can show when the copy ends. In that
    case the sampler is marked stranded and stops sampling. The surface, allocator, list and readback
    buffer stay referenced for the rest of the process. The presenter's sampler is never destroyed,
    and the log says
    x2w-present picture signature: Signal failed after a copy was submitted; sampling stopped, its surface stays referenced.
  • The destructor, used only by checks, waits up to 10 s for a copy in flight. If the copy has not
    finished by then, it releases nothing the copy may still use.

2. Source-built control. This is startup_present_signature_held_source_warp, which runs with
the debug layer on:

  • The queue Waits on an unsignalled fence, and the sampler records its row copy behind it.
  • The caller releases its only reference; the check confirms that exactly one reference, the
    sampler's, is left. The fence is then signalled from the CPU.
  • The published cells must equal the CPU reduction of the released surface's rows. The sampler
    must drop its reference after the fence, and the info queue must hold no error or corruption
    message.
  • The same check also uses a forwarding queue whose Signal fails, and requires the stranded
    sampler to keep the surface.

The negative control is startup_present_signature_unheld_source_control_warp. It runs the same
stall with a plain copy that does not hold its source, and passes only when the debug layer reports
OBJECT_DELETED_WHILE_STILL_IN_USE. As a mutant, removing the sampler's AddRef makes the
held-source check crash with an access violation.

3. Opt-in.

  • The signature block gains a sampling_wanted field at +0x1478. The GameInput stand-in sets it
    only for scripts with at least one wait, and logs x2w-input script: picture signature requested.
  • Until then, the presenter only counts presents (marks still report present numbers), creates no
    GPU objects and submits nothing.
  • X2W_PRESENT_SIGNATURE_EVERY=<n> still samples from the start without a request, and 0 turns
    the signature off.
  • Checks: a sampler with always = false creates nothing until the block asks. A new marks_only
    case (negative control) shows that a script without a wait never sets the request.

Command, run in dev and release (12/12 passed in each, no skips):

ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries|syntax)|keys|history|contracts_check)$|^startup_present_signature_(warp|held_source_warp|unheld_source_control_warp)$|^d3d12x_device_(create|negative|struct_return)_warp$' -V

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146977760 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1977#issuecomment-7146977760). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T23:04:14Z. --- Thanks, all three points are addressed in `2a898640`, which is rebased on current main. **1. Source lifetime.** - The sampler now `AddRef`s the presented surface just before `ExecuteCommandLists` and releases it once the copy's fence has passed. - If `Signal` fails after submission, there is no fence that can show when the copy ends. In that case the sampler is marked stranded and stops sampling. The surface, allocator, list and readback buffer stay referenced for the rest of the process. The presenter's sampler is never destroyed, and the log says `x2w-present picture signature: Signal failed after a copy was submitted; sampling stopped, its surface stays referenced`. - The destructor, used only by checks, waits up to 10 s for a copy in flight. If the copy has not finished by then, it releases nothing the copy may still use. **2. Source-built control.** This is `startup_present_signature_held_source_warp`, which runs with the debug layer on: - The queue `Wait`s on an unsignalled fence, and the sampler records its row copy behind it. - The caller releases its only reference; the check confirms that exactly one reference, the sampler's, is left. The fence is then signalled from the CPU. - The published cells must equal the CPU reduction of the released surface's rows. The sampler must drop its reference after the fence, and the info queue must hold no error or corruption message. - The same check also uses a forwarding queue whose `Signal` fails, and requires the stranded sampler to keep the surface. The negative control is `startup_present_signature_unheld_source_control_warp`. It runs the same stall with a plain copy that does not hold its source, and passes only when the debug layer reports `OBJECT_DELETED_WHILE_STILL_IN_USE`. As a mutant, removing the sampler's `AddRef` makes the held-source check crash with an access violation. **3. Opt-in.** - The signature block gains a `sampling_wanted` field at +0x1478. The GameInput stand-in sets it only for scripts with at least one `wait`, and logs `x2w-input script: picture signature requested`. - Until then, the presenter only counts presents (marks still report present numbers), creates no GPU objects and submits nothing. - `X2W_PRESENT_SIGNATURE_EVERY=<n>` still samples from the start without a request, and `0` turns the signature off. - Checks: a sampler with `always = false` creates nothing until the block asks. A new `marks_only` case (negative control) shows that a script without a wait never sets the request. Command, run in dev and release (12/12 passed in each, no skips): ```powershell ctest --preset dev --no-tests=error -R '^startup_gameinput_(script_(long|entries|syntax)|keys|history|contracts_check)$|^startup_present_signature_(warp|held_source_warp|unheld_source_control_warp)$|^d3d12x_device_(create|negative|struct_return)_warp$' -V ``` AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1970
No description provided.