Skip to content

startup: implement next copy command-list slot in d3d12_xs_device (Part of #870) - #2070

Merged
R0Y00 merged 7 commits into
R0Y00:mainfrom
tedin7:x2w-870-copy-slot
Nov 25, 2026
Merged

R0Y00 merged 7 commits into
R0Y00:mainfrom
tedin7:x2w-870-copy-slot

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #870

What this unblocks: command-list slot 16 CopyTextureRegion (texture to texture, texture to buffer, buffer to texture) is no longer dropped in render mode, so title copies reach the desktop list.

What changes

  • Slot 16 maps both locations to their desktop resources, checks the arguments, moves the pair to COPY_SOURCE / COPY_DEST for the call (Close returns them to COMMON), and forwards the call.
  • A call the desktop would reject is counted, logged (first six) and not forwarded, with a named reason: unknown_resource, buffer_to_buffer, bad_box, source_overflow, dest_overflow, bad_pitch, bad_offset, footprint_overflow, sample_mismatch, bad_alignment.
  • Pure checks live in src/startup_stubs/list_copy_texture.h; the handler is in list_copy_texture.inl (one include and one install line in d3d12_xs_device.cpp).
  • x2w_d3d12_list_copy_texture_stats exports the counters.
  • CopyTiles (18) is left out on purpose. Slots 15, 17, 19 are in startup: copy and resolve whole resources on a recording list (slots 15, 17, 19) #1944.

The slot placement follows the unshifted order of slots 12 to 25 and has not been seen in a title log yet.

Verification: (Win2025: x2w_pipe.py win2025 2070 at head 91c1329, debug and release /O2, release ctest 23/23 passed incl. startup_list_copy_texture and startup_list_copy_texture_overflow_control; Linux checks below)

g++ -std=c++17 -Wall -Wextra -o /tmp/lct tests/startup_list_copy_texture_check.cpp && /tmp/lct   # ok
/tmp/lct --mutate overflow   # FAIL: dest overflow (negative control, exit 1)
x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only -Isrc -Isrc/startup_stubs src/startup_stubs/d3d12_xs_device.cpp   # only the 2 existing __try/__except errors of this toolchain
git diff --check   # clean

@tedin7
tedin7 marked this pull request as ready for review November 25, 2026 00:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:13:43.971479Z 91c1329 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91c1329631

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/startup_stubs/list_copy_texture.inl Resolved
Comment thread src/startup_stubs/list_copy_texture.inl Resolved
Comment thread src/startup_stubs/list_copy_texture.inl Resolved
Comment thread src/startup_stubs/list_copy_texture.inl Resolved
Comment thread src/startup_stubs/list_copy_texture.h Resolved
Comment thread src/startup_stubs/d3d12_xs_device.cpp Resolved
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

All 6 review threads fixed and pushed in 394dbe3 (rebased on origin/main).

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation currently derives mip using modulo without checking the full subresource index (including array slice and plane), and computes format_src/format_dst without checking compatibility. An invalid subresource can reach the desktop call. A multisample mismatch also needs exact sample-count validation and whole-subresource restrictions. Please begin with a documented slice whose subresource range, formats and sample count are all known, and refuse the others before upload or barriers. Make the footprint extent arithmetic checked at each multiply/add before submitting. Add a source-built wrapped-list readback, with a bad index and incompatible format rejected before any desktop copy; arithmetic-only tests can continue to cover the size checks. Desktop CopyTextureRegion contract

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in d7610f5 (code in 2927598).

Fix:

  • The subresource index is now decoded as mip + slice * mips + plane * mips * array_size and must lie inside mips * array_size * planes. A mip-only modulo no longer reads an out-of-range slice as mip 0 (bad_subresource). Planar formats are refused (planar_unsupported).
  • Both sides must name the same format (format_mismatch) and the same sample count (sample_mismatch). A multisampled copy must be whole subresource to whole subresource at origin 0 (partial_multisample).
  • Every multiply and add in the footprint extent arithmetic is overflow-checked.
  • All refusals happen before any barrier, upload or desktop copy.

Regression tests:

  • startup_list_copy_texture (Linux and Windows): index decode, last valid index, one past the last slice, 0xffffffff, sample counts, formats, checked arithmetic. Negative controls: startup_list_copy_texture_overflow_control, startup_list_copy_texture_slice_control.
  • startup_list_copy_texture_warp (new): through the wrapped list, two images round-trip through array slices 1 and 2 and read back byte for byte. A list with subresource 6, 0xffffffff and a format mismatch is refused before any desktop copy, and a sentinel-filled readback buffer stays unchanged.

Verification:

  • g++ -std=c++17 -Wall -Wextra -Isrc tests/startup_list_copy_texture_check.cpp and run: ok. Both --mutate overflow and --mutate slice fail as expected.
  • python3 -B tests/docs_links_check.py and tests/bidi_controls_check.py: pass.
  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 2070 at d7610f5: dev 25/25 and release 25/25 pass (100%), including startup_list_copy_texture_warp.

AI-assisted; commands listed were executed locally.

…Y00#870)

Maps both copy locations to desktop resources, refuses calls the desktop would reject with a named reason, and forwards the rest with COPY_SOURCE/COPY_DEST states.
… slot 16 (Part of R0Y00#870)

Index = mip + slice * mips + plane * mips * array_size must lie inside the resource; planar,
format-mismatched and partial multisampled copies are refused; footprint arithmetic is checked
at each multiply and add. Adds a wrapped-list readback test.
@tedin7
tedin7 requested a review from R0Y00 November 25, 2026 11:18

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array-slice, format and footprint changes address the original review. During recheck I found that a multisampled copy could still forward a non-null source box covering the full resource. The desktop API requires a null box for those copies and for depth-stencil copies. I added exact controls for both and kept the existing reasons for other refusals. Windows Release passed all five selected checks. The wrapped-list copies round-tripped both slices and kept the refused index/format cases off the desktop path on WARP and RTX 4060 Laptop.

Reference: https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copytextureregion

@R0Y00
R0Y00 merged commit 5d86af3 into R0Y00:main Nov 25, 2026
5 checks passed
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.

2 participants