shader(lower,cost): add exact float min/max and med3 rewrites with cache-key switches #165
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/165"
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 Androtim on 2026-11-29T20:54:20Z.
## Summary
min/maxandmed3rewrites invictory-shader(emit/cost.rs,emit/lower/minmax.rs,emit/bitcode/census.rs):VICTORY_MINMAX_NONZERO(on by default): omits the two-zero sign test and select when one operand is a constant with nonzero magnitude bits.VICTORY_MED3_CLAMP(on by default): lowersmed3(x, lo, hi)with normal/infinite constant bounds tomin(max(x, lo), hi)on every host (matching NaN-to-lobehavior, leaving zero/denormal/NaN bounds on the general form).VICTORY_MINMAX_NONZEROandVICTORY_MED3_CLAMPtocrates/victory-gpu/src/shader_cache.rs::buildtranslation fingerprint.emit/valu_tests/cost_checks.rscovering bit-exactness on hardware and WARP across denormals, signed zeros, infinities, and NaNs.Test plan
cargo run -p xtask -- policy: passed (308 files ok)cargo test -p victory-shader valu_tests: passed (hardware & WARP)cargo test -p victory-shader wave64_tests: passedcargo test -p victory-gpu shader_cache::: passedcargo clippy --workspace --all-targets(default and--features diagnostics) with-D warnings: passedImported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T21:05:35Z.
Automated triage for the maintainers (not an approval).
Verdict:
needs-gpu-test· CI (check):passingReview Summary
Logic, edge-case handling, and cache-key plumbing look solid, and CI is passing. Because this enables two new default-on DXIL shader lowering rewrites (
VICTORY_MINMAX_NONZEROandVICTORY_MED3_CLAMP), it warrants a quick local real-GPU smoke test before merging.Verified Changes
crates/victory-shader/src/emit/lower/minmax.rs(extracted fromemit/lower.rs):Lower::max_min: WhenRewrite::MinMaxNonzerois enabled and either operand is a float constant with nonzero magnitude bits (k.to_bits() & 0x7FFF_FFFF != 0), skipping the two-zero sign-select sequence is exact because((ia | ib) & 0x7FFF_FFFF) == 0is always false regardless of the other operand. Zero constants (+0.0/-0.0) remain on the general path.Lower::med3/Lower::med3_clamp: WhenRewrite::Med3Clampis enabled and exactly two operands are normal or infinite float constants (excluding NaN, ±0, and denormals viak & 0x7FFF_FFFF > 0x7F80_0000 || k & 0x7F80_0000 == 0), ordering the bounds and emittingFMin(FMax(x, lo), hi)matches the general form across all inputs, including NaN (FMax(NaN, lo) -> lo,FMin(lo, hi) -> lo), ±0, and denormals.crates/victory-shader/src/emit/cost.rs&crates/victory-gpu/src/shader_cache.rs:"0", are picked up bycrates/victory-shader/build.rs(VICTORY_SHADER_SWITCHES, verified byevery_rewrite_has_a_switch_in_the_fingerprint), and are included inshader_cache::buildso toggling either switch invalidates cached translations.crates/victory-shader/src/emit/bitcode/census.rs&crates/victory-shader/src/emit/valu_tests/cost_checks.rs:#[cfg(test)]thread-localcensus::countinghelper and tests verifying bit-exactness across signed zeros, denormals, normals, infinities, and NaNs on both hardware D3D12 and WARP, alongside instruction-count reductions.Minor Nits (non-blocking)
crates/victory-shader/src/emit/valu_tests/cost_checks.rs: tiny doc typo(if ewer is not 0)→fewer.Next Step
Run the hardware
valu_testssuite (specificallycost_checks) and a brief real-GPU game smoke test to confirm no driver-specific regressions with the shortenedFMin/FMaxsequences before merging.Generated with Antigravity CLI (
agy).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T21:20:19Z.
Verified PR #165 (
04b7aa29) on live RTX 4060 Ti 8 GB Series S (verify-world.ps1 -AutoNudgeMenu, isolatedD:\victory-data\cache-minivi-pr165, 75s warm run after initial cold shader/PSO cache population):pr164-minmax): Reached 3D world cleanly (crashes=0, untranslated=0, VRAM5656/6436 MB), populatedcache-minivi-pr165(1,103files /416 MB), while dropping ~1,470 draws/frame awaiting initial shader/PSO compilation (lit=0/24).pr164-minmax-warm): 6/6 gates PASS (ok: true)world_windows=16,max_draws=11145crashes=0,no_host_texture_errors=0,untranslated=08.95 fps(111.9 ms), preparing54.3 ms, GPU0.7 ms, copyback14.0 ms5507 MB/ budget min6569 MB(over=0 MB,room_false=14.3%)45552,final_waiting=2610,max_waiting=30810mapped()6.4 ms/s(15400calls, longest21.0 ms)lit=19/24, medianluma=110.74,near_black=0.0%,edge_energy=6.34,max_magenta=0.0%; inspectedframe-5095.png(clean lighting, skin/wood/foliage detail with a couple transient dark water squares while streaming settles) andframe-5271.png(clean daylight lighting, water shading, wood grain, foliage, and clouds with zero NaN/black/magenta artifacts).Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T21:27:46Z.
Automated RTX 4060 Ti 8 GB Open-World A/B hardware verification PASSED (
playtest/wave5vsorigin/mainb1b6dc1,VICTORY_LEVELS_ON_DEMAND=0play-parity):cargo test(RTX 4060 Ti): 645 passed, 0 failed (victory39/39,victory-shaderemit::wave64_tests19/19 &lower19/19,victory-gpu568/568).scripts/verify-world.ps1, DLSS Quality + open-world save):9.4 fpsvs7.5 fps(+1.90 fps / +25%), min8.3 fpsvs0.8 fps, preparing53.6 msvs60.0 ms5760 MBvs6005 MB(-245 MB,0 MBover budget);no room for new oneshalved (9,000vs18,000);max_waitingdropped (36,432vs41,431)0mismatches (other_bytes=0, showed_another_view=0, failed=0vs5and2on baseline)mapped_rate1.63 ms/svs6.9 ms/s(-76%, max12.9vs51.9 ms)frame-5975.png,frame-5983.png),edge_energy=4.69vs3.88,near_black=0.02%,magenta=0.0%(and#1412bf6800showed zero visual artifacts).