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

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2782 into main
andrewpozdnakov7-jpg commented 2026-11-25 20:21:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T20:21:35Z.


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]>.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5498544509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T20:21:35Z. --- 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7173446623) 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]>`.
kotekompotek commented 2026-11-25 21:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:38:06Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173960392 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7173960392). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:38:06Z. --- 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.
oni-swr commented 2026-11-25 21:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:57:30Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174418376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7174418376). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:57:30Z. --- 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).
fuzeofficlal commented 2026-11-25 22:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:05:19Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174595339 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7174595339). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:05:19Z. --- 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**.
Marvisak commented 2026-11-26 00:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:24:01Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177507000 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7177507000). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:24:01Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 03:08:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:08:24Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::read_fp_round_mode_field_after_each_setting: 1 passed, 0 failed (RTX 5090 hardware + WARP).
  • 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068021353 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#pullrequestreview-6068021353). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:08:24Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::valu_tests::read_fp_round_mode_field_after_each_setting`: **1 passed, 0 failed** (RTX 5090 hardware + WARP). - `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).
fuzeofficlal commented 2026-11-27 00:53:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:53:22Z.

Review: CHANGES_REQUESTED


s_getreg_b32 selector decoding (MODE[3:2] offsets (2, 1), (3, 1), (2, 2)) and bit extraction match RDNA2, and read_fp_round_mode_field_after_each_setting passes on both RTX 5090 and WARP (clippy and xtask policy also pass).

Two functional issues need fixing before merge (plus a minor formatting nit):

  1. Whole-wave sections skip mode16 updates (crates/victory-shader/src/emit/lower.rs:1367-1375)

    • When self.sections emits j in i + 1..end via section_inst and jumps i = end, round16_after is not applied to instructions inside the section. A s_round_mode inside a whole-wave section (e.g., s_or_saveexec_b32; s_round_mode 0xc; restore EXEC; s_getreg_b32) leaves self.mode16 stale, so s_getreg_b32 silently reads 0 instead of 3. Updating self.mode16 across i + 1..end avoids stale reads.
  2. Destination guard misses EXEC_HI (lower.rs:3566, :3581)

    • inst.write(Reg::S(EXEC)).is_some() || self.is_mask(lo) only checks EXEC_LO (EXEC) and st.masks, missing EXEC_HI / st.highs in Wave64, and writing a numeric constant into VCC can turn a downstream s_cbranch_vccnz into a per-lane bit test rather than a wave-wide nonzero check.

Minor formatting nit: rustfmt --edition 2024 --check flags crates/victory-shader/src/emit/lower.rs:3586 and crates/victory-shader/src/emit/valu_tests.rs:252.

<!-- greyfinch-sync:Marvisak/VIctory:review:6082090808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#pullrequestreview-6082090808). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:53:22Z. **Review:** CHANGES_REQUESTED --- `s_getreg_b32` selector decoding (`MODE[3:2]` offsets `(2, 1)`, `(3, 1)`, `(2, 2)`) and bit extraction match RDNA2, and `read_fp_round_mode_field_after_each_setting` passes on both RTX 5090 and WARP (`clippy` and `xtask policy` also pass). Two functional issues need fixing before merge (plus a minor formatting nit): 1. **Whole-wave sections skip `mode16` updates (`crates/victory-shader/src/emit/lower.rs:1367-1375`)** - When `self.sections` emits `j in i + 1..end` via `section_inst` and jumps `i = end`, `round16_after` is not applied to instructions inside the section. A `s_round_mode` inside a whole-wave section (e.g., `s_or_saveexec_b32; s_round_mode 0xc; restore EXEC; s_getreg_b32`) leaves `self.mode16` stale, so `s_getreg_b32` silently reads `0` instead of `3`. Updating `self.mode16` across `i + 1..end` avoids stale reads. 2. **Destination guard misses `EXEC_HI` (`lower.rs:3566`, `:3581`)** - `inst.write(Reg::S(EXEC)).is_some() || self.is_mask(lo)` only checks `EXEC_LO` (`EXEC`) and `st.masks`, missing `EXEC_HI` / `st.highs` in Wave64, and writing a numeric constant into `VCC` can turn a downstream `s_cbranch_vccnz` into a per-lane bit test rather than a wave-wide nonzero check. Minor formatting nit: `rustfmt --edition 2024 --check` flags `crates/victory-shader/src/emit/lower.rs:3586` and `crates/victory-shader/src/emit/valu_tests.rs:252`.
andrewpozdnakov7-jpg commented 2026-11-27 06:35:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T06:35:10Z.


Thanks @fuzeofficlal. 7102a71 advances the rounding mode through whole-wave sections. The added shader reads MODE[3:2] after s_round_mode 0xc inside one of those sections. It returned 0 on c891413 and now returns 3 on WARP.

The lowering also rejects s_getreg_b32 directly into either half of EXEC or VCC before simulating a section, and checks high halves of tracked lane masks. The tests cover all four architectural destinations, including the high halves under wave64, and the existing MODE field selections.

All three focused tests, strict all-features shader Clippy, and the asset policy check passed locally. AI-assisted with Codex. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211661538 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2782#issuecomment-7211661538). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T06:35:10Z. --- Thanks @fuzeofficlal. [7102a71](https://github.com/Marvisak/VIctory/pull/2782/commits/7102a710cab4a61fa1deb0d3e8a389ed52fded96) advances the rounding mode through whole-wave sections. The added shader reads `MODE[3:2]` after `s_round_mode 0xc` inside one of those sections. It returned 0 on `c891413` and now returns 3 on WARP. The lowering also rejects `s_getreg_b32` directly into either half of EXEC or VCC before simulating a section, and checks high halves of tracked lane masks. The tests cover all four architectural destinations, including the high halves under wave64, and the existing MODE field selections. All three focused tests, strict all-features shader Clippy, and the asset policy check passed locally. AI-assisted with Codex. Synthetic shaders only.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2782:upstream-pr/2782'
git switch 'upstream-pr/2782'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2782'
git switch 'upstream-pr/2782'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2782'
git switch 'upstream-pr/2782'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2782'
git switch 'main'
git merge --squash 'upstream-pr/2782'
git switch 'main'
git merge --ff-only 'upstream-pr/2782'
git switch 'main'
git merge 'upstream-pr/2782'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2780
No description provided.