Shader: the ray test's triangle multiplies stay apart from their adds #1903
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
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
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
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/Marvisak--VIctory!1903
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@kais7654 on GitHub · 2026-11-25 00:28 UTC · original
kais7654:shader/bvh-fma→main· +28 −7 · 1 files · 1 commits · openProblem
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).@oni-swr on GitHub · 2026-11-25 01:06 UTC · original
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
@Headache3318 on GitHub · 2026-11-25 02:06 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 08:18 UTC · original · edited 2026-11-25 16:47 UTC
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
@sinan-cmyk on GitHub · 2026-11-25 11:34 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head cbafed53 onto
main940d32f(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.