GPU: deferred CopyBufferRegion can read stale CPU memory before preceding GPU writes complete #2781
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#2781
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@FunWithFlagsDev on GitHub · 2026-11-25 20:21 UTC · original
<html>Summary
While investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of
CopyBufferRegion.A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted.
The same ordering hazard appears possible across different command lists prepared within one host submission.
This report includes source-level evidence, an asset-free differential model, and a proposed native regression test.
1. Source-level evidence
Upstream revision inspected:
13f91caee25f2fdf2c062be5f7a27f058e51cbcaCopyBufferRegion is deferred to CPU execution
crates/victory-gpu/src/list.rs:626–640The operation becomes a deferred CPU copy rather than an ordered GPU copy.
host.rs:2024Deferred copies execute before GPU submission
host.rs:2271–2300All participating lists have their deferred steps processed before the host executes the GPU command lists.
See
host.rs:1207–1255.GPU-produced results are subsequently copied back into title memory after GPU completion.
See
host.rs:1304–1390.2. Ordering mismatch
Consider the following synthetic command sequence:
Expected execution:
Potential current execution:
The producer and consumer can therefore observe an ordering different from the recorded command sequence.
This is not limited to a single command list:
Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes.
3. Relevance to BVH construction
Fxceless's ray-tracing work independently identifies this mechanism:
https://github.com/fxceless/victory-fork/pull/994
That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches.
When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes.
The fork implements selected copies directly on the GPU behind the producing shaders.
Relevant implementation:
Copy routing in list.rs
HostList::copy_on_card and shaders_wrote
This may represent an additional upstream BVH blocker independent of the
DispatchXthread-count investigation in #2750.Its actual contribution to incomplete BVH construction in upstream has not yet been measured.
4. Asset-free differential model
The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies.
The scenarios include:
GPU producer and CPU copy within the same list.
Producer and consumer in separate lists within the same submission.
Separate submissions.
CPU-produced source data.
Reversed producer/consumer ordering.
Disjoint source ranges.
Results:
The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words.
All producer and sentinel controls must pass before the ordering invariant is evaluated.
Important scope limitations:
The producer is a real GPU buffer copy, not a translated shader.
The consumer exercises
HostList::defer_copy, not the public COMCopyBufferRegionentry point.The Rust test has not yet been compiled or executed.
The test intentionally requires a working D3D12 host rather than silently skipping.
A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect.
6. Suggested reproduction
Use a dedicated checkout at the pinned upstream revision.
The included preparation script checks the exact commit and normalized Git blob hash of
host.rs, then stages the test-only source modification without editing the checkout.Review the staged
host.rsbefore copying it into the dedicated checkout.Run on WARP:
An independent hardware run would also be useful.
Please report the adapter, driver, revision, debug-layer errors, and all three
copy-orderdiagnostic lines.The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested.
7. Existing related upstream work
Two existing PRs are particularly relevant:
#2608 — splits and flushes command-list segments after texture readbacks, addressing related same-list and same-batch ordering hazards.
#2240 — refreshes page-table-backed title memory after intervening CPU writes.
The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed.
Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism.
8. Possible correction strategies
A. Dependency-aware GPU copies
When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer.
This requires:
Correct resource barriers.
Source and destination lifetime retention.
Destination write tracking and copy-back.
Correct handling of overlapping resource regions and memory aliases.
B. Dependency-aware submission segmentation
Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy.
This would need to preserve command-list state and ordering across multiple lists in one submission.
Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences.
Additional correctness requirement
Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory.
A dependent copy must not bypass that protection by committing results whose validity has been withheld.
Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard.
9. Requested verification
Could an independent tester run the proposed synthetic regression on the pinned revision?
If the ordering mismatch is reproduced, I suggest:
Adding a shader-backed producer regression.
Extending coverage to the actual
CopyBufferRegionentry point.Testing same-list and same-submission dependencies.
Reviewing integration with #2608.
Evaluating the effect on BVH compacted-size readbacks after the remaining builder prerequisites are available.
Attachment
bvh_copy_order_audit.zipContents:
README.mdmodel.pytest_model.pymatrix.csvresults.txtnative_probe.rsprepare_probe.pyPython reproduction:
Credits and limitations
Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994.
This comparative investigation and its synthetic regression proposal were developed with AI assistance using ChatGPT.
No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included.
Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending.
This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.
</html>## SummaryWhile investigating the remaining blockers in upstream BVH construction following #2750, I identified a potential command-ordering defect in the implementation of
CopyBufferRegion.A buffer copy recorded after GPU work that writes its source can execute against stale CPU-side title memory before the preceding GPU work has even been submitted.
The same ordering hazard appears possible across different command lists prepared within one host submission.
This report includes source-level evidence, an asset-free differential model, and a proposed native regression test.
1. Source-level evidence
Upstream revision inspected:
13f91caee25f2fdf2c062be5f7a27f058e51cbcaCopyBufferRegion is deferred to CPU execution
[crates/victory-gpu/src/list.rs:626–640](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/list.rs#L626-L640)The operation becomes a deferred CPU copy rather than an ordered GPU copy.
[host.rs:2024](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2024)Deferred copies execute before GPU submission
[host.rs:2271–2300](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L2271-L2300)All participating lists have their deferred steps processed before the host executes the GPU command lists.
See
[host.rs:1207–1255](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1207-L1255).GPU-produced results are subsequently copied back into title memory after GPU completion.
See
[host.rs:1304–1390](https://github.com/Marvisak/VIctory/blob/13f91cae/crates/victory-gpu/src/host.rs#L1304-L1390).2. Ordering mismatch
Consider the following synthetic command sequence:
Expected execution:
Potential current execution:
The producer and consumer can therefore observe an ordering different from the recorded command sequence.
This is not limited to a single command list:
Because the deferred preparation of both lists precedes GPU execution, list B may consume stale CPU-side bytes.
3. Relevance to BVH construction
Fxceless's ray-tracing work independently identifies this mechanism:
https://github.com/fxceless/victory-fork/pull/994
That PR describes the title copying acceleration-structure compacted sizes from buffers written by preceding builder dispatches.
When those copies execute on the CPU during submission preparation, they may consume previous-frame values or zeros instead of the newly generated sizes.
The fork implements selected copies directly on the GPU behind the producing shaders.
Relevant implementation:
github.com/fxceless/victory-fork@c9ca6b2611/crates/victory-gpu/src/list.rs (L816-L850))github.com/fxceless/victory-fork@c9ca6b2611/crates/victory-gpu/src/host.rs (L6436-L6501))This may represent an additional upstream BVH blocker independent of the
DispatchXthread-count investigation in #2750.Its actual contribution to incomplete BVH construction in upstream has not yet been measured.
4. Asset-free differential model
The attached archive contains a Python ordering model covering 24 synthetic scenarios evaluated under four policies.
The scenarios include:
Results:
All nine Python unit tests passed.
Both divergences occur when a CPU copy consumes an overlapping result produced by preceding GPU work in the same submission.
These results validate the modeled ordering hazard. They are not measurements of its frequency in the title.
The alternative policies are idealized ordering strategies, not validated production implementations.
5. Proposed native regression
The archive also includes a proposed test-only addition to the existing
host::batchtest module.Test name:
gpu_producer_must_precede_deferred_title_copyThe test initializes independent synthetic memory pools with:
An actual D3D12 buffer copy produces
NEWin the source shadow.The consumer uses the production
HostList::defer_copypath.Three execution arrangements are compared:
222222221111111122222222111111112222222222222222The test checks the GPU-produced value, CPU-side source after completion, destination value, and surrounding sentinel words.
All producer and sentinel controls must pass before the ordering invariant is evaluated.
Important scope limitations:
HostList::defer_copy, not the public COMCopyBufferRegionentry point.A failed compilation, unavailable adapter, device removal, or failed producer control must not be interpreted as reproduction of the ordering defect.
6. Suggested reproduction
Use a dedicated checkout at the pinned upstream revision.
The included preparation script checks the exact commit and normalized Git blob hash of
host.rs, then stages the test-only source modification without editing the checkout.Review the staged
host.rsbefore copying it into the dedicated checkout.Run on WARP:
An independent hardware run would also be useful.
Please report the adapter, driver, revision, debug-layer errors, and all three
copy-orderdiagnostic lines.The preparation script's source anchors and pinned blob were checked against public source. Full-checkout staging remains untested.
7. Existing related upstream work
Two existing PRs are particularly relevant:
The mechanism investigated here concerns the opposite dependency direction: a CPU copy consuming a result produced by GPU work that has not completed.
Coordination with #2608 may allow reuse of its dependency-aware segmentation infrastructure instead of introducing another independent mechanism.
8. Possible correction strategies
A. Dependency-aware GPU copies
When a copy's source overlaps an earlier GPU-written range, record the copy on the GPU behind its producer.
This requires:
B. Dependency-aware submission segmentation
Alternatively, split at a GPU-to-CPU dependency, execute the producer segment, complete its write-back, and only then perform the CPU copy.
This would need to preserve command-list state and ordering across multiple lists in one submission.
Neither strategy should force every buffer copy onto the GPU or introduce unnecessary fences.
Additional correctness requirement
Upstream already withholds selected GPU writes when programs using computed title addresses encounter missing memory.
A dependent copy must not bypass that protection by committing results whose validity has been withheld.
Similarly, falling back to a stale CPU copy after detecting a known GPU dependency would reintroduce the original ordering hazard.
9. Requested verification
Could an independent tester run the proposed synthetic regression on the pinned revision?
If the ordering mismatch is reproduced, I suggest:
CopyBufferRegionentry point.Attachment
bvh_copy_order_audit.zipContents:
README.mdmodel.pytest_model.pymatrix.csvresults.txtnative_probe.rsprepare_probe.pyPython reproduction:
Credits and limitations
Credit to the Fxceless contributors for identifying the compacted-size copy hazard and implementing the ordered GPU-copy approach in #994.
bvh_copy_order_audit.zip
No proprietary game assets, executable files, console SDK headers, shader dumps, or game captures were used or included.
Only public source inspection and Python-based synthetic validation were performed by this investigation. Native D3D12 reproduction remains pending.
This report does not claim that the identified ordering hazard is the sole cause of incomplete upstream BVH construction.
github-bot referenced this issue2026-11-26 05:14:47 +00:00
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 21:01 UTC · original
An asset-free WARP test now reproduces this through VIctory's guest CopyBufferRegion call. On
13f91cathe GPU writes 0x55667788 while the destination receives 0x11223344 in one list and in two lists of one submission. Separate submissions return 0x55667788.I offered 34fc326 directly on #2608 head 5bf646428c48f4e2cd31a4063597e1c87d3a3d12. That head shows the same original results. The fix orders copies whose source overlaps a declared GPU write. The same test now returns 0x55667788 in all three layouts. Disjoint source ranges, a copy recorded before the write and surrounding sentinel words are unchanged. Six paired WARP runs and both full serial GPU suites passed on the fix, with 203 passed and one ignored per suite.
Please retain the Git author on cherry-pick or rebase. If folding the fix or test into another commit, please include the following trailer.
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted with Codex. Synthetic buffers on WARP.
@Venom2054 on GitHub · 2026-11-25 21:09 UTC · original
I ran the proposed four-byte probe at upstream commit
13f91caetwice on each adapter. NVIDIA RTX 5070 Ti (621.01) and Microsoft WARP (10.0.26100.9818) returned the same three results. I built victory-gpu with the diagnostics feature and checked the selected adapter for each run.Both adjacent sentinels stayed at 0x5a5a5a5a and the device remained healthy. Only the final ordering assertion failed. On both adapters the debug queue already contained message #1419 about the sampler heap during host initialization, before creating the test buffers. After draining it, the three cases generated no further D3D12 error or corruption messages.
This verifies the proposed HostList::defer_copy probe on physical NVIDIA hardware as well as WARP, alongside the guest-entry WARP check above. My runs used the upstream revision before the proposed fix. For the public CopyBufferRegion entry point, #387 also has a real-queue test and fix results. I haven't measured the effect on in-game BVH construction.
@kotekompotek on GitHub · 2026-11-25 21:12 UTC · original
Root cause confirmed and fixed in #2810:
HostList::run_deferredexecutesStep::Copy/Fillat submission preparation, beforeExecuteCommandLists— aCopyBufferRegionreading a range the submission's shaders write carries stale bytes (they only reach title memory in the post-fence copy-back), and one writing such a range gets overwritten by it.The fix queues any deferred copy/fill touching a range declared GPU-written (shared
Batchstate, so cross-list ordering works) on alatelist that runs after the copy-backs, before the writes that signal completion to the title. Includes an end-to-end test throughHost::execute.@Marvisak on GitHub · 2026-11-25 21:46 UTC · original
Automated triage for the maintainers.
Confirmed on main
61bfc77. Incrates/victory-gpu/src/host.rs,Host::executecallsHostList::run_deferredfor every list of the submission beforeExecuteCommandLists.run_deferredrunsStep::Copy(queued byHostList::defer_copyfromCopyBufferRegioninlist.rs) as a CPUcopy_mappedat that point. A copy whose source the same submission's shaders write therefore reads the bytes from before the copy-back. Two commenters reproduced it with synthetic buffers on WARP and on an RTX 5070 Ti.Open PRs: #2810 runs such copies after the copy-backs and is the most direct fix. #387 (ordering of buffer copies) and #2608 (splitting after texture read-backs) are related. The fork commit offered in a comment above is not a PR. PRs are open to everyone, so please open one, or coordinate on #2810, if that change differs from it.
Generated by Claude Code