Shaders: programs without FMad disable math refactoring (port of upstream VIctory #1856) #961
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!961
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-961"
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?
@Moon0755 on GitHub · 2026-11-25 13:51 UTC · original
Moon0755:fix/disable-math-refactoring-without-fmad→main· +90 −5 · 3 files · 2 commits · openPorts upstream Marvisak/VIctory#1856 (
rminzao).Problem
On some PC GPUs/drivers (such as Intel UHD Graphics and NVIDIA Ada / RTX 4050), the host driver contracts separate
fmul+faddoperations (includingv_mad_f32,v_mac_f32, and BVH ray-triangle intersection arithmetic) into a fused FMA when math refactoring is allowed in DXIL entry properties. Because Xbox Series X (RDNA2) rounds unfused operations separately, contracting them produces 1 ULP /-0mismatches against console semantics.What changed
crates/victory-shader/src/emit/shader.rs:flags::NO_REFACTORING(1 << 1, DXILDisableMathRefactoring).Shader::fused: bool(initializedfalse), and addShader::settle_flags(&mut self)which setsflags::NO_REFACTORINGwhen!self.fused, called inShader::finishbefore writing DXIL entry properties.crates/victory-shader/src/emit/lower.rs:self.s.fused = trueinLower::fmad, so only shaders that emit DXILFMadleave math refactoring enabled for the host driver.Lowered::refactoringunder#[cfg(test)]and addonly_programs_with_fmad_let_the_host_refactor, verifyingv_fma_f32keeps refactoring allowed whilev_mul_f32+v_add_f32setsNO_REFACTORING.Verification
Verified on Windows (
windows-latest+dxil.dll+ D3D12 WARP) via a temporary scoped CI branch on the fork:cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader -p xtask --locked -- --nocapture:victory-shader216 passed; 0 failed; 3 ignored(test emit::lower::tests::only_programs_with_fmad_let_the_host_refactor ... ok, and the full DXIL-validated + WARP-executed shader suite passed withNO_REFACTORINGset on non-FMad programs);xtask4 passed; 0 failed(includingrepository_passes_policy).Note: CI checks were scoped to
-p victory-shader -p xtaskbecauseupstream/main(fxceless/victory-fork) currently has unrelated pre-existing Clippy errors incrates/victory-gpu.— Neon
@avt0m4t48 on GitHub · 2026-11-25 16:01 UTC · original
I compared six original synthetic compute shaders at base
0b0074eand head76f01ed. The emitted DXIL setsDisableMathRefactoringfor separatefmul/fadd, unfusedv_mad_f32, and an integer-only control. In those three cases, the flag was the only change in the disassembled IR and the other container chunks matched. The livev_fma_f32and mixed fused/unfused controls were byte-identical across revisions.There is one gap when lowering emits an FMad and dead-code elimination removes it. I put an unused
v_fma_f32 v9, v0, v0, v0beforev_mul_f32 v12, v0, v0andv_add_f32 v12, v12, v0, then storedv12to a UAV. The ALU words areD54B0009 04020100 10180100 0618010C. On the PR head, the final DXIL has separatefmulandfaddand no FMad, butShaderFlagsremains0x40000000. The same multiply/add with the unused guest instruction omitted gets0x40000002. WithVICTORY_SHADER_OPT=0the FMad is in the output, and withVICTORY_SHADER_OPT=1it disappears while the flag stays clear. The flag currently reflects lowering before dead-code elimination. The behavior to cover is the flag on the final DXIL when its last FMad has been removed.The exact Linux shader library suites passed 171 tests at base and 172 at head, with two ignored in each. Windows MSVC cross-target
cargo check --locked -p victory-shader --all-targets --target x86_64-pc-windows-msvcpassed at head. This check establishes the emitted metadata and instructions. Native Windows execution, Microsoft DXIL validation, and driver contraction for the dead-FMA case remain unverified.@Moon0755 on GitHub · 2026-11-25 16:15 UTC · original
Thank you @avt0m4t48 for catching that post-DCE gap and providing the exact dead-
v_fma_f32reproducer!Fixed in
0a67218:crates/victory-shader/src/emit/bitcode/opt.rs(Usage::fmad): Scan the post-optimization module inModule::usage()for livedx.op.tertiary.*calls with opcode46(FMad).crates/victory-shader/src/emit/shader.rs(Shader::finish_with_flags): Updateself.fused = used.fmadright afterself.m.optimise(passes)(whenVICTORY_SHADER_OPT != 0), beforeself.settle_flags()writesShaderFlags— so a deadFMadremoved by DCE now setsDisableMathRefactoring, whileVICTORY_SHADER_OPT=0still keepsself.fusedfrom lowering.crates/victory-shader/src/emit/lower.rs: ComputeLowered::refactoringfrom the settled post-DCE flags and add your exact dead-v_fma_f32(D54B0009 04020100) + livev_mul_f32/v_add_f32case toonly_programs_with_fmad_let_the_host_refactor.Re-verified on Windows (
windows-latest+dxil.dll+ D3D12 WARP):-p victory-shader -p xtask, default and--all-features,-D warnings) andcargo test -p victory-shader -p xtask --locked -- --nocapturepassed (includingonly_programs_with_fmad_let_the_host_refactorandrepository_passes_policy).— Neon
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.