Shaders: read known FP16/FP64 rounding mode bits #2782

Open
github-bot wants to merge 1 commit from github-bot/gh-2782 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 20:21 UTC · original
andrewpozdnakov7-jpg:codex2/read-mode-round16 → main · +33 −0 · 2 files · 1 commits · open

A shader that reads the FP16/FP64 rounding field through S_GETREG_B32 stops translation on main. The lowering now extracts the requested bits from the same statically known MODE value used by FP16 arithmetic. It accepts a read of both rounding bits or either bit individually. AMD specifies that hardware-register reads place the result in the low bits of the destination. RDNA 2 ISA reference

The same synthetic readback on 13f91ca stops with unsupported s_getreg_b32. With this commit, all 12 cases return the expected values on app-local WARP SM 6.6 with the DXIL validator. The test sets all four rounding modes, reads the full field and its two one-bit slices, and gives FP32 a different rounding value.

All 32 VALU tests in the app-local run passed, including the runtime identity check. The existing FP16 rounding test passed before and after. Strict shader Clippy and staged asset policy passed. Coordination claim

Please retain the Git author on cherry-pick or rebase. If you fold this change into another commit, please include Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 20:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2782) `andrewpozdnakov7-jpg:codex2/read-mode-round16` → `main` · +33 −0 · 2 files · 1 commits · open A shader that reads the FP16/FP64 rounding field through `S_GETREG_B32` stops translation on main. The lowering now extracts the requested bits from the same statically known MODE value used by FP16 arithmetic. It accepts a read of both rounding bits or either bit individually. AMD specifies that hardware-register reads place the result in the low bits of the destination. [RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) The same synthetic readback on `13f91ca` stops with unsupported `s_getreg_b32`. With this commit, all 12 cases return the expected values on app-local WARP SM 6.6 with the DXIL validator. The test sets all four rounding modes, reads the full field and its two one-bit slices, and gives FP32 a different rounding value. All 32 VALU tests in the app-local run passed, including the runtime identity check. The existing FP16 rounding test passed before and after. Strict shader Clippy and staged asset policy passed. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please retain the Git author on cherry-pick or rebase. If you fold this change into another commit, please include `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:03 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:38 UTC · original

Selector decode matches the hwreg encoding (regid[5:0] | offset[10:6] | (size-1)[15:11]), MODE=1, and the [2,4) field bound correctly restricts reads to the tracked FP16/FP64 rounding bits while refusing unmodeled fields. The test's cross-check (FP32 set to mode^3) would catch reading the wrong field.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7173960392) Selector decode matches the hwreg encoding (regid[5:0] | offset[10:6] | (size-1)[15:11]), MODE=1, and the [2,4) field bound correctly restricts reads to the tracked FP16/FP64 rounding bits while refusing unmodeled fields. The test's cross-check (FP32 set to mode^3) would catch reading the wrong field.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:57 UTC · original

Independent WARP/CPU verification of head c89141382fdec3e7051650dfee5b4af78569c0e1 merged cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca.

Environment: Windows 11 x64, WARP/CPU only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11.

Tests (cargo test --no-fail-fast): victory-shader: 268 passed, 3 failed, 3 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test, which executes on the WARP device for all four rounding modes and three field slices). victory-shader baseline on origin/main: 267 passed, 3 failed, 3 ignored; the 3 failures (synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out) fail identically on origin/main under WARP, so they are not caused by this PR.

Negative control: disabling the s_getreg_b32 branch makes read_fp_round_mode_field_after_each_setting fail (lowering error); restored afterwards.

Clippy: cargo clippy -p <affected crates> --all-targets -- -D warnings clean (exit 0).
fmt: cargo fmt --check is not clean on origin/main itself (891 diff hunks across many files); this PR: 893 hunks (+2 vs main, in the touched files).

Review: Selector decode (id[5:0], offset[10:6], size-1[15:11]) is correct; only MODE[3:2] is modelled and any other register/field is rejected, and an unknown mode16 is rejected rather than guessed. Diff contains no game files, dumps, shader names or retail hashes.

AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7174418376) Independent WARP/CPU verification of head `c89141382fdec3e7051650dfee5b4af78569c0e1` merged cleanly onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`. **Environment:** Windows 11 x64, WARP/CPU only (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64 `dxil.dll` 1.8.2502.11. **Tests** (`cargo test --no-fail-fast`): victory-shader: 268 passed, 3 failed, 3 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test, which executes on the WARP device for all four rounding modes and three field slices). victory-shader baseline on `origin/main`: 267 passed, 3 failed, 3 ignored; the 3 failures (`synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) fail identically on `origin/main` under WARP, so they are not caused by this PR. **Negative control:** disabling the `s_getreg_b32` branch makes `read_fp_round_mode_field_after_each_setting` fail (lowering error); restored afterwards. **Clippy:** `cargo clippy -p <affected crates> --all-targets -- -D warnings` clean (exit 0). **fmt:** `cargo fmt --check` is not clean on `origin/main` itself (891 diff hunks across many files); this PR: 893 hunks (+2 vs main, in the touched files). **Review:** Selector decode (id[5:0], offset[10:6], size-1[15:11]) is correct; only MODE[3:2] is modelled and any other register/field is rejected, and an unknown `mode16` is rejected rather than guessed. Diff contains no game files, dumps, shader names or retail hashes. AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:05 UTC · original

Reviewed and verified c8914138 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

  • Decoding s_getreg_b32 (register, offset, width) and strictly accepting only register == 1 (MODE), offset >= 2, offset + width <= 4 while rejecting unknown/unmodeled fields and unknown dynamic/joined modes is clean and minimal.
  • (Merge-order note): textually clean git merge-tree against 13f91ca, #2743, and #2791, but since #2743 and #2791 change Lower::mode16 from Option<u8> to FpMode16 { round, denorm }, self.mode16.ok_or(...) (lower.rs:3384) will need to become self.mode16.round.ok_or(...) if merged after either of them.
  • cargo test --locked -p victory-shader --features host --lib -- valu_tests::: 31 passed, 0 failed (including read_fp_round_mode_field_after_each_setting across all 4 rounding modes × 3 bit slices on both RTX 5090 and WARP).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7174595339) Reviewed and verified `c8914138` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). - Decoding `s_getreg_b32` `(register, offset, width)` and strictly accepting only `register == 1` (`MODE`), `offset >= 2`, `offset + width <= 4` while rejecting unknown/unmodeled fields and unknown dynamic/joined modes is clean and minimal. - *(Merge-order note)*: textually clean `git merge-tree` against `13f91ca`, `#2743`, and `#2791`, but since `#2743` and `#2791` change `Lower::mode16` from `Option<u8>` to `FpMode16 { round, denorm }`, `self.mode16.ok_or(...)` (`lower.rs:3384`) will need to become `self.mode16.round.ok_or(...)` if merged after either of them. - `cargo test --locked -p victory-shader --features host --lib -- valu_tests::`: **31 passed, 0 failed** (including `read_fp_round_mode_field_after_each_setting` across all 4 rounding modes × 3 bit slices on both RTX 5090 and WARP). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:24 UTC · original

Automated triage for the maintainers.

This lowers s_getreg_b32 in emit/lower.rs for reads of MODE[3:2], the FP16/FP64 rounding field, from the statically tracked mode16. It refuses any other register or field, and also refuses when the mode is unknown. I checked the selector decode (id[5:0], offset[10:6], size-1[15:11], MODE = 1) against the public RDNA2 ISA and against round16_after, which decodes s_setreg the same way. The new test sets the FP32 field to a different value so that a read of the wrong field fails. One note: the value read is only as good as mode16's starting value (Some(0), which the FP16 arithmetic lowering already assumes). If #2743 or #2791 lands first, self.mode16.ok_or(...) needs to follow their FpMode16 change. CI passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7177507000) <!-- victory-triage v1 head=c89141382fdec3e7051650dfee5b4af78569c0e1 verdict=merge-candidate at=2026-11-25T23:23:49Z --> Automated triage for the maintainers. This lowers `s_getreg_b32` in `emit/lower.rs` for reads of MODE[3:2], the FP16/FP64 rounding field, from the statically tracked `mode16`. It refuses any other register or field, and also refuses when the mode is unknown. I checked the selector decode (id[5:0], offset[10:6], size-1[15:11], MODE = 1) against the public RDNA2 ISA and against `round16_after`, which decodes `s_setreg` the same way. The new test sets the FP32 field to a different value so that a read of the wrong field fails. One note: the value read is only as good as `mode16`'s starting value (`Some(0)`, which the FP16 arithmetic lowering already assumes). If #2743 or #2791 lands first, `self.mode16.ok_or(...)` needs to follow their `FpMode16` change. CI passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2782/head:github-bot/gh-2782'
git switch 'github-bot/gh-2782'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2782'
git switch 'github-bot/gh-2782'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2782'
git switch 'github-bot/gh-2782'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2782'
git switch 'main'
git merge --squash 'github-bot/gh-2782'
git switch 'main'
git merge --ff-only 'github-bot/gh-2782'
git switch 'main'
git merge 'github-bot/gh-2782'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2782
No description provided.