Repository navigation
fix(shader): apply the f32 output modifier on the bits like the hardware - #567
Conversation
|
Thanks, this is the follow-up from #508. The rule reads right to me: the picks are made on the bits of the unmodified result, the The one thing to sort out is the order with #323 and #537, which change the same three files:
Output modifiers are on PPSA21564's shader path, so once it's rebased I'll run it through my PPSA21564 check before merging. |
af77150 to
39a3c21
Compare
|
Rebased on current main: the only conflict was the neighbouring TechnicalDebt line (now |
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>
…A does v_ceil/floor/trunc/rndne/fract/sqrt/rsq/rcp/rcp_iflag/log/exp/sin/cos (f32 and f16) and v_frexp_mant_f32 left NaN, invalid, zero and infinite results to the driver: signalling NaNs came back unquieted, lavapipe lost the NaN sign and payload, invalid results were +NaN instead of -NaN, f32 sin/cos at whole and half cycles returned tiny values instead of +0, and v_fract_f16 of a tiny negative rounded up to 1.0. Adds an execution test for the 27 opcodes with expected values from hardware; approximate ops are compared with tolerances from the Vulkan precision table. Co-Authored-By: Claude <noreply@anthropic.com>
|
Thanks for the rebase. The TechnicalDebt conflict is resolved the right way, and the commit is otherwise the same as before. One thing I noticed while merging the open shader PRs together: this now conflicts with #323 (and so with #537, which carries #323's commits) in The f32 part is unchanged and still looks right to me. PPSA21564 uses |
Co-Authored-By: Claude <noreply@anthropic.com>
39a3c21 to
b5da7d0
Compare
|
Rebased onto #537 (carries #323's commits unchanged) and kept #323's f16 rule:
|
|
Thanks, this is what I was after. The branch is now #537's head (f3b74e2, with #323's three commits unchanged) plus only this commit, and the range-diff against the previous version shows just the f16 parts gone: no #323, then #537, then this one merges cleanly at every step here, and the full ctest passes on main with the stack merged ( As before, PPSA21564 uses Gated on PPSA21564 on top of #537: no visual or FPS change. |
What
The VOP3 output modifier (
mul:2,mul:4,div:2) on f32 results was a plainFMulby 2, 4 or 0.5. That differs from the hardware in three places, and the NaN result was left to the driver:v_mul_f32_e64 v, -0, 1.0 mul:2);div:2, a result that drops below the smallest normal becomes a zero with the sign of the result (0x80800000→0x80000000, and0x00ffffff→+0where round to nearest gives0x00800000);FMulon a NaN lets the driver choose the payload (NVIDIA returns0x7fffffff).applyF32ResultModifiersnow picks these cases on the bits of the unmodified result. Other results still go throughFMul, which is exact for these factors, overflow to infinity included. Clamp is still applied after the output modifier.f16 results follow #323:
applyF16ResultModifiersignores omod, as the hardware does while f16 denormals are enabled (the LLVM default), so this PR only changes the f32 path. I added a line to TechnicalDebt for the mode assumption of the f32 rule and for the f16 case with denormals flushed, which isn't modelled.packedFloat16(VOP3P) has no output modifier field, so its call sites don't change.Behaviour measured on HW
The measurements were taken on a gfx1035 GPU through the HSA runtime, with MODE set to IEEE=0 and f32 denormals flushed. That is the mode the recompiler already assumes for f32 (the LLVM graphics default). With IEEE=1, or with f32 output denormals on, the hardware ignores the output modifier.
v_mul/add/fma/min/max/fract/cvt_f32_i32and each of the three modifiers. Every cell matches the rule above when it is applied to the hardware's own unmodified result:0x00800000: +0;div:2with magnitude below0x01000000: signed zero;v_mul_f32 2.0, 0xff61b1e6 div:2overflows to -inf and stays -inf.Tested
agc_driver_f32_output_modifiertest (tests/execution/F32OutputModifier.cpp): 16 forms (mul, add, sub, fma, min, max, floor, cvt_f32_i32 with each modifier, and clamp after the modifier), with 32 rows of expected values from the hardware. A cell is checked only when AnyPS5's result without the modifier is defined on every driver: no subnormal inputs or results, and fma only where the product is exact. For max with two identical NaN sources the NaN bits are chosen by our code, so those cells are checked bit for bit (sNaN included). For add/mul/fma NaN cells the driver chooses the NaN, so they only require a NaN.agc_driver_pixel_helper_lanes,agc_driver_global_load_addtidandagc_driver_vop3_carry_out, which also fail onmainon this RADV (wave32 lane 32 on RADV's 64-wide subgroup).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)