perf: texture reads ask the texture, not process-wide tables under a lock #444
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!444
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-444"
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 18:53 UTC · original
KainanP:perf/texture-read-locks→main· +379 −17 · 3 files · 1 commits · openPort of the idea of Marvisak/VIctory#3274 (mine) to this tree. There the contended lock was
TEXTURES_ATinalias_source; on Vice-Tay a draw's texture read still takes up to four process-wide mutexes that every recording thread shares (and, with the launcher'sVICTORY_THIN=1, all eight translating threads), so I applied the same "ask the texture, not the shared table" approach to each.The problem
Per texture a draw reads through a view (
draw::readable):PLACED_TEXTURESresource::texture_at(viadescriptor::host::placed_texture)BTreeMaplookup keyed by address and 14 wordsTARGETS_ATresource::alias_ofHOST_WRITTENtexture::upload_fromSTAGINGtexture::staged_frominupload_fromThe change
PLACED_TEXTURESon this base, so what a thread found holds.alias_of: a texture keeps its "no target at my memory" answer together with the change count of its memory's bucket (1,024 counters by 64 KiB block, bumped underTARGETS_AT's lock when a target enters the table). While the count is unchanged the answer stands without the lock; a target leaving the table can't make "none" wrong. A texture that has a target is looked up as before.STAGING's lock wherever the table gains or loses the entry:staging,unstage, the idle sweep;forgetruns as the texture goes).upload_fromreads them without the locks.texture_atkept itsrawdescription only in diagnostics builds; it is now always kept (the per-thread slots are keyed by it).Same answers as the locked lookups; a change racing a read is the same race as one landing right after the locked lookup returned. The tables stay for every other reader.
Measured
List bench of #441, draw sequence (root CBV, 4 root constants, index buffer, indexed draw reading six textures), 1 and 5 threads at once, each thread its own list, all reading the same textures. Best of 5 × 20,000 draws per thread; 7 runs per build interleaved, median [min–max]. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile. Quiet machine: no game running, Windows reported 0–31 % CPU load around the runs (mostly under 16 %).
ns a draw, per thread:
So on five threads: −18 % alone (−35 % with placed views), −18 % on top of #443 (−35 % with placed views). Five threads now cost about 2.0× one thread (1.8× with placed views), against 2.4× (2.8×) on main.
Tests
New,
texture/read_marks_tests.rs:a_textures_staged_level_follows_its_staging_buffer: made by the first upload, gone when the buffer is let go, equal to the table's answer each time.a_texture_the_host_wrote_is_marked_and_not_uploaded.a_texture_read_again_takes_neither_tables_lock: a read again in a list, from another first level, finishes while another thread holdsHOST_WRITTENandSTAGING.a_placed_texture_finds_a_target_made_at_its_memory_later: "none" kept (and given while another thread holdsTARGETS_AT), then a render target made at the same memory is found, then "none" once it is released.placed_textures_found_again_are_the_tables: same resource each time (filler words ignored as before), found again while another thread holdsPLACED_TEXTURES.Checked against mutations on this base: without the bump on a target's entry, without the reset in
unstage, or withupload_fromaskingSTAGINGagain, the matching test fails (3 of 5 fail in that build; the other two pin behaviour).cargo test -p victory-gpu --release --lib, one thread: RTX 4060 Laptop 426 passed (main 421); with #441/#443 too, Intel UHD (a78b,VICTORY_D3D12_ADAPTER=Intel) 428 passed (main 421) and WARP (--features diagnostics,VICTORY_D3D12_WARP=1) the same single failure as main (timeline::report::tests::real_waits_are_recorded_with_who_ended_them). Clippy (--all-targets, with and withoutdiagnostics): only main's warning.cargo xtask policyok, ruff clean.What this does not show
No in-game numbers: I don't run the title here. How much it matters depends on how many threads translate at once and how many placed, title-filled textures each draw reads; in the bench all five threads read the same six. Please A/B it in game, ideally with #443 and
VICTORY_THIN=1(eight translating threads).Memory: about 18 KB per thread that reads placed views (256 slots), 4 KB of counters, 12 bytes per title resource.
Overlaps
git merge-treeagainst the open PRs that touchthird_party/victoryand merge with main: no conflict. #441 and #443 merge with this in any order (built and tested together).Ideas credited: caching lookups that title threads repeat was also the approach of wbkepler's Marvisak/VIctory#1356 (per-HostList VA/view caches), and moving title-thread lookups off shared mutexes the aim of 0xkn0wh3r3's Marvisak/VIctory#2821. No code is taken from either.
AI use: Claude Code (Claude Opus 5.5) ported the change, wrote the tests, ran the measurements and drafted this description.
🤖 Generated with Claude Code
e1c09d8609to0ff5f10084@KainanP on GitHub · 2026-11-26 20:21 UTC · original
Re-ported onto the combined base (#409) and force-pushed: the same four shared locks are on a texture read there. List bench of #441, median of 7 interleaved runs, RTX 4060 Laptop, draw sequence on 5 threads: 5597 → 4919 ns alone (placed views 5192 → 3345, tuned set 3306 → 2704), and with #443 3955 ns (placed 2805, tuned 2125). The new tests hold each table's lock on one thread and read on another; with main's locked lookups they fail. Description updated.
AI use: Claude Code (Claude Opus 5.5).
0ff5f10084to4ede49b37e@KainanP on GitHub · 2026-11-26 20:46 UTC · original
Main reverted #409 (#452), so this is back to the Neptune-base version measured in the original body, rebased onto
15024d5(RTX: its tests pass, and the suite gives the same results as before). The combined-base port is kept on branchperf/texture-read-locks-combinedfor when it returns.AI use: Claude Code (Claude Opus 5.5).
4ede49b37etoe6e7c9e983@KainanP on GitHub · 2026-11-26 23:48 UTC · original
Re-ported onto the Vice-Tay base (#454): all four shared locks of a texture read are still there on that base. On
b6d86cf8(list bench of #441, quiet machine), draw sequence on five threads 3267 → 2689 ns alone (placed views 4315 → 2796), 2156 (2347) with #443. Suites on RTX, Intel UHD and WARP: same results as main; the new tests fail under the matching mutations. Description updated; the Neptune version is onperf/texture-read-locks-neptune.AI use: Claude Code (Claude Opus 5.5).
@pepezin-ai on GitHub · 2026-11-27 02:28 UTC · original
A combined data point that may help with merging these, measured on a machine at the 16-thread threshold.
Machine: Ryzen 7 5700X 8C/16T, 32 GB RAM, RTX 5070 12 GB, Windows 11.
anyxboxx runwith its default settings onmainb62053f,VICTORY_OUTPUT=1920x1080, Series X, warm cache, same save and the same opening scene of it (letterboxed, ~7,000 draws a frame), 90 s after pipelines reached 0, one run each:mainb62053fmain+ #444 #446 #451 #456 #457 #458 #465 #466All eight merged cleanly on top of
b62053f(only README conflicts on our side). No device loss, no new picture faults spotted in screenshots. I cannot say which PR carries most of the gain; happy to run single-PR A/B runs if that helps.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.