Shaders: preserve round mode changes in whole-wave sections #2884

Open
yumaste wants to merge 1 commit from upstream-pr/2886 into main
yumaste commented 2026-11-25 23:04:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yumaste on 2026-11-25T23:04:58Z.


## Summary

Whole-wave sections use a separate lowering path for their body. A rounding-mode write inside that body was skipped by the block's instruction-by-instruction tracking, so later FP16 conversions in the same block could use a stale mode.

Apply the existing round16_after transfer function to instructions in the section as well. Add a synthetic compute regression that selects round-toward-zero with s_round_mode and restores round-to-nearest-even with s_setreg_imm32_b32 in a second section. Both conversions run after EXEC is restored.

Validation

  • Before the fix, a positive input rounded to 0x3c00 instead of truncating to 0x3bff. The negative case also failed.
  • The regression passed on the hardware adapter and WARP. The semantics and whole-wave suites reported 42 passes, with one pre-existing ignored test.
  • Clippy passed for victory-shader with all targets and features and warnings denied.

AI-assisted (Codex). Validation used synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6615563296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886). Originally posted by [yumaste](https://github.com/yumaste) on 2026-11-25T23:04:58Z. --- ## Summary Whole-wave sections use a separate lowering path for their body. A rounding-mode write inside that body was skipped by the block's instruction-by-instruction tracking, so later FP16 conversions in the same block could use a stale mode. Apply the existing `round16_after` transfer function to instructions in the section as well. Add a synthetic compute regression that selects round-toward-zero with `s_round_mode` and restores round-to-nearest-even with `s_setreg_imm32_b32` in a second section. Both conversions run after EXEC is restored. ## Validation - Before the fix, a positive input rounded to `0x3c00` instead of truncating to `0x3bff`. The negative case also failed. - The regression passed on the hardware adapter and WARP. The semantics and whole-wave suites reported 42 passes, with one pre-existing ignored test. - Clippy passed for `victory-shader` with all targets and features and warnings denied. AI-assisted (Codex). Validation used synthetic shaders only.
kotekompotek commented 2026-11-26 00:03:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:34:37Z.

Review: COMMENTED


Correct: a MODE write inside a whole-wave section must take effect for the remaining section instructions — tracking round16_after per j while walking the section does that, and the test covers both s_round_mode and s_setreg restoring default. The before-behavior (entry mode for the whole section) was observably wrong for sectioned mode changes. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066474173 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886#pullrequestreview-6066474173). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:34:37Z. **Review:** COMMENTED --- Correct: a MODE write inside a whole-wave section must take effect for the remaining section instructions — tracking round16_after per j while walking the section does that, and the test covers both s_round_mode and s_setreg restoring default. The before-behavior (entry mode for the whole section) was observably wrong for sectioned mode changes. LGTM.
fuzeofficlal commented 2026-11-26 00:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:10:35Z.


Reviewed and verified 2aa17674 on Windows 11 (RTX 5090 + WARP + dxil.dll) against main (842b0cb):

  • Updating self.mode16 = round16_after(&p.blocks[b].insts[j], self.mode16) right after section_inst inside the whole-wave section loop preserves exact post-instruction rounding-mode semantics (s_round_mode / s_setreg_imm32_b32(HW_REG_MODE)).
  • Local checks: semantics_tests 35/35 passed (including whole_wave_sections_keep_rounding_mode_changes on RTX 5090 + WARP + dxil.dll), emit::lower::tests 33/33 passed, cargo clippy --locked -p victory-shader --all-targets -- -D warnings 0 warnings, cargo xtask policy (191 files ok; emit/lower.rs = 520,652 bytes).

Clean 1-line fix, ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177230739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886#issuecomment-7177230739). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:10:35Z. --- Reviewed and verified `2aa17674` on Windows 11 (RTX 5090 + WARP + `dxil.dll`) against `main` (`842b0cb`): - Updating `self.mode16 = round16_after(&p.blocks[b].insts[j], self.mode16)` right after `section_inst` inside the whole-wave section loop preserves exact post-instruction rounding-mode semantics (`s_round_mode` / `s_setreg_imm32_b32(HW_REG_MODE)`). - Local checks: `semantics_tests` 35/35 passed (including `whole_wave_sections_keep_rounding_mode_changes` on RTX 5090 + WARP + `dxil.dll`), `emit::lower::tests` 33/33 passed, `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` 0 warnings, `cargo xtask policy` (`191 files ok`; `emit/lower.rs` = `520,652` bytes). Clean 1-line fix, ready to merge.
Marvisak commented 2026-11-26 05:04:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:28:45Z.


Automated triage for the maintainers.

Merge candidate. The lowering loop in emit/lower.rs now updates mode16 with round16_after for instructions inside whole-wave sections, so an s_round_mode or MODE s_setreg inside a section is no longer lost for the rest of the block; this matches the block-entry analysis round16(), which already counts them. The test decodes correctly per the RDNA2 ISA and expects v_cvt_f16_f32 results to follow the mode per section.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182630329 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886#issuecomment-7182630329). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:28:45Z. --- <!-- victory-triage v1 head=2aa17674855c6089f017b656f01430b84bee9a44 verdict=merge-candidate at=2026-11-26T04:28:36Z --> Automated triage for the maintainers. **Merge candidate.** The lowering loop in `emit/lower.rs` now updates `mode16` with `round16_after` for instructions inside whole-wave sections, so an `s_round_mode` or MODE `s_setreg` inside a section is no longer lost for the rest of the block; this matches the block-entry analysis `round16()`, which already counts them. The test decodes correctly per the RDNA2 ISA and expects `v_cvt_f16_f32` results to follow the mode per section. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 10:04:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:28:52Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib whole_wave_sections_keep_rounding_mode_changes -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean one-line fix preserving rounding mode updates across whole-wave sections.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6071556078 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886#pullrequestreview-6071556078). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T09:28:52Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib whole_wave_sections_keep_rounding_mode_changes -- --test-threads=1`: passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Clean one-line fix preserving rounding mode updates across whole-wave sections. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 11:03:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:32:34Z.

Review: APPROVED


Updating self.mode16 = round16_after(&p.blocks[b].insts[j], self.mode16) inside the whole-wave section loop (emit/lower.rs:1372) aligns in-block lowering with the existing round16() block-entry analysis, and the regression verifies both s_round_mode and s_setreg_imm32_b32 mode changes before restoring EXEC. git merge-tree against current main (63bcca43) is clean, and emit/lower.rs is 520,652 bytes (under the 512 KiB limit).

Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, 2aa17674):

  • cargo run --locked -p xtask -- policy: passed (191 files ok)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean
  • whole_wave_sections_keep_rounding_mode_changes -- --test-threads=1 (RTX 5090 and VICTORY_WARP=1): 1 passed, 0 failed on both
<!-- greyfinch-sync:Marvisak/VIctory:review:6072499001 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2886#pullrequestreview-6072499001). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:32:34Z. **Review:** APPROVED --- Updating `self.mode16 = round16_after(&p.blocks[b].insts[j], self.mode16)` inside the whole-wave section loop (`emit/lower.rs:1372`) aligns in-block lowering with the existing `round16()` block-entry analysis, and the regression verifies both `s_round_mode` and `s_setreg_imm32_b32` mode changes before restoring `EXEC`. `git merge-tree` against current `main` (`63bcca43`) is clean, and `emit/lower.rs` is `520,652` bytes (under the 512 KiB limit). Verified locally on Windows 11 x64 (RTX 5090 + WARP + `dxil.dll`, `2aa17674`): - `cargo run --locked -p xtask -- policy`: passed (`191 files ok`) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): clean - `whole_wave_sections_keep_rounding_mode_changes -- --test-threads=1` (RTX 5090 and `VICTORY_WARP=1`): 1 passed, 0 failed on both
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/2886:upstream-pr/2886'
git switch 'upstream-pr/2886'

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/2886'
git switch 'upstream-pr/2886'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2886'
git switch 'upstream-pr/2886'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2886'
git switch 'main'
git merge --squash 'upstream-pr/2886'
git switch 'main'
git merge --ff-only 'upstream-pr/2886'
git switch 'main'
git merge 'upstream-pr/2886'
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!2884
No description provided.