Shaders: lower v_div_scale_f64 and its lane mask #2973

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/2975 into main
andrewpozdnakov7-jpg commented 2026-11-26 01:58:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T01:58:35Z.


Summary

  • Lower the GFX10 VOP3B v_div_scale_f64 instruction and write its binary64 result and scale mask.
  • Apply the measured exponent thresholds, normalize subnormals as needed, and honor the four known f64 rounding modes. The lowering uses paired i32 words and keeps subnormals under VIctory's current f64 denormal model.

Verification

  • The same synthetic shader test fails on main at VOP3B opcode 0x16e. The patch matches all 68 result pairs and masks across 27 instruction forms on Agility WARP with DXIL validation. The cases cover both operand roles, explicit SGPR and VCC masks, directed rounding, special values, and modifiers.
  • WARP suites passed 35 VALU tests, 35 shader semantics tests (one ignored), and 33 lowerer tests. Default/all-features strict Clippy and asset policy passed.
  • Both division tests also passed with the exact #2953 head after retaining both lowerer entries and module declarations in a local composition.

References: RDNA2 hardware observations, directed downscale measurements, and clamp/OMOD characterization.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617806521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T01:58:35Z. --- ## Summary - Lower the GFX10 VOP3B v_div_scale_f64 instruction and write its binary64 result and scale mask. - Apply the measured exponent thresholds, normalize subnormals as needed, and honor the four known f64 rounding modes. The lowering uses paired i32 words and keeps subnormals under VIctory's current f64 denormal model. ## Verification - The same synthetic shader test fails on main at VOP3B opcode 0x16e. The patch matches all 68 result pairs and masks across 27 instruction forms on Agility WARP with DXIL validation. The cases cover both operand roles, explicit SGPR and VCC masks, directed rounding, special values, and modifiers. - WARP suites passed 35 VALU tests, 35 shader semantics tests (one ignored), and 33 lowerer tests. Default/all-features strict Clippy and asset policy passed. - Both division tests also passed with the exact #2953 head after retaining both lowerer entries and module declarations in a local composition. References: [RDNA2 hardware observations](https://github.com/boykopovar/AnyPS5/pull/474), [directed downscale measurements](https://github.com/boykopovar/AnyPS5/pull/24629), and [clamp/OMOD characterization](https://github.com/boykopovar/AnyPS5/pull/663).
fuzeofficlal commented 2026-11-26 03:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:10:44Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll, VICTORY_D3D12_DEBUG=1) — clean implementation and ready to merge:

  • Pure 32-bit integer bit-level lowering in crates/victory-shader/src/emit/lower/div_scale.rs (zero f64 DXIL ops, zero pred::ONE predicates, preserves SFI0 flags), keeping emit/lower.rs at 520,966 B (+403 B, 3,322 B below the 512 KiB cap).
  • Correctly handles exponent difference thresholds (delta >= 768 / <= -768, de == 0, de >= 2045, ne <= 53), value == denominator selection after neg modifiers, subnormal renormalization via unaryBits.i32, subnormal downscale rounding across all 4 IEEE rounding modes, ±0.0 -> canonical -qNaN, clamp, and VCC/lane-mask tracking (Val::Missing("a lane mask read as data")).
  • Merge-order note with #2953: functionally complementary to #2953 (v_div_fixup_f64), with 3 small adjacent text overlaps in emit/lower.rs (module declaration, opcode match, and identical operand64_dwords helper).

Local verification:

  • victory-shader (binary64_division_scale_returns_both_words_and_lane_mask + lower::tests + related): 51/51 passed on both RTX 5090 and WARP (dxil.dll + DEBUG=1)
  • cargo clippy --all-targets -- -D warnings (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067626597 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975#pullrequestreview-6067626597). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:10:44Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`, `VICTORY_D3D12_DEBUG=1`) — clean implementation and ready to merge: - Pure 32-bit integer bit-level lowering in `crates/victory-shader/src/emit/lower/div_scale.rs` (zero `f64` DXIL ops, zero `pred::ONE` predicates, preserves SFI0 flags), keeping `emit/lower.rs` at **520,966 B** (`+403 B`, **3,322 B** below the 512 KiB cap). - Correctly handles exponent difference thresholds (`delta >= 768` / `<= -768`, `de == 0`, `de >= 2045`, `ne <= 53`), `value == denominator` selection after `neg` modifiers, subnormal renormalization via `unaryBits.i32`, subnormal downscale rounding across all 4 IEEE rounding modes, `±0.0` -> canonical `-qNaN`, `clamp`, and `VCC`/lane-mask tracking (`Val::Missing("a lane mask read as data")`). - **Merge-order note with #2953**: functionally complementary to #2953 (`v_div_fixup_f64`), with 3 small adjacent text overlaps in `emit/lower.rs` (module declaration, opcode `match`, and identical `operand64_dwords` helper). **Local verification**: - `victory-shader` (`binary64_division_scale_returns_both_words_and_lane_mask` + `lower::tests` + related): **51/51 passed** on both **RTX 5090** and **WARP** (`dxil.dll` + `DEBUG=1`) - `cargo clippy --all-targets -- -D warnings` (default & `--all-features`) + `cargo xtask policy` (`191 files ok`): 0 warnings
kotekompotek commented 2026-11-26 03:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:32:10Z.

Review: COMMENTED


Verified: consistent with #2953's div_fixup model — the mask marks lanes needing fixup, both aliased-input forms (src0=den vs src0=num) are covered, and the round-mode limit table matches (nearest saturates to inf, directed modes saturate sign-side, toward-zero takes max-finite both ways). The subnormal rounding window (exponents 117-128, shift 1-12 so all discarded bits stay in lo) is correctly reasoned. Note: this adds the same operand64_dwords refactor as #2953 — the second to merge gets a trivial conflict.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067782369 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975#pullrequestreview-6067782369). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:32:10Z. **Review:** COMMENTED --- Verified: consistent with #2953's div_fixup model — the mask marks lanes needing fixup, both aliased-input forms (src0=den vs src0=num) are covered, and the round-mode limit table matches (nearest saturates to inf, directed modes saturate sign-side, toward-zero takes max-finite both ways). The subnormal rounding window (exponents 117-128, shift 1-12 so all discarded bits stay in lo) is correctly reasoned. Note: this adds the same operand64_dwords refactor as #2953 — the second to merge gets a trivial conflict.
steven-seagull27 commented 2026-11-26 03:05:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:29:41Z.


I ran v_div_scale_f64 from ce620efb and v_div_fixup_f64 from #2953 (f0f5fb5b) in the same wave32 compute shader. The scale result supplied the first operand of fixup. Both the physical RTX 5080 and Microsoft WARP matched all 5,688 lane records per adapter.

  • Restored EXEC and scale flags. I tried both operand roles and both mask destinations (VCC and s20), at numerator-minus-denominator exponent differences −769, −768, −767, 0, 767, 768 and 769. After executing both instructions on even lanes and restoring EXEC, v_cndmask_b32 read back 0x55555555 at both ±768 thresholds and zero at ±767. The inactive lanes retained both sentinel dwords. With full EXEC the corresponding masks were 0xffffffff and zero. All 1,792 records matched, including the quotient-sign repair.
  • Rounding across the two output dwords. I read back scale and fixup separately for 3,896 input/mode rows, covering both signs and all four rounding modes. These included normalization at every one of the 52 subnormal fraction-bit positions, downscaling across exponent fields 116–130, and halfway cases where rounding carries out of the low dword. For example, downscaling 0x08000001ffffffff gave 0x0008000100000000 for nearest-even and toward +∞, and 0x00080000ffffffff for toward zero and toward −∞. Both instructions returned those bits.

The rounding reference used exact rational power-of-two scaling and the adjacent binary64 values for directed rounding. For exponent field 116 I used the overflow behavior measured on the RX 6900 XT. These synthetic shaders exercise the handoff with a supplied preliminary quotient. Their DXIL validated and the containers requested neither double-precision instructions, double extensions nor int64. Related RDNA2 hardware measurement

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180855094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975#issuecomment-7180855094). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T02:29:41Z. --- I ran `v_div_scale_f64` from `ce620efb` and `v_div_fixup_f64` from #2953 (`f0f5fb5b`) in the same wave32 compute shader. The scale result supplied the first operand of fixup. Both the physical RTX 5080 and Microsoft WARP matched all 5,688 lane records per adapter. - **Restored EXEC and scale flags.** I tried both operand roles and both mask destinations (VCC and `s20`), at numerator-minus-denominator exponent differences −769, −768, −767, 0, 767, 768 and 769. After executing both instructions on even lanes and restoring EXEC, `v_cndmask_b32` read back `0x55555555` at both ±768 thresholds and zero at ±767. The inactive lanes retained both sentinel dwords. With full EXEC the corresponding masks were `0xffffffff` and zero. All 1,792 records matched, including the quotient-sign repair. - **Rounding across the two output dwords.** I read back scale and fixup separately for 3,896 input/mode rows, covering both signs and all four rounding modes. These included normalization at every one of the 52 subnormal fraction-bit positions, downscaling across exponent fields 116–130, and halfway cases where rounding carries out of the low dword. For example, downscaling `0x08000001ffffffff` gave `0x0008000100000000` for nearest-even and toward +∞, and `0x00080000ffffffff` for toward zero and toward −∞. Both instructions returned those bits. The rounding reference used exact rational power-of-two scaling and the adjacent binary64 values for directed rounding. For exponent field 116 I used the overflow behavior measured on the RX 6900 XT. These synthetic shaders exercise the handoff with a supplied preliminary quotient. Their DXIL validated and the containers requested neither double-precision instructions, double extensions nor int64. [Related RDNA2 hardware measurement](https://github.com/boykopovar/AnyPS5/pull/24629)
Marvisak commented 2026-11-26 06:03:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:26:05Z.


Automated triage for the maintainers.

Merge candidate (recommending a look, not approving). This lowers v_div_scale_f64 (VOP3B 0x16e), which main refuses, in a new crates/victory-shader/src/emit/lower/div_scale.rs: it computes the ±128 exponent scale and the lane mask from the exponent difference (±768) and the denominator and numerator edge cases, handles zero inputs, normalizes and rounds subnormals under the f64 rounding mode, and applies clamp. I compared the cases with the ISA pseudocode. Where they differ (for example the mask on a zero denominator, or overflow below exponent 117), the new semantics_tests.rs test pins the values the PR cites from RDNA2 hardware measurements in the AnyPS5 oracle, which semantics_tests.rs on main already cites. A commenter ran it together with #2953 (v_div_fixup_f64) and got matching results, and the two PRs only touch neighbouring lines. CI check passes.

Small request: the comment As measured on RDNA2 (#663) in div_scale_f64 reads as VIctory issue #663; please write it as AnyPS5 #663, as the test does.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183481774 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975#issuecomment-7183481774). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:26:05Z. --- <!-- victory-triage v1 head=ce620efb6cdbba46f06a8d44c1e05a0958c54a10 verdict=merge-candidate at=2026-11-26T05:27:30Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not approving). This lowers `v_div_scale_f64` (VOP3B 0x16e), which `main` refuses, in a new `crates/victory-shader/src/emit/lower/div_scale.rs`: it computes the ±128 exponent scale and the lane mask from the exponent difference (±768) and the denominator and numerator edge cases, handles zero inputs, normalizes and rounds subnormals under the f64 rounding mode, and applies clamp. I compared the cases with the ISA pseudocode. Where they differ (for example the mask on a zero denominator, or overflow below exponent 117), the new `semantics_tests.rs` test pins the values the PR cites from RDNA2 hardware measurements in the AnyPS5 oracle, which `semantics_tests.rs` on `main` already cites. A commenter ran it together with #2953 (`v_div_fixup_f64`) and got matching results, and the two PRs only touch neighbouring lines. CI `check` passes. Small request: the comment `As measured on RDNA2 (#663)` in `div_scale_f64` reads as VIctory issue #663; please write it as AnyPS5 #663, as the test does. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 08:02:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T07:10:26Z.

Review: APPROVED


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

  • cargo test -p victory-shader binary64_division_scale_returns_both_words_and_lane_mask -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6069872881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2975#pullrequestreview-6069872881). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T07:10:26Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + `dxil.dll`): - `cargo test -p victory-shader binary64_division_scale_returns_both_words_and_lane_mask -- --test-threads=1` (RTX 5090 & WARP): 1 passed, 0 failed on both. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2975:upstream-pr/2975'
git switch 'upstream-pr/2975'

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