Shaders: lower v_ldexp_f16 (VOP2 0x3b and VOP3 0x13b) #1223
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!1223
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1223"
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?
@ESAT586 on GitHub · 2026-11-24 16:31 UTC · original
ESAT586:shader/ldexp-f16→main· +109 −1 · 2 files · 1 commits · openWhat's wrong
v_ldexp_f16(VOP20x3b/ VOP30x13b) is decoded ingfx10/opcodes.rsbut not lowered incrates/victory-shader/src/emit/lower.rs, causing shaders scaling half-precision values by powers of two (HLSLldexponmin16float/float16_t) to fail lowering.Fix
v_ldexp_f16invalu16/valu16_op:abs/negmodifiers onS1(which is a signed 16-bit integer exponent), while honoringabs[0]/neg[0]/opsel[0]onS0viahalf_fsrcandopsel[1]onS1viahalf_src(sign-extended fromi16toi32).eto[-64, 64]and construct the exact f32 power of two(e + 127) << 23before multiplying in f32:2^eis always a finite positive normal f32,±0 * 2^estays±0(never0 * inf = NaN) and±inf * 2^estays±inf(neverinf * 0 = NaN).[2^-24, 65504], soe >= 64always overflows f16 to±inf(2^-24 * 2^64 = 2^40) ande <= -64always underflows f16 to±0(65504 * 2^-64 < 2^-47).legacyF32ToF16rounds toward zero on host drivers (saturating finite overflows to0x7BFFinstead of±inf), promote finite results with|r| >= 65520.0(the binary16 round-to-nearest-even overflow threshold) to signed±infbeforefloat_result.float_result(legacyF32ToF16+write_half, preserving the untouched half and honoring VOP3clampandopsel[3]).emit::valu_tests::v_ldexp_f16_matches_rdna2incrates/victory-shader/src/emit/valu_tests.rstesting VOP2 normals, subnormals (0x0001 * 2^24,1.0 * 2^-15), overflow/underflow (i16::MAX,i16::MIN),±0 * 2^32767,±inf * 2^-32768,NaN, and VOP3abs[0] + opsel:[1,0,0,1] + clamp.Verification (Real GPU + WARP + CI Gates)
Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver
32.0.16.1656), Rust1.98.1:cargo test -p victory-shader --lib v_ldexp_f16_matches_rdna2: ok (dxil.dllvalidator + RTX 3060 Ti hardware + Microsoft WARP)cargo test -p victory-shader --locked: 121 passed, 0 failed, 1 ignoredcargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)cargo xtask policy:asset policy: 154 files okScope & Non-Overlap
#157coversv_ldexp_f32; no open PR or issue coversv_ldexp_f16.423310ed21to921092c908@pablogonz12 on GitHub · 2026-11-24 17:03 UTC · original
Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main
ffe310eplus #1017 — main's host build is broken without it (E0425 host_resourceinvictory-gpu), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped.No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you lower, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).
Not tested: in-game.
@Zipettte on GitHub · 2026-11-24 17:59 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
ba53233:cargo test -p victory-shaderpasses, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 01:19 UTC · original · edited 2026-11-26 05:35 UTC
Automated triage for the maintainers.
Merge candidate. The rebase is clean against current
main. The PR lowersv_ldexp_f16in the half-precision VALU path ofLower(victory-shader/src/emit/lower.rs), whichmaindecodes (gfx10/opcodes.rs, 0x03b) but does not translate: it sign-extends the 16-bit exponent, clamps it to [-64, 64] (wide enough for every finite f16 result to overflow or underflow correctly, while 02^e and inf2^e never hit 0*inf), multiplies in f32 by an exact power of two and narrows once throughfloat_result, so rounding, denormal mode and clamp follow the shader's MODE. It rejects abs/neg on the integer exponent operand.v_ldexp_f16_matches_rdna2covers normal, subnormal, overflow, underflow, signed zero, infinity, NaN, and the VOP3 op_sel/abs/clamp forms with the other half of the register left alone; the expected values follow the public RDNA2 ISA definition (S0.f16 * 2^S1.i16).CI: passing. Recommending a look, not approving.
Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 11:21 UTC · original
Rebased onto \main\ (\
940d32f) at $sha. Verified on RTX 3060 Ti + WARP: \_ldexp_f16_matches_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.@ESAT586 on GitHub · 2026-11-25 12:57 UTC · original
Addressed triage review at $sha: dropped the extra |r| >= 65520 -> ±inf\ override and outdated \legacyF32ToF16\ comment so \loat_result\ →
arrow16\ handles overflow/rounding according to the shader's \MODE\ (keeping all overflow test cases). Verified on RTX 3060 Ti + WARP: \_ldexp_f16_matches_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.
@fuzeofficlal on GitHub · 2026-11-26 15:26 UTC · original · approved these changes
The clamped power-of-two f32 scaling (
emit/lower.rs:7003-7025) is exact for all finite f16 inputs with zero double rounding (verified exhaustively across all 63,490 non-NaN half encodings × 136 exponents = 8,634,640 combinations against direct half round-to-nearest-even) and preserves±0,±Inf, and NaNs across extreme signedi16exponents while deferring rounding/overflow tofloat_result->narrow16.Non-blocking follow-up notes:
valu_tests.rs:2297-2304, the e64 fixture exercisesop_selon VOP3-promoted0x13b(v_ldexp_f16); on RDNA2 (section 6.2 / Table 21), half selection/preservation on promoted VOP2 ops is encoded via SDWA (WORD_1+dst_unused:PRESERVE), so an SDWA fixture alongside legal e64abs/clamp(and notingomodstays safely refused infloat_result) would tighten coverage.rustfmt --edition 2024 --checkflags new linesvalu_tests.rs:2307, 2337, 2348.emit/lower.rsafter merging ontoorigin/mainis522,152 B(2,136 Bunder cap; note stacking with#2160would exceed524,288 Bby1,082 B).Local verification at
921092c9(and cleanly merged ontoorigin/mainatd86cca0e):xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets(defaultand--all-features, 0 warnings),census_tests(1/1), andemit::valu_testson both RTX 5090 and WARP (36/36, includingv_ldexp_f16_matches_rdna2) all passed. Approving.@Dukestar69 on GitHub · 2026-11-26 19:11 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).[-64, 64]so2^eis always a normal finite f32 (preserving±0,±inf, and NaN semantics), rejecting float modifiers on the integer exponent operand, and multiplying in f32 beforefloat_resultcleanly handles both VOP20x3band VOP30x13b.cargo test -p victory-shader --lib emit::valu_tests::v_ldexp_f16 -- --test-threads=1: passed on RTX 5090 andVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.