Skip to content

runtime: forward CopyBufferRegion from a title-backed buffer through a snapshot - #3501

Merged
R0Y00 merged 5 commits into
R0Y00:mainfrom
Kawiu:runtime/copy-buffer-title-snapshot
Nov 30, 2026
Merged

R0Y00 merged 5 commits into
R0Y00:mainfrom
Kawiu:runtime/copy-buffer-title-snapshot

Conversation

@Kawiu

@Kawiu Kawiu commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Change

CopyBufferRegion from a title-backed buffer that has no desktop copy is skipped as title_backed_source. A title that
updates a constant buffer this way keeps the old or empty bytes in the destination.

With the opt-in X2W_D3D12_TITLE_COPY_SNAPSHOT=1, such a copy of up to 64 KiB reads the source's title memory at record
time into the snapshot pool and copies from there. Without the switch the behavior is unchanged.

Limits:

  • CPU writes to the source after recording, and GPU writes into the source, are not seen. This is why it is opt-in.
  • This covers the copy only. Translated draws still read a table buffer in a non-aliased placement from title memory, so
    they do not see the copied bytes yet. That is a separate follow-up.
  • Not added to run_presets.json.

Verification

Commit b97a694, Windows 11, AMD Radeon RX 6750 XT (driver 32.0.21045.29003) and WARP, debug layer requested
(X2W_D3D12_DEBUG=1; the test fails on any stored error).

cmake --preset dev
cmake --build --preset dev --target startup_list_copy startup_list_copy_check startup_list_copy_texture_check startup_list_copy_texture_warp
ctest --preset dev -R "^startup_list_copy"

13/13 passed.

cmake --build --preset pr
ctest --preset pr --no-tests=error -j 4

82/82 passed.

Evidence and follow-up

The new cases in tests/startup_list_copy.cpp are built from the test's own byte pattern. A 128 KiB buffer is placed
256 bytes into a VirtualAlloc block, so it cannot alias.

  • Default: the copy is refused and the destination stays zero.
  • Switch on: the destination holds the 256 bytes exactly, although the test overwrites the source memory after recording.
  • Refused in both modes: a source with decommitted pages, and a range over 64 KiB.

Follow-up: let translated draws read a destination written this way from the desktop buffer.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

…a snapshot

Opt-in X2W_D3D12_TITLE_COPY_SNAPSHOT=1. A copy of up to 64 KiB whose source
has no desktop copy is read from title memory at record time instead of being
skipped as title_backed_source.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

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

The change itself reads well. It's opt-in, limited to buffers of 64 KiB or less, it reads at record time into the upload ring, and it skips the COPY_SOURCE transition on the title resource when the ring slice is the source. Overwriting the source after recording is a good way to show it's a record-time snapshot.

Two things:

  1. The header comment of tests/startup_list_copy.cpp lost a line break. Item 8 is now glued to the end of 7b:

    //      whose pages are gone, or a range over 64 KiB, is refused either way//   8. after Close, the same calls change no counter
    

    It needs a newline before // 8..

  2. 8e doesn't show why it was refused. With the switch off, 8e is refused as title_backed_source because the snapshot is never tried. With it on, 8e is refused because 0x10004 bytes is over the cap. Both count as one refusal, so a regression that dropped the 64 KiB cap would still pass with the switch off, and would only fail with it on if the counter changed. If step or the log can check the refusal reason, asserting the reason in snapshot mode would pin the cap. Otherwise, copying 0x10000 bytes (accepted) next to 0x10004 (refused) in snapshot mode would show the boundary.

A related note: title_copy_snapshot probes with readable_window and then calls ring_copy(..., true). Until #3469 lands, that copy is a plain memcpy, so a page decommitted between the probe and the copy would fault, as #3468 describes. Once #3469 merges, this path fails closed like the other snapshot callers.

AI-assisted.

Fix the line break in the header comment of startup_list_copy.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@Kawiu

Kawiu commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both fixed in the new commit:

  1. Restored the line break before item 8 in the header comment.
  2. Added an exactly-64 KiB case (0x10000) next to the 0x10004 one. With the switch on it is accepted and 0x10004 is refused. I removed the cap locally as a control: startup_list_copy_title_snapshot_warp and _hardware both failed.

ctest --preset dev -R "^startup_list_copy": 13/13 passed.

Agreed on #3469: this path relies on it for the probe-to-copy window. I have not changed ring_copy here.

AI-assisted.

@R0Y00 R0Y00 added the priority: P0 Highest project priority label Nov 30, 2026 — with ChatGPT Codex Connector

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

Reviewed 484fe487 by reading the diff; not built or run.

Verdict: comment. No MUST: the off path is inert (enabled is checked first, and snapshot stays null, so the old transition and source are used). One SHOULD belongs in this PR because it is on the same lines.

  • SHOULD With mesh_xmem_tracking() on, a snapshotted copy still hands from.resource and source_offset to note_mesh_xmem_write (src/startup_stubs/list_copy.inl:271-272). That function records a second CopyBufferRegion from that resource into the lease (mesh_xmem_handoff.inl:296), so:

    • the lease gets the stale desktop bytes while the destination gets the snapshot;
    • for the default-uav source, the title resource never got its COPY_SOURCE transition, because line 252 skips it when snapshot is set.

    Before this PR, both cases were refused. Passing the snapshot resource and offset there fixes it. It only happens when both opt-ins are on.

  • SHOULD Nothing counts or logs a snapshotted copy. It increments list_buffer_copies like any other forwarded copy, so a real-title run cannot show whether any copy took this path. One counter, or a first-N log line, would cover it.

  • NIT The comment at list_copy.inl:214, the docs paragraph and the PR body say "upload ring". ring_copy(..., true) reserves from the separate snapshot pool (128 MiB cap), so the upload_ring_* counters do not include it.

  • Checked, no finding:

    • check_copy_buffer_region bounds the range before the snapshot is taken.
    • When the pool is full, the copy is refused as before.
    • Pool chunks are GENERIC_READ upload buffers, so a copy from them needs no transition.
    • The list holds the chunk until its fence, so running a closed list again reads the same bytes.

Tests: startup_list_copy_title_snapshot_{warp,hardware} reach the new branch:

  • 8c: the copy is accepted with exact bytes, even after the source is overwritten;
  • the two size cases: exactly 64 KiB accepted, 4 bytes more refused;
  • 8d: the decommitted source.

No test turns on the mesh handoff switches. CI did not run any startup_list_copy* test, because the pr filter in CMakePresets.json leaves them out.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 484fe48 (static read plus a trial merge into current main, which has no conflicts; nothing built or run): no MUST.

  • The snapshot is taken at record time after the range checks, with a 64 KiB cap and a readable-window probe. The tests cover the refusal paths (decommitted source, 0x10004 bytes) and the exact 0x10000 boundary. The switch is off by default and the off path is unchanged.

SHOULD

  1. With mesh_xmem_tracking on, note_mesh_xmem_write still receives from.resource and source_offset instead of the snapshot, so that path records a second copy of the stale bytes. This is the same point lukaslw-lab raised on this head, and it is still open.
  2. No test uses a nonzero source offset, so a mutant that drops + offset passes. Add a case with an offset and check the copied bytes.
  3. The pr preset has no startup_list_copy, so CI ran none of the new tests.

NIT
4. The author email on the second commit is not a noreply address.

AI-assisted.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@openbotgit
openbotgit Bot force-pushed the runtime/copy-buffer-title-snapshot branch from 1b82bb5 to 577a17f Compare November 30, 2026 18:46
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>

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

Reviewed c308f362 by reading the diff since our review at 484fe487; not built or run. The merge of main is clean, and 113a764f differs from 484fe487 only in the author email.

Verdict: approve. Both SHOULDs from our earlier review are fixed, and the off path stays inert. No MUST.

  • Fixed: the snapshot now reaches the handoff. note_mesh_xmem_write gets the pool chunk and its offset (list_copy.inl:277-278), and srv_word accepts a snapshot source (:266). note_mesh_xmem_write records no transition on the source, and the chunk is a GENERIC_READ upload buffer. So the default-uav case needs no COPY_SOURCE transition either.
  • Fixed: a log line. The first ten snapshot copies are logged (:252-256), enough to see the path in a real-title run.
  • New test, checked. startup_mesh_title_snapshot_{warp,hardware} reaches the fixed line. The fixture enables the handoff itself. The source sits 256 bytes into a VirtualAlloc block, so its desktop copy is a committed buffer that never received the title bytes (d3d12_xs_device.cpp:6585-6590). The old code leased zeros there, and the test asserts red.
  • NIT For a snapshot copy, source_kind still names the title resource's kind (buffer / default-uav) (list_copy.inl:272-273). Handoff traces therefore do not show that the lease came from a snapshot.
  • NIT The PR body still reports verification at b97a694d. It does not mention the handoff fix, the log line, or the new pr filter entries.

Tests: CI ran startup_list_copy_title_snapshot_warp and startup_mesh_title_snapshot_warp at this head, both passed (97/97), now that the PR adds them to the pr filter. The _hardware cases did not run on CI. The default-uav (12-byte mesh arguments) snapshot branch has no test.

@Kawiu

Kawiu commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! I’ve pushed updates addressing the feedback:

  • The mesh handoff now uses the snapshot resource and offset, so it receives the same bytes as the destination.
  • Added a snapshot diagnostic, a nonzero source-offset case, and the copy tests to the PR CI preset. The wording now refers to the snapshot pool.
  • Added a mesh handoff test. It passed on WARP and the AMD Radeon RX 6750 XT; restoring the previous behavior made it fail on both.
  • Updated the commit author email to the GitHub noreply address.

The D3D12 debug layer was unavailable locally. GitHub reports three successful checks and two skipped jobs. This change was AI-assisted.

@R0Y00
R0Y00 merged commit fec482a into R0Y00:main Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants