feat(shader): follow DX10_CLAMP in the clamp modifier #1866
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1866"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T22:25:32Z.
What
Part of #981. The clamp modifier always mapped a NaN result to +0. That is the hardware behaviour with
DX10_CLAMP=1, the setting in every Astro's Playroom shader but ten. WithDX10_CLAMP=0 the hardware writes the NaN unchanged. Translation now followsGuestContext::floatMode.dx10Clamp(#1816).Measured on RDNA2 (gfx1035) with the HW oracle, over 196 rows (quiet and signaling NaNs of both signs, ±inf, ±0, values above 1 and below 0) at IEEE=0 and IEEE=1. The ops cover f32 arithmetic, min/max/med3, unary, rcp/sqrt/exp,
mul_legacy, f16 (add/mul/max,cvt_f16_f32,cvt_f32_f16), packed f16 (pk_add/pk_max) and f64 (add/mul/max/fma_f64):DX10_CLAMP=1: a NaN result clamps to +0, as before.DX10_CLAMP=0: a NaN result is written unchanged. Every other value clamps to [0, 1] as before.IEEE_MODEdoesn't change the clamp itself.Changes:
applyF32ResultModifiers,applyF16ResultModifiersandclampF16Bitskeep a NaN result whenDX10_CLAMP=0. A shader without a known float mode keepsDX10_CLAMP=1.DX10_CLAMP=0 now goes through the existing NaN-on-the-bits selection, and the lane it picks is clamped. Without that, a min/max that returns the non-NaN operand would skip the clamp.DX10_CLAMP=0 instead of writing 0.DX10_CLAMP=0 throws.DX10_CLAMPas read.Tested
Linux (CachyOS, GCC), RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8).
agc_driver_dx10_clamp: 16 clamped instructions (f32, f16, packed f16) × 32 rows captured on hardware withDX10_CLAMP=1 and =0, IEEE=0,FLOAT_MODE0xc0. 216 of the 512 cells differ between the two settings. The test runs with no mode and withDX10_CLAMP=1 (checked against the first table) and withDX10_CLAMP=0 (the second). Where the NaN bits come from a driver op (f32 and scalar f16 arithmetic) any NaN is accepted. Where translation chooses them (packed f16) they are compared bit for bit.agc_driver_f32_output_modifier,agc_driver_float16_modifiersandagc_driver_packed_alupass unchanged.mainwith #1850, the new test andagc_driver_f32_denormal_flushpass on both drivers.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)