GPU: preserve execution ordering for buffer copies #387
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!387
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-387"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@aycow on GitHub · 2026-11-24 02:51 UTC · original
aycow:fix/gpu-buffer-copy-ordering→main· +1813 −128 · 8 files · 14 commits · openChange
A title buffer copy or unaligned root CBV can read CPU staging before an earlier GPU write in the same title command list has run. The recording now cuts at a read of a known overlapping producer. Submission preparation completes the producer group before filling the dependent staging buffer. Unrelated work still batches.
The planner checks alias byte ranges for the dependency and whole pages for potentially withheld writes. For a staged reader after the last computed-address list, the host checks the mapping marks after the native fence. It publishes the prefix before preparing that reader only if no mapping missed and frame-level withholding is inactive. Otherwise the reader stages from published title memory. Actual withheld pages also guard against ordinary copyback through the same shadow.
An ordered buffer copy can now precede a refresh of the same shadow. On a miss, the fenced GPU ranges stay private and the refresh runs around them. Only the bytes the kernel reports writing to the title destination are reflected in those ranges, including writes through a known physical alias. Opaque host writes remain grouped.
A direct buffer-only root-CBV reader can now stage from a fenced producer before a later computed dispatch. This retains the address-map layout used by the producer and tracks the reader's derived buffer outputs through the final miss decision. Exact-range and marked-page copyback both hold those outputs on a miss. Independent writes still publish.
The interleaved path requires a single ordinary direct dispatch with known buffer outputs and a later buffer-only computed phase. Untracked readbacks, texture or dynamic descriptor effects, ambiguous shadow ownership, and replays across the phase boundary keep the original scheduling. These cases can still read the earlier published value. The PR leaves those paths available and does not change the scope of the title-memory miss policy.
An eligible staged read adds a native fence. Title workload frequency and cost remain unmeasured.
Synthetic validation
The current-main control at
13f91caread11after a producer wrote29. The revised title queue'sCopyBufferRegionand all staged-CBV controls read29. The plain WARP run required a device and passed 201 diagnostics GPU tests, with one ignored. Strict GPU diagnostics Clippy passed.AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP passed the staged CBV, real title buffer copy, and write-withholding controls with full GPU-based validation. The native validation used a local Agility 1.620.2 adapter setup and startup sampler workaround. Neither is part of this PR.
On
53e5ee0, the computed fixture passed on AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP with full GPU-based validation. The staged root CBV and CPU copy both read29after a clean producer and11after a fresh miss or inherited withholding. The same-page refresh regression also preserved29for the native consumer and55from the neighboring CPU copy while withholding the computed dword from title memory. The hardware setup used Agility 1.620.2 with local startup compatibility adjustments for sampler validation and descriptor heap probing.On
f66fc14, the clean overlapping-copy case delivered29to the copied dword and the native consumer. After a miss, the private consumer retained29, the neighboring CPU copy reached it as55, and title memory retained11at the withheld source. AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP passed with the same full GPU-based validation setup. Additional controls cover physical aliases, same-value CPU overwrites, and unmapped destinations.On
be723f7, AMD Radeon Graphics, NVIDIA RTX 5070 Laptop GPU, and WARP passed six focused tests each with full GPU-based validation. The translated GFX10 root-CBV fixture validated its emitted DXIL and used the normal binding and dispatch path. All three native stages read29. A clean run published[29, 29, 29]. A data-dependent late miss left title memory at[11, 0, 0]for both exact and page-marked derived writes, kept the unrelated output at29, and caused the next refresh to discard the private value. A readback completion handler disabled private staging.The WARP submission-count control measured one native submission for disjoint work, and two for each dependent read. Closed-list replay reproduced the correct copied value. Tests include the same-page withholding case and the opaque-address case. The checks use original synthetic data. Title frame time remains unmeasured.
The existing branch history retains the earlier continuation and copyback work, including jeremygold02's independent WARP validation. This revision uses main's current command-list segmentation and copyback. Earlier validation · Previous head
AI-assisted using OpenAI Codex.
@jeremygold02 on GitHub · 2026-11-24 04:24 UTC · original
Thanks @aycow for the execution-order regression coverage. I tested head
b5d18276f5160fa60ac49c1f3c34ea2bbf8059a6with the buffer-copy GPU tests:Result: 17 passed, 0 failed (46 filtered out). The cases cover ordered copies across lists/submissions, CPU/GPU staging handoffs, overlapping and disjoint ranges, copyback, and resource lifetime. I also tried the optional GPU-based-validation flag, but its debug-layer initialization was unavailable (
0x887A002D); the test suite passed with that optional mode disabled.@aycow on GitHub · 2026-11-24 04:29 UTC · original
Thanks, @jeremygold02, for independently running all 17 buffer-copy tests on WARP and for including the exact command and head. The
0x887A002Ddetail also helps distinguish this run from the separate Agility SDK GPU-validation pass. I’m following up on the dirty-copy timing to see how much is spent refreshing source bytes, waiting for GPU completion, and copying writes back.@aycow on GitHub · 2026-11-24 04:46 UTC · original
Thanks again for the independent WARP run. The draft now includes
df2276b, which speeds up dirty-buffer copyback while preserving the bytewise merge when the title changed memory after the GPU snapshot.In eight alternating optimized AMD samples per revision, median total time for 128 dirty 1 MiB copies fell from 191.12 to 102.55 ms. The sparse workload fell from 90.72 to 73.77 ms. Both revisions produced matching outputs and byte counts. All 18 focused cases passed on AMD, NVIDIA, and WARP with the D3D12 debug layer and full GPU-based validation. The actual #322 composition also passed its mapping controls and the copy cases.
Could an independent tester run a controlled in-game A/B of
b5d1827anddf2276bwith the same integration stack, scene, settings, and diagnostics flags? Total submission time, copyback time and bytes, and frames completed before any device removal would help distinguish the copyback gain from timing variance.@aycow on GitHub · 2026-11-24 18:13 UTC · original
Published
709647fon this branch, following @KevinPratap's #1322 repro. Current UAV declarations are now recorded during preparation and snapshotted before execution, after synchronous CPU refreshes. The focused fixture changed the observed constant from 11 to 43 and preserved the GPU write (77) and later CPU write (61). All 19 buffer-ordering tests passed on each of AMD Radeon Graphics, RTX 5070 Laptop and WARP with full GBV. Both workspace Clippy configurations passed. Duff's changed-byte concurrent copyback work (#1024) remains a separate candidate for measuring fragmented writes.@aycow on GitHub · 2026-11-24 18:47 UTC · original
I tested a new byte-precise candidate composed on
709647f, retaining Duff's authored change. SIMD comparison, a 4 KiB fallback for inaccessible neighbors, and fewer journal operations passed all 23 tests on AMD Radeon Graphics, RTX 5070 Laptop and WARP with full GBV. The partially mapped fixture preserved all 1,008 valid writes and took 2.786 ms of CPU copyback.For five alternating optimized Windows samples over 4 MiB, old byte runs versus this candidate were 6.713→2.217 ms dense, 4.234→1.658 ms sparse, and 784.636→634.196 ms fragmented. The changed-byte candidate remains separate from this draft because fragmented workloads still need one guarded kernel write per run. A protection query or VirtualLock is insufficient to guarantee the saved destination mapping survives through direct stores. The synchronous ordering fix on the draft stays independently reviewable.
@aycow on GitHub · 2026-11-24 19:01 UTC · original
Published
0899b7dto this PR. Exact rgarage and709647fboth reproduced stale staged root and table constants (11) when an earlier closed list in the same submission wrote 29. The normal path had bypassed title-byte dependency planning when no buffer-copy continuation existed. The fix uses that planner for recorded GPU writes and splits only when the later staging read overlaps. Both staged routes now read 29, and the permanent regression verifies two native calls for overlapping work and one for unrelated work.All 20 buffer-ordering tests plus the nine material staging controls passed on each of AMD and NVIDIA hardware and WARP with full GBV. Both strict workspace Clippy configurations and asset policy passed. This resolves the ordinary two-list case. The title colour operand source, copies inside one native list, and the separate concurrent-write copyback cost are still open.
@aycow on GitHub · 2026-11-24 21:24 UTC · original
The new diagnostics composition passed its allocation/reset control on AMD and WARP. The independent 4 MiB CPU reconciliation profile found that 131,072 checked writes took 1,805.63 ms with Win32 and 114.69 ms with the native primitive already under review in #1215. Replay into an explicitly owned fixture mapping took 2.50 ms, and the metadata-only control took 2.18 ms. The direct path depends on ownership of the mapping and its protection. The guard and partial-mapping behavior of a general write backend remains under review, so #387 stays in draft. Contributor coordination and protection result.
AI-assisted using Codex.
@Marvisak on GitHub · 2026-11-25 00:15 UTC · original · edited 2026-11-26 01:22 UTC
Automated triage for the maintainers.
Still needs work. The only push since the last triage is
86c3887, a merge of currentmainthat keeps the recorded copyback layout. The branch merges cleanly and CI (check) passes. None of the three earlier asks has been addressed yet:interleaved_reader,Batch::allow_private_reader/stage_private/preserve_gpu_writes, anddraw/interleaved_tests.rs. Please limit this PR to the ordering cut and submission split (list.rs,cpu_read_boundaries,computed_tail) and put the rest in a follow-up.Host::require_batch_fencestill callsfail, while a failed wait inmain's submit loop only logs. Please make the two consistent or explain why the split path has to abort.yumaste's report (a later CPU
CopyBufferRegioninto a dword the GPU wrote earlier in the same list or submission loses to the GPU copyback) looks like the same planner gap from the destination side. It would be worth folding in or answering here.Generated by Claude Code
@aycow on GitHub · 2026-11-25 01:02 UTC · original · edited 2026-11-25 16:58 UTC
I reproduced the remaining ordering defect on upstream
42363abusing WARP with the preview Agility runtime, debug layer, and full GPU-based validation. In the same command list a GPU producer wrote29, but the titleCopyBufferRegionand the staged unaligned root CBV received the earlier value11. The aligned root CBV and the separately submitted unaligned control both received29. The draft’s continuation planner predates current bindless and computed-address dependencies, and the same-list staging path still needs a fix. The branch remains a conflicted draft while that ordering and ownership are unresolved.Current-main recheck at
67e8ae1: WARP still observed[29,29,11,11]for the aligned same-list, unaligned separate-submission, unaligned same-batch, and unaligned same-list controls. The titleCopyBufferRegionalso returned11after its producer wrote29. The existing wait segments do not provide this staging handoff, and the old draft conflicts with the current submission and texture code. The branch remains a draft pending a fix that honors current write withholding and copyback ownership.@aycow on GitHub · 2026-11-25 17:40 UTC · original
Updated #387 at
4be4f82with the current-main ordering fix. The original same-list and same-batch staged reads now return29instead of11, and the title buffer copy returns the producer's29through the real queue. AMD, NVIDIA, and WARP passed the focused controls with full GPU-based validation. The WARP suite passed 201 tests and strict GPU Clippy passed.A dependency can split a submission only when earlier copyback is safe. The new controls keep disjoint work batched and block a cut across potentially withheld pages or opaque computed-address writes. The PR description lists the reproduction and the remaining staging limitation for those batches.
@yumaste on GitHub · 2026-11-25 21:16 UTC · original
I tested a related ordering case on this PR's head (
be723f7). A guestCopyBufferRegionreads from a separate CPU buffer and overwrites a dword previously written by the GPU. The GPU copy-back wins when both commands are in one list or in two lists in the same submission. Separate submissions preserve the later CPU copy.yumaste/VIctory@b65714d extends the existing guarded submission boundary to overlaps with the copy destination. With the patch, the destination holds the CPU value in all three layouts. The planner test also checks that a potentially withheld write on the same page still prevents an early boundary.
The guest-entry regression passes on Microsoft WARP and on the default hardware adapter. The standard WARP diagnostics suite passed 205 tests with 9 ignored, and strict GPU Clippy passed. An explicit run of eight ignored draw tests had the same seven failures on the PR head and on the patched branch in my setup. All buffers were synthetic. AI-assisted with Codex.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.