Repository navigation
Shaders: lower v_div_fixup_f16 - #379
LouisRiverstone wants to merge 3 commits into
Conversation
|
Thanks @LouisRiverstone for adding this missing f16 fixup lowering. I tested head Result: 1 passed, 0 failed (69 filtered out). The synthetic quotient/denominator/numerator cases cover the ISA special-value rules for signed zeros, subnormal and finite values, infinities, and NaNs against the bit-based reference. This does not measure behavior on console hardware. |
|
RDNA2 hardware measurement against the test's reference: it matches everywhere except one case: a NaN quotient with a finite, non-zero numerator and denominator gives ±infinity on the hardware, not NaN. Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs Fit: 1034/1084 match
The result is Other values seen: 0/0 and inf/inf give The same holds for AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
|
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
|
The ISA's special cases in its order: a NaN numerator or denominator comes back quieted, 0/0 and inf/inf give NaN, x/0 and inf/x a signed infinity, 0/x and x/inf a signed zero, otherwise |S0| with the quotient's sign. Worked on the f32 values of the f16 operands, which are exact.
dfaa5aa to
f6da63f
Compare
|
Thanks @Lyrnc for the hardware run. The NaN-quotient case is fixed in 5ecb6ab.
AI use: Claude Code (Claude Opus 5.5) wrote the fix and ran the tests. |
The ISA's "exponent of S0 all ones -> overflow" check runs before the final |S0| case, so a NaN quotient with a finite, non-zero numerator and denominator gives sign | infinity, as measured on gfx1036 hardware. The zero, infinity and invalid checks still come first.
f6da63f to
5ecb6ab
Compare
|
Independent check of the corrected head
No game data or title execution used. |
catminou4
left a comment
There was a problem hiding this comment.
v_div_fixup_f16 is the fiddly one — NaN propagation (numerator first), 0/0 and inf/inf → NaN, x/0 and inf/x → signed infinity, 0/x and x/inf → signed zero, all-ones-exponent quotient → signed infinity (gfx1036 behavior, noted), else |q| with quotient sign. The select chain is ordered "last check to first" so the first matching rule wins, which is the correct way to encode the ISA's priority list, and the comment documents each rule.
Test quality is excellent: div_fixup_f16_reference is an independent Rust implementation of the ISA table, and the execution test sweeps 4 quotients × 10 den × 10 num = 400 cases including NaNs, asserting the high half stays untouched.
Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) green — the new valu_tests execution cases are #[cfg(windows)]-gated like the rest of that suite, so they will run on the Windows CI lane, not here.: 96 passed / 0 failed / 1 ignored (execution test Windows-gated).
Applied as the net diff of upstream PR Marvisak#379 (head 5ecb6ab), 2 commits: 5ecb6ab,85b04965.
|
Re-checked
So the NaN-quotient case now gives AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them; the numbers are from those runs. |
|
Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
|
…fied together Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053 Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402 (which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were merged by keeping both sides (additions next to each other); a PR was kept only if cargo clippy -p victory-shader --all-targets -- -D warnings still passed with it. No instruction name is handled in two places. Marvisak#98 is not in this version: an offline measurement on a retail dump showed it loses 31 programs that validate on Marvisak#1402. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (381 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Merge candidate. Rebased to CI: passing. Generated by Claude Code |
# Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed 55019c8e245ce429a354e348bb7081ffc684b610 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll).
The ISA special-case ordering (numerator NaN, denominator NaN, 0/0 & Inf/Inf, x/0 & Inf/x, 0/x & x/Inf, all-ones quotient exponent -> sign | Inf matching @Lyrnc's gfx1036 hardware run, then sign | |q|) is clean and well-tested across the 400-case table.
Non-blocking follow-up notes:
- For
0/0andInf/Inf,default_nan(0x7FC0_0000) narrows to0x7e00whereas RDNA2 specifies0xfe00(as @Lyrnc also observed ongfx1036); switching that constant to0xFFC0_0000would match the exact halfword too. - Adding a nonzero sentinel in the untouched destination halfword would exercise
op_sel[3]preservation, and movingdiv_fixupinto a child module underemit/lower/would recover ~2.8 KB ofemit/lower.rsheadroom (currently523,378 B, leaving910 Bbelow the524,288 Bcap, which exceeds the cap by696 Bif stacked with#1856).
Verification
cargo run -p xtask -- policy(191 files ok),cargo clippy(default &--all-features) clean, changed linesrustfmt-clean.emit::valu_tests(36/36 passed) andemit::census_tests(1/1 passed) on both RTX 5090 and WARP withdxil.dllactive (PR head and merged onto63bcca43).
Dukestar69
left a comment
There was a problem hiding this comment.
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib v_div_fixup_f16_follows_the_isa_special_casespassed on RTX 5090 and underVICTORY_WARP=1- Priority order of special cases (
numNaN ->denNaN ->0/0/inf/inf->x/0/inf/x->0/x/x/inf-> quotient overflow -> signed|q|) matches RDNA2V_DIV_FIXUP_F16semantics cleanly cargo clippy -p victory-shader --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
v_div_fixup_f16(VOP3 0x35f) was not lowered. Compilers emit it after every f16 division, so those programs failed to translate.It follows the ISA's checks, in the ISA's order. S0 is the quotient, S1 the denominator, S2 the numerator:
The operands are worked on as their f32 values, which are exact, and the result is narrowed like the other f16 three-operand ops: clamp applies, an output modifier is refused. #200 adds
v_div_fixup_f32in another part oflower.rs. This PR doesn't touch it, and the two don't conflict.Test:
v_div_fixup_f16_follows_the_isa_special_casesinvalu_tests.rs. It runs 300 cases on the host GPU and WARP and checks them against a reference written from the ISA on the f16 bits: three quotients (one of them NaN) × ten denominators × ten numerators, covering ±0, ±1.5, a subnormal, max finite, ±inf and ±NaN.dxil.dll10.0.26100 passes.lower.rschange it fails withUnsupported { what: "v_div_fixup_f16" }.cargo xtask policyare clean.No game files.
AI-assisted (Claude Code): I reviewed the change and ran the tests above.