Recompiler: float16 params reach the PS as the floats of their halves #3584
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3584"
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 ivall/xcl. Originally posted by CharlyRien on 2026-12-01T15:42:34Z.
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_*(36e1c899) 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 (https://github.com/xcl-dev/xcl/pull/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: #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) (main493dbd3d+ #3528 + #3517 + 42 local commits + two lab switches that leave out #2571's mask forms and #3501's quad-ballot lowering, see https://github.com/xcl-dev/xcl/pull/2571#issuecomment-7311064649), 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
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T18:08:20Z.
merge-check
base:
1c8b551475head:
7de960d31emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2918 passed, 1 failed, 51 ignored (base: 2909 passed); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing:
hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime. Not this PR: it is the race #3551 fixes, and it passed alone 3 of 3 on this merge.review: Rerun on the new head (
7de960d3: one commit that logs the float16 layouts only the other stage can confirm; the HLSL / DXIL produced is unchanged). The earlier report, on44b3dcd0, is below. read7de960d3(3 files, +75 -6). No correctness problem found; logging only.F16Param::disagreesand logs a record whose export matches neither layout, and a flag-1 param exported packed.v_interp_p2_f16read of a flag-1 attribute past the low half of dword 0. Each shape is logged once per process (the line does not name the shader).float16 PS read: v_interp_p2_f16 reads flag-1 attribute 0 at channel 1 as packed halves: right only if its VS exports it packedandfloat16 export: param 1 (flag-1 record) exported over dwords 0x7, neither its packed dwords 0x3 nor one a component 0xf: laid out Halves.a_ps_read_of_a_flag1_attribute_beyond_its_first_half_assumes_packing), withXCL_REQUIRE_GPU=mesh: 3 of 3 rounds, 10 passed, none skipped.performance: none: a set lookup per float16 export / read at translation time.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Earlier report on
44b3dcd0(base6bfb5c51)Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:33:29Z.
Review (head
44b3dcd0, diff read, not a merge-check):HalvesorPackedfor a flag-1 param from the export'sen(out_param_layout,gpu/recomp/mod.rs~769-778), but the PS picks it from the instruction alone:v_interp_p2_f16always takes the packed reading (ps_f16_slot, ~817;emit.rs~2515,lower_gfx.rs~418) andv_interp_mov_f32always the one-half reading (emit.rs~2535,lower_gfx.rs~430). Sov_interp_p2_f16reading channel 1 of a flag-1.xyzwparam exported over four dwords (the shape the description calls the title's usual one) gets component 2, and channels 2-3 read 0;v_interp_mov_f32on a flag-1 param exported packed gets only the low half. The description counts 0 such reads in one title, but nothing detects or refuses these shapes.F16Param::disagreesis never called outside tests.mod.rs~750 computes when a record and its export disagree, but no translator path calls it (out_param_elements, ~799, is also test-only), so a mismatched export silently gets theHalvesguess with no log line. That is the one signal that would make the shapes above visible on other titles.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.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-01T23:15:35Z.
Thanks, both points are right (checked on
44b3dcd0).envs instruction), and nothing detected a disagreement. On the retail title I surveyed its shader pack offline before opening the PR: across all 12095 PS programs, nov_interp_p2_f16read of a flag-1 attribute beyond channel 0; across its 67 flag-1 VS/MS records, no export that disagrees with the record; and the 41 used pipelines that pair a flag-1 export with a PS read are all consistent (VS one half a dword +v_interp_mov_f32). So this title is not affected, but nothing protects another one.F16Param::disagreeswas indeed test-only.New commit
7de960d3makes these shapes visible without changing any layout (the HLSL / DXIL produced is the same): each stage logs once per shape what is right only if the other stage made the same choice:disagrees, now called inout_param_layout), and a flag-1 param exported packed (a PS reading it withv_interp_mov_f32would get only the low half);v_interp_p2_f16read of a flag-1 attribute beyond the low half of dword 0 (right only if its VS packed it).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
7de960d3(RTX 3090, Windows 11, release unless said): the 10 named tests (the 9 of the PR anda_ps_read_of_a_flag1_attribute_beyond_its_first_half_assumes_packing) on the GPU: 10 passed, no SKIPPED. Whole suite (debug,--test-threads=4): 2910 passed, 2 failed, 51 ignored; the 2 failures are the same two e2e debug-layer tests that fail on main on this card. Smoke (60 s, cold cache): 516 frames vs 543 on mainb2b1f109(95 %), peak commit 16,013 vs 15,844 MB, no removal, no crash; the PR description's blocks are updated.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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:17:54Z.
Follow-up review (head
7de960d3, since44b3dcd0, diff read, not a merge-check):flag1_packed,gpu/recomp/mod.rs~812), the PS av_interp_p2_f16read of a flag-1 attribute past the low half of dword 0 (note_ps_f16_read, ~784, fromemit.rs~2516 andlower_gfx.rs~420). The translation still picks each stage's layout on its own, so av_interp_p2_f16read at channel 1 of a flag-1.xyzwparam exported over four dwords still gets component 2, and av_interp_mov_f32of a flag-1 param exported packed still gets only the low half; nothing compares the two stages at link time or refuses the pair. The log lines are once per shape for the process and do not name the shader.F16Param::disagreesis never called outside tests: fixed.out_param_layout(~808) now calls it on the VS, HLSL MS and DXIL MS paths and logs a record whose export matches neither layout.out_param_elements(~842) is still test-only.New: none.
7de960d3changes only logging, both PS translators make the same check, and the new unit tests coverps_f16_read_assumes_packedandflag1_packed.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by claudetools-gh on 2026-12-02T13:37:52Z.
Tested head
7de960d3on another card, cherry-picked onto an older tree. Our lab line is main from late November plus local commits. Main's36e1c899went in first, since this PR builds on it. The only conflict was a test indxil/robustness_tests.rs: our older version of the test needed the newparams: Nonefield onMsInterface.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:
XCL_DUMP_TARGETSframe with the PR, in the prologue cell, has the hair dark brown in the albedo target and near white in the lit target, so the colour comes from the lighting pass.AI-assisted.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 2395High: The float16 param path calls
exp_comp(srcs, compr, dw)and then shifts by 16*half. For a COMPR export,exp_compalready 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). Forexp param0 compr en=0x3of a packed float16 param (srcs[0] = c0|c1<<16), component 1 maps to dw 0, half 1.exp_comp(.., 0)givessrcs[0] & 0xFFFF, and>> 16of that is 0, so c1 reads 0.0. Thedwordsmask is also built per half (0x3 for one dword), soF16Param::layout/disagreescompare against the wrong mask. For COMPR, reading the raw dword (notexp_comp) before shifting would fix all four sites.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Code review location:
crates/xcl/src/gpu/recomp/mod.rs; line 678High: 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. 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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Code review location:
crates/xcl/src/gpu/recomp/mod.rs; line 950High: Mesh shaders now take
paramsfromvs_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. An MS whose FSSM has count 0 at +0x1D4+0xC0 (or a sub-version-5 MS whose table holds unrelated records) parses toSome(vec![]).out_param_layoutthen returns no elements for everyexp 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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Code review location:
crates/xcl/src/gpu/recomp/mod.rs; line 858High: The PS side reads a flag-1 (unpaired) float16 attribute with
v_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 the two stages disagree, and the PR only logs it. For a flag-1.xyzwparam exported over en 0xF, a PSv_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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Code review location:
crates/xcl/src/gpu/recomp/mod.rs; line 680Medium: 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.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:37Z.
Review: COMMENTED
Review of
7de960d3: 6 finding(s) (4 high, 2 medium), most severe first.crates/xcl/src/gpu/recomp/emit.rs:2395: The float16 param path callsexp_comp(srcs, compr, dw)and then shifts by 16*half. (inline)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)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)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)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)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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:38Z.
Code review location:
crates/xcl/src/gpu/dxil/lower_gfx.rs; line 436Medium:
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. That's the bug44b3dcd0fixed only forv_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, returnsto_f16of another element's component instead of 0, the same wrong-component read44b3dcd0reported for 6 PS in the title's pack.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:03:40Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.