Shader: the ray test's triangle multiplies stay apart from their adds #1901
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1903"
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 Marvisak/VIctory. Originally posted by kais7654 on 2026-11-25T00:28:54Z.
Problem
The three BVH intersection tests fail on NVIDIA hardware (
bvh_tests.rs:787),one to three ULPs off in t's numerator (and occasionally a barycentric), while
WARP matches the reference word for word.
Replaying the failing inputs shows the reference (strict, per-operation
rounding, the instruction's documented behavior) is bit-identical to the
driver only if every
fmulfeeding afadd/fsubis contracted into anFMA. And indeed the emitted DXIL carries no fast-math flags — the ops are
precise (DXC emits plain
fmul/faddforprecise,fmul fastotherwise) —yet the driver's DXIL compiler contracts them anyway.
Fix
In the triangle test (
crates/victory-shader/src/emit/lower/bvh.rs), themultiplies that feed a following add or sub (the sheared products, the edge
products and t's three summands) are emitted as
dx.op.tertiary.f32(FMad, opcode 46) over a zero:
FMad(a, b, z)rounds exactly like the plaina * b, but the call is opaque to the fusion pass, so each add keeps its ownrounding. The addend is a zero the driver cannot see through — a
selectdriven by the direction's own comparison, over
+0.0and-0.0(both roundthe product alike); a constant zero would fold straight back into the
multiplication.
The box test and the remaining products are untouched: nothing there feeds an
add.
Testing
and on WARP, hardware and warp each (e.g. 2093 boxes and 324 triangles
hit, equal).
cargo test -p victory-shader --lib -- --test-threads=1:225 passed; the 4 remaining failures are pre-existing on
main(
02fcf5b) and outside this change.cargo clippy -p victory-shader --all-targets: clean.bvh.rs(23 insertions, 7 deletions).Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T01:06:11Z.
AMD RDNA3 (RX 7800 XT) test report for #1903 at head
cbafed53merged withmain42363ab6(clean merge).Result: regression on RX 7800 XT hardware — the 3 BVH intersection tests pass on
main42363ab6, and all 3 fail by 1 ULP ontwith #1903.Tested
hardware adapter fuses FMad: true), Ryzen 7 5700X3D, 64 GB RAM, Windows 11 Pro 26200, Rust 1.100.0 MSVC, debug build.origin/main42363ab6:cargo test -p victory-shader --lib bvh_tests -- --test-threads=1 --nocapture: 14 passed, 0 failed, 0 ignored (1.17s). Both hardware and WARP matched the reference on all 3 GPU intersection tests (551 boxes / 76 triangles,519 boxes / 74 triangles,2093 boxes / 324 triangles,1070 boxes / 138 triangles).cbafed53merged with42363ab6):cargo test -p victory-shader --lib bvh_tests -- --test-threads=1 --nocapture: 11 passed, 3 failed, 0 ignored (0.49s):emit::bvh_tests::intersections_on_nodes_in_title_memory_equal_the_reference(bvh_tests.rs:787):hardware: type 1, Ray { extent: 5.0, origin: [6.125, 0.890625, 0.359375], dir: [-1.0, -0.796875, -0.796875], inv: [-1.0, -1.254902, -1.254902] }left: [1118671093, 1092638436, 1079331024, 1076591664]vsright: [1118671094, 1092638436, 1079331024, 1076591664]emit::bvh_tests::intersections_on_the_gpu_equal_the_reference(bvh_tests.rs:787): identical mismatch (left[0] = 1118671093vsright[0] = 1118671094).emit::bvh_tests::intersections_with_64_bit_pointers_on_the_gpu_equal_the_reference(bvh_tests.rs:787):hardware: type 3, Ray { extent: 5.0, origin: [-6.421875, -5.90625, -7.171875], dir: [0.203125, 0.5, -0.0625], inv: [4.923077, 2.0, -16.0] }left: [1140801401, 1105748384, 1088566368, 1092953536]vsright: [1140801402, 1105748384, 1088566368, 1092953536]cargo test -p victory-shader --lib -- --test-threads=1 --nocapture: 243 passed, 3 failed, 3 ignored (34.84s; the 3 failures are only the 3 BVH tests above; 6no console [or PC] compiler; skipped+ 1warp: no pipeline for a wave of 32; skipped).cargo clippy -p victory-shader --all-targets: clean.Not tested
victory-shader, or a game run.AI use
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:47:13Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. Ray-test triangle multiplies kept apart from adds (no FMA contraction) — precision-preserving for the intersection math; suite green.
Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T02:06:55Z.
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
cbafed5applied cleanly onto currentmainccfb029.cargo test -p victory-shader --locked: 133 passed, 0 failed, 2 ignored. All tests pass.cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on mainccfb029). The PR introduces no new clippy warnings.Not tested: Windows MSVC build, the title itself. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:18:14Z.
Automated triage for the maintainers.
Needs work. The triangle test's multiplies in
Lower::bvh(emit/lower/bvh.rs) are now emitted as FMad (opcode 46) over a run-time zero, so a driver cannot contract them with the following add or sub.What changed: the zero now carries the product's sign,
(bits(a) ^ bits(b)) & 0x8000_0000, instead of a+0.0select. That answers the earlier signed-zero point. By my readingFMad(a, b, z)now gives the plain product's rounding whether or not the driver fuses it.What is still open:
t; they pass onmain. The sign change only affects zero products, so it does not obviously explain a 1 ULP difference int. Please rerun the three tests on AMD hardware on this head.bvh_tests.rsdoes.smulduplicatesLower::fmadinlower.rs. Calling that helper would be shorter.An offline translate run on the earlier head reported no change in validated count. CI: passing (WARP).
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:34:27Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
cbafed53ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
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.