fix(gpu): keep placed alias views out of texture pool #550
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem#550
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@chefulano on GitHub · 2026-12-05 02:46 UTC · original
Problem
Placed texture views that alias a GPU render target or UAV (
alias_of(this).is_some()) havefills(&desc) == true, sohosted_for()could sub-allocate them from the CPU-filled texture pool, markhost.filled = true(making idle sweeps evict them as CPU-uploadable textures), or take CPU upload shortcuts (compare_source/ahead::take) in the bindless slot refresh path instead of runningreadable()/texture::alias(). On constrained 8 GiB VRAM / 16 GiB RAM AMD RDNA 3 (RX 7600M XT 8 GiB) setups where pool eviction andVICTORY_POOL_MOVErun aggressively, GPU-copied alias contents could be lost or skipped (causing ghosting or black sky/reflections).Change
hosted_for()passesallow_pool = !is_aliastohost_texture_in()and setshost.filled = can_pool_or_evict_as_title_filled(fills(&r.desc), is_alias)(also removing the now-unusedhost_texture/host_texture_aswrappers).copy_target(): Before callingwant_level(this, 0), if a placed alias copy target already holds a pooled, title-filled, or partial-mip (base > 0) copy (copy_target_needs_detach()), resetwanted = 0, unstage it, remove it fromsweep_members(), retire the oldMadeontoREPLACED, allocate a full-mip private non-pooled copy, and queue descriptor rebuilding viadescriptor::queue_texture_replaced()(drained indescriptor::make_waiting()right before submission with zero slot locks held;REPLACEDkeeps the retired copy alive for any in-flight lists). Non-alias callers followmain's exact path.readable():draw.rsaddsplan_bindless_slot()so placed aliases in the bindless pass runreadable()(schedulingtexture::alias()and shader-resource transitions) while skipping CPUcompare_source()and asyncahead::take().texture::alias()acquires the destination viaresource::copy_target(placed)and callslist.note_gpu_written(placed, None)on both direct-copy and buffer-mediated paths.Measured impact
Pure correctness fix; non-alias textures follow
main's exact path. Observed fixing missing alias contents on an earlier combined build running on an 8 GiB VRAM / 16 GiB RAM AMD RDNA 3 (RX 7600M XT 8 GiB) Linux host under RADV + vkd3d-proton; end-to-end GPU rendering was not re-run standalone onb581f7e.Verification
main(b581f7e). Recommended to merge ahead of the companion castable-alias and sweep/residency PRs, which touch adjacent lines inresource.rsandtexture.rs.cargo xtask policy:359 files ok;cargo test -p xtask -- policy::tests:7 passed, 0 failed.cargo check --locked --target x86_64-pc-windows-msvc -p victory-gpu -p victory --tests: 0 errors, 0 new warnings (only baselineroom_lately).5 passed, 0 failed):draw::tests::(including newbindless_alias_routes_through_readable_and_skips_cpu_upload),resource::tests::alias_views_are_not_pooled_or_evicted_as_title_filled(covering pooled, title-filled, andbase > 0partial-mip cases),descriptor::tests::placed_key_matches_only_inline_placed_records_at_address, anddescriptor::tests::queued_texture_replacements_coalesce_and_drain. Live D3D12 alias-copy rendering requires a D3D12 device.Pull request details or commits were not available from GitHub; kept as an issue.
github-bot referenced this issue2026-12-05 02:47:00 +00:00
github-bot referenced this issue2026-12-05 02:52:32 +00:00
github-bot referenced this issue2026-12-05 02:52:35 +00:00
@Kal0s-design on GitHub · 2026-12-05 03:36 UTC · original
Checked
65f3c84on native Windows (one NVIDIA desktop card plus WARP, didn't run the game).This is a default behaviour change, there is no switch. I confirmed it with a throwaway device test (reverted) that makes an R32_UINT UAV target and an R9G9B9E5 view placed at the same address, in both orders, and asks for the view's host copy, then calls copy_target on it. On main, both orders gave a pooled copy with filled set and the view in the sweep set, and copy_target kept that same copy. On this PR, target first gives a private copy with filled clear that stays out of the sweep set from the start. View first starts pooled and filled, then copy_target swaps it for a new private full-mip copy, queues exactly one (view, address, remake=true) entry, and a second copy_target call reuses that copy without queueing again. Same results with the debug layer on and on WARP.
Unit tests, cargo test -p victory-gpu --lib (skipping views_die_with_their_resource): 356 passed and 5 failed on the PR, 352 passed and the same 5 failed on main (indirect host_list_* x2, the two pipeline library loads, the flaky watch test). The 4 extra passes are the new tests. With the diagnostics feature and VICTORY_D3D12_DEBUG=1 it's 404 vs 400 with the same 5 failures. On WARP descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in also fails, but it fails the same way on main, so it isn't from this PR. clippy -p victory-gpu --all-targets gives the same warnings on both sides, and cargo check -p victory is clean apart from the existing room_lately warning.
Most of the protection against eviction comes from copy_destination, not from filled. take_idle and the pool move pick candidates by fills(&r.desc), copy_destination and host_wrote (resource.rs:2307-2313 and 2384-2391), not by host.filled. On main, alias() only called want_level, so an alias view never got copy_destination and could be let go or moved. Now alias() goes through copy_target (texture.rs:175), which sets it for good. Clearing host.filled (resource.rs:1724) mostly changes sweep set membership and the KINDS and census counters. That's fine, but the body makes it sound like filled is what keeps these out of eviction. Another side effect worth stating is that alias copies are now never idle-evicted at all. That's probably what you want for probes and the sky, but it is a memory change on the low-VRAM setups the body talks about.
note_gpu_written (texture.rs:318 and 354) does little by default. keep_gpu_written() falls back to placed_copied(), which is off unless VICTORY_PLACED_COPIED or VICTORY_KEEP_GPU_WRITTEN is set (texture.rs:1276), and the fresh copy from the detach isn't grown. So in the default config those two calls are close to a no-op.
The question I'd most like answered is about the descriptor refresh timing. make_waiting drains the queue right before the submission (descriptor.rs:1083) and rewrites the slots to the fresh copy at once (records.rs:850, descriptor/host.rs:2468 and 2495). main's own path for a replaced copy, texture_views_remade, waits until the submissions before it have finished (RESHOWN_AFTER, descriptor/host.rs:2420-2433), and the want_level doc says the old slots keep showing the old copy until the new one is filled. Here, a slot rewritten before the list that does the alias copy runs, or read by draws recorded earlier in that same list, sees the new copy before anything has been copied into it. Since the old copy held title-memory bytes anyway, that's at most one frame of wrong content, but I'd like to know whether skipping the wait was deliberate. texture_replaced also calls host::moved(start), so the placed slots get marked due again through the existing path as well. That looks harmless, just a double refresh.
Lock order looks fine to me. copy_target takes made, then unstage, sweep_members and REPLACED, which is the same order want_level uses (resource.rs:1415-1427). queue_texture_replaced only runs after made is dropped (resource.rs:2996-2998). texture_replaced lets go of the views read lock before it takes the record shard locks and the per-slot made locks, and refresh_placed_at lets go of placed before it locks slots. The key decoding in is_placed_key_at (descriptor.rs:732) matches kind_words/key_of. Table generations stay below the kind bits, and placed addresses fit the 40 bits. The full key scan in refresh_texture (records.rs:870-878) runs once per detached view, which is only the view-first case, so the cost seems acceptable. forget also drops queued entries for a released resource (descriptor.rs:1264), which is good.
The bindless change in draw.rs:4061-4072 and plan_bindless_slot (draw.rs:6465) does what the body says. An alias view no longer stops at compare_source "same" and always reaches readable(), which calls texture::alias. That means one alias copy per bindless pass per slot. I think that's right because the GPU rewrites the source, I'm just mentioning the cost.
Compared with #551, the shared helpers match. The descriptor/host.rs refresh_slot/refresh_placed_at hunk and the records.rs refresh_texture hunk are identical, and in descriptor.rs the only differences are the doc comment on the queue and two test comments. A trial merge of the two branches still conflicts in descriptor.rs (comments only), in resource.rs (hosted_for, copy_target and the test module) and in texture.rs (the top of alias(), where #551 adds the castable early return before want_level). So the helper part of a rebase is trivial, but the resource.rs and texture.rs parts need a real merge.
The body says the observed fix came from an earlier combined build on another driver stack and wasn't re-run on
b581f7e. I couldn't confirm the visual fix either.Not tested: the game, any visual result, an actual descriptor slot mirroring the view before and after the refresh (I read that path but didn't exercise it with a live slot), the other copy_target callers in list.rs (956, 1057, 1395) that could now hit the detach if a title copy ever targets an alias view, AMD or vkd3d-proton, and memory behaviour under pressure.
AI-assisted: yes
@t-jonesy on GitHub · 2026-12-05 14:19 UTC · original
We hit what looks like the same bug independently, on a 16 GB card, so it is not only a low-VRAM problem. Here is our root cause and data, in case it helps the review.
Setup: RX 9070 XT 16 GB, game 1.0.2.1, Series X,
VICTORY_POOL_MOVE=1, with the card at about 94% of its budget during load-in.Symptom: a frozen picture of the load-in scene over the live one. It shows behind the phone (the apartment instead of the street) and as a "ghost" over opaque surfaces. It stays for the whole session.
Cause, as we traced it. The DOF chain's half-size scene:
Under load-in pressure,
move_out(POOL_MOVE) let go of that view's host copy when its texture block was drained. The copy was placed and title-filled, and neitherhost_wrotenorcopy_destination, becausealias()set neither. The nextalias()made a new host copy and copied into it.But the slot the draws read was a records (canon) slot. Canon slots are made again only on a fresh record, or through
levels_changed_afterwhen a copy grows, and alias copies trigger neither. So the slot kept showing the old host copy, holding the load-in frame, for the rest of the session. The alias lookups and copies themselves were fine throughout: we had counters on lookups and copies, and they never moved in ghost runs. What was wrong was which host copy the slot showed.Evidence that the move is the trigger:
VICTORY_POOL_MOVE=0alone avoids it.Our fix (fork only,
VICTORY_PLACED_REFRESH) has two halves:alias()marks the view a copy destination, so pool moves and the idle sweep leave its host copy alone. This is the same as yourcopy_targetchange, and as Kal0s says, it is the part that actually protects it.With it, the user's 8-minute drive had 96 "stale placed views" lines, every one with 0 stale and 0 slots showing another copy, despite 3 pool moves. The phone backdrop was correct.
On the refresh timing Kal0s asked about. We hit the same question and chose to wait:
list.defer_hoston the list that does the alias copy into the new host copy, recording that submission's number.texture_slots_flipmakes the slot from its record only oncehost::submissions()says that submission has finished. That is the same pattern as main'sRESHOWN_AFTERfortexture_views_remade.The cost is that the slot is up to one submission late in showing the live copy. That is harmless, since the old copy was already stale. In #550's view-first detach path, deferring the
queue_texture_replaceddrain to "after the next list that copies into the new copy has finished" would avoid the empty frame Kal0s describes. TheREPLACEDentry already keeps the old copy alive for that long.Two smaller notes from our tracing:
records.rsrefresh_texturepart of #550 is the part that reaches it.@chefulano on GitHub · 2026-12-05 20:22 UTC · original
Opened follow-up PR #623 (
fix(gpu): defer view-first alias descriptor rewrite until copy finishes) implementing the deferredRESHOWN_AFTER-style descriptor rewrite recommended by @Kal0s-design and @t-jonesy.7/14ghosted with a pool move during load-in vs0/28without, Pass 2668's R9G9B9E5 canon slot, and0stale across an 8-minute drive with 3 pool moves) confirms the samecopy_destination+records::refresh_textureroot cause beyond 8 GiB cards.copy_destinationvsfilled: Confirmed — eviction and pool-move protection come fromcopy_destinationset bycopy_target(), while clearinghost.filledkeeps target-first alias views out ofsweep_members()and title-filled census counters (meaning alias copies are not idle-evicted). For theR32/R9G9B9E5probes and sky aliases,#551removes the duplicate allocation entirely.note_gpu_writtenand bindless cost: Agreed —note_gpu_writtenkeeps parity whenVICTORY_PLACED_COPIEDorVICTORY_KEEP_GPU_WRITTENis enabled, and routing bindless alias slots throughreadable()is required because the GPU rewrites the source.RESHOWN_AFTER): Skipping the submission wait in#550was deliberate to keep the initial fix small (accepting up to one uncopied frame in view-first order). PR #623 now defers view-first descriptor rewrites viaqueue_texture_replaced_after+list.defer_hostuntil the copy submission finishes, with an RAII fallback to immediate refresh on early returns.github-bot referenced this issue2026-12-06 00:27:01 +00:00