perf(shader): fold idempotent Saturate, FMax, and FMin calls (#312) #314
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/314"
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-02T09:01:11Z.
Summary
Implements bit-exact algebraic folding for idempotent
Saturate,FMax, andFMinDXIL intrinsic calls incrates/victory-shader/src/emit/bitcode/opt.rs::Module::simplify.Fixes #312
Refs #276
AI-Ready Context & Change Map
For downstream coding/review agents, here is the exact scope, rewrite rule set, and verification summary of this PR:
crates/victory-shader/src/emit/bitcode/opt.rs—Module::simplify(Op::Callarm,opt.rs:693-726)args[0]viaself.int_k(...)and handles:dx.op.unary.f32opcode7(Saturate):Saturate(Saturate(y)) -> Saturate(y)(Some(*x)when*xis itselfdx.op.unary.f32(7, _)).Saturatealready maps every finite/infinite/NaN input into[+0.0, 1.0].dx.op.binary.f32opcodes35(FMax) and36(FMin):op(a, a) -> a. Under DXILFMax/FMinsemantics, a NaN is returned only if both inputs are NaN, so(a, a)always producesabit-for-bit (preserving-0.0and NaN payloads).op(op(x, y), z) -> op(x, y)andop(z, op(x, y)) -> op(x, y)wheneverz == x || z == yand both calls share the same opcode (35 == 35or36 == 36). Preserves DXIL NaN propagation in all 4 finite/one-NaN/both-NaN cases; cross-opcode nests likeFMax(FMin(x, y), y)are intentionally not absorbed.REUSE+drop_dead()inModule::optimisealready deduplicate identical inner calls and remove dead producers oncesimplifyreturns the existingV.crates/victory-shader/src/emit/bitcode/opt.rs— Unit Testidempotent_saturate_and_minmax_calls_fold(opt.rs:2261-2332) testingSaturate(Saturate(x)),FMax(x, x),FMin(y, y),FMax(FMax(x, y), y),FMin(x, FMin(x, y)), and negative caseFMax(FMin(x, y), y), plusModule::write()round-trip.Rig Specs Tested On
x86_64-pc-windows-msvcfull workspace clippy and live GPU frame-time benchmarks deferred to GitHub Actions (windows-latest) / maintainer runRun Settings & Profile
victory-shaderbitcode optimizer changes on top oforigin/main(c7d3102)VICTORY_*Overrides: N/AMeasurements & Verification
cargo clippy --workspace --all-targets --locked -- -D warnings(requiresx86_64-pc-windows-msvc; verified on GitHub Actionswindows-latestCI)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(requiresx86_64-pc-windows-msvc; verified on GitHub Actionswindows-latestCI)cargo clippy --locked -p victory-shader --lib -- -D warnings-> 0 warnings, exit 0cargo test --locked -p victory-shader -- --test-threads=1-> 253 passed, 0 failed, 2 ignored (includingidempotent_saturate_and_minmax_calls_foldandevery_pass_leaves_what_random_programs_store)cargo test --locked -p xtask-> 8 passed, 0 failedcargo xtask policy->asset policy: 321 files okImported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T09:03:55Z.
Automated triage for the maintainers (not an approval).
Verdict:
needs-rebase· CI (check):passingThis PR no longer merges cleanly into
main.To change the verdict: Rebase onto current
mainand resolve conflicts; CI and triage will run again automatically.Generated with Antigravity CLI (
agy).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T11:12:47Z.
Gate 3 Live Windows D3D12 Cold-Cache GPU Verification — PASS
Tested combined PR #311 + PR #314 on Windows 11 + NVIDIA RTX 4060 Ti 8 GB (
1440pDLSS Quality, fresh cold shader cache):14/14victory-shader::emit::bitcode::opt::testspassing (idempotent_saturate_and_minmax_calls_fold+ differential suite).DRAWS 9904,DROPPED 172,0 being made, peak dedicated VRAM5476 / 6613 MiB).Note: Once PR #311 merges, PR #314 only has a trivial adjacent unit-test line conflict at the bottom of
crates/victory-shader/src/emit/bitcode/opt.rs(zero production-code overlap). Ready to merge!Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T11:33:06Z.
PR
#311has merged (8780a119), leaving the expected adjacent unit-test conflict incrates/victory-shader/src/emit/bitcode/opt.rs. Gate 3 cold-cache GPU verification already passed — once rebased ontomainwith green CI, ready to auto-merge immediately.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.