Shaders: lower v_div_fixup_f16 #379
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!379
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-379"
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?
@LouisRiverstone on GitHub · 2026-11-24 02:46 UTC · original
LouisRiverstone:shader-div-fixup-f16→main· +116 −0 · 2 files · 3 commits · openv_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.
@jeremygold02 on GitHub · 2026-11-24 04:15 UTC · original
Thanks @LouisRiverstone for adding this missing f16 fixup lowering. I tested head
dfaa5aaaf9398fcadfaa2af014802e2800da0398with: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.
@Lyrnc on GitHub · 2026-11-24 05:58 UTC · original
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
v_div_fixup_f16 v10, v4, v5, v6(quotient, denominator, numerator) on 1084 triples. 484 come from your value set plus0x7d00(a signalling NaN), with quotients0x4248,0xc248,0x7e00,0x7c01; the other 600 are random 16-bit triples. The destination was preset to0xdead0000. RDNA2 desktop silicon, not the console's. No game data.Fit: 1034/1084 match
div_fixup_f16_reference. All 50 that don't are the same case:0x7e000x3c000x3c000x7c000x7e000x3c000xbe000xfc000x7e000x00010x7bff0x7c000x7c010xbe000xbe000x7c00The result is
sign | 0x7c00, with the usual sign (denominator xor numerator). That fits the ISA's later "exponent of S0 all ones → overflow" step coming before "else |S0|". The zero, infinity and 0/0 cases come first, as in your reference: a NaN quotient with a zero numerator still gives a signed zero (matched).Other values seen: 0/0 and inf/inf give
0xfe00, and a NaN numerator or denominator comes back quieted with its payload (0x7d00→0x7f00,0xfe01→0xfe01), as your reference allows. The high half is kept:0xdeadon all 1084, which your test cannot see because it starts from 0.The same holds for
v_div_fixup_f32: a NaN quotient with1.0 / 1.0gives0x7f800000.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.
@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the hardware device of
run_cases(local adapter-selection patch, not part of this PR);cargo test -p victory-shader --release valu_testsat the PR head. Negative control: the PR's non-test files reverted to its merge base, its new tests kept.v_div_fixup_f16_follows_the_isa_special_casespass on both AMD GPUs.@LouisRiverstone on GitHub · 2026-11-24 10:40 UTC · original · edited 2026-11-24 10:52 UTC
Thanks @Lyrnc for the hardware run. The NaN-quotient case is fixed in
5ecb6ab.sign | 0x7c00(sign | infin f32), applied after the zero, infinity and invalid checks. A NaN quotient with a zero numerator still gives a signed zero, as you measured.div_fixup_f16_referencefollows the hardware for this case, and the inputs now include quotient0x7c01(sNaN).mainto resolve the conflict.cargo test -p victory-shader --releaseon Windows: 121 passed, 0 failed. Negative control: with only the lowering change reverted, the test fails withv_div_fixup_f16(0x7e00, 0x3c00, 0x3c00) = 0x7fff, want 0x7c00.v_div_fixup_f32isn't lowered onmainyet, so it has nothing to change for now.AI use: Claude Code (Claude Opus 5.5) wrote the fix and ran the tests.
@Halfect on GitHub · 2026-11-24 11:28 UTC · original
Independent check of the corrected head
5ecb6abon Windows 11:cargo test --locked -p victory-shader --lib -- --test-threads=1: 121 passed, 0 failed, 1 ignored.v_div_fixup_f16_follows_the_isa_special_cases: passed on the default D3D12 hardware adapter, covering all 400 quotient/denominator/numerator combinations, including the corrected NaN/sNaN-quotient overflow cases. DXIL validation passed as part of the test. WARP was unavailable, so no WARP result is claimed here.cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.cargo xtask policy: 154 files ok.No game data or title execution used.
@Lyrnc on GitHub · 2026-11-24 15:23 UTC · original
Re-checked
5ecb6abagainst the hardware, using the same encodings on both sides:v_div_fixup_f16on 1,414(q, den, num)triples. That's 6 quotients (0x4248,0xc248,0x7e00,0x7c01,0xfc00,0x7bff) against 13 edge values for den and num (zeros, ±inf, NaNs, denormals, max), plus 400 random triples.VOP3word throughbuild_valu_cs, on the RTX 5080 (610.88) and on the same Radeon iGPU (#94'sVICTORY_ADAPTER).So the NaN-quotient case now gives
sign | 0x7c00, as the hardware does. Every non-NaN result matches, including the signed zero for a NaN quotient with a zero numerator. The only differences are which NaN comes back (low 16 bits compared). No game data.AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them; the numbers are from those runs.
@Yaekai on GitHub · 2026-11-24 16:39 UTC · original
Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
5ecb6ab:cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 102 passed, 0 failed.cargo clippy -p victory-shader -- -D warnings: 0 warnings.1.0.2.1,--console series-s, 19-min world run): no regressions. Ready to merge!@Marvisak on GitHub · 2026-11-25 00:28 UTC · original · edited 2026-11-26 02:17 UTC
Automated triage for the maintainers.
Merge candidate. Rebased to
55019c8, which merges cleanly intomain. The change is the same one reviewed before.v_div_fixup_f16joins the f16 three-operand list incrates/victory-shader/src/emit/lower.rs, and the newdiv_fixupdoes the ISA's checks in the ISA's order on the exact f32 values: a NaN numerator, then a NaN denominator, comes back quieted; 0/0 and inf/inf give NaN; x/0 and inf/x give a signed infinity; 0/x and x/inf give a signed zero; an all-ones quotient exponent gives a signed infinity; anything else is |q| with the sign.mainhas no other lowering of this opcode. The NaN-quotient case is backed by Lyrnc's bit-for-bit comparison against gfx1036 hardware (only NaN payloads differ).v_div_fixup_f16_follows_the_isa_special_caseschecks 400 cases against a reference written from the ISA.CI: passing.
Generated by 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.