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. |
|
Tested head RTX 5070 Ti 16 GB, driver 621.40, Windows 11, release build, direct DXIL for graphics (the default). Same title, a new game, so the intro cutscenes are compared at the same moments. Two runs without the PR, one with it. The preparation took 16 s and there was no crash or device removal. What changed, compared with the reference footage:
Still off with the PR, in case it helps narrow the remaining cases:
AI-assisted. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 7de960d3: 6 finding(s) (4 high, 2 medium), most severe first.
- High
crates/xcl/src/gpu/recomp/emit.rs:2395: The float16 param path callsexp_comp(srcs, compr, dw)and then shifts by 16*half. (inline) - High
crates/xcl/src/gpu/recomp/mod.rs:678: On the VS/MS side,f16_registerstreats every flag-3 param as a pair and gives it the lowest float16 register above it that no table entry starts. (inline) - High
crates/xcl/src/gpu/recomp/mod.rs:950: Mesh shaders now takeparamsfromvs_output_tablewith no sanity check, so a table that parses but is empty or wrong replaces the earlier "N-th distinct OSG1 register" mapping and drops or moves every param export. (inline) - High
crates/xcl/src/gpu/recomp/mod.rs:858: The PS side reads a flag-1 (unpaired) float16 attribute withv_interp_p2_f16as packed (comp = 2*chan + high), while the VS side lays out the title's usual flag-1 export (en 0xF) as Halves (component c in the low half of dword c), so t.... (inline) - Medium
crates/xcl/src/gpu/recomp/mod.rs:680: Not certain about this one: the dword where a pair's second register starts comes from the declared width of the first register in each stage's own signature (PS inputs on one side, VS/MS outputs on the other). (inline) - Medium
crates/xcl/src/gpu/dxil/lower_gfx.rs:436:v_interp_mov_f32of an unpaired float16 attribute usesplacefromps_attribute_slot, which falls back to the register's first element when no element declares the channel. (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| let v = Self::exp_comp(srcs, compr, c); | ||
| let v = if e.component_type == 3 { format!("asfloat({v})") } else { format!("{v}") }; | ||
| // float16: component c is the float of its half (`ParamLayout::place`) | ||
| let (dw, half) = layout.place(first, c); |
There was a problem hiding this comment.
High: The float16 param path calls exp_comp(srcs, compr, dw) and then shifts by 16*half. For a COMPR export, exp_comp already returns a 16-bit half picked by component index, so the half is selected twice and the layout is applied in the wrong space. The same code is at emit.rs:2463 (MS), lower_gfx.rs:341 (DXIL VS) and lower_mem.rs:2710 (DXIL MS). For exp param0 compr en=0x3 of a packed float16 param (srcs[0] = c0|c1<<16), component 1 maps to dw 0, half 1. exp_comp(.., 0) gives srcs[0] & 0xFFFF, and >> 16 of that is 0, so c1 reads 0.0. The dwords mask is also built per half (0x3 for one dword), so F16Param::layout / disagrees compare against the wrong mask. For COMPR, reading the raw dword (not exp_comp) before shifting would fix all four sites.
| let second = match second { | ||
| Some(r) if r != first => Some(r), | ||
| _ if !pair => None, | ||
| _ => sig.iter().filter(|e| e.component_type == 6 && e.system_value == 0 && e.register > first && !claimed(e.register)).map(|e| e.register).min(), |
There was a problem hiding this comment.
High: On the VS/MS side, f16_registers treats every flag-3 param as a pair and gives it the lowest float16 register above it that no table entry starts. It never excludes registers another flag-3 param has already taken as its second, and flag 3 only means "more than one dword", not "has a second register". With float16 outputs r1, r3, r4 (.xyzw), p0 = r1 flag 3 (one register packed in dwords 0-1, filler 0/0x3c00 in dwords 2-3, the title's exp param 7 shape) and p1 = r3 flag 3 (r3+r4), claimed = {1,3}, so p0 also takes r4 and writes r4 from its filler dwords (0.0, 1.0). If p0 is exported after p1, the PS reads filler instead of p1's real data, and p0's packed mask gains 0xC, which changes the disagreement check. Tracking claimed seconds, and only pairing when the param's dwords actually extend past the first register, would avoid it.
| threads, | ||
| max_vertices: (p.ms_max_vertices as u32).clamp(1, 256), | ||
| max_primitives: (p.ms_max_primitives as u32).clamp(1, 256), | ||
| params: vs_output_table(&f.data), |
There was a problem hiding this comment.
High: Mesh shaders now take params from vs_output_table with no sanity check, so a table that parses but is empty or wrong replaces the earlier "N-th distinct OSG1 register" mapping and drops or moves every param export. An MS whose FSSM has count 0 at +0x1D4+0xC0 (or a sub-version-5 MS whose table holds unrelated records) parses to Some(vec![]). out_param_layout then returns no elements for every exp param N, each param becomes a dummy, and the PS reads 0 for every attribute where it used to be correct. Falling back to the old mapping when the table is empty or doesn't cover the exported params would keep MS working.
|
|
||
| /// The place in `ranked(inputs, false)` and the component of the float16 in half `high` of | ||
| /// dword `chan` of a packed attribute (`regs`: `ps_attribute_f16`). None: no such component. | ||
| pub fn ps_f16_slot(ps: &PsInterface, regs: &[(u32, usize)], chan: usize, high: bool) -> Option<(usize, usize)> { |
There was a problem hiding this comment.
High: The PS side reads a flag-1 (unpaired) float16 attribute with v_interp_p2_f16 as packed (comp = 2*chan + high), while the VS side lays out the title's usual flag-1 export (en 0xF) as Halves (component c in the low half of dword c), so the two stages disagree, and the PR only logs it. For a flag-1 .xyzw param exported over en 0xF, a PS v_interp_p2_f16 attr0.y (chan 1, low half) maps to PS component 2, so it reads the VS's .z where the console reads .y. A high-half read of chan 0 gets .y instead of the high half of dword 0 (0 on hardware). Both stages need to use the same layout decision for flag-1 params.
| _ if !pair => None, | ||
| _ => sig.iter().filter(|e| e.component_type == 6 && e.system_value == 0 && e.register > first && !claimed(e.register)).map(|e| e.register).min(), | ||
| }; | ||
| let width = sig.iter().filter(|e| e.system_value == 0 && e.register == first).map(|e| 8 - e.mask.leading_zeros() as usize).max().unwrap_or(4); |
There was a problem hiding this comment.
Medium: Not certain about this one: the dword where a pair's second register starts comes from the declared width of the first register in each stage's own signature (PS inputs on one side, VS/MS outputs on the other). So a PS that declares fewer components than the VS writes puts it at a different dword. With VS/MS r1 .xyzw (second register at dword 2) and the PS's ISG1 declaring r1 as .xy (second at dword 1), the PS read of chan 1 goes to the second register while the VS wrote r1.zw there. The PS gets r2's values in place of r1.zw and is off by one dword from then on. Taking the width from the producing stage on both sides would make them agree.
| // second register (packed) | ||
| let f16_mov = match ps_attribute_f16(&ps, attr as usize).filter(|_| name == "v_interp_mov_f32") { | ||
| Some(regs) if ps.attrs.as_ref().and_then(|t| t.get(attr as usize)).is_some_and(|a| a.pair.is_some()) => Some([ps_f16_slot(&ps, ®s, chan as usize, false), ps_f16_slot(&ps, ®s, chan as usize, true)]), | ||
| Some(_) => Some([place, None]), |
There was a problem hiding this comment.
Medium: v_interp_mov_f32 of an unpaired float16 attribute uses place from ps_attribute_slot, which falls back to the register's first element when no element declares the channel. That's the bug 44b3dcd fixed only for v_interp_p2_f16, and emit.rs:2540 has the same code. A flag-1 float16 attribute whose register declares only .xy, read flat at chan 2 or 3, returns to_f16 of another element's component instead of 0, the same wrong-component read 44b3dcd reported for 6 PS in the title's pack.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
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