perf(shader): fold idempotent Saturate, FMax, and FMin calls in bitcode::opt #312
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Androtim/MiniVI. Originally posted by RUIZ-Enrique-25002136 on 2026-12-02T08:59:02Z.
Summary
crates/victory-shader/src/emit/bitcode/opt.rs::Module::simplifycurrently leavesOp::Callunhandled (_ => None), missing bit-exact algebraic simplifications on DXIL float intrinsics generated repeatedly by loweredv_med3_f32,v_max_f32,v_min_f32, and clamp/saturate modifiers:dx.op.unary.f32(7, ...)(Saturate):Saturate(Saturate(x)) -> Saturate(x)Saturateclamps to[0.0, 1.0]and mapsNaN -> +0.0(or passes/normalizes identically on re-application); any output ofSaturate(x)is already in[+0.0, 1.0], so applyingSaturatea second time is bit-for-bit identical for all inputs (including-0.0andNaN).dx.op.binary.f32(35 | 36, ...)(FMax/FMin):FMax(x, x) -> xandFMin(x, x) -> x. In DXIL,FMax/FMinreturn the non-NaN operand if one is NaN, and returnNaNonly if both are NaN — so for(x, x)the result is alwaysx(preserving-0.0andNaNpayload).FMax(FMax(x, y), z) -> FMax(x, y)(and symmetricFMax(z, FMax(x, y))) wheneverz == x || z == y; likewise forFMin.xandyare both finite/infinite,FMax(FMax(x, y), x) = max(max(x, y), x) = max(x, y).xisNaNandyis non-NaN:FMax(x, y) = y, thenFMax(y, x) = y(and forz == y:FMax(y, y) = y).xandyareNaN:FMax(x, y)isNaN(xory), andFMax(NaN, NaN)isNaN.Related
victory-shaderGPU Shader Timeclamp/f32folds backlog).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T10:33:46Z.
Thanks for the clear DXIL bit-exactness breakdown and for opening PR #314 (as well as PR #311)!
Both PRs have green CI (
checkpassing) and solid static analysis — we have them queued for our live Windows D3D12 cold-shader-cache GPU verification gate before merging. Appreciate the clean contributions!