GPU: a list lends the host copy it read to its next reads of the texture (no shared lock or refcount per texture read; 5-thread draw −12 %, needs #3258) #3405
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3405
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3405"
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?
@KainanP on GitHub · 2026-11-26 22:32 UTC · original
KainanP:perf/read-copy-lent→main· +498 −33 · 5 files · 2 commits · openDepends on #3258 (this branch contains its commit
723d6d5c; review only the top commit0d7876f3). Part of the list-call scaling work in #2586.What it costs today
Each texture a draw reads (
draw::readable, shader-resource views) callsresource::host_copy: the title resource'shostmutex, then anArcclone and drop of the host copy. When several title threads record lists reading the same textures (the world's render threads do), every one of those writes the same two cache lines. On the list bench (6 table textures per draw) with the recommended stack (main + #1978 + #2821 + #3258 + #3274 + #3275 + rebased #1356), a per-call-site lock profile at 5 threads puts that mutex first: 6 takes per draw, 65 % of them contended, ~740 ns per draw spent there; every other lock on the path is list-local and uncontended.What changes
Resourcegetshost_generation: AtomicU64. Every write ofResource::host(made inhost(), given up inresource::give_up) now goes throughResource::set_host, which stores a generation no write ever stored before (a global counter, under thehostlock). It is 0 before the first write, and nothing at generation 0 is ever kept.HostListkeepsread_copies: per title texture, the generation andArc<HostTexture>it read.HostList::with_host_copy(resource, f)compares the resource's generation now (oneAcquireload of a word only those writes change) with the kept one; if equal it lends the list's ownArctof, with no shared lock and no refcount change. Otherwise it reads copy and generation together under thehostlock (resource::host_copy_at) and keeps them.draw::readableuses it for the upload check and the state transition. Nothing else changes.Why it is safe (no use-after-free, no stale copy)
Arcinread_copies. A copy replaced by a newer generation moves toread_copies.before, so it is not dropped. Both are cleared only inHostList::reset, which runs after the list's last submission finished (the same pointstatesdrops the copies it holds). A lent&Arcis borrowed under the list's own mutex, so it cannot be dropped whilefruns. A nested call fromfusestry_lockand falls back to the shared path, so it never deadlocks.evict) or made again, or a title texture released with another one made at the same object address, always has a generation different from any kept one. Generations come from one global counter and are written under thehostlock together with the value. A list therefore lends a copy only while it is still the texture's copy. Before this change,host_copycould also return a copy thatevictgave up a moment later (documented as a shortcut), so the race window is no wider.host_copyit replaces. A draw that names a released resource is undefined on both paths.Test
draw::tests::a_list_lends_a_read_copy_only_while_it_is_the_textures:made_copy(without the generation check the old one would be returned). The first copy stays alive while the list is open and is let go atreset.readableby a recorded, closed list is released by the title (Release) beforeexecute. The list still runs and reads its texels (64/255).Numbers
RTX 4060, release,
VICTORY_LIST_BENCH_SCALING=1(fork branch perf/list-call-bench). Median of 7 interleaved runs, stack + rebased #1356, with and without this commit:Caveat: a game was running in the foreground during these runs (CPU 46–69 % busy). Both columns are inflated by the same load: on a quiet machine the same stack measured ~1.4 µs / ~2.5 µs earlier. The ranges were 2943–3350 vs 2519–3143. The lock profile is the cleaner evidence: the
Resource::hostmutex goes from 6 takes and ~740 ns per draw (65 % contended) to ~0 takes per draw. No lock left on the 5-thread path is contended.Checks
cargo test -p victory-gpu --release --libdynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views: heap NumDescriptors assertion).heap_direct_texture_reads_mark_their_heap_indexskipped (access violation on main too).--features diagnostics,VICTORY_D3D12_WARP=1, serial): 249 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without--all-features: clean.cargo test -p xtask(policy): ok. Changed lines rustfmt-clean.Related: #3249 (targets: clones a texture only when a barrier is owed) touches
HostList::transition, not this path. #3288 would add a write ofResource::host; with this PR it should go throughset_host.AI use: written with Claude Code (Claude Opus 5.5); I reviewed the change, the safety argument and the measurements.
🤖 Generated with Claude Code
@Dukestar69 on GitHub · 2026-11-26 22:48 UTC · original · approved these changes
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 23 passed, 0 failed (a_list_lends_a_read_copy_only_while_it_is_the_textures,a_host_textures_kept_flags_give_what_its_description_does,a_texture_read_uploads_once_and_moves_as_a_read_by_resource).cargo test -p victory-gpu --lib resource:: -- --test-threads=1: 18 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 23:02 UTC · original · approved these changes
Reviewed
0d7876f3(which cleanly stacks on#3258/723d6d5cand merges ontomain63bcca43with zero conflicts).Verification
cargo xtask policy: 191 files ok;cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(both default and--features diagnostics): 0 warnings.draw::tests::,resource::tests::, andtexture::tests::passed on both a discrete NVIDIA RTX 5090 and WARP with--features diagnosticsandVICTORY_D3D12_DEBUG=1.Resource::hostincrates/victory-gpu/src/resource.rs: bothResource::host_at(resource.rs:1536) andgive_up(resource.rs:1787) go throughResource::set_host(resource.rs:1560), bumping the global monotonicHOST_GENERATIONS(starting at1) underself.host's lock withRelease/Acquireordering, while newly allocatedResourceinstances start at0(resource.rs:1837) so same-address reallocation cannot ABA-match a cached generation.VICTORY_D3D12_DEBUG=1):with_host_copyre-entrancy inside its own closure cleanly takes theWouldBlockfallback without deadlocking.Resourcerelease (via vtable slot0x10->resource_release) followed by confirmed same-addressResourcereallocation (aba_same_addr_reused = true) on the same openHostList: both draws read exact texels (0.1255and0.5020) with 0 Debug Layer errors, andlist.reset()drops the list'sby_texture/beforereferences cleanly.readablecalls) racing a dedicated eviction thread (1,096concurrent evictions in 32 ms on RTX 5090;964in 25 ms on WARP): 0 panics, 0 deadlocks, and 0 Debug Layer errors.Minor non-blocking note
a_list_lends_a_read_copy_only_while_it_is_the_textures(crates/victory-gpu/src/draw.rs:3026-3133),crate::object::release(...)only decrements the baseObjectrefcount without invokingresource_release(release_boxed::<Resource>), so theBox<Resource>is not actually freed in that test. Calling the resource's vtableReleaseslot (crate::object::slot::<extern "system" fn(This) -> u32>(obj, 0x10)(obj), as indraw.rs:4160) will genuinely exercise release and same-address reallocation.LGTM.
@Jackster on GitHub · 2026-11-26 23:10 UTC · original
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:63bcca4alone (it carries the #3258 changes it says it needs):cargo test -p victory-gpu --libgives 234 passed / 0 failed / 1 ignored (unpatched main: 231; +3), clippy clean.draw.rs,host.rs,list.rs,resource.rsandtexture.rs. So this is stacked on #3258, not additive to it; whoever lands second needs a rebase.draw::tests::a_list_lends_a_read_copy_only_while_it_is_the_textures; the other two names it adds come from #3258.Synthetic only. AI-assisted.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.