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

Open
kotekompotek wants to merge 4 commits from upstream-pr/2810 into main
kotekompotek commented 2026-11-25 21:12:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:12:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5499258356 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T21:12:12Z. --- ## 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)
Venom2054 commented 2026-11-25 22:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Venom2054 on 2026-11-25T21:21:31Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174968968 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7174968968). Originally posted by [Venom2054](https://github.com/Venom2054) on 2026-11-25T21:21:31Z. --- 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.
fuzeofficlal commented 2026-11-25 22:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:30:42Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175173530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7175173530). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:30:42Z. --- 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.
AwsAli05 commented 2026-11-25 23:15:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:15:40Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066282014 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#pullrequestreview-6066282014). Originally posted by [AwsAli05](https://github.com/AwsAli05) on 2026-11-25T23:15:40Z. **Review:** COMMENTED --- 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.
HLVM04 commented 2026-11-26 00:03:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by HLVM04 on 2026-11-25T23:56:48Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7178230459 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7178230459). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-25T23:56:48Z. --- 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.
kotekompotek commented 2026-11-26 01:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:29:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7178808681 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7178808681). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:29:18Z. --- 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.
Marvisak commented 2026-11-26 03:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:19:33Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180693340 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7180693340). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:19:33Z. --- <!-- 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)_
kotekompotek commented 2026-11-26 07:01:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:27:11Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184443244 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7184443244). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:27:11Z. --- 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 commented 2026-11-26 07:01:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:53:25Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184883740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7184883740). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:53:25Z. --- 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 commented 2026-11-26 08:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T07:54:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185957438 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7185957438). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T07:54:00Z. --- 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 commented 2026-11-26 09:06:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T08:40:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186891368 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7186891368). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T08:40:59Z. --- 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 commented 2026-11-26 17:25:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T17:25:57Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7199006170 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7199006170). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T17:25:57Z. --- 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.
ZeOs360 commented 2026-11-26 21:18:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-26T21:18:29Z.


A small timing-counter note from running e2a68d9 in a combined test build on main 63bcca4 (alongside several other open PRs and a local change; RX 7800 XT, diagnostics build):

The per-frame "copying back" number now includes the GPU's time, so preparing + on the GPU + copying back exceeds ms/frame.

  • let copying = std::time::Instant::now() (host.rs:1255, just before the segment loop) starts the clock before the segments run, and each segment waits for its submission on the fence.
  • COPY_BACK[0] then adds copying.elapsed() at host.rs:1445 after the loop, without subtracting gpu.
  • On main, copying starts after the submission has finished, so the two counters don't overlap there.

In that run this made "copying back" read about 420 ms per frame, while the copy-back work itself (that minus "on the GPU") was about 230 ms. Using copying.elapsed().saturating_sub(gpu), or accumulating a Duration around only the post-wait copy-back block inside the segment loop (which also avoids counting late_refresh there), would keep the counter meaning what it did on main. Nothing outside the frame-rate log counters is affected.

AI-assisted: found with Claude Code (Claude Opus 5.5) and Gemini 4 Neon. I checked the code and ran the build on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203598484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7203598484). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-26T21:18:29Z. --- A small timing-counter note from running `e2a68d9` in a combined test build on `main` `63bcca4` (alongside several other open PRs and a local change; RX 7800 XT, diagnostics build): The per-frame "copying back" number now includes the GPU's time, so `preparing + on the GPU + copying back` exceeds `ms/frame`. - `let copying = std::time::Instant::now()` (`host.rs:1255`, just before the segment loop) starts the clock before the segments run, and each segment waits for its submission on the fence. - `COPY_BACK[0]` then adds `copying.elapsed()` at `host.rs:1445` after the loop, without subtracting `gpu`. - On `main`, `copying` starts after the submission has finished, so the two counters don't overlap there. In that run this made "copying back" read about 420 ms per frame, while the copy-back work itself (that minus "on the GPU") was about 230 ms. Using `copying.elapsed().saturating_sub(gpu)`, or accumulating a `Duration` around only the post-wait copy-back block inside the segment loop (which also avoids counting `late_refresh` there), would keep the counter meaning what it did on `main`. Nothing outside the frame-rate log counters is affected. AI-assisted: found with Claude Code (Claude Opus 5.5) and Gemini 4 Neon. I checked the code and ran the build on my machine.
gtport646 commented 2026-11-29 03:47:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by gtport646 on 2026-11-29T03:47:10Z.


In-title evidence for the #2781 scenario. This is from a fork, with a narrower fix than this PR's, not this PR's code.

Setup: RTX 4090, Series S profile, the title's structure builder running.

What happens:

  • The title asks the builder for a new structure's compacted size.
  • In the same list, it copies that size out of the small buffer the builder stored it in.
  • The copy ran on the CPU at submission, before the list's dispatches, so it read the slot's old value.
  • The title then sized the compacted structure from that old value, and copying the structure in wrote over neighbouring bottom levels.
  • Rays then walked another structure's nodes, and one scene's indirect light went dark.

Fix in the fork (idea from Iweisc/leopard 6ab839ebdc): copies whose source is one page of such a small result buffer are recorded on the card at their place in the list. They go into a read-back buffer that lands with the list. That's about 4,100 copies per run to frame 3,000.

Measured (a dark-scene luminance probe; console about 60):

Build Launches Result
With the fix 5 of 5 lit 58-63 through frame 3,000, no late flips
Same build, fix off 52-55
Before the fork's fix 57, 60, 48 then 30 at ~2,886, 53, 42, 57 then 30 at ~2,550

The reader of that size is the CPU (the title), so this PR's late copy after the copy-backs should cover the same case. Your unchecked "in-title verification" box is the scenario we hit.

No game data used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7250256966 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2810#issuecomment-7250256966). Originally posted by [gtport646](https://github.com/gtport646) on 2026-11-29T03:47:10Z. --- In-title evidence for the #2781 scenario. This is from a fork, with a narrower fix than this PR's, not this PR's code. **Setup:** RTX 4090, Series S profile, the title's structure builder running. **What happens:** - The title asks the builder for a new structure's compacted size. - In the same list, it copies that size out of the small buffer the builder stored it in. - The copy ran on the CPU at submission, before the list's dispatches, so it read the slot's old value. - The title then sized the compacted structure from that old value, and copying the structure in wrote over neighbouring bottom levels. - Rays then walked another structure's nodes, and one scene's indirect light went dark. **Fix in the fork** (idea from Iweisc/leopard `6ab839ebdc`): copies whose source is one page of such a small result buffer are recorded on the card at their place in the list. They go into a read-back buffer that lands with the list. That's about 4,100 copies per run to frame 3,000. **Measured** (a dark-scene luminance probe; console about 60): | Build | Launches | Result | |---|---|---| | With the fix | 5 of 5 lit | 58-63 through frame 3,000, no late flips | | Same build, fix off | | 52-55 | | Before the fork's fix | | 57, 60, 48 then 30 at ~2,886, 53, 42, 57 then 30 at ~2,550 | The reader of that size is the CPU (the title), so this PR's late copy after the copy-backs should cover the same case. Your unchecked "in-title verification" box is the scenario we hit. No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2810:upstream-pr/2810'
git switch 'upstream-pr/2810'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2810'
git switch 'upstream-pr/2810'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2810'
git switch 'upstream-pr/2810'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2810'
git switch 'main'
git merge --squash 'upstream-pr/2810'
git switch 'main'
git merge --ff-only 'upstream-pr/2810'
git switch 'main'
git merge 'upstream-pr/2810'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2808
No description provided.