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

Merged
tedin7 merged 7 commits from upstream-pr/2070 into main 2026-11-25 14:51:59 +00:00
tedin7 commented 2026-11-24 23:58:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:58:32Z.


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 #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 91c13296, 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
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593919425 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:58:32Z. --- 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 #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 91c13296, 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 ```
chatgpt-codex-connector[bot commented 2026-11-25 01:01:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049544071 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6049544071). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `91c1329631` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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". </details>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:07:01Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148159082 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#issuecomment-7148159082). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:07:01Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"91c1329631b9cfa32f24d5f63eed2491976c7218","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T00:13:43.971479Z">2026-11-25T00:13:43.971479Z</relative-time> | `91c1329` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). 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. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 96

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);

P1 Badge Preserve fixed states for upload and readback footprint buffers

For footprint buffers on UPLOAD or READBACK heaps, these calls emit invalid barriers. device_create_committed_x() creates those resources in GENERIC_READ and COPY_DEST respectively, but require_state() assumes an unseen resource starts in COMMON, transitions it to the requested state, and returns it to COMMON at Close. Upload/readback resources must remain in their fixed heap states, so ordinary buffer-to-texture uploads and texture-to-buffer readbacks can invalidate the whole command list. Detect these heap types and exclude them from the COMMON-based transition tracking.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402816 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402816). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 96 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve fixed states for upload and readback footprint buffers** For footprint buffers on UPLOAD or READBACK heaps, these calls emit invalid barriers. `device_create_committed_x()` creates those resources in GENERIC_READ and COPY_DEST respectively, but `require_state()` assumes an unseen resource starts in COMMON, transitions it to the requested state, and returns it to COMMON at Close. Upload/readback resources must remain in their fixed heap states, so ordinary buffer-to-texture uploads and texture-to-buffer readbacks can invalidate the whole command list. Detect these heap types and exclude them from the COMMON-based transition tracking. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 80

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");

P2 Badge Materialize non-aliased source data before copying

When a source texture has been filled through its guest backing but has never been sampled, unwrapping own().real does not provide its current contents. Placed textures use non-aliased desktop stand-ins, and d3d12_draw.inl::upload_texture() normally populates them lazily during a draw; this handler never invokes that synchronization. Likewise, slot 133 can return non-aliased Placement::copied_buffer sources. Copies from these backings therefore read stale or zero desktop data instead of the supplied source bytes. Materialize the relevant source data before forwarding, or explicitly refuse unsupported backings.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402823 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402823). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 80 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Materialize non-aliased source data before copying** When a source texture has been filled through its guest backing but has never been sampled, unwrapping `own().real` does not provide its current contents. Placed textures use non-aliased desktop stand-ins, and `d3d12_draw.inl::upload_texture()` normally populates them lazily during a draw; this handler never invokes that synchronization. Likewise, slot 133 can return non-aliased `Placement::copied_buffer` sources. Copies from these backings therefore read stale or zero desktop data instead of the supplied source bytes. Materialize the relevant source data before forwarding, or explicitly refuse unsupported backings. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 101

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);
+    D3D12_TEXTURE_COPY_LOCATION to = *dst, from = *src;
+    to.pResource = real_dst;
+    from.pResource = real_src;
+    static_cast<ID3D12GraphicsCommandList*>(self->own().real)->CopyTextureRegion(&to, x, y, z, &from, box ? box : nullptr);
+    InterlockedIncrement(&list_copy_texture_forwarded);

P2 Badge Prevent lazy uploads from overwriting copied textures

For a destination texture with title_memory, no render-target/depth/UAV flags, and no previous sampler bind, this copy updates only the desktop resource and leaves its TextureUpload cache untouched. On the first subsequent sample, draw_translated() calls upload_texture(), whose initial done == false schedules an upload from the stale guest backing over the copied pixels. Thus a valid copy from a rendered texture into a shader-only texture is lost before it is sampled. Publish the GPU write to the texture-coherence tracking so the first-bind uploader preserves copied contents.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402831 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402831). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 101 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); + D3D12_TEXTURE_COPY_LOCATION to = *dst, from = *src; + to.pResource = real_dst; + from.pResource = real_src; + static_cast<ID3D12GraphicsCommandList*>(self->own().real)->CopyTextureRegion(&to, x, y, z, &from, box ? box : nullptr); + InterlockedIncrement(&list_copy_texture_forwarded); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Prevent lazy uploads from overwriting copied textures** For a destination texture with `title_memory`, no render-target/depth/UAV flags, and no previous sampler bind, this copy updates only the desktop resource and leaves its `TextureUpload` cache untouched. On the first subsequent sample, `draw_translated()` calls `upload_texture()`, whose initial `done == false` schedules an upload from the stale guest backing over the copied pixels. Thus a valid copy from a rendered texture into a shader-only texture is lost before it is sampled. Publish the GPU write to the texture-coherence tracking so the first-bind uploader preserves copied contents. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 96

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);

P2 Badge Transition subresources separately for intra-resource copies

When the locations name different subresources of the same texture, such as two array slices, both checks pass but real_src == real_dst. require_state() tracks states per resource, and transition() always uses ALL_SUBRESOURCES, so the second call moves the source subresource back out of COPY_SOURCE and into COPY_DEST immediately before the copy. This turns a legal intra-resource copy into an invalid D3D12 command. Track and transition the selected subresources independently, or refuse this case until that is supported.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402838 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402838). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 96 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Transition subresources separately for intra-resource copies** When the locations name different subresources of the same texture, such as two array slices, both checks pass but `real_src == real_dst`. `require_state()` tracks states per resource, and `transition()` always uses ALL_SUBRESOURCES, so the second call moves the source subresource back out of COPY_SOURCE and into COPY_DEST immediately before the copy. This turns a legal intra-resource copy into an invalid D3D12 command. Track and transition the selected subresources independently, or refuse this case until that is supported. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:40Z.

Code review location: src/startup_stubs/list_copy_texture.h; line 95

@@ -0,0 +1,100 @@
+// Experimental (docs/startup-runtime.md, #870): the argument checks for command list slot 16,
+// CopyTextureRegion(dst, x, y, z, src, box). Plain standard C++ so a Linux fixture can run it; the
+// handler (list_copy_texture.inl) maps the title's resources and forwards only what passes here.
+// A call the desktop runtime would reject is refused with a named reason instead.
+#pragma once
+
+#include <cstdint>
+#include <initializer_list>
+
+namespace x2w_list_copy_texture {
+
+enum class Kind : std::uint32_t { subresource = 0, placed_footprint = 1 };
+
+// What the check needs to know about one side of the copy. For a subresource side, width/height/depth are
+// the subresource's size in blocks (texels for an uncompressed format). For a footprint side, the footprint
+// size in blocks, the row pitch in bytes, the byte offset and the bytes per block are used, and
+// resource_bytes is the size of the buffer.
+struct Side {
+    Kind kind;
+    std::uint32_t width, height, depth;
+    std::uint64_t offset;
+    std::uint32_t row_pitch, bytes_per_block;
+    std::uint64_t resource_bytes;
+    bool multisampled;
+    std::uint32_t block_w, block_h;  // texels per block (4 x 4 for block-compressed formats, else 1 x 1)
+};
+
+struct Box {
+    std::uint32_t left, top, front, right, bottom, back;
+};
+
+enum class Verdict {
+    ok,
+    buffer_to_buffer,   // a footprint on both sides: the desktop wants CopyBufferRegion
+    bad_box,            // an empty or inverted source box
+    source_overflow,    // the source box leaves the source subresource
+    dest_overflow,      // the destination origin plus box size leaves the destination subresource
+    bad_pitch,          // a footprint row pitch below one row, or not a multiple of 256
+    bad_offset,         // a footprint offset that is not a multiple of 512
+    footprint_overflow, // the footprint reaches past the end of its buffer
+    sample_mismatch,    // a multisampled side paired with a single-sample one
+    bad_alignment       // a block-compressed copy that does not start on a block
+};
+
+inline const char* name(Verdict v) noexcept
+{
+    switch (v) {
+    case Verdict::ok: return "ok";
+    case Verdict::buffer_to_buffer: return "buffer_to_buffer";
+    case Verdict::bad_box: return "bad_box";
+    case Verdict::source_overflow: return "source_overflow";
+    case Verdict::dest_overflow: return "dest_overflow";
+    case Verdict::bad_pitch: return "bad_pitch";
+    case Verdict::bad_offset: return "bad_offset";
+    case Verdict::footprint_overflow: return "footprint_overflow";
+    case Verdict::sample_mismatch: return "sample_mismatch";
+    case Verdict::bad_alignment: return "bad_alignment";
+    }
+    return "unknown";
+}
+
+// Bytes a footprint of the given size reaches, from its offset (the last row is not padded).
+inline bool footprint_end(const Side& s, std::uint32_t w, std::uint32_t h, std::uint32_t d, std::uint64_t& end) noexcept
+{
+    if (!w || !h || !d) { end = s.offset; return true; }
+    const std::uint64_t row = std::uint64_t{(w + s.block_w - 1) / s.block_w} * s.bytes_per_block;
+    const std::uint64_t rows = (h + s.block_h - 1) / s.block_h;
+    if (row > s.row_pitch) return false;
+    const std::uint64_t slice = std::uint64_t{s.row_pitch} * (rows - 1) + row;
+    const std::uint64_t total = std::uint64_t{s.row_pitch} * rows * (d - 1) + slice;
+    end = s.offset + total;
+    return end >= s.offset;
+}
+
+// box == nullptr copies the whole source (for a footprint source, the whole footprint).
+inline Verdict check(const Side& dst, std::uint32_t x, std::uint32_t y, std::uint32_t z, const Side& src, const Box* box) noexcept
+{
+    if (dst.kind == Kind::placed_footprint && src.kind == Kind::placed_footprint) return Verdict::buffer_to_buffer;
+    if (dst.multisampled != src.multisampled) return Verdict::sample_mismatch;
+    const Box whole{0, 0, 0, src.width, src.height, src.depth};
+    const Box use = box ? *box : whole;
+    if (use.left >= use.right || use.top >= use.bottom || use.front >= use.back) return Verdict::bad_box;
+    if (use.right > src.width || use.bottom > src.height || use.back > src.depth) return Verdict::source_overflow;
+    const Side& tex = dst.kind == Kind::subresource ? dst : src;  // the side that knows the block size
+    if (x % tex.block_w || use.left % tex.block_w || y % tex.block_h || use.top % tex.block_h) return Verdict::bad_alignment;
+    const std::uint32_t w = use.right - use.left, h = use.bottom - use.top, d = use.back - use.front;
+    if (std::uint64_t{x} + w > dst.width || std::uint64_t{y} + h > dst.height || std::uint64_t{z} + d > dst.depth)
+        return Verdict::dest_overflow;
+    for (const Side* s : {&dst, &src}) {
+        if (s->kind != Kind::placed_footprint) continue;
+        if (!s->row_pitch || s->row_pitch % 256) return Verdict::bad_pitch;
+        if (s->offset % 512) return Verdict::bad_offset;
+        std::uint64_t end = 0;
+        if (!footprint_end(*s, w, h, d, end)) return Verdict::bad_pitch;
+        if (end > s->resource_bytes) return Verdict::footprint_overflow;

P2 Badge Include copy origins in footprint buffer bounds

For partial footprint copies, the byte-end calculation uses only the copied extent and ignores both the destination origin and the source box origin. The portable checker returns ok for a 1x1 RGBA8 copy into a 64x64 footprint with row pitch 256, buffer size 256, and destination Y=63, although the write ends at byte 16132. Source boxes with nonzero top/front have the same problem, and 3D slice strides must use the footprint height rather than the copied height. Include those offsets and strides, or conservatively validate the complete footprint, before forwarding an out-of-buffer copy.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402847 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402847). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:40Z. **Code review location:** `src/startup_stubs/list_copy_texture.h`; line 95 ~~~~diff @@ -0,0 +1,100 @@ +// Experimental (docs/startup-runtime.md, #870): the argument checks for command list slot 16, +// CopyTextureRegion(dst, x, y, z, src, box). Plain standard C++ so a Linux fixture can run it; the +// handler (list_copy_texture.inl) maps the title's resources and forwards only what passes here. +// A call the desktop runtime would reject is refused with a named reason instead. +#pragma once + +#include <cstdint> +#include <initializer_list> + +namespace x2w_list_copy_texture { + +enum class Kind : std::uint32_t { subresource = 0, placed_footprint = 1 }; + +// What the check needs to know about one side of the copy. For a subresource side, width/height/depth are +// the subresource's size in blocks (texels for an uncompressed format). For a footprint side, the footprint +// size in blocks, the row pitch in bytes, the byte offset and the bytes per block are used, and +// resource_bytes is the size of the buffer. +struct Side { + Kind kind; + std::uint32_t width, height, depth; + std::uint64_t offset; + std::uint32_t row_pitch, bytes_per_block; + std::uint64_t resource_bytes; + bool multisampled; + std::uint32_t block_w, block_h; // texels per block (4 x 4 for block-compressed formats, else 1 x 1) +}; + +struct Box { + std::uint32_t left, top, front, right, bottom, back; +}; + +enum class Verdict { + ok, + buffer_to_buffer, // a footprint on both sides: the desktop wants CopyBufferRegion + bad_box, // an empty or inverted source box + source_overflow, // the source box leaves the source subresource + dest_overflow, // the destination origin plus box size leaves the destination subresource + bad_pitch, // a footprint row pitch below one row, or not a multiple of 256 + bad_offset, // a footprint offset that is not a multiple of 512 + footprint_overflow, // the footprint reaches past the end of its buffer + sample_mismatch, // a multisampled side paired with a single-sample one + bad_alignment // a block-compressed copy that does not start on a block +}; + +inline const char* name(Verdict v) noexcept +{ + switch (v) { + case Verdict::ok: return "ok"; + case Verdict::buffer_to_buffer: return "buffer_to_buffer"; + case Verdict::bad_box: return "bad_box"; + case Verdict::source_overflow: return "source_overflow"; + case Verdict::dest_overflow: return "dest_overflow"; + case Verdict::bad_pitch: return "bad_pitch"; + case Verdict::bad_offset: return "bad_offset"; + case Verdict::footprint_overflow: return "footprint_overflow"; + case Verdict::sample_mismatch: return "sample_mismatch"; + case Verdict::bad_alignment: return "bad_alignment"; + } + return "unknown"; +} + +// Bytes a footprint of the given size reaches, from its offset (the last row is not padded). +inline bool footprint_end(const Side& s, std::uint32_t w, std::uint32_t h, std::uint32_t d, std::uint64_t& end) noexcept +{ + if (!w || !h || !d) { end = s.offset; return true; } + const std::uint64_t row = std::uint64_t{(w + s.block_w - 1) / s.block_w} * s.bytes_per_block; + const std::uint64_t rows = (h + s.block_h - 1) / s.block_h; + if (row > s.row_pitch) return false; + const std::uint64_t slice = std::uint64_t{s.row_pitch} * (rows - 1) + row; + const std::uint64_t total = std::uint64_t{s.row_pitch} * rows * (d - 1) + slice; + end = s.offset + total; + return end >= s.offset; +} + +// box == nullptr copies the whole source (for a footprint source, the whole footprint). +inline Verdict check(const Side& dst, std::uint32_t x, std::uint32_t y, std::uint32_t z, const Side& src, const Box* box) noexcept +{ + if (dst.kind == Kind::placed_footprint && src.kind == Kind::placed_footprint) return Verdict::buffer_to_buffer; + if (dst.multisampled != src.multisampled) return Verdict::sample_mismatch; + const Box whole{0, 0, 0, src.width, src.height, src.depth}; + const Box use = box ? *box : whole; + if (use.left >= use.right || use.top >= use.bottom || use.front >= use.back) return Verdict::bad_box; + if (use.right > src.width || use.bottom > src.height || use.back > src.depth) return Verdict::source_overflow; + const Side& tex = dst.kind == Kind::subresource ? dst : src; // the side that knows the block size + if (x % tex.block_w || use.left % tex.block_w || y % tex.block_h || use.top % tex.block_h) return Verdict::bad_alignment; + const std::uint32_t w = use.right - use.left, h = use.bottom - use.top, d = use.back - use.front; + if (std::uint64_t{x} + w > dst.width || std::uint64_t{y} + h > dst.height || std::uint64_t{z} + d > dst.depth) + return Verdict::dest_overflow; + for (const Side* s : {&dst, &src}) { + if (s->kind != Kind::placed_footprint) continue; + if (!s->row_pitch || s->row_pitch % 256) return Verdict::bad_pitch; + if (s->offset % 512) return Verdict::bad_offset; + std::uint64_t end = 0; + if (!footprint_end(*s, w, h, d, end)) return Verdict::bad_pitch; + if (end > s->resource_bytes) return Verdict::footprint_overflow; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Include copy origins in footprint buffer bounds** For partial footprint copies, the byte-end calculation uses only the copied extent and ignores both the destination origin and the source box origin. The portable checker returns `ok` for a 1x1 RGBA8 copy into a 64x64 footprint with row pitch 256, buffer size 256, and destination Y=63, although the write ends at byte 16132. Source boxes with nonzero top/front have the same problem, and 3D slice strides must use the footprint height rather than the copied height. Include those offsets and strides, or conservatively validate the complete footprint, before forwarding an out-of-buffer copy. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 01:02:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:13:41Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 3759

@@ -3755,6 +3756,7 @@ void build_tables()
         list_typed[52] = reinterpret_cast<ListTyped>(&list_clear_target);
         list_typed[139] = reinterpret_cast<ListTyped>(&list_reset);
         list_typed[12] = reinterpret_cast<ListTyped>(&list_draw);
+        list_typed[16] = reinterpret_cast<ListTyped>(&list_copy_texture);

P1 Badge Document the new copy-slot capability and reproduction command

Installing slot 16 changes the public startup-runtime capability and adds a new reproducible fixture, but neither README.md nor docs/experiments.md is updated; repository-wide searches find the new fixture only in source, tests, and CMake. The root AGENTS.md explicitly requires updating one of those documents when a public capability or reproduction command changes. Add the fixture command, its measured portable-check scope, and the unverified Windows-forwarding status rather than leaving that information only in the commit message.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688402855 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688402855). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T00:13:41Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 3759 ~~~~diff @@ -3755,6 +3756,7 @@ void build_tables() list_typed[52] = reinterpret_cast<ListTyped>(&list_clear_target); list_typed[139] = reinterpret_cast<ListTyped>(&list_reset); list_typed[12] = reinterpret_cast<ListTyped>(&list_draw); + list_typed[16] = reinterpret_cast<ListTyped>(&list_copy_texture); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new copy-slot capability and reproduction command** Installing slot 16 changes the public startup-runtime capability and adds a new reproducible fixture, but neither `README.md` nor `docs/experiments.md` is updated; repository-wide searches find the new fixture only in source, tests, and CMake. The root `AGENTS.md` explicitly requires updating one of those documents when a public capability or reproduction command changes. Add the fixture command, its measured portable-check scope, and the unverified Windows-forwarding status rather than leaving that information only in the commit message. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/91c1329631b9cfa32f24d5f63eed2491976c7218/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:33Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050220789 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050220789). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:33Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:36Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050221241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050221241). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:36Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:39Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050221748 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050221748). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:39Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:42Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050222200 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050222200). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:42Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:45Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050222739 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050222739). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:45Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:48Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050223206 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050223206). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:48Z. **Review:** COMMENTED --- _No description provided._
R0Y00 commented 2026-11-25 02:01:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T02:00:52Z.

Review: CHANGES_REQUESTED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050502079 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6050502079). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T02:00:52Z. **Review:** CHANGES_REQUESTED --- 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](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copytextureregion)
tedin7 commented 2026-11-25 02:02:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:13:48Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149336317 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#issuecomment-7149336317). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:13:48Z. --- All 6 review threads fixed and pushed in 394dbe3a (rebased on origin/main).
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:33Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 96

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);

Fixed in 394dbe3a: fixed_heap_state() detects UPLOAD/READBACK buffers and skips require_state() for them; an upload destination or readback source is refused (bad_heap). Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688991070 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688991070). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:33Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 96 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); ~~~~ --- Fixed in 394dbe3a: `fixed_heap_state()` detects UPLOAD/READBACK buffers and skips `require_state()` for them; an upload destination or readback source is refused (`bad_heap`). Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:36Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 80

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");

Fixed in 394dbe3a: texture sides call upload_texture() before the copy; a non-aliased copied-buffer source is refused (stale_source). Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688991501 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688991501). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:36Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 80 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); ~~~~ --- Fixed in 394dbe3a: texture sides call `upload_texture()` before the copy; a non-aliased copied-buffer source is refused (`stale_source`). Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:39Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 101

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);
+    D3D12_TEXTURE_COPY_LOCATION to = *dst, from = *src;
+    to.pResource = real_dst;
+    from.pResource = real_src;
+    static_cast<ID3D12GraphicsCommandList*>(self->own().real)->CopyTextureRegion(&to, x, y, z, &from, box ? box : nullptr);
+    InterlockedIncrement(&list_copy_texture_forwarded);

Fixed in 394dbe3a: the destination texture is uploaded via upload_texture() before the copy, so the first sample no longer schedules an upload over the copied texels. Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688991981 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688991981). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:39Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 101 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); + D3D12_TEXTURE_COPY_LOCATION to = *dst, from = *src; + to.pResource = real_dst; + from.pResource = real_src; + static_cast<ID3D12GraphicsCommandList*>(self->own().real)->CopyTextureRegion(&to, x, y, z, &from, box ? box : nullptr); + InterlockedIncrement(&list_copy_texture_forwarded); ~~~~ --- Fixed in 394dbe3a: the destination texture is uploaded via `upload_texture()` before the copy, so the first sample no longer schedules an upload over the copied texels. Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:42Z.

Code review location: src/startup_stubs/list_copy_texture.inl; line 96

@@ -0,0 +1,108 @@
+// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870).
+// Each location's resource is mapped to its desktop resource, the call is checked by
+// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close
+// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded.
+#include "list_copy_texture.h"
+
+volatile LONG list_copy_texture_forwarded, list_copy_texture_refused;
+
+namespace {
+
+// One side of the copy, read from the desktop resource it names. False when the location is unusable.
+bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side,
+                       DXGI_FORMAT& format)
+{
+    Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr;
+    if (!w || w->own().kind != resource_kind || !w->own().real) return false;
+    real = static_cast<ID3D12Resource*>(w->own().real);
+    const D3D12_RESOURCE_DESC desc = real->GetDesc();
+    side = {};
+    side.block_w = side.block_h = 1;
+    side.multisampled = desc.SampleDesc.Count > 1;
+    if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) {
+        if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+        const auto& fp = location->PlacedFootprint;
+        side.kind = x2w_list_copy_texture::Kind::placed_footprint;
+        side.width = fp.Footprint.Width;
+        side.height = fp.Footprint.Height;
+        side.depth = fp.Footprint.Depth;
+        side.offset = fp.Offset;
+        side.row_pitch = fp.Footprint.RowPitch;
+        side.resource_bytes = desc.Width;
+        format = fp.Footprint.Format;
+        return true;
+    }
+    if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false;
+    const UINT mips = desc.MipLevels ? desc.MipLevels : 1;
+    const UINT mip = location->SubresourceIndex % mips;
+    side.kind = x2w_list_copy_texture::Kind::subresource;
+    side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip));
+    side.height = (std::max<UINT>)(1, desc.Height >> mip);
+    side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1;
+    format = desc.Format;
+    return true;
+}
+
+// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy.
+void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side)
+{
+    const D3D12_RESOURCE_DESC desc = texture->GetDesc();
+    ID3D12Device* device = nullptr;
+    if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return;
+    D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{};
+    UINT rows = 0;
+    UINT64 row_bytes = 0, total = 0;
+    device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total);
+    device->Release();
+    const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) ||
+                    (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB);
+    side.block_w = side.block_h = bc ? 4 : 1;
+    const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w);
+    side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks);
+}
+
+}  // namespace
+
+// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box).
+void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z,
+                                 const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box)
+{
+    if (!self->own().list_open) return;
+    static LONG logged;
+    const auto refuse = [&](const char* why) {
+        InterlockedIncrement(&list_copy_texture_refused);
+        if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why);
+    };
+    ID3D12Resource *real_dst = nullptr, *real_src = nullptr;
+    x2w_list_copy_texture::Side side_dst{}, side_src{};
+    DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN;
+    if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src))
+        return refuse("unknown_resource");
+    ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src;
+    if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) {
+        x2w_list_copy_texture::Side blocks{};
+        copy_texture_block(texture, blocks);
+        for (auto* s : {&side_dst, &side_src}) {
+            s->block_w = blocks.block_w ? blocks.block_w : 1;
+            s->block_h = blocks.block_h ? blocks.block_h : 1;
+            if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block;
+        }
+    }
+    x2w_list_copy_texture::Box copy_box{};
+    if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back};
+    const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr);
+    if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict));
+    require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST);

Fixed in 394dbe3a: a copy whose two sides are the same resource is refused (same_resource) since states are tracked per resource. Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688992444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688992444). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:42Z. **Code review location:** `src/startup_stubs/list_copy_texture.inl`; line 96 ~~~~diff @@ -0,0 +1,108 @@ +// Included by d3d12_xs_device.cpp after d3d12_draw.inl. Command list slot 16, CopyTextureRegion (#870). +// Each location's resource is mapped to its desktop resource, the call is checked by +// list_copy_texture.h, the two resources move to COPY_SOURCE / COPY_DEST for the call (the list's Close +// puts them back to COMMON), and a call the desktop would reject is counted and logged, not forwarded. +#include "list_copy_texture.h" + +volatile LONG list_copy_texture_forwarded, list_copy_texture_refused; + +namespace { + +// One side of the copy, read from the desktop resource it names. False when the location is unusable. +bool copy_texture_side(const D3D12_TEXTURE_COPY_LOCATION* location, ID3D12Resource*& real, x2w_list_copy_texture::Side& side, + DXGI_FORMAT& format) +{ + Wrapper* w = location && x2w_local::readable(location, sizeof(*location)) ? as_wrapper(location->pResource) : nullptr; + if (!w || w->own().kind != resource_kind || !w->own().real) return false; + real = static_cast<ID3D12Resource*>(w->own().real); + const D3D12_RESOURCE_DESC desc = real->GetDesc(); + side = {}; + side.block_w = side.block_h = 1; + side.multisampled = desc.SampleDesc.Count > 1; + if (location->Type == D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const auto& fp = location->PlacedFootprint; + side.kind = x2w_list_copy_texture::Kind::placed_footprint; + side.width = fp.Footprint.Width; + side.height = fp.Footprint.Height; + side.depth = fp.Footprint.Depth; + side.offset = fp.Offset; + side.row_pitch = fp.Footprint.RowPitch; + side.resource_bytes = desc.Width; + format = fp.Footprint.Format; + return true; + } + if (location->Type != D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX || desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return false; + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT mip = location->SubresourceIndex % mips; + side.kind = x2w_list_copy_texture::Kind::subresource; + side.width = static_cast<UINT>((std::max<UINT64>)(1, desc.Width >> mip)); + side.height = (std::max<UINT>)(1, desc.Height >> mip); + side.depth = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? (std::max<UINT>)(1, desc.DepthOrArraySize >> mip) : 1; + format = desc.Format; + return true; +} + +// Texels per block and bytes per block, from the desktop's own footprint for a one-subresource copy. +void copy_texture_block(ID3D12Resource* texture, x2w_list_copy_texture::Side& side) +{ + const D3D12_RESOURCE_DESC desc = texture->GetDesc(); + ID3D12Device* device = nullptr; + if (FAILED(texture->GetDevice(IID_PPV_ARGS(&device))) || !device) return; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT fp{}; + UINT rows = 0; + UINT64 row_bytes = 0, total = 0; + device->GetCopyableFootprints(&desc, 0, 1, 0, &fp, &rows, &row_bytes, &total); + device->Release(); + const bool bc = (desc.Format >= DXGI_FORMAT_BC1_TYPELESS && desc.Format <= DXGI_FORMAT_BC5_SNORM) || + (desc.Format >= DXGI_FORMAT_BC6H_TYPELESS && desc.Format <= DXGI_FORMAT_BC7_UNORM_SRGB); + side.block_w = side.block_h = bc ? 4 : 1; + const UINT64 blocks = (std::max<UINT64>)(1, (desc.Width + side.block_w - 1) / side.block_w); + side.bytes_per_block = static_cast<std::uint32_t>(row_bytes / blocks); +} + +} // namespace + +// List slot 16 (unshifted, like slots 12 to 25), CopyTextureRegion(dst, x, y, z, src, box). +void __stdcall list_copy_texture(Wrapper* self, const D3D12_TEXTURE_COPY_LOCATION* dst, UINT x, UINT y, UINT z, + const D3D12_TEXTURE_COPY_LOCATION* src, const D3D12_BOX* box) +{ + if (!self->own().list_open) return; + static LONG logged; + const auto refuse = [&](const char* why) { + InterlockedIncrement(&list_copy_texture_refused); + if (first_calls(logged, 6)) log("x2w-d3d12 CopyTextureRegion refused: %s", why); + }; + ID3D12Resource *real_dst = nullptr, *real_src = nullptr; + x2w_list_copy_texture::Side side_dst{}, side_src{}; + DXGI_FORMAT format_dst = DXGI_FORMAT_UNKNOWN, format_src = DXGI_FORMAT_UNKNOWN; + if (!copy_texture_side(dst, real_dst, side_dst, format_dst) || !copy_texture_side(src, real_src, side_src, format_src)) + return refuse("unknown_resource"); + ID3D12Resource* texture = side_dst.kind == x2w_list_copy_texture::Kind::subresource ? real_dst : real_src; + if (side_dst.kind == x2w_list_copy_texture::Kind::subresource || side_src.kind == x2w_list_copy_texture::Kind::subresource) { + x2w_list_copy_texture::Side blocks{}; + copy_texture_block(texture, blocks); + for (auto* s : {&side_dst, &side_src}) { + s->block_w = blocks.block_w ? blocks.block_w : 1; + s->block_h = blocks.block_h ? blocks.block_h : 1; + if (s->kind == x2w_list_copy_texture::Kind::placed_footprint) s->bytes_per_block = blocks.bytes_per_block; + } + } + x2w_list_copy_texture::Box copy_box{}; + if (box && x2w_local::readable(box, sizeof(*box))) copy_box = {box->left, box->top, box->front, box->right, box->bottom, box->back}; + const auto verdict = x2w_list_copy_texture::check(side_dst, x, y, z, side_src, box ? &copy_box : nullptr); + if (verdict != x2w_list_copy_texture::Verdict::ok) return refuse(x2w_list_copy_texture::name(verdict)); + require_state(self, real_src, D3D12_RESOURCE_STATE_COPY_SOURCE); + require_state(self, real_dst, D3D12_RESOURCE_STATE_COPY_DEST); ~~~~ --- Fixed in 394dbe3a: a copy whose two sides are the same resource is refused (`same_resource`) since states are tracked per resource. Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:45Z.

Code review location: src/startup_stubs/list_copy_texture.h; line 95

@@ -0,0 +1,100 @@
+// Experimental (docs/startup-runtime.md, #870): the argument checks for command list slot 16,
+// CopyTextureRegion(dst, x, y, z, src, box). Plain standard C++ so a Linux fixture can run it; the
+// handler (list_copy_texture.inl) maps the title's resources and forwards only what passes here.
+// A call the desktop runtime would reject is refused with a named reason instead.
+#pragma once
+
+#include <cstdint>
+#include <initializer_list>
+
+namespace x2w_list_copy_texture {
+
+enum class Kind : std::uint32_t { subresource = 0, placed_footprint = 1 };
+
+// What the check needs to know about one side of the copy. For a subresource side, width/height/depth are
+// the subresource's size in blocks (texels for an uncompressed format). For a footprint side, the footprint
+// size in blocks, the row pitch in bytes, the byte offset and the bytes per block are used, and
+// resource_bytes is the size of the buffer.
+struct Side {
+    Kind kind;
+    std::uint32_t width, height, depth;
+    std::uint64_t offset;
+    std::uint32_t row_pitch, bytes_per_block;
+    std::uint64_t resource_bytes;
+    bool multisampled;
+    std::uint32_t block_w, block_h;  // texels per block (4 x 4 for block-compressed formats, else 1 x 1)
+};
+
+struct Box {
+    std::uint32_t left, top, front, right, bottom, back;
+};
+
+enum class Verdict {
+    ok,
+    buffer_to_buffer,   // a footprint on both sides: the desktop wants CopyBufferRegion
+    bad_box,            // an empty or inverted source box
+    source_overflow,    // the source box leaves the source subresource
+    dest_overflow,      // the destination origin plus box size leaves the destination subresource
+    bad_pitch,          // a footprint row pitch below one row, or not a multiple of 256
+    bad_offset,         // a footprint offset that is not a multiple of 512
+    footprint_overflow, // the footprint reaches past the end of its buffer
+    sample_mismatch,    // a multisampled side paired with a single-sample one
+    bad_alignment       // a block-compressed copy that does not start on a block
+};
+
+inline const char* name(Verdict v) noexcept
+{
+    switch (v) {
+    case Verdict::ok: return "ok";
+    case Verdict::buffer_to_buffer: return "buffer_to_buffer";
+    case Verdict::bad_box: return "bad_box";
+    case Verdict::source_overflow: return "source_overflow";
+    case Verdict::dest_overflow: return "dest_overflow";
+    case Verdict::bad_pitch: return "bad_pitch";
+    case Verdict::bad_offset: return "bad_offset";
+    case Verdict::footprint_overflow: return "footprint_overflow";
+    case Verdict::sample_mismatch: return "sample_mismatch";
+    case Verdict::bad_alignment: return "bad_alignment";
+    }
+    return "unknown";
+}
+
+// Bytes a footprint of the given size reaches, from its offset (the last row is not padded).
+inline bool footprint_end(const Side& s, std::uint32_t w, std::uint32_t h, std::uint32_t d, std::uint64_t& end) noexcept
+{
+    if (!w || !h || !d) { end = s.offset; return true; }
+    const std::uint64_t row = std::uint64_t{(w + s.block_w - 1) / s.block_w} * s.bytes_per_block;
+    const std::uint64_t rows = (h + s.block_h - 1) / s.block_h;
+    if (row > s.row_pitch) return false;
+    const std::uint64_t slice = std::uint64_t{s.row_pitch} * (rows - 1) + row;
+    const std::uint64_t total = std::uint64_t{s.row_pitch} * rows * (d - 1) + slice;
+    end = s.offset + total;
+    return end >= s.offset;
+}
+
+// box == nullptr copies the whole source (for a footprint source, the whole footprint).
+inline Verdict check(const Side& dst, std::uint32_t x, std::uint32_t y, std::uint32_t z, const Side& src, const Box* box) noexcept
+{
+    if (dst.kind == Kind::placed_footprint && src.kind == Kind::placed_footprint) return Verdict::buffer_to_buffer;
+    if (dst.multisampled != src.multisampled) return Verdict::sample_mismatch;
+    const Box whole{0, 0, 0, src.width, src.height, src.depth};
+    const Box use = box ? *box : whole;
+    if (use.left >= use.right || use.top >= use.bottom || use.front >= use.back) return Verdict::bad_box;
+    if (use.right > src.width || use.bottom > src.height || use.back > src.depth) return Verdict::source_overflow;
+    const Side& tex = dst.kind == Kind::subresource ? dst : src;  // the side that knows the block size
+    if (x % tex.block_w || use.left % tex.block_w || y % tex.block_h || use.top % tex.block_h) return Verdict::bad_alignment;
+    const std::uint32_t w = use.right - use.left, h = use.bottom - use.top, d = use.back - use.front;
+    if (std::uint64_t{x} + w > dst.width || std::uint64_t{y} + h > dst.height || std::uint64_t{z} + d > dst.depth)
+        return Verdict::dest_overflow;
+    for (const Side* s : {&dst, &src}) {
+        if (s->kind != Kind::placed_footprint) continue;
+        if (!s->row_pitch || s->row_pitch % 256) return Verdict::bad_pitch;
+        if (s->offset % 512) return Verdict::bad_offset;
+        std::uint64_t end = 0;
+        if (!footprint_end(*s, w, h, d, end)) return Verdict::bad_pitch;
+        if (end > s->resource_bytes) return Verdict::footprint_overflow;

Fixed in 394dbe3a: footprint_end() includes the destination/source-box origin and the footprint-height slice stride; tests added (dest origin Y=63 -> footprint_overflow, box origin, 3D slice stride). Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688992934 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688992934). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:45Z. **Code review location:** `src/startup_stubs/list_copy_texture.h`; line 95 ~~~~diff @@ -0,0 +1,100 @@ +// Experimental (docs/startup-runtime.md, #870): the argument checks for command list slot 16, +// CopyTextureRegion(dst, x, y, z, src, box). Plain standard C++ so a Linux fixture can run it; the +// handler (list_copy_texture.inl) maps the title's resources and forwards only what passes here. +// A call the desktop runtime would reject is refused with a named reason instead. +#pragma once + +#include <cstdint> +#include <initializer_list> + +namespace x2w_list_copy_texture { + +enum class Kind : std::uint32_t { subresource = 0, placed_footprint = 1 }; + +// What the check needs to know about one side of the copy. For a subresource side, width/height/depth are +// the subresource's size in blocks (texels for an uncompressed format). For a footprint side, the footprint +// size in blocks, the row pitch in bytes, the byte offset and the bytes per block are used, and +// resource_bytes is the size of the buffer. +struct Side { + Kind kind; + std::uint32_t width, height, depth; + std::uint64_t offset; + std::uint32_t row_pitch, bytes_per_block; + std::uint64_t resource_bytes; + bool multisampled; + std::uint32_t block_w, block_h; // texels per block (4 x 4 for block-compressed formats, else 1 x 1) +}; + +struct Box { + std::uint32_t left, top, front, right, bottom, back; +}; + +enum class Verdict { + ok, + buffer_to_buffer, // a footprint on both sides: the desktop wants CopyBufferRegion + bad_box, // an empty or inverted source box + source_overflow, // the source box leaves the source subresource + dest_overflow, // the destination origin plus box size leaves the destination subresource + bad_pitch, // a footprint row pitch below one row, or not a multiple of 256 + bad_offset, // a footprint offset that is not a multiple of 512 + footprint_overflow, // the footprint reaches past the end of its buffer + sample_mismatch, // a multisampled side paired with a single-sample one + bad_alignment // a block-compressed copy that does not start on a block +}; + +inline const char* name(Verdict v) noexcept +{ + switch (v) { + case Verdict::ok: return "ok"; + case Verdict::buffer_to_buffer: return "buffer_to_buffer"; + case Verdict::bad_box: return "bad_box"; + case Verdict::source_overflow: return "source_overflow"; + case Verdict::dest_overflow: return "dest_overflow"; + case Verdict::bad_pitch: return "bad_pitch"; + case Verdict::bad_offset: return "bad_offset"; + case Verdict::footprint_overflow: return "footprint_overflow"; + case Verdict::sample_mismatch: return "sample_mismatch"; + case Verdict::bad_alignment: return "bad_alignment"; + } + return "unknown"; +} + +// Bytes a footprint of the given size reaches, from its offset (the last row is not padded). +inline bool footprint_end(const Side& s, std::uint32_t w, std::uint32_t h, std::uint32_t d, std::uint64_t& end) noexcept +{ + if (!w || !h || !d) { end = s.offset; return true; } + const std::uint64_t row = std::uint64_t{(w + s.block_w - 1) / s.block_w} * s.bytes_per_block; + const std::uint64_t rows = (h + s.block_h - 1) / s.block_h; + if (row > s.row_pitch) return false; + const std::uint64_t slice = std::uint64_t{s.row_pitch} * (rows - 1) + row; + const std::uint64_t total = std::uint64_t{s.row_pitch} * rows * (d - 1) + slice; + end = s.offset + total; + return end >= s.offset; +} + +// box == nullptr copies the whole source (for a footprint source, the whole footprint). +inline Verdict check(const Side& dst, std::uint32_t x, std::uint32_t y, std::uint32_t z, const Side& src, const Box* box) noexcept +{ + if (dst.kind == Kind::placed_footprint && src.kind == Kind::placed_footprint) return Verdict::buffer_to_buffer; + if (dst.multisampled != src.multisampled) return Verdict::sample_mismatch; + const Box whole{0, 0, 0, src.width, src.height, src.depth}; + const Box use = box ? *box : whole; + if (use.left >= use.right || use.top >= use.bottom || use.front >= use.back) return Verdict::bad_box; + if (use.right > src.width || use.bottom > src.height || use.back > src.depth) return Verdict::source_overflow; + const Side& tex = dst.kind == Kind::subresource ? dst : src; // the side that knows the block size + if (x % tex.block_w || use.left % tex.block_w || y % tex.block_h || use.top % tex.block_h) return Verdict::bad_alignment; + const std::uint32_t w = use.right - use.left, h = use.bottom - use.top, d = use.back - use.front; + if (std::uint64_t{x} + w > dst.width || std::uint64_t{y} + h > dst.height || std::uint64_t{z} + d > dst.depth) + return Verdict::dest_overflow; + for (const Side* s : {&dst, &src}) { + if (s->kind != Kind::placed_footprint) continue; + if (!s->row_pitch || s->row_pitch % 256) return Verdict::bad_pitch; + if (s->offset % 512) return Verdict::bad_offset; + std::uint64_t end = 0; + if (!footprint_end(*s, w, h, d, end)) return Verdict::bad_pitch; + if (end > s->resource_bytes) return Verdict::footprint_overflow; ~~~~ --- Fixed in 394dbe3a: `footprint_end()` includes the destination/source-box origin and the footprint-height slice stride; tests added (dest origin Y=63 -> footprint_overflow, box origin, 3D slice stride). Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:33:47Z.

Code review location: src/startup_stubs/d3d12_xs_device.cpp; line 3759

@@ -3755,6 +3756,7 @@ void build_tables()
         list_typed[52] = reinterpret_cast<ListTyped>(&list_clear_target);
         list_typed[139] = reinterpret_cast<ListTyped>(&list_reset);
         list_typed[12] = reinterpret_cast<ListTyped>(&list_draw);
+        list_typed[16] = reinterpret_cast<ListTyped>(&list_copy_texture);

Fixed in a2702c0d: new section 'Command list CopyTextureRegion (list slot 16)' in docs/startup-runtime.md with capability, scope, unverified Windows forwarding, and the command ctest --preset dev --no-tests=error -R '^startup_list_copy_texture' -V. Win2025 x2w_pipe.py win2025 2070: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688993370 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#discussion_r4688993370). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:33:47Z. **Code review location:** `src/startup_stubs/d3d12_xs_device.cpp`; line 3759 ~~~~diff @@ -3755,6 +3756,7 @@ void build_tables() list_typed[52] = reinterpret_cast<ListTyped>(&list_clear_target); list_typed[139] = reinterpret_cast<ListTyped>(&list_reset); list_typed[12] = reinterpret_cast<ListTyped>(&list_draw); + list_typed[16] = reinterpret_cast<ListTyped>(&list_copy_texture); ~~~~ --- Fixed in a2702c0d: new section 'Command list CopyTextureRegion (list slot 16)' in docs/startup-runtime.md with capability, scope, unverified Windows forwarding, and the command `ctest --preset dev --no-tests=error -R '^startup_list_copy_texture' -V`. Win2025 `x2w_pipe.py win2025 2070`: dev and release 23/23 ctest passed, incl. startup_list_copy_texture and its overflow control. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 04:04:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:03:19Z.


Addressed in d7610f5b (code in 2927598b).

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 d7610f5b: dev 25/25 and release 25/25 pass (100%), including startup_list_copy_texture_warp.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151544697 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#issuecomment-7151544697). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:03:19Z. --- Addressed in d7610f5b (code in 2927598b). 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 d7610f5b: dev 25/25 and release 25/25 pass (100%), including `startup_list_copy_texture_warp`. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 15:01:31 +00:00
R0Y00 commented 2026-11-25 15:01:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T14:45:31Z.

Review: APPROVED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6059798428 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2070#pullrequestreview-6059798428). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T14:45:31Z. **Review:** APPROVED --- 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
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!2063
No description provided.