Repository navigation
gpu, docs: copy within one buffer through a staging buffer - #50
Conversation
479ba8d to
e634776
Compare
simnJS
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. The fix is right: one buffer cannot be in COPY_SOURCE and COPY_DEST at once, so a copy-engine copy within one buffer has to go through a second buffer. The two tests whose 538 allowances you removed do cover the non-overlapping case (copy_memory(at + 448, at, 64) in list.rs, the page-5 copy inside one card buffer in host/buffers.rs), and the debug-layer job is green. Approving.
Two points for a follow-up:
-
Cost per copy. A non-overlapping copy within one buffer used to allocate nothing. Now each one places a new System-pool buffer on the recording thread (
CreatePlacedResource,Map, the lease, at least 64 KiB of pool held until the list is reset), andPool::placezeroes any reused range on the CPU although the GPU overwrites all of it. WithXTP_CARD_BUFFERS=1, a copy that stayed in card memory now crosses PCIe twice. A list recording hundreds of small copies inside one ring buffer would hold tens of MiB of the pool. A count of same-buffer copies per frame would show whether this matters; if it does, one staging buffer per list reused across its copies, or no zeroing for this use, would fix it. -
Failure path. If
shared_bufferfails,copynow returns false for any same-buffer copy, and the caller falls back to a CPU copy of title memory at submission, which misses shader writes made earlier in the list. Overlapping copies already behaved so and it needs memory exhaustion, but aonce!warning there would help.
Nits: the title becomes the squash commit, so it should be imperative, e.g. "gpu: copy within one buffer through a staging buffer". Please also drop the Co-Authored-By trailer; the description already records the AI assistance, which is where the project keeps it.
I will merge as soon as the trailer is gone and the title is updated (a force-push of the reworded commit is fine).
|
Pushed 3db9e91 on top: follow-ups from an in-house review.
The debug-layer suite and the full WARP pr-check pass. Left for later: reusing one staging buffer per list, and splitting very large copies into chunks. |
|
Thanks for the follow-ups: the card-side staging and the throttled warning both look right. Before I merge:
The two |
3db9e91 to
b5b8d70
Compare
|
Pushed b5b8d70 on 4a0cdb3, with the imperative title and no Co-Authored-By trailers. The description records both Claude's original/follow-up work and Codex's integration and verification. The functional patch is unchanged from the prepared branch: same-buffer copies stage separately, card-resident copies use card staging, the staging state returns to COMMON, and allocation failure emits the counted warning. Both 538 allowances are gone. Fresh verification from this worktree passed on the first run:
The previous silent CPU fallback on staging allocation failure remains a documented limitation. Staging reuse/chunking and a same-buffer-copy frequency measurement are follow-ups. Current main merges cleanly with this head. |
simnJS
left a comment
There was a problem hiding this comment.
Thanks: the title, the trailers and the AI line are fixed, and the card staging (COMMON→DEST→SOURCE→COMMON) looks right.
One blocker: both clippy jobs fail because known_layer_errors is now never used (crates/xtp-gpu/src/testgpu.rs:103). Main removed its other caller in a1367f5, so dropping the two 538 allowances in this PR leaves it unused once merged. Please delete the function, which is cleaner than #[allow(dead_code)], then rebase on main and I'll merge once CI is green.
Route every same-buffer copy through a staging resource so D3D12 never reads and writes one resource in incompatible states. Keep the fallback warning when staging allocation fails.
b5b8d70 to
fa35267
Compare
|
Addressed the Clippy blocker on
Fresh local checks on that exact head:
The first full-check attempt inherited The PR description includes the cleanup and keeps the existing allocation-failure fallback limitation explicit. No new title or hardware run. Please re-review the current head once CI finishes. |
simnJS
left a comment
There was a problem hiding this comment.
Thanks: known_layer_errors and its state are gone, the branch is rebased, and both clippy jobs and the debug-layer job are green. The card staging and the counted warning are unchanged. Approving; I'll merge.
What and why
Copying between two ranges of one host buffer left the source in
COPY_DEST, which D3D12 rejects with message 538. Every same-buffer copy now uses a separate staging buffer so the source and destination states remain valid.Card-resident copies stage on the card; other copies use a shared buffer. The staging resource stays alive with the recording and returns to
COMMONafter the copy. If allocation fails, a counted warning reports the size and memory kind before the existing CPU fallback. That fallback can miss shader writes earlier in the list; bounded staging/reuse remains follow-up work.The two message-538 allowances are removed, and
gpu-measure.mddescribes staging for all same-buffer copies. With #49 and #51 on main, these were the last allowances: remove the unused allowance helper and reporting state fromtestgpu.rs, plus its staleCONTRIBUTING.mdreference. Deliberate-invalid-input scopes and strict debug-layer failures remain intact.Part of: #45
Depends on: none
Area
gpu,docs:shadow.rs, copy regression tests inlist.rsandhost/buffers.rs,testgpu.rs,CONTRIBUTING.md, anddocs/analysis/gpu-measure.md.Tests
cargo xtask pr-checkpasses on my machineThe existing non-overlapping same-buffer test and card-buffer shader-write/copy-back test exercise the fix. The latter also checks that card staging was used. Fresh strict WARP diagnostics and full WARP PR-check results are recorded in the review reply for the published head.
Ran on a title: no new title run for this integration cleanup.
Provenance
AI assistance: Claude Code drafted the initial fix and the card-staging, failure-warning, documentation and test follow-ups. Codex rebased, reviewed callers and verified the result. No external code was copied or translated. I answer for every line.
Checklist
<area>: <summary>; one topic; under 400 changed lines, or the reason is above