Repository navigation
Recompiler: float16 params reach the PS as the floats of their halves - #3584
CharlyRien wants to merge 5 commits into
Conversation
A retail title's world pixel shaders (xcl-dev#505; 173 of its 362) pack their float16 interpolants: two components per dword (component c of a register in dword c / 2, the even one in the low half) and up to two signature registers per attribute, the second after the dwords the first one's components take (1 for .xy, 2 for .xyz / .xyzw). The PS reads each half with v_interp_p2_f16, SRC0 bit 8 choosing the high one. XCL refused the PS input table of such programs (records [6, reg, mask, attr, 0, reg2, packed reg, flags]: flag 8 = float16, flag 16 = byte 5 names the second register, byte 6 below byte 1 from the first pair on), so every attribute, plain ones included, fell back to "the N-th register" and the ones after a pair read their neighbour. The PS also converted the raw packed dword as a float, ignored the high bit and declared the float16 inputs nointerpolation. Now the table parses, each (dword, half) of a packed attribute maps to its element and component (f16_registers, ps_f16_slot; a record that repeats its own register pairs it with the next float16 register no other attribute names), and the PS reads that component as a float, interpolated with the attribute's own mode. Both translators (HLSL and direct DXIL). The layout was checked on the title's dumped programs: every v_interp_p2_f16 (dword, half) of 376 of 378 packed attributes in 362 PS is a declared component (2 read one past a .xy register). Not covered here: the VS / mesh side still exports the packed dwords raw (the next commit), so the GPU test feeds the PS from a PC VS that hands over each component as a float. register always in dwords 2-3, a repeated register paired with itself - which does not match the title's programs after a .xy register; both have since dropped their float16 part in favour of this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The other half of the previous commit: the VS and mesh (NGG) programs that feed those pixel shaders export their float16 interpolants packed the same way - two components per dword, up to two signature registers per exp param. XCL refused the output table of such programs (records [6, reg, param, reg, 0, 1 | 3]: 1 = float16, 3 = more than one dword) and fell back to "the N-th register", so every param after a pair went to its neighbour's register; a packed param went raw into its first register alone. A mesh program never used its table at all. Now the table parses for VS and mesh programs (MsInterface::params) and a packed param is unpacked where it is exported: each half goes as a float to its own component of its own element, in the VS outputs and in the mesh record, in both translators. The table does not name the second register of a pair: the float16 registers pair up in order, so it is the next one no other param starts with (f16_registers). Checked on the title's dumped programs: the enable mask of every exp param of 383 packed params in 442 MS is exactly the predicted dwords. A mesh program with a table now takes its params' registers from it, float16 or not, as a VS already did; without one nothing changes. dwords 2-3 and paired a mesh program's registers without its table; it has since dropped that part in favour of this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two commits before this one (PR 2513, ported) take every float16 record of a VS / mesh output table - flag 1 or 3 - as two halves a dword. The retail title (xcl-dev#505) has two kinds (PR 2513's thread, CharlyRien 2026-11-29, and its own listings): flag-3 records packed in dwords 0-1, with filler in dwords 2-3 of an .xyzw register (exp param 7: two v_pack_b32_f16, 0 and 0x3c00, en 0xF), and flag-1 records on .xyzw registers exported over four dwords, a half in the low bits of each (four v_and_b32 v, 0xffff, h, en 0xF). Taken as packed, the second kind lost dwords 2-3 and its components 1-3 got the wrong halves. A flag-3 record is packed; a flag-1 one only where its export writes exactly its packed dwords and not also one dword per component, else one half a dword: component c is the low half of dword c (ParamLayout, F16Param). Either way each component reaches its element as the float of its half, in the VS export and the mesh store of both translators, so a float16 element is an ordinary float however the PS reads it: interpolated by v_interp_p2_f16 (the PR's single float16, a flag-1 .x read so), or flat by v_interp_mov_f32, which now gives the half of a float16 attribute's float back in the low bits, as the title's v_cvt_f32_f16 takes it - both halves of the dword where the PS record names a second register (packed). The round trip is exact for every half but a NaN's payload. On the HLSL path the VS export assigned a dword to a float output as a number for every component type but 3 (the thread, 13:44Z: a raw half 1.0 arrived as 0, 0.7 as 2048); it is now bitcast for every element HLSL declares float (all but types 1 and 2). And a float16 PS input takes the interpolation its reads give it - flat where v_interp_mov reads it, interpolated where v_interp_p1 / p2 do - where it was flat unless the PS table marked it packed; integers stay flat. Both translators. Tests, each failing without its part: - dxil::core_tests::f16_params_reach_the_ps_as_the_floats_of_their_halves: the title's two kinds (flag 3 packed with filler, en 0xF; flag 1 over four dwords) and a flag-1 .x, from an HLSL and a direct VS to a PC PS; - dxil::core_tests::f16_params_reach_a_console_ps_however_it_reads_them: the same from a console VS to a console PS reading them by v_interp_p2_f16 per half, by v_interp_mov_f32 and v_cvt_f32_f16, and the .x interpolated by v_interp_p2_f16 - HLSL and direct, and across; - dxil::core_tests::f16_ps_inputs_take_the_mode_their_reads_give_them; - recomp::attribute_tests::a_float16_params_layout_follows_its_record_and_its_export; - recomp::tests::a_float16_ps_input_takes_the_mode_its_reads_give_it. Ported from Jockerino/xcl-fork b6ee86a1 (https://github.com/Jockerino/xcl-fork, GPL-3.0-or-later), written there on top of the fork's own port of xcl-dev#2513, with the fork author's agreement. Moved onto main b2b1f10 + xcl-dev#2513: conflicts in lower_gfx.rs (main's integer-to-float conversion of PS inputs, kept) and recomp/mod.rs. Co-authored-by: Jockerino <51916136+Jockerino@users.noreply.github.com> Assisted-by: Antigravity CLI (Gemini 4 Neon), conflict resolution Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ps_f16_slot fell back to the register's first element when no element declared the component of a (dword, half): the PS then read another element's component instead of the 0 its doc comment promises. In a retail title's shader pack 6 pixel shaders (character shaders) read such a half: channel 3 of a packed attribute whose register declares .xy only. Now the slot is None and both translators read 0. Test: f16_packed_attributes checks two such halves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rerun on the new head ( merge-check
Earlier report on 44b3dcd (base 6bfb5c5) |
|
Review (head 44b3dcd, diff read, not a merge-check):
Fine: the flag-1/flag-3 split, the half extraction and the float bitcast of float16 outputs match between the HLSL and direct DXIL VS/MS paths; a half no element declares now reads 0 in both PS translators; the GPU tests cover each case through both translators. This carries #2513's two commits rebased and fixes its flag-1 handling, so merging it supersedes #2513. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
Review on PR 3584 (Foniass): the VS picks a flag-1 param's layout from its export, the PS from its instruction, and nothing showed when they could disagree; F16Param::disagrees was only used by tests. Each stage now logs once per shape what is right only if the other made the same choice: an export that disagrees with its record, a flag-1 param exported packed (a PS reading it with v_interp_mov_f32 gets the low half), and a v_interp_p2_f16 read of a flag-1 attribute beyond the low half of dword 0 (right only if its VS packed it). The layouts chosen do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, both points are right (checked on 44b3dcd).
New commit
It does not refuse anything: with VS and PS translated separately there is no way to know which side is wrong, and a consistent packed flag-1 pair logs both lines (bounded by the once-per-shape dedup). Linking the two at PSO creation would need both stages' layouts outside the translation cache; I left that out of this PR. Tested on AI use: Claude Code (Claude Opus 5.5) checked the points, wrote the commit, ran the tests and wrote this reply, posted at my request; Gemini 4 Neon (Antigravity CLI) reviewed the commit. |
|
Follow-up review (head 7de960d, since 44b3dcd, diff read, not a merge-check):
New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
Stacked on #2513 (MacieGx, float16 interpolants packed two per dword); only the commits above #2513's two belong here. #2513's two commits are included rebased onto current main (
b2b1f109), with three conflicts resolved: main's integer-to-float conversion of PS inputs inv_interp_p2_*(36e1c89) is kept next to #2513's per-half mapping, and main'svok/pokmesh guards are kept with #2513'sparams.The first of them (
27332a4e) is a port ofb6ee86a1from Jockerino's fork (https://github.com/Jockerino/xcl-fork, GPL-3.0-or-later), with the author's agreement. It fixes the flag-1 case we reported on #2513 (#2513, 29/11): a float16 record with flag 1 is one half per dword (component c in the low half of dword c, exported over four dwords), not two halves a dword; only flag 3 is packed. Taken as packed, a flag-1.xyzwparam lost dwords 2-3 and its components 1-3 read the wrong halves. It also bitcasts the HLSL VS export for every float element, and gives a float16 PS input the interpolation its reads ask for, in both translators.What is in it
2790f41d,6d0d0b63: Recompiler: float16 interpolants packed two per dword reach the PS per half #2513 (MacieGx), rebased onto main (gpu/dxil/lower_gfx.rs,kernel.rs,recomp/emit.rs,recomp/mod.rs, tests).27332a4e: flag 1 vs flag 3, from the fork'sb6ee86a1(recomp/mod.rsParamLayout/F16Param,recomp/emit.rs,dxil/lower_gfx.rs,dxil/lower_mem.rs, 5 tests).44b3dcd0: a float16 half that no PS input element declares reads 0 (recomp/mod.rsps_f16_slot): it fell back to the register's first element, so the PS read another element's component. Found by review, then counted in the title's shader pack: 6 pixel shaders (character shaders) read such a half (channel 3 of a packed attribute whose register declares.xyonly). Test: two such halves inf16_packed_attributes.7de960d3: no layout change (the HLSL / DXIL produced is the same); each stage logs once per shape what is right only if the other stage chose the same float16 layout: a VS / MS record and its export that disagree (F16Param::disagrees, now called inout_param_layout), a flag-1 param exported packed, and a PSv_interp_p2_f16read of a flag-1 attribute beyond the low half of dword 0 (after Foniass's review). Test:a_ps_read_of_a_flag1_attribute_beyond_its_first_half_assumes_packing, and the layout test checksdisagrees.Tested
XCL_REQUIRE_GPU=mesh, the only skip allowed is "no wave64"): 10 passed, 0 failed, no SKIPPED (on7de960d3).cargo test --workspace --no-fail-fast -- --test-threads=4(debug) on7de960d3: 2910 passed, 2 failed, 51 ignored; 25 SKIPPED (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps). The 2 failures are the e2e debug-layer teststest_title_draws_with_a_root_signature_under_the_debug_layerandtest_title_runs_under_the_debug_layer_with_dred; they fail on mainb2b1f109on this card too (2900 passed, the same 2 failed, 51 ignored).44b3dcd0on our local tree (7de960d3adds log lines only) (main 493dbd3 + D3D12.X: use whole form once ready for split ExecuteIndirect #3528 + Memory: the 16-window layout keeps 4 runtime sparse windows #3517 + 42 local commits + two lab switches that leave out Recompiler: direct PS compares skip the per-quad mask where no helper bit is read #2571's mask forms and Recompiler: direct DXIL PS IR cuts (shared float decode, direct quad shuffles, predicate-derived lane masks) #3501's quad-ballot lowering, see Recompiler: direct PS compares skip the per-quad mask where no helper bit is read #2571 (comment)), fresh shader preparation, same switches as there; world reached in 2 of 3 runs:Regression run
scripts/smoke.ps1, 60 s, the retail title,XCL_PREPARE=0, cold shader cache on both sides; main first, then this head: 516 frames vs 543 (95 %), peak commit 16,013 vs 15,844 MB, no removal, no crash.Not tested
b6ee86a1, checked against every program of the retail title's shader pack (12,095 PS, 11,518 VS / MS) and the 1,375 graphics pipelines a run used: a half nothing declares (6 PS, fixed in44b3dcd0); a float16 attribute without a second register read byv_interp_mov_f32(35 PS in the used pipelines, all fed by a flag-1 VS param, so the one-half-per-dword reading is right: 0 mismatches); a one-half-per-dword attribute read byv_interp_p2_f16at a channel > 0 (0 cases); a flag-1 export with a partial mask (0 cases). Not checked on other titles.byte 6 < byte 1without a float16 flag, which can replace the old "N-th register" fallback; the HLSL VS export now bitcasts every element HLSL declares float (types other than 1 and 2), where it converted every type but 3.AI use