perf(hwrt): cache static clamped IBs, dedup sanitize state, and cut BLAS/TLAS overhead #4144
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!4144
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4144"
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?
@steven-seagull27 on GitHub · 2026-11-30 16:43 UTC · original
steven-seagull27:perf/hwrt-clamped-ib-and-tlas-cache→main· +963 −125 · 2 files · 1 commits · closed without mergingSummary
Builds on #3706 to reduce CPU contention,
VirtualQueryoverhead, and redundant GPU compute dispatches / D3D12 state binds across hardware DXR (VICTORY_HW_RT=1) BLAS build/refit batches, TLAS instance remapping, andRayQueryroot SRV bindings:Persistent fence-gated cache of clamped static
R32_UINTindex buffers (ClampedIbCache)R16_UINT/R32_UINTindex buffers on the GPU viaclamp_ib_psoso out-of-range indices degenerate in place without shiftingPrimitiveIndexorGeometryIndex. Previously, everyPERFORM_UPDATErefit re-ranshadow::find, allocated a transienttris * 12lease slice, dispatchedclamp_ib_pso, and cycled UAV/SRV barriers even when the underlying index buffer was immutable (!sh.written()).ClampedIbCache(64 MiB / 4096-entry LRU, trimming to a 75% watermark) plus intra-batchWork::batch_ibsdeduplication. Newly populatedDEFAULTbuffers transition once toNON_PIXEL_SHADER_RESOURCEatflush_blas_batchand become eligible for cross-list hits only afterClampedIbReadydrops past the populating command list's GPU fence.Weak<Shadow>and automatically self-evict (viaArc::ptr_eq-guarded removal) if the shadow buffer is dropped, written on the GPU, or taken over;title_memory_freedinvalidates freed[at, at + len)ranges and retires GPU resources outside write locks.validated_ibson initial non-written builds/rehydrates (bounded at 65,536 entries) and checksvb_shadow.left(vertex_buffer) >= exp_bytesdirectly before falling back toshadow::find.Sanitize compute root signature & PSO deduplication (
SanitizePso)None/ClampIb/CopyVb) across an entireblas_workchunk loop soSetComputeRootSignatureis issued at most once perblas_workcall andSetPipelineStateis issued only when switching betweenclamp_ib_psoandcopy_vb_pso.O(1)BlasLru&Backloghot-path operationsCopyonOwnedGeometryand updatesBlasLru::recipesin place (preserving non-update flags while strippingPERFORM_UPDATE) without heap reallocation when a refit's geometry count matches.BlasLru::wantedwith aHashSet<u64>(wanted_set) soBlasLru::completededuplicates evicted BLAS marks inO(1)instead of linearVec::containsscans.Backlogqueue entries with monotonic sequence numbers(key, seq)soBacklog::removebecomesO(1)(skipping stale entries lazily ontake/keysand compactingorderonly when stale slack exceeds2 * len + 64), replacing linearVecDeque::retainscans.Bounded CPU geometry decode memory queries
base_viheaders (meshlet_idis 11 bits) indecode_title_meshlet_iband computes the exact maximum(base_vi + i_loc)referenced bytrisbefore callingreadable_len, avoiding an unconditional 256 KiBVirtualQuerywalk pastvi_addr.title_readablechecks indecode_title_quant24_vbinto a singletitle_readable(vb_va - 0x20, vbytes + 0x20)call.Shared per-list TLAS remap uploads & lock-free root TLAS binding cache
plane_uploadBLAS remap hash table (acquire_blas_table) across consecutive TLAS builds recorded on the same(HostList, epoch)within a frame whenas_map_versionhas not changed, and maintains atomicas_map_len/waiting_len/evicted_lencounters so table sizing avoids lockingqueue,lru, andas_mapon every TLAS build.tlas_versioncounter inhwrtand caches resolved(console_va, host_gpu_va)pairs perSLOT_TLAS_BASE..=SLOT_TLAS_MAX(t230..t241) slot indraw::State(keyed by(HostList, epoch)andtlas_version, cleared onreset/clear_state/replay) so consecutive RT dispatches binding the same TLAS skipas_map.read()and duplicatelist.keepclones while preserving recording-epoch resource keep-alive invariants.Verification
cargo test -p victory-gpu --lib -- hwrt:: --test-threads=1(including new synthetic unit tests forBlasLruin-place refit updates &wanted_setdeduplication,BackloglazyO(1)removal & FIFO compaction,ClampedIbCachebyte/entry LRU eviction & range invalidation,SanitizePsobind suppression, andVirtualAllocpage-boundary meshlet IB decoding)cargo test -p victory-gpu --lib -- draw:: --test-threads=1(including synthetic unit tests for per-(HostList, epoch)/tlas_versionroot TLAS slot caching and state resets)cargo check -p victory-gpu --lib --features diagnosticscargo clippy -p victory-gpu --lib --testscargo run -p xtask -- policy@MrDenn on GitHub · 2026-11-30 23:30 UTC · original
Some in-game numbers for hardware RT's CPU side, in case they help prioritise. Included is one negative result: decoding the title's quant24 and meshlet geometry on the card.
Setup: RTX 5080 16 GB (driver 621.40), Ryzen 7 9700X, 32 GB DDR5-6400, Windows 11 24H2, v2026.11.30.03 release (
e1251c31, without this PR). Series X, native 1440p, DLSS Performance, no frame cap. Gameplay seconds only.RT is CPU-bound here, as a chain rather than one thread
VICTORY_HW_RT=1execute_blas_batch)Under load the CPU runs at ~5.37 GHz effective (close to max boost), with ~60 % of logical CPU busy and no thread above ~56 %. Rendering at 1080p instead of 1440p gained ~1 fps.
BLAS budget churn while driving
In a 14-minute session with more fast driving, the BLAS budget (1,492 MB, a tenth of the card capped at 1.5 GB) stayed full:
rebuilt after evictionstays small (31), so most of the churn is new geometry streaming in and old geometry being let go. The CPU cost doubles while that happens, and at the same time textures fall back to small levels for want of room. A larger budget isn't free on a 16 GB card, but cheaper rehydrates or a keep-alive for structures likely to be needed again might be worth a look.Things that did not help with RT on (same build, same settings)
VICTORY_ASYNC_SUBMIT=1VICTORY_THIN=1(with async)VICTORY_SUBMIT_SPLIT=1On the last one: I moved
decode_title_quant24_vband the rehydrate path ofdecode_title_meshlet_ibinto a compute pass besideSANITIZE_HLSL, with the same rules (sane_position/sane_triangle). The CPU then read only the 32-byte header and the meshlet headers, andshadow::find+refreshprovided the source. It built and the shaders compiled; in game,BLAS prepdidn't drop. My guess is that refreshing the raw buffers up to the card costs about what the decode did, so the decode arithmetic was never the expensive part. I can share the diff, but I wouldn't pursue it.A visual note
With hardware RT on, small pieces of geometry occasionally flicker or stretch into a large stray polygon for a moment, then disappear. It isn't frequent and doesn't break the game. I haven't isolated it yet.
Measurements from my own PC; the logs were read and this was written with an AI assistant (Claude).
e07cfb9123to22e26be04d@paales on GitHub · 2026-12-01 01:41 UTC · original
Written by 🤖:
Tested together with #4338, #4579 and #4171 on an RTX 5070 Ti with 12 cores (#4338). With
VICTORY_HW_RT=1the CPU is the limit: median frame 47.9 ms with the card 62 % busy.BLAS prepis about 75 ms a second; the submitting thread loses most to the buffer and texture refreshes (its waits for helpers inwide_each_scopedare 28 % of its time, 8 % without ray tracing), not to the structure code (fill_blas_table0.3 %). The cherry-pick onto #4338 and #4579 conflicts inHwRtManagerandtitle_memory_freed; both sides stay.@KruIN689 on GitHub · 2026-12-01 05:04 UTC · original
Independent test of this PR alone, hardware RT, while moving. So far it was only tested stacked with #4338/#4578/#4170.
Setup
22e26be0cherry-picked; it applies cleanly.VICTORY_HW_RT=1, Series X native 1440p.What I read from it
cargo test -p victory-gpu --lib hwrton the cherry-pick gives 24 passed.Limits
Tested with the help of Claude Code (Claude Opus 5.5).
22e26be04dto7317623344@trustno1-coder on GitHub · 2026-12-01 18:46 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed