Repository navigation
fix(shader): choose packed f16 NaN results on the bits, as RDNA does - #533
Conversation
5ea4d17 to
2310597
Compare
|
Rebased on current main: the only Windows failure was |
|
Thanks. I checked the min/max part against the RDNA2 ISA pseudocode for V_MIN_F16/V_MAX_F16: a signaling NaN wins and is quieted (src0 before src1), and a single NaN returns the other source, which is what the selects do. For two quiet NaNs the pseudocode would give src1, while your capture and the code give src0; I'm fine going with the hardware there, and the mutation row covers it. The old sNaN test ( One note, not blocking: quieting a signaling NaN on add/mul/fma is the IEEE=1 result, and the recompiler doesn't read the mode from PGM_RSRC1. Main already made the same assumption for v_pk_min/max, so this keeps it consistent.
|
|
Rebased on main (TechnicalDebt conflict with the v_mullit_f32 line: both kept). PackedAlu passes on RADV and lavapipe. |
2310597 to
55298aa
Compare
55298aa to
6899421
Compare
|
Rebased on main (TechnicalDebt conflict with the v_fma_legacy_f32 line, both kept). packed_alu passes on RADV and on CI's lavapipe. |
Co-Authored-By: Claude <noreply@anthropic.com>
6899421 to
a000305
Compare
|
Taken off hold for #981. The ops now follow the shader's float mode, which #1816 carries into the request. Rebased on
Tested: packed_alu on RADV and CI's lavapipe, full ctest 489/489. Negative checks each fail: quieting at IEEE=0, src2 NaN beating an invalid product, sNaN min/max rule applied at IEEE=0, the flush mode not refused. |
|
Scalar cross-check of the NaN rules, measured on RDNA2 (gfx1036, Ryzen 7950X3D iGPU) with the hardware oracle: AI-assisted: yes (Claude Code). |
What
The packed f16 ops (
v_pk_add_f16,v_pk_mul_f16,v_pk_fma_f16,v_pk_fmac_f16,v_pk_min_f16,v_pk_max_f16) left NaN results to the driver, or got them wrong:min(0xffff, 0)returned the NaN instead of0.neg_lo/neg_hi, so a negated NaN kept its old sign.NaN results are now chosen on the bits of each half, after
op_sel/op_sel_hi/neg_lo/neg_hi. Numeric results are unchanged. Withclampthe result keeps the current path: on hardware it is+0for any NaN, which belongs to the f16 clamp work (#323, #500).Behaviour measured on HW (RDNA2, gfx1035)
0xfe00, even when src2 is a NaN; if no source is a NaN and the result is invalid (inf−inf), it is0xfe00too.v_pk_fmac_f16gives the same result asv_pk_fma_f16with src2 = the destination.GuestContext::floatMode(feat(shader): carry the shader float mode into the recompile request #1816); a shader with no known mode is translated as IEEE=0. A mode that flushes f16 denormals or rounds f16 other than to nearest even throws (FLOAT_MODE step of Shader float mode (IEEE_MODE, DX10_CLAMP, FLOAT_MODE) is per shader; the recompiler assumes one #981).Also added to TechnicalDebt (not changed here):
v_fma_f16,v_pk_fma_f16andv_pk_fmac_f16are an f32 FMA rounded to f16, so the result can be rounded twice (0x62e9 * 0xd159 + 0x23ecgives0xf89e; the hardware gives0xf89f).Tested
New execution test
agc_driver_packed_alu_testsruns 44 instructions covering all 19 VOP3P packed ops plusv_pk_fmac_f16: each plain op,op_sel/op_sel_hivariants, andneg_lo/neg_hivariants on the f16 ops. Rows were picked by class (integer overflow, sign and shift counts; f16 inf/zero/NaN, quiet and signaling NaN per source), with fixed rows for inf·0, inf−inf and inf·0 with a NaN src2. The expected values are what the hardware returns at IEEE=1 (Expected) and IEEE=0 (ExpectedIeeeOff), and the Python model matches them in every cell. The test runs with no mode (checked against IEEE=0), with IEEE=1, and with a flush-f16 mode that must throw. Denormal inputs and results are excluded.It passes on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8). The integer ops already passed on
main. The test fails with each of these changes: no NaN override (=main), quiet NaNs treated as signaling,negignored on NaN sources, a positive invalid NaN, the last NaN source picked first, NaN not quieted, src1 picked when both min/max sources are NaN, the wrong signaling-NaN order, and the fmac accumulator ignored.The full Release ctest passes (489/489).
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)