shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests #37
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!37
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/37/head"
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?
@alessiodeia on GitHub · 2026-11-23 23:30 UTC · original
alessiodeia:fix/valu-med3-fract-trig→main· +686 −6 · 3 files · 1 commits · merged 2026-11-24 00:38 UTCWhat
Addresses the remaining RDNA2 VALU semantic mismatches from #2 (leaving signed BFE untouched to avoid conflicting with #13):
v_med3_f32/v_med3_f16: returnmin3(a, b, c)whenever any operand is NaN (pred::UNOcheck), instead of IEEEminNum/maxNumreturning the larger non-NaN operand.v_fract_f32/v_fract_f16: clamp finite results past the largest representable value below1.0(>= 1.0→0x3F7F_FFFFfor f32;>= 1 - 2^-12(0x3F7F_F000) →0x3F7F_E000(0x3BFFin f16) for f16). Usespred::OGEagainst a threshold distinct from the clamped value so drivers (observed on NVIDIA Turing) do not foldr > C ? C : rintominNum(FMNMX) and swallow NaN.v_sin_f32/v_cos_f32/v_sin_f16/v_cos_f16: reduce revolutions viaa - Round_ne(a)into[-0.5, 0.5]before scaling by2π, fixing large-turn phase drift on NVIDIA while preserving±inf → NaNandNaN → NaN.crates/victory-shader/src/emit/valu_tests.rs): builds minimal GFX10 compute programs, runs them throughir::build→resource::track→io::raise→structure::structure→lower::lower, validates the emitted DXIL container withdxil.dllwhen present, and executes them viaHost::dispatchon both hardware GPU and WARP without requiring consoledxc.Tested
Windows 11 x64 (26300), Rust
1.98.1(--locked), NVIDIA GeForce RTX 2070 SUPER (driver617.42) + WARP +dxil.dll1.9.2609:v_med3_f32(1.0, 2.0, NaN)=2.0→ now1.0v_med3_f16(1.0, 2.0, NaN)=0x4000→ now0x3c00v_fract_f32(-1e-10)=0x3f800000(1.0) → now0x3f7fffff(andNaN/±infstayNaN)v_sin_f32(255.0)=-9.57e-5→ now< 1e-5v_sin_f16(65504.0)=-0.0245→ now0.0cargo test -p victory-shader --locked --offline: 63 passed, 0 failed (hardware GPU + WARP +dxil.dllvalidation).cargo test --workspace --locked --offline(skipping sandboxed socket testonly_loopback_is_reachable): all passed.cargo clippy -p victory-shader --all-targets --locked --offline -- -D warnings: 0 warnings.cargo --offline xtask policy:asset policy: 148 files ok.AI-assisted; no game assets were used.
@Sunkiller-qc on GitHub · 2026-11-23 23:46 UTC · original
Thanks for the thorough work and the GPU-run tests! Heads-up: main now has
36eb0b4and0b499d7, which cover med3-with-NaN, the fract clamp and turn reduction, so this conflicts inlower.rs. Main'strig_turns(lower.rs:1430on main) also keepssin(-0) = -0, whichturns_to_radhere loses because-0 - round_ne(-0)is+0, and it gives exact zeros at half and quarter turns. Two parts of this PR look like they'd still add value on top of main: (1) the NaN-preserving fract compare. Main'sfract(lower.rs:1413-1418) usesr > k ? k : rwith the same constant as threshold and clamp value, which is the exactminshape you describe NVIDIA folding intoFMNMX. YourOGEagainst a distinct threshold avoids that. (2) Thevalu_tests.rsharness running synthetic GFX10 programs on the GPU and WARP. Would you consider rebasing down to just those two, against main's helpers? Static review, not built or run.@alessiodeia on GitHub · 2026-11-23 23:53 UTC · original
@Sunkiller-qc Done! Rebased onto
main(d222b87) down to just those two changes:fract()inlower.rs: switched topred::OGEagainst a distinct threshold (1.0for f32,1 - 2^-12for f16) so NVIDIA's DXIL compiler does not foldr > k ? k : rintoFMNMX(minNum). Verified live againstmain(36eb0b4) on RTX 2070 SUPER wherev_fract_f32(NaN)returned0x3f7fffffandv_fract_f16(NaN)returned0x3bff; both now preserveNaN(and±inf -> NaN) on both RTX 2070 SUPER and WARP.valu_tests.rs: synthetic GFX10 → DXIL →dxil.dll→Host::dispatchGPU + WARP tests running againstmain's helpers (med3,fract,trig_turnsincludingsin(-0.0) == -0.0and exact+0.0at half/quarter turns, plusv_bfe_i32/v_bfe_u32/s_bfe_i32).cargo test -p victory-shader --locked --offlinepasses 64/64 (RTX 2070 SUPER + WARP +dxil.dll),cargo clippyis clean, andcargo xtask policypasses (149 files ok).@DaviTostes on GitHub · 2026-11-23 23:54 UTC · original
Tested
2e5001cstacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.mainalone does not build on Linux (E0425 invictory-gpu), so the check uses #39 as the base; the merge is clean.cargo test --workspace: 155 passed, 0 failed, 3 ignored, including the newcrates/victory-shader/src/emit/valu_tests.rscases (the 675-line synthetic VALU set) — no NaN/fract/trig regressions in the rest of the suite.AI-assisted (DeepSeek V4.1 Flash coding agent).
@lordon1a on GitHub · 2026-11-24 00:25 UTC · original
Verified
2e5001cf9on Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@35b054ec0) on two real D3D12 GPUs:1. NVIDIA GeForce RTX 3070 Ti Laptop GPU (
10de:24e0, driver616.64) — PASS (7/7)cargo xtask policy: 151 files okcargo test -p victory-shader valu_tests: 7 passed, 0 failed (v_med3_f32,v_med3_f16,v_fract_f32,v_fract_f16,v_sin_and_v_cos_f32,v_sin_and_v_cos_f16,bfe_signed_and_unsigned).crates/victory-shader/src/emit/lower.rstomainon the same RTX 3070 Ti): 5 passed, 2 failed — bothv_fract_f32_never_returns_oneandv_fract_f16_never_returns_onefail onmainand pass with this PR.2. Intel(R) Iris(R) Xe Graphics (
8086:46a6, driver32.0.101.7088) — 6/7 passed, 1 pre-existingmainmed3_f32 failurev_med3_f16,v_fract_f32,v_fract_f16,v_sin_and_v_cos_f32,v_sin_and_v_cos_f16,bfe_signed_and_unsigned: all pass.v_med3_f32_matches_rdna2_with_nan: fails onmain'smed3()with: (The PR's new test caught a real Intel Xe D3D12 driver /fcmp unoissue inmain'smed3()forf32;v_fract_*itself is completely green on Intel Xe too.)(Note: on dual-GPU laptops DXGI adapter 0 is Intel Iris Xe, so the RTX 3070 Ti run selected the discrete adapter locally via
IDXGIFactory6::EnumAdapterByGpuPreference.)AI-assisted.