gpu/heap_worker: add race-safe opt-in VICTORY_HEAP_WORKER #720
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!720
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-720"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@mint17 on GitHub · 2026-11-28 04:23 UTC · original
mint17:feat/heap-worker-race-safe→main· +1171 −93 · 8 files · 1 commits · openPorts the opt-in
VICTORY_HEAP_WORKER=1background texture upload worker (off by default and gated onhost::late()) intoVIctory-NVIDIAwhile closing the descriptor-publication TOCTOU race and preserving bake, residency, prelude-upload, and relay guards (zero merge conflict with #693 or #704).Changes
victory-heapworker (heap_worker.rs): Opt-in viaVICTORY_HEAP_WORKER=1(off by default), 128 MiB / 80 ms batch flush, fast-core pinning (cores::keep_on_fast_cores),AtomicUsizeurgent waiter guard with RAII decrement,Ready.list: Option<HostList>sosame-only batches publish cleanly without allocating an empty list, plus splittake_ready_for_late()anddrain_for_bake(gpu)(settling in-flight GPU work viasettle_for_fence()even on list-less batches).descriptor/host.rs): Refactorspublish_uploaded_slotaroundpublish_uploaded_slot_with(index, handle, key, ...)which re-verifiesrecord_key(handle) == keyunderself.made.lock(index)and resolvesViewstrictly fromkey(view_at) without re-readinghandleor callingmirror(). Key-pins flip helpers (texture_slot_flip,texture_slot_show_after,show_later,texture_slot_show_ahead,mirror_after,flip), fixes the latentnote_bufferre-queue loop with a RAIIPublishingGuardchecked inqueue_texture(), restoresquick_isordering, and preservesVICTORY_SHOW_AFTER=1,VICTORY_SHOW_NEW_LATER=1, andVICTORY_HELD_LEVELS=1shows_othermip-upgrade deferral inpublish_for_late().resource.rs,draw.rs): Addsresource::hold(reusing existingobject::add_ref_aliveandresource::Held) to pin live texture objects across worker execution includingState::card_accounting; preservesTells/Told,-> boolbake return,bring_bake_sources,is_aliased, and placed RT/DS/UAV publication on the worker path.VICTORY_JOIN_PARTS,VICTORY_PRELUDE_UPLOADS, &VICTORY_TEXTURE_ONCEcompatibility (host.rs,list.rs,texture.rs): Hookstake_ready_for_late()inHost::send_late()viaprepend_ahead_order()so joined-part split indices shift cleanly; addsStaging::refresh_ahead()preservingVICTORY_TEXTURE_ONCE=1,VICTORY_TEXTURE_GUARD=0, andVICTORY_PRELUDE_UPLOADS=1.Verification
cargo test --locked -p victory-gpu --lib -- publish_rejects_slot_replaced_between_reads published_slot_stays_out_of_texture_queue publish_for_late_ prepend_ahead_lists_shifts_join_parts urgent_stops_worker_and_ready_drains_cleanly descriptor::host::tests -- --test-threads=1(53 passed, 0 failed) and--features diagnostics(6 passed, 0 failed):descriptor::host::bake_flip_tests::publish_rejects_slot_replaced_between_readsdescriptor::host::bake_flip_tests::published_slot_stays_out_of_texture_queuedescriptor::host::bake_flip_tests::publish_for_late_same_after_combines_show_after_and_new_laterdescriptor::host::bake_flip_tests::publish_for_late_defers_shows_other_mip_upgradehost::submission_tests::prepend_ahead_lists_shifts_join_partsheap_worker::tests::urgent_stops_worker_and_ready_drains_cleanly--all-features) andcargo test --locked -p xtaskpassed (6 passed, 0 failed, including asset policy).@Dukestar69 on GitHub · 2026-11-28 04:46 UTC · original · approved these changes
LGTM — verified on Windows (RTX 5090):
cargo test -p victory-gpu --lib heap_worker::(1/1) anddescriptor::(66/66, including all 4 newbake_flip_tests::) passed on RTX 5090cargo xtask policypassed (295 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@nick0451 on GitHub · 2026-11-28 17:24 UTC · original
A smoke test only: the scene barely reaches this path.
RTX 3090 24 GB (driver 610.88), i9-14900K, 32 GB, Windows 11. A release build of this PR merged onto main at
63b902f. Series S, DLSS Performance, frame generation off. Every run used the same frozen save, outdoors on a balcony by the water (about 5,900 draws a frame), standing still. One warm-up start per build, then main and four PR builds were run in turn, three rounds each. Each run is 40 s to settle, 60 s measured, then a screenshot. An A/A run of main against itself in this setup differs by 2-3%.VICTORY_HEAP_WORKER=1: the worker's line reads0.0 ms at worka frame, 0-0.2 lists. Standing still, almost nothing new streams in, so the worker is idle.ERRORline.cargo test -p victory-gpu --lib: 459 passed (the 5 new tests included).A real test needs movement or a scene change that streams textures; I'll add one when I can drive one repeatably.
Tested with an AI assistant (Claude Code); results are from this PC.
@paales on GitHub · 2026-11-30 20:51 UTC · original
Written by 🤖:
In-game numbers for this PR. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Each run: a new game (settings save, no story save), one A press, the first cutscene for 60 s from its first frame. On this PC the same build's submitting thread took 24 ms a frame in one run and 35 ms in another half an hour later, so only large differences count.
I merged it by hand onto
main84bd61e2with #3918, #1727, #3553, #3043, #4207 and #4138: branchheap-workeron paales/VIctory-NVIDIA. There were 18 conflict blocks indescriptor/host.rs,draw.rs,texture.rs,host.rsandlib.rs.mainreads the slot's record once too now. The merge keeps:is_textureand theresource[0] != 1guard, withheldtaken from this PR'srecord;writes_since), with this PR'sstale_aheadadded to the turn check;queue_texture_inner(…, None)where this PR re-queues (queue_textureis test-only inmainnow);seed_pending(new inmain) on the worker's list when the target isAhead.cargo test -p victory-gpu --lib -- descriptor::host heap_worker prepend_ahead draw:: texture::: 158 passed, 0 failed.The same build, back to back on an idle PC:
VICTORY_HEAP_WORKER=0VICTORY_HEAP_WORKER=1The worker line said 5 to 6 ms a frame of its own work, about 55 slots shown a frame, none left to the submission. In the first 5 s of the scene, textures were 0.4 to 5.9 frames late with the worker, against 10 to 16 without it. Two runs on a busier PC were slower with the worker (the submitting thread 32 and 41 ms a frame), so a busy CPU can take the gain away. No crash, and nothing wrong in captures every 250 ms. I play with it on.
@paales on GitHub · 2026-11-30 22:38 UTC · original
Written by 🤖:
A follow-up with this PR in my build: with the pass on the worker thread, a larger pass budget fixes the missing textures at cuts.
Same PC (RTX 5070 Ti 16 GB, Ryzen 9 5900X), Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Scene: a story save that loads into a mission cutscene in the city; A held at 35 s skips the interview into a montage of quick cuts (an airfield, a beach, a yard, a whale statue, a bridge). Play sets
VICTORY_TEXSPK_PASS_MS=8, doubled to 16 on this card while it has room.VICTORY_TEXSPK_PASS_MS=8VICTORY_TEXSPK_PASS_MS=24The run with 24 ms also had
VICTORY_WAIT_SPIN=300,VICTORY_WIDE_SPIN=100andVICTORY_WIDE_THREADS=12; those touch the refreshes, not the texture pass. With 8 ms the worker worked 9 to 14 ms a frame and 181 of 228 passes stopped at their time, while up to 18,104 slots were due. On screen with 8 ms: the beach people without skin textures, a yard white and gray, and the whale statue gray for 1.6 s after its cut. With 24 ms all of them are textured at their cuts.Before this PR, 24 ms on the recording thread made the frames slower (median 53 against 39 ms). With the worker, a default of about 24 ms seems right when
VICTORY_HEAP_WORKER=1.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.