Skip to content

GPU: track each write range once per submission - #440

Closed
tcurtsinger wants to merge 1 commit into
Marvisak:mainfrom
tcurtsinger:perf/track-submission-write-ranges
Closed

tcurtsinger wants to merge 1 commit into
Marvisak:mainfrom
tcurtsinger:perf/track-submission-write-ranges

Conversation

@tcurtsinger

Copy link
Copy Markdown

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

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

@DaviTostes

Copy link
Copy Markdown

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 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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 0ba3e44 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed).

The change looks correct. Declarations are deduplicated per (shadow, address, len). Copy-back keeps first-declaration order, and the membership set is dropped before the GPU wait.

This overlaps almost line for line with #435 (melon0918, "coalesce identical write declarations within a submission"), which I also reviewed. The two cannot both merge, since they rewrite the same hunk of run_deferred and copy-back. The one real difference:

  • #440 still runs batch.flush() on a repeated declaration.
  • #435 skips the flush for repeats.

By my reading of Shadow::writing both are equivalent. A repeat never retakes the snapshot, and refreshes queued between two declarations are flushed by the next title_written() or the final batch flush before the lists run. #440's form is the more conservative of the two. It would be good for the maintainers to pick one and close the other. #440 also brings the submission_tests.rs harness, which #435 lacks.

I have not merged this into our fork, because it conflicts with #435, which is already merged there.

AI-assisted (Claude Code).

@tcurtsinger

Copy link
Copy Markdown
Author

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.

@AgneyaK

AgneyaK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@tcurtsinger
tcurtsinger deleted the perf/track-submission-write-ranges branch November 24, 2026 18:46
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
texture_at inserted failed host creations into PLACED_TEXTURES, so a
later lookup returned Some with host == None. Release the resource and
return None instead (VIC-BT-027 / Marvisak#440).

Refs Marvisak#440.

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…iled-host-440-111a

GPU: do not cache placed textures without a host copy (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
v_cvt_f16_f32 / v_cvt_f32_f16 already go through valu16 (abs/neg/clamp);
remove the unreachable opsel==0 arms (VIC-BT-028). image_get_resinfo
returns 0 for unused size channels instead of 1 (VIC-BT-038 / Marvisak#440).

Refs Marvisak#440.

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ily-440-111a

HLE: report analytics family as Windows.Xbox (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…arvisak#440

resource::track visited blocks in index order, so after split_irreducible
appended copies a descriptor access could run before its dominating s_load
was recorded in out.scalar and miss the waterfall offset load. Collect every
scalar address first, then resolve descriptors in reverse postorder.

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…-440-111a

Shaders: track scalar addresses in RPO before waterfall lookup (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
… Refs Marvisak#440

Hardware masks base, soffset, and imm_offset with & ~3 independently
before summing; adding first then truncating shifts the load when low
bits of two terms carry into bit 2.

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…naligned-440-111a

Shaders: dword-truncate each s_buffer_load address term before adding (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
RDNA flushes f32 subnormals on v_mad_f32 / v_mac_f32 (inputs, product,
sum, and after omod) regardless of MODE.denorm32. Without that, mul:2 of
a flushed-to-zero mad sum could yield FLT_MIN instead of +0.

Refs Marvisak#440.

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…lush-440-111a

Shaders: flush subnormals around v_mad_f32 / v_mac_f32 omod (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
Unfused mad/mac must round a×b to binary16 before adding the
accumulator; conflating them with fused v_fma_f16 / v_fmac_f16 made
256h×256h+(-65504h) yield 32h instead of +inf (VIC-BT-042).

Refs Marvisak#440

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…40-111a

Shaders: round v_mad_f16 / v_mac_f16 product to f16 before add (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…pages-440-111a

xmem: recycle freed physical page numbers under churn (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…tname-440-111a

HLE: allow local gethostname through offline resolvable() (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…gister-440-111a

HLE: lock XPackageUnregisterInstallationProgressChanged to bool unregister (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…-440-111a

Shaders: keep SCC uniform for two-mask s_cmp_eq/lg (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
Unreachable CFG predecessors left empty outs during rename, so phi.args
got NONE (Value(u32::MAX)) and remove_trivial_phis panicked in release.
Prune blocks unreachable from entry (and re-prune in rename if needed)
so SSA never sees those edges. Refs Marvisak#438 Marvisak#440 (VIC-BT-002).

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…chable-preds-111a

Shaders: prune unreachable blocks before SSA renaming (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…pipeline-111a

GPU: bind CreateCommandList pInitialState like Reset (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ull-result-111a

HLE: document and harden getaddrinfo null-on-failure tests (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…uns-111a

GPU: split execute batches when the same HostList repeats (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…ar-rt-ds-440-111a

GPU: drop optimized clear values without RT or DS flags (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…-dsv-dim-111a

GPU: synthesize NULL-desc RTV/DSV dimensions from the resource shape (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…-null-desc-111a

GPU: resolve null/UNKNOWN views on typeless-promoted textures (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…i16-440-111a

Shaders: decode inline floats as f32 bits for 16-bit integer ops (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
When LaneExit::Branch has taken == not_taken, calling edge() twice
overwrote the first critical-edge block under the same (from, to) key
and left fill_phis missing a CondBr predecessor. Treat that case as an
unconditional jump (VIC-BT-007 / Marvisak#438/Marvisak#440).

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…edge-map-440-111a

Shaders: collapse Branch with identical arms before critical-edge map (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…er-cmp-slots-111a

Shaders: distinct static slots for comparison vs plain immediate samplers (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…r-high-half-111a

Shaders: keep d16 format-load high halves and saturate integer channels (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…unknown-440-111a

HLE: GameInput QueryInterface accepts IUnknown and own IIDs (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…-440-111a

GPU: clarify null CreateConstantBufferView always writes a null CBV (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…are-440-111a

GPU: bind descriptor heaps by creation id to avoid ABA reuse (Marvisak#440)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…d-d16-440-111a

Shaders: keep image_load d16 high half and saturate integer texels (Marvisak#440)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants