Recompiler: float16 params reach the PS as the floats of their halves #3584

Open
CharlyRien wants to merge 5 commits from upstream-pr/3584 into main
CharlyRien commented 2026-12-01 15:42:34 +00:00 (Migrated from github.com)

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 in v_interp_p2_* (36e1c899) is kept next to #2513's per-half mapping, and main's vok / pok mesh guards are kept with #2513's params.

The first of them (27332a4e) is a port of b6ee86a1 from 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 .xyzw param 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's b6ee86a1 (recomp/mod.rs ParamLayout / 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.rs ps_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 .xy only). Test: two such halves in f16_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 in out_param_layout), a flag-1 param exported packed, and a PS v_interp_p2_f16 read 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 checks disagrees.

Tested

  • RTX 3090 24 GB (driver 616.56, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631, release.
  • The 10 new tests by name, on the GPU (XCL_REQUIRE_GPU=mesh, the only skip allowed is "no wave64"): 10 passed, 0 failed, no SKIPPED (on 7de960d3).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on 7de960d3: 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 tests test_title_draws_with_a_root_signature_under_the_debug_layer and test_title_runs_under_the_debug_layer_with_dred; they fail on main b2b1f109 on this card too (2900 passed, the same 2 failed, 51 ignored).
  • The retail title, the commits up to 44b3dcd0 on our local tree (7de960d3 adds log lines only) (main 493dbd3d + #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:
    • the half-dark window (a black / red triangle over the window, ~55-64 % of its frame dark in our runs without this PR) is gone in both runs that reached the world: 0-5 % dark, the view through the window is drawn;
    • no bright isolated speckles (0.00-0.01 per mille of the window area, 0.93 without);
    • 0.76 and 0.80 presents/s (0.66 and 1.41 without); the third run hung the GPU before the world in a compute shader whose translation this PR leaves byte-identical.

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.
xcl-smoke v1
commit: b2b1f109d27e746a62ec95b04dd1f9924452e682
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 543 (PresentX 543)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15844 MB
xcl-smoke v1
commit: 7de960d31e2c0b101db6d675d124c5c385e19196
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 516 (PresentX 516)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16013 MB

Not tested

  • AMD and wave64 hardware.
  • Plain main in the world (our tree carries other changes, listed above).
  • Edge cases from a read-only review of #2513 + 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 in 44b3dcd0); a float16 attribute without a second register read by v_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 by v_interp_p2_f16 at a channel > 0 (0 cases); a flag-1 export with a partial mask (0 cases). Not checked on other titles.
  • Changes for programs without float16 params (from #2513, read, not measured): a mesh shader now uses its output table when the table parses, so a table whose order differs from the OSG1 registers moves its exports (and an empty table that parses drops them); the PS input-table parser also accepts records with byte 6 < byte 1 without 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

  • Claude Code (Claude Opus 5.5) ran the builds, tests and game runs, checked the ports and wrote this description; Antigravity CLI (Gemini 4 Neon) resolved the rebase conflicts; Codex (GPT-6.2 Sol) reviewed the result read-only. The flag-1 analysis on #2513 and the fork's code are credited above. Checked and opened by me.
<!-- greyfinch-sync:ivall/xcl:issue:5589103056 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584). Originally posted by [CharlyRien](https://github.com/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 in `v_interp_p2_*` (36e1c899) is kept next to #2513's per-half mapping, and main's `vok` / `pok` mesh guards are kept with #2513's `params`. The first of them (`27332a4e`) is a port of `b6ee86a1` from 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 `.xyzw` param 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's `b6ee86a1` (`recomp/mod.rs` `ParamLayout` / `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.rs` `ps_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 `.xy` only). Test: two such halves in `f16_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 in `out_param_layout`), a flag-1 param exported packed, and a PS `v_interp_p2_f16` read 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 checks `disagrees`. **Tested** - RTX 3090 24 GB (driver 616.56, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631, release. - The 10 new tests by name, on the GPU (`XCL_REQUIRE_GPU=mesh`, the only skip allowed is "no wave64"): 10 passed, 0 failed, no SKIPPED (on `7de960d3`). - `cargo test --workspace --no-fail-fast -- --test-threads=4` (debug) on `7de960d3`: 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 tests `test_title_draws_with_a_root_signature_under_the_debug_layer` and `test_title_runs_under_the_debug_layer_with_dred`; they fail on main `b2b1f109` on this card too (2900 passed, the same 2 failed, 51 ignored). - The retail title, the commits up to `44b3dcd0` on our local tree (`7de960d3` adds log lines only) (main 493dbd3d + #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: - the half-dark window (a black / red triangle over the window, ~55-64 % of its frame dark in our runs without this PR) is gone in both runs that reached the world: 0-5 % dark, the view through the window is drawn; - no bright isolated speckles (0.00-0.01 per mille of the window area, 0.93 without); - 0.76 and 0.80 presents/s (0.66 and 1.41 without); the third run hung the GPU before the world in a compute shader whose translation this PR leaves byte-identical. **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. ``` xcl-smoke v1 commit: b2b1f109d27e746a62ec95b04dd1f9924452e682 gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 543 (PresentX 543) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15844 MB ``` ``` xcl-smoke v1 commit: 7de960d31e2c0b101db6d675d124c5c385e19196 gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 516 (PresentX 516) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16013 MB ``` **Not tested** - AMD and wave64 hardware. - Plain main in the world (our tree carries other changes, listed above). - Edge cases from a read-only review of #2513 + `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 in `44b3dcd0`); a float16 attribute without a second register read by `v_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 by `v_interp_p2_f16` at a channel > 0 (0 cases); a flag-1 export with a partial mask (0 cases). Not checked on other titles. - Changes for programs without float16 params (from #2513, read, not measured): a mesh shader now uses its output table when the table parses, so a table whose order differs from the OSG1 registers moves its exports (and an empty table that parses drops them); the PS input-table parser also accepts records with `byte 6 < byte 1` without 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** - Claude Code (Claude Opus 5.5) ran the builds, tests and game runs, checked the ports and wrote this description; Antigravity CLI (Gemini 4 Neon) resolved the rebase conflicts; Codex (GPT-6.2 Sol) reviewed the result read-only. The flag-1 analysis on #2513 and the fork's code are credited above. Checked and opened by me.
fromthemoonx commented 2026-12-01 18:08:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T18:08:20Z.


merge-check
base: 1c8b551475
head: 7de960d31e
merge: 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, on 44b3dcd0, is below. read 7de960d3 (3 files, +75 -6). No correctness problem found; logging only.

  • The VS / MS export path now calls F16Param::disagrees and logs a record whose export matches neither layout, and a flag-1 param exported packed.
  • Both PS translators log a v_interp_p2_f16 read 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).
  • The lines show up in the suite, for example 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 packed and float16 export: param 1 (flag-1 record) exported over dwords 0x7, neither its packed dwords 0x3 nor one a component 0xf: laid out Halves.
  • The 10 named tests (the 9 earlier plus a_ps_read_of_a_flag1_attribute_beyond_its_first_half_assumes_packing), with XCL_REQUIRE_GPU=mesh: 3 of 3 rounds, 10 passed, none skipped.
  • The layout disagreement Foniass found is now logged, not fixed: a mismatched VS / PS pair still reads the wrong half (his follow-up). The author's survey of one title's pack found no such pair. Another title's would show these lines. I missed this point in my first report.
  • No retail title on this machine.
    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 (base 6bfb5c51)
merge-check
base: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
head: 44b3dcd0e170f9a3921cc1e6eaa3a3218ba84aaf
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 1 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); 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` (left 2, right 1). Not this PR: it is the shared-counter race #3551 fixes, and it passed alone 3 of 3 on this merge.
review: read the whole diff (all 4 commits, so #2513's two as well: 11 files, +972 -54). No correctness problem found.
- The 9 new tests by name with `XCL_REQUIRE_GPU=mesh` on this wave32 GPU: 3 of 3 rounds, 9 passed, none skipped. The GPU ones (`f16_params_reach_the_ps_as_the_floats_of_their_halves`, `f16_params_reach_a_console_ps_however_it_reads_them`, `gpu_mesh_f16_packed_params`, ...) ran.
- Mutation: `F16Param::layout` always `Packed` (the flag-1 fix undone) fails `a_float16_params_layout_follows_its_record_and_its_export`, `f16_params_reach_the_ps_as_the_floats_of_their_halves` and `f16_params_reach_a_console_ps_however_it_reads_them`. Good.
- Mutation: `ps_f16_slot` ignoring the element's mask (the top commit undone) fails `f16_packed_attributes`. Good.
- Changes that also reach programs without float16, worth knowing:
  - Mesh `exp param N` now follows the FSSM output table (`MsInterface::params` from `vs_output_table`) where it used the N-th distinct register (`param_registers`). This applies to every mesh program with a table, float16 or not. It matches what the VS already did; the description's 442 MS are its evidence. No title was run here.
  - `ps_input_table` accepts a record whose byte 6 is below its register (`r[6] > r[1]` rejects, was `r[6] != r[1]`), also in tables with no float16 pair. Before, such a table was refused and the attributes fell back to distinct-register order.
  - The HLSL VS export now writes `asfloat` for every element type other than 1 / 2 (uint / sint), not only type 3.
- `src/gpu/recomp/{emit,mod}.rs` and `src/gpu/dxil` are in the translator identity, so cached translations rebuild once after the update.
- Provenance: the fork commit is credited in `27332a4e` (`Co-authored-by: Jockerino`, GPL-3.0-or-later, the author's agreement), and #2513's commits keep MacieGx as author.
- No retail title on this machine: the title's float16 shaders were not translated or drawn here.
performance: not measured. Float16 halves cost a shift and an `f16tof32` per component at export; programs without float16 records take the old paths (apart from the mesh table above).
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)
<!-- greyfinch-sync:ivall/xcl:comment:7320463197 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7320463197). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T18:08:20Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 7de960d31e2c0b101db6d675d124c5c385e19196 merge: 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, on `44b3dcd0`, is below. read `7de960d3` (3 files, +75 -6). No correctness problem found; logging only. - The VS / MS export path now calls `F16Param::disagrees` and logs a record whose export matches neither layout, and a flag-1 param exported packed. - Both PS translators log a `v_interp_p2_f16` read 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). - The lines show up in the suite, for example `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 packed` and `float16 export: param 1 (flag-1 record) exported over dwords 0x7, neither its packed dwords 0x3 nor one a component 0xf: laid out Halves`. - The 10 named tests (the 9 earlier plus `a_ps_read_of_a_flag1_attribute_beyond_its_first_half_assumes_packing`), with `XCL_REQUIRE_GPU=mesh`: 3 of 3 rounds, 10 passed, none skipped. - The layout disagreement Foniass found is now logged, not fixed: a mismatched VS / PS pair still reads the wrong half (his follow-up). The author's survey of one title's pack found no such pair. Another title's would show these lines. I missed this point in my first report. - No retail title on this machine. 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) <details><summary>Earlier report on 44b3dcd0 (base 6bfb5c51)</summary> ```text merge-check base: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c head: 44b3dcd0e170f9a3921cc1e6eaa3a3218ba84aaf merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 1 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); 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` (left 2, right 1). Not this PR: it is the shared-counter race #3551 fixes, and it passed alone 3 of 3 on this merge. review: read the whole diff (all 4 commits, so #2513's two as well: 11 files, +972 -54). No correctness problem found. - The 9 new tests by name with `XCL_REQUIRE_GPU=mesh` on this wave32 GPU: 3 of 3 rounds, 9 passed, none skipped. The GPU ones (`f16_params_reach_the_ps_as_the_floats_of_their_halves`, `f16_params_reach_a_console_ps_however_it_reads_them`, `gpu_mesh_f16_packed_params`, ...) ran. - Mutation: `F16Param::layout` always `Packed` (the flag-1 fix undone) fails `a_float16_params_layout_follows_its_record_and_its_export`, `f16_params_reach_the_ps_as_the_floats_of_their_halves` and `f16_params_reach_a_console_ps_however_it_reads_them`. Good. - Mutation: `ps_f16_slot` ignoring the element's mask (the top commit undone) fails `f16_packed_attributes`. Good. - Changes that also reach programs without float16, worth knowing: - Mesh `exp param N` now follows the FSSM output table (`MsInterface::params` from `vs_output_table`) where it used the N-th distinct register (`param_registers`). This applies to every mesh program with a table, float16 or not. It matches what the VS already did; the description's 442 MS are its evidence. No title was run here. - `ps_input_table` accepts a record whose byte 6 is below its register (`r[6] > r[1]` rejects, was `r[6] != r[1]`), also in tables with no float16 pair. Before, such a table was refused and the attributes fell back to distinct-register order. - The HLSL VS export now writes `asfloat` for every element type other than 1 / 2 (uint / sint), not only type 3. - `src/gpu/recomp/{emit,mod}.rs` and `src/gpu/dxil` are in the translator identity, so cached translations rebuild once after the update. - Provenance: the fork commit is credited in `27332a4e` (`Co-authored-by: Jockerino`, GPL-3.0-or-later, the author's agreement), and #2513's commits keep MacieGx as author. - No retail title on this machine: the title's float16 shaders were not translated or drawn here. performance: not measured. Float16 halves cost a shift and an `f16tof32` per component at export; programs without float16 records take the old paths (apart from the mesh table above). 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) ``` </details>
Foniass commented 2026-12-01 20:33:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:33:29Z.


Review (head 44b3dcd0, diff read, not a merge-check):

  • The PS and the VS can disagree on a non-pair float16 attribute's layout. The VS picks Halves or Packed for a flag-1 param from the export's en (out_param_layout, gpu/recomp/mod.rs ~769-778), but the PS picks it from the instruction alone: v_interp_p2_f16 always takes the packed reading (ps_f16_slot, ~817; emit.rs ~2515, lower_gfx.rs ~418) and v_interp_mov_f32 always the one-half reading (emit.rs ~2535, lower_gfx.rs ~430). So v_interp_p2_f16 reading channel 1 of a flag-1 .xyzw param 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_f32 on 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::disagrees is 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 the Halves guess 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.

<!-- greyfinch-sync:ivall/xcl:comment:7324890829 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7324890829). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T20:33:29Z. --- Review (head 44b3dcd0, diff read, not a merge-check): - **The PS and the VS can disagree on a non-pair float16 attribute's layout.** The VS picks `Halves` or `Packed` for a flag-1 param from the export's `en` (`out_param_layout`, `gpu/recomp/mod.rs` ~769-778), but the PS picks it from the instruction alone: `v_interp_p2_f16` always takes the packed reading (`ps_f16_slot`, ~817; `emit.rs` ~2515, `lower_gfx.rs` ~418) and `v_interp_mov_f32` always the one-half reading (`emit.rs` ~2535, `lower_gfx.rs` ~430). So `v_interp_p2_f16` reading channel 1 of a flag-1 `.xyzw` param 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_f32` on 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::disagrees` is 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 the `Halves` guess 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.
CharlyRien commented 2026-12-01 23:15:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-01T23:15:35Z.


Thanks, both points are right (checked on 44b3dcd0).

  • The PS and the VS pick a flag-1 param's layout independently (export en vs 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, no v_interp_p2_f16 read 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::disagrees was indeed test-only.

New commit 7de960d3 makes 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:

  • VS / MS export: a record and its export that disagree (disagrees, now called in out_param_layout), and a flag-1 param exported packed (a PS reading it with v_interp_mov_f32 would get only the low half);
  • PS: 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).

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 and a_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 main b2b1f109 (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.

<!-- greyfinch-sync:ivall/xcl:comment:7329114021 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7329114021). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-01T23:15:35Z. --- Thanks, both points are right (checked on 44b3dcd0). - The PS and the VS pick a flag-1 param's layout independently (export `en` vs 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, no `v_interp_p2_f16` read 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::disagrees` was indeed test-only. New commit `7de960d3` makes 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: - VS / MS export: a record and its export that disagree (`disagrees`, now called in `out_param_layout`), and a flag-1 param exported packed (a PS reading it with `v_interp_mov_f32` would get only the low half); - PS: 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). 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 and `a_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 main `b2b1f109` (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.
Foniass commented 2026-12-01 23:17:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T23:17:54Z.


Follow-up review (head 7de960d3, since 44b3dcd0, diff read, not a merge-check):

  • The PS and the VS can disagree on a non-pair float16 attribute's layout: partly fixed. Each stage now logs the shapes that are right only if the other stage chose the same layout: the VS a flag-1 param exported packed (flag1_packed, gpu/recomp/mod.rs ~812), the PS a v_interp_p2_f16 read of a flag-1 attribute past the low half of dword 0 (note_ps_f16_read, ~784, from emit.rs ~2516 and lower_gfx.rs ~420). The translation still picks each stage's layout on its own, so a v_interp_p2_f16 read at channel 1 of a flag-1 .xyzw param exported over four dwords still gets component 2, and a v_interp_mov_f32 of 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::disagrees is 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. 7de960d3 changes only logging, both PS translators make the same check, and the new unit tests cover ps_f16_read_assumes_packed and flag1_packed.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7329172227 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7329172227). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T23:17:54Z. --- Follow-up review (head 7de960d3, since 44b3dcd0, diff read, not a merge-check): - **The PS and the VS can disagree on a non-pair float16 attribute's layout:** partly fixed. Each stage now logs the shapes that are right only if the other stage chose the same layout: the VS a flag-1 param exported packed (`flag1_packed`, `gpu/recomp/mod.rs` ~812), the PS a `v_interp_p2_f16` read of a flag-1 attribute past the low half of dword 0 (`note_ps_f16_read`, ~784, from `emit.rs` ~2516 and `lower_gfx.rs` ~420). The translation still picks each stage's layout on its own, so a `v_interp_p2_f16` read at channel 1 of a flag-1 `.xyzw` param exported over four dwords still gets component 2, and a `v_interp_mov_f32` of 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::disagrees` is 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. `7de960d3` changes only logging, both PS translators make the same check, and the new unit tests cover `ps_f16_read_assumes_packed` and `flag1_packed`. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
claudetools-gh commented 2026-12-02 13:37:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by claudetools-gh on 2026-12-02T13:37:52Z.


Tested head 7de960d3 on another card, cherry-picked onto an older tree. Our lab line is main from late November plus local commits. Main's 36e1c899 went in first, since this PR builds on it. The only conflict was a test in dxil/robustness_tests.rs: our older version of the test needed the new params: None field on MsInterface.

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:

  • Night police stop (Lucia and Jason with their hands up): Lucia's white top was black in both runs without the PR. With it, it is white, as in the footage. Jason's face and black tank top also look right.
  • Living room on the sofa: without the PR, Jason's face was a flat black mask. With it, the face is shaded normally.

Still off with the PR, in case it helps narrow the remaining cases:

  • Jason's white tank top in the living-room scene renders dark grey.
  • Lucia's dark brown hair renders pale grey or near white. A XCL_DUMP_TARGETS frame 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.
  • Lucia's eyes render black.
  • One straight hair strand crosses Jason's face.

AI-assisted.

<!-- greyfinch-sync:ivall/xcl:comment:7347186109 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7347186109). Originally posted by [claudetools-gh](https://github.com/claudetools-gh) on 2026-12-02T13:37:52Z. --- Tested head `7de960d3` on another card, cherry-picked onto an older tree. Our lab line is main from late November plus local commits. Main's `36e1c899` went in first, since this PR builds on it. The only conflict was a test in `dxil/robustness_tests.rs`: our older version of the test needed the new `params: None` field on `MsInterface`. 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: - **Night police stop** (Lucia and Jason with their hands up): Lucia's white top was black in both runs without the PR. With it, it is white, as in the footage. Jason's face and black tank top also look right. - **Living room on the sofa:** without the PR, Jason's face was a flat black mask. With it, the face is shaded normally. Still off with the PR, in case it helps narrow the remaining cases: - Jason's white tank top in the living-room scene renders dark grey. - Lucia's dark brown hair renders pale grey or near white. A `XCL_DUMP_TARGETS` frame 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. - Lucia's eyes render black. - One straight hair strand crosses Jason's face. AI-assisted.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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 2395

@@ -2380,18 +2382,26 @@ impl Em {
                 // param N is a register: channel c goes to component c of every element there
                 let k = (tgt - 32) as usize;
                 let params = ranked(&vs.outputs, true);
-                let at = vs_param_register(vs, k).map(|r| elements_at(&vs.outputs, true, r)).unwrap_or_default();
+                let (at, layout) = out_param_layout(&vs.outputs, vs.params.as_deref(), k, dwords);
                 if at.is_empty() {
                     self.line("/* param without an OSG1 element (dummy) */");
                     return Ok(());
                 }
-                for j in at {
+                for (j, first) in at {
                     let e = params[j];
                     let n = out_comps(e);
                     for c in 0..n {
-                        if enabled(c) {
-                            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);

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597580 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597580). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Code review location:** `crates/xcl/src/gpu/recomp/emit.rs`; line 2395 ~~~~diff @@ -2380,18 +2382,26 @@ impl Em { // param N is a register: channel c goes to component c of every element there let k = (tgt - 32) as usize; let params = ranked(&vs.outputs, true); - let at = vs_param_register(vs, k).map(|r| elements_at(&vs.outputs, true, r)).unwrap_or_default(); + let (at, layout) = out_param_layout(&vs.outputs, vs.params.as_deref(), k, dwords); if at.is_empty() { self.line("/* param without an OSG1 element (dummy) */"); return Ok(()); } - for j in at { + for (j, first) in at { let e = params[j]; let n = out_comps(e); for c in 0..n { - if enabled(c) { - 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); ~~~~ --- **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.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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 678

@@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> {
     let mut out = Vec::with_capacity(n);
     for k in 0..n {
         let r = fssm.get(base + 6 * k..base + 6 * k + 6)?;
-        if r[2] as usize != k || r[3..6] != [0, 0, 0] {
+        let f16 = r[5] & 1 == 1;
+        if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) {
             return None;
         }
-        out.push(r[1] as u32);
+        out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 });
     }
     Some(out)
 }
 
+/// Where a float16-packed param / attribute keeps its registers: (register, first dword).
+/// The console's compiler puts two float16 components in a dword – component c of a register
+/// in dword c / 2, the even one in the low half – and up to two registers in one param: the
+/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy).
+/// The registers pair up in order, so where a table does not name the second one it is the
+/// next float16 register that starts no param of its own (`claimed`). Checked against the
+/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes
+/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable
+/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords.
+pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> {
+    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(),

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597597 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597597). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Code review location:** `crates/xcl/src/gpu/recomp/mod.rs`; line 678 ~~~~diff @@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> { let mut out = Vec::with_capacity(n); for k in 0..n { let r = fssm.get(base + 6 * k..base + 6 * k + 6)?; - if r[2] as usize != k || r[3..6] != [0, 0, 0] { + let f16 = r[5] & 1 == 1; + if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) { return None; } - out.push(r[1] as u32); + out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 }); } Some(out) } +/// Where a float16-packed param / attribute keeps its registers: (register, first dword). +/// The console's compiler puts two float16 components in a dword – component c of a register +/// in dword c / 2, the even one in the low half – and up to two registers in one param: the +/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy). +/// The registers pair up in order, so where a table does not name the second one it is the +/// next float16 register that starts no param of its own (`claimed`). Checked against the +/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes +/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable +/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords. +pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> { + 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(), ~~~~ --- **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.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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 950

@@ -713,6 +947,7 @@ pub fn interface(blob: &[u8], sh: &super::xbox::XboxShader, f: &super::xbox::Fss
                 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),

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597615 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597615). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Code review location:** `crates/xcl/src/gpu/recomp/mod.rs`; line 950 ~~~~diff @@ -713,6 +947,7 @@ pub fn interface(blob: &[u8], sh: &super::xbox::XboxShader, f: &super::xbox::Fss 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), ~~~~ --- **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.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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 858

@@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> {
     let mut out = Vec::with_capacity(n);
     for k in 0..n {
         let r = fssm.get(base + 6 * k..base + 6 * k + 6)?;
-        if r[2] as usize != k || r[3..6] != [0, 0, 0] {
+        let f16 = r[5] & 1 == 1;
+        if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) {
             return None;
         }
-        out.push(r[1] as u32);
+        out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 });
     }
     Some(out)
 }
 
+/// Where a float16-packed param / attribute keeps its registers: (register, first dword).
+/// The console's compiler puts two float16 components in a dword – component c of a register
+/// in dword c / 2, the even one in the low half – and up to two registers in one param: the
+/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy).
+/// The registers pair up in order, so where a table does not name the second one it is the
+/// next float16 register that starts no param of its own (`claimed`). Checked against the
+/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes
+/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable
+/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords.
+pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> {
+    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(),
+    };
+    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);
+    std::iter::once((first, 0)).chain(second.map(|r| (r, width.div_ceil(2)))).collect()
+}
+
+/// The registers of `exp param N` with the first dword of each (`f16_registers`), and whether
+/// they hold packed float16: the console's table, else the N-th distinct register.
+pub fn out_param_registers(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize) -> Option<(Vec<(u32, usize)>, bool)> {
+    match params {
+        Some(t) => {
+            let p = t.get(n)?;
+            if !p.f16 {
+                return Some((vec![(p.register, 0)], false));
+            }
+            Some((f16_registers(outputs, p.register, None, p.pair, &|r| t.iter().any(|q| q.register == r)), true))
+        }
+        None => param_registers(outputs, true).get(n).map(|&r| (vec![(r, 0)], false)),
+    }
+}
+
+/// How `exp param N` holds the components of its elements in its dwords (`out_param_layout`).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ParamLayout {
+    /// component c is dword c as it is (a float element takes its bits)
+    Dwords,
+    /// float16, two halves a dword: component c is half c & 1 of dword first + c / 2
+    Packed,
+    /// float16, one half a dword: component c is the low half of dword c
+    Halves,
+}
+
+impl ParamLayout {
+    /// The dword component `c` of an element whose register starts at dword `first` comes from,
+    /// and its half (None: the whole dword). A half reaches the element as its float value.
+    pub fn place(self, first: usize, c: usize) -> (usize, Option<u32>) {
+        match self {
+            ParamLayout::Dwords => (c, None),
+            ParamLayout::Packed => (first + c / 2, Some(c as u32 & 1)),
+            ParamLayout::Halves => (c, Some(0)),
+        }
+    }
+}
+
+/// What decides a float16 param's layout (`f16_param_shape`): its record and its export.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct F16Param {
+    /// a flag-3 record (more than one dword); else flag 1
+    pub flag3: bool,
+    /// the dwords its first register's components take one a dword (bit c: dword c)
+    pub plain: u32,
+    /// the dwords it takes packed, two halves a dword
+    pub packed: u32,
+    /// the dwords the export writes
+    pub en: u32,
+}
+
+impl F16Param {
+    /// A flag-3 record is packed; a flag-1 one only where the export writes exactly its packed
+    /// dwords and not also one dword per component, else one half a dword (on a `.x` register,
+    /// where both are dword 0, the two are the same).
+    pub fn layout(self) -> ParamLayout {
+        if self.flag3 || (self.en == self.packed && self.en != self.plain) {
+            ParamLayout::Packed
+        } else {
+            ParamLayout::Halves
+        }
+    }
+
+    /// The record and the export disagree: a flag-3 record whose packed dwords the export does
+    /// not all write, or a flag-1 one whose export writes neither its packed dwords nor one
+    /// dword per component.
+    pub fn disagrees(self) -> bool {
+        if self.flag3 {
+            self.en & self.packed != self.packed
+        } else {
+            self.en != self.packed && self.en != self.plain
+        }
+    }
+
+    /// A flag-1 record whose export takes it packed (`layout`): right only for a PS that reads it
+    /// with `v_interp_p2_f16`; one that takes it flat (`v_interp_mov_f32`) gets the low half.
+    pub fn flag1_packed(self) -> bool {
+        !self.flag3 && self.layout() == ParamLayout::Packed
+    }
+}
+
+/// Logs once per kind and shape what the float16 layouts cannot settle alone (PR 3584 review):
+/// a record and its export that disagree, a flag-1 param exported packed, and a PS that reads a
+/// flag-1 attribute packed (`ps_f16_read_assumes_packed`). Each is right only if the other stage
+/// made the same choice; the translation goes on with the layout it picked.
+fn note_f16_shape(kind: &'static str, key: (usize, u32, u32, u32), what: impl FnOnce() -> String) {
+    static SEEN: std::sync::Mutex<Option<BTreeSet<(&'static str, (usize, u32, u32, u32))>>> = std::sync::Mutex::new(None);
+    if SEEN.lock().unwrap_or_else(|e| e.into_inner()).get_or_insert_with(BTreeSet::new).insert((kind, key)) {
+        crate::xlog_warn!("Recompiler: float16 {kind}: {}", what());
+    }
+}
+
+/// A PS read of float16 attribute `attr` by `v_interp_p2_f16` at channel `chan` / half `high`
+/// that assumes the VS packed a flag-1 record (two halves a dword: `ps_f16_slot`) - beyond the
+/// low half of dword 0, where packed and one-half-a-dword part.
+pub fn ps_f16_read_assumes_packed(ps: &PsInterface, attr: usize, chan: usize, high: bool) -> bool {
+    ps.attrs.as_ref().and_then(|t| t.get(attr)).is_some_and(|a| a.f16 && a.pair.is_none()) && (chan > 0 || high)
+}
+
+/// `ps_f16_read_assumes_packed`, logged once per attribute, channel and half.
+pub fn note_ps_f16_read(ps: &PsInterface, attr: usize, chan: usize, high: bool) {
+    if ps_f16_read_assumes_packed(ps, attr, chan, high) {
+        note_f16_shape("PS read", (attr, chan as u32, high as u32, 0), || {
+            format!("v_interp_p2_f16 reads flag-1 attribute {attr} at channel {chan}{} as packed halves: right only if its VS exports it packed", if high { " (high half)" } else { "" })
+        });
+    }
+}
+
+/// The elements `exp param N` writes (places in `ranked(outputs, true)`, each with the first
+/// dword of its register) and how its dwords hold them, for an export whose enabled dwords are
+/// `en` (bit c: dword c). A float16 param of the table reaches its elements as float values,
+/// laid out as its record and its export say (`F16Param::layout`). PR 2513's thread
+/// (CharlyRien, 2026-11-29) and the title's own listings: flag-1 records on `.xyzw` registers
+/// exported over four dwords, a half in the low bits of each (`en 0xF`); flag-3 ones packed in
+/// dwords 0-1 with filler in dwords 2-3 (`en 0xF`). As values, a half reaches a PS that
+/// interpolates it (`v_interp_p2_f16`) and one that takes it flat (`v_interp_mov_f32`, whose
+/// read gives its half back: `emit::interp`) alike.
+pub fn out_param_layout(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize, en: u32) -> (Vec<(usize, usize)>, ParamLayout) {
+    let Some((regs, f16)) = out_param_registers(outputs, params, n) else { return (Vec::new(), ParamLayout::Dwords) };
+    let at = |regs: &[(u32, usize)]| -> Vec<(usize, usize)> { regs.iter().flat_map(|&(r, first)| elements_at(outputs, true, r).into_iter().map(move |j| (j, first))).collect() };
+    if !f16 {
+        return (at(&regs), ParamLayout::Dwords);
+    }
+    let shape = f16_param_shape(outputs, params, n, &regs, en);
+    if shape.disagrees() {
+        note_f16_shape("export", (n, shape.en, shape.packed, shape.plain | (shape.flag3 as u32) << 8), || {
+            format!("param {n} ({} record) exported over dwords {:#x}, neither its packed dwords {:#x} nor one a component {:#x}: laid out {:?}", if shape.flag3 { "flag-3" } else { "flag-1" }, shape.en, shape.packed, shape.plain, shape.layout())
+        });
+    } else if shape.flag1_packed() {
+        note_f16_shape("export", (n, shape.en, shape.packed, shape.plain | 1 << 9), || {
+            format!("flag-1 param {n} exported packed (dwords {:#x}): a PS that reads it with v_interp_mov_f32 gets only the low half", shape.en)
+        });
+    }
+    match shape.layout() {
+        ParamLayout::Packed => (at(&regs), ParamLayout::Packed),
+        // (one half a dword: the first register's components; a flag-1 record names no second)
+        l => (at(&regs[..1]).into_iter().map(|(j, _)| (j, 0)).collect(), l),
+    }
+}
+
+/// `F16Param` of float16 param `n` over `regs` (`out_param_registers`) at an export writing
+/// dwords `en`.
+pub fn f16_param_shape(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize, regs: &[(u32, usize)], en: u32) -> F16Param {
+    let (packed, plain) = f16_param_dwords(outputs, regs);
+    F16Param { flag3: params.and_then(|t| t.get(n)).is_some_and(|p| p.pair), plain, packed, en: en & 0xF }
+}
+
+/// The dwords (bit c: dword c) a float16 param over `regs` (`out_param_registers`) takes packed,
+/// two halves a dword, and one component a dword (its first register's components).
+pub fn f16_param_dwords(outputs: &[SigElement], regs: &[(u32, usize)]) -> (u32, u32) {
+    let width = |r: u32| outputs.iter().filter(|e| e.system_value == 0 && e.register == r).map(|e| 8 - e.mask.leading_zeros() as usize).max().unwrap_or(4).clamp(1, 4);
+    let packed = regs.iter().fold(0u32, |m, &(r, first)| m | ((1u32 << width(r).div_ceil(2)) - 1) << first) & 0xF;
+    let plain = regs.first().map_or(0, |&(r, _)| (1u32 << width(r)) - 1);
+    (packed, plain)
+}
+
+/// The elements `exp param N` writes (places in `ranked(outputs, true)`), each with the first
+/// dword of its register, and whether the param holds packed float16 (`out_param_registers`).
+pub fn out_param_elements(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize) -> (Vec<(usize, usize)>, bool) {
+    let (regs, f16) = out_param_registers(outputs, params, n).unwrap_or_default();
+    (regs.iter().flat_map(|&(r, first)| elements_at(outputs, true, r).into_iter().map(move |j| (j, first))).collect(), f16)
+}
+
+/// The registers of a float16-packed PS attribute with the first dword of each (None: the
+/// attribute is not packed).
+pub fn ps_attribute_f16(ps: &PsInterface, attr: usize) -> Option<Vec<(u32, usize)>> {
+    let t = ps.attrs.as_ref()?;
+    let a = t.get(attr).filter(|a| a.f16)?;
+    let claimed = |r: u32| t.iter().any(|b| b.register as u32 == r || b.pair.is_some_and(|p| p as u32 == r));
+    Some(f16_registers(&ps.inputs, a.register as u32, a.pair.map(|p| p as u32), a.pair.is_some(), &claimed))
+}
+
+/// 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)> {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597637 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597637). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Code review location:** `crates/xcl/src/gpu/recomp/mod.rs`; line 858 ~~~~diff @@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> { let mut out = Vec::with_capacity(n); for k in 0..n { let r = fssm.get(base + 6 * k..base + 6 * k + 6)?; - if r[2] as usize != k || r[3..6] != [0, 0, 0] { + let f16 = r[5] & 1 == 1; + if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) { return None; } - out.push(r[1] as u32); + out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 }); } Some(out) } +/// Where a float16-packed param / attribute keeps its registers: (register, first dword). +/// The console's compiler puts two float16 components in a dword – component c of a register +/// in dword c / 2, the even one in the low half – and up to two registers in one param: the +/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy). +/// The registers pair up in order, so where a table does not name the second one it is the +/// next float16 register that starts no param of its own (`claimed`). Checked against the +/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes +/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable +/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords. +pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> { + 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(), + }; + 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); + std::iter::once((first, 0)).chain(second.map(|r| (r, width.div_ceil(2)))).collect() +} + +/// The registers of `exp param N` with the first dword of each (`f16_registers`), and whether +/// they hold packed float16: the console's table, else the N-th distinct register. +pub fn out_param_registers(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize) -> Option<(Vec<(u32, usize)>, bool)> { + match params { + Some(t) => { + let p = t.get(n)?; + if !p.f16 { + return Some((vec![(p.register, 0)], false)); + } + Some((f16_registers(outputs, p.register, None, p.pair, &|r| t.iter().any(|q| q.register == r)), true)) + } + None => param_registers(outputs, true).get(n).map(|&r| (vec![(r, 0)], false)), + } +} + +/// How `exp param N` holds the components of its elements in its dwords (`out_param_layout`). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ParamLayout { + /// component c is dword c as it is (a float element takes its bits) + Dwords, + /// float16, two halves a dword: component c is half c & 1 of dword first + c / 2 + Packed, + /// float16, one half a dword: component c is the low half of dword c + Halves, +} + +impl ParamLayout { + /// The dword component `c` of an element whose register starts at dword `first` comes from, + /// and its half (None: the whole dword). A half reaches the element as its float value. + pub fn place(self, first: usize, c: usize) -> (usize, Option<u32>) { + match self { + ParamLayout::Dwords => (c, None), + ParamLayout::Packed => (first + c / 2, Some(c as u32 & 1)), + ParamLayout::Halves => (c, Some(0)), + } + } +} + +/// What decides a float16 param's layout (`f16_param_shape`): its record and its export. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct F16Param { + /// a flag-3 record (more than one dword); else flag 1 + pub flag3: bool, + /// the dwords its first register's components take one a dword (bit c: dword c) + pub plain: u32, + /// the dwords it takes packed, two halves a dword + pub packed: u32, + /// the dwords the export writes + pub en: u32, +} + +impl F16Param { + /// A flag-3 record is packed; a flag-1 one only where the export writes exactly its packed + /// dwords and not also one dword per component, else one half a dword (on a `.x` register, + /// where both are dword 0, the two are the same). + pub fn layout(self) -> ParamLayout { + if self.flag3 || (self.en == self.packed && self.en != self.plain) { + ParamLayout::Packed + } else { + ParamLayout::Halves + } + } + + /// The record and the export disagree: a flag-3 record whose packed dwords the export does + /// not all write, or a flag-1 one whose export writes neither its packed dwords nor one + /// dword per component. + pub fn disagrees(self) -> bool { + if self.flag3 { + self.en & self.packed != self.packed + } else { + self.en != self.packed && self.en != self.plain + } + } + + /// A flag-1 record whose export takes it packed (`layout`): right only for a PS that reads it + /// with `v_interp_p2_f16`; one that takes it flat (`v_interp_mov_f32`) gets the low half. + pub fn flag1_packed(self) -> bool { + !self.flag3 && self.layout() == ParamLayout::Packed + } +} + +/// Logs once per kind and shape what the float16 layouts cannot settle alone (PR 3584 review): +/// a record and its export that disagree, a flag-1 param exported packed, and a PS that reads a +/// flag-1 attribute packed (`ps_f16_read_assumes_packed`). Each is right only if the other stage +/// made the same choice; the translation goes on with the layout it picked. +fn note_f16_shape(kind: &'static str, key: (usize, u32, u32, u32), what: impl FnOnce() -> String) { + static SEEN: std::sync::Mutex<Option<BTreeSet<(&'static str, (usize, u32, u32, u32))>>> = std::sync::Mutex::new(None); + if SEEN.lock().unwrap_or_else(|e| e.into_inner()).get_or_insert_with(BTreeSet::new).insert((kind, key)) { + crate::xlog_warn!("Recompiler: float16 {kind}: {}", what()); + } +} + +/// A PS read of float16 attribute `attr` by `v_interp_p2_f16` at channel `chan` / half `high` +/// that assumes the VS packed a flag-1 record (two halves a dword: `ps_f16_slot`) - beyond the +/// low half of dword 0, where packed and one-half-a-dword part. +pub fn ps_f16_read_assumes_packed(ps: &PsInterface, attr: usize, chan: usize, high: bool) -> bool { + ps.attrs.as_ref().and_then(|t| t.get(attr)).is_some_and(|a| a.f16 && a.pair.is_none()) && (chan > 0 || high) +} + +/// `ps_f16_read_assumes_packed`, logged once per attribute, channel and half. +pub fn note_ps_f16_read(ps: &PsInterface, attr: usize, chan: usize, high: bool) { + if ps_f16_read_assumes_packed(ps, attr, chan, high) { + note_f16_shape("PS read", (attr, chan as u32, high as u32, 0), || { + format!("v_interp_p2_f16 reads flag-1 attribute {attr} at channel {chan}{} as packed halves: right only if its VS exports it packed", if high { " (high half)" } else { "" }) + }); + } +} + +/// The elements `exp param N` writes (places in `ranked(outputs, true)`, each with the first +/// dword of its register) and how its dwords hold them, for an export whose enabled dwords are +/// `en` (bit c: dword c). A float16 param of the table reaches its elements as float values, +/// laid out as its record and its export say (`F16Param::layout`). PR 2513's thread +/// (CharlyRien, 2026-11-29) and the title's own listings: flag-1 records on `.xyzw` registers +/// exported over four dwords, a half in the low bits of each (`en 0xF`); flag-3 ones packed in +/// dwords 0-1 with filler in dwords 2-3 (`en 0xF`). As values, a half reaches a PS that +/// interpolates it (`v_interp_p2_f16`) and one that takes it flat (`v_interp_mov_f32`, whose +/// read gives its half back: `emit::interp`) alike. +pub fn out_param_layout(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize, en: u32) -> (Vec<(usize, usize)>, ParamLayout) { + let Some((regs, f16)) = out_param_registers(outputs, params, n) else { return (Vec::new(), ParamLayout::Dwords) }; + let at = |regs: &[(u32, usize)]| -> Vec<(usize, usize)> { regs.iter().flat_map(|&(r, first)| elements_at(outputs, true, r).into_iter().map(move |j| (j, first))).collect() }; + if !f16 { + return (at(&regs), ParamLayout::Dwords); + } + let shape = f16_param_shape(outputs, params, n, &regs, en); + if shape.disagrees() { + note_f16_shape("export", (n, shape.en, shape.packed, shape.plain | (shape.flag3 as u32) << 8), || { + format!("param {n} ({} record) exported over dwords {:#x}, neither its packed dwords {:#x} nor one a component {:#x}: laid out {:?}", if shape.flag3 { "flag-3" } else { "flag-1" }, shape.en, shape.packed, shape.plain, shape.layout()) + }); + } else if shape.flag1_packed() { + note_f16_shape("export", (n, shape.en, shape.packed, shape.plain | 1 << 9), || { + format!("flag-1 param {n} exported packed (dwords {:#x}): a PS that reads it with v_interp_mov_f32 gets only the low half", shape.en) + }); + } + match shape.layout() { + ParamLayout::Packed => (at(&regs), ParamLayout::Packed), + // (one half a dword: the first register's components; a flag-1 record names no second) + l => (at(&regs[..1]).into_iter().map(|(j, _)| (j, 0)).collect(), l), + } +} + +/// `F16Param` of float16 param `n` over `regs` (`out_param_registers`) at an export writing +/// dwords `en`. +pub fn f16_param_shape(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize, regs: &[(u32, usize)], en: u32) -> F16Param { + let (packed, plain) = f16_param_dwords(outputs, regs); + F16Param { flag3: params.and_then(|t| t.get(n)).is_some_and(|p| p.pair), plain, packed, en: en & 0xF } +} + +/// The dwords (bit c: dword c) a float16 param over `regs` (`out_param_registers`) takes packed, +/// two halves a dword, and one component a dword (its first register's components). +pub fn f16_param_dwords(outputs: &[SigElement], regs: &[(u32, usize)]) -> (u32, u32) { + let width = |r: u32| outputs.iter().filter(|e| e.system_value == 0 && e.register == r).map(|e| 8 - e.mask.leading_zeros() as usize).max().unwrap_or(4).clamp(1, 4); + let packed = regs.iter().fold(0u32, |m, &(r, first)| m | ((1u32 << width(r).div_ceil(2)) - 1) << first) & 0xF; + let plain = regs.first().map_or(0, |&(r, _)| (1u32 << width(r)) - 1); + (packed, plain) +} + +/// The elements `exp param N` writes (places in `ranked(outputs, true)`), each with the first +/// dword of its register, and whether the param holds packed float16 (`out_param_registers`). +pub fn out_param_elements(outputs: &[SigElement], params: Option<&[OutParam]>, n: usize) -> (Vec<(usize, usize)>, bool) { + let (regs, f16) = out_param_registers(outputs, params, n).unwrap_or_default(); + (regs.iter().flat_map(|&(r, first)| elements_at(outputs, true, r).into_iter().map(move |j| (j, first))).collect(), f16) +} + +/// The registers of a float16-packed PS attribute with the first dword of each (None: the +/// attribute is not packed). +pub fn ps_attribute_f16(ps: &PsInterface, attr: usize) -> Option<Vec<(u32, usize)>> { + let t = ps.attrs.as_ref()?; + let a = t.get(attr).filter(|a| a.f16)?; + let claimed = |r: u32| t.iter().any(|b| b.register as u32 == r || b.pair.is_some_and(|p| p as u32 == r)); + Some(f16_registers(&ps.inputs, a.register as u32, a.pair.map(|p| p as u32), a.pair.is_some(), &claimed)) +} + +/// 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)> { ~~~~ --- **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.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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 680

@@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> {
     let mut out = Vec::with_capacity(n);
     for k in 0..n {
         let r = fssm.get(base + 6 * k..base + 6 * k + 6)?;
-        if r[2] as usize != k || r[3..6] != [0, 0, 0] {
+        let f16 = r[5] & 1 == 1;
+        if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) {
             return None;
         }
-        out.push(r[1] as u32);
+        out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 });
     }
     Some(out)
 }
 
+/// Where a float16-packed param / attribute keeps its registers: (register, first dword).
+/// The console's compiler puts two float16 components in a dword – component c of a register
+/// in dword c / 2, the even one in the low half – and up to two registers in one param: the
+/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy).
+/// The registers pair up in order, so where a table does not name the second one it is the
+/// next float16 register that starts no param of its own (`claimed`). Checked against the
+/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes
+/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable
+/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords.
+pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> {
+    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(),
+    };
+    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);

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597655 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597655). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Code review location:** `crates/xcl/src/gpu/recomp/mod.rs`; line 680 ~~~~diff @@ -628,14 +653,220 @@ pub fn vs_output_table(fssm: &[u8]) -> Option<Vec<u32>> { let mut out = Vec::with_capacity(n); for k in 0..n { let r = fssm.get(base + 6 * k..base + 6 * k + 6)?; - if r[2] as usize != k || r[3..6] != [0, 0, 0] { + let f16 = r[5] & 1 == 1; + if r[2] as usize != k || r[4] != 0 || !matches!(r[5], 0 | 1 | 3) || (r[3] != 0 && !(f16 && r[3] == r[1])) { return None; } - out.push(r[1] as u32); + out.push(OutParam { register: r[1] as u32, f16, pair: r[5] == 3 }); } Some(out) } +/// Where a float16-packed param / attribute keeps its registers: (register, first dword). +/// The console's compiler puts two float16 components in a dword – component c of a register +/// in dword c / 2, the even one in the low half – and up to two registers in one param: the +/// second follows the dwords the first one's components take (2 for .xyz / .xyzw, 1 for .xy). +/// The registers pair up in order, so where a table does not name the second one it is the +/// next float16 register that starts no param of its own (`claimed`). Checked against the +/// code of a retail title: every `v_interp_p2_f16` channel / half of 376 packed attributes +/// (362 PS) is a declared component (2 more read one past a .xy register), and the enable +/// mask of every `exp param` of 383 packed params (442 MS) is exactly these dwords. +pub fn f16_registers(sig: &[SigElement], first: u32, second: Option<u32>, pair: bool, claimed: &dyn Fn(u32) -> bool) -> Vec<(u32, usize)> { + 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(), + }; + 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); ~~~~ --- **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.
bmjask commented 2026-12-02 15:03:37 +00:00 (Migrated from github.com)

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.

  1. High crates/xcl/src/gpu/recomp/emit.rs:2395: The float16 param path calls exp_comp(srcs, compr, dw) and then shifts by 16*half. (inline)
  2. High crates/xcl/src/gpu/recomp/mod.rs:678: 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. (inline)
  3. High crates/xcl/src/gpu/recomp/mod.rs:950: 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. (inline)
  4. High crates/xcl/src/gpu/recomp/mod.rs:858: 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 t.... (inline)
  5. 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)
  6. Medium crates/xcl/src/gpu/dxil/lower_gfx.rs:436: 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. (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.

<!-- greyfinch-sync:ivall/xcl:review:6153412947 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#pullrequestreview-6153412947). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:37Z. **Review:** COMMENTED --- Review of `7de960d3`: 6 finding(s) (4 high, 2 medium), most severe first. 1. **High** `crates/xcl/src/gpu/recomp/emit.rs:2395`: The float16 param path calls `exp_comp(srcs, compr, dw)` and then shifts by 16*half. (inline) 2. **High** `crates/xcl/src/gpu/recomp/mod.rs:678`: 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. (inline) 3. **High** `crates/xcl/src/gpu/recomp/mod.rs:950`: 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. (inline) 4. **High** `crates/xcl/src/gpu/recomp/mod.rs:858`: 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 t.... (inline) 5. **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) 6. **Medium** `crates/xcl/src/gpu/dxil/lower_gfx.rs:436`: `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. (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._
bmjask commented 2026-12-02 15:03:38 +00:00 (Migrated from github.com)

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 436

@@ -401,11 +412,35 @@ impl Lw {
             let s1 = f("SRC1");
             (f("VDST"), if s1 >= 256 { s1 - 256 } else { s1 }, f("SRC0") & 0x3F, f("SRC0") >> 6 & 3)
         };
-        let Some(slot) = ps_attribute_slot(&ps, attr as usize, chan as usize) else { return err(d, "attribute outside ISG1") };
-        let load = |lw: &mut Lw| -> (Value, u32) {
+        // a float16-packed attribute: the PC input is the component itself (SRC0 bit 8: the
+        // high half of the dword); a half nothing declares reads 0
+        let place = match ps_attribute_f16(&ps, attr as usize).filter(|_| name.ends_with("_f16")) {
+            Some(regs) => {
+                let high = d.enc.name != "ENC_VINTRP" && f("SRC0") >> 8 & 1 == 1;
+                if name == "v_interp_p2_f16" {
+                    crate::gpu::recomp::note_ps_f16_read(&ps, attr as usize, chan as usize, high);
+                }
+                ps_f16_slot(&ps, &regs, chan as usize, high)
+            }
+            None => match ps_attribute_slot(&ps, attr as usize, chan as usize) {
+                Some(slot) => Some((slot, chan as usize)),
+                None => return err(d, "attribute outside ISG1"),
+            },
+        };
+        // `v_interp_mov_f32` of a float16 attribute, whose halves reach the PS as their floats
+        // (`recomp::out_param_layout`): the half of channel `chan`'s float in the low bits, as the
+        // title's `v_cvt_f32_f16` takes it - both halves of the dword where the record names a
+        // 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, &regs, chan as usize, false), ps_f16_slot(&ps, &regs, chan as usize, true)]),
+            Some(_) => Some([place, None]),

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 44b3dcd0 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 44b3dcd0 reported for 6 PS in the title's pack.

<!-- greyfinch-sync:ivall/xcl:review-comment:4771597673 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#discussion_r4771597673). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T15:03:38Z. **Code review location:** `crates/xcl/src/gpu/dxil/lower_gfx.rs`; line 436 ~~~~diff @@ -401,11 +412,35 @@ impl Lw { let s1 = f("SRC1"); (f("VDST"), if s1 >= 256 { s1 - 256 } else { s1 }, f("SRC0") & 0x3F, f("SRC0") >> 6 & 3) }; - let Some(slot) = ps_attribute_slot(&ps, attr as usize, chan as usize) else { return err(d, "attribute outside ISG1") }; - let load = |lw: &mut Lw| -> (Value, u32) { + // a float16-packed attribute: the PC input is the component itself (SRC0 bit 8: the + // high half of the dword); a half nothing declares reads 0 + let place = match ps_attribute_f16(&ps, attr as usize).filter(|_| name.ends_with("_f16")) { + Some(regs) => { + let high = d.enc.name != "ENC_VINTRP" && f("SRC0") >> 8 & 1 == 1; + if name == "v_interp_p2_f16" { + crate::gpu::recomp::note_ps_f16_read(&ps, attr as usize, chan as usize, high); + } + ps_f16_slot(&ps, &regs, chan as usize, high) + } + None => match ps_attribute_slot(&ps, attr as usize, chan as usize) { + Some(slot) => Some((slot, chan as usize)), + None => return err(d, "attribute outside ISG1"), + }, + }; + // `v_interp_mov_f32` of a float16 attribute, whose halves reach the PS as their floats + // (`recomp::out_param_layout`): the half of channel `chan`'s float in the low bits, as the + // title's `v_cvt_f32_f16` takes it - both halves of the dword where the record names a + // 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, &regs, chan as usize, false), ps_f16_slot(&ps, &regs, chan as usize, true)]), + Some(_) => Some([place, None]), ~~~~ --- **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 44b3dcd0 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 44b3dcd0 reported for 6 PS in the title's pack.
bmjask commented 2026-12-02 15:03:40 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7349641705 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3584#issuecomment-7349641705). Originally posted by [bmjask](https://github.com/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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3584:upstream-pr/3584'
git switch 'upstream-pr/3584'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3584'
git switch 'upstream-pr/3584'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3584'
git switch 'upstream-pr/3584'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3584'
git switch 'main'
git merge --squash 'upstream-pr/3584'
git switch 'main'
git merge --ff-only 'upstream-pr/3584'
git switch 'main'
git merge 'upstream-pr/3584'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3584
No description provided.