Repository navigation
fix(shader): apply clamp but not omod to f16 results, as RDNA does - #323
Conversation
|
The fix itself looks right to me. It matches what ACO does: no omod on 16-bit results unless f16 denormals are flushed, and no output modifiers on |
f3b9360 to
256bc5f
Compare
|
Thanks for running it on NVIDIA. The test now accepts any NaN in each 16-bit half where a NaN is expected ( |
|
Thanks for the IsNan16 change, that fixes the NaN payload rows on NVIDIA. With those out of the way the test now gets further and stops at "lane 7 sin_mul2 is 0x00000003, expected 0x00000006" on my NVIDIA machine. Input 0x0001 gives sin(2pi * 2^-24), about 6 f16 denormal ulps. That value comes straight from the driver's sine, and NVIDIA's sine has an absolute error bound larger than the value itself (Vulkan only asks for 2^-11 absolute for sin), so 0x0003 is a valid result there and RDNA, RADV and lavapipe just happen to be exact. Could the sin rows use an input whose sine is well above that error (around 0.25 to 0.5, where mul:2 applied or ignored still differs clearly), with the sin columns compared within a tolerance? Then it's ready from my side, and since it changes f16 results that carry clamp, I'll run it through my PPSA21564 check before merging. |
|
Thanks, done (new last commit, rebased on current main):
|
01bddbf to
cc69286
Compare
|
Thanks, the new comparison looks right to me.
Since this changes f16 results that carry clamp, I'll run it through my PPSA21564 check next and merge it after that if it's clean. |
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>
…yload Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
cc69286 to
6686bff
Compare
What
RDNA f16 VALU results take the
clampbit but, in the default float mode, notomod. The recompiler had it the other way around in several places:writeF16(every f16 result written through it: VOP3v_rcp/floor/fract/…_f16,v_cvt_f16_f32,v_cvt_f16_u16/i16,v_fma_f16, SDWAv_add/mul_f16) ignored clamp:v_rcp_f16 0.25 clampgave 4.0 instead of 1.0.applyF32ResultModifiers, so they applied omod.v_cvt_pkrtz_f16_f32applied clamp and omod to its inputs. The hardware ignores both on this opcode.Measured on an RDNA2 GPU (ROCm HSA, raw kernels; same VALU as gfx1013 for these opcodes):
applyF16ResultModifiersdoes the clamp.writeF16,float16Unaryandfloat16Trignow use it.vCvtPkrtzF16F32no longer modifies its inputs.Test
agc_driver_float16_result_modifiers: 16 ops × 32 lanes with values captured on the RDNA2 GPU: clamp and omod on VOP1/VOP3/SDWA f16 results,v_fma_f16,v_cvt_f16_f32/u16andv_cvt_pkrtz, including NaN, ±inf, −0 and SDWAWORD_1withUNUSED_PRESERVE. f16 inputs are kept normal and f32 inputs away from denormals because those depend on the driver's float controls.Tested
Linux, full ctest (100) passes.
rcp_clamp is 0x4400, expected 0x3c00(both drivers). Reverting only the pkrtz part:pkrtz_div2 is 0x30cc, expected 0x34cc. Reverting only the sqrt/sin part:sqrt_clamp_mul2 is 0x3c00, expected 0x3800.Follow-up: in VOP3, the decoder still rejects clamp on the f16 binaries and on
mad/min3/max3/med3_f16. That will come in a separate PR after #252, which touches the same checks.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)