Skip to content

Diagnostics: heap-sync counters and run-hash shader labels (buffer-release change reverted) - #3

Open
CocoBeans64 wants to merge 5 commits into
mainfrom
perf-submission-thread
Open

CocoBeans64 wants to merge 5 commits into
mainfrom
perf-submission-thread

Conversation

@CocoBeans64

@CocoBeans64 CocoBeans64 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Performance work on the prologue's world, toward a steadier frame rate (goal: 30 fps, even at reduced quality). It comes from one evening of measurements with a reproducible bench on Windows 10 (RX 6800 XT, Ryzen 7 7800X3D, Agility SDK, Series X profile, FSR at 0.5 scale from Marvisak#1793).

Update 2026-11-26: commit 1 is reverted in this branch (adfdbcb). After the rebase onto upstream 842b0cb, a control run gave 799 ms/frame with it and 750 ms/frame without (one run each, noise ~±5 %). A profile on the new base then showed why: memory::prepare / Shared::rewrite is down to 0.09 % of the process, against 17 % of the submission thread on the old base. The driver no longer frees buffers on the critical path, most likely since Marvisak#1865 writes the page tables directly. This PR now only adds diagnostics (commits 2 and 3, plus a clippy fix). The measurements below are kept for the record.

New targets on 842b0cb (sampled stacks, prologue's world): the submission thread is still the critical path, and it runs alone for ~380 ms a frame. It spends 29 % in Shadow::writing, 15 % in sync_heaps, 15 % in Batch::flush and 8.5 % in copy_mapped. The main recording thread spends 35 % in list::allocate_upload and 14 % on contended locks.

Main finding: the frame is bound by the submission thread. A context-switch profile (xperf) shows two phases taking turns. First, the title's five recording threads record for ~300 ms. Then queue::pump -> Host::execute runs alone at ~100 % of one core for ~400 ms while every other thread waits. Cutting work elsewhere (lock waits, heap syncs, resolution, the GPU) barely moved the frame time. Freeing that thread helped on the old base.

Commits

  1. GPU: release title-buffer copies off the submission thread (the gain). 17 % of the submission thread's time went to the driver freeing buffers that are no longer used: memory::Shared::rewrite drops the old page table's last references, then ID3D12Resource release, then amdxc64. Shadow::buffer is now released on a thread of its own. shadow::BUFFERS also becomes a RwLock, with a shared read path in find. It removes a lock convoy between the recording threads, but brought no measurable gain of its own.
  2. GPU (diagnostics): what heap syncs look at and make. Counters and samples for sync_heaps. They show that ~63 % of the slots made per frame are made null, and that ~12,000 slots a frame hold the title's own data (floats, index lists) rather than descriptors. The big shader-visible heap's memory is shared with other data.
  3. translate: name programs by the hash run logs; VICTORY_EMIT_ONLY. This is how the two costliest GPU pipelines were identified: they are XboxBvhBuilder.dll's, 51.6 ms per frame, ~40 % of GPU command time.

Measurements (300 s of the prologue's world, scripted camera loop)

Run mean ms/frame mean fps median fps
Base (FSR 0.5) 846 — 1.5
BVH builder skipped (VICTORY_SKIP_PIPELINES, image about the same) 705–759 (4 runs) 1.41–1.56 1.4–1.5
+ this branch's commit 1 647 1.69 1.6
New base 842b0cb (BVH skipped), without commit 1 750 1.38 1.4
New base 842b0cb (BVH skipped), with commit 1 799 1.34 1.3

On the old base: −24 % per frame since the base. With the BVH builder skipped, the GPU drops from 214 to 135 ms per frame, but the frame shortens by only ~110 ms, because the submission thread is the bound.

What did not help (measured, for the record)

  • SHADER_HEAPS as a RwLock: title wait 250 → 100–135 ms, but sync time ×3; no gain.
  • Diffing heap pages to skip unchanged slots: at most ~7 ms per frame (reading is only 6.7 ms of a ~40 ms sync).
  • The shadow::BUFFERS read-write lock on its own: within noise.

Next targets on the submission thread

  • sync_heaps (19 % of its time): mostly null views made for the title's own data.
  • Shadow::update / watch::take_split (22 % + 14 %): could run on more threads, since 13 cores sit idle.
  • Contended locks (14 %).

Test plan

🤖 Generated with Claude Code

CocoBeans64 and others added 4 commits November 26, 2026 00:24
A profile of the prologue's world (xperf, context switches and ready
events) shows the title's recording threads and the submission thread
(queue::pump -> Host::execute) taking turns: the submission thread runs
alone at ~100 % of a core for ~400 ms a frame while everything else
waits, so it is the frame's critical path. 17 % of its time was the
driver freeing the memory of host copies gone (memory::Shared::rewrite
dropping the old page table's last references -> ID3D12Resource release
-> amdxc64).

- `Shadow::buffer` is released by a thread of its own (`release_later`).
  A copy goes only once no submission holds it, and D3D12 objects are
  free-threaded.
- `shadow::BUFFERS` becomes a read-write lock: `find` looks buffers up
  shared and writes only to make a first copy. The title's five
  recording threads woke each other ~2,400 times a second on the mutex
  (no gain of its own, measured).

Bench (Series X, FSR 0.5, BVH builder skipped, 300 s of the prologue on
an RX 6800 XT / Ryzen 7 7800X3D, Windows 10 + Agility SDK): mean frame
647 ms against 705-759 ms over four reference runs, 1.69 fps mean
(1.41-1.56). victory-gpu shadow tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Counters per frame-rate line for `sync_heaps`, to find what its time
goes to:

- "heap syncs per frame": syncs, mapped pages, slots looked at, slots
  stale, time reading/comparing records and time making the stale ones.
- "stale slots per frame": made null, first made, the same view again
  (by content), another view; by kind.
- "made null per frame": zeroed records, old generations, anything else;
  time making null slots and views. Each call takes under a
  microsecond, so this split reads low (truncated to whole us).
- "unknown records per frame": records neither zero nor ours: how many
  repeat their bytes, become ours or zero when read again, look like a
  GPU address; their most frequent first dwords and a few samples.

In the prologue's world (Series X, FSR 0.5) a frame syncs ~19 times and
looks at ~590,000 slots, ~34,000 of them stale: 6.7 ms reading, ~36 ms
making. ~21,000 of those are made null: ~9,200 zeroed records, ~12,200
"unknown" records that are the title's own data (floats such as
0x3f800000, index lists), which shares the big shader-visible heap's
memory with descriptors in turn. Only ~0.5 % are the same view again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`run` names shaders by the blake3 of the container as the title passes
it (its own size), e.g. in VICTORY_GPU_TIMING's "GPU ... ms/frame"
lines; `translate --list` named them by file and offset only. Each
program's label now starts with that hash (`h<16 hex digits>`), so a
costly pipeline in a run can be found in the list (the two costliest
compute pipelines of the prologue's world, 51.6 ms/frame, are
XboxBvhBuilder.dll's).

VICTORY_EMIT_ONLY (comma-separated label substrings) limits
VICTORY_EMIT_DUMP to those programs, and dumped files keep the start of
the label, where the hash is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CocoBeans64
CocoBeans64 force-pushed the perf-submission-thread branch from 0f101be to 2295330 Compare November 25, 2026 23:29
@CocoBeans64 CocoBeans64 changed the title GPU: release title-buffer copies off the submission thread (-10 % per frame) + heap-sync diagnostics GPU: release title-buffer copies off the submission thread (unproven on upstream 842b0cb) + heap-sync diagnostics Nov 26, 2026
@AwkGrep256

AwkGrep256 commented Nov 26, 2026 •

Copy link
Copy Markdown

📊 Same picture on another machine: the frame is CPU-bound, and FSR barely helps

Thanks for the xperf breakdown. It matches what we just measured on avatarmanz/VIctory-7900XTX with FSR from Marvisak#1793 and frame generation (avatarmanz/VIctory-7900XTX#53):

Mode Rendered fps GPU time On screen
⚪ Title's own upscaler 18.4 — 18
🟢 FSR 1080p → 4K 19.7 — 20
🟢 FSR 1440p → 4K 20.0 — 20
🚀 + Frame Generation 3 19.9 — ~40
🚀 + Frame Generation 4.0.2 17.9 11–13 ms ~36
  • 🧮 GPU 11–13 ms of a ~50 ms frame: like your finding, the CPU side sets the pace, so render scale hardly matters (FSR at 1080p or 1440p is only +7–9 % over the title's own upscaler).
  • 🧵 That fork goes after the same thread you profiled: list calls recorded on eight threads of its own (VICTORY_THIN), submissions prepared on a separate thread and joined (VICTORY_ASYNC_SUBMIT, VICTORY_JOIN_PARTS). Its full mode reaches ~16 fps average on a 7900 XTX with 64 GB. It might be a useful comparison for your submission-thread profile.
  • 🚀 Frame generation sidesteps it for what's on screen: ~18–20 rendered becomes ~36–40 displayed, at little cost on the GPU, which is mostly idle anyway.

RX 9070 XT, Ryzen 7 9800X3D, 32 GB, Series X profile, play.ps1 -Safe (full mode pages on 32 GB).

This reverts commit e837b60.

On upstream 842b0cb the cost it moved is gone: a profile of the
prologue's world (xperf, sampled stacks) shows memory::prepare /
Shared::rewrite at 0.09 % of the process, against 17 % of the
submission thread on the old base (13f91ca), most likely since Marvisak#1865
writes the page tables directly. A control run gave 799 ms/frame with
the commit and 750 ms/frame without (one run each, noise ~5 %), so it
adds a thread and a ManuallyDrop for nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CocoBeans64 CocoBeans64 changed the title GPU: release title-buffer copies off the submission thread (unproven on upstream 842b0cb) + heap-sync diagnostics Diagnostics: heap-sync counters and run-hash shader labels (buffer-release change reverted) Nov 26, 2026
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.

2 participants