fix(shader): read v_ldexp_f16 src1 float inline constants as f16 #1966
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1966"
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 Deftera186 on 2026-10-09T03:07:44Z.
What
v_ldexp_f16read src1 withreadU32, so a float inline constant in src1 gave the low 16 bits of its f32 pattern. For 0.5, 1.0, 2.0, 4.0 and their negatives that is 0, and the instruction returned src0 unchanged; for 1/(2*pi) (0x3e22f983) it is 0xf983 (-1661, clamped to -64), and the instruction returned a zero with the sign of src0. The hardware treats src1 as an f16 operand, so these constants arrive in their f16 encoding: 0.5 is 0x3800, an exponent of 14336. Measured on gfx1101,ldexp(1.0, 0.5)is +inf andldexp(1.0, -0.5)is +0.VOP3 src1 is now read through
readF16SourceBits, which maps the nine float inline constants to their f16 bits and reads every other operand as before. Registers, integer inline constants and literals already matched the hardware, which uses their sign-extended low 16 bits (table below). SDWA is the only other form that can put an inline constant in src1; it keeps the old read bit for bit, since gfx11 has no SDWA to measure it on. VOP3op_seland src1abs/negonv_ldexp_f16are still refused by the decoder.Sources:
VOP2Instructions.tdat 928f895, L1083-L1093: "The ldexp.f16 intrinsic expects a integer src1 operand, though the hardware encoding treats src1 as an f16";LDEXP_F16_VOPProfileisVOPProfile <[f16, f16, f16, untyped]>.V_LDEXP_F16uses it on subtargets with 16-bit instructions and without true16 (L1107-L1108), and gfx10 encodes it as VOP2 0x03b (L2384). llvm-mc 23.1.2 for gfx1013 accordingly encodesv_ldexp_f16_e64 v25, v4, 0x3800with the inline constant 0.5 and0x3118with 1/(2*pi), whilev_add_nc_u16 v25, v4, 0x3800keeps a literal.Tested
Gentoo Linux, RX 7700 XT (gfx1101), RADV (Mesa 26.2.3).
LdexpF16InlineConstants.cpp(ctestagc_driver_ldexp_f16_inline_constants): 32 f16 inputs (normal, subnormal, +0, -0) by 16 VOP3 src1 forms: the nine float inline constants, the integer inline constants 2, -1, 64 and -16, the literal 0x3f000000, an SGPR holding 0x3f000000 and a VGPR holding 0x3800. The expected values are the gfx1101 results in the mode the test compiles with (FLOAT_MODE 0xc0, IEEE=0, DX10_CLAMP=1).ldexp f16 inline constants: v_ldexp_f16 0x3c00, 0.5 is 0x3c00, expected 0x7c00; 270 of the 512 results differ, all in the nine float-constant columns. After the fix it passes.100% tests passed, 0 tests failed out of 495.agc_driver_ldexp_f16_inline_constants,agc_driver_sdwa_ldexp_f16andagc_driver_float16_miscpass on llvmpipe (LLVM 20.1.2, Mesa 25.2.8) in an Ubuntu 24.04 container with the packages and configure flags of the Linux CI job.Hardware results on gfx1101 (oracle kernels assembled with
-mattr=-real-true16, so the 16-bit operands are gfx10-style VGPRs), FLOAT_MODE 0xc0, IEEE=0, DX10_CLAMP=1. The recompiler result before the fix is in parentheses where it differed; after the fix every result matches.All 512 results of the test were measured in the 16 combinations of IEEE 0/1, f32 denormals flushed/kept, f16 denormals flushed/kept and DX10_CLAMP 0/1. The eight modes that keep f16 denormals give identical results. The eight that flush them differ in 142 results, all from the flush: a subnormal src0 reads as a signed zero (0x0001 with 0.5 gives 0x0000) and a result that is tiny before rounding is written as a signed zero (0x07ff with -1 gives 0x0000, not 0x0400). For normal src0 the float constants give the same results in all 16 modes.
v_ldexp_f16does not read the f16 denormal mode before or after this change.A VOP3 literal src1, hand-encoded with
.longto set every bit of the literal dword, reads as its sign-extended low 16 bits on gfx1101 in all 16 modes. With src0 1.0, the literals 0x00000002, 0x12340002 and 0xffff0002 give 0x4400, 0x0000fffe gives 0x3400, 0x00010000, 0x7fff0000 and 0x3f000000 give 0x3c00, 0x00008000 and 0x0000ffc0 give 0x0000, and 0x00003800, 0x00007fff and 0x0000003f give 0x7c00. The recompiler reads literals the same way before and after this change.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:14:29Z.
I verified the Actions API for this exact head: Build, Conventions and Progress report are marked
action_required, so upstream CI has not run yet. Per CONTRIBUTING, a maintainer needs to approve those workflow runs; please request that approval.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:14:43Z.
Review: COMMENTED
Reviewed the complete diff. The change is scoped to VOP3 src1, which can encode the scalar float-inline constants; VOP2 src1 is a VGPR field and remains unchanged, as does SDWA.
readF16SourceBitsmaps the supported inline-float encodings and leaves literals/register sources on their existing raw-bit path. The new execution test is picked up by the existingtests/execution/*.cppglob and covers inline floats, integer inline values, literals and register sources across normal/subnormal/zero inputs. The reported hardware and lavapipe results are detailed. I found no code issue; I am holding approval until theaction_requiredupstream checks run.Imported from boykopovar/AnyPS5. Originally posted by snoozedDev on 2026-10-09T03:51:12Z.
Re-measured on RDNA2: Ryzen 7 7700X iGPU (Raphael, gfx1036, not the PS5's gfx1013),
tools/hw-oracleon Linux (hsa-rocr 7.2.4, LLVM 22.1.8), head7ba98071.LdexpCodewords 7-39 unchanged (withs8 = 0x3f000000,v5 = 0x3800set first), gfx10-style 16-bit operands so no-mattr, wave32, in the same 16 modes as above.Rowsbit for bit in the 8 modes keeping f16 denormals, including the test's mode; the 8 flushing modes differ in 142 cells, the same count as on gfx1101.agc_driver_ldexp_f16_inline_constantspasses on an RTX 3090 (NVIDIA 610.57.04) and on the RADV iGPU (Mesa 26.2.2); withmain'sFloatInstructions.cppboth fail atv_ldexp_f16 0x3c00, 0.5 is 0x3c00, expected 0x7c00.Bodies, rows and per-mode results: https://gist.github.com/snoozedDev/c81c82507b46f9de87c5ecbdff54cde6 (
pr1966-*). Generated with Claude Code (Claude Fable 5.1), driven and checked by me; the numbers are the hardware's output.Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T05:54:23Z.
The SDWA form can be measured on RDNA2, which has SDWA. On gfx1036 (Radeon 610M) with
tools/hw-oracle, wave32, IEEE=0, DX10_CLAMP=1, f16 denormals kept,v_ldexp_f16_sdwa vN, v4, <src1> src0_sel:WORD_0 dst_sel:DWORD, src0 = 1.0 (0x3c00):main(WORD_0, WORD_1)So SDWA also reads a float inline constant as its f16 bits, zero-extended to 32 bits (WORD_1 is 0). Integer constants are sign-extended (WORD_1 of -16 is 0xffff). The SDWA path still reads the f32 bits and differs on these rows. The same holds for src0 0xbc00, 0x0001, 0x07ff and 0x3555, and with f16 denormals flushed apart from the flush itself. The VOP3 0.5 and 1/(2*pi) rows I ran as controls match your table.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T08:59:49Z.
NVIDIA and Intel results on Windows, to go with the RADV runs.
Windows 11, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, fullctestwithANYPS5_REQUIRE_VULKAN=1on both GPUs of one machine: RTX 4080 (driver 617.42) and Intel UHD Graphics 770 (Raptor Lake-S, driver 101.6129, Vulkan 1.3.295), selected withANYPS5_GPU. Base:main6cc0503dplus #2093, sincemainalone does not build its tests right now (spirv/unified1/spirv.hppnot found).agc_driver_ldexp_f16_inline_constantspasses on both GPUs. The five UHD 770 failures are the same tests with and without this PR (vop3_mad_i64, #1246, plus four filed as #2114), so nothing new fails.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T09:26:09Z.
NVIDIA data point. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), GCC 15.2.0 (WinLibs r7), Release. Head
7ba98071merged ontomaind9484c71, together with #1979 and #1963.agc_driver_ldexp_f16_inline_constants,agc_driver_sdwa_ldexp_f16andagc_driver_float16_miscpass.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:06:12Z.
Checked the 512 cells of
LdexpF16InlineConstantson the HW oracle (gfx1035, the test's mode: IEEE=0, f32 denormals flushed, f16 kept): all match bit for bit. The new test fails without the change and passes with it on RADV. Merging.The SDWA form is a separate, pre-existing issue: as @CouchRiv measured, and we see the same on gfx1035, SDWA src1 reads a float inline constant as its f16 bits zero-extended (
src1_sel:WORD_0with 0.5 gives +inf from 1.0,WORD_1gives 1.0), while the recompiler still reads the f32 bits there. A follow-up PR for that path would be welcome.