Round unsigned shader conversions once (port of Marvisak/VIctory#2186) #2018

Open
github-bot wants to merge 2 commits from github-bot/gh-2018 into main AGit
Owner

@⁠xiepeixuan on GitHub · 2026-11-29 07:34 UTC · original
xiepeixuan:auto/v-cvt-f32-u32 → main · +98 −2 · 4 files · 2 commits · open

No issue in this repo. Upstream context: FIND-5 in Marvisak/VIctory#1633.

What it changes

The AMD RDNA 2 ISA reference, §12.8, p. 138 specifies V_CVT_F32_U32 as “0.5ULP accuracy” and D.f = (float)S0.u. WARP can misround a full-width DXIL unsigned cast. The lowering converts the two 16-bit halves separately and computes hi * 65536 + lo. Both casts and the scaled high half are exact, so only the sum rounds.

Ported from Dmitrii (Razdva122), Marvisak/VIctory#2186, merged commit 084d4ff3ae (original b21594a4). The WARP test uses all 34 U32_EDGES values and the 50 midpoint/reported cases: 82 distinct inputs after deduplication, compared exactly with (x as f32).to_bits().

Player-visible effect: The RTX 5080 report in Marvisak/VIctory#2186 found that the plain cast already rounded correctly on NVIDIA hardware: 0xffffff7f returned 0x4f7fffff before and after the fix. No visible change is expected on NVIDIA GPUs. The fix makes WARP match hardware bit-for-bit on the tested inputs and keeps the WARP regression exact. Cost: five DXIL operations instead of one per v_cvt_f32_u32. Physical-GPU performance was not measured.

How it was tested

  • Same-base comparison: upstream main 716a0c99d4c616c0b5f9a1b8b068af58ddb85f03 and rebased head dc3dd4e1d7fd69718515fc0c22b4a1491199871b. Synthetic GFX10 Wave32, CPU evaluator and D3D12 WARP only; no physical GPU or game run.
  • WARP: main + tests only failed (exit 101): 0xde84975e returned 0x4f5e8498 instead of 0x4f5e8497. The rebased head passed (exit 0) and matched all 82 inputs.
  • Portable Linux: main + tests only failed at 0x01000001 (exit 101); the rebased head passed (exit 0).
  • Unfiltered cargo test -p victory-shader --locked: Linux 295 → 296 passed, 0 failed and 2 ignored on both. Windows 457 → 459 passed, 5 failed and 9 ignored on both. The five Windows failures were the same device/readback tests on both revisions.
Failing Windows test Plain main Rebased head
emit::intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves Failed Failed
emit::wave64_tests::cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only Failed Failed
emit::wave64_tests::nv05d1_native_readlane_gpu_reference Failed Failed
emit::wave64_tests::one_console_wave_divergent_loop_lds_widens_for_one_and_two_block_loops Failed Failed
emit::wave64_tests::one_console_wave_divergent_loop_wave_ops_widen_for_one_and_two_block_loops Failed Failed
  • Windows cargo check --workspace --locked passed on both revisions. Both strict configurations stopped only at diagnostics also present on main: unused_imports (PAIR_MEETINGS and analysis::lane_regions), clippy::while_immutable_condition, and clippy::too_many_arguments. Default Clippy also reported dead_code (unwind_copy) on both. All-features Clippy comparison.

Checked for overlap

Other uses checked

The GFX10 opcode table and VALU dispatch are unchanged; only v_cvt_f32_u32 gets new arithmetic. v_cvt_f32_i32, the four v_cvt_f32_ubyte* paths, and the shared fmad and write_f implementations and their other callers are unchanged, including output modifiers and lane guards. The other uses found are synthetic shader fixtures. The existing shader source fingerprint invalidates cached DXIL on rebuild; no cache key or switch changed.

Opened as a draft early so others know this is being worked on (README: 'Opening a draft pull request early works too').

AI-assisted (Codex). Not run in the game.

**@⁠xiepeixuan** on GitHub · 2026-11-29 07:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2018) `xiepeixuan:auto/v-cvt-f32-u32` → `main` · +98 −2 · 4 files · 2 commits · open No issue in this repo. Upstream context: FIND-5 in Marvisak/VIctory#1633. ## What it changes The [AMD RDNA 2 ISA reference, §12.8, p. 138](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf#page=138) specifies `V_CVT_F32_U32` as “0.5ULP accuracy” and `D.f = (float)S0.u`. WARP can misround a full-width DXIL unsigned cast. The lowering converts the two 16-bit halves separately and computes `hi * 65536 + lo`. Both casts and the scaled high half are exact, so only the sum rounds. Ported from [Dmitrii (Razdva122)](https://github.com/Razdva122), [Marvisak/VIctory#2186](https://github.com/Marvisak/VIctory/pull/2186), [merged commit 084d4ff3ae](https://github.com/Marvisak/VIctory/commit/084d4ff3aeade44017851a52220da5e9f004bd38) (original [b21594a4](https://github.com/Marvisak/VIctory/commit/b21594a44e8f483460e70e9c9014e55870d78884)). The WARP test uses all 34 `U32_EDGES` values and the 50 midpoint/reported cases: 82 distinct inputs after deduplication, compared exactly with `(x as f32).to_bits()`. **Player-visible effect:** The [RTX 5080 report in Marvisak/VIctory#2186](https://github.com/Marvisak/VIctory/pull/2186#issuecomment-7158148529) found that the plain cast already rounded correctly on NVIDIA hardware: `0xffffff7f` returned `0x4f7fffff` before and after the fix. No visible change is expected on NVIDIA GPUs. The fix makes WARP match hardware bit-for-bit on the tested inputs and keeps the WARP regression exact. Cost: five DXIL operations instead of one per `v_cvt_f32_u32`. Physical-GPU performance was not measured. ## How it was tested - Same-base comparison: upstream main `716a0c99d4c616c0b5f9a1b8b068af58ddb85f03` and rebased head `dc3dd4e1d7fd69718515fc0c22b4a1491199871b`. Synthetic GFX10 Wave32, CPU evaluator and D3D12 WARP only; no physical GPU or game run. - WARP: [main + tests only](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46316530805/job/141514569825) failed (exit 101): `0xde84975e` returned `0x4f5e8498` instead of `0x4f5e8497`. The [rebased head](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46316530805/job/141514570052) passed (exit 0) and matched all 82 inputs. - Portable Linux: [main + tests only](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46316530805/job/141514570079) failed at `0x01000001` (exit 101); the [rebased head](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46316530805/job/141514570124) passed (exit 0). - Unfiltered `cargo test -p victory-shader --locked`: Linux **295 → 296 passed**, 0 failed and 2 ignored on both. Windows **457 → 459 passed**, 5 failed and 9 ignored on both. The five Windows failures were the same device/readback tests on both revisions. | Failing Windows test | Plain main | Rebased head | | --- | --- | --- | | `emit::intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves` | Failed | Failed | | `emit::wave64_tests::cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only` | Failed | Failed | | `emit::wave64_tests::nv05d1_native_readlane_gpu_reference` | Failed | Failed | | `emit::wave64_tests::one_console_wave_divergent_loop_lds_widens_for_one_and_two_block_loops` | Failed | Failed | | `emit::wave64_tests::one_console_wave_divergent_loop_wave_ops_widen_for_one_and_two_block_loops` | Failed | Failed | - Windows `cargo check --workspace --locked` passed on both revisions. Both strict configurations stopped only at diagnostics also present on main: `unused_imports` (`PAIR_MEETINGS` and `analysis::lane_regions`), `clippy::while_immutable_condition`, and `clippy::too_many_arguments`. Default Clippy also reported `dead_code` (`unwind_copy`) on both. [All-features Clippy comparison](https://github.com/xiepeixuan/VIctory-NVIDIA/actions/runs/46317144685). ## Checked for overlap - [x] PRs: #2011, #2001, #1972, #1967, #1935, #1894, #1866, #1811, #1809, #1538, #1537, #1527, #1504, #978, #831, #822, #479, #348, #246. Triage map: [#1138](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/1138). - None duplicates the unsigned-cast fix or its exact WARP regression. ## Other uses checked The GFX10 opcode table and VALU dispatch are unchanged; only `v_cvt_f32_u32` gets new arithmetic. `v_cvt_f32_i32`, the four `v_cvt_f32_ubyte*` paths, and the shared `fmad` and `write_f` implementations and their other callers are unchanged, including output modifiers and lane guards. The other uses found are synthetic shader fixtures. The existing shader source fingerprint invalidates cached DXIL on rebuild; no cache key or switch changed. Opened as a draft early so others know this is being worked on (README: '[Opening a draft pull request early works too](https://github.com/trustno1-coder/VIctory-NVIDIA/blob/d4599073159082b0eba33c711ab25e2977ef3458/README.md)'). AI-assisted (Codex). Not run in the game.
Port Dmitrii (Razdva122) in Marvisak/VIctory#2186 (084d4ff3aeade44017851a52220da5e9f004bd38).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 07:37:49 +00:00
github-bot force-pushed github-bot/gh-2018 from d2917a17cf to dc3dd4e1d7 2026-11-29 22:12:29 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2018/head:github-bot/gh-2018'
git switch 'github-bot/gh-2018'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2018'
git switch 'github-bot/gh-2018'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2018'
git switch 'github-bot/gh-2018'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2018'
git switch 'main'
git merge --squash 'github-bot/gh-2018'
git switch 'main'
git merge --ff-only 'github-bot/gh-2018'
git switch 'main'
git merge 'github-bot/gh-2018'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2018
No description provided.