perf(shader): round v_cvt_pknorm and v_cvt_pk_u8 in f32 #2410

Merged
karanvora2599 merged 4 commits from upstream-pr/2410 into main 2026-10-11 10:16:08 +00:00
karanvora2599 commented 2026-10-09 18:29:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-09T18:29:08Z.


What

v_cvt_pknorm_i16_f32, v_cvt_pknorm_u16_f32 and v_cvt_pk_u8_f32 round f32 values to integers to nearest even. The norm conversions did that with 64-bit integer arithmetic and v_cvt_pk_u8_f32 with a hand-built fraction test; both are now computed with f32 operations that give the same bits. On an RTX 4060 the norm conversions drop from 52-53.5 to 28.5-29.5 instructions and v_cvt_pk_u8_f32 from 16.5 to 8.5.

Background

  • v_cvt_pknorm_u16_f32 d, a, b packs round(clamp(a, 0, 1) * 65535) and the same of b into two 16-bit halves; the i16 form uses clamp(x, -1, 1) * 32767. Rounding is to nearest even on the exact product, NaN gives 0, f32 denormal inputs are flushed.
  • v_cvt_pk_u8_f32 d, x, i, s rounds x to nearest even, clamped to 0..255 (NaN gives 0), and inserts it as byte i & 3 of s.

Before

  • normF32 (Translation/src/FloatInstructions.cpp, #596) formed the exact product significand * scale as a 64-bit integer (IMul64), shifted it right by 149 - exponent (a variable 64-bit shift), recovered the sticky bit with a second variable 64-bit shift and a 64-bit compare, and rounded with the parity of the truncated result. On NVIDIA each 64-bit multiply, variable shift and compare is several instructions.
  • vCvtPkU8F32 (Translation/src/ConvertInstructions.cpp) truncated with the saturating conversion, converted the integer back to f32, subtracted it to get the fraction, and compared the fraction with 0.5 and the integer's parity to decide the rounding.

After

  • Norm conversions, for |x| < 1: p, the f32 nearest to |x| * scale, and its exact error e, from correctly rounded subtractions only.
    • scale + 1 (65536 or 32768) is a power of two, so A = |x| * (scale + 1) is exact and the exact product is A - |x|. Since A >= |x|, p = A - |x| and e = (A - p) - |x| is Fast2Sum: e is exactly A - |x| - p.
    • An earlier version took e from fma(|x|, scale, -p). Vulkan gives GLSL Fma on f32 only the precision of OpFMul followed by OpFAdd, and lavapipe in Mesa 25.2.8 (CI's) splits it, so e was 0 there (see the review).
    • p is the f32 nearest to the exact product, so no half-integer lies strictly between them; roundEven(p) is therefore the right answer unless p is itself exactly k + 0.5. For p < 2^23 (p <= 65535 here) every k + 0.5 is exactly representable in f32, so that case is recognised as p - floor(p) == 0.5.
    • At p = k + 0.5 the exact product is p + e: e > 0 rounds up to k + 1, e < 0 down to k, and e == 0 is a true tie that roundEven resolves.
    • e only matters when p >= 0.5; then |x| >= 0.5 / 65535, so the exact product is a multiple of at least 2^-40 and e is either 0 or a normal number: a driver that flushes denormals can't change it.
    • NaN, |x| >= 1 and the sign keep their previous selects. The lanes that select a constant multiply 0 instead of |x|, so the conversion to integer only ever sees values in range.
  • v_cvt_pk_u8_f32: NaN and x <= 0 give 0, x >= 255 gives 255, anything else is roundEven(x) converted to an integer. The source is read without the f32 denormal flush, which can't change a value rounded to an integer. The byte insertion is unchanged.

All the operations used (FPMul32, FPSub32, FPFloor32, FPRoundEven32, the compares) lower to single native SPIR-V instructions, and the multiply and subtractions carry NoContraction.

Where it matters

v_cvt_pknorm_* packs 16-bit normalized values (for example for 16-bit unorm/snorm outputs and packed normals), v_cvt_pk_u8_f32 builds RGBA8 words in compute shaders. Only an Ada GPU (sm_89) was measured.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, ANYPS5_ENABLE_SPIRV_TOOLS=ON, the branch merged with main at 1c75f4d2. GPU tests on an NVIDIA GeForce RTX 4060 Laptop GPU (driver 591.86, subgroup 32), an Intel UHD Graphics (Raptor Lake, driver 101.6790), and lavapipe from Mesa 25.2.8 (the version CI installs) and Mesa 26.2.4, both the Windows builds, with GALLIUM_OVERRIDE_CPU_CAPS=avx.

Correctness

  • New agc_driver_f32_pack_rounding: 563,232 inputs through all three instructions in one dispatch (FLOAT_MODE 0xc0):

    • for every k, the f32 nearest to (k + 0.5) / 65535 and to (k + 0.5) / 32767, and the two floats on each side of it, which is where the product rounds to or next to a half-integer;
    • the same around k + 0.5 for k < 256 (for v_cvt_pk_u8_f32);
    • a share of their negations;
    • ±0, denormals, 2^-126, 0.5, values next to 1, 255 and 256, ±infinity and NaNs.

    Expected values come from the exact product in double (24 × 16 significant bits, so exact) rounded to nearest even on the host, with the saturation, sign and NaN rules of the bit-level version. It passes on all four devices, and so does the previous bit-level implementation of main, which checks the expectations against the code that was measured on hardware.

  • Negative checks, each fails the new test on the RTX 4060 and on lavapipe:

    • the tie error taken from the rounded product (|x| * scale - p, what a split fma gives): f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001. The fma version of this PR failed the same way on lavapipe 25.2.8;
    • the norm conversion without the tie correction (only roundEven(p)): f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001 (the product rounds to exactly 1.5 but the exact value is below it);
    • v_cvt_pk_u8_f32 rounding halves up (floor(x + 0.5)): f32 pack rounding: v_cvt_pk_u8_f32 of 0x3f000000 is 0x00000001, expected 0x00000000.
  • agc_driver_vop3_pack_ldexp (v_cvt_pknorm_* rows computed on the bits as measured on RDNA2) and agc_driver_vop3_legacy_source_modifiers (v_cvt_pk_u8_f32 with every source modifier) pass on all four devices.

  • Every shader test (agc_driver_*, agc_shader_*, agc_spirv_*, vector_*, agc_masked_select, agc_validate_program, agc_denormal*, agc_float16_*; 320 tests):

    • RTX 4060: everything passes except the device-lost tests agc_driver_flat_loads*, agc_driver_global_loads*, agc_driver_flat_apertures_2, agc_driver_flat_apertures_4 (then 0xc0000409) and agc_driver_pixel_interlock. None of them runs a pack conversion.
    • lavapipe 25.2.8: everything passes or is skipped for missing device features, except agc_driver_image_plane_address_on_line_implicit_lod (pixel 20,0 component 0 is 170, expected 10). It fails the same way with main's recompiler on lavapipe 25.2.8 and 26.2.4.

Instructions per op (RTX 4060, not committed)

Method: a wave32 compute program with a dependent chain of 16 v_xor_b32 + <op> steps (the xor keeps the compiler from folding the chain), sources other than the chain in registers, recompiled with FLOAT_MODE 0xc0 and created with APS5_PIPELINE_STATS=1; "Binary Size" / 16 bytes per instruction, compared with the same chain of v_add_nc_u32 steps.

main (1c75f4d2) this PR registers
v_cvt_pknorm_u16_f32 52 28.5 30 → 24
v_cvt_pknorm_i16_f32 53.5 29.5 30 → 24
v_cvt_pk_u8_f32 (byte index in a register) 16.5 8.5 26 → 26

All other opcodes in the sweep compile to the same size. The exact subtractions cost 1.5 and 1 instructions more than the earlier fma version (27 and 28.5). Through ptxas (CUDA 12.4), the same sequence is 2 instructions longer than the fma one on sm_61, sm_75, sm_86 and sm_89 alike: FMUL and three FADD instead of FMUL and FFMA.

The measurement programs aren't part of this PR; I can attach them if useful.

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:4804351218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2410). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-09T18:29:08Z. --- ### What `v_cvt_pknorm_i16_f32`, `v_cvt_pknorm_u16_f32` and `v_cvt_pk_u8_f32` round f32 values to integers to nearest even. The norm conversions did that with 64-bit integer arithmetic and `v_cvt_pk_u8_f32` with a hand-built fraction test; both are now computed with f32 operations that give the same bits. On an RTX 4060 the norm conversions drop from 52-53.5 to 28.5-29.5 instructions and `v_cvt_pk_u8_f32` from 16.5 to 8.5. #### Background - `v_cvt_pknorm_u16_f32 d, a, b` packs `round(clamp(a, 0, 1) * 65535)` and the same of `b` into two 16-bit halves; the `i16` form uses `clamp(x, -1, 1) * 32767`. Rounding is to nearest even on the exact product, NaN gives 0, f32 denormal inputs are flushed. - `v_cvt_pk_u8_f32 d, x, i, s` rounds `x` to nearest even, clamped to 0..255 (NaN gives 0), and inserts it as byte `i & 3` of `s`. #### Before - `normF32` (`Translation/src/FloatInstructions.cpp`, #596) formed the exact product `significand * scale` as a 64-bit integer (`IMul64`), shifted it right by `149 - exponent` (a variable 64-bit shift), recovered the sticky bit with a second variable 64-bit shift and a 64-bit compare, and rounded with the parity of the truncated result. On NVIDIA each 64-bit multiply, variable shift and compare is several instructions. - `vCvtPkU8F32` (`Translation/src/ConvertInstructions.cpp`) truncated with the saturating conversion, converted the integer back to f32, subtracted it to get the fraction, and compared the fraction with 0.5 and the integer's parity to decide the rounding. #### After - **Norm conversions**, for `|x| < 1`: `p`, the f32 nearest to `|x| * scale`, and its exact error `e`, from correctly rounded subtractions only. - `scale + 1` (65536 or 32768) is a power of two, so `A = |x| * (scale + 1)` is exact and the exact product is `A - |x|`. Since `A >= |x|`, `p = A - |x|` and `e = (A - p) - |x|` is Fast2Sum: `e` is exactly `A - |x| - p`. - An earlier version took `e` from `fma(|x|, scale, -p)`. Vulkan gives GLSL `Fma` on f32 only the precision of `OpFMul` followed by `OpFAdd`, and lavapipe in Mesa 25.2.8 (CI's) splits it, so `e` was 0 there (see the review). - `p` is the f32 nearest to the exact product, so no half-integer lies strictly between them; `roundEven(p)` is therefore the right answer unless `p` is itself exactly `k + 0.5`. For `p < 2^23` (`p <= 65535` here) every `k + 0.5` is exactly representable in f32, so that case is recognised as `p - floor(p) == 0.5`. - At `p = k + 0.5` the exact product is `p + e`: `e > 0` rounds up to `k + 1`, `e < 0` down to `k`, and `e == 0` is a true tie that `roundEven` resolves. - `e` only matters when `p >= 0.5`; then `|x| >= 0.5 / 65535`, so the exact product is a multiple of at least `2^-40` and `e` is either 0 or a normal number: a driver that flushes denormals can't change it. - NaN, `|x| >= 1` and the sign keep their previous selects. The lanes that select a constant multiply 0 instead of `|x|`, so the conversion to integer only ever sees values in range. - **`v_cvt_pk_u8_f32`**: NaN and `x <= 0` give 0, `x >= 255` gives 255, anything else is `roundEven(x)` converted to an integer. The source is read without the f32 denormal flush, which can't change a value rounded to an integer. The byte insertion is unchanged. All the operations used (`FPMul32`, `FPSub32`, `FPFloor32`, `FPRoundEven32`, the compares) lower to single native SPIR-V instructions, and the multiply and subtractions carry `NoContraction`. #### Where it matters `v_cvt_pknorm_*` packs 16-bit normalized values (for example for 16-bit unorm/snorm outputs and packed normals), `v_cvt_pk_u8_f32` builds RGBA8 words in compute shaders. Only an Ada GPU (sm_89) was measured. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `ANYPS5_ENABLE_SPIRV_TOOLS=ON`, the branch merged with `main` at 1c75f4d2. GPU tests on an NVIDIA GeForce RTX 4060 Laptop GPU (driver 591.86, subgroup 32), an Intel UHD Graphics (Raptor Lake, driver 101.6790), and lavapipe from Mesa 25.2.8 (the version CI installs) and Mesa 26.2.4, both the Windows builds, with `GALLIUM_OVERRIDE_CPU_CAPS=avx`. **Correctness** - New `agc_driver_f32_pack_rounding`: 563,232 inputs through all three instructions in one dispatch (`FLOAT_MODE` 0xc0): - for every `k`, the f32 nearest to `(k + 0.5) / 65535` and to `(k + 0.5) / 32767`, and the two floats on each side of it, which is where the product rounds to or next to a half-integer; - the same around `k + 0.5` for `k < 256` (for `v_cvt_pk_u8_f32`); - a share of their negations; - ±0, denormals, 2^-126, 0.5, values next to 1, 255 and 256, ±infinity and NaNs. Expected values come from the exact product in double (24 × 16 significant bits, so exact) rounded to nearest even on the host, with the saturation, sign and NaN rules of the bit-level version. It passes on all four devices, and so does the previous bit-level implementation of `main`, which checks the expectations against the code that was measured on hardware. - Negative checks, each fails the new test on the RTX 4060 and on lavapipe: - the tie error taken from the rounded product (`|x| * scale - p`, what a split `fma` gives): `f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001`. The `fma` version of this PR failed the same way on lavapipe 25.2.8; - the norm conversion without the tie correction (only `roundEven(p)`): `f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001` (the product rounds to exactly 1.5 but the exact value is below it); - `v_cvt_pk_u8_f32` rounding halves up (`floor(x + 0.5)`): `f32 pack rounding: v_cvt_pk_u8_f32 of 0x3f000000 is 0x00000001, expected 0x00000000`. - `agc_driver_vop3_pack_ldexp` (`v_cvt_pknorm_*` rows computed on the bits as measured on RDNA2) and `agc_driver_vop3_legacy_source_modifiers` (`v_cvt_pk_u8_f32` with every source modifier) pass on all four devices. - Every shader test (`agc_driver_*`, `agc_shader_*`, `agc_spirv_*`, `vector_*`, `agc_masked_select`, `agc_validate_program`, `agc_denormal*`, `agc_float16_*`; 320 tests): - RTX 4060: everything passes except the device-lost tests `agc_driver_flat_loads*`, `agc_driver_global_loads*`, `agc_driver_flat_apertures_2`, `agc_driver_flat_apertures_4` (then `0xc0000409`) and `agc_driver_pixel_interlock`. None of them runs a pack conversion. - lavapipe 25.2.8: everything passes or is skipped for missing device features, except `agc_driver_image_plane_address_on_line_implicit_lod` (`pixel 20,0 component 0 is 170, expected 10`). It fails the same way with `main`'s recompiler on lavapipe 25.2.8 and 26.2.4. **Instructions per op** (RTX 4060, not committed) Method: a wave32 compute program with a dependent chain of 16 `v_xor_b32` + `<op>` steps (the xor keeps the compiler from folding the chain), sources other than the chain in registers, recompiled with `FLOAT_MODE` 0xc0 and created with `APS5_PIPELINE_STATS=1`; "Binary Size" / 16 bytes per instruction, compared with the same chain of `v_add_nc_u32` steps. | | `main` (1c75f4d2) | this PR | registers | |---|---|---|---| | `v_cvt_pknorm_u16_f32` | 52 | 28.5 | 30 → 24 | | `v_cvt_pknorm_i16_f32` | 53.5 | 29.5 | 30 → 24 | | `v_cvt_pk_u8_f32` (byte index in a register) | 16.5 | 8.5 | 26 → 26 | All other opcodes in the sweep compile to the same size. The exact subtractions cost 1.5 and 1 instructions more than the earlier `fma` version (27 and 28.5). Through `ptxas` (CUDA 12.4), the same sequence is 2 instructions longer than the `fma` one on sm_61, sm_75, sm_86 and sm_89 alike: `FMUL` and three `FADD` instead of `FMUL` and `FFMA`. The measurement programs aren't part of this PR; I can attach them if useful. ### 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
github-actions[bot] commented 2026-10-09 18:29:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T18:29:18Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6086882991 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2410#issuecomment-6086882991). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T18:29:18Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
adriadam10 commented 2026-10-11 08:19:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:19:17Z.

Review: CHANGES_REQUESTED


Ran this on the CI lavapipe (Mesa 25.2.8, the one in the "Install lavapipe" step) and the new test fails there, while it passes on RADV and on a current lavapipe:

AGC graphics: f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001
  • Translation/src/FloatInstructions.cpp:310: the tie correction relies on e = fma(|x|, scale, -p) being the exact error of the product. FPFma32 is emitted as GLSL Fma (SpirvAluEmitterMath.cpp:1174), and for f32 the Vulkan spec (spirvenv, precision table) only guarantees the precision of OpFMul followed by OpFAdd, so a driver may split it. Then e == 0 for every input and a product that rounds up to k + 0.5 is resolved by roundEven instead of by the sign of the real error. NoContraction does not prevent splitting an explicit Fma. Same issue as #446.
  • Fix: get the error from correctly rounded ops only (e.g. Dekker/Veltkamp split of |x| and scale, as EmitFPFma64 does for f64), or keep the 64-bit integer path. The test you added already covers it; please also run it with the CI lavapipe, since the PR CI doesn't build.
  • v_cvt_pk_u8_f32 (ConvertInstructions.cpp:214-222) uses only exact ops and passes on both.

The instruction counts (RTX 4060) could not be checked here; they stay as your measurement.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482523834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2410#pullrequestreview-5482523834). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T08:19:17Z. **Review:** CHANGES_REQUESTED --- Ran this on the CI lavapipe (Mesa 25.2.8, the one in the "Install lavapipe" step) and the new test fails there, while it passes on RADV and on a current lavapipe: ``` AGC graphics: f32 pack rounding: v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001 ``` - `Translation/src/FloatInstructions.cpp:310`: the tie correction relies on `e = fma(|x|, scale, -p)` being the exact error of the product. `FPFma32` is emitted as GLSL `Fma` (`SpirvAluEmitterMath.cpp:1174`), and for f32 the Vulkan spec (`spirvenv`, precision table) only guarantees the precision of `OpFMul` followed by `OpFAdd`, so a driver may split it. Then `e == 0` for every input and a product that rounds up to `k + 0.5` is resolved by `roundEven` instead of by the sign of the real error. `NoContraction` does not prevent splitting an explicit `Fma`. Same issue as #446. - Fix: get the error from correctly rounded ops only (e.g. Dekker/Veltkamp split of `|x|` and `scale`, as `EmitFPFma64` does for f64), or keep the 64-bit integer path. The test you added already covers it; please also run it with the CI lavapipe, since the PR CI doesn't build. - `v_cvt_pk_u8_f32` (`ConvertInstructions.cpp:214-222`) uses only exact ops and passes on both. The instruction counts (RTX 4060) could not be checked here; they stay as your measurement.
karanvora2599 commented 2026-10-11 09:59:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karanvora2599 on 2026-10-11T09:59:07Z.


Thanks for running it on CI's lavapipe. I reproduced it with the Windows build of Mesa 25.2.8 (GALLIUM_OVERRIDE_CPU_CAPS=avx): the same v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001. In that version llvmpipe emits every NIR ffma as llvm.fmuladd (lp_bld_nir_soa.c), which LLVM splits into a multiply and an add when FMA is off. Mesa 26.x does that only for ffma_weak, which is why my lavapipe passed.

Fixed in 17267336 without Fma. scale + 1 (65536 or 32768) is a power of two, so A = |x| * (scale + 1) is exact and the exact product is A - |x|. Since A >= |x|, p = A - |x| and e = (A - p) - |x| is Fast2Sum: e is the exact error of p, from correctly rounded subtractions only.

  • agc_driver_f32_pack_rounding, agc_driver_vop3_pack_ldexp and agc_driver_vop3_legacy_source_modifiers pass on lavapipe 25.2.8 and 26.2.4, the RTX 4060 and an Intel UHD.
  • Taking the error from the rounded product instead (|x| * scale - p, which is what the split fma computed) makes the new test fail on the RTX 4060 and on lavapipe 26.2.4 with the same line, so it catches this on a driver that fuses too.
  • Shader tests (320) on the RTX 4060 and lavapipe 25.2.8: the only failures are the device-lost flat/global/interlock tests on the RTX 4060, which run no pack conversion, and agc_driver_image_plane_address_on_line_implicit_lod on lavapipe, which fails the same way with main's recompiler.
  • It costs 1 to 1.5 instructions more than the fma version on the RTX 4060. Against current main, v_cvt_pknorm_u16_f32 goes from 52 to 28.5 and v_cvt_pknorm_i16_f32 from 53.5 to 29.5.

I also merged current main (1c75f4d2) and updated the description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107816834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2410#issuecomment-6107816834). Originally posted by [karanvora2599](https://github.com/karanvora2599) on 2026-10-11T09:59:07Z. --- Thanks for running it on CI's lavapipe. I reproduced it with the Windows build of Mesa 25.2.8 (`GALLIUM_OVERRIDE_CPU_CAPS=avx`): the same `v_cvt_pknorm_u16_f32 of 0x37c000c0 is 0x00020002, expected 0x00010001`. In that version llvmpipe emits every NIR `ffma` as `llvm.fmuladd` (`lp_bld_nir_soa.c`), which LLVM splits into a multiply and an add when FMA is off. Mesa 26.x does that only for `ffma_weak`, which is why my lavapipe passed. Fixed in 17267336 without `Fma`. `scale + 1` (65536 or 32768) is a power of two, so `A = |x| * (scale + 1)` is exact and the exact product is `A - |x|`. Since `A >= |x|`, `p = A - |x|` and `e = (A - p) - |x|` is Fast2Sum: `e` is the exact error of `p`, from correctly rounded subtractions only. - `agc_driver_f32_pack_rounding`, `agc_driver_vop3_pack_ldexp` and `agc_driver_vop3_legacy_source_modifiers` pass on lavapipe 25.2.8 and 26.2.4, the RTX 4060 and an Intel UHD. - Taking the error from the rounded product instead (`|x| * scale - p`, which is what the split `fma` computed) makes the new test fail on the RTX 4060 and on lavapipe 26.2.4 with the same line, so it catches this on a driver that fuses too. - Shader tests (320) on the RTX 4060 and lavapipe 25.2.8: the only failures are the device-lost flat/global/interlock tests on the RTX 4060, which run no pack conversion, and `agc_driver_image_plane_address_on_line_implicit_lod` on lavapipe, which fails the same way with `main`'s recompiler. - It costs 1 to 1.5 instructions more than the `fma` version on the RTX 4060. Against current `main`, `v_cvt_pknorm_u16_f32` goes from 52 to 28.5 and `v_cvt_pknorm_i16_f32` from 53.5 to 29.5. I also merged current `main` (1c75f4d2) and updated the description.
adriadam10 commented 2026-10-11 10:16:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:16:05Z.

Review: APPROVED


Re-checked on the current head: agc_driver_f32_pack_rounding (563,232 inputs) passes on RADV and on CI's lavapipe (Mesa 25.2.8), as do agc_driver_vop3_pack_ldexp and agc_driver_vop3_legacy_source_modifiers. Mutating the tie correction and the v_cvt_pk_u8_f32 rounding (floor(x + 0.5)) both fail the new test. The Fast2Sum error term no longer depends on Fma. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482904525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2410#pullrequestreview-5482904525). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T10:16:05Z. **Review:** APPROVED --- Re-checked on the current head: `agc_driver_f32_pack_rounding` (563,232 inputs) passes on RADV and on CI's lavapipe (Mesa 25.2.8), as do `agc_driver_vop3_pack_ldexp` and `agc_driver_vop3_legacy_source_modifiers`. Mutating the tie correction and the `v_cvt_pk_u8_f32` rounding (`floor(x + 0.5)`) both fail the new test. The Fast2Sum error term no longer depends on `Fma`. Merging.
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!2410
No description provided.