GPU: track each write range once per submission #440

Closed
github-bot wants to merge 1 commit from gh-pr/440/head into gh-pr/440/base
Owner

@⁠tcurtsinger on GitHub · 2026-11-24 03:25 UTC · original
tcurtsinger:perf/track-submission-write-ranges → main · +95 −28 · 3 files · 1 commits · closed without merging

Change

Each submission prepares every declared GPU write and then, after the fence, walks all deferred commands again to find the distinct ranges to copy back. Repeating a declaration also grows the shadow's pending list, which later refreshes search.

Record each exact (shadow identity, address, length) on its first declaration. Flush preceding refreshes at every declaration, including repeats. Keep the first-declaration order for copy-back so distinct views that overlap title memory finish in the same order as before. The membership set is released before the GPU wait.

Synthetic measurements

Windows D3D12 WARP, optimized diagnostics build, base d2a4bae. Each range is 512 bytes. Each sample submits closed command lists with deferred refreshes and GPU-write declarations and checks the resulting title bytes. Values are median microseconds per submission across eight fresh processes per revision in counterbalanced order. Each process ran three warm-up batches and nine measured batches of eight submissions.

Declarations / distinct ranges Pending entries, main → PR CPU preparation, main → PR (µs) Whole submission, main → PR (µs)
1 / 1 1 → 1 1.1 → 1.0 36.7 → 31.9
128 / 128 128 → 128 149.4 → 156.2 464.6 → 469.9
512 / 16 512 → 16 71.9 → 50.4 237.5 → 213.1
2,048 / 32 2,048 → 32 254.4 → 133.8 471.1 → 322.1

The 128-distinct control took about 1% longer end to end. The two repeated-range cases improved. The frequency of repeated write declarations in a native world frame and the effect on FPS remain unmeasured.

Verification

  • The regression fails on main and passes here. It covers exact repeats within and across command lists, overlapping views with different lengths, two shadows sharing a title address, a refresh before a duplicate, and resubmitting the same lists after the fence.
  • Windows workspace tests passed with default features (265 passed, four ignored) and with diagnostics on WARP (268 passed, four ignored). The existing frame-clock test missed a tick on the first diagnostics run and passed both in isolation and on the full rerun.
  • Asset policy and diff checks passed. GPU Clippy completed with its existing test-only safety-comment warning.
  • A test merge is clean with #124, #261, and #393 separately. #401 changes the copy-back loop and would need to retain its shared scratch buffer. #387 changes execution ordering and would need to scope this tracking to each submission segment.

Related to #400. AI-assisted implementation and testing.

**@⁠tcurtsinger** on GitHub · 2026-11-24 03:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/440) `tcurtsinger:perf/track-submission-write-ranges` → `main` · +95 −28 · 3 files · 1 commits · closed without merging ## Change Each submission prepares every declared GPU write and then, after the fence, walks all deferred commands again to find the distinct ranges to copy back. Repeating a declaration also grows the shadow's pending list, which later refreshes search. Record each exact (shadow identity, address, length) on its first declaration. Flush preceding refreshes at every declaration, including repeats. Keep the first-declaration order for copy-back so distinct views that overlap title memory finish in the same order as before. The membership set is released before the GPU wait. ## Synthetic measurements Windows D3D12 WARP, optimized diagnostics build, base `d2a4bae`. Each range is 512 bytes. Each sample submits closed command lists with deferred refreshes and GPU-write declarations and checks the resulting title bytes. Values are median microseconds per submission across eight fresh processes per revision in counterbalanced order. Each process ran three warm-up batches and nine measured batches of eight submissions. | Declarations / distinct ranges | Pending entries, main → PR | CPU preparation, main → PR (µs) | Whole submission, main → PR (µs) | | --- | ---: | ---: | ---: | | 1 / 1 | 1 → 1 | 1.1 → 1.0 | 36.7 → 31.9 | | 128 / 128 | 128 → 128 | 149.4 → 156.2 | 464.6 → 469.9 | | 512 / 16 | 512 → 16 | 71.9 → 50.4 | 237.5 → 213.1 | | 2,048 / 32 | 2,048 → 32 | 254.4 → 133.8 | 471.1 → 322.1 | The 128-distinct control took about 1% longer end to end. The two repeated-range cases improved. The frequency of repeated write declarations in a native world frame and the effect on FPS remain unmeasured. ## Verification - The regression fails on main and passes here. It covers exact repeats within and across command lists, overlapping views with different lengths, two shadows sharing a title address, a refresh before a duplicate, and resubmitting the same lists after the fence. - Windows workspace tests passed with default features (265 passed, four ignored) and with diagnostics on WARP (268 passed, four ignored). The existing frame-clock test missed a tick on the first diagnostics run and passed both in isolation and on the full rerun. - Asset policy and diff checks passed. GPU Clippy completed with its existing test-only safety-comment warning. - A test merge is clean with #124, #261, and #393 separately. #401 changes the copy-back loop and would need to retain its shared scratch buffer. #387 changes execution ordering and would need to scope this tracking to each submission segment. Related to #400. AI-assisted implementation and testing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:03 +00:00
github-bot closed this pull request 2026-11-26 04:04:03 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 03:35 UTC · original

Overlaps with #435: both deduplicate Step::GpuWrite per submission in crates/victory-gpu/src/host.rs, and they conflict textually — git merge-tree --write-tree pr435 pr440 reports CONFLICT (content) in host.rs. Worth choosing one.

Both were verified separately on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (--test-threads=1):

  • this PR (0ba3e44): victory-gpu 44 passed, 0 failed, 1 ignored; shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order passes.
  • #435 (657efd8): 44 passed, 0 failed, 1 ignored; its host::batch::exact_gpu_writes_are_declared_once_per_submission passes.

This PR keeps the first-declaration copy-back order and tests it; #435 keeps the set inside Batch::new_gpu_write. Both fix the same repeated-range cost, so one supersedes the other.

**@⁠DaviTostes** on GitHub · 2026-11-24 03:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/440#issuecomment-7121236610) Overlaps with #435: both deduplicate `Step::GpuWrite` per submission in `crates/victory-gpu/src/host.rs`, and they conflict textually — `git merge-tree --write-tree pr435 pr440` reports `CONFLICT (content)` in `host.rs`. Worth choosing one. Both were verified separately on **Arch Linux x86_64**, Windows MSVC release build under **Wine 11.22** (`--test-threads=1`): - this PR (`0ba3e44`): `victory-gpu` **44 passed, 0 failed, 1 ignored**; `shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order` passes. - #435 (`657efd8`): **44 passed, 0 failed, 1 ignored**; its `host::batch::exact_gpu_writes_are_declared_once_per_submission` passes. This PR keeps the first-declaration copy-back order and tests it; #435 keeps the set inside `Batch::new_gpu_write`. Both fix the same repeated-range cost, so one supersedes the other.
Author
Owner

@⁠tcurtsinger on GitHub · 2026-11-24 15:27 UTC · original

Thanks for testing both PRs. I ran the same ordering test on both heads with Windows D3D12 WARP. A refresh queued between two identical write declarations is visible to a host callback immediately after the repeat in #440. On #435 the callback ran before the refresh and saw the old byte.

Build Byte read by the callback (expected 33)
#440 at 0ba3e44 33, pass
#435 at 657efd8, with the identical test added 0, fail
#435 with self.flush() moved immediately before if self.new_gpu_write(...) 33, pass

The callback is synthetic. Gameplay impact remains unmeasured. Either implementation can preserve the existing ordering by flushing before the duplicate check. I’d keep the regression in whichever PR lands. Test source

cargo test --locked -p victory-gpu --lib --features diagnostics shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order -- --exact --test-threads=1 with VICTORY_D3D12_WARP=1.

AI-assisted testing.

**@⁠tcurtsinger** on GitHub · 2026-11-24 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/440#issuecomment-7136070981) Thanks for testing both PRs. I ran the same ordering test on both heads with Windows D3D12 WARP. A refresh queued between two identical write declarations is visible to a host callback immediately after the repeat in #440. On #435 the callback ran before the refresh and saw the old byte. | Build | Byte read by the callback (expected 33) | | --- | ---: | | #440 at `0ba3e44` | 33, pass | | #435 at `657efd8`, with the identical test added | 0, fail | | #435 with `self.flush()` moved immediately before `if self.new_gpu_write(...)` | 33, pass | The callback is synthetic. Gameplay impact remains unmeasured. Either implementation can preserve the existing ordering by flushing before the duplicate check. I’d keep the regression in whichever PR lands. [Test source](https://github.com/Marvisak/VIctory/blob/0ba3e44575a2590bfc583e8e4d232fcfbcbb5c84/crates/victory-gpu/src/shadow/submission_tests.rs#L25-L46) `cargo test --locked -p victory-gpu --lib --features diagnostics shadow::submission_tests::repeated_gpu_writes_keep_their_first_copy_back_order -- --exact --test-threads=1` with `VICTORY_D3D12_WARP=1`. AI-assisted testing.
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-24 18:24 UTC · original

Test report on a 6 GB / 16 GB laptop: on top of #393 this PR gives a further small gain (3,347 → 3,221 ms per world frame, copies 100 → 67 ms). That's within this machine's run-to-run spread (about ±10%), so it's not a clear effect.

Setup: RTX 3050 6 GB Laptop (NVIDIA, driver 32.0.16.2124), i7-13700H, 16 GB RAM, Windows 11 26300, diag build. Title 1.0.2.1, Series X profile, the story load. Base tree: main ffe310e + the PRs listed in #1232 + #431. Each PR was merged onto that base, and each row is one run of 300 s from launch. "World frame" is the average of the fps, ms/frame (…) lines under 10 fps with 20+ draws. Write-watch numbers are the last 8 copystat lines.

tree world frame preparing copies write-watch askings / frame their time / frame
base (+ #431) 3,966 ms 1,988 447 867 475 ms
+ #393 3,347 ms 1,579 100 585 13 ms
+ #440 + #393 3,221 ms 1,553 67 572 14 ms
+ #515 5,256 ms 3,228 1,223 884 1,605 ms
+ #440 + #515 + #393 4,090 ms 2,243 201 550 29 ms

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine and drafted this report; results are from the runs described.

**@⁠AgneyaK** on GitHub · 2026-11-24 18:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/440#issuecomment-7140611188) Test report on a 6 GB / 16 GB laptop: on top of #393 this PR gives a further small gain (3,347 → 3,221 ms per world frame, copies 100 → 67 ms). That's within this machine's run-to-run spread (about ±10%), so it's not a clear effect. **Setup:** RTX 3050 6 GB Laptop (NVIDIA, driver 32.0.16.2124), i7-13700H, 16 GB RAM, Windows 11 26300, diag build. Title 1.0.2.1, Series X profile, the story load. Base tree: `main` `ffe310e` + the PRs listed in #1232 + #431. Each PR was merged onto that base, and each row is one run of 300 s from launch. "World frame" is the average of the `fps, ms/frame (…)` lines under 10 fps with 20+ draws. Write-watch numbers are the last 8 `copystat` lines. | tree | world frame | preparing | copies | write-watch askings / frame | their time / frame | |---|---:|---:|---:|---:|---:| | base (+ #431) | 3,966 ms | 1,988 | 447 | 867 | 475 ms | | + #393 | **3,347 ms** | 1,579 | **100** | 585 | **13 ms** | | + #440 + #393 | **3,221 ms** | 1,553 | 67 | 572 | 14 ms | | + #515 | 5,256 ms | 3,228 | 1,223 | 884 | **1,605 ms** | | + #440 + #515 + #393 | 4,090 ms | 2,243 | 201 | 550 | 29 ms | AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine and drafted this report; results are from the runs described.

Pull request closed

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!440
No description provided.