fix(shader): round a 2-bit SNORM buffer store component away from zero at 0.5 #25877

Merged
Lyrnc merged 1 commit from upstream-pr/25877 into main 2026-11-27 18:37:41 +00:00
Lyrnc commented 2026-11-22 19:47:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Lyrnc on 2026-11-22T19:47:42Z.


What

The 2-bit component of 2_10_10_10_SNORM and 10_10_10_2_SNORM went through NormStoreBits like the wider SNORM components, which rounds to nearest even, so 0.5 and -0.5 stored 0. RDNA2 stores 1 and -1 for them. TwoBitSnormStoreBits now stores 1 with the value's sign for a magnitude of at least 0.5 and 0 otherwise (NaN included). 8-, 10- and 16-bit SNORM components keep nearest-even rounding, which the hardware also uses for them.

These formats are common for packed normals and tangents, where the 2-bit component carries the handedness sign.

Measured behaviour

A store sweep through tools/hw-oracle (default runtime vs HW_ORACLE_RUNTIME=vulkan) of tbuffer_store_format_xyzw in 75 data/number formats, reading the stored dwords back, differed only in these two formats, and only in the 2-bit component. Over 32 inputs (±0, ±0.1, ±0.25, ±0.4, ±0.49, ±0.4999999, ±0.5, ±0.5000001, ±0.51, ±0.75, ±0.99, ±1, 1.5, -1.5, -2, 1e-30, ±inf), the hardware and the recompiler agreed on everything except exactly 0.5 (hardware 1, recompiler 0) and -0.5 (hardware -1, recompiler 0). Exact halves in 8-, 10- and 16-bit SNORM and in every UNORM width (e.g. 0.5/127, 0.5/511, 0.5/255) already matched.

Hardware: RDNA2, Ryzen 7 9800X3D iGPU (gfx1036), AMD Windows driver 2026.04.17, HIP runtime; not the PS5's gfx1013.

agc_driver_buffer_format_store_two_bit_snorm stores 20 values (x = w = value, y = 0.25, z = -0.75) in both formats and checks the packed words measured there.

Tested

Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1. No validation layer on this machine.

main this PR
agc_driver_buffer_format_store_two_bit_snorm, RTX 5080 (610.88) fails (2_10_10_10_SNORM of x = w = 0.5 is 0x28120100, expected 0x68120100) 3 of 3 pass
same, AMD iGPU (2026.04.17) fails, same first failure 3 of 3 pass
oracle store sweep, 75 formats, both GPUs 2 formats differ all match
^agc_|^shader, both GPUs 2101 tests on each GPU: one failure, agc_storage_write_back_host_retile, which also fails on unchanged main here (#23708, fix in #23751)

The test needs no native f16 or other optional feature, so it should also run on lavapipe in CI; not run on lavapipe here.

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 and the licence notice of code adapted from upstream
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 610.88, Windows 11 Pro 10.0.26200; AMD Radeon Graphics (Ryzen 7 9800X3D iGPU, gfx1036), AMD 2026.04.17, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5442681986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25877). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-22T19:47:42Z. --- ### What The 2-bit component of `2_10_10_10_SNORM` and `10_10_10_2_SNORM` went through `NormStoreBits` like the wider SNORM components, which rounds to nearest even, so 0.5 and -0.5 stored 0. RDNA2 stores 1 and -1 for them. `TwoBitSnormStoreBits` now stores 1 with the value's sign for a magnitude of at least 0.5 and 0 otherwise (NaN included). 8-, 10- and 16-bit SNORM components keep nearest-even rounding, which the hardware also uses for them. These formats are common for packed normals and tangents, where the 2-bit component carries the handedness sign. ### Measured behaviour A store sweep through `tools/hw-oracle` (default runtime vs `HW_ORACLE_RUNTIME=vulkan`) of `tbuffer_store_format_xyzw` in 75 data/number formats, reading the stored dwords back, differed only in these two formats, and only in the 2-bit component. Over 32 inputs (±0, ±0.1, ±0.25, ±0.4, ±0.49, ±0.4999999, ±0.5, ±0.5000001, ±0.51, ±0.75, ±0.99, ±1, 1.5, -1.5, -2, 1e-30, ±inf), the hardware and the recompiler agreed on everything except exactly 0.5 (hardware 1, recompiler 0) and -0.5 (hardware -1, recompiler 0). Exact halves in 8-, 10- and 16-bit SNORM and in every UNORM width (e.g. 0.5/127, 0.5/511, 0.5/255) already matched. Hardware: RDNA2, Ryzen 7 9800X3D iGPU (gfx1036), AMD Windows driver 2026.04.17, HIP runtime; not the PS5's gfx1013. `agc_driver_buffer_format_store_two_bit_snorm` stores 20 values (x = w = value, y = 0.25, z = -0.75) in both formats and checks the packed words measured there. ### Tested Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`. No validation layer on this machine. | | `main` | this PR | |---|---|---| | `agc_driver_buffer_format_store_two_bit_snorm`, RTX 5080 (610.88) | fails (`2_10_10_10_SNORM of x = w = 0.5 is 0x28120100, expected 0x68120100`) | 3 of 3 pass | | same, AMD iGPU (2026.04.17) | fails, same first failure | 3 of 3 pass | | oracle store sweep, 75 formats, both GPUs | 2 formats differ | all match | | `^agc_\|^shader`, both GPUs | | 2101 tests on each GPU: one failure, `agc_storage_write_back_host_retile`, which also fails on unchanged `main` here (#23708, fix in #23751) | The test needs no native f16 or other optional feature, so it should also run on lavapipe in CI; not run on lavapipe here. ### 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 and the licence notice of code adapted from upstream - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 610.88, Windows 11 Pro 10.0.26200; AMD Radeon Graphics (Ryzen 7 9800X3D iGPU, gfx1036), AMD 2026.04.17, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-22 20:30:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T20:30:07Z.

Review: COMMENTED


Reviewed — no blocking findings

The change matches its stated scope; I found no defect in the code reviewed, but could not run the tests in this review environment.

What I ran

Reviewed head 16dd36cead1dc46d65cec9c66dc3e7b0ceb850ca. Read the prepared description, commits, manifest, diff, and all three changed files through repo_read.py; no tests or builds were run.

Results

Check Result Note
Code review passed Changed logic and test inspected
Build and tests not run No execution environment available

Negative control

Not run; a test environment was unavailable.

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed the changed implementation, its formatted store dispatch, the new execution test, and the debt entry at the pinned head.

Not verified

Build and runtime test results were not independently verified. The hardware measurements in the PR description are author reported.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6014377842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25877#pullrequestreview-6014377842). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T20:30:07Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change matches its stated scope; I found no defect in the code reviewed, but could not run the tests in this review environment. ## What I ran Reviewed head `16dd36cead1dc46d65cec9c66dc3e7b0ceb850ca`. Read the prepared description, commits, manifest, diff, and all three changed files through `repo_read.py`; no tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Changed logic and test inspected | | Build and tests | not run | No execution environment available | ## Negative control Not run; a test environment was unavailable. ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed the changed implementation, its formatted store dispatch, the new execution test, and the debt entry at the pinned head. ## Not verified Build and runtime test results were not independently verified. The hardware measurements in the PR description are author reported. ## To get this to a good state Nothing is required.
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!25877
No description provided.