perf(gpu): snapshot placed-copy constants on GPU and enable VICTORY_PLACED_ORDER #34

Open
github-bot wants to merge 1 commit from github-bot/gh-34 into main AGit
Owner

@⁠k0ma2k15 on GitHub · 2026-11-27 11:56 UTC · original
k0ma2k15:perf/card-steps → main · +178 −6 · 4 files · 1 commits · open

Summary

  • Snapshot placed-copy constants directly on the GPU (HostList::place_constant) so constant buffers reading bytes written earlier in the same command list by HostList::place_copy no longer emit a CPU Step::Fill.
  • Enable VICTORY_PLACED_ORDER by default (VICTORY_PLACED_ORDER=0 restores the previous behaviour), allowing card_steps::cut_for to split cross-list Step::Placed -> Step::Fill dependencies instead of refusing the entire submission.

Problem

When card_steps runs with VICTORY_RELAY=2 and VICTORY_CARD_STEPS=2, submissions were repeatedly refused with BEHIND_PLACED (a copy at its place in a list writes what it reads, or reads or writes what it writes), stalling the submitting thread on waiting for flights (8.6–8.7 ms/frame average, spikes up to 43–51 ms/frame).

Turning on VICTORY_PLACED_ORDER=1 eliminated cross-list refusals via cut_for, leaving 100% of remaining BEHIND_PLACED refusals as a single pattern: an earlier Step::Placed followed in the same command list by a constant-buffer Step::Fill wholly inside [placed.dst, placed.dst + placed.len). Because Step::Fill reads title memory on the CPU while Step::Placed wrote the destination on the GPU, card_steps had to refuse and wait for flights (and if place_copy copied shader-written bytes, the CPU view was also stale).

Changes

  • HostList::place_constant (place.rs, wired in draw.rs):
    • Tracks [dst, dst + len) destinations written by HostList::place_copy per recording (has_placed atomic fast-path on HostList, placed_written and placed_cbv on Deferred, invalidated on overlapping HostList::defer_copy, cleared on HostList::reset).
    • For View::Constant descriptors and unaligned constant-buffer root_views wholly covered by the most recent place_copy in the same recording (bailing to the normal Step::Fill path on partial overlap or disjoint ranges), copies [src, src + len) directly on the GPU from the destination host copy into a per-list 256-byte-aligned DEFAULT buffer (D3D12_RESOURCE_STATE_GENERIC_READ).
    • Escape hatch: VICTORY_PLACED_CONSTANTS=0 disables GPU constant snapshots.
    • Adds D3D12 unit test host::place::tests::place_constant_reads_what_place_copy_wrote.
  • placed_order() (card_steps.rs):
    • Defaults VICTORY_PLACED_ORDER to enabled (VICTORY_PLACED_ORDER=0 disables).

Measured results

Measured on Windows 11, Ryzen 7 8845HS, NVIDIA GeForce RTX 4070 SUPER (USB4 eGPU), Series X profile, 2560x1440, DLSS Quality, release build, same gameplay area (excluding the initial scene-load transition frame):

Configuration BEHIND_PLACED seconds waiting_for_flights avg (max) Seconds with 0.0 ms wait on the GPU wait avg
Baseline (main) 89 s 8.6–8.7 ms (43.2–50.7 ms) 5–8% (6/115 s, 9/117 s) 7.6–11.4 ms
VICTORY_PLACED_ORDER=1 only 40–47 s 4.4–8.3 ms (19.1–91.5 ms) 14–28% (19/68 s, 10/69 s) 5.4–10.7 ms
VICTORY_PLACED_ORDER (default) + place_constant 0 s 1.7 ms (17.3 ms) 50% (27/54 s) 3.2 ms

In the verification run, 7.3–10.0 constants per frame were read in place, 0 errors were logged, and no visual regressions were observed.

Verification

  • cargo test --workspace --exclude victory-gpu --locked (including xtask asset-policy tests): passed
  • cargo test -p victory-gpu --lib host::card_steps --locked: 9 passed, 0 failed, 1 ignored (#[ignore] multi-process test)
  • cargo test -p victory-gpu --lib host::place --locked (including new D3D12 test place_constant_reads_what_place_copy_wrote): 9 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --all-targets --locked & --all-features: 0 warnings in modified code
  • cargo build --release --locked -p victory: passed
**@⁠k0ma2k15** on GitHub · 2026-11-27 11:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/34) `k0ma2k15:perf/card-steps` → `main` · +178 −6 · 4 files · 1 commits · open ## Summary - **Snapshot placed-copy constants directly on the GPU (`HostList::place_constant`)** so constant buffers reading bytes written earlier in the same command list by `HostList::place_copy` no longer emit a CPU `Step::Fill`. - **Enable `VICTORY_PLACED_ORDER` by default** (`VICTORY_PLACED_ORDER=0` restores the previous behaviour), allowing `card_steps::cut_for` to split cross-list `Step::Placed` -> `Step::Fill` dependencies instead of refusing the entire submission. ## Problem When `card_steps` runs with `VICTORY_RELAY=2` and `VICTORY_CARD_STEPS=2`, submissions were repeatedly refused with `BEHIND_PLACED` (`a copy at its place in a list writes what it reads, or reads or writes what it writes`), stalling the submitting thread on `waiting for flights` (`8.6–8.7 ms/frame` average, spikes up to `43–51 ms/frame`). Turning on `VICTORY_PLACED_ORDER=1` eliminated cross-list refusals via `cut_for`, leaving **100%** of remaining `BEHIND_PLACED` refusals as a single pattern: an earlier `Step::Placed` followed in the **same command list** by a constant-buffer `Step::Fill` wholly inside `[placed.dst, placed.dst + placed.len)`. Because `Step::Fill` reads title memory on the CPU while `Step::Placed` wrote the destination on the GPU, `card_steps` had to refuse and wait for flights (and if `place_copy` copied shader-written bytes, the CPU view was also stale). ## Changes - **`HostList::place_constant` ([place.rs](crates/victory-gpu/src/host/place.rs), wired in [draw.rs](crates/victory-gpu/src/draw.rs)):** - Tracks `[dst, dst + len)` destinations written by `HostList::place_copy` per recording (`has_placed` atomic fast-path on `HostList`, `placed_written` and `placed_cbv` on `Deferred`, invalidated on overlapping `HostList::defer_copy`, cleared on `HostList::reset`). - For `View::Constant` descriptors and unaligned constant-buffer `root_view`s wholly covered by the most recent `place_copy` in the same recording (bailing to the normal `Step::Fill` path on partial overlap or disjoint ranges), copies `[src, src + len)` directly on the GPU from the destination host copy into a per-list 256-byte-aligned `DEFAULT` buffer (`D3D12_RESOURCE_STATE_GENERIC_READ`). - Escape hatch: `VICTORY_PLACED_CONSTANTS=0` disables GPU constant snapshots. - Adds D3D12 unit test `host::place::tests::place_constant_reads_what_place_copy_wrote`. - **`placed_order()` ([card_steps.rs](crates/victory-gpu/src/host/card_steps.rs)):** - Defaults `VICTORY_PLACED_ORDER` to enabled (`VICTORY_PLACED_ORDER=0` disables). ## Measured results Measured on Windows 11, Ryzen 7 8845HS, NVIDIA GeForce RTX 4070 SUPER (USB4 eGPU), Series X profile, 2560x1440, DLSS Quality, `release` build, same gameplay area (excluding the initial scene-load transition frame): | Configuration | `BEHIND_PLACED` seconds | `waiting_for_flights` avg (max) | Seconds with `0.0 ms` wait | `on the GPU` wait avg | |---|---:|---:|---:|---:| | Baseline (`main`) | 89 s | 8.6–8.7 ms (43.2–50.7 ms) | 5–8% (`6/115 s`, `9/117 s`) | 7.6–11.4 ms | | `VICTORY_PLACED_ORDER=1` only | 40–47 s | 4.4–8.3 ms (19.1–91.5 ms) | 14–28% (`19/68 s`, `10/69 s`) | 5.4–10.7 ms | | `VICTORY_PLACED_ORDER` (default) + `place_constant` | **0 s** | **1.7 ms (17.3 ms)** | **50% (`27/54 s`)** | **3.2 ms** | In the verification run, `7.3–10.0` constants per frame were read in place, `0` errors were logged, and no visual regressions were observed. ## Verification - `cargo test --workspace --exclude victory-gpu --locked` (including `xtask` asset-policy tests): passed - `cargo test -p victory-gpu --lib host::card_steps --locked`: 9 passed, 0 failed, 1 ignored (`#[ignore]` multi-process test) - `cargo test -p victory-gpu --lib host::place --locked` (including new D3D12 test `place_constant_reads_what_place_copy_wrote`): 9 passed, 0 failed, 1 ignored - `cargo clippy -p victory-gpu --all-targets --locked` & `--all-features`: 0 warnings in modified code - `cargo build --release --locked -p victory`: passed
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:58:35 +00:00
Author
Owner

@⁠heklokate on GitHub · 2026-11-27 18:04 UTC · original

Test results on an RTX 3070 Laptop GPU

The GPU constant snapshot path was active, averaging nine constants read in place per frame in each window. The main runs had about 0.3 ms/frame of flight wait in this save. This did not reproduce the sustained flight waits in the PR description.

Hardware and setup. Intel Core i9-12900H, RTX 3070 Laptop GPU (8 GB, driver 32.0.16.1742), 32 GB DDR5-4800, Windows 11 build 26100. Release build, Series S, DLSS Quality, frame generation off. The same deck save and independently warmed caches were used throughout.

Samples. Two valid runs per configuration, one 30-second PresentMon capture at 180–181 seconds after launch per run. The table lists each run. Warm-ups were excluded.

Revisions. Main d12eb1b and the af242da patch applied to that same revision. Both used VICTORY_RELAY=2 and VICTORY_CARD_STEPS=2.

Metric Main 1 Main 2 PR 1 PR 2
Frames sampled 260 257 263 255
Median FPS 8.92 8.83 9.15 8.71
1% low FPS 5.99 5.23 5.51 5.93
P95 frame time (ms) 141.90 151.24 148.78 148.38
P99 frame time (ms) 166.86 191.22 181.37 168.51
Median draws per frame 5955 6036 5970 5939
Flight wait median (ms/frame) 0.30 0.30 0.30 0.30
Log intervals with refused submissions 1 0 0 0
Constants read in place per frame — — 9.00 9.00

Draw counts were within 2% between the runs. One early PR attempt stopped during load with a guest access violation that also occurred during main warm-up. A completed run taken before the separate warm-up retry was excluded from the table.

Tested and documented by Codex.

**@⁠heklokate** on GitHub · 2026-11-27 18:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/34#issuecomment-7225085295) ### Test results on an RTX 3070 Laptop GPU The GPU constant snapshot path was active, averaging nine constants read in place per frame in each window. The main runs had about 0.3 ms/frame of flight wait in this save. This did not reproduce the sustained flight waits in the PR description. **Hardware and setup.** Intel Core i9-12900H, RTX 3070 Laptop GPU (8 GB, driver `32.0.16.1742`), 32 GB DDR5-4800, Windows 11 build 26100. Release build, Series S, DLSS Quality, frame generation off. The same deck save and independently warmed caches were used throughout. **Samples.** Two valid runs per configuration, one 30-second PresentMon capture at 180–181 seconds after launch per run. The table lists each run. Warm-ups were excluded. **Revisions.** Main `d12eb1b` and the `af242da` patch applied to that same revision. Both used `VICTORY_RELAY=2` and `VICTORY_CARD_STEPS=2`. | Metric | Main 1 | Main 2 | PR 1 | PR 2 | |---|---:|---:|---:|---:| | Frames sampled | 260 | 257 | 263 | 255 | | Median FPS | 8.92 | 8.83 | 9.15 | 8.71 | | 1% low FPS | 5.99 | 5.23 | 5.51 | 5.93 | | P95 frame time (ms) | 141.90 | 151.24 | 148.78 | 148.38 | | P99 frame time (ms) | 166.86 | 191.22 | 181.37 | 168.51 | | Median draws per frame | 5955 | 6036 | 5970 | 5939 | | Flight wait median (ms/frame) | 0.30 | 0.30 | 0.30 | 0.30 | | Log intervals with refused submissions | 1 | 0 | 0 | 0 | | Constants read in place per frame | — | — | 9.00 | 9.00 | Draw counts were within 2% between the runs. One early PR attempt stopped during load with a guest access violation that also occurred during main warm-up. A completed run taken before the separate warm-up retry was excluded from the table. Tested and documented by Codex.
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/34/head:github-bot/gh-34'
git switch 'github-bot/gh-34'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-34'
git switch 'github-bot/gh-34'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-34'
git switch 'github-bot/gh-34'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-34'
git switch 'main'
git merge --squash 'github-bot/gh-34'
git switch 'main'
git merge --ff-only 'github-bot/gh-34'
git switch 'main'
git merge 'github-bot/gh-34'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.