Shaders: track rounding modes set from constant SGPRs #2889
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2891"
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?
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T23:11:37Z.
S_SETREG_B32can take the MODE value from a scalar register. Reuse the lowerer's constant proof for that operand, so the FP16/FP64 rounding analysis sees values written throughs_mov_b32ands_movk_i32. Both block-entry analysis and instruction lowering use the same result.The same synthetic
V_CVT_F16_F32test runs on app-local WARP SM 6.6 before and after. It sets round-to-zero through two scalar moves, converts, resets to nearest-even throughs_movk_i32, and converts again. On842b0cbfour of six inputs differ from the CPU model. For input0x3f801800, the two low halves are[0x3c01, 0x3c01]with[0x3c00, 0x3c01]expected. With this commit all six match, including positive and negative values, overflow, subnormal rounding, and signed zero. The existing literal MODE test, 35 VALU tests, DXIL validation, strict shader Clippy and the asset policy passed.I also combined the patch locally with #2886 at
2aa1767, keeping both fixtures and passing the lowerer to its whole-wave update. Both regression tests passed on WARP.RDNA 2 ISA · Coordination claim
Please retain the Git author when moving the patch. If you fold it into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:31:28Z.
Review: COMMENTED
Verified head
dbfe2c21cleanly merged ontoorigin/main(842b0cb7) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0dxil.dll).Code & Cross-PR Review
round16/round16_afterinsideLower::run(afterself.def_blockandself.x.st.guardsare built) and resolvings_setreg_b32/s_setreg_imm32_b32writes coveringhwreg(MODE=1)bits3:2vialower.konst_operandhandles inline constants, literals, and unguardeds_mov_b32/s_movk_i32chains while conservatively falling back toNoneon guarded definitions, partial bitfield writes, dynamic ALU/phi sources, or conflicting CFG joins.emit/lower.rsis520,513B (3,775B below the 512 KiB limit; cleanly compatible with#2893at521,232B combined).#2886): Because#2891updatesround16_afterto takelower: &Lower<'_>as its first parameter, if#2886lands alongside#2891,#2886's whole-wave section call site will need&selfadded to match.Local Verification
cargo test --locked -p victory-shader --lib semantics_tests: 35/35 passed (1 ignored) on RTX 5090 + WARP +dxil.dll, includingf16_rounding_follows_a_constant_setreg_source.cargo test --locked -p victory-shader --lib emit::lower::tests: 33/33 passed.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.cargo xtask policy:191 files ok.Looks clean and ready to merge.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:34:40Z.
Review: COMMENTED
Sound widening: a MODE write whose source is a constant SGPR is just as constant as a literal — resolving through konst_operand picks those up without treating runtime values as modes. The round16 field removal keeping mode16 as the live state is consistent. LGTM.
Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-25T23:31:38Z.
VERIFY-2891: verified
dbfe2c21(basemain842b0cb) on NVIDIA GeForce RTX 4070, Windows 11. The semantics harness ran both the hardware host (the 4070) and WARP.Review
off <= 2 && off + size >= 4), andinput >> (2 - off) & 3extracts those bits. Partial overlaps still giveNone, and writes that miss bits 3:2 keep the current mode.konst_operandhandlesLiteralitself, sos_setreg_imm32_b32behaves as before. For an SGPR source it walks unguardeds_mov_b32/s_movk_i32defs throughdef_block, which is filled inLower::new. That makes it safe to call fromround16at the start ofrun(), before any block is lowered. Other constant producers (s_or_b32and so on), phis and guarded moves still giveNone. That is conservative and matches the old behaviour.0xB9800881 | reg<<16is SOPK op 0x13 (s_setreg_b32), and simm160x0881is hwreg(id 1 = MODE, offset 2, size 2).0xB0020000iss_movk_i32 s2, 0. The harness disassembly confirms this. I also checked the expected values:0x3F801800is above the midpoint between 1.0 and the next f16 (RTZ gives0x3c00, RNE gives0x3c01).0x47800000= 65536 gives max finite0x7bffunder RTZ and inf under RNE.0x337FFFFFis just below 2^-24, so RTZ gives 0 and RNE gives0x0001.round16_after(inst, mode)call site, and this PR changes the function's signature. Whichever merges second needs the trivial rebase that the PR description mentions.Tests (PR head)
cargo test -p victory-shader --locked --lib -- emit::semantics_tests::f16_: 4 passed, including the newf16_rounding_follows_a_constant_setreg_source.cargo test -p victory-shader --locked --lib -- emit::semantics_tests: 35 passed, 1 ignored.cargo test -p victory-shader --locked --lib -- emit::lower: 33 passed.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.Without the fix (
842b0cbplus only thesemantics_tests.rshunk,--test-threads=1): the new test fails, with 4 of 6 inputs mismatching on both hardware and WARP. Both conversions come out RNE. For example,3f801800gives[3c01, 3c01]where[3c00, 3c01]is expected, and47800000gives[7c00, 7c00]where[7bff, 7c00]is expected. This matches the PR description.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:28:10Z.
Automated triage for the maintainers.
Merge candidate. FP16/FP64 round-mode tracking in
emit/lower.rs(round16_after,round16) now accepts ans_setreg_b32MODE source from a scalar register holding a proven constant via the existingkonst_operand, not only a literal; the field-coverage check is unchanged anddef_blockis built inLower::new, so the block-entry modes are safe to compute at the start ofrun. The test checks against an independent CPU model (to_f16) using synthetic encodings.CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:12:29Z.
Review: APPROVED
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-shader --lib f16_rounding -- --test-threads=1: passed on RTX 5090 and WARP (f16_rounding_follows_a_constant_setreg_source).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly resolves constant SGPR sources in
round16_aftervialower.konst_operandrather than matching only literal operands.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.