Recompiler: read VS / PS spill slots from their shadows in direct DXIL #3793

Open
raylitebull wants to merge 1 commit from upstream-pr/3793 into main
raylitebull commented 2026-12-03 15:07:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-12-03T15:07:14Z.


The direct DXIL translator refused any VS / PS in which a v_readlane reads a v_writelane spill slot from its scalar shadow (upper_lanes::Read::Shadow), with graphics v_writelane spill needs the HLSL path (dxil/kernel.rs). Those shaders took the HLSL + DXC path. This change gives direct DXIL the HLSL emitter's spill shadows (Em::upper: xcl_sh<v>_<l>, xcl_present). Wave32 VS / PS and the 64-lane form of wave64 VS / PS with spill slots now stay on direct DXIL. The 32-lane form of a wave64 VS / PS (pso::graphics_wave32, true on any adapter whose wave range starts at 32) still refuses reads of lanes 32–63; #3795, stacked on this one, handles them.

What is in it

  • dxil/kernel.rs: VS / PS keep the upper_lanes result instead of refusing Read::Shadow. Lw::setup_gfx_lanes runs after the entry setup, when there is a shadowed slot.
  • dxil/lower_gfx.rs: GfxLanes. Each shadowed slot (VGPR, lane) is an SSA temporary that starts at 0 (static uint xcl_sh = 0u). For a slot ≥ 32 it also keeps the lanes launched at entry: ballot(true), or in a PS ballot_px(true), which counts whole live quads (xcl_present).
  • dxil/lower_valu.rs: v_writelane also writes the slot's shadow. A v_readlane that upper_lanes resolves to Shadow reads the shadow. For a slot ≥ 32 it reads the lane itself where the present mask has that lane. Every other read is unchanged.
  • Tests:
    • New dxil::core_tests::graphics_spill_slots_read_their_shadows: wave32 and wave64 VS and PS, plus a slot written on both sides of a branch. Each one validates, and its disassembly is checked: a slot < 32 has no lane read; a slot ≥ 32 has one waveReadLaneAt of lane 36 selected by the present bit (in a PS, quad ops build the present mask); the branch case has a phi.
    • recomp::tests wave32_graphics_spill_shadows_and_direct_fallback and wave64_graphics_spill_shadows_cover_native_partial_waves asserted the refusal. They now expect the direct translation (the second one still expects the 32-lane form to refuse).
    • The GPU tests gpu_wave64_ps_spill_slots, gpu_wave64_vs_spill_slots_and_identity and gpu_wave32_ps_and_vs_spill_slots_in_partial_waves now also draw with the direct VS / PS and check the same values. They use draw_console_direct, and draw_passthrough_ps is split out of draw_console_views.

Tested

  • Linux x86_64 (Ubuntu 24.04), no GPU, rustc 1.99.0. cargo check --workspace --all-targets --target x86_64-pc-windows-gnu builds, with the same warnings as main a815de93 (39 lib, 20 lib test) and none in the changed files. git diff --check is clean.
  • Lib tests were cross-built (x86_64-pc-windows-gnu, debug) and run under Wine 9.0 with DXC 1.10.2611's dxcompiler.dll / dxil.dll (GitHub release, XCL_DXC_DIR). So IDxcValidator and the disassembler did run on the direct-DXIL tests. There is no GPU, so every GPU test printed SKIPPED (no GPU) and none counts as coverage. Each module ran in its own process with 2 threads; the uma_driver group was left out (address space under Wine).
    • this PR (02f9cbf1): 2547 passed, 75 failed, 35 ignored; hle::netoff::tests timed out (Wine sockets).
    • main a815de93, same setup: 2545 passed, 76 failed, 35 ignored; hle::netoff::tests timed out.
    • No test fails only with this PR. The +2 passed are the new test, and hle::d3d12x::frame::tests::origin_events_issue_tokens_and_flips_have_statistics, which failed on the main run (timing under Wine). The other failures are the same set (hle::d3d12x device / sparse / list tests and gpu::dxil::round_tests::directed_reference_basics under Wine).

Regression run
Pending: scripts/smoke.ps1 from main and from this head, on Windows with an RX 9070 XT, still to be run.

Not tested

  • Windows, any GPU: the GPU tests above (direct VS / PS draws) were skipped here, and IDxcValidator was not run on Windows.
  • scripts/smoke.ps1 and the whole suite on a GPU (pending, RX 9070 XT).
  • How many retail shaders now stay direct (xcl shaders --direct): no game data here.

AI use

  • Capy (Claude Opus 5.5) wrote the code, the tests and this description, and ran the builds and the Wine test runs above.
<!-- greyfinch-sync:ivall/xcl:issue:5629160730 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3793). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-12-03T15:07:14Z. --- The direct DXIL translator refused any VS / PS in which a `v_readlane` reads a `v_writelane` spill slot from its scalar shadow (`upper_lanes::Read::Shadow`), with `graphics v_writelane spill needs the HLSL path` (`dxil/kernel.rs`). Those shaders took the HLSL + DXC path. This change gives direct DXIL the HLSL emitter's spill shadows (`Em::upper`: `xcl_sh<v>_<l>`, `xcl_present`). Wave32 VS / PS and the 64-lane form of wave64 VS / PS with spill slots now stay on direct DXIL. The 32-lane form of a wave64 VS / PS (`pso::graphics_wave32`, true on any adapter whose wave range starts at 32) still refuses reads of lanes 32–63; #3795, stacked on this one, handles them. **What is in it** - `dxil/kernel.rs`: VS / PS keep the `upper_lanes` result instead of refusing `Read::Shadow`. `Lw::setup_gfx_lanes` runs after the entry setup, when there is a shadowed slot. - `dxil/lower_gfx.rs`: `GfxLanes`. Each shadowed slot (VGPR, lane) is an SSA temporary that starts at 0 (`static uint xcl_sh = 0u`). For a slot ≥ 32 it also keeps the lanes launched at entry: `ballot(true)`, or in a PS `ballot_px(true)`, which counts whole live quads (`xcl_present`). - `dxil/lower_valu.rs`: `v_writelane` also writes the slot's shadow. A `v_readlane` that `upper_lanes` resolves to `Shadow` reads the shadow. For a slot ≥ 32 it reads the lane itself where the present mask has that lane. Every other read is unchanged. - Tests: - New `dxil::core_tests::graphics_spill_slots_read_their_shadows`: wave32 and wave64 VS and PS, plus a slot written on both sides of a branch. Each one validates, and its disassembly is checked: a slot < 32 has no lane read; a slot ≥ 32 has one `waveReadLaneAt` of lane 36 selected by the present bit (in a PS, quad ops build the present mask); the branch case has a phi. - `recomp::tests` `wave32_graphics_spill_shadows_and_direct_fallback` and `wave64_graphics_spill_shadows_cover_native_partial_waves` asserted the refusal. They now expect the direct translation (the second one still expects the 32-lane form to refuse). - The GPU tests `gpu_wave64_ps_spill_slots`, `gpu_wave64_vs_spill_slots_and_identity` and `gpu_wave32_ps_and_vs_spill_slots_in_partial_waves` now also draw with the direct VS / PS and check the same values. They use `draw_console_direct`, and `draw_passthrough_ps` is split out of `draw_console_views`. **Tested** - Linux x86_64 (Ubuntu 24.04), no GPU, rustc 1.99.0. `cargo check --workspace --all-targets --target x86_64-pc-windows-gnu` builds, with the same warnings as `main` a815de93 (39 lib, 20 lib test) and none in the changed files. `git diff --check` is clean. - Lib tests were cross-built (`x86_64-pc-windows-gnu`, debug) and run under Wine 9.0 with DXC 1.10.2611's `dxcompiler.dll` / `dxil.dll` (GitHub release, `XCL_DXC_DIR`). So `IDxcValidator` and the disassembler did run on the direct-DXIL tests. There is no GPU, so every GPU test printed `SKIPPED` (no GPU) and none counts as coverage. Each module ran in its own process with 2 threads; the `uma_driver` group was left out (address space under Wine). - this PR (02f9cbf1): 2547 passed, 75 failed, 35 ignored; `hle::netoff::tests` timed out (Wine sockets). - `main` a815de93, same setup: 2545 passed, 76 failed, 35 ignored; `hle::netoff::tests` timed out. - No test fails only with this PR. The +2 passed are the new test, and `hle::d3d12x::frame::tests::origin_events_issue_tokens_and_flips_have_statistics`, which failed on the `main` run (timing under Wine). The other failures are the same set (`hle::d3d12x` device / sparse / list tests and `gpu::dxil::round_tests::directed_reference_basics` under Wine). **Regression run** Pending: `scripts/smoke.ps1` from `main` and from this head, on Windows with an RX 9070 XT, still to be run. **Not tested** - Windows, any GPU: the GPU tests above (direct VS / PS draws) were skipped here, and `IDxcValidator` was not run on Windows. - `scripts/smoke.ps1` and the whole suite on a GPU (pending, RX 9070 XT). - How many retail shaders now stay direct (`xcl shaders --direct`): no game data here. **AI use** - Capy (Claude Opus 5.5) wrote the code, the tests and this description, and ran the builds and the Wine test runs above.
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/3793:upstream-pr/3793'
git switch 'upstream-pr/3793'

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/3793'
git switch 'upstream-pr/3793'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3793'
git switch 'upstream-pr/3793'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3793'
git switch 'main'
git merge --squash 'upstream-pr/3793'
git switch 'main'
git merge --ff-only 'upstream-pr/3793'
git switch 'main'
git merge 'upstream-pr/3793'
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!3793
No description provided.