Skip to content

startup: copy and resolve whole resources on a recording list (slots 15, 17, 19) - #1944

Merged
R0Y00 merged 6 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-list-copy
Nov 25, 2026
Merged

R0Y00 merged 6 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-list-copy

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Related to #870 (no Fixes).

What changes

In render mode, three command-list slots that were dropped now copy whole resources:

  • slot 15 CopyBufferRegion, slot 17 CopyResource, slot 19 ResolveSubresource (unshifted, like slots 12 to 25).
  • Each argument is mapped to its desktop resource. The pair moves to COPY_SOURCE/COPY_DEST or RESOLVE_SOURCE/RESOLVE_DEST for the call and back to COMMON at Close. An upload buffer stays readable and a readback buffer stays a copy destination.
  • A call the desktop would reject is counted, logged (first six) and not forwarded, with a named reason (size_mismatch, sample_mismatch, range_overflow, source_not_multisampled, ...). Calls on a closed list are ignored.
  • A typeless resolve format resolves as the family's typed choice (half float for R16G16B16A16, as in startup: show a typeless 16-bit RGBA surface through a half-float view #1729; normalised for the 8-bit and 10-bit families). One with no single choice (for example R16_TYPELESS) is refused as bad_format.
  • x2w_d3d12_list_copy_stats exports the counters for fixtures.
  • CopyTextureRegion (16) and CopyTiles (18) are left out on purpose.

Code is in new files: src/startup_stubs/list_copy.h (pure checks) and list_copy.inl (handlers). d3d12_xs_device.cpp gets one include of each, plus three install lines after the slot 52 line.

These slots have not been seen in a title log yet; the placement follows the unshifted slot order.

Checks run locally (Linux)

g++ -std=c++17 -Wall -Wextra -Isrc -I/usr/include/directx -I/usr/include/wsl/stubs -include wsl/winadapter.h tests/startup_list_copy_check.cpp
./a.out   # ok; --mutate overflow, typeless, samples each fail
x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only -Isrc tests/startup_list_copy.cpp
x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only ... src/startup_stubs/d3d12_xs_device.cpp   # only the two __try/__except errors of local_log.h, none from the new code
git diff --check
python3 -B tests/docs_links_check.py
python3 -B tests/bidi_controls_check.py
git merge-tree --write-tree HEAD <ref>   # origin/main, #1726, #1787, #1788, #1799, #1800, #1803: no conflicts

Not run

startup_list_copy_{warp,hardware} and the new device code have not been built or run; they need Windows. The fixture records on one list: clear and copy, a swapped copy (the empty texture stays empty), a 4-sample resolve, a typeless half-float resolve, two buffer copies with offsets, four refused calls (size mismatch, null source, one-sample resolve source, range past the end) and calls on a closed list, then reads everything back and checks the debug layer.

AI-assisted; commands listed were executed locally.


Replaces closed draft #1811 (rebased cleanly on origin/main).
AI-assisted; commands listed were executed locally.

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

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T22:08:13.259429Z e7b39dc Draft marked ready
ℹ️ About Codex in GitHub

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

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

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7b39dc483

ℹ️ About Codex in GitHub

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

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

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

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

Comment thread src/startup_stubs/list_copy.inl Resolved
Comment thread src/startup_stubs/list_copy.inl Resolved
Comment thread src/startup_stubs/list_copy.inl Resolved
Comment thread src/startup_stubs/list_copy.h Resolved
Comment thread src/startup_stubs/list_copy.inl Resolved
Comment thread src/startup_stubs/list_copy.h Resolved
@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Merge-order check: these four PRs cannot all land in any order — one pair conflicts, the other three compose

Four open PRs now add command-list behaviour to the same two files (CMakeLists.txt, src/startup_stubs/d3d12_xs_device.cpp):
#1975, #1974, #1972, #1944. I merged them against main 889cd3f4 in every pair, then all four together.

#1975 + #1974   clean
#1975 + #1972   clean
#1975 + #1944   clean
#1974 + #1972   clean
#1974 + #1944   clean
#1972 + #1944   conflict: CMakeLists.txt, src/startup_stubs/d3d12_xs_device.cpp

And the four-way merge conflicts on the same pair, at the shared CMakeLists.txt insertion point just after the
foreach(backend IN ITEMS warp hardware …) block that registers the list tests — the two PRs append their new
add_executable / add_test group at the same anchor, so git has no ordering hint to pick.

The three that do compose, compose for real

Merged #1975 + #1974 + #1972 onto main, configured, built and ran their tests:

git merge pr-1975 pr-1974 pr-1972          # 0 conflicts
cmake --preset dev                          # Generating done
cmake --build --preset dev --target startup_root_constant_store startup_list_dispatch_check startup_clear_uav
build exit 0

ctest --preset dev -R 'root_constant|list_dispatch|clear_uav'
1/6 startup_root_constant_store ............   Passed 0.15
2/6 startup_clear_uav_warp .................   Passed 0.62
3/6 startup_clear_uav_hardware .............   Passed 4.03   (physical GPU, not a skip)
4/6 startup_list_dispatch ..................   Passed 0.14
5/6 startup_list_dispatch_no-limit_control .   Passed 0.03
6/6 startup_list_dispatch_no-state_control .   Passed 0.02
100% tests passed, 0 tests failed out of 6

So the command-list slots those three add coexist in one build, including both negative controls that #1974 registers.

What this means for ordering

Nothing is semantically wrong with #1944 — it is a text conflict at a shared anchor. The practical consequence is that whichever of
#1972 / #1944 lands second has to rebase
, and a rebase that resolves the anchor by hand needs the same care as the original: the
ENVIRONMENT list (X2W_D3D12_PERMISSIVE, X2W_D3D12_LIST_NOOP, X2W_D3D12_RENDER, X2W_D3D12_DEBUG) and SKIP_RETURN_CODE 77
have to survive on both groups, or one PR's tests silently run without the permissive flags and fail in CI instead of here.

I did not resolve the conflict myself: the resolution depends on which PR the maintainer wants first, and inventing an ordering would
hide the decision.

Aside, same family

#1951 and #1947 (the two tools/ PRs in this batch) touch different files and do not conflict with any of the above.

Notes

  • AI-assisted, run on Windows 11 build 26300.9974 with MSVC 19.44.

@Makto94

Makto94 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

WARP and hardware run of startup_list_copy_* at head e7b39dc4 (Debug build, Windows 11 build 26300, NVIDIA GeForce RTX 3070 Ti driver 32.0.16.2101, D3D12 debug layer enabled via X2W_D3D12_DEBUG=1):

ctest --test-dir out/build/dev -j1 --no-tests=error -R '^startup_list_copy_' -V

Result: 6/6 passed (100% tests passed, 0 tests failed out of 6).

  • Passed: startup_list_copy_warp and startup_list_copy_hardware, plus the 4 startup_list_copy_validation* tests. 0 capability skips (exit code 77).
  • Debug-layer messages in the log (sev is D3D12_MESSAGE_SEVERITY: 1 = ERROR, 2 = WARNING): no sev=0 or sev=1 line; each GPU test logs 4 sev=2 id=820 warnings (ClearRenderTargetView: The clear values do not match those passed to resource creation).

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed in 5bda1cf (all six review threads):

  • Title-backed sources (P1): CopyResource and CopyBufferRegion refresh the source first. A texture takes the draw path's upload, an upload buffer is copied through a desktop mapping, an aliased placed buffer is already current. A title-backed default-heap buffer is refused as title_backed_source.
  • GPU-written destinations (P1): a copy or resolve destination with title memory is marked GPU-written in the texture upload state, so a later draw no longer uploads stale title memory over the result.
  • Placed buffer initial state (P2): a buffer whose recorded initial state is not COMMON is refused as initial_state, like list_execute_indirect().
  • Resolve format (P2): a fully typed endpoint now fixes the format exactly (typed destination or source is picked before the typeless fallback); family compatibility only applies to typeless endpoints.
  • Heap direction (P2): an upload buffer as a destination or a readback buffer as a source is refused as heap_direction.
  • DXGI families (P2): the family table now covers BC1-7, R8, R8G8, R16, R32G32, R32G32B32, R32G8X24, R24G8, B8G8R8X8 and the depth members.

Verification: x2w_pipe.py win2025 1944 on Win2025: 27/27 passed, including startup_list_copy_warp and startup_list_copy_validation (new pure checks for typed-endpoint resolve and the BC7/R16/R8 families; the warp probe now refuses a copy into an upload buffer and out of a readback buffer). The title-backed sync and GPU-written paths need a title-memory resource, which the warp probe does not create, so they are not covered by a fixture yet.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 force-pushed the x2w-frontier-list-copy branch from 5bda1cf to 0c60379 Compare November 25, 2026 03:38

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independent Release test of 0c60379: all six existing cases pass, including WARP and RTX 4060 Laptop. One remaining source-path issue is outside those cases. sync_title_source returns success for a title-backed texture even when upload_texture cannot stage it; the handler can then copy an older desktop texture and mark the destination GPU-written. The upload-buffer branch also recopies into the same backing at command recording, without preserving bytes already referenced by a stalled submission.

Please keep the validated direct-resource and genuinely aliased source paths. For other title-backed sources either refuse while the upload is unavailable, or use a validated per-recording upload whose lifetime follows the consuming fence. A source-built missing/unreadable title input should leave the destination sentinel unchanged. If keeping the copied upload-buffer path, gate submission A, change its title bytes and submit B, then release and check both payloads. The current six cases remain useful and should stay.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. Fixed in dfadc46 (code in 0004422).

  • upload_texture now reports whether it really staged the texture. sync_title_source returns that result, so a title-backed texture that cannot be staged (unreadable, unsupported or too many mips) is refused with title_backed_source. The destination is never written and not marked GPU-written.
  • The upload-buffer branch is removed. A title-backed upload buffer is refused rather than recopied into one backing while an earlier submission may still read it. Direct resources and aliased placed buffers behave as before. Docs updated.
  • Tests (startup_list_copy): the six existing cases stay. New 8a copies from a staged title-backed texture and checks the destination texels. New 8b copies from a title-backed texture whose pages are decommitted: it is refused, counted, and the destination keeps its sentinel.

Verification (Windows Server 2025, WARP, default 3-slot pool, x2w_pipe.py win2025 1944 --force): dev 26/26 and release 26/26 passed, no skips, including startup_list_copy_warp and the startup_list_copy_validation* tests. A first release attempt died on a compile-cache connection reset and passed on rerun. Linux: python3 -I tests/docs_links_check.py passed.

The upload-buffer refusal has no GPU case of its own yet; I only covered it through the docs and the shared refusal path.

AI-assisted; commands listed were executed locally.

…n, check heap direction and DXGI families

- CopyResource/CopyBufferRegion refresh a title-backed source first (texture upload, upload-buffer map copy); title-backed default buffers are refused.
- Copy and resolve destinations are marked GPU-written so a later draw does not re-upload stale title memory over them.
- Placed buffers that do not start in COMMON and upload/readback buffers used in the wrong direction are refused.
- Resolve format is exact against a fully typed endpoint; CopyResource accepts the remaining DXGI families (BC, R8, R16, R32G32, depth).
…drop the upload-buffer recopy

A title-backed texture is copied from only when the draw path's upload staged it (or the GPU wrote it); otherwise the copy is refused and the destination is untouched. A title-backed upload buffer is refused instead of being rewritten while an earlier submission may still read it. Aliased placed buffers and direct resources are unchanged. Tests: staged and unreadable title-backed sources.
@tedin7
tedin7 force-pushed the x2w-frontier-list-copy branch from dfadc46 to 3f7b8a5 Compare November 25, 2026 05:57

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Independent Release check on 3f7b8a5f: all six existing startup_list_copy_* checks passed. A source-built repro added to the same fixture fails on both WARP and RTX 4060 Laptop: create a placed texture with CPU texels 0x44332211, record CopyResource into it, Close and Reset without submitting, then copy out of that texture and wait on the fence. Actual 0x00000000, expected 0x44332211. The destination is marked GPU-written during recording, so the discarded copy prevents its first CPU upload.

I tried a focused local revision. Track unsubmitted writes on their recording, use them for reads on that list, publish the GPU-written state on submission, and discard the pending records on Reset or failed Close. For CPU-backed texture copy sources, take a fresh snapshot using the existing recording-owned upload and fence retirement path. The shared draw upload cache may reuse an earlier snapshot within one frame.

With that revision, ctest --preset release -j1 --no-tests=error -R '^startup_list_copy_' -V passed 6/6. Both adapters read back 44332211 after the discarded write, 44332211 then 88776655 from two copies recorded around a CPU write, and ff0000ff from a GPU-written texture both on its own recording and after submission. Windows 11 build 26200.9974, NVIDIA 32.0.16.1656, WARP 10.0.26100.9818, debug layer enabled. Both reported zero errors and four existing clear-value warnings (820), with no skips.

The slot 15 wording also needs an update. A local trace shows a 68-byte copy at a nonzero source offset between two non-aliased placed buffers. The source is UAV-capable. Please keep that case refused until there is a validated source of current bytes. The texture revision adds no new buffer-backing behavior.

…hile recording

A copy recorded then discarded by Close and Reset no longer stops the destination's first upload from title memory. Pending writes are tracked per recording, read by that list, committed by ExecuteCommandLists and dropped on Reset or a failed Close.
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, reproduced and fixed in 18ec51d (code in 0aafe6b).

  • A copy or resolve into a title-backed texture is now recorded as a pending write on its recording. The texture is marked GPU-written only when ExecuteCommandLists submits that list. Reset and a failed Close drop the pending writes, so a discarded copy no longer blocks the first upload from title memory.
  • Reads on the same recording (a later copy source, or a draw upload check) see that list's own pending writes, so a texture written earlier on the same list is not overwritten from stale memory.
  • New startup_list_copy case 10: place a texture with 0x44332211, record CopyResource into it, Close and Reset without submitting, then copy out of it and wait on the fence. It reads back 0x44332211. Docs wording updated.
  • Not done: the fresh snapshot for CPU-backed copy sources recorded around a CPU write, and the slot 15 wording update. Slot 15 behaviour is unchanged and that case stays refused.

Verification (Windows Server 2025, WARP, default 3-slot pool, x2w_pipe.py win2025 1944 --force): dev 26/26 and release 26/26 passed, no skips. An earlier release attempt died on a compile-cache connection error and passed on rerun. Linux: python3 -I tests/docs_links_check.py passed.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The previous source and discarded-recording findings are resolved. On Windows Release I independently ran all six startup_list_copy checks on this head. Both WARP and RTX 4060 Laptop passed the discarded-copy and same-recording read controls. A Reset leaves the first upload available and a real submitted copy preserves GPU-written contents.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants