Shaders: forward SGPRs reloaded from VGPR lanes as the spilled value #309

Closed
github-bot wants to merge 1 commit from gh-pr/309/head into gh-pr/309/base
Owner

@⁠AntoninMichelq on GitHub · 2026-11-24 02:13 UTC · original
AntoninMichelq:up/sgpr-spill-lanes → main · +649 −15 · 6 files · 1 commits · closed without merging

Requested by 4nto · project thread

Summary

When it runs short of SGPRs, the console compiler spills a dword, often a lane mask, into one lane of a VGPR with v_writelane_b32. It reloads the dword later with v_readlane_b32 at the same lane. Reads of such a reload now read the spilled value directly, so a reloaded lane mask is again the same mask for the structurer and the lowering. This is a port of the spill resolution from #54 by alessiodeia, on its own and without #54's Wave64/host-wave changes.

What changed

  • New victory_shader::sgpr_spill module:
    • forward(&mut Program) replaces every read of a reload whose VGPR lane provably holds one scalar value with that value. "Provably" covers other lanes' writes, agreeing joins, lane bits masked to the wave size, and the value being available wherever the reload runs.
    • dead(&Program) names the spills and reloads that nothing reads any more.
  • forward runs right after ir::build, in emit::translate and in victory translate.
  • Lowering skips dead spills and reloads. They are also left out of the console-lane and whole-wave-section scans.
  • When a scalar mask operation's SCC is read as data (for example by s_cselect), it now lowers as "some lane is set", meaning the mask's ballot is not zero. This applies where masks may be read as data (compute). Before, it failed with "a lane mask read as data".
  • A whole-wave section now ends at the EXEC write that reads the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it.

No dependency on other open PRs.

How it was tested

  • cargo test -p victory-shader on Linux: all tests pass. New tests in sgpr_spill::tests:

    • a_reloaded_mask_is_the_spilled_mask
    • a_spilled_mask_holding_lanes_elsewhere_is_used_as_a_mask_again
    • only_the_same_lane_written_by_a_lane_write_is_forwarded
    • a_reload_needs_the_value_wherever_it_runs
    • the_scc_of_a_mask_operation_is_whether_a_lane_is_set

    Also emit::wave::tests::a_section_restores_exec_from_a_reload_of_the_saved_mask.

  • cargo check for Windows (x86_64-pc-windows-msvc) passes, for victory-shader and for victory with CARGO_FEATURE_PURE=1.

  • On the game's 26,148 programs, "a lane mask holding lanes elsewhere read as data" went from 276 to 42. This was measured with victory translate on the integration stack.

Where 3D rendering stands on an RX 7600 (Windows 11)

  • In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view).
  • Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black.
  • No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs.
  • About 10,000 draws per frame, at well under 1 fps.

These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66

**@⁠AntoninMichelq** on GitHub · 2026-11-24 02:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/309) `AntoninMichelq:up/sgpr-spill-lanes` → `main` · +649 −15 · 6 files · 1 commits · closed without merging <!-- claude-projects-attribution: {"github_login":"AntoninMichelq"} --> _Requested by **4nto** · [project thread](https://claude.ai/code/project/chan_01XYoPEzLL1bj63HP9pniGvs?thread=cmsg_01XYoPEzLL1bj63HP9pniGvsYRPS2v37oeDeGaCHT7dFsi)_ ## Summary When it runs short of SGPRs, the console compiler spills a dword, often a lane mask, into one lane of a VGPR with `v_writelane_b32`. It reloads the dword later with `v_readlane_b32` at the same lane. Reads of such a reload now read the spilled value directly, so a reloaded lane mask is again the same mask for the structurer and the lowering. This is a port of the spill resolution from #54 by alessiodeia, on its own and without #54's Wave64/host-wave changes. ## What changed - New `victory_shader::sgpr_spill` module: - `forward(&mut Program)` replaces every read of a reload whose VGPR lane provably holds one scalar value with that value. "Provably" covers other lanes' writes, agreeing joins, lane bits masked to the wave size, and the value being available wherever the reload runs. - `dead(&Program)` names the spills and reloads that nothing reads any more. - `forward` runs right after `ir::build`, in `emit::translate` and in `victory translate`. - Lowering skips dead spills and reloads. They are also left out of the console-lane and whole-wave-section scans. - When a scalar mask operation's SCC is read as data (for example by `s_cselect`), it now lowers as "some lane is set", meaning the mask's ballot is not zero. This applies where masks may be read as data (compute). Before, it failed with "a lane mask read as data". - A whole-wave section now ends at the EXEC write that reads the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it. No dependency on other open PRs. ## How it was tested - `cargo test -p victory-shader` on Linux: all tests pass. New tests in `sgpr_spill::tests`: - `a_reloaded_mask_is_the_spilled_mask` - `a_spilled_mask_holding_lanes_elsewhere_is_used_as_a_mask_again` - `only_the_same_lane_written_by_a_lane_write_is_forwarded` - `a_reload_needs_the_value_wherever_it_runs` - `the_scc_of_a_mask_operation_is_whether_a_lane_is_set` Also `emit::wave::tests::a_section_restores_exec_from_a_reload_of_the_saved_mask`. - `cargo check` for Windows (`x86_64-pc-windows-msvc`) passes, for `victory-shader` and for `victory` with `CARGO_FEATURE_PURE=1`. - On the game's 26,148 programs, "a lane mask holding lanes elsewhere read as data" went from 276 to 42. This was measured with `victory translate` on the integration stack. ## Where 3D rendering stands on an RX 7600 (Windows 11) - In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view). - Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black. - No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs. - About 10,000 draws per frame, at well under 1 fps. These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Short of SGPRs, the console compiler spills a dword into one lane of a
VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the
same constant lane. Lane masks are spilled like this too, and the reload
is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec;
EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill
read the mask as a number (failing with "a lane mask holding lanes
elsewhere read as data" for an else-mask), and the reload was an opaque
cross-lane read the lane-mask analysis no longer knew as that mask.

New pass sgpr_spill::forward, run right after the IR is built (in
translation and in `victory translate`): every read of a
reload whose VGPR lane provably holds one scalar value (through other
lanes' writes and agreeing joins, lane bits masked to the wave size, the
value available wherever the reload runs) reads that value directly, so
structure tracks the reloaded mask as the same mask. sgpr_spill::dead
names the reloads and spills nothing reads any more; lowering leaves
them out (and out of the console-lane and whole-wave-section scans).

Also:
- SCC of a scalar mask operation read as data (s_cselect on it) is
  "some lane is set": the mask's ballot is not zero, where masks may be
  read as data (compute). Was "a lane mask read as data".
- A whole-wave section ends at the EXEC write reading the saved mask
  from any register, so a forwarded reload of a spilled saved EXEC
  closes it.

Based on the spill resolution in #54 by alessiodeia.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:48 +00:00
github-bot closed this pull request 2026-11-26 03:58:48 +00:00
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 02:31 UTC · original

Tested the spill forwarding as a retry on Causeway's 32-lane translation path with the saved shaders from our RTX 3060 Ti story trace. The Windows SDK validator accepted 44 more compute shaders (53 → 97 successes out of 177 previously rejected shaders). All prior successful outputs stayed byte-identical across this set, 118 controls and a separate historical set of 50.

I sampled five of the 44 newly validated programs for compute pipeline creation on Microsoft WARP. Four created pipelines in 89–101 ms. The fifth reached our process memory guard during compilation. This measured pipeline creation only. The two mesh shaders responsible for most dropped draws in our trace still stop at sampler reconstruction.

**@⁠ifBars** on GitHub · 2026-11-24 02:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7120236228) Tested the spill forwarding as a retry on Causeway's 32-lane translation path with the saved shaders from our RTX 3060 Ti story trace. The Windows SDK validator accepted 44 more compute shaders (53 → 97 successes out of 177 previously rejected shaders). All prior successful outputs stayed byte-identical across this set, 118 controls and a separate historical set of 50. I sampled five of the 44 newly validated programs for compute pipeline creation on Microsoft WARP. Four created pipelines in 89–101 ms. The fifth reached our process memory guard during compilation. This measured pipeline creation only. The two mesh shaders responsible for most dropped draws in our trace still stop at sampler reconstruction.
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 02:58 UTC · original

Correction to our earlier 44-shader result. During review we found that a separate descriptor matcher on our branch equated first-lane offsets across different active masks. Once I restricted that matcher to provable identity, only two of the 177 previously rejected shaders still validated on the combined branch. The earlier 44 additional outputs passed the DXIL validator, but they depended on the unsafe matcher and should not be counted as recovered story programs. The forwarding fixtures still pass. This issue was in our descriptor matching, separate from this PR's spill forwarding.

**@⁠ifBars** on GitHub · 2026-11-24 02:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7120654830) Correction to our earlier 44-shader result. During review we found that a separate descriptor matcher on our branch equated first-lane offsets across different active masks. Once I restricted that matcher to provable identity, only two of the 177 previously rejected shaders still validated on the combined branch. The earlier 44 additional outputs passed the DXIL validator, but they depended on the unsafe matcher and should not be counted as recovered story programs. The forwarding fixtures still pass. This issue was in our descriptor matching, separate from this PR's spill forwarding.
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-24 03:48 UTC · original

Tested with the title at 64c7188.

  • NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build of the branch merged onto main d2a4bae (clean), its own empty VICTORY_CACHE_DIR, VICTORY_KEYS into story mode, until the host GPU failure (#71, unrelated); compared program by program with a main run made the same way (#400 has the setup).
  • 8 programs that stop on main translate and run. 0 programs that ran on main stop.
  • 7 more compute programs that stop in translation on main (a select on an untracked mask 3, a lane mask holding lanes elsewhere read as data 3, a lane-mask join of an untracked mask 1) translate with this PR, but the driver refuses their pipelines with E_INVALIDARG. That is the same refusal as the 119 wave64 compute programs main already has on this 32-lane card, the class #233 / #320 deal with. So on NVIDIA they only run together with that stack.
  • The world hang is unchanged.

Not tested: this PR together with #320, AMD GPUs, a release build, image results.

(Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)

**@⁠SpaghettiMaster545** on GitHub · 2026-11-24 03:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7121442243) **Tested with the title** at `64c7188`. - NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build of the branch merged onto `main` `d2a4bae` (clean), its own empty `VICTORY_CACHE_DIR`, `VICTORY_KEYS` into story mode, until the host GPU failure (#71, unrelated); compared program by program with a `main` run made the same way (#400 has the setup). - 8 programs that stop on `main` translate and run. 0 programs that ran on `main` stop. - 7 more compute programs that stop in translation on `main` (`a select on an untracked mask` 3, `a lane mask holding lanes elsewhere read as data` 3, `a lane-mask join of an untracked mask` 1) translate with this PR, but the driver refuses their pipelines with `E_INVALIDARG`. That is the same refusal as the 119 wave64 compute programs `main` already has on this 32-lane card, the class #233 / #320 deal with. So on NVIDIA they only run together with that stack. - The world hang is unchanged. **Not tested**: this PR together with #320, AMD GPUs, a release build, image results. (Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)
Author
Owner

@⁠Mesrine67 on GitHub · 2026-11-24 04:09 UTC · original

Local DXIL translation/validation comparison for this PR head 64c7188a17 against its exact base d2a4bae1f4, using the same local shaders.rpf, Windows SDK 10.0.26100.0 dxil.dll, and translate --validate --jobs 4:

Stage Base emitted / validated PR emitted / validated Delta
Vertex + pixel 12,272 / 12,172 12,368 / 12,268 +96 / +96
Compute 1,693 / 1,670 1,732 / 1,698 +39 / +28
Mesh 8,191 / 8,129 8,192 / 8,130 +1 / +1
Total 22,156 / 21,971 22,292 / 22,096 +136 / +125

The translator's lane mask holding lanes elsewhere read as data rejection bucket fell from 276 to 20. Both runs processed 26,084 programs after skipping the same 614 duplicate containers.

This was CPU-side translation plus DXIL validation only: zero D3D12 pipelines were created, and no title code was executed. The RX 6750 XT in this Windows 11 PC was not exercised by this scan, so these numbers do not establish GPU acceptance or a rendered in-game scene. Logs are available locally if a reproducer is useful.

**@⁠Mesrine67** on GitHub · 2026-11-24 04:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7121761546) Local DXIL translation/validation comparison for this PR head 64c7188a17f998756edf57a1c6aa803f4e2c7022 against its exact base d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989, using the same local shaders.rpf, Windows SDK 10.0.26100.0 dxil.dll, and translate --validate --jobs 4: | Stage | Base emitted / validated | PR emitted / validated | Delta | | --- | ---: | ---: | ---: | | Vertex + pixel | 12,272 / 12,172 | 12,368 / 12,268 | +96 / +96 | | Compute | 1,693 / 1,670 | 1,732 / 1,698 | +39 / +28 | | Mesh | 8,191 / 8,129 | 8,192 / 8,130 | +1 / +1 | | **Total** | **22,156 / 21,971** | **22,292 / 22,096** | **+136 / +125** | The translator's lane mask holding lanes elsewhere read as data rejection bucket fell from 276 to 20. Both runs processed 26,084 programs after skipping the same 614 duplicate containers. This was CPU-side translation plus DXIL validation only: zero D3D12 pipelines were created, and no title code was executed. The RX 6750 XT in this Windows 11 PC was not exercised by this scan, so these numbers do not establish GPU acceptance or a rendered in-game scene. Logs are available locally if a reproducer is useful.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 04:13 UTC · original

Measured 64c7188 on the retail shaders (v1.0.2.1, Series X package), offline with victory translate --jobs 8 --list against main d2a4bae, same 26,148 programs. This was asked for in #160's thread: the 4 cube image_sample_d_cl programs #160 leaves at a cross-lane operation outside compute.

main this PR #160 (25e917b) #160 + this PR #160 + #54 (f30734f)
Vertex and pixel programs emitted 12,284 12,380 12,357 12,457 12,412
The 27 cube image_sample_d_cl programs translating 0 0 (the opcode is #160's) 23 27 27
Programs that translated on main and stop – 0 0 0 0

Both merges were clean (no conflicts). On its own, this PR clears a select on an untracked mask (288 → 0), a cross-lane operation outside compute (46 → 0), an opaque lane mask (29 → 0) and a conditional export (8 → 0), and cuts a lane mask holding lanes elsewhere read as data from 276 to 20. Most of the programs that get further now stop at a descriptor read only as data (183 → 692).

AI-assisted.

**@⁠EduAzevedo** on GitHub · 2026-11-24 04:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7121827728) Measured `64c7188` on the retail shaders (v1.0.2.1, Series X package), offline with `victory translate --jobs 8 --list` against `main` `d2a4bae`, same 26,148 programs. This was asked for in #160's thread: the 4 cube `image_sample_d_cl` programs #160 leaves at `a cross-lane operation outside compute`. | | `main` | this PR | #160 (`25e917b`) | #160 + this PR | #160 + #54 (`f30734f`) | |---|---|---|---|---|---| | Vertex and pixel programs emitted | 12,284 | **12,380** | 12,357 | **12,457** | 12,412 | | The 27 cube `image_sample_d_cl` programs translating | 0 | 0 (the opcode is #160's) | 23 | **27** | 27 | | Programs that translated on `main` and stop | – | 0 | 0 | 0 | 0 | Both merges were clean (no conflicts). On its own, this PR clears `a select on an untracked mask` (288 → 0), `a cross-lane operation outside compute` (46 → 0), `an opaque lane mask` (29 → 0) and `a conditional export` (8 → 0), and cuts `a lane mask holding lanes elsewhere read as data` from 276 to 20. Most of the programs that get further now stop at `a descriptor read only as data` (183 → 692). AI-assisted.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 04:55 UTC · original

Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602):

  • Translation failures: 3,733 on main → 3,597 with this PR (−136). "a select on an untracked mask" disappears and "a lane mask holding lanes elsewhere read as data" drops from 276 to 20.
  • 11 compute programs that failed to emit on main (9 × "a lane mask holding lanes elsewhere read as data", 2 × "a lane-mask join of an untracked mask") now emit but fail DXIL validation with Entry function performs some operation that is incompatible with the shader stage or other entry properties. No program that validated on main fails now.
  • Merges cleanly with #385: 3,572 failures together (−161), and that validation error goes from 24 to 55 modules.
**@⁠iurysf** on GitHub · 2026-11-24 04:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7122460721) Tested offline against main `d2a4bae` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602): - Translation failures: 3,733 on main → 3,597 with this PR (−136). "a select on an untracked mask" disappears and "a lane mask holding lanes elsewhere read as data" drops from 276 to 20. - 11 compute programs that failed to emit on main (9 × "a lane mask holding lanes elsewhere read as data", 2 × "a lane-mask join of an untracked mask") now emit but fail DXIL validation with `Entry function performs some operation that is incompatible with the shader stage or other entry properties`. No program that validated on main fails now. - Merges cleanly with #385: 3,572 failures together (−161), and that validation error goes from 24 to 55 modules.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-24 17:32 UTC · original

Runtime verification, Win10/RTX 3080 (driver 621.24): this PR clears the lane-mask classes at runtime — "a select on an untracked mask" (102) and "a lane mask holding lanes elsewhere read as data" (97) disappear from the captured-failure census. Those shaders then translate past masks and fail deeper (mostly "a descriptor read only as data", since cleared by #1067). Net in-game effect with #1067 stacked: untranslated 444 → 100.

Merge note for whoever integrates this with the newer main: the wave-form decision in lower.rs (console_lanes/split/wants_console_flow) must be computed on every instruction (insts()), not on the dead-spill-filtered set. Filtering the resolved spill reloads out of that analysis picks wrong wave forms and stalls the title at boot (we hit this and bisected it). The lowering still skips dead spills via self.dead; only the wave-form analysis needs the full set. With that, boot/menus/world all run normally.

AI use: Qwen Code (underlying model name not disclosed by the tool); the boot-stall finding is from a local bisect on this machine.

**@⁠justlovett0** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/309#issuecomment-7139347096) Runtime verification, Win10/RTX 3080 (driver 621.24): this PR clears the lane-mask classes at runtime — "a select on an untracked mask" (102) and "a lane mask holding lanes elsewhere read as data" (97) disappear from the captured-failure census. Those shaders then translate past masks and fail deeper (mostly "a descriptor read only as data", since cleared by #1067). Net in-game effect with #1067 stacked: untranslated 444 → 100. **Merge note for whoever integrates this with the newer main:** the wave-form decision in `lower.rs` (`console_lanes`/`split`/`wants_console_flow`) must be computed on **every instruction** (`insts()`), not on the dead-spill-filtered set. Filtering the resolved spill reloads out of that analysis picks wrong wave forms and **stalls the title at boot** (we hit this and bisected it). The lowering still skips dead spills via `self.dead`; only the wave-form analysis needs the full set. With that, boot/menus/world all run normally. AI use: Qwen Code (underlying model name not disclosed by the tool); the boot-stall finding is from a local bisect on this machine.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!309
No description provided.