GPU: a deferred copy of memory the submission's shaders write runs after the copy-backs #2810

Open
github-bot wants to merge 4 commits from github-bot/gh-2810 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-25 21:12 UTC · original
kotekompotek:gpu/deferred-copy-after-gpu-writes → main · +668 −182 · 2 files · 4 commits · open

Summary

Fixes #2781.

A title CopyBufferRegion (or buffer CopyResource) recorded behind a dispatch ran its deferred CPU copy at submission preparation — before ExecuteCommandLists — while the shader's writes reach title memory only in the post-fence copy-back. The copy therefore carried stale bytes. Symmetrically, a copy writing a destination the shaders also wrote had its result overwritten by the copy-back.

Deferred copies/fills now check the title ranges the submission's lists have declared GPU-written so far (Batch::gpu_writes, shared across all lists of the submission, so a copy in a later list sees an earlier list's writes). A copy touching a written range is queued on Batch::late and runs after the copy-backs but before the bottom-of-pipe writes that signal completion to the title. A copy recorded before the write in step order still runs at once, matching the console's asynchronous GPU ordering.

Behaviour changes to state

  • Unmapped source pages are now copied as zeros. Before, the copy was skipped unless both ranges were committed. copy_mapped writes zeros for unmapped source pages, and stops at the first unmapped page of the destination. This is the buffer copies' existing fallback, now shared by CopyMemoryToMemoryX.
  • Overlap. The pre-change direct path used std::ptr::copy (memmove). The deferred path copies through the process-memory read/write pair, which makes no promise for overlapping source and destination. Overlapping copies are already undefined behaviour for the console API this implements (CopyMemoryToMemoryX is the title's memcpy), so no overlap handling is added; non-overlapping copies are unaffected.

Later commits on this head

  • 2180802 — chained deferral: later copies touching a pending deferred range (either end) defer in order; Step::Fill stays at record time (its destination is the list's own upload memory); a GpuWrite over a pending destination clips the deferred copy.
  • 889d785 — CopyMemoryToMemoryX goes through defer_copy like the buffer copies; the last unconditional Step::Run/HostList::defer users are removed.
  • e2a68d9 — same-submission reads: Host::execute splits ExecuteCommandLists before a reader's segment and runs pending late copies/refreshes in between, so a reader in a later list sees the copy's bytes (a reader in the same list still sees stale bytes — no split point inside one list's step walk; stated in the test). Deferred sources are tracked and later writers to them defer in order (late_sourced).

Test plan

  • host::copy_order::a_copy_past_a_gpu_write_sees_what_it_wrote — end-to-end through Host::execute.
  • host::copy_order::deferred_copies_chain_and_a_later_gpu_write_wins — chained copies, fills, GPU-write clipping.
  • host::copy_order::a_late_copy_keeps_its_source_until_it_reads_it — source protection.
  • host::copy_order::a_read_of_a_late_copy_sees_it_in_a_split_submission — split submissions; documents the same-list limit.
  • cargo clippy -p victory-gpu --all-targets clean
  • In-title verification of the #2781 scenario (no direct report yet)

Generated with Devin

**@⁠kotekompotek** on GitHub · 2026-11-25 21:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810) `kotekompotek:gpu/deferred-copy-after-gpu-writes` → `main` · +668 −182 · 2 files · 4 commits · open ## Summary Fixes #2781. A title `CopyBufferRegion` (or buffer `CopyResource`) recorded behind a dispatch ran its deferred CPU copy at submission preparation — before `ExecuteCommandLists` — while the shader's writes reach title memory only in the post-fence copy-back. The copy therefore carried stale bytes. Symmetrically, a copy writing a destination the shaders also wrote had its result overwritten by the copy-back. Deferred copies/fills now check the title ranges the submission's lists have declared GPU-written so far (`Batch::gpu_writes`, shared across all lists of the submission, so a copy in a later list sees an earlier list's writes). A copy touching a written range is queued on `Batch::late` and runs after the copy-backs but before the bottom-of-pipe writes that signal completion to the title. A copy recorded before the write in step order still runs at once, matching the console's asynchronous GPU ordering. ## Behaviour changes to state - **Unmapped source pages are now copied as zeros.** Before, the copy was skipped unless both ranges were committed. `copy_mapped` writes zeros for unmapped source pages, and stops at the first unmapped page of the destination. This is the buffer copies' existing fallback, now shared by `CopyMemoryToMemoryX`. - **Overlap.** The pre-change direct path used `std::ptr::copy` (memmove). The deferred path copies through the process-memory read/write pair, which makes no promise for overlapping source and destination. Overlapping copies are already undefined behaviour for the console API this implements (`CopyMemoryToMemoryX` is the title's memcpy), so no overlap handling is added; non-overlapping copies are unaffected. ## Later commits on this head - `2180802` — chained deferral: later copies touching a pending deferred range (either end) defer in order; `Step::Fill` stays at record time (its destination is the list's own upload memory); a `GpuWrite` over a pending destination clips the deferred copy. - `889d785` — `CopyMemoryToMemoryX` goes through `defer_copy` like the buffer copies; the last unconditional `Step::Run`/`HostList::defer` users are removed. - `e2a68d9` — same-submission reads: `Host::execute` splits `ExecuteCommandLists` before a reader's segment and runs pending late copies/refreshes in between, so a reader in a later list sees the copy's bytes (a reader in the *same* list still sees stale bytes — no split point inside one list's step walk; stated in the test). Deferred sources are tracked and later writers to them defer in order (`late_sourced`). #### Test plan - [x] `host::copy_order::a_copy_past_a_gpu_write_sees_what_it_wrote` — end-to-end through `Host::execute`. - [x] `host::copy_order::deferred_copies_chain_and_a_later_gpu_write_wins` — chained copies, fills, GPU-write clipping. - [x] `host::copy_order::a_late_copy_keeps_its_source_until_it_reads_it` — source protection. - [x] `host::copy_order::a_read_of_a_late_copy_sees_it_in_a_split_submission` — split submissions; documents the same-list limit. - [x] `cargo clippy -p victory-gpu --all-targets` clean - [ ] In-title verification of the #2781 scenario (no direct report yet) Generated with [Devin](https://devin.ai)
A title CopyBufferRegion recorded behind a dispatch reads its source at
submission preparation, before the lists run: the shader's bytes reach
title memory only in the post-fence copy-back, so the copy carried old
data (issue #2781). A copy whose destination they write was likewise
overwritten by the copy-back.

Deferred copies and fills now check the title ranges the submission's
lists declared GPU-written so far (recorded per shared batch, so a copy
in a later list sees an earlier list's writes): one touching a written
range runs late, after the copy-backs and before the bottom-of-pipe
writes that signal completion to the title. Copies in step order before
the write still run at once, matching the console's asynchronous GPU.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:48 +00:00
Two review findings on the deferral:

- A fill writes the list's own upload memory, which its commands read
  while it runs: deferring one past ExecuteCommandLists leaves the GPU
  reading memory the fill never reached. Fills copy at once again; a
  source the shaders write stays old there, as it was before the
  deferral existed.

- A deferred copy's title destination was not recorded as pending, so a
  later copy reading or overwriting it ran early (with the stale bytes),
  and a later refresh of it refreshed before its bytes landed. The
  pending destinations are now tracked: a copy touching one defers in
  order behind it, a refresh touching one runs just after the late
  copies, and a GPU write recorded over one keeps the shader's bytes
  (the deferred copy's covered part is dropped, as on the console where
  the later write wins).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
Owner

@⁠Venom2054 on GitHub · 2026-11-25 21:21 UTC · original

I ran the five-case guest CopyBufferRegion test from 34fc326c twice on this PR's head, 9ba63034, using a physical RTX 5070 Ti (driver 621.01) with the D3D12 debug layer enabled. All five cases passed both times.

Destination word (hex) #2608 head 5bf64642 Fix 34fc326c This PR 9ba63034
Producer then copy in one list 11223344 55667788 55667788
Two lists in one submission 11223344 55667788 55667788
Separate submissions 55667788 55667788 55667788
Copy from a disjoint range aabbccdd aabbccdd aabbccdd
Copy before the producer 11223344 11223344 11223344

I used the same guest test and controls on all three revisions. 5bf64642 is the parent of 34fc326c. This PR branches from 13f91cae. The GPU and CPU source checks returned 55667788, adjacent sentinels stayed intact, and the device remained healthy. Debug message 1419 was already queued before the cases began. This verifies four-byte buffer-copy ordering on hardware. The in-game effect on BVH construction and lighting remains unmeasured.

**@⁠Venom2054** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7174968968) I ran the five-case guest CopyBufferRegion test from [34fc326c](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/34fc326cdf19c7c286fc0413050640ff186c54f8) twice on this PR's head, 9ba63034, using a physical RTX 5070 Ti (driver 621.01) with the D3D12 debug layer enabled. All five cases passed both times. | Destination word (hex) | #2608 head 5bf64642 | Fix 34fc326c | This PR 9ba63034 | |---|---|---|---| | Producer then copy in one list | 11223344 | 55667788 | 55667788 | | Two lists in one submission | 11223344 | 55667788 | 55667788 | | Separate submissions | 55667788 | 55667788 | 55667788 | | Copy from a disjoint range | aabbccdd | aabbccdd | aabbccdd | | Copy before the producer | 11223344 | 11223344 | 11223344 | I used the same guest test and controls on all three revisions. 5bf64642 is the parent of 34fc326c. This PR branches from 13f91cae. The GPU and CPU source checks returned 55667788, adjacent sentinels stayed intact, and the device remained healthy. Debug message 1419 was already queued before the cases began. This verifies four-byte buffer-copy ordering on hardware. The in-game effect on BVH construction and lighting remains unmeasured.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:30 UTC · original

Verified 9ba63034 on Windows 11 (RTX 5090 + WARP, --features diagnostics):

  • cargo xtask policy: 184 files ok; cargo clippy (default & --features diagnostics): 0 warnings.
  • RTX 5090 host::copy_order + memory::tests (excluding pre-existing baseline lists_share): 5/5 passed.
  • WARP (--features diagnostics): 197 passed / 1 ignored, plus dynamic_slots and lists_share individually passed (199/199).
  • Merge check via git merge-tree: clean against origin/main 13f91ca, #2608, and #2611.

One ordering edge case worth flagging in the same Batch submission: batch.late defers a copy whose src or dst overlaps batch.gpu_writes, but does not record the deferred copy's own dst range (B) as pending for later ops in the same batch (gpu_written only checks batch.gpu_writes). When B, C, D are disjoint from shader-written A, three same-batch sequences can still run out of recording order:

  1. shader1 writes A -> Copy(dst=B, src=A) [deferred to batch.late] -> Copy(dst=C, src=B): gpu_written(B) is false, so B -> C executes eagerly before A -> B runs, copying stale B into C.
  2. shader1 writes A -> Copy(dst=B, src=A) [deferred] -> shader2 reads B (Step::Refresh(B) / Step::Fill): Refresh runs in batch.flush() before ExecuteCommandLists, while A -> B runs after copy-back, so shader2 sees stale B.
  3. shader1 writes A -> Copy(dst=B, src=A) [deferred] -> Copy(dst=B, src=D): D -> B runs eagerly, then batch.late runs A -> B afterward and overwrites D's data.

Tracking deferred dst ranges (so subsequent copies touching B also defer in order, and a shader read of B forces a batch split/flush) would close all three chains.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7175173530) Verified `9ba63034` on Windows 11 (RTX 5090 + WARP, `--features diagnostics`): - `cargo xtask policy`: 184 files ok; `cargo clippy` (default & `--features diagnostics`): 0 warnings. - RTX 5090 `host::copy_order` + `memory::tests` (excluding pre-existing baseline `lists_share`): 5/5 passed. - WARP (`--features diagnostics`): 197 passed / 1 ignored, plus `dynamic_slots` and `lists_share` individually passed (199/199). - Merge check via `git merge-tree`: clean against `origin/main` `13f91ca`, #2608, and #2611. One ordering edge case worth flagging in the same `Batch` submission: `batch.late` defers a copy whose `src` or `dst` overlaps `batch.gpu_writes`, but does not record the deferred copy's own `dst` range (`B`) as pending for later ops in the same batch (`gpu_written` only checks `batch.gpu_writes`). When `B`, `C`, `D` are disjoint from shader-written `A`, three same-batch sequences can still run out of recording order: 1. `shader1 writes A -> Copy(dst=B, src=A) [deferred to batch.late] -> Copy(dst=C, src=B)`: `gpu_written(B)` is false, so `B -> C` executes eagerly before `A -> B` runs, copying stale `B` into `C`. 2. `shader1 writes A -> Copy(dst=B, src=A) [deferred] -> shader2 reads B` (`Step::Refresh(B)` / `Step::Fill`): `Refresh` runs in `batch.flush()` before `ExecuteCommandLists`, while `A -> B` runs after copy-back, so `shader2` sees stale `B`. 3. `shader1 writes A -> Copy(dst=B, src=A) [deferred] -> Copy(dst=B, src=D)`: `D -> B` runs eagerly, then `batch.late` runs `A -> B` afterward and overwrites `D`'s data. Tracking deferred `dst` ranges (so subsequent copies touching `B` also defer in order, and a shader read of `B` forces a batch split/flush) would close all three chains.
Author
Owner

@⁠HLVM04 on GitHub · 2026-11-25 23:56 UTC · original

An in-title count for the open "in-title verification" item, from the fork (fxceless/victory-fork), not this PR's code. The fork has the same order: Host::submit runs each list's deferred CPU copies (run_deferred -> copy_mapped) before ExecuteCommandLists, and shader writes reach title memory only later.

RTX 5070 Ti, Series S profile, one instrumented 200 s run:

  • About 2,000 title buffer copies read a source that shaders in an earlier list of the same submission write. All of them came during loading (about 58-86 s in).
  • About 25% of those also have their destination read by shaders later in the same submission. So the chained case raised in the review above (a late copy's destination counting as pending for later readers) does occur in the title, not only in synthetic tests.
  • A local change of ours with the same idea (hold such copies until the submission's writes have landed; fills left as they are, since their destination is the list's own upload memory) cost no measurable frame time. It did not fix the intermittent black character skin we were chasing (fine in 4 of 6 runs with it, 2 of 6 without, which is not significant).

One run for the counts, so they will vary with the scene.

**@⁠HLVM04** on GitHub · 2026-11-25 23:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7178230459) An in-title count for the open "in-title verification" item, from the fork (fxceless/victory-fork), not this PR's code. The fork has the same order: `Host::submit` runs each list's deferred CPU copies (`run_deferred` -> `copy_mapped`) before `ExecuteCommandLists`, and shader writes reach title memory only later. RTX 5070 Ti, Series S profile, one instrumented 200 s run: - About 2,000 title buffer copies read a source that shaders in an earlier list of the same submission write. All of them came during loading (about 58-86 s in). - About 25% of those also have their destination read by shaders later in the same submission. So the chained case raised in the review above (a late copy's destination counting as pending for later readers) does occur in the title, not only in synthetic tests. - A local change of ours with the same idea (hold such copies until the submission's writes have landed; fills left as they are, since their destination is the list's own upload memory) cost no measurable frame time. It did not fix the intermittent black character skin we were chasing (fine in 4 of 6 runs with it, 2 of 6 without, which is not significant). One run for the counts, so they will vary with the scene.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 00:29 UTC · original

Useful data — thanks for instrumenting it in-title. The ~25% chained rate is exactly the case the gpu_writes/late ordering covers: a late copy's destination stays pending for later readers because the copy runs after the copy-backs but before the writes that signal completion, so the chain can't read back a not-yet-written destination. Good to hear the same idea costs nothing measurable at 60 fps — matches the expectation (the deferred list just reorders work the submitting thread already did).

The black-skin chase being unaffected is consistent with this fix's scope — it only removes stale reads at submission boundaries, not visual artifacts with other causes.

**@⁠kotekompotek** on GitHub · 2026-11-26 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7178808681) Useful data — thanks for instrumenting it in-title. The ~25% chained rate is exactly the case the `gpu_writes`/`late` ordering covers: a late copy's destination stays pending for later readers because the copy runs after the copy-backs but before the writes that signal completion, so the chain can't read back a not-yet-written destination. Good to hear the same idea costs nothing measurable at 60 fps — matches the expectation (the deferred list just reorders work the submitting thread already did). The black-skin chase being unaffected is consistent with this fix's scope — it only removes stale reads at submission boundaries, not visual artifacts with other causes.
It was the last step writing title memory outside the deferred copies,
so it read a source the submission's shaders write before the copy-backs
and lost a destination to them; chaining past a deferred copy's
destination did not reach it either. Routed through defer_copy it orders
like the buffer copies, its write is guarded from the write-watch like
theirs, and its unmapped pages fall back the same way. The title-memory
step kind is gone with it.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
Owner

@⁠AwsAli05 on GitHub · 2026-11-25 23:15 UTC · original · reviewed

The late-copy check misses dependencies through an earlier late copy. I added a final pool 1 -> pool 3 to the existing copy-order fixture at bcd9329, after it recorded pool 0 -> pool 1. Pool 0 is the GPU-written range. On the RTX 5070 Ti, pool 1 correctly received 0xBB, while pool 3 received its old 0x00 instead of 0xBB.

The second copy runs during preparation because neither of its ranges is in gpu_writes. A pending late copy's destination needs to participate in the dependency check so later consumers wait too. Please add the chained-copy regression alongside the direct cases.

AI-assisted review and local synthetic test.

**@⁠AwsAli05** on GitHub · 2026-11-25 23:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#pullrequestreview-6066282014) · **reviewed** The late-copy check misses dependencies through an earlier late copy. I added a final `pool 1 -> pool 3` to the existing copy-order fixture at `bcd9329`, after it recorded `pool 0 -> pool 1`. Pool 0 is the GPU-written range. On the RTX 5070 Ti, pool 1 correctly received `0xBB`, while pool 3 received its old `0x00` instead of `0xBB`. The second copy runs during preparation because neither of its ranges is in `gpu_writes`. A pending late copy's destination needs to participate in the dependency check so later consumers wait too. Please add the chained-copy regression alongside the direct cases. AI-assisted review and local synthetic test.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:19 UTC · original · edited 2026-11-26 08:25 UTC

Automated triage for the maintainers.

Thanks for 889d785. copy_memory (CopyMemoryToMemoryX, list.rs) now records through HostList::defer_copy, so it gets the same gpu_written/late_pending ordering as the buffer copies, and the write-watch guard of copy_mapped. Step::Run and HostList::defer lose their last caller and are removed. a_memory_copy_past_a_gpu_write_sees_what_it_wrote covers the call through the real list entry point. That part reads right.

Two behaviour changes come with it. Please state them in the description:

  • Unmapped source pages are now copied as zeros. Before, the copy was skipped unless both ranges were committed. copy_mapped now writes zeros for unmapped source pages, and stops at the first unmapped page of the destination.
  • Overlap. The old code used std::ptr::copy, which is overlap-safe. copy_mapped goes through ReadProcessMemory, which makes no promise for overlapping source and destination. If the title can call CopyMemoryToMemoryX on overlapping ranges, that needs handling.

The two gaps from the last triage are still open on this head (Batch in host.rs):

  • A read in the same submission still sees stale bytes. A Refresh/Heap/Memory range over a deferred destination goes to late_refresh, which runs after ExecuteCommandLists. A shader later in the same submission that reads that destination still reads the old shadow. Splitting the batch at that point would fix it. HLVM04's count in the thread shows this chain occurs in the title (about 25% of such copies).
  • The deferred copy's source is not protected. A copy deferred because of its destination reads its source after the lists run. A later Step::Copy that writes that source, with neither range GPU-written or pending, still runs at once. Recording deferred sources as pending for later writers would close it.

Tests that fail on this head for those two sequences, and pass with the fix, would change the verdict.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7180693340) · edited 2026-11-26 08:25 UTC <!-- victory-triage v1 head=889d785b1b00885566f69c570a142e2e2435fca7 verdict=needs-work at=2026-11-26T08:20:18Z --> Automated triage for the maintainers. Thanks for `889d785`. `copy_memory` (`CopyMemoryToMemoryX`, `list.rs`) now records through `HostList::defer_copy`, so it gets the same `gpu_written`/`late_pending` ordering as the buffer copies, and the write-watch guard of `copy_mapped`. `Step::Run` and `HostList::defer` lose their last caller and are removed. `a_memory_copy_past_a_gpu_write_sees_what_it_wrote` covers the call through the real list entry point. That part reads right. Two behaviour changes come with it. Please state them in the description: - **Unmapped source pages are now copied as zeros.** Before, the copy was skipped unless both ranges were committed. `copy_mapped` now writes zeros for unmapped source pages, and stops at the first unmapped page of the destination. - **Overlap.** The old code used `std::ptr::copy`, which is overlap-safe. `copy_mapped` goes through `ReadProcessMemory`, which makes no promise for overlapping source and destination. If the title can call `CopyMemoryToMemoryX` on overlapping ranges, that needs handling. The two gaps from the last triage are still open on this head (`Batch` in `host.rs`): - **A read in the same submission still sees stale bytes.** A `Refresh`/`Heap`/`Memory` range over a deferred destination goes to `late_refresh`, which runs after `ExecuteCommandLists`. A shader later in the same submission that reads that destination still reads the old shadow. Splitting the batch at that point would fix it. HLVM04's count in the thread shows this chain occurs in the title (about 25% of such copies). - **The deferred copy's source is not protected.** A copy deferred because of its destination reads its source after the lists run. A later `Step::Copy` that writes that source, with neither range GPU-written or pending, still runs at once. Recording deferred sources as pending for later writers would close it. Tests that fail on this head for those two sequences, and pass with the fix, would change the verdict. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 06:27 UTC · original

Both findings addressed in 2180802:

  • Step::Fill no longer defers — back to an unconditional copy_mapped at record time. A fill's destination is the list's own upload memory, read by its commands while it runs; it cannot wait for the copy-backs. A GPU-written source stays old, as before the deferral.
  • Chained deferral — Batch now tracks each deferred copy's title destination as pending. A later Step::Copy whose source or destination touches a pending range defers in order behind it (so it reads the deferred bytes, and the later write still wins by ordering). A later Step::Refresh/Heap/Memory range touching one is queued in late_refresh and runs right after the late copies. And a Step::GpuWrite recorded over a pending destination clips the covered part of the deferred copy — console order has the later shader write win.

copy_order gained deferred_copies_chain_and_a_later_gpu_write_wins, which discriminates all three: the chained copy reads 0xBB (not the stale pool byte), the fill lands 0xAA (old source — proving it ran at record time), and the range written by a later GpuWrite keeps the shader's 0xEE.

**@⁠kotekompotek** on GitHub · 2026-11-26 06:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7184443244) Both findings addressed in `2180802`: - **`Step::Fill` no longer defers** — back to an unconditional `copy_mapped` at record time. A fill's destination is the list's own upload memory, read by its commands while it runs; it cannot wait for the copy-backs. A GPU-written source stays old, as before the deferral. - **Chained deferral** — `Batch` now tracks each deferred copy's title destination as pending. A later `Step::Copy` whose source *or* destination touches a pending range defers in order behind it (so it reads the deferred bytes, and the later write still wins by ordering). A later `Step::Refresh`/`Heap`/`Memory` range touching one is queued in `late_refresh` and runs right after the late copies. And a `Step::GpuWrite` recorded over a pending destination clips the covered part of the deferred copy — console order has the later shader write win. `copy_order` gained `deferred_copies_chain_and_a_later_gpu_write_wins`, which discriminates all three: the chained copy reads `0xBB` (not the stale pool byte), the fill lands `0xAA` (old source — proving it ran at record time), and the range written by a later `GpuWrite` keeps the shader's `0xEE`.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 06:53 UTC · original

CI failure on 2180802 is a pre-existing flake, not this change: frame::tests::waits_end_on_ticks_and_count_frames polls the origin with a zero time-out twice in a row, and a host that wakes the thread a whole 2 ms tick late between the asks makes the second one return S_OK (the failure's left/right). #3080 hardens it.

**@⁠kotekompotek** on GitHub · 2026-11-26 06:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7184883740) CI failure on `2180802` is a pre-existing flake, not this change: `frame::tests::waits_end_on_ticks_and_count_frames` polls the origin with a zero time-out twice in a row, and a host that wakes the thread a whole 2 ms tick late between the asks makes the second one return S_OK (the failure's left/right). #3080 hardens it.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 07:54 UTC · original

889d785 — same defect, adjacent callsite: CopyMemoryToMemoryX ran as the only step kind that writes title memory outside the deferred copies, so it read a GPU-written source stale, lost a GPU-written destination, and did not chain past a deferred copy's destination. It now goes through defer_copy, which also guards its write from the write-watch and gives its unmapped pages the buffer copies' fallback; the now-unused title-memory step kind is removed. a_memory_copy_past_a_gpu_write_sees_what_it_wrote covers it through the real list calls.

**@⁠kotekompotek** on GitHub · 2026-11-26 07:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7185957438) 889d785 — same defect, adjacent callsite: `CopyMemoryToMemoryX` ran as the only step kind that writes title memory outside the deferred copies, so it read a GPU-written source stale, lost a GPU-written destination, and did not chain past a deferred copy's destination. It now goes through `defer_copy`, which also guards its write from the write-watch and gives its unmapped pages the buffer copies' fallback; the now-unused title-memory step kind is removed. `a_memory_copy_past_a_gpu_write_sees_what_it_wrote` covers it through the real list calls.
A read of a deferred copy's destination in the same submission saw the
stale shadow bytes: the copy ran after the whole ExecuteCommandLists.
Tag deferred copies with the list that produced them and refresh notes
with the list that reads them, and split ExecuteCommandLists before a
reader's segment so the copy lands in its shadow first.

A copy writing a deferred copy's source ran eagerly and clobbered the
bytes the deferred one was waiting to take. Track the sources too and
defer a copy whose destination is one.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 08:40 UTC · original

Both remaining gaps are addressed in e2a68d9:

  • Same-submission reads now see the deferred bytes. Deferred copies carry the run-index of the list that produced them, and each late_refresh note carries the run-index of its reader. Host::execute splits ExecuteCommandLists before a reader's segment and runs the pending late copies and refreshes in between, so a reader in a later list sees the copy's bytes. Phase-run refreshes also skip ranges that segment's shaders write, so they can no longer clobber GPU output. Limit, stated in the test: a reader in the same list as the producer still sees stale bytes — there is no split point inside one list's step walk.
  • Deferred sources are protected. late tracks each deferred copy's source range, and a Step::Copy whose destination touches one defers in order behind it (late_sourced), so the later writer cannot clobber the bytes the deferred copy is waiting to take. clip_late keeps shrinking both the tracked destination and source.

copy_order gained two discriminators: a_late_copy_keeps_its_source_until_it_reads_it (a writer to a deferred source defers; the late copy still reads 0xBB) and a_read_of_a_late_copy_sees_it_in_a_split_submission (samples shadow bytes at each list's boundary: [0x55, 0xBB] across two lists, and documents the same-list limit). All 4 copy_order tests pass; clippy clean.

The other 5 failures in a local -p victory-gpu run reproduce on the base commit on this hardware (GTX 1050-class): a_texture_written_in_one_format…, compute_view_marks_rebind_after_depth_twin_conversion, dynamic_slots_are_held_until_released, lists_share… (the known baseline), and the waits_end_on_ticks… flake.

**@⁠kotekompotek** on GitHub · 2026-11-26 08:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7186891368) Both remaining gaps are addressed in `e2a68d9`: - **Same-submission reads now see the deferred bytes.** Deferred copies carry the run-index of the list that produced them, and each `late_refresh` note carries the run-index of its reader. `Host::execute` splits `ExecuteCommandLists` before a reader's segment and runs the pending late copies and refreshes in between, so a reader in a *later* list sees the copy's bytes. Phase-run refreshes also skip ranges that segment's shaders write, so they can no longer clobber GPU output. Limit, stated in the test: a reader in the *same* list as the producer still sees stale bytes — there is no split point inside one list's step walk. - **Deferred sources are protected.** `late` tracks each deferred copy's source range, and a `Step::Copy` whose destination touches one defers in order behind it (`late_sourced`), so the later writer cannot clobber the bytes the deferred copy is waiting to take. `clip_late` keeps shrinking both the tracked destination and source. `copy_order` gained two discriminators: `a_late_copy_keeps_its_source_until_it_reads_it` (a writer to a deferred source defers; the late copy still reads `0xBB`) and `a_read_of_a_late_copy_sees_it_in_a_split_submission` (samples shadow bytes at each list's boundary: `[0x55, 0xBB]` across two lists, and documents the same-list limit). All 4 `copy_order` tests pass; clippy clean. The other 5 failures in a local `-p victory-gpu` run reproduce on the base commit on this hardware (GTX 1050-class): `a_texture_written_in_one_format…`, `compute_view_marks_rebind_after_depth_twin_conversion`, `dynamic_slots_are_held_until_released`, `lists_share…` (the known baseline), and the `waits_end_on_ticks…` flake.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 17:25 UTC · original

Both behaviour changes are now stated in the description (unmapped pages copied as zeros; overlap undefined, matching the console API's memcpy semantics). The two gaps were addressed in e2a68d9, pushed after the triage head 889d785: same-submission readers see deferred bytes through split submissions, and deferred sources defer later writers in order - with the discriminating tests listed above.

**@⁠kotekompotek** on GitHub · 2026-11-26 17:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7199006170) Both behaviour changes are now stated in the description (unmapped pages copied as zeros; overlap undefined, matching the console API's memcpy semantics). The two gaps were addressed in e2a68d9, pushed after the triage head 889d785: same-submission readers see deferred bytes through split submissions, and deferred sources defer later writers in order - with the discriminating tests listed above.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2810/head:github-bot/gh-2810'
git switch 'github-bot/gh-2810'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2810'
git switch 'github-bot/gh-2810'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2810'
git switch 'github-bot/gh-2810'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2810'
git switch 'main'
git merge --squash 'github-bot/gh-2810'
git switch 'main'
git merge --ff-only 'github-bot/gh-2810'
git switch 'main'
git merge 'github-bot/gh-2810'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2810
No description provided.