startup: copy compute input snapshots after the output checks #3481

Merged
Leyukaka merged 4 commits from upstream-pr/3481 into main 2026-11-30 08:44:53 +00:00
Leyukaka commented 2026-11-29 17:14:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T17:14:19Z.


Fixes #3479.

What changes

On main (c4b8a41b), indirect_table_buffer copies a compute input that lives only in guest memory into the snapshot pool as soon as the input is resolved, and reserves the 16 zero bytes of a null input at the same point. The dispatch's outputs are checked afterwards, so a dispatch refused on an output has already used pool bytes.

With this change:

  • indirect_table_buffer returns a pending view for these two cases (source 2: guest address and size, no resource; source 3: 16 bytes, no resource). The guest range is still checked for readability there.
  • record_translated_dispatch does the copy and the null reservation after the output, heap SRV and indirect-argument checks have passed. It is the same recording call, still under draw_lock. Readability is checked again just before the copy.
  • For a typed input, FirstElement is set from the actual pool offset once the copy is done. The descriptor size check stays where it was.
  • compute_inputs_snapshot and compute_inputs_snapshot_kib advance after Dispatch/ExecuteIndirect is recorded, for the same inputs as before (raw, source 2). A refused dispatch no longer counts.
  • The once-per-key "input comes from" log line is emitted after these checks, so a refused dispatch no longer consumes it.
  • New export x2w_d3d12_snapshot_pool_used() in the shim (sum of used over the snapshot chunks, under allocator_lock), used by the fixture.

Only the two callers that allow snapshots, both in record_translated_dispatch, can receive a pending view.

The copy happens later in the call than before, so the interval in which another guest thread can write the range before it is copied is slightly longer. Nothing in the recording call writes guest memory in between.

Refusal order

Refusal texts are unchanged. Which refusal is reported first changes for a dispatch that has two refusals at once:

  • An input-side pool refusal (guest range not readable at copy time, copy from guest memory failed, "a null input could not get its zero bytes", pool offset not on a whole element or not 16-byte aligned) together with a refusal on a later input, an output, a heap SRV or the indirect argument: the second one is now reported first.
  • For one typed input, the minimum-size check is now reported before a pool reservation failure.

Tests

New startup_compute_snapshot_order_{warp,hardware}: one synthetic translated dispatch whose input is only in guest memory, sampled with x2w_d3d12_snapshot_pool_used() before and after recording.

  • accepted dispatch: 1,536 bytes (1,280 rounded to the pool's 512-byte alignment);
  • same input with an empty output descriptor, refused with "an output buffer descriptor has zero records": 0 bytes;
  • null input with the same empty output: 0 bytes;
  • snapshot flag off: refused as on main, 0 bytes.

Both pass on WARP and on hardware.

ctest -R '^startup_compute_(snapshot_order|dispatch(_input|_output)?|typed_buffer_srv)_(warp|hardware)$' -j 1

9 passed, 0 failed.

Skipped, reported separately: startup_compute_typed_buffer_srv_warp exits 77 because WARP here lacks SM 6.6 with 32-lane waves. The hardware variant passes.

Mutations, against startup_compute_snapshot_order_warp:

  • eager ring_copy put back in indirect_table_buffer: fails (refused dispatch uses 1,536 bytes);
  • eager null-input reservation put back: fails (refused dispatch uses 512 bytes).

Merges cleanly with #3469, #3466 and #3480.

Not covered

  • Two refusals come after the copy and still use pool bytes: "a formatted input has no word 3" and "an input texture could not be uploaded". The counters stay correct in both cases.
  • No test makes the deferred copy itself fail.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5553114033 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3481). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T17:14:19Z. --- Fixes #3479. ## What changes On `main` (`c4b8a41b`), `indirect_table_buffer` copies a compute input that lives only in guest memory into the snapshot pool as soon as the input is resolved, and reserves the 16 zero bytes of a null input at the same point. The dispatch's outputs are checked afterwards, so a dispatch refused on an output has already used pool bytes. With this change: - `indirect_table_buffer` returns a pending view for these two cases (source 2: guest address and size, no resource; source 3: 16 bytes, no resource). The guest range is still checked for readability there. - `record_translated_dispatch` does the copy and the null reservation after the output, heap SRV and indirect-argument checks have passed. It is the same recording call, still under `draw_lock`. Readability is checked again just before the copy. - For a typed input, `FirstElement` is set from the actual pool offset once the copy is done. The descriptor size check stays where it was. - `compute_inputs_snapshot` and `compute_inputs_snapshot_kib` advance after `Dispatch`/`ExecuteIndirect` is recorded, for the same inputs as before (raw, source 2). A refused dispatch no longer counts. - The once-per-key "input comes from" log line is emitted after these checks, so a refused dispatch no longer consumes it. - New export `x2w_d3d12_snapshot_pool_used()` in the shim (sum of `used` over the snapshot chunks, under `allocator_lock`), used by the fixture. Only the two callers that allow snapshots, both in `record_translated_dispatch`, can receive a pending view. The copy happens later in the call than before, so the interval in which another guest thread can write the range before it is copied is slightly longer. Nothing in the recording call writes guest memory in between. ## Refusal order Refusal texts are unchanged. Which refusal is reported first changes for a dispatch that has two refusals at once: - An input-side pool refusal (guest range not readable at copy time, copy from guest memory failed, "a null input could not get its zero bytes", pool offset not on a whole element or not 16-byte aligned) together with a refusal on a later input, an output, a heap SRV or the indirect argument: the second one is now reported first. - For one typed input, the minimum-size check is now reported before a pool reservation failure. ## Tests New `startup_compute_snapshot_order_{warp,hardware}`: one synthetic translated dispatch whose input is only in guest memory, sampled with `x2w_d3d12_snapshot_pool_used()` before and after recording. - accepted dispatch: 1,536 bytes (1,280 rounded to the pool's 512-byte alignment); - same input with an empty output descriptor, refused with "an output buffer descriptor has zero records": 0 bytes; - null input with the same empty output: 0 bytes; - snapshot flag off: refused as on `main`, 0 bytes. Both pass on WARP and on hardware. ``` ctest -R '^startup_compute_(snapshot_order|dispatch(_input|_output)?|typed_buffer_srv)_(warp|hardware)$' -j 1 ``` 9 passed, 0 failed. Skipped, reported separately: `startup_compute_typed_buffer_srv_warp` exits 77 because WARP here lacks SM 6.6 with 32-lane waves. The hardware variant passes. Mutations, against `startup_compute_snapshot_order_warp`: - eager `ring_copy` put back in `indirect_table_buffer`: fails (refused dispatch uses 1,536 bytes); - eager null-input reservation put back: fails (refused dispatch uses 512 bytes). Merges cleanly with #3469, #3466 and #3480. ## Not covered - Two refusals come after the copy and still use pool bytes: "a formatted input has no word 3" and "an input texture could not be uploaded". The counters stay correct in both cases. - No test makes the deferred copy itself fail.
Not-Saii commented 2026-11-29 20:58:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T20:58:39Z.

Review: COMMENTED


I read this against main, and the deferral looks correct:

  • pending views carry no resource and so can't alias an output or the indirect argument;
  • the counters and the "comes from" log line keep their old scope (raw inputs only, with source 1 still logged);
  • the typed path's whole-element check moves to the point where the real pool offset is known.

One gap in the test. In startup_compute_snapshot_order_check.py, the accepted dispatch is the first snapshot in a fresh process, so its pool slice probably starts at offset 0. The new code that matters most is the part that uses the actual slice:

  • view.offset from the deferred ring_copy;
  • FirstElement = view.offset / element for a typed input.

At offset 0, a mutant that kept the pending offset (0) or skipped the FirstElement update would still pass. Two ways to pin it:

  • record a second snapshot dispatch, or a null input first, in the same process, so the checked slice starts at a non-zero offset;
  • add a mutation that leaves FirstElement at 0, and one that binds the pending offset, and show both fail.

A typed-input variant of the accepted case would also cover the described branch of the deferred loop, which the raw-only cases don't reach.

A minor, pre-existing point that this PR makes visible: the pool hands out slices aligned to 512 bytes, so a 3-channel typed input (12-byte elements) is refused with "does not start at a whole element" unless its slice starts at a multiple of 1,536. main has the same behaviour with the eager copy, so it's not a regression. Now that the check runs after the copy, it may be worth a comment.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6104774510 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3481#pullrequestreview-6104774510). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-29T20:58:39Z. **Review:** COMMENTED --- I read this against `main`, and the deferral looks correct: - pending views carry no resource and so can't alias an output or the indirect argument; - the counters and the "comes from" log line keep their old scope (raw inputs only, with source 1 still logged); - the typed path's whole-element check moves to the point where the real pool offset is known. One gap in the test. In `startup_compute_snapshot_order_check.py`, the accepted dispatch is the first snapshot in a fresh process, so its pool slice probably starts at offset 0. The new code that matters most is the part that uses the actual slice: - `view.offset` from the deferred `ring_copy`; - `FirstElement = view.offset / element` for a typed input. At offset 0, a mutant that kept the pending offset (0) or skipped the `FirstElement` update would still pass. Two ways to pin it: - record a second snapshot dispatch, or a null input first, in the same process, so the checked slice starts at a non-zero offset; - add a mutation that leaves `FirstElement` at 0, and one that binds the pending offset, and show both fail. A typed-input variant of the accepted case would also cover the `described` branch of the deferred loop, which the raw-only cases don't reach. A minor, pre-existing point that this PR makes visible: the pool hands out slices aligned to 512 bytes, so a 3-channel typed input (12-byte elements) is refused with "does not start at a whole element" unless its slice starts at a multiple of 1,536. `main` has the same behaviour with the eager copy, so it's not a regression. Now that the check runs after the copy, it may be worth a comment. AI-assisted.
Leyukaka commented 2026-11-29 21:20:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T21:20:20Z.


New head 9f3068b2 covers the three points:

  • The accepted case now records a zero-filled seed snapshot first, so the checked slice starts at pool byte 1536 (raw FirstElement 384); pool use is asserted as 1536 -> 3072.
  • A typed-input variant (12-byte elements, FirstElement 128) reaches the described branch of the deferred loop; the input words encode their pool position, so the readback shows where the view began.
  • d3d12_compute_dispatch.inl has a comment on the 512-byte slice alignment and the 1536-byte multiple for 12-byte elements. No behaviour change.

Mutations, each alone, on WARP and hardware: binding the pending offset fails at startup_compute_snapshot_order_check.py:83 (word 0 read 01234567, expected ea74e376); leaving FirstElement at 0 fails at :106 (word 0 read 00000000, expected 00000600).

ctest -R '^(startup_compute_snapshot_order|startup_compute_dispatch_input|startup_compute_d16_sample_srv_)': 7 run, 6 passed, d16_sample_srv_warp skipped for capability.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7262795301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3481#issuecomment-7262795301). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T21:20:20Z. --- New head 9f3068b2 covers the three points: - The accepted case now records a zero-filled seed snapshot first, so the checked slice starts at pool byte 1536 (raw `FirstElement` 384); pool use is asserted as `1536 -> 3072`. - A typed-input variant (12-byte elements, `FirstElement` 128) reaches the `described` branch of the deferred loop; the input words encode their pool position, so the readback shows where the view began. - `d3d12_compute_dispatch.inl` has a comment on the 512-byte slice alignment and the 1536-byte multiple for 12-byte elements. No behaviour change. Mutations, each alone, on WARP and hardware: binding the pending offset fails at `startup_compute_snapshot_order_check.py:83` (`word 0 read 01234567, expected ea74e376`); leaving `FirstElement` at 0 fails at `:106` (`word 0 read 00000000, expected 00000600`). `ctest -R '^(startup_compute_snapshot_order|startup_compute_dispatch_input|startup_compute_d16_sample_srv_)'`: 7 run, 6 passed, `d16_sample_srv_warp` skipped for capability.
lukaslw-lab commented 2026-11-30 08:31:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T08:31:17Z.

Review: APPROVED


Reviewed 9f3068b2 by reading the diff; not built or run.

Verdict: approve. The deferral is contained to the one function that can receive a pending view, and the body's list of what still uses pool bytes is exact. No MUST.

  • Callers: only d3d12_compute_dispatch.inl:221 (inside typed_dword_input_view, called only at :1023) and :1034 pass allow_title_snapshot = true. Both are in record_translated_dispatch. The result-word path (:1234), the draw path and native mesh57 keep the default, so they never see a null-resource view. #3506's head adds no snapshot caller either. record_translated_dispatch is reached only from the guest list's Dispatch and ExecuteIndirect entry points (d3d12_xs_device.cpp:4113, :4845), so the later copy stays on the recording thread under draw_lock.
  • After the copy: the only refusals between the deferred loop (:1248) and Dispatch (:1392) are "a formatted input has no word 3" (:1300) and "an input texture could not be uploaded" (:1314). That matches "Not covered", and the counters skip both because they advance after Dispatch.
  • Source 1 views pass through the new loop only to keep their alignment check and "comes from" line. Source 0 continues, so the old log scope is kept.

Tests: startup_compute_snapshot_order_{warp,hardware} reach the deferred copy, the null reservation, both binding paths at a non-zero offset, and three refusals at zero pool use. CI did not run them: they are not in the pr preset's list, and /O2 was skipped on the PR. The author's WARP and hardware runs are the only ones at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6108928168 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3481#pullrequestreview-6108928168). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T08:31:17Z. **Review:** APPROVED --- Reviewed `9f3068b2` by reading the diff; not built or run. **Verdict: approve.** The deferral is contained to the one function that can receive a pending view, and the body's list of what still uses pool bytes is exact. No MUST. - Callers: only `d3d12_compute_dispatch.inl:221` (inside `typed_dword_input_view`, called only at `:1023`) and `:1034` pass `allow_title_snapshot = true`. Both are in `record_translated_dispatch`. The result-word path (`:1234`), the draw path and native mesh57 keep the default, so they never see a null-resource view. #3506's head adds no snapshot caller either. `record_translated_dispatch` is reached only from the guest list's Dispatch and ExecuteIndirect entry points (`d3d12_xs_device.cpp:4113`, `:4845`), so the later copy stays on the recording thread under `draw_lock`. - After the copy: the only refusals between the deferred loop (`:1248`) and `Dispatch` (`:1392`) are "a formatted input has no word 3" (`:1300`) and "an input texture could not be uploaded" (`:1314`). That matches "Not covered", and the counters skip both because they advance after `Dispatch`. - Source 1 views pass through the new loop only to keep their alignment check and "comes from" line. Source 0 `continue`s, so the old log scope is kept. Tests: `startup_compute_snapshot_order_{warp,hardware}` reach the deferred copy, the null reservation, both binding paths at a non-zero offset, and three refusals at zero pool use. CI did not run them: they are not in the `pr` preset's list, and `/O2` was skipped on the PR. The author's WARP and hardware runs are the only ones at this head.
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!3481
No description provided.