Repository navigation
shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests - #37
Conversation
03a08bf to
ba987ad
Compare
|
Thanks for the thorough work and the GPU-run tests! Heads-up: main now has 36eb0b4 and 0b499d7, which cover med3-with-NaN, the fract clamp and turn reduction, so this conflicts in |
…ests Fixes a real-hardware NVIDIA bug in fract() from 36eb0b4 and adds synthetic GFX10 -> DXIL -> GPU/WARP regression tests for the RDNA2 VALU lowerings from Marvisak#2: - fract(): select(OGT(r, k), k, r) is folded by NVIDIA's DXIL compiler into FMNMX (minNum), which swallows NaN and turns v_fract_f32(NaN) into 0x3f7fffff (and v_fract_f16(NaN) into 0x3bff). Comparing with pred::OGE against a distinct threshold (1.0 for f32, 1 - 2^-12 for f16) prevents the minNum fold and preserves NaN and +/-inf -> NaN on both NVIDIA hardware and WARP. - valu_tests.rs: builds minimal synthetic GFX10 compute shaders, lowers them through the full pipeline (ir::build -> resource::track -> io::raise -> structure -> lower), validates with dxil.dll when present, and executes them via Host::dispatch on both hardware GPU and WARP without requiring console dxc. Covers v_fract_f32/f16, v_med3_f32/f16, v_sin/v_cos_f32/f16, and v_bfe_i32/u32 + s_bfe_i32. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
ba987ad to
2e5001c
Compare
|
@Sunkiller-qc Done! Rebased onto
|
|
Tested
AI-assisted (DeepSeek V4.1 Flash coding agent). |
|
Verified 1. NVIDIA GeForce RTX 3070 Ti Laptop GPU (
|
Adds host_waves: None to the Parts initializers added in main by Marvisak#37 and Marvisak#81, and disambiguates the duplicate mod tests introduced in host.rs on main. Co-authored-by: BlueKaiman <360454391+BlueKaiman@users.noreply.github.com>
shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests
…ard (no settle for them, frame ~10 % shorter) (Marvisak#37) When the title writes memory that in-flight submissions' shaders also write, and the copy has a card side, the layer put each changed run of bytes up to the card as a copy of its own, up to VICTORY_MERGE_RUNS (512), and above that settled the flights (waited for the card). The title changes tens to hundreds of thousands of runs of a few bytes a frame there, so the cap always overflowed: about one settle a frame, 55-100 ms of the submitting thread waiting for the card, on a card idle ~45 ms a frame. Now those bytes are merged on the card: - shadow.rs: `Masked::take` compares a page 8 bytes at a time and sets one bit per changed byte, per 64 KiB block of the copy (the CPU side `held` ends as before); `merge_under_writes` uses the mask for copies with a card side (they no longer count against the cap); `card_masked` hands the masks out per submission (and, with the relay, keeps them by send number so `card_merge_relay` leaves those bytes out bit by bit, as it does for ranges sent up). - host.rs: `CARD_MERGE` (cs_5_1), one thread per mask dword (32 bytes): card = (card & ~m) | (title & m), reading the title's bytes from the CPU side; bytes outside the mask keep what the shaders wrote. Recorded in the sync list where the per-run copies went (after the flights' lists, before this submission's), then the touched pieces are hashed again once each. Mask buffers in PC memory are reused once the fence passes the submission that read them (up to 32). Without the shader, a free buffer or a copy a multiple of 64 KiB, the same bytes go up as per-run copies as before. - VICTORY_MERGE_ON_CARD: on by default; =0 off; =alt 20 s on / 20 s off, said in the log, to measure both on one scene. Tests: a WARP test (random card and title bytes, over 3,000 random runs of 1-9 bytes crossing dwords, mask dwords and blocks): only the masked bytes change (checked to fail with a broken shader); unit tests: the mask has a bit for every changed byte and no other at any alignment; the relay merge keeps title bytes that went up through the merge. Measured on an RTX 3060 12 GB (Ryzen 5 5600GT), first rooms: - fxceless/victory-fork base with its frame-rate switches, two A/B pairs and three alternating runs: settles "title memory changed under shader writes" 1.17 -> 0.00 a frame, waiting for the card 58-61 -> 13 ms, usual frame 162-172 -> 139-140 ms; alternating runs -9.5 to -12.5 %. - This tree with the README preset (RELAY=2 etc.), one alternating run: frame-rate lines median 663 -> 472 ms, mean 886 -> 668 ms (a heavy, streaming stretch); the preset settles less for this reason to begin with (0.29 a frame). Pieces fetched after the compare unchanged (7.8-8.2 %); no device loss. Co-authored-by: Martin Hartfelder <contato@hexor.com.br>
…ts 189-190, and volume overlap guard (port Belobug Marvisak#195/Marvisak#37/Marvisak#7/Marvisak#21)
What
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.