Shaders: match RDNA2 NaN bits for negative F16 logarithms #3204

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3206 into main
andrewpozdnakov7-jpg commented 2026-11-26 12:42:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T12:42:54Z.


AMD specifies 0xfe00 for v_log_f16(-1) and v_log_f16(-inf). A native RX 6700 XT sweep also records this word for negative nonzero inputs. In the current VIctory lowering the host logarithm supplies the NaN bits. WARP 1.0.22 returned 0xffff after narrowing. AMD RDNA 2 ISA · Native RDNA2 sweep

Select the documented quiet NaN for ordered x < 0 in the F16 log lowering. This keeps both zero signs on the existing logarithm path.

The same synthetic test on upstream 63bcca4 reported four mismatches for fc00, bc00, 8400, and 8001. With the fix all 11 input/output pairs pass on WARP 1.0.22 with D3D12 Agility 1.620.2. The controls cover both zero signs, a positive subnormal, powers of two and positive infinity. Every case checks that the high half of the destination is preserved.

cargo test --locked -p victory-shader --lib emit::valu_tests::v_log_f16_matches_rdna2_special_values -- --exact --test-threads=1

WARP suites passed (36 VALU, 34 semantics with 1 ignored), as did strict shader Clippy and cargo xtask policy. Physical GPU and in-game behavior were outside this run.

Claim in #1633

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6626888817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3206). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T12:42:54Z. --- AMD specifies `0xfe00` for `v_log_f16(-1)` and `v_log_f16(-inf)`. A native RX 6700 XT sweep also records this word for negative nonzero inputs. In the current VIctory lowering the host logarithm supplies the NaN bits. WARP 1.0.22 returned `0xffff` after narrowing. [AMD RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [Native RDNA2 sweep](https://github.com/ubiquitarianism/leonida/blob/a73a57e1339be072baf5522351c8ec7f1482b56b/docs/shader_validation.md#L1538-L1607) Select the documented quiet NaN for ordered `x < 0` in the F16 log lowering. This keeps both zero signs on the existing logarithm path. The same synthetic test on upstream `63bcca4` reported four mismatches for `fc00`, `bc00`, `8400`, and `8001`. With the fix all 11 input/output pairs pass on WARP 1.0.22 with D3D12 Agility 1.620.2. The controls cover both zero signs, a positive subnormal, powers of two and positive infinity. Every case checks that the high half of the destination is preserved. ```text cargo test --locked -p victory-shader --lib emit::valu_tests::v_log_f16_matches_rdna2_special_values -- --exact --test-threads=1 ``` WARP suites passed (36 VALU, 34 semantics with 1 ignored), as did strict shader Clippy and `cargo xtask policy`. Physical GPU and in-game behavior were outside this run. [Claim in #1633](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7192268506) AI-assisted with Codex.
Dukestar69 commented 2026-11-26 12:47:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:47:22Z.

Review: APPROVED


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

  • cargo test -p victory-shader --lib v_log_f16_matches_rdna2_special_values -- --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 fix matching RDNA2 NaN bits for negative F16 logarithms.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6074372044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3206#pullrequestreview-6074372044). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:47:22Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib v_log_f16_matches_rdna2_special_values -- --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 fix matching RDNA2 NaN bits for negative F16 logarithms. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 14:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T13:06:54Z.


WARP test report (claim: #1633)

  • Head: 5398738488fb9c0f9a5304ae22d6ba15516799e0, base: origin/main 63bcca43c6 (head sits directly on it, no merge needed)
  • Backend: WARP (VICTORY_D3D12_WARP=1). Windows 11, Rust per rust-toolchain.toml, cargo test --locked -p victory-shader --lib -- --test-threads=1, VICTORY_D3D12_WARP=1 and VICTORY_WARP=1 (the shader tests only honour the latter, so every device in the run was WARP; no physical GPU). Validator: Windows SDK 10.0.26100 dxil.dll. Synthetic word streams only, no game data.
  • victory-shader suite: 299 passed, 4 failed, 3 ignored. New test v_log_f16_matches_rdna2_special_values passes, not skipped (all 11 cases on WARP, including -inf, -1.0 and negative denormals expecting 0xfe00).
  • Control: with only the new test applied to main it fails on all four negative inputs (got 0xabcdffff, want 0xabcdfe00 for 0xfc00, 0xbc00, 0x8400, 0x8001). Suite on main alone: 298 passed, 4 failed, 3 ignored; the same 4 unrelated failures as on the PR (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out).
  • Review: no defect found. -0 and +0 are not < 0, so they still give -inf (0xfc00), and a NaN input is not < 0, so it still goes through the log. The 0xfe00 result relies on the host turning the f32 NaN 0xffc00000 into f16 0xfe00, which holds on WARP; the comment says so. I could not check other hosts.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192894360 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3206#issuecomment-7192894360). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T13:06:54Z. --- **WARP test report (claim: #1633)** - Head: `5398738488fb9c0f9a5304ae22d6ba15516799e0`, base: `origin/main` 63bcca43c6a0 (head sits directly on it, no merge needed) - Backend: WARP (VICTORY_D3D12_WARP=1). Windows 11, Rust per `rust-toolchain.toml`, `cargo test --locked -p victory-shader --lib -- --test-threads=1`, `VICTORY_D3D12_WARP=1` and `VICTORY_WARP=1` (the shader tests only honour the latter, so every device in the run was WARP; no physical GPU). Validator: Windows SDK 10.0.26100 `dxil.dll`. Synthetic word streams only, no game data. - `victory-shader` suite: **299 passed, 4 failed, 3 ignored**. New test `v_log_f16_matches_rdna2_special_values` passes, not skipped (all 11 cases on WARP, including -inf, -1.0 and negative denormals expecting 0xfe00). - Control: with only the new test applied to `main` it **fails** on all four negative inputs (`got 0xabcdffff, want 0xabcdfe00` for 0xfc00, 0xbc00, 0x8400, 0x8001). Suite on main alone: 298 passed, 4 failed, 3 ignored; the same 4 unrelated failures as on the PR (`a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_mask_high_address_bits_and_divergent_branches`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`). - Review: no defect found. `-0` and `+0` are not `< 0`, so they still give -inf (0xfc00), and a NaN input is not `< 0`, so it still goes through the log. The 0xfe00 result relies on the host turning the f32 NaN `0xffc00000` into f16 0xfe00, which holds on WARP; the comment says so. I could not check other hosts. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5).
Jackster commented 2026-11-26 16:06:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:06:35Z.


AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), victory-shader built with --features host:

  • On 63bcca4 with only the test applied, the hardware backend reports no mismatch — the card already returns 0xfe00 for the four negative cases; only WARP returns 0xffff.
  • With the PR both agree, 11/11.

So on AMD hardware this is a WARP/CI-facing fix. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197193351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3206#issuecomment-7197193351). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T16:06:35Z. --- AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), `victory-shader` built with `--features host`: - On 63bcca4 with only the test applied, the hardware backend reports no mismatch — the card already returns `0xfe00` for the four negative cases; only WARP returns `0xffff`. - With the PR both agree, 11/11. So on AMD hardware this is a WARP/CI-facing fix. Synthetic only. AI-assisted.
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/3206:upstream-pr/3206'
git switch 'upstream-pr/3206'

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