shader: prefer exact Wave32 before wave64 folding and cap eager fold at 255 host regs #2261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2261"
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 qlfu on 2026-11-29T11:09:59Z.
What it changes Fixes a severe GPU performance regression introduced when
folded()(8f0a0c24) was placed at the very top ofemit_strict's Wave64 retry block incrates/victory-shader/src/emit/mod.rs: 1. Try non-widened exact native Wave32 forms before folding (without early-outs,without skips,local waves (idiom),without skips, scalars followed), while keepingfolded()ahead ofwiden()(wave-wide branches). Previously, placingfolded()first hijacked 55 of 105 gameplay Wave64 compute shaders that already lowered cleanly and exactly to native Wave32 without doubling VGPRs (CS_Prop_BatchCull,CS_Slod_BatchCull,CS_BatchCullMeshlets*,CS_HairTileClassify, etc.). Keepingfolded()ahead ofwiden()preserves bit-exact 64-lane semantics for all reflection/screen-probe shaders (WIDE_SKIP_DEFAULT, 20/20 verified folded, avoiding the window-reflection artifacts caused bywiden()). 2. Guardsafe_single_wavewith!lower::wide_fallback_skipped()inemit_strictso reflection and screen-probe programs listed inWIDE_SKIP_DEFAULT(sr_tracing:CS_RayPrePass_Opaque_SSR,sr_denoising:CS_TemporalResolve*, screen probes) never enterwiden()viasafe_single_waveeven when folding is disabled or skipped. 3. Defer folding pastAPPROXIMATEwhen2 * console_vgprs + TEMP_VGPRS > 255(fold::fits_host_regs,console_vgprs > 126). Folding doubles every VGPR; on 32-lane NVIDIA hosts (255 hardware registers/thread), folding 129-VGPR shaders (ptfx_CS_lightAtlas_Sprite2561af9577c47289andptfx_CS_lightAtlas_Trailc06aa62112ffba4c→ 260 host VGPRs, 88 KB code, 100 wave-wide EXEC branches) forces heavy local-memory register spilling to VRAM, turning a <0.5 ms pass into a 21 ms average / 70–105 ms peak GPU stall. Over-255-register shaders are still tried withfolded()as a last resort if no non-folded lowering succeeds, so 0 new refusals are introduced (636/636gameplay compute shaders translate). 4. All shadow/hair/reflection shaders that rely on folding (CS_GenerateShadowMasks*, all 20WIDE_SKIP_DEFAULTreflection & screen-probe shaders) continue to fold identically. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X 1440p, DLSS Balanced, FrameGen off (-NoFrameGenReady), Ray Tracing off (VICTORY_PORT_CONSTANTS=1;VICTORY_WAIT_RESIDENT=textures), clean 90s gameplay A/B onorigin/main(829188e9). - Before (origin/main829188e9,victory-nvidia-20261129-120600.log): - FPS: median 16.80 | mean 16.58 | min 8.8 | p10 9.3 -cardmeterGPU time (120600.log): median 40.8 ms, p95 105.6 ms, max 122.7 ms (ptfx_CS_lightAtlas_Sprite2561af9577c47289alone: 18.3–21.3 ms avg, ~80–105 ms peak), GPU busy ~94% - Folded gameplay compute shaders: 105 (of 636) - After (pr/wave64-fold-after-exact-and-vgpr-cap): - Shader audit: 636/636 gameplay compute shaders translate (0 refused), folded count 105 → 48 (55 clean exact Wave32 shaders + 2 >255-regptfx_CS_lightAtlasshaders rescued), 20/20WIDE_SKIP_DEFAULTreflection & screen-probe shaders verified folded (0 enteringwiden), 0/67sr_tracing/sr_denoisingshaders enteringwiden. - Clean 90s warm gameplay verification (victory-nvidia-20261129-145029.log, 0 WARNs / 0 ERRORs) eliminates the 80–105 msptfx_CS_lightAtlasGPU stall:cardmeterGPU time drops from 40.8 / 105.6 / 122.7 ms (med / p95 / max) to 30.1 / 43.9 / 52.2 ms (-61.7 ms p95, -70.5 ms max), with 0 reflection shaders enteringwiden(). - For shader changes, the wave sizes tested (32 and/or 64 lanes): 32-lane host (RTX 4070 Ti) lowering Wave64 compute shaders; new unit tests inemit::folded_testscoverfits_host_regsandemit_strictprecedence for exact Wave32 vs folded (<=126 VGPRs) vs deferred (>126 VGPRs). -cargo testpassed for the crates it touches: yes (cargo test -p victory-shader --lib --locked: 464 passed, 0 failed;emit::folded_tests: 19 passed, 0 failed after final revision;cargo test -p victory-gpu --lib --locked shader_cache: 11 passed, 0 failed;cargo clippy -p victory-shader --lib --tests --locked: 0 new warnings). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2220 (touches adaptive shadow pass Wave32 scalars, no overlap withfold.rsoremit/mod.rsretry ordering).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-29T12:35:19Z.
Ran the folded-wave32 lowering tests at
a91133e0on an NVIDIA Blackwell desktop part.System
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5Results
VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-shader --lib emit::folded_tests --locked -- --test-threads=1: 19 passed, 0 failed, 0 ignored.What this adds
All 19
emit::folded_testspass here, covering the exact-Wave32-before-folding precedence, the 255-host-register cap and theWIDE_SKIP_DEFAULTordering. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti. These are translation-level tests; I did not repeat the author's 90 s gameplay A/B and claim no FPS number.Not tested
A retail title, FPS/GPU-time A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-29T15:54:53Z.
Build attempt at
829188e9on an NVIDIA Blackwell desktop part failed. This is a factual build report, not a review or a title run.System
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5cargo build --locked --profile diag -p victory --features diagnostics, detached worktree at829188e9Results
victory-gpu:copystat.rs:1349-1352:cannot find function mb(4 errors)host.rs:9127,9169,9180: a localtimingbinding shadowsfn timing()(3 errors)host.rs:9172:strhas noSizedbound inruns[i].slowest(...)(2 errors)What this adds
This commit is the base named in the PR description for the before/after A/B. I am reporting only the measured build outcome on this host and toolchain. No source was changed and no game was run.
Not tested
A retail title, a paired smoke run, other drivers, AMD and Intel GPUs, other toolchains, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the command above on this machine and wrote this report; no game data was used.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T23:54:49Z.
Rebased cleanly onto
main(41adb551,v2026.11.29.05): keepsfits_host_regs(native.vgprs)(<= 255host VGPRs) on pre-widen wave64 folding (emit/mod.rs) and!lower::wide_fallback_skipped()onsafe_single_wave. Verifiedemit::folded_testspass (0failed).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T12:36:50Z.
Updated pre-widen
folded (before wave-wide)guard incrates/victory-shader/src/emit/mod.rsto also check!scene_kernelso curatedwide_by_defaultcompute kernels stay on the wave-wide path instead of being folded ahead ofwide_by_default, and respectedwide_fallback_skipped(). Verified withfolded_testsand cleanmerge-treeagainst41adb551.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.