fix(water,shaders) & perf(gpu,hle): fix water black squares and broad RAM/CPU/GPU optimizations #408
No reviewers
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/gamingwithhomie--larp!408
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-408"
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?
@ZerefDragnee1l on GitHub · 2026-12-06 00:18 UTC · original
ZerefDragnee1l:fix/water-black-squares-and-perf-optimizations→main· +4376 −1743 · 68 files · 5 commits · closed without mergingSummary
This PR combines fixes for black squares on water, targeted replacement compute shader correctness/performance fixes, and broad RAM, CPU, GPU, DirectStorage, audio, input, and build optimizations rebased cleanly onto
main(d2a79dd).shaders/replace/,crates/larp-shader,crates/larp-gpu,crates/larp-hle,crates/larp-formats,crates/larp-loader,crates/larp-game,crates/larp-pipeline,apps/larp,Cargo.toml, anddocs/.blobs::name),VICBLOB1headers, andpipeline_cache/blobs/paths are unchanged, so existing host driver pipeline blobs continue to load from disk without recompilation (only shaders whose translated DXIL actually changes from the water/shader bugfixes generate new DXIL keys).1. Water Black Squares Fixes
Root causes identified across fog/transmission compute shaders, translator LDS synchronization, NIS linear HDR luminance, and D3D12 copyback transitions:
6871d6e4,a10179ab,926c46ba): Guardedlog2(max(..., ...)), filtered NaN/non-finite lanes beforeWaveActiveSum/WaveActiveCountBits, clampedz/topslice bounds and cluster lookup (max(d514, 1u) - 1u), sanitizedaS/aTwith HLSL-2021select(), and gatedrun_copyLDSInterlockedMin/InterlockedMaxongo.07fb4c72,d3c33084): Guardedw > x && h > yaround mask evaluation /InterlockedOrin07fb4c72and clampedfx1/fy1ind3c33084.crates/larp-shader): Updatedlds_meetingsinemit/lower.rsto also synchronize overlapping plain (ds_write*) + atomic DS writes, and addedCS_TV_Tiled(0x5dc3b25986622949),CS_AlphaTransmissionDepthTileGenerationMip1(0x5c6224a6bc3a4066), andCS_AlphaTransmissionDepthTileGenerationMip25(0x9bdd33d77fb8ca0f) toidle_lds_reads.rs.NIS_Scaler.h): Clamped thegetYdot product insidesqrt(max(..., NVF(0.0f)))underNIS_HDR_MODE_LINEAR.barriers.rs,copyback.rs): AddedLAYOUT_DIRECT_UNORDERED_ACCESS/LAYOUT_DIRECT_SHADER_RESOURCEhandling and emitted aGlobalSYNC_ALL -> SYNC_COPY(ACCESS_COMMON -> ACCESS_COMMON) barrier incopyback::behindwhen sources transition fromCOMMON.2. Replacement Shader Fixes & Wave32 Optimizations
07c93bfb(RT shadow): Added Wave32 cross-wavegroupsharedreductions for 8x8 tile hit ballots and min/max/sum stats, gated tile UAV writes to a single lane, and removed redundant barriers.2561af95(LightAtlas sprites): Added finite-checkedquad_uv_gradto executeQuadReadLaneAtunder uniform control flow outside divergent branches.0f9382de,ca91c139,d5f6125b,f76abe01(ScreenProbes): Replaced earlyreturns beforeGroupMemoryBarrierWithGroupSync()withexitedflags + neutral sentinels so every thread participates in trailing barriers without corrupting UAVs or wave ballots.e4a9f58e,c4183d3c,b9688048,1f1fbd86(Decals & tiles): Clamped chainedsqrtinputs against negative-zero rounding NaNs, guarded 1-based object index underflow, and replaced O(N²) LDS loops with wave intrinsics in1f1fbd86.559d9f01,002e93a6,0e64f14f,191ecaed(Shadow & tile RMW): Guarded+infneighbor depth NaNs in559d9f01and serialized per-tile UAV read-modify-write races.3. GPU, VRAM & Pipeline Optimizations (
larp-gpu,larp-pipeline)draw.rs: KeyedHostList::first_useperstrides_buffer(), refinedWHOLEthrottle gating so secondary lists hold copies properly with bounded map pruning, moved per-drawVecscratch (twins,viewed,kinds) ontoScratch, cachedPicksspans/slots (FastMap+spans_cache), and replaced linearbuilt.bytes.containsscans with aBYTESbitflag.descriptor/host.rs: Added lock-free Acquire/Release fast hits inHostHeap::make_from, replacedVec<bool>free search indynamic/releasewith a 64-bit word bitset (trailing_zeros), batched COM retirements, and short-circuited no-opkeepupdates.pipeline/{make,blobs,host}.rs,pipeline.rs,shader_cache.rs,larp-pipeline/cache.rs:run_with_frame_budget(fixing multi-thread budget starvation) and deduplicatedQueue::bump(with unit tests).blobs/in memory (ON_DISK) to eliminate repeatedstat()syscalls during warming/writes.rect_list_gsbytecode, andquad_mask_stage(OnceLock); deferred COMCreateRootSignature/ID3D12Device2QI andPlan::ofallocation until afterblobs::unless_on_diskprewarm checks.shader_cache::cachedto incrementalCacheKey::hasher+ directstore/lookupwithout redundant.concat()allocations or miss read-backs.host.rs,copyback/buffers.rs,slotfree.rs,allocators.rs,staging.rs,rt.rs,overlay/perf.rs,capture.rs,stall.rs,watch.rs:DXGI_GPU_PREFERENCE_HIGH_PERFORMANCEadapter, bumped internalBUFFERSfrom 2 to 3 (all swap-chain consumers query dynamically), skipped redundantCOPY_DESTpresent barrier when overlay is hidden, and gated diagnostics-onlyHostList::pipelinesandCardClockbackground activity.KEPT_COUNTfast skip and single-lockforget()incopyback/buffers.rs; added anunstampedcursor inslotfree.rs; capped idle allocators (MAX_FREE_PER_KIND = 64) and idle 16 MiB staging arenas (MAX_IDLE_ARENAS = 16).RecordScratchbuffers inrt.rs; switchedoverlay/perf.rspercentile/median selection to O(N)select_nth_unstable_by; cached capture-folder check andLARP_STALL_S=0fast path; pruned unguarded/freed/unclean entries and boundedfoundcapacity inwatch.rs.4. HLE, RAM, DirectStorage, Audio, Input & Loader Optimizations
xmem.rs: Reclaimed freed physical page place slices once all mapped views unmap, switched non-alias allocations toSEC_RESERVE(committed on demand across CPU/GPU/VEH paths), and droppedPHYSICALacrosstitle_memory_remappingwhile re-validating mapped spans.dstorage.rs: Released staging right after decode when landing intoDestination::Buffer, bypassed Head-of-Line stalls on tight staging budgets, reused thread-local scratch buffers, and reserved headroom indefault_worker_count(with unit tests).bcpack.rs,texture.rs,files.rs,apu.rs,audio.rs,dsp.rs,xma.rs: Reused thread-local/voice scratch buffers, eliminated modulo division inConvolutionState::process, preserved XMA2 prior half-frame overlap on corrupt frames + stack-allocated IMDCT butterflies + lock-freeXma::pumpinactive/drained slot skipping.storage.rs,xasync.rs,xgamesave.rs: Cachedstorageused bytes withFindFirstChangeNotificationWchange invalidation; consolidated delayedXTaskQueuesubmits onto a shared backgroundTimerthread with pool wakeup accounting; movedxgamesaveontoRwLock+ targeted root migration + serialized backgroundSaveWorker.host.rs,theme.rs,gameinput/{sdl,playstation}.rs,settings/{menu,look,extra}.rs,tls_watch.rs,console_insn.rs,prompts/hook.rs: DroppedMODULESlock aroundLoadLibraryExA(preventing OS loader lock inversion), cached DWM dark-mode state, throttled SDL controller hotplug enumeration to 1 Hz + dirty-checked rumble, cached DualSense env lookup, added lock-free closed-menu fast path +OnceLockGDI/path caches, gatedtls_watchbehind opt-inLARP_TLS_WATCH=1, expandedconsole_insnVirtualQuerycache to 16 slots, and validatedprompts/hookmovies in-place before boxing.5. Build, Subrender Safety & Documentation
apps/larp/build.rs: Parallelized DXC HLSL replacement compiles (both heap sizes) across up to 8 worker threads.Cargo.toml: Addedcodegen-units = 1under[profile.release](keepinglto = "thin"anddiagnosticslogging compatibility).apps/larp/src/subrender.rs: Added length/bounds guard before indexingdirty_wordsrows.docs/environment-variables.md: AddedMemory, Threading, Shaders & Cachingdocumentation for--card-budget,LARP_ALIAS_SHARE,LARP_CORES,LARP_DSTORAGE_CACHE_GB,LARP_RT_WHOLE,LARP_SHADER_OPT, andLARP_SKIP_PIPELINES.Verification
d2a79ddtree:cargo check -p larpexited0with 0 errors and 0 warnings in any modified file lines.c36328dafter final warning fix):cargo build --release -p larpexited0(compilingtarget/release/larp.exeand all 85.dxilreplacement shaders for both 1M and 2M view heaps via DXC).cargo testand runtime in-game testing were not executed after the edits and remain recommended during review/CI.Reduce CPU draw recording overhead, lock contention, allocation churn, and VRAM growth across larp-gpu & larp-pipeline: - draw.rs: Key HostList::first_use per strides_buffer, refine WHOLE copy gating & secondary list holds, reuse Scratch vecs, cache Picks spans/slots, and replace bytes.contains with BYTES bitflag. - descriptor/host.rs: Add lock-free Acquire/Release fast-hit path in make_from, 64-bit word bitset allocator in dynamic/release, batched COM retires, and no-op keep guard. - pipeline/{make,blobs,host}.rs, pipeline.rs, shader_cache.rs, larp-pipeline/cache.rs: Fix concurrent frame wait budget accounting & dedupe Queue::bump; cache on-disk blob index; cache serialized root signatures, rect GS & quad mask stages and defer COM creation/Plan past on-disk prewarm skips; stream incremental BLAKE3 hashing in shader_cache without changing on-disk PSO blob keys/format. - host.rs, copyback/buffers.rs, slotfree.rs, allocators.rs, staging.rs, rt.rs, overlay/perf.rs, capture.rs, stall.rs, watch.rs: Prefer high-perf GPU adapter & triple buffering, gate diagnostics-only fields/CardClock, skip empty KEPT locks, use unstamped cursor in slotfree, cap idle allocators (64) and staging arenas (16), add RT BLAS->TLAS UAV barrier + scratch reuse, use O(N) select_nth_unstable_by in perf overlay, fast-path disabled capture/stall, and prune write-watch journal.Reduce RAM usage, streaming stalls, audio/format scratch allocations, and lock contention in HLE, formats, prompts, and loader: - xmem.rs: Recycle freed page place slices safely after last unmap, switch non-alias allocations to SEC_RESERVE on demand, and drop PHYSICAL mutex across title_memory_remapping. - dstorage.rs: Avoid Head-of-Line queue stalls on tight staging budget, release staging before mip landing, reuse thread-local scratch buffers, and leave headroom in default worker count. - bcpack.rs, texture.rs, files.rs, apu.rs, audio.rs, dsp.rs, xma.rs: Reuse thread-local/voice scratch buffers, remove inner FFT/ring modulo division, preserve XMA2 overlap half-frame on bad frames, speed up bitreader/IMDCT butterflies, and skip idle Xma::pump slots lock-free. - storage.rs, xasync.rs, xgamesave.rs: Cache storage used_bytes with Win32 directory change notifications, coalesce delayed XAsync tasks onto a shared Timer thread + pool wakeup tracking, and use RwLock + background SaveWorker in xgamesave. - host.rs, theme.rs, gameinput/{sdl,playstation}.rs, settings/{menu,look,extra}.rs, tls_watch.rs, console_insn.rs, prompts/hook.rs: Drop MODULES lock across LoadLibraryExA, cache DWM dark-mode state, throttle SDL plug polling to 1 Hz + dirty-checked rumble, cache DualSense trigger env, add lock-free closed-menu fast path & OnceLock GDI/path caches, make TLS watch opt-in (LARP_TLS_WATCH=1), expand VirtualQuery cache to 16 slots, and validate prompts/hook movies in-place before boxing.@Narcotic-oa on GitHub · 2026-12-06 00:21 UTC · original
u r the man , u r killing it bro
@Heliumrich on GitHub · 2026-12-06 00:22 UTC · original
I doubt a PR this large (+5k lines of codes), that does multiple completely different things, will get merged as is.
Pretty sure you'll have to split it into multiple parts and make multiple PRs
@ZerefDragnee1l on GitHub · 2026-12-06 00:23 UTC · original
yeah ik i'll do it, have lots of prs
@erdtreefaithful on GitHub · 2026-12-06 00:33 UTC · original
Yeah, even for the most powerful LLM, reviewing something like this would be tough - and I personally wouldn’t feel comfortable merging it without spending an hour or two playing the game. But changes sound good ngl
@erdtreefaithful on GitHub · 2026-12-06 00:35 UTC · original
We need to find and fix that freeze with 0 gpu usage drop asap tho.
@ZerefDragnee1l on GitHub · 2026-12-06 00:35 UTC · original
yep yep working on that
@ZerefDragnee1l on GitHub · 2026-12-06 00:36 UTC · original
now im gonna split the pr.
@erdtreefaithful on GitHub · 2026-12-06 00:38 UTC · original
Thats dope, im gonna take a look at it after testing new version too, we dont wanna mess up the build. I mean once that freeze is gone, the game is basically playable with rt on high endish hardware
@vanya890 on GitHub · 2026-12-06 00:39 UTC · original
One interaction worth checking while splitting this PR: the new build path starts up to 8 DXC processes concurrently. Issue #249 reports that compiling
191ecaed66eea3b1.compute.hlslwith-O1/-O3can exhaust host system memory; my separate PR #421 applies-Odonly to that shader and leaves-O3on the rest.The parallel build may amplify peak memory pressure across several compiler processes, even with that per-shader exception. It may be worth validating the worker count on lower-RAM machines or keeping the reported heavy shader serialized/bounded when you split the build-system changes. I haven't benchmarked the parallel path or measured its peak memory, so this is a risk to test rather than a confirmed regression.
@Narcotic-oa on GitHub · 2026-12-06 00:40 UTC · original
u deserve a nobel prize
@ZerefDragnee1l on GitHub · 2026-12-06 00:41 UTC · original
thanks. noted that
@Heliumrich on GitHub · 2026-12-06 01:14 UTC · original
Played for +30 min and works really well, lighting and graphics are really better.
I do disable the game TAA when using DLSS, otherwise it looks blurry AF (weird this project doesn't force game TAA/FSR4 off when DLSS is on...)
specular reflections are still kinda boiling but afaik it's just how the game is. I haven't felt increasing the ingame hidden settings changing anything on this regard.
@justihsann on GitHub · 2026-12-06 01:22 UTC · original
nasıl indireceğim
@ZerefDragnee1l on GitHub · 2026-12-06 01:26 UTC · original
thanks. i'll do more.
@erdtreefaithful on GitHub · 2026-12-06 01:35 UTC · original
Im gonna do some diag now on 1.1.6 with wpr, try to capture fucker
@ZerefDragnee1l on GitHub · 2026-12-06 01:56 UTC · original
Closing this monolithic PR in favor of focused, individually reviewable PRs against
main:map_upscaler_mode()unit test.texevents.rsread_late()queue accounting (#250), withread_lateregression test.191ecaed66eea3b1replacement on NVIDIA 616.x to avoid compiler OOM (#249).cbufferLoadLegacy4095 clamp + constant-row folding, Wave64 hosts,lds_meetingsmixed plain/atomic write barriers, and wateridle_lds_reads+ CPU regression tests.blobs-index.binfail-open warm startup, zero cache invalidation) + codec and caller-level fail-open tests.taa=0) when an external upscaler (DLSS/FSR/DittoSR) is active (LARP_KEEP_GAME_TAA=1opt-out).NIS_Scaler.hclamp, and D3D12 copyback/barrier fixes.QuadReadLaneAtcontrol-flow, ScreenProbes barriers, decal NaNs, and tile RMW fixes.xmem,dstorage,audio,xgamesave,xasync, input, settings, loader, prompts) optimizations.>150 KiBshaders like191ecaed66eea3b1per @vanya890 / #249),subrenderbounds guard,LARP_LICENSES, automatic Windows NVIDIA shader heap (LARP_NO_AUTO_NVPROFILE=1), and env docs.Pull request closed