Commit Graph
23 Commits
Author SHA1 Message Date
thuanquangandClaude Opus 5.5 3a4d3bb35e fix(shader): flush v_cvt_pkrtz_f16_f32 and v_pack_b32_f16 f16 denormals
Both ignored the FLOAT_MODE f16 denormal field. On RDNA2 (gfx1031)
v_cvt_pkrtz_f16_f32 flushes each denormal half result to its signed zero
when bit 7 of FLOAT_MODE is clear, and v_pack_b32_f16 flushes each
denormal half input when bit 6 is clear. Modes that keep them and
shaders without a known float mode are translated as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 13:24:16 +07:00
AlexandClaude Sonnet 5.5 95988c9c34 fix(shader): flush f16 denormals in unary, frexp and conversion ops per the float mode
The f16 unary ops, v_frexp_mant_f16, v_frexp_exp_i16_f16, the norm
conversions and v_cvt_f32_f16 read denormal halves as they are and
rounded denormal results as they are, whatever the denormal field of
FLOAT_MODE says. On RDNA2 a clear bit 0 flushes a denormal half input
to its signed zero and a clear bit 1 flushes a denormal half result.

One shared rule now drives all of them, and v_ldexp_f16 uses it for its
input too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 14:27:58 -04:00
Karan Vora 8d0a0504ae Merge remote-tracking branch 'origin/main' into perf/shader-pack-conversions-f32 2026-10-11 04:57:04 -04:00
Adrià df09e33759 Merge pull request #2407 from karanvora2599/perf/shader-float-to-int-once
perf(shader): saturate f32 to integer conversions once
2026-10-11 10:14:22 +02:00
Dean 43c981462a Merge pull request #3039 from CouchRiv/fix-shader-cvt-f32-int-directed-rounding
fix(shader): honor directed round32 in integer to f32 conversions
2026-10-11 19:35:24 +13:00
AlexandComposer 43ff4e926a fix(shader): honor directed round32 in integer to f32 conversions
v_cvt_f32_i32 and v_cvt_f32_u32 used the host Convert which always
rounds to nearest even. When FLOAT_MODE bits 1:0 are directed, build
the f32 bits from the integer magnitude so discarded low bits follow
round toward +inf, -inf or zero, as measured on RDNA2 (gfx1036).

Co-Authored-By: Composer <noreply@cursor.com>
2026-10-10 16:34:07 -04:00
951526662f fix(shader): honor directed f16 rounding in f16 conversions and ldexp
Directed FLOAT_MODE modes for v_cvt_f16_f32, v_cvt_f16_i16,
v_cvt_f16_u16 and v_ldexp_f16 were ignored, so results stayed
round-to-nearest-even. Hardware uses FLOAT_MODE bits 3:2 (round16);
the directed path runs only when f16 denormals are preserved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 16:27:01 -04:00
Karan Vora b6442c2137 Merge remote-tracking branch 'origin/main' into perf/shader-pack-conversions-f32 2026-10-10 12:01:10 -04:00
Karan Vora 14867c51a3 Merge remote-tracking branch 'origin/main' into perf/shader-float-to-int-once 2026-10-10 12:01:07 -04:00
aleandClaude Fable 5.1 0bea402a1c feat(shader): follow FP16_OVFL in every f16 result
With FP16_OVFL=1 the hardware writes an f16 result that would round to
infinity as the largest finite value of that sign, unless a source
operand is infinite. v_div_fixup_f16 keeps the infinity it writes for a
zero denominator or an infinite numerator. Measured on RDNA2 (gfx1036)
at IEEE=0 and IEEE=1 with f16 denormals kept and flushed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 04:32:38 -03:00
AlexandClaude Opus 5.5 e1f81abd85 fix(shader): quiet signaling NaN halves in v_pack_b32_f16 in IEEE mode
With IEEE_MODE=1 the hardware quiets each signaling NaN half that
v_pack_b32_f16 packs, after neg and abs; with IEEE=0 it copies the bits.
The recompiler always copied them. Same rule as #1867, measured on
gfx1036 in both modes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 08:52:03 +02:00
Karan Vora 3a16e5e54e perf(shader): round v_cvt_pknorm and v_cvt_pk_u8 in f32
v_cvt_pknorm_i16/u16_f32 rounded |x| * 32767 or 65535 to nearest even
with a 64-bit integer product, variable 64-bit shifts and a sticky bit.
In f32, p = |x| * scale is the f32 nearest to the exact product, so
roundEven(p) is the answer unless p is exactly k + 0.5, where the sign of
the exact error fma(|x|, scale, -p) decides. Lanes that select a
constant (NaN, |x| >= 1) multiply 0 instead.

v_cvt_pk_u8_f32 truncated with the saturating conversion and rounded the
fraction by hand; it is now roundEven(x) between the 0 and 255 clamps,
NaN giving 0, read without the f32 denormal flush.

New test agc_driver_f32_pack_rounding: 563,232 inputs around every
rounding tie, checked against the exact product in double.
2026-10-09 14:05:07 -04:00
Karan Vora b7df8884ff perf(shader): saturate f32 to integer conversions once
The translation of v_cvt_i32/u32/flr_i32/rpi_i32_f32 and v_cvt_i16/u16_f16
already maps NaN to 0 and clamps the value into range before
ConvertS32F32/ConvertU32F32, and the backend truncated it again and
repeated the NaN and range selects on the result. Those IR ops have no
other producers, so the backend now emits one OpConvertFToS or
OpConvertFToU, and EmitF32ToU32 and EmitTruncF32Value, which had no
other users, are removed.

The translation drops its FPTrunc32, as the conversions round toward
zero, and the selects whose constant the conversion of the clamped value
already gives. v_cvt_i32_f32 and v_cvt_u32_f32 read their source without
the f32 denormal flush: a denormal truncates to 0 either way.
2026-10-09 13:28:39 -04:00
Adrià FranchandClaude f132f16155 feat(shader): flush f32 denormals in the float modes that flush them
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-08 23:59:24 +02:00
Adrià FranchandClaude 7bb6c59e83 fix(shader): v_mullit_f32 legacy rules, v_cvt_pk_u8_f32 rounding and VOP3 neg/abs
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 10:53:50 +02:00
Dean 698c23d81e Merge pull request #528 from adriadam10/test/vop1-vop2-integer
fix(shader): v_cvt_rpi/flr_i32_f32 NaN and exact round-half-up, VOP1/VOP2 integer test
2026-10-05 21:35:53 +13:00
Dean e90d2edf54 Merge pull request #596 from adriadam10/fix/vop3-pack-ldexp-bits
fix(shader): compute v_cvt_pknorm_*_f32, v_ldexp_f32 and v_pack_b32_f16 on the bits
2026-10-05 18:11:01 +13:00
Adrià FranchandClaude a4482e0b71 fix(shader): compute v_cvt_pknorm_*_f32, v_ldexp_f32 and v_pack_b32_f16 on the bits
v_pack_b32_f16 applied neg/abs to bit 31 of the source dword instead of the
selected half. v_cvt_pknorm_{i16,u16}_f32 and v_ldexp_f32 used GLSL
PackSnorm2x16/PackUnorm2x16/Ldexp, which leave NaN, rounding ties and
denormals to the driver. Compute them on the bits as measured on RDNA2.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 03:42:08 +02:00
Adrià FranchandClaude b94b1f96dc fix(shader): apply clamp but not omod to f16 results, as RDNA does
writeF16 dropped the clamp bit, so VOP3/SDWA f16 results with clamp
(v_rcp_f16, v_fma_f16, v_cvt_f16_f32, v_add_f16_sdwa, ...) were not
saturated. Clamp now limits to [0, 1] with NaN and -0 going to +0.
The f16 sqrt/rsq/log and sin/cos paths applied omod, which the
hardware ignores on f16 results in the default float mode, and
v_cvt_pkrtz_f16_f32 applied clamp and omod to its inputs, which the
hardware ignores as well.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 03:38:07 +02:00
Adrià FranchandClaude b02c80254e fix(shader): v_cvt_rpi/flr_i32_f32 NaN and exact round-half-up
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-04 22:35:56 +02:00
boykopovar 713e2b9606 feat(shader): impl dispatch instruction functions for translator 2026-09-16 13:16:09 +03:00
boykopovar fbb8fcbf4e feat(shader): add translation convert instructions impl 2026-09-16 13:00:51 +03:00
boykopovar d084eed394 feat(shader): rdna memory op decoder impl 2026-09-15 07:07:50 +03:00