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

Closed
opened 2026-11-24 09:32:30 +00:00 by fromthemoonx · 1 comment
fromthemoonx commented 2026-11-24 09:32:30 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T09:32:30Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:6578772225 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/958). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T09:32:30Z. --- `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.
zohaiblazuli commented 2026-11-24 10:04:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by zohaiblazuli on 2026-11-24T09:50:01Z.


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)

<!-- greyfinch-sync:ivall/xcl:comment:7127951711 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/issues/958#issuecomment-7127951711). Originally posted by [zohaiblazuli](https://github.com/zohaiblazuli) on 2026-11-24T09:50:01Z. --- 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)
Sign in to join this conversation.
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
xcl-dev/xcl#952
No description provided.