fix(shader): round a 2-bit SNORM buffer store component away from zero at 0.5 #25877
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25877"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Lyrnc on 2026-11-22T19:47:42Z.
What
The 2-bit component of
2_10_10_10_SNORMand10_10_10_2_SNORMwent throughNormStoreBitslike the wider SNORM components, which rounds to nearest even, so 0.5 and -0.5 stored 0. RDNA2 stores 1 and -1 for them.TwoBitSnormStoreBitsnow 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 vsHW_ORACLE_RUNTIME=vulkan) oftbuffer_store_format_xyzwin 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_snormstores 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.mainagc_driver_buffer_format_store_two_bit_snorm, RTX 5080 (610.88)2_10_10_10_SNORM of x = w = 0.5 is 0x28120100, expected 0x68120100)^agc_|^shader, both GPUsagc_storage_write_back_host_retile, which also fails on unchangedmainhere (#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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
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 throughrepo_read.py; no tests or builds were run.Results
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.