perf(shader): fold idempotent Saturate, FMax, and FMin calls in bitcode::opt #312
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Androtim--MiniVI#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?
@RUIZ-Enrique-25002136 on GitHub · 2026-12-02 08:59 UTC · original
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).github-bot referenced this issue2026-12-02 09:05:14 +00:00
@Androtim on GitHub · 2026-12-03 10:33 UTC · original
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!