fix(shader): honor directed round32 in integer to f32 conversions #3039

Merged
CouchRiv merged 1 commit from upstream-pr/3039 into main 2026-10-11 06:35:24 +00:00
CouchRiv commented 2026-10-10 20:55:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-10T20:55:29Z.


What

AGC graphics: integer to f32 rounding: mode 1 lane 24 column 0 is 0xcf000000, expected 0xceffffff

v_cvt_f32_i32 and v_cvt_f32_u32 always used the host Convert to f32, which rounds to nearest even. On RDNA2 (gfx1036), when FLOAT_MODE bits 1:0 (round32) are 1, 2 or 3, integers with more than 24 significant bits round toward +inf, −inf or zero. Independent probes that change only bits 3:2 (round16) match every measured row, so only round32 matters. Nearest-even (round32 = 0) and shaders without a known float mode stay as on main.

The directed path builds the f32 bits from the integer magnitude (signed via absolute value, including INT_MIN), increments when discarded low bits are non-zero and the mode rounds away from zero, and handles significand overflow into the next exponent.

Tested

CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV gfx1036), lavapipe (Mesa llvmpipe).

  • agc_driver_integer_to_f32_rounding passes on NVIDIA, RADV and lavapipe (each under 1 s).
  • Without the Translation change, the same test fails with the line above (NVIDIA).
  • Sweep replay vs gfx1036 hardware rows (R1–R3 and M1, both opcodes, 32 rows each): 18 mismatches on main per driver, 0 on this branch, 0 regressions. M2–M4 batches for these cases were not present in the sweep; nearest-even coverage is M1.
  • python3 tools/check_conventions.py --base origin/main, git diff --check.

Not tested: clamp / omod / SDWA with directed round32, gfx1013, denorm fields other than the R/M1 settings above.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4814374148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3039). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-10T20:55:29Z. --- ### What ``` AGC graphics: integer to f32 rounding: mode 1 lane 24 column 0 is 0xcf000000, expected 0xceffffff ``` `v_cvt_f32_i32` and `v_cvt_f32_u32` always used the host `Convert` to f32, which rounds to nearest even. On RDNA2 (gfx1036), when `FLOAT_MODE` bits 1:0 (`round32`) are 1, 2 or 3, integers with more than 24 significant bits round toward +inf, −inf or zero. Independent probes that change only bits 3:2 (`round16`) match every measured row, so only `round32` matters. Nearest-even (`round32` = 0) and shaders without a known float mode stay as on `main`. The directed path builds the f32 bits from the integer magnitude (signed via absolute value, including `INT_MIN`), increments when discarded low bits are non-zero and the mode rounds away from zero, and handles significand overflow into the next exponent. ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV gfx1036), lavapipe (Mesa llvmpipe). - `agc_driver_integer_to_f32_rounding` passes on NVIDIA, RADV and lavapipe (each under 1 s). - Without the Translation change, the same test fails with the line above (NVIDIA). - Sweep replay vs gfx1036 hardware rows (R1–R3 and M1, both opcodes, 32 rows each): 18 mismatches on `main` per driver, 0 on this branch, 0 regressions. M2–M4 batches for these cases were not present in the sweep; nearest-even coverage is M1. - `python3 tools/check_conventions.py --base origin/main`, `git diff --check`. Not tested: `clamp` / `omod` / SDWA with directed `round32`, gfx1013, denorm fields other than the R/M1 settings above. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Silverash-i8 commented 2026-10-11 01:35:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:35:08Z.


Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto main d31b57a4 in one build with #3039, #3134, #3175 and #3194, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).

  • agc_driver_integer_to_f32_rounding passes on both GPUs.

Across all agc_* tests in that build, the only new failure on either GPU is agc_driver_flat_store, which comes from #3175 alone (reported there). The Intel failures besides it are the known ones from #2114 and #3207.

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104243946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3039#issuecomment-6104243946). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:35:08Z. --- Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto `main` d31b57a4 in one build with #3039, #3134, #3175 and #3194, on an RTX 5060 Laptop and the Arrow Lake iGPU (`ANYPS5_GPU=Intel`). - `agc_driver_integer_to_f32_rounding` passes on both GPUs. Across all `agc_*` tests in that build, the only new failure on either GPU is `agc_driver_flat_store`, which comes from #3175 alone (reported there). The Intel failures besides it are the known ones from #2114 and #3207. AI-assisted (Claude Code); I ran this on my machine.
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
boykopovar/AnyPS5!3039
No description provided.