Repository navigation
startup: carry verified copy ranges into indirect draws - #2240
Conversation
…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.
…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
left a comment
There was a problem hiding this comment.
Review of head 13b21704066faf51a335d1a3068efb639e6eb898 (range handoff on top of merge b6755e9e).
Verdict: no P1, no P2. Three nits. Linux-side review only; I did not build or run the MSVC/WARP fixtures (see "Not verified").
Commands executed locally (Linux):
gh pr checks 2240-> no CI checks reported on the branch.mergeable: MERGEABLE, title neutral.git diff --stat origin/main...HEAD-> 11 files, +1779/-21.git diff --stat b6755e9e HEAD-> 6 files; the handoff itself is small.python3 tests/docs_links_check.py-> "Checked 18 Markdown files and 412 links."python3 tests/bidi_controls_check.py-> "no bidirectional controls."git diff --check origin/main...HEAD-> exit 0.
What I checked in the handoff diff:
d3d12_xs_device.cpp:2019-2040list_copied_gpu_range/note_copy_gpu_range: containment testoffset >= r.offset && bytes <= r.bytes && offset - r.offset <= r.bytes - bytescannot underflow or overflow. The overlap erase handles both orderings and is also run for non-authoritative writers, so an untracked overlapping copy drops the proof. Cap of 64 fails closed.- Scope: ranges live in
Pass, whichrelease_targetsresets withpass = Pass{}at Close (:2071), matching the doc claim that another recording needs its own writer. list_copy.inl:158-174copy_source_authoritative: requires live wrapper,COMMONinitial state, same device, and for title-backed sources a unique placed owner that is either an alias or already covered. Reasonable and fail-closed.list_copy.inl:186-196: with the flag off,check_endpoint_roles+sync_title_sourceis equivalent to the oldcheck_roles_and_sync(..., true), so the old refusal behaviour is unchanged.d3d12_draw.inl:1446-1453: a non-alias placement now needslist_copied_gpu_rangefor the whole view; alias path unchanged.
Findings:
- nit,
list_copy.inl:196and:223-225:mark_gpu_writtenis no longer called for buffer destinations, for CopyBufferRegion and for CopyResource of buffers, and this also applies with the feature off. I found no consumer for buffers (gpu_writtenis read only for textures:d3d12_draw.inl:1034,list_copy.inl:87-88), so I think it is harmless, but please mention it in the PR body or keep the call to leave the flag-off path byte-identical. - nit,
list_copy.inl:223: a whole-resourceCopyResourcebuffer-to-buffer from an authoritative source only erases ranges; it never records one. This is conservative (fails closed) but worth a one-line note indocs/experiments.mdso nobody expects it to qualify. - nit,
d3d12_xs_device.cpp:2026:list_copied_gpu_rangereturns early on the env flag butnote_copy_gpu_rangeis also gated, so both are consistent; consider caching oneindirect_copy_ranges()result per call site to make that obvious. No functional issue.
Not verified (honest limits):
- No Windows build or WARP/hardware run was done by me; the new CTest entries
startup_indirect_copy_provenance_{warp,hardware}and..._off_...rely on the author's reported local run. The PR is not Draft, and there are no CI checks, so a real Win2025 WARP dev+release pass is still needed before merge. - I did not perform a logic mutation: the touched code is MSVC/D3D12 only and cannot be built on Linux here. Suggested mutations for the Windows pass: (1) drop the
offset - range.offset <= range.bytes - bytesbound; (2) skip the overlap erase innote_copy_gpu_range; (3) drop theplacement_devicecheck incopy_source_authoritative. The 64-byte-copy and untracked-overwrite cases in the fixture should kill (1) and (2); I could not tell from reading whether any case kills (3).
AI-assisted; commands listed were executed locally.
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head f81d3c8aada029fa30fbbbba136125facb66decd (previous review covered 13b2170; this head merges main on top).
Commands executed locally (worktree of the PR head):
git diff --stat origin/main...HEAD: 6 files, +173/-21 (CMakeLists, docs/experiments.md, d3d12_draw.inl, d3d12_xs_device.cpp, list_copy.inl, tests/startup_indirect_draw_indexed.cpp)python3 tests/docs_links_check.py: self-test passed, 18 Markdown files / 419 links OKpython3 tests/bidi_controls_check.py: 1527 files, no bidirectional controlsgit diff --check origin/main...HEAD: cleangh pr checks 2240: Linux Python checks, gfx1013 fixtures and Windows build/test pass; /O2 job skipped- Mergeable: yes. Title is neutral.
- No C++ mutation run: this is D3D12 code that only builds on Windows, and no Linux build exists for it. I rely on the green Windows CI job and did not queue the Win2025 VM.
Findings
P2: src/startup_stubs/list_copy.inl:~200 (list_copy_buffer_region) and :~224 (list_copy_resource, buffer branch). The unconditional mark_gpu_written(self, to) is gone from both paths, and the new range bookkeeping returns early when X2W_TRANSLATED_INDIRECT_COPY_RANGES is off. With the flag off (the default), a copy into a title-backed buffer no longer queues the destination in pending_gpu_writes. commit_list_gpu_writes then never sets gpu_written/done for it on submit. That is a behavior change on the default path for a PR that presents itself as opt-in. Suggested fix: keep mark_gpu_written(self, to) on the buffer paths regardless of the flag, and add the range note on top. Or, if the removal is intended because it never applied to buffers, say so in the commit message and cover it with a test. Today the copy-provenance-off case only checks that indirect draws are refused, so it would not notice this.
P2 (test gap): the -off case does not pin that the pre-existing copy behavior is unchanged with the flag off. I'd add one assertion on the pending-write or gpu_written state after a buffer copy with the flag off.
Nit: note_copy_gpu_range silently drops a range when ranges.size() >= 64 and the 65th is authoritative. Overlapping ranges are erased first, so the stale entry is gone and the case fails closed. That is the right direction, but a one-line comment would make it deliberate.
Nit: note_copy_gpu_range swallows std::bad_alloc with a bare return. That also fails closed (no range recorded), so it is fine. It just deserves a comment saying why.
What looks right
- Containment check
offset - range.offset <= range.bytes - bytesis overflow-safe, andaddress + offsethas an explicit overflow guard. CopyResourceof a buffer records a non-authoritative range, which erases overlapping authoritative ranges. That correctly invalidates them.d3d12_draw.inlnow requireslist_copied_gpu_rangewhenever the placement has no alias. It stays fail-closed.
AI-assisted; commands listed were executed locally.
Depends on #1944 and #2236. Refs #870. The review base composes their tested heads
18ec51deand741e2ef7so this diff contains only the range handoff.With
X2W_TRANSLATED_INDIRECT_COPY_RANGES=1, the translated indirect Draw can bind a copied placed buffer when a verified slot 15 CopyBufferRegion on the same recording supplied the complete descriptor range. The source must be an authoritative desktop buffer, an exact alias, or a range already covered in that recording. An overlapping write without provenance drops the earlier proof. A new command-list recording must establish its own coverage. The draw reads the actual desktop destination at the recorded byte offset and leaves CPU backing alone.The source-built fixture recreates a 68-byte request at source offset
0xbfffa0. The compute writer fills the source, slot 15 copies it, and fenced colour readback gets eight red pixels while the title-memory sentinel stays green. The same DLL with the feature disabled leaves the target clear. Changing recordings, shortening the copy to 64 bytes, or overwriting part of it from an untracked endpoint also leaves the target clear. The observed request shape alone does not establish the provenance of a live non-aliased source.Local MSVC Release on Windows 11 build 26200.9974. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The indirect draw fixtures enable the D3D12 debug layer.
12/12 passed, no skips. AI-assisted. Commands executed locally.