perf(gpu): split VIEW_SHAPES lock, O(1) FxHashMap, and forget() read-check in descriptor.rs #666
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/666"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Capt-Speed on 2026-11-28T03:07:42Z.
Summary
Single-file lock-contention and lookup optimization in
crates/victory-gpu/src/descriptor.rs(zero new crate dependencies, zero shader-cache impact):VIEW_SHAPESout of the globalVIEWSRwLock: Placed-view shapes (shapes+shape_index) are append-only and read heavily across concurrent recording threads. Moving them to their ownVIEW_SHAPESRwLockstops frequentPLACEDlookups from blocking behindVIEWSinsertions andforget(resource)writes.BTreeMapwith a zero-dependency 64-bitFxHasherHashMap(FastMap) forViews::index,Views::by_resource, andViewShapes::shape_index, reducing lock hold times fromO(log n)comparisons over large view structs toO(1).forget(resource): checkviews_read().by_resource.contains_key(&resource)before taking the exclusive write lock, avoiding unnecessary write-lock stalls when releasing resources that had no registered views.All existing
#58placed-view padding clearing andownerlesscap behavior are preserved unchanged.Why
Even after
#58eliminated placed-view padding leaks,VIEWSstill guarded both placed-shape lookups and resource view registration/release under one process-wideRwLockbacked byBTreeMap. In heavy outdoor scenes (7,000–10,000+draws/frame),the views' lockwait still averaged ~38–40 msper 5-second interval (with spikes up to147 ms).Measurements
Tested on Ryzen 7 9800X3D + NVIDIA RTX 5090 D (32 GB), Windows 11,
--release, Series X 4K (3840x2160), DLSS Balanced (Preset K), DLSS Frame Generation 4x, Jason's House outdoor save (#573), built froma4d05e7(which already includes#58):VICTORY_*switches identical between baseline (main) and patched (pr-view-shapes).victory.exepath before launch (shared NVIDIA DXCache;4,010gameplay pipelines pre-warmed viavictory warm --used+25,758shaders pre-translated).VICTORY_KEYS_FILEcamera/walk sequence.1. Direct lock contention (
the views' lock)maina4d05e7)VIEW_SHAPES+FastMap)36×5svs33×5s)40.5 ms / 5s(total1,458 ms, max147 ms)20.0 ms / 5s(total661 ms, max83 ms)-50.6%20×5s= 100 s)38.3 ms / 5s(total766 ms, max96 ms)18.4 ms / 5s(total369 ms, max83 ms)-52.0%(Control check: a 3rd run on the same warm
36 MBhost-pipelines.binwithout this patch still showed29.9 ms / 5swarm /35.2 ms / 5sfullviews' lockwait, confirming the ~50% lock reduction is from this change rather than cache warmth.)2. Gameplay frame time & native FPS (strictly filtered clean ticks)
gpu < 1 ms, no library save within±10 s)main)VIEW_SHAPES+FastMap)7,513vs7,517draws;n=15vsn=19)20.15 FPS/51.1 ms(med18.60)21.78 FPS/47.7 ms(med19.70)+8.1% FPS/-3.4 ms(-6.7%)draws >= 9,000(avg9,642vs9,542;n=8vsn=11)18.16 FPS/55.3 ms(max62.6 ms)19.06 FPS/52.5 ms(max57.4 ms)+5.0% FPS/-2.8 ms(-5.1%)7,000–8,999(n=2vsn=3)17.60 FPS/56.9 ms18.77 FPS/53.4 ms+6.6% FPS/-3.5 ms(-6.2%)Validation
main(8fc2254): 1 file changed (crates/victory-gpu/src/descriptor.rs,+132/-34).cargo test --lib -p victory-gpu descriptor:62 passed; 0 failed; 1 ignored(includingownerless_entries_are_capped,buffer_views_differing_in_padding_are_one_shape_and_offsets_stay_apart,views_at_new_addresses_add_no_entries,views_die_with_their_resource).--features diagnosticsbuilds.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-28T05:37:44Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090):
cargo test -p victory-gpu --lib descriptor::passed (62/62) on RTX 5090cargo xtask policypassed (294 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T06:14:33Z.
Tested this PR in a controlled 20-minute 3D A/B run on Windows 11 — PASS (clean stability + lower
Prep/heaptime on >=4k draw workloads, 0 regressions).Setup
tearing=true), default4 MiBwindows,VICTORY_GPU_BCPACK=0,VICTORY_WAIT_RESIDENT=0,VICTORY_TEXTURE_ROOM_PERCENT=70,VICTORY_LAND_SKIP=1.v2026.11.27.10(8fc2254) + AVX2/ThinLTO + PR #516 + PR #340 + PR #81 (d354ec4). PR #666 applied cleanly with zero conflicts.cargo test --locked -p victory-gpu --lib -- descriptor:: --test-threads=1(VICTORY_D3D12_WARP=1) — 64/64 passed (0.84 s).20-Minute 3D A/B Results (Strict 3D-only, Draw-Count-Matched)
d354ec4, 20m)0 / 0 / 00 / 0 / 0hw.csv)325 / 327(99.4%)316 / 316(100.0%)100%1 / 1 / 10 / 2 / 00spikes >=500ms2789.9 ms397.9 msn=162 / 172)13.7p50 /13.68mean (Prep 59.5 ms)13.4p50 /13.67mean (Prep 57.9 ms)Prep -1.6 msframe_times(1s lines)65.0med /86.1p95 /98.3p99 ms65.4med /87.5p95 /101.0p99 msn=103 / 105)17.70p50 /17.20mean (Prep 44.7)17.00p50 /17.03mean (Prep 47.6)n=57 / 63)12.70p50 /12.95mean (Prep 64.0,heap 14.5)12.50p50 /13.34mean (Prep 58.2,heap 12.5)+3.0%,Prep -5.8 msn=24 / 26)10.75p50 (Prep 75.9,heap 14.7)10.25p50 (Prep 74.6,heap 10.8)heap -3.9 ms(copiesslightly higher in late streaming)n=3 / 3)8.80p50 (Prep 96.0 ms)9.30p50 (Prep 81.8 ms)+5.7%,Prep -14.2 msTakeaways
views_kept()takesviews_read()thenshapes_read(); no other path nests both locks).0rendering anomalies,100%window responsiveness,0frames >=500 ms, and consistentPrep/heapreductions on medium-to-heavy draw-count workloads (4k+draws/frame). Overall FPS stays mostly flat because CPU copy work (copies 30–52 ms) remains the dominant bottleneck on this 8C/16T CPU.