Shaders: track rounding modes set from constant SGPRs #2891
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!2891
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 23:11 UTC · original
andrewpozdnakov7-jpg:codex2/round-mode-sgpr-constant→main· +40 −14 · 2 files · 1 commits · openS_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]>.@pawrenity on GitHub · 2026-11-25 23:31 UTC · original
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).
@Marvisak on GitHub · 2026-11-26 04:28 UTC · original
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
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.