victory-shader: flush denormal inputs in v_cube* instructions #623

Open
github-bot wants to merge 1 commit from github-bot/gh-623 into a-publier AGit
Owner

@⁠SalmanBarkat on GitHub · 2026-11-27 14:42 UTC · original
SalmanBarkat:fix/cube-ftz-denormals → a-publier · +75 −1 · 2 files · 1 commits · open

The DXIL lowering of \ _cubeid_f32, \ _cubesc_f32, \ _cubetc_f32, and \ _cubema_f32\ fed raw float coordinates into major-axis comparisons and coordinate arithmetic. Adapters that preserve 32-bit denormals treated subnormal axes as nonzero magnitudes and propagated un-flushed denormal results, diverging from the console's FTZ float mode.

Summary

  • Add \Lower::ftz_f32\ in \crates/victory-shader/src/emit/lower.rs\ to flush 32-bit subnormals to zero while preserving the sign bit.
  • Flush (x, y, z)\ operands via \ tz_f32\ in \ _cubeid_f32, \ _cubesc_f32, \ _cubetc_f32, and \ _cubema_f32.
  • Add \emit::valu_tests::cube_denormal_coordinates_flush_to_zero\ covering all four cube instructions across hardware and WARP.

Verification

  • \cargo test --locked -p victory-shader emit::valu_tests::cube_denormal_coordinates_flush_to_zero -- --exact\
  • \cargo test --locked -p victory-shader\ (304 passed, 4 ignored)
  • \cargo clippy --workspace --all-targets --locked -- -D warnings\
  • \cargo clippy --workspace --all-targets --all-features --locked -- -D warnings\
  • \cargo test -p xtask --locked\ (9 passed)
**@⁠SalmanBarkat** on GitHub · 2026-11-27 14:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/623) `SalmanBarkat:fix/cube-ftz-denormals` → `a-publier` · +75 −1 · 2 files · 1 commits · open The DXIL lowering of \ _cubeid_f32\, \ _cubesc_f32\, \ _cubetc_f32\, and \ _cubema_f32\ fed raw float coordinates into major-axis comparisons and coordinate arithmetic. Adapters that preserve 32-bit denormals treated subnormal axes as nonzero magnitudes and propagated un-flushed denormal results, diverging from the console's FTZ float mode. ## Summary - Add \Lower::ftz_f32\ in \crates/victory-shader/src/emit/lower.rs\ to flush 32-bit subnormals to zero while preserving the sign bit. - Flush \(x, y, z)\ operands via \ tz_f32\ in \ _cubeid_f32\, \ _cubesc_f32\, \ _cubetc_f32\, and \ _cubema_f32\. - Add \emit::valu_tests::cube_denormal_coordinates_flush_to_zero\ covering all four cube instructions across hardware and WARP. ## Verification - \cargo test --locked -p victory-shader emit::valu_tests::cube_denormal_coordinates_flush_to_zero -- --exact\ - \cargo test --locked -p victory-shader\ (304 passed, 4 ignored) - \cargo clippy --workspace --all-targets --locked -- -D warnings\ - \cargo clippy --workspace --all-targets --all-features --locked -- -D warnings\ - \cargo test -p xtask --locked\ (9 passed)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:47:23 +00:00
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 15:38 UTC · original · reviewed

Tested on an RTX 3060 Ti (Windows 11, debug build), base 4eb6cfd against head 144e1ed.

base 4eb6cfd head 144e1ed
cube_denormal_coordinates_flush_to_zero, copied onto base fails on the card: hardware: v_cubesc_f32 case 0 got 0x80000001 (the v_cubeid_f32 cases pass) passes on the card and on WARP
cargo test -p victory-shader --lib 304 passed, 4 ignored
cargo clippy -p victory-shader --all-targets -- -D warnings, with and without --all-features clean

On this card the base already picks the face you expect for a denormal axis, but it passes the denormal through to the coordinate: v_cubesc_f32 of (-denormal, 0, 0) comes out -denormal instead of -0. So the card treats it as zero in the comparisons and keeps its bits where the value is only moved. With the flush, the two agree.

One question about the premise. Whether the console flushes these inputs depends on the program's float mode, which the translator doesn't model:

  • lower.rs:5803 says so ("MODE is not modelled").
  • The RDNA2 reference at valu_tests.rs:1694 was measured "with f32 denormals kept".
  • s_denorm_mode is dropped at ir.rs:1486.

The program's FLOAT_MODE is in COMPUTE_PGM_RSRC1, which native.rs already reads for the VGPR count. For a program that runs with f32 denormals kept, this flush would make v_cube* differ from the console. I can't check here which mode titles use.

It conflicts with #618, #611, #578 and #502, all in valu_tests.rs. With #618, both PRs add a test at the end of the file.

**@⁠lvndrpup** on GitHub · 2026-11-27 15:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/623#pullrequestreview-6090464695) · **reviewed** Tested on an RTX 3060 Ti (Windows 11, debug build), base `4eb6cfd` against head `144e1ed`. | | base `4eb6cfd` | head `144e1ed` | |---|---|---| | `cube_denormal_coordinates_flush_to_zero`, copied onto base | fails on the card: `hardware: v_cubesc_f32 case 0 got 0x80000001` (the `v_cubeid_f32` cases pass) | passes on the card and on WARP | | `cargo test -p victory-shader --lib` | | 304 passed, 4 ignored | | `cargo clippy -p victory-shader --all-targets -- -D warnings`, with and without `--all-features` | | clean | On this card the base already picks the face you expect for a denormal axis, but it passes the denormal through to the coordinate: `v_cubesc_f32` of `(-denormal, 0, 0)` comes out `-denormal` instead of `-0`. So the card treats it as zero in the comparisons and keeps its bits where the value is only moved. With the flush, the two agree. One question about the premise. Whether the console flushes these inputs depends on the program's float mode, which the translator doesn't model: - `lower.rs:5803` says so ("MODE is not modelled"). - The RDNA2 reference at `valu_tests.rs:1694` was measured "with f32 denormals kept". - `s_denorm_mode` is dropped at `ir.rs:1486`. The program's `FLOAT_MODE` is in `COMPUTE_PGM_RSRC1`, which `native.rs` already reads for the VGPR count. For a program that runs with f32 denormals kept, this flush would make `v_cube*` differ from the console. I can't check here which mode titles use. It conflicts with #618, #611, #578 and #502, all in `valu_tests.rs`. With #618, both PRs add a test at the end of the file.
Author
Owner

@⁠SalmanBarkat on GitHub · 2026-11-27 16:06 UTC · original

That is a good distinction to call out. Two notes from checking the tree:

  1. Without flushing (x, y, z), hardware ( cmp treats subnormals as zero on SM 6.6) and WARP ( cmp preserves them) disagree on face selection, and even on hardware a coordinate moved without arithmetic ( _cubesc_f32 selecting x for (-denormal, 0, 0)) comes out -denormal even though comparisons treated that axis as
**@⁠SalmanBarkat** on GitHub · 2026-11-27 16:06 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/623#issuecomment-7222871110) That is a good distinction to call out. Two notes from checking the tree: 1. Without flushing (x, y, z), hardware ( cmp treats subnormals as zero on SM 6.6) and WARP ( cmp preserves them) disagree on face selection, and even on hardware a coordinate moved without arithmetic ( _cubesc_f32 selecting x for (-denormal, 0, 0)) comes out -denormal even though comparisons treated that axis as
Author
Owner

@⁠lvndrpup on GitHub · 2026-11-27 16:57 UTC · original

@⁠SalmanBarkat Your comment stops partway through note 1 ("…comparisons treated that axis as"), and note 2 is missing. Could you post the rest? Note 1 matches what I saw on the RTX 3060 Ti: v_cubesc_f32 gave 0x80000001 for that input before this PR and -0 with it.

**@⁠lvndrpup** on GitHub · 2026-11-27 16:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/623#issuecomment-7223867457) @⁠SalmanBarkat Your comment stops partway through note 1 ("…comparisons treated that axis as"), and note 2 is missing. Could you post the rest? Note 1 matches what I saw on the RTX 3060 Ti: `v_cubesc_f32` gave `0x80000001` for that input before this PR and `-0` with it.
This pull request can be merged automatically.
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/623/head:github-bot/gh-623'
git switch 'github-bot/gh-623'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-623'
git switch 'github-bot/gh-623'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-623'
git switch 'github-bot/gh-623'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-623'
git switch 'a-publier'
git merge --squash 'github-bot/gh-623'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-623'
git switch 'a-publier'
git merge 'github-bot/gh-623'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.