Skip to content

GPU: async background worker for heap-indexed texture uploads (VICTORY_HEAP_WORKER=1) - #1007

Open
TG0000 wants to merge 3 commits into
fxceless:mainfrom
TG0000:pr/async-heap-worker
Open

TG0000 wants to merge 3 commits into
fxceless:mainfrom
TG0000:pr/async-heap-worker

Conversation

@TG0000

@TG0000 TG0000 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Moves heap-indexed texture creation and upload work off the recording/submission critical path onto a dedicated background worker thread (heap_worker.rs), gated behind VICTORY_HEAP_WORKER=1 (off by default).

Also includes two small hygiene commits on top of 0b0074e so Windows clippy and unit tests pass cleanly:

  • 5586210: fixes four existing Windows clippy warnings on main.
  • d3627f4: fixes a flaky indirect-budget test ordering assertion.
    (Happy to split those two commits out if you prefer.)

Measured Results (AMD Radeon RX 6800 16 GB, Adrenalin 26.11.2, Windows 11, Series X 1440p, full texture budget, 420 s warm runs)

Measured in ABBA order on a single build (worker ON vs OFF):

  • Heap pass on recording thread: 62-65 ms -> 16 ms (-62.9 +-24.1 ms paired within a single launch, n=13 pairs; passes cut short by budget: 0.73 -> 0.03).
  • Textures uploaded by first world bakes: 12,213 -> 26,787 (textures arrive earlier, not later).
  • Frame time / FPS: 4.54 / 4.72 FPS OFF (~212-220 ms mean) -> 4.96 / 5.47 FPS ON (~183-202 ms mean, ~162-202 ms median; +13% vs OFF, +17% vs 4.47 FPS baseline).
  • Stability: 0 device removals across all 420 s runs.

Verification

  • Windows clippy (both CI commands): 0 warnings.
  • Unit tests (victory-gpu 171 passed, victory-shader 215 passed, 0 failed).
  • AI-assisted implementation and testing.

TG0000 and others added 3 commits November 25, 2026 15:51
…EAP_WORKER=1, off)

The pass over textures picked by index asks what of each due texture is mapped, makes the host
texture, makes a staging buffer and records the copy, on whichever thread of the title records the
frame's first shader that picks textures by index. With a backlog that is up to 250 ms of a frame,
and the threads waiting for that list wait with it.

With VICTORY_HEAP_WORKER=1 (needs VICTORY_LATE_WAIT) the pass runs on a thread of its own and the
recording thread only wakes it. Its uploads go into host lists of our own, which the next late
submission runs ahead of the title's lists; a texture's host slot is given its view at that
submission, not before; the title's texture and heap are held while the worker uses them; the
uploads before the decoration bake stay on the recording thread.

Off by default; the numbers go in the pull request.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
On WARP the second group's draws can win the budget; the test asserts what holds either way,
that the record that is no draw runs empty.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@UwUCammie

Copy link
Copy Markdown

Tested the worker commit (233a65f) on RX 7900 XT (CachyOS Linux, Wine 11.22 + vkd3d-proton + RADV) with VICTORY_HEAP_WORKER=1 alongside VICTORY_RELAY=2 + VICTORY_LATE_WAIT=3 + VICTORY_INDIRECT_GATHER=1. Ran a full 480 s gameplay pass to frame 5100 with 0 device removals, 0 GPUVM faults, and the recording thread's heap-textures pass dropped down to 0.0 ms/frame (steady 8.5 fps / 116–117 ms median, 97 ms shortest).

@tippythetaidum

Copy link
Copy Markdown

Tested on an RTX 5080 16 GB (driver 621.14, Windows 11, Ryzen 7 9800X3D with 8 threads, Series X profile), in the prison opening.

Build: release build of main ca8829f with #24, #927, #823, #606, #1002, #907 and #834, plus this PR's 233a65f (it picked cleanly).

Two 600-second runs, one each, same switches (VICTORY_INDIRECT_WINDOW, COPY_PLAIN, JOIN_PARTS, BACK_OWN_VIEW, INDIRECT_GATHER and CARD_REHASH_RUNS, all =1), without and with VICTORY_HEAP_WORKER=1. Frame-rate lines from the first world frame on, about 92 per run:

median 25th percentile max
without 5.3 fps 2.3 fps 8.1 fps
with 5.6 fps 4.4 fps 7.0 fps

Most of the gain here is in the slow stretches: the slowest quarter of the frame lines went from 2.3 to 4.4 fps. No errors and no device loss in either run.

I haven't checked the picture with it yet, because these release builds didn't save frames. My next runs with it do save frames, and I'll add what they show.

AI-assisted (Claude Code, Claude Opus 5.5). Counts only, nothing from the game attached.

@tippythetaidum

Copy link
Copy Markdown

Picture follow-up to my numbers above: with VICTORY_HEAP_WORKER=1, the multicoloured square noise I'd been seeing on the escort guard's forearm in the prison corridor didn't show.

In an earlier run without it (a diagnostics build of a similar tree), the noise was on his forearm in three saved frames of the corridor walk (world frames +768, +864 and +960). In two release runs with it today, 60 saved frames from the yard through the counselor's office, his arms and hands are clean in every frame where they're in view, including the corridor (+960, +1056, +1632, +1824). That fits "a slot shows a texture only once its upload is submitted": the noise looked like a fresh texture in memory another one had used, shown before its upload.

The runs differ in more than this switch: release against diagnostics, and both of today's runs also have #1031, one of them with VICTORY_LEVELS_ON_DEMAND=1. So it's a consistent observation, not an A/B.

AI-assisted (Claude Code, Claude Opus 5.5). Descriptions only, nothing from the game attached.

dkdknight pushed a commit to dkdknight/victory-fork that referenced this pull request Nov 25, 2026
…x uploaded on a thread of their own (VICTORY_HEAP_WORKER=1, off)

Conflicts: both list helpers kept (defer_texture_upload and
refresh_textures_ahead); a staging texture keeps both its last change and
its ahead read, hashed when either says so; this branch's indirect budget
test, bench field and resource cfg kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ExoCalibra added a commit to ExoCalibra/victory-exo that referenced this pull request Nov 26, 2026
# Conflicts:
#	crates/victory-gpu/src/draw.rs
#	crates/victory-gpu/src/indirect.rs
#	crates/victory-gpu/src/resource.rs
@Exopus-0x65f7ad0

Copy link
Copy Markdown

Data from a profile, plus a small change that helped here. Setup: RTX 5060 Ti 8 GB, 16 GB RAM, Series S profile, opening cutscene.

What the profile showed: the victory-heap thread was idle about half of each frame (112 of 220 ms, in Condvar::wait inside worker). Over the same seconds, 20,000+ texture slots were due. The worker runs one pass per kick, and a kick comes once per frame. At 4 fps that is about 4 passes per second, and each pass stops at its time limit with slots left over.

Change (local tree, about 15 lines): when the pass leaves slots due, meaning it stopped on bytes or time or was handed a full 4,096, the worker puts the same heap back in job.heap (if no newer heap was handed meanwhile) and runs another pass straight away instead of waiting. The flag is set where the pass ends. VICTORY_HEAP_WORKER_CHAIN=0 turns it off.

// worker(), after the pass and the make_way loop
if chain_on() && crate::draw::BACKLOG_LEFT.load(Relaxed) {
    let mut next = lock(&job.heap);
    if next.is_none() {
        *next = Some(heap);
    }
}

Result:

Happy to open it as a PR stacked on this one if that is useful.

🤖 Generated with Claude Code

fxceless added a commit that referenced this pull request Nov 26, 2026
…CTORY_HEAP_WORKER=1, off by default; fork pull request #1007, its worker commit 233a65f)

The pass that uploads textures picked by index ran on whichever thread of the title recorded the frame's first shader that picks by index: here 62 ms a frame in the heavy area and 95 to 115 ms a frame on the earlier save (the frame line's heap pass figure, runs 301 and 306 to 308), with the threads waiting for that list waiting with it. With the switch the recording thread only wakes a worker; the worker records the uploads into lists of ours, which the next submission runs ahead of its own, and a slot is given its view at that submission, not before. Needs VICTORY_LATE_WAIT. The pull request's worker commit applied by a three-way merge; one more call site of ours (the marked heap pass) given the same change by hand. Its own test comes along. Clippy clean in both builds, 225 gpu tests pass one at a time. Not yet run in a game here; four testers ran it elsewhere (its thread), one on an NVIDIA card.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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