gpu: join copy_beside before placed_copy/publish in submit split and note batch writes on shader_writes #2433

Manually merged
github merged 1 commit from github-bot/gh-2433 into main 2026-11-30 14:14:39 +00:00 AGit
Owner

@⁠qlfu on GitHub · 2026-11-29 13:00 UTC · original
qlfu:pr/fix-submit-split-send-beside-and-indirect-batch → main · +12 −2 · 2 files · 1 commits · merged 2026-11-30 14:12 UTC

What it changes

Fixes two synchronization/tracking bugs in opt-in GPU submission and indirect-batching paths on origin/main (829188e9):

  1. Join VICTORY_SEND_BESIDE=1 before placed_copy / submission publish under VICTORY_SUBMIT_SPLIT=1 (crates/victory-gpu/src/host.rs): When publish is true, Host::submit calls self.card_take(...) which spawns asynchronous copy_beside reads of Shadow::data, then only joined snapped(&mut snapping) before mutating Shadow::data via shadow.placed_copy(...) and releasing the submitted lock for the next submission's refreshes. Joining own.copied() immediately after snapped(&mut snapping) preserves overlap with snapping while preventing torn Shadow::data reads.
  2. Record HostList::note_batch_write on early returns in Shadow::gpu_writes and Shadow::shader_writes (crates/victory-gpu/src/shadow.rs): Under VICTORY_INDIRECT_BATCH=3, Shadow::shader_writes returned early for self.place.is_some() (e.g. VICTORY_PORT_CONSTANTS=1) and wc_no_back buffers without calling list.note_batch_write, and Shadow::gpu_writes omitted it on the wc_no_back early return. Both paths now record the write in WriteLog so subsequent indirect batches do not reuse stale clamped arguments.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): correctness/race fix verified via unit tests and Clippy on Windows x64 (RTX 4070 Ti + Ryzen 7 5700X); gameplay verification in combined stack pending.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): no shader changes.
  • cargo test passed for the crates it touches: yes (cargo test -p victory-gpu --lib --locked indirect::batch -- --test-threads=1 passed, exit 0; cargo clippy -p victory-gpu --lib --tests --locked: 0 new warnings; --all-features hits pre-existing main shadowing in host.rs:8673 tracked by #2208).

Checked for overlap

  • I searched open pull requests for SEND_BESIDE, SUBMIT_SPLIT, shader_writes, and note_batch_write; no overlapping open PR found.
**@⁠qlfu** on GitHub · 2026-11-29 13:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2433) `qlfu:pr/fix-submit-split-send-beside-and-indirect-batch` → `main` · +12 −2 · 2 files · 1 commits · merged 2026-11-30 14:12 UTC ## What it changes Fixes two synchronization/tracking bugs in opt-in GPU submission and indirect-batching paths on `origin/main` (`829188e9`): 1. **Join `VICTORY_SEND_BESIDE=1` before `placed_copy` / submission publish under `VICTORY_SUBMIT_SPLIT=1` (`crates/victory-gpu/src/host.rs`):** When `publish` is true, `Host::submit` calls `self.card_take(...)` which spawns asynchronous `copy_beside` reads of `Shadow::data`, then only joined `snapped(&mut snapping)` before mutating `Shadow::data` via `shadow.placed_copy(...)` and releasing the `submitted` lock for the next submission's refreshes. Joining `own.copied()` immediately after `snapped(&mut snapping)` preserves overlap with snapping while preventing torn `Shadow::data` reads. 2. **Record `HostList::note_batch_write` on early returns in `Shadow::gpu_writes` and `Shadow::shader_writes` (`crates/victory-gpu/src/shadow.rs`):** Under `VICTORY_INDIRECT_BATCH=3`, `Shadow::shader_writes` returned early for `self.place.is_some()` (e.g. `VICTORY_PORT_CONSTANTS=1`) and `wc_no_back` buffers without calling `list.note_batch_write`, and `Shadow::gpu_writes` omitted it on the `wc_no_back` early return. Both paths now record the write in `WriteLog` so subsequent indirect batches do not reuse stale clamped arguments. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): correctness/race fix verified via unit tests and Clippy on Windows x64 (RTX 4070 Ti + Ryzen 7 5700X); gameplay verification in combined stack pending. - For shader changes, the wave sizes tested (32 and/or 64 lanes): no shader changes. - `cargo test` passed for the crates it touches: yes (`cargo test -p victory-gpu --lib --locked indirect::batch -- --test-threads=1` passed, exit 0; `cargo clippy -p victory-gpu --lib --tests --locked`: 0 new warnings; `--all-features` hits pre-existing `main` shadowing in `host.rs:8673` tracked by #2208). ## Checked for overlap - [x] I searched open pull requests for `SEND_BESIDE`, `SUBMIT_SPLIT`, `shader_writes`, and `note_batch_write`; no overlapping open PR found.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 13:00:43 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 13:04 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean 12-line merge across crates/victory-gpu/src/host.rs and shadow.rs.
  • Tests (RTX 5090):
    • cargo test -p victory-gpu --lib shadow:: passed (71 passed; 0 failed; 5 ignored).
    • cargo test -p victory-gpu --lib host::written_spans_tests:: passed (3 passed; 0 failed).
  • 0 new warnings.

Clean ordering fix joining copy_beside before placed_copy/publish in submit split and recording batch writes on shader_writes. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-29 13:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2433#pullrequestreview-6102993867) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean 12-line merge across `crates/victory-gpu/src/host.rs` and `shadow.rs`. - **Tests (RTX 5090)**: - `cargo test -p victory-gpu --lib shadow::` passed (`71 passed; 0 failed; 5 ignored`). - `cargo test -p victory-gpu --lib host::written_spans_tests::` passed (`3 passed; 0 failed`). - 0 new warnings. Clean ordering fix joining `copy_beside` before `placed_copy`/`publish` in submit split and recording batch writes on `shader_writes`. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot force-pushed github-bot/gh-2433 from 48099873f9 to d5e6ebc0e7 2026-11-29 14:56:31 +00:00 Compare
Author
Owner

@⁠qlfu on GitHub · 2026-11-29 14:53 UTC · original

Updated with deferred copy_beside join (send::CopyWait + Host::pending_copy_beside):

  • Still joins immediately before Shadow::placed_copy when !batch.placed.is_empty() and before Shadow::update / refresh_front / refresh_ahead / run_deferred on the next submission (plus top of Host::settle), keeping the CopyWait mutex held across copying.join().
  • Restores CPU/background-copy overlap between submission N's copy_beside and submission N+1's card_steps / sweep / ask_once.
  • Verified in 90s release benchmark (0 WARNs / 0 ERRORs): card_copies dropped 2.10 -> 1.30 ms median (2.53 -> 1.57 ms mean, -0.96 ms/frame); all indirect::batch, host::send, and full victory-gpu (926 passed; 0 failed) tests pass with 0 new clippy warnings.
**@⁠qlfu** on GitHub · 2026-11-29 14:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2433#issuecomment-7257662411) Updated with deferred `copy_beside` join (`send::CopyWait` + `Host::pending_copy_beside`): - Still joins immediately before `Shadow::placed_copy` when `!batch.placed.is_empty()` and before `Shadow::update` / `refresh_front` / `refresh_ahead` / `run_deferred` on the next submission (plus top of `Host::settle`), keeping the `CopyWait` mutex held across `copying.join()`. - Restores CPU/background-copy overlap between submission N's `copy_beside` and submission N+1's `card_steps` / `sweep` / `ask_once`. - Verified in 90s release benchmark (`0 WARNs / 0 ERRORs`): `card_copies` dropped **`2.10 -> 1.30 ms`** median (`2.53 -> 1.57 ms` mean, **-0.96 ms/frame**); all `indirect::batch`, `host::send`, and full `victory-gpu` (`926 passed; 0 failed`) tests pass with `0` new clippy warnings.
github-bot force-pushed github-bot/gh-2433 from d5e6ebc0e7 to 48099873f9 2026-11-29 15:36:10 +00:00 Compare
Author
Owner

@⁠qlfu on GitHub · 2026-11-29 15:33 UTC · original

Reverted the deferred CopyWait experiment back to joining own.copied() immediately before placed_copy/publish (48099873):

  • Audit found that victory-relay (Shadow::card_merge_relay in shadow.rs:7188) mutates Shadow::data concurrently without holding Host::submitted, so keeping copy_beside active past publish can race with landed shader writes (and produced visual reflection artifacts in live testing).
  • Joining own.copied() immediately before placed_copy/publish guarantees no background copy_beside reader remains alive once Host::submit releases submitted.
**@⁠qlfu** on GitHub · 2026-11-29 15:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2433#issuecomment-7258181137) Reverted the deferred `CopyWait` experiment back to joining `own.copied()` immediately before `placed_copy`/`publish` (`48099873`): - Audit found that `victory-relay` (`Shadow::card_merge_relay` in `shadow.rs:7188`) mutates `Shadow::data` concurrently without holding `Host::submitted`, so keeping `copy_beside` active past `publish` can race with landed shader writes (and produced visual reflection artifacts in live testing). - Joining `own.copied()` immediately before `placed_copy`/`publish` guarantees no background `copy_beside` reader remains alive once `Host::submit` releases `submitted`.
Author
Owner

@⁠Yoruiopz on GitHub · 2026-11-30 11:22 UTC · original

Independent Windows verification on .05 (41adb551) with synthetic memory. The CPU-only fixture used the production submit, send, and shadow code. A pending 32 KiB upload captured 0xC7 from a later placed update instead of its original 0x39 in four controlled schedules: the update was in the same submission or after handoff, and the copy job was queued or already claimed by a worker. All four preserve 0x39 when the exact patch from 48099873 is applied on .05. The synchronous and already-completed controls pass on both revisions.

The locked Windows diagnostics crate build passed eight relevant CPU unit tests, with one adapter-dependent case ignored. The reproduction used CPU memory and synthetic bytes. The current #3809 and #3881 patches also apply cleanly on this tree.

**@⁠Yoruiopz** on GitHub · 2026-11-30 11:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2433#issuecomment-7276943910) Independent Windows verification on .05 (41adb551) with synthetic memory. The CPU-only fixture used the production submit, send, and shadow code. A pending 32 KiB upload captured 0xC7 from a later placed update instead of its original 0x39 in four controlled schedules: the update was in the same submission or after handoff, and the copy job was queued or already claimed by a worker. All four preserve 0x39 when the exact patch from 48099873 is applied on .05. The synchronous and already-completed controls pass on both revisions. The locked Windows diagnostics crate build passed eight relevant CPU unit tests, with one adapter-dependent case ignored. The reproduction used CPU memory and synthetic bytes. The current #3809 and #3881 patches also apply cleanly on this tree.
github manually merged commit 3f55cb5163 into main 2026-11-30 14:14:39 +00:00
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/trustno1-coder--VIctory-NVIDIA!2433
No description provided.