shader: exact float guard simplification (VICTORY_FLOAT_GUARDS) #3148
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!3148
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3148"
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?
@nidea1 on GitHub · 2026-11-29 20:18 UTC · original
nidea1:perf/exact-float-legacy-mul-minmax-opt→main· +2081 −11 · 6 files · 1 commits · closed without mergingSummary
Adds an exact, host-independent DXIL float value-range and backward zero-sign-liveness pass (
bitcode::zero_sign, switched byVICTORY_FLOAT_GUARDS, default on) underopt::FOLDthat eliminates redundant RDNA2-compatibility guards on any host (both FTZ hardware and non-FTZ WARP):v_mul_legacy_f32(legacy_mul): eliminatesselect(a == 0 || b == 0, +0.0, a * b)whena == b, both operands are guaranteed normal non-zero (NORMAL_NON_ZERO), both are non-negative with no0 * inf/0 * NaNpossible, or downstream does not observe zero sign (+0.0vs-0.0) and0 * inf/0 * NaNis impossible; narrows two-sidedOr(OEQ(a, 0), OEQ(b, 0))to one side when the other is normal non-zero or finite with zero-sign-safe result.v_max_f32/v_min_f32/v_max3_f32/v_min3_f32(max_min): eliminates the 8-instruction bitcast zero-sign guard (both two-variable andFOLD-folded±0.0forms, includingFOLD-collapsedbitcast(bitcast(i32))operands) when either operand has non-zero magnitude bits, both are non-negative, or downstream does not observe zero sign.v_med3_f32(med3(x, ±0.0, bound)): collapses the general 5-call + integeris_nan_f32select sequence to a 2-callFMin(FMax(x, lo), hi)clamp when downstream does not observe zero sign or the input cannot be-0.0/ negative denormal (reusing existingt = FMin(FMax(x, lo), hi)in canonical order, splicing otherwise).is_nan_f32/UNO/ORDfolding: statically foldsIUGT(And(bitcast(x), 0x7FFF_FFFF), 0x7F80_0000)andUNO/ORDwhen operands are proven non-NaN.VICTORY_FLOAT_GUARDSinemit::cost::SWITCHESandvictory-gpu::shader_cache::KEYED.Soundness
NON_ZERO_BITS(bits & 0x7FFF_FFFF != 0, preserved only across non-FTZ bit-preserving ops such as literal constants,Select, andBitcast(Bitcast(x)), or viaNORMAL_NON_ZERO) fromNORMAL_NON_ZERO(bits & 0x7F80_0000 != 0, excludes denormals so FTZ hardware and non-FTZ WARP agree on every input including±denormacrossFMax/FMin/FAbs/Sub(-0.0, b)).FloatPropsproperty is invariant under stripping guard selects, so simultaneous rewriting is sound by induction.write_fbitcasts do not pollute liveness, records only explicit guard-ownedmax_minnodes (guard_sv,guard_si,guard_ci,guard_mi,guard_ei, strictly excluding non-guard inputsxandia_val), and propagatesguard_internaltop-down per uniqueguard_internalparent so externally used or shared guard nodes cannot mask sign observation.Measured Impact (RTX 3060 Ti,
VICTORY_FLOAT_GUARDS=0vs1)941,016 -> 895,228 B(-4.87%)114,265 -> 105,647(-7.54%)14,528 -> 12,495(-14.0%)14,749 -> 12,660(-14.2%)676 -> 802 mstranslate38,708,802 -> 37,586,606 B(-2.90%, -1.12 MB)4,371,508 -> 4,179,799(-4.39%)505,644 -> 436,779(-13.6%)515,043 -> 493,526(-4.18%)20.57 -> 21.40 s(+0.8 ms/shader)3,000,136 -> 2,974,048 B(-0.87%)421,701 -> 417,258(-1.05%)14,489 -> 14,397 ms(-92 ms, top 4 all faster)cost_checks::a_run_of_float_math60 -> 25(-58.3%)5 -> 0(-100%)14 -> 4(-71.4%)11 -> 8math callsVerification
Latest commit
4d587846(rebased on5fabb46e):cargo test -j 4 --locked -p victory-shader --lib -- zero_sign— 7/7 pass (6zero_signunit tests coveringguard_internalsoundness and FTZNON_ZERO_BITS+cost_checksnegative control)cargo test -j 4 --locked -p victory-shader --lib -- emit::bitcode— 47/47 pass (2 ignored; includes randomized differential oracleevery_pass_leaves_what_random_programs_storeanddxil_opt_hw_gpu_bit_exact_parity_and_validation)cargo test -j 4 --locked -p victory-shader --lib -- cost_checks— 7/7 pass (1 ignored; all existing + 4float_guards_*suites sweepingFLOATS/PAIR_FLOATS/TRIPLE_FLOATSon both hardware GPU and Microsoft WARP)cargo test -j 4 --locked -p victory-gpu --lib -- shader_cache— 12/12 pass (includingevery_switch_of_the_translator_is_in_the_key)cargo clippy -j 4 --locked -p victory-shader --all-targets -- -D warningsand--all-features— 0 warningscargo xtask policy— asset policy: 465 files okVICTORY_FLOAT_GUARDS=1andplaydefault switches): 25,789 shaders translated, 2,736 / 2,736 pipelines created and saved to pipeline library (0 build failures), and live 3D gameplay verified cleanly with 0 GPU/device errors (not yet re-run on4d587846).61b9753615tof9769fd0caf9769fd0cato2a456785032a45678503to74456c6a7e@nidea1 on GitHub · 2026-12-01 09:36 UTC · original · edited 2026-12-01 16:07 UTC
Cross-referencing independent GPU profiling from #4762 (Nsight trace follow-up by @plapha on RTX 5060):
In the two command lists holding 5.5 of 13.7 ms of frame draw time (dominated by the 3 slowest mesh programs:
MS(NC)_VS_PropFoliage(Skin)Deferred,MS_VS_TransformD, andMS(NC)_VS_PedTransform(Skin)D), the hottest shader-profiler lines are spread flat across the programs, with many landing onfcmp oeq float x, 0legacy-multiply guards — specifically1,451 fcmp+1,423 selectout of14,254DXIL instructions (~20%) in the foliage mesh shader (c32dea401eb799a7).This PR (
VICTORY_FLOAT_GUARDS) targets the provably redundant subset of those legacy-multiply / min-max / med3 float guards while preserving exact FTZ and non-FTZ semantics, making those mesh shaders a good independent profiling motivation and benchmark target.Calibration update (follow-up in #4762 by @plapha):
1,451 fcmp + 1,423 selectguards inc32dea401eb799a7are unbounded two-variablerawBufferLoadlegacy_mulguards that#3148keeps by design (exact semantics), so the ~20% figure reflects the total guard share rather than what#3148alone removes.4d587846, ~10,000 draws/frame, per-command GPU timing):31.0 mswithVICTORY_FLOAT_GUARDS=1vs31.1 msoff (indirect draws16.1vs16.4 ms, mesh draws3.9vs3.7 ms, compute8.3vs8.4 ms) — within the ~1.5 ms run-to-run scatter (foliage output changed so the switch was active; newer4d587846revision not yet re-measured). Measuring the relaxed share of those two-variable guards is whatVICTORY_HOST_RDNA=1 VICTORY_RDNA_FLOAT=2targets.74456c6a7eto4d58784618@nidea1 on GitHub · 2026-12-01 10:31 UTC · original
Updated to
4d587846(rebased ontomain5fabb46e) with four soundness fixes inbitcode::zero_signplus a cleaned-up commit message:guard_internaltop-down propagation (externalsv/ciuse): recorded explicit guard-owned node IDs (guard_sv,guard_si,guard_ci,guard_mi,guard_ei) inMaxMinGuardand gated child credit on the parent actually beingguard_internal, so an external use ofsv = bitcast(si)orcicannot leakguard_internalontosi/mi/ei.sv/ci/mi): propagatedguard_internallevel-by-level once per uniqueguard_internalparent (sv/ci->si/mi->ei), preventing twomax_minguards sharingsvorcifrom double-counting child uses and masking an external live user ofsi/ei(while preserving CSE-mergedsi == eiinFMinguards).min(x, +0.0)non-guard inputs: strictly excluded non-guard inputsxandia_valfromguard_sv/guard_si/guard_ei, somin(bitcast(user_int), +0.0)never marks arbitrary user integer ops (includingBin::Or) asguard_internal.NON_ZERO_BITSpropagation: stopped propagating bare denormalNON_ZERO_BITSacross FTZ-flushing float ops (FMax,FMin,FAbs,Sub(-0.0, b)), propagating onlyNORMAL_NON_ZEROthere while keepingNON_ZERO_BITSfor bit-preserving ops (literal constants,Select,Bitcast(Bitcast(x))).zero_sign::testscovering all 4 bugs and positive controls, and re-verifiedzero_sign(7/7),emit::bitcode(47/47),cost_checks(7/7),victory-gpu::shader_cache(12/12),victory-shaderclippy (--all-targetswith and without--all-features, 0 warnings), andcargo xtask policy(465 files ok).@nidea1 on GitHub · 2026-12-01 12:33 UTC · original
Live runtime verification on updated head
4d587846(with all 4zero_signsoundness fixes active under defaultVICTORY_FLOAT_GUARDS=1; RTX 3060 Ti 8 GB (ReBAR off, driver621.40), 32 GB RAM, Windows 11, Series S, DLSS Quality, FSR 3 FG, RT off,VICTORY_SAMPLED_EVICT=1,VICTORY_WINDOW_GROW=1,VICTORY_POOL_SMALL=0,VICTORY_RIPE_BLOCKS=12— 5-minute (300 sin-world,357 stotal) live validation on a combined 15-PR release build overorigin/main(5fabb46eaf).):+3,054additional shaders live (12,262 -> 15,316cached) with0shader translation failures or warnings,0Victory errors, and0nvlddmkmevents.+60 s..+300 s):20.61 FPSmean (20.80median),47.80 msmedian /70.15 msp99 frame time, VRAM6,559 / 6,770 MB, Shared GPU RAM5,980 MB.+31 sindoor café portrait,+151 sand+285 sbacklit prison-cell window/hair/glass/fence): clean rendering with0visual artifacts or NaN/sign glitches.Caveat: combined 15-PR release build over a 5-minute opening/cell sequence (not an isolated
VICTORY_FLOAT_GUARDS=0/1A/B or driving soak).Pull request closed