D3D12.X: CopyMemoryToMemoryX within one unified-memory window copies a buffer in COPY_DEST to itself (debug layer error 538) #958

Closed
opened 2026-11-26 04:38:27 +00:00 by github-bot · 1 comment
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 09:32 UTC · original

CopyMemoryToMemoryX with its source and destination in the same unified-memory window copies inside one buffer while that buffer is in D3D12_RESOURCE_STATE_COPY_DEST. The D3D12 debug layer reports it as an error on every such copy, because a copy source must be in COPY_SOURCE.

Seen: on main 077ce40, in the e2e test title under the debug layer (e2e::test_title_draws_with_a_root_signature_under_the_debug_layer, XCL_D3D12_DEBUG=1), target/e2e-debug-layer/data/XCL.TestTitle/logs/xcl.log:

D3D12 debug layer (error, id 538): ID3D12CommandList::CopyBufferRegion: ... Resource state (0x400: D3D12_RESOURCE_STATE_COPY_DEST) of resource (...) (subresource: 0) is invalid for use as a source buffer.  Expected State Bits (all): 0x800: D3D12_RESOURCE_STATE_COPY_SOURCE, Actual State: 0x400: D3D12_RESOURCE_STATE_COPY_DEST, Missing State: 0x800: D3D12_RESOURCE_STATE_COPY_SOURCE.

It comes from the test title's console_list_methods, which copies 64 bytes within its own graphics memory. That step makes no CopyBufferRegion call of its own. The copy is XCL's translation in list_x.rs copy_memory_x:

if d == s {
    // one window: the buffer is the source and the destination (the ranges do not overlap)
    as_copy_dest(this, d, || copy_buffer_region(this, d, doff, s, soff, size));
    return;
}

The cross-window path transitions the source to COPY_SOURCE; this one cannot, because one buffer cannot be in COPY_SOURCE and COPY_DEST at once.

Effect: the bytes do arrive. The test title checks them (CopyMemoryToMemoryX passes), and so did the RTX 3060 here. So nothing is visibly wrong today. But it is a copy D3D12 does not define, so a driver may handle it differently, and it is an error in every debug-layer log of a title that copies within a window.

Possible fix (not tried): copy through a scratch buffer, as #473 does for sources outside unified memory: first source range → scratch (COPY_SOURCE → COPY_DEST), then scratch → destination range. Or, when the two ranges are in different placed resources of the window, use those.

Also, the e2e debug-layer test only looks for "No root signature has been set". On main the same log has 5 debug-layer errors: this one, three id 93 and one id 1046. The id 93 and 1046 errors come from the deliberately invalid console shaders in pso_capture_and_fallback / xbox_native_pso, and XCL falls back from them as intended. An allow-list of those ids would let the test catch new errors.

Machine: RTX 3060 12 GB, driver 32.0.16.1088, Windows 11 26300, Graphics Tools (D3D12 SDK layers) installed, Rust 1.100.0 MSVC, debug.

Not tested: AMD; a retail title.

AI use: Claude Code (Claude Opus 5.5) ran the test, traced the message to copy_memory_x and wrote this issue.

**@⁠fromthemoonx** on GitHub · 2026-11-24 09:32 UTC · [original](https://github.com/xcl-dev/xcl/issues/958) `CopyMemoryToMemoryX` with its source and destination in the same unified-memory window copies inside one buffer while that buffer is in `D3D12_RESOURCE_STATE_COPY_DEST`. The D3D12 debug layer reports it as an error on every such copy, because a copy source must be in `COPY_SOURCE`. **Seen**: on `main` `077ce40`, in the e2e test title under the debug layer (`e2e::test_title_draws_with_a_root_signature_under_the_debug_layer`, `XCL_D3D12_DEBUG=1`), `target/e2e-debug-layer/data/XCL.TestTitle/logs/xcl.log`: ``` D3D12 debug layer (error, id 538): ID3D12CommandList::CopyBufferRegion: ... Resource state (0x400: D3D12_RESOURCE_STATE_COPY_DEST) of resource (...) (subresource: 0) is invalid for use as a source buffer. Expected State Bits (all): 0x800: D3D12_RESOURCE_STATE_COPY_SOURCE, Actual State: 0x400: D3D12_RESOURCE_STATE_COPY_DEST, Missing State: 0x800: D3D12_RESOURCE_STATE_COPY_SOURCE. ``` It comes from the test title's `console_list_methods`, which copies 64 bytes within its own graphics memory. That step makes no `CopyBufferRegion` call of its own. The copy is XCL's translation in `list_x.rs` `copy_memory_x`: ```rust if d == s { // one window: the buffer is the source and the destination (the ranges do not overlap) as_copy_dest(this, d, || copy_buffer_region(this, d, doff, s, soff, size)); return; } ``` The cross-window path transitions the source to `COPY_SOURCE`; this one cannot, because one buffer cannot be in `COPY_SOURCE` and `COPY_DEST` at once. **Effect**: the bytes do arrive. The test title checks them (`CopyMemoryToMemoryX` passes), and so did the RTX 3060 here. So nothing is visibly wrong today. But it is a copy D3D12 does not define, so a driver may handle it differently, and it is an error in every debug-layer log of a title that copies within a window. **Possible fix** (not tried): copy through a scratch buffer, as #473 does for sources outside unified memory: first source range → scratch (`COPY_SOURCE` → `COPY_DEST`), then scratch → destination range. Or, when the two ranges are in different placed resources of the window, use those. Also, the e2e debug-layer test only looks for "No root signature has been set". On `main` the same log has 5 debug-layer errors: this one, three id 93 and one id 1046. The id 93 and 1046 errors come from the deliberately invalid console shaders in `pso_capture_and_fallback` / `xbox_native_pso`, and XCL falls back from them as intended. An allow-list of those ids would let the test catch new errors. **Machine**: RTX 3060 12 GB, driver 32.0.16.1088, Windows 11 26300, Graphics Tools (D3D12 SDK layers) installed, Rust 1.100.0 MSVC, debug. **Not tested**: AMD; a retail title. AI use: Claude Code (Claude Opus 5.5) ran the test, traced the message to `copy_memory_x` and wrote this issue.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:38:27 +00:00
Author
Owner

@⁠zohaiblazuli on GitHub · 2026-11-24 09:50 UTC · original

I'm working on this: CopyMemoryToMemoryX within one window will read its source through a second buffer placed on the same window heap (in COPY_SOURCE), so no buffer is in COPY_DEST and COPY_SOURCE at once. PR with a debug-layer test soon. (Claude Code, Claude Opus 5.5)

**@⁠zohaiblazuli** on GitHub · 2026-11-24 09:50 UTC · [original](https://github.com/xcl-dev/xcl/issues/958#issuecomment-7127951711) I'm working on this: CopyMemoryToMemoryX within one window will read its source through a second buffer placed on the same window heap (in COPY_SOURCE), so no buffer is in COPY_DEST and COPY_SOURCE at once. PR with a debug-layer test soon. (Claude Code, Claude Opus 5.5)
This discussion has been locked. Commenting is limited to contributors.
No description provided.