startup: record the calls into the D3D12 stand-in and replay them offline (draft for discussion) #3208

Open
github-bot wants to merge 15 commits from github-bot/gh-3206 into main AGit
Owner

@⁠tedin7 on GitHub · 2026-11-27 21:43 UTC · original
tedin7:up-replay-tool → main · +7106 −4 · 30 files · 15 commits · draft

Part of #870

What this unblocks: reproducing a title's D3D12 work offline, on WARP or any GPU, with the real stand-in and translator, so a runtime or translator fix can be checked against the same frames without the title.

Draft for discussion. This is large (about 6.7k lines, most of it tests and the player). It will be split into reviewable PRs before anyone is asked to review it (plan at the end). It is open now so the design can be discussed and so the refusal census in #3200 has its input documented.

What it records

X2W_REPLAY_RECORD=all, <start s>,<seconds>, f<first present>,<presents> or d<draws>,<seconds> wraps every slot of every object kind the stand-in hands out (src/startup_stubs/d3d12_record.inl) and writes X2W_REPLAY_RECORD_FILE (default replay.x2wr). Unset, nothing is wrapped and nothing changes. Per call it keeps:

  • the slot, the object, the register and stack argument words, the return value, and a global sequence number taken before the call;
  • the memory behind pointer arguments, from the per-slot layouts in src/startup_stubs/d3d12_replay_slots.h (generic calls copy a bounded amount), stored once per content as blobs;
  • the wrapper an output pointer received, so the player can map recorded objects to its own;
  • for title memory that GPU work reads (placed resources, descriptor memory, optionally root-view ranges): page images and later changed pages at Present / submit, under a byte budget (src/startup_stubs/replay_pages.h);
  • the shader cache files the run used and the process's X2W_ settings.

Each title thread appends to its own buffer (no lock shared between title threads per call); full buffers go to the file under one lock. Size caps stop the recording cleanly with its end chunk.

File format

Chunks <4-byte tag><u32 header bytes><u64 data bytes>, header, data (src/replay/replay_file.h reads it mapped, in place):
XREC (version, timer frequency), XENV (settings), CALL, ARGM (argument memory: seq, arg, address, bytes, blob hash), BLOB (hash, bytes; once per content), OUTP (output wrapper after the call), HPLC (heap behind a slot 133 placement), DARR / DHPM (descriptor-copy arrays, caller-backed descriptor heap), PAGE / MAP (title memory pages and where they apply), SHDR (shader cache files), PRES (present), XEND (totals, dropped counts). The reader validates every chunk against its call before playing.

How a replay runs

x2w_replay <recording.x2wr> <out dir> [--adapter warp|hardware] [--from-present K] [--max-seconds S] [--prefix-live on] [--pace on]

src/replay/x2w_replay.cpp loads the stand-in (delay-loaded, so the recorded settings are in the environment first), reserves the recorded title ranges at their addresses, seeds the shader cache, then makes every recorded call again in sequence order on the stand-in's objects: recorded wrappers, descriptor handles, mapped and GPU addresses are rewritten to the replay's, argument memory is rebuilt from the blobs, pages are written before the first call that follows them, and fence waits wait for the recorded value. No title code runs; the stand-in, the translator and any fix run for real. It writes stderr.txt (the stand-in log), present_<nnnn>.png per present (X2W_PRESENT_PICTURES, src/startup_stubs/d3d12_present_pictures.inl), replay_summary.json, and one x2w-replay score line; exit codes name the failure (bad file, a title range that cannot be reserved, no device, time limit, a slot result that differs, no adapter).

What it found

Replaying recordings on WARP with the debug layer showed invalid calls that hardware drivers had tolerated; each one is its own small draft: console-format clear values (#3196), viewports, scissors and DSV formats (#3197), the presenter's allocator reset (#3198), debug-layer floods (#3199), sampler fields (#3201), UAV/RTV/DSV view fields (#3202). Shader resource view validation (MipLevels 0 from a UAV descriptor read as an SRV, depth-stencil plane slices) follows. Run on a recording with X2W_SHADER_CACHE set, tools/startup/refusal_census.py (#3200) ranks the first shader refusals by the draws and dispatches they block.

Not in this draft (follow-ups)

  • Replaying on a device whose descriptor increments differ from the recording GPU's (title handles mapped by descriptor index).
  • Submission dumps for work without Present, replays of compute work that writes title memory.
  • Float arguments passed by value, one replay thread per recorded thread.

Split plan

  1. File format reader, page store and slot layouts with their pure tests (startup_replay_pages, startup_replay_prefix_live, startup_replay_call_formats).
  2. The recorder in the stand-in, with startup_replay_record_*.
  3. The player and present pictures, with startup_replay_*, startup_replay_determinism_*, startup_replay_submit_pages_*, startup_replay_title_ranges_warp.
  4. The follow-ups above.

Tests in this draft

  • startup_replay_pages + 3 WILL_FAIL mutants, startup_replay_prefix_live, startup_replay_invoke, startup_replay_call_formats, startup_replay_pages_play (pure or synthetic recordings).
  • startup_replay_record_{warp,hardware}: a stream draw fixture recorded draws the same pixels and the file is well formed.
  • startup_replay_{warp,hardware} and the slot_layouts, null_views, paced variants: a recorded scene replays to the same pictures pixel for pixel; a recording with one clear colour changed replays to a different last picture only; mutated frame token / no-op return are detected.
  • startup_replay_determinism_{warp,hardware}, startup_replay_submit_pages_{warp,hardware}, startup_replay_title_ranges_warp.

Verification:

  • x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -fms-extensions -Isrc -Isrc/startup_stubs src/startup_stubs/d3d12_xs_device.cpp -> the same 17 errors as on main (MSVC __try/__except only), no new ones
  • x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only -fms-extensions -Isrc src/replay/x2w_replay.cpp -> OK; same for the five new test programs
  • python3 -m py_compile tests/startup_replay_*.py -> OK
  • cmake -S . -B /tmp/cfg -G Ninja -DDXC_EXECUTABLE=/bin/true -> configure OK
  • Win2025 (Build 26100, MSVC, D3D12 WARP) at 35a14b3e, x2w_pipe.py win2025 3206 --targets x2w_replay,startup_replay_quad,startup_replay_pages,startup_replay_prefix_live_check,startup_replay_submit_pages,startup_replay_invoke,startup_stream_consumer,d3d12_xs_shim --regex '^startup_replay_' --force:
    • dev: ctest --preset dev -R '^startup_replay_' -> 23/23 passed
    • release (/O2): same -> 23/23 passed

Thanks to @⁠Makto94 for the testing that found this.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 21:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3206) `tedin7:up-replay-tool` → `main` · +7106 −4 · 30 files · 15 commits · draft Part of #870 What this unblocks: reproducing a title's D3D12 work offline, on WARP or any GPU, with the real stand-in and translator, so a runtime or translator fix can be checked against the same frames without the title. **Draft for discussion.** This is large (about 6.7k lines, most of it tests and the player). It will be split into reviewable PRs before anyone is asked to review it (plan at the end). It is open now so the design can be discussed and so the refusal census in #3200 has its input documented. ## What it records `X2W_REPLAY_RECORD=all`, `<start s>,<seconds>`, `f<first present>,<presents>` or `d<draws>,<seconds>` wraps every slot of every object kind the stand-in hands out (`src/startup_stubs/d3d12_record.inl`) and writes `X2W_REPLAY_RECORD_FILE` (default `replay.x2wr`). Unset, nothing is wrapped and nothing changes. Per call it keeps: - the slot, the object, the register and stack argument words, the return value, and a global sequence number taken before the call; - the memory behind pointer arguments, from the per-slot layouts in `src/startup_stubs/d3d12_replay_slots.h` (generic calls copy a bounded amount), stored once per content as blobs; - the wrapper an output pointer received, so the player can map recorded objects to its own; - for title memory that GPU work reads (placed resources, descriptor memory, optionally root-view ranges): page images and later changed pages at Present / submit, under a byte budget (`src/startup_stubs/replay_pages.h`); - the shader cache files the run used and the process's `X2W_` settings. Each title thread appends to its own buffer (no lock shared between title threads per call); full buffers go to the file under one lock. Size caps stop the recording cleanly with its end chunk. ## File format Chunks `<4-byte tag><u32 header bytes><u64 data bytes>`, header, data (`src/replay/replay_file.h` reads it mapped, in place): `XREC` (version, timer frequency), `XENV` (settings), `CALL`, `ARGM` (argument memory: seq, arg, address, bytes, blob hash), `BLOB` (hash, bytes; once per content), `OUTP` (output wrapper after the call), `HPLC` (heap behind a slot 133 placement), `DARR` / `DHPM` (descriptor-copy arrays, caller-backed descriptor heap), `PAGE` / `MAP` (title memory pages and where they apply), `SHDR` (shader cache files), `PRES` (present), `XEND` (totals, dropped counts). The reader validates every chunk against its call before playing. ## How a replay runs ``` x2w_replay <recording.x2wr> <out dir> [--adapter warp|hardware] [--from-present K] [--max-seconds S] [--prefix-live on] [--pace on] ``` `src/replay/x2w_replay.cpp` loads the stand-in (delay-loaded, so the recorded settings are in the environment first), reserves the recorded title ranges at their addresses, seeds the shader cache, then makes every recorded call again in sequence order on the stand-in's objects: recorded wrappers, descriptor handles, mapped and GPU addresses are rewritten to the replay's, argument memory is rebuilt from the blobs, pages are written before the first call that follows them, and fence waits wait for the recorded value. No title code runs; the stand-in, the translator and any fix run for real. It writes `stderr.txt` (the stand-in log), `present_<nnnn>.png` per present (`X2W_PRESENT_PICTURES`, `src/startup_stubs/d3d12_present_pictures.inl`), `replay_summary.json`, and one `x2w-replay score` line; exit codes name the failure (bad file, a title range that cannot be reserved, no device, time limit, a slot result that differs, no adapter). ## What it found Replaying recordings on WARP with the debug layer showed invalid calls that hardware drivers had tolerated; each one is its own small draft: console-format clear values (#3196), viewports, scissors and DSV formats (#3197), the presenter's allocator reset (#3198), debug-layer floods (#3199), sampler fields (#3201), UAV/RTV/DSV view fields (#3202). Shader resource view validation (MipLevels 0 from a UAV descriptor read as an SRV, depth-stencil plane slices) follows. Run on a recording with `X2W_SHADER_CACHE` set, `tools/startup/refusal_census.py` (#3200) ranks the first shader refusals by the draws and dispatches they block. ## Not in this draft (follow-ups) - Replaying on a device whose descriptor increments differ from the recording GPU's (title handles mapped by descriptor index). - Submission dumps for work without Present, replays of compute work that writes title memory. - Float arguments passed by value, one replay thread per recorded thread. ## Split plan 1. File format reader, page store and slot layouts with their pure tests (`startup_replay_pages`, `startup_replay_prefix_live`, `startup_replay_call_formats`). 2. The recorder in the stand-in, with `startup_replay_record_*`. 3. The player and present pictures, with `startup_replay_*`, `startup_replay_determinism_*`, `startup_replay_submit_pages_*`, `startup_replay_title_ranges_warp`. 4. The follow-ups above. ## Tests in this draft - `startup_replay_pages` + 3 WILL_FAIL mutants, `startup_replay_prefix_live`, `startup_replay_invoke`, `startup_replay_call_formats`, `startup_replay_pages_play` (pure or synthetic recordings). - `startup_replay_record_{warp,hardware}`: a stream draw fixture recorded draws the same pixels and the file is well formed. - `startup_replay_{warp,hardware}` and the `slot_layouts`, `null_views`, `paced` variants: a recorded scene replays to the same pictures pixel for pixel; a recording with one clear colour changed replays to a different last picture only; mutated frame token / no-op return are detected. - `startup_replay_determinism_{warp,hardware}`, `startup_replay_submit_pages_{warp,hardware}`, `startup_replay_title_ranges_warp`. Verification: - `x86_64-w64-mingw32-g++ -std=c++20 -fsyntax-only -fms-extensions -Isrc -Isrc/startup_stubs src/startup_stubs/d3d12_xs_device.cpp` -> the same 17 errors as on main (MSVC `__try`/`__except` only), no new ones - `x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only -fms-extensions -Isrc src/replay/x2w_replay.cpp` -> OK; same for the five new test programs - `python3 -m py_compile tests/startup_replay_*.py` -> OK - `cmake -S . -B /tmp/cfg -G Ninja -DDXC_EXECUTABLE=/bin/true` -> configure OK - Win2025 (Build 26100, MSVC, D3D12 WARP) at `35a14b3e`, `x2w_pipe.py win2025 3206 --targets x2w_replay,startup_replay_quad,startup_replay_pages,startup_replay_prefix_live_check,startup_replay_submit_pages,startup_replay_invoke,startup_stream_consumer,d3d12_xs_shim --regex '^startup_replay_' --force`: - dev: `ctest --preset dev -R '^startup_replay_'` -> 23/23 passed - release (`/O2`): same -> 23/23 passed Thanks to @⁠Makto94 for the testing that found this. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:43:17 +00:00
The recorder captured the array for queue slot 10 only, so a recording of a title that submits on slot 35 replayed no list. Any queue slot called with (count 1-64, readable array of list wrappers) is captured now. Adds a slot-35 scene mode and a WARP replay test.

(cherry picked from commit cb3fc8182ec991b049c8e6dffcedd676c4d8aa17)
(cherry picked from commit d1c7775adad942159953ba6279b3bead229eee64)
(cherry picked from commit c89e574d3bb3175f21d3f1fec52f74a8da91fedd)
(cherry picked from commit f0a080f5e2a3060bedce3c19ee31552ddca3f74a)
(cherry picked from commit b262dfd2f32d1c5a127fac8a6705df3b778c7122)
(cherry picked from commit 71be2dd9df0dc0939b30c251b7ea623ce644050e)
(cherry picked from commit 0e9b856993a34c1a11141baa23372780469f234d)
(cherry picked from commit b1c859f168d26917d41ed8e0a152a95501c873b9)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-28 13:01 UTC · original

Update (still Draft), head 9bdc41be5. Merged current main, then added:

  • Queue calls shaped like ExecuteCommandLists (count 1-64 plus a readable array of list wrappers) now have their list array recorded on any slot, not only slot 10. New test startup_replay_execute_slot35_{warp,hardware}.
  • Opt-in X2W_REPLAY_INFER_EXECUTE=1 in the player: a submit recorded without its array submits the next closed lists in Close order; a recorded array always wins. New test startup_replay_infer_execute_{warp,hardware}.
  • Command lists closed before the recorder window have their calls carried in memory (cap X2W_REPLAY_CARRY_MAX_MIB, default 64) and written to the file when the window first submits the list; a list the window Resets is dropped. Tests startup_replay_static_list_*.
  • A carried list is forgotten at its last Release in every phase, so a reused address does not inherit old calls. Test startup_replay_static_release_* (reads the carried bytes before and after the Release).

Not included: the GPU-VA binding of plain title memory, the window-start GPU snapshot and the timed-window shift. They build on replay-draw-memory and GPU-state pieces this PR does not contain, so they belong with those pieces. The pass-statistics option is also left out: it is a separate diagnostic outside this PR's scope.

Verification (aws-1, dev + release):

  • x2w_pipe.py win2025 3206 --host aws-1 --wait 7200 --regex '^startup_replay_' --force: 31/31 passed on both legs.
  • Mutant 1: recorder captures the array on slot 10 only (patched run): 9 of 31 fail on each leg, including execute_slot35, infer_execute, static_list, static_release and slot_layouts.
  • Mutant 2: carry cap default 0 (patched run): static_list and static_release fail on both backends and both legs.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-28 13:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3206#issuecomment-7239629796) Update (still Draft), head 9bdc41be5. Merged current main, then added: - Queue calls shaped like ExecuteCommandLists (count 1-64 plus a readable array of list wrappers) now have their list array recorded on any slot, not only slot 10. New test `startup_replay_execute_slot35_{warp,hardware}`. - Opt-in `X2W_REPLAY_INFER_EXECUTE=1` in the player: a submit recorded without its array submits the next closed lists in Close order; a recorded array always wins. New test `startup_replay_infer_execute_{warp,hardware}`. - Command lists closed before the recorder window have their calls carried in memory (cap `X2W_REPLAY_CARRY_MAX_MIB`, default 64) and written to the file when the window first submits the list; a list the window Resets is dropped. Tests `startup_replay_static_list_*`. - A carried list is forgotten at its last Release in every phase, so a reused address does not inherit old calls. Test `startup_replay_static_release_*` (reads the carried bytes before and after the Release). Not included: the GPU-VA binding of plain title memory, the window-start GPU snapshot and the timed-window shift. They build on replay-draw-memory and GPU-state pieces this PR does not contain, so they belong with those pieces. The pass-statistics option is also left out: it is a separate diagnostic outside this PR's scope. Verification (aws-1, dev + release): - `x2w_pipe.py win2025 3206 --host aws-1 --wait 7200 --regex '^startup_replay_' --force`: 31/31 passed on both legs. - Mutant 1: recorder captures the array on slot 10 only (patched run): 9 of 31 fail on each leg, including execute_slot35, infer_execute, static_list, static_release and slot_layouts. - Mutant 2: carry cap default 0 (patched run): static_list and static_release fail on both backends and both legs. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-28 22:08 UTC · original

Status update, still Draft: merged current main (merge commit, no force push, no conflicts); head is now 8494b98cd.

Verification (Windows Server 2025, D3D12 WARP, head 8494b98cd): x2w_pipe.py win2025 3206 --regex '^startup_replay' -> 31/31 passed.

This stays Draft until an independent review of the head. @⁠KelboLive or @⁠MasterDomino, a review of this head would be welcome; after that I will mark it Ready.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-28 22:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3206#issuecomment-7246519544) Status update, still Draft: merged current `main` (merge commit, no force push, no conflicts); head is now `8494b98cd`. Verification (Windows Server 2025, D3D12 WARP, head `8494b98cd`): `x2w_pipe.py win2025 3206 --regex '^startup_replay'` -> 31/31 passed. This stays Draft until an independent review of the head. @⁠KelboLive or @⁠MasterDomino, a review of this head would be welcome; after that I will mark it Ready. AI-assisted; commands listed were executed locally.
This pull request has changes conflicting with the target branch.
  • src/startup_stubs/d3d12_xs_device.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3208/head:github-bot/gh-3206'
git switch 'github-bot/gh-3206'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3206'
git switch 'github-bot/gh-3206'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3206'
git switch 'github-bot/gh-3206'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3206'
git switch 'main'
git merge --squash 'github-bot/gh-3206'
git switch 'main'
git merge --ff-only 'github-bot/gh-3206'
git switch 'main'
git merge 'github-bot/gh-3206'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.