AMD: fewer registers in translated loops (LARP_LOOP_EXIT, LARP_JOIN_EDGES) #247

Manually merged
github merged 1 commit from github-bot/gh-247 into gh-pr/247/base 2026-12-06 01:08:16 +00:00 AGit
Owner

@⁠ambrosia-works on GitHub · 2026-12-05 22:08 UTC · original
ambrosia-works:perf/amd-loop-exit-join-edges → amd-test · +316 −21 · 7 files · 1 commits · merged 2026-12-05 23:28 UTC

Summary

Two shader-translator changes that cut register pressure in AMD's shader compiler. Both are ported from the cool_fox fork (6becc5fc2, 1e316adbe), where they were measured on an RX 7900 XT under Windows. They target this branch because the gain is AMD-specific.

Both are on by default on Windows and off under Wine/Proton, where they were never tested against vkd3d-proton. LARP_LOOP_EXIT=0|1 and LARP_JOIN_EDGES=0|1 override the default. Both names are in larp_shader::SWITCHES, and their effective values are hashed into the shader cache's build key, so the translation cache rebuilds once.

LARP_LOOP_EXIT

A counted loop that reached its iteration limit used to return from the program inside the loop. Because of that return, AMD's compiler kept the whole program's values live through the loop.

  • Now the limit test is folded into the branch before the latch, and the loop leaves through its own exit.
  • Measured in cool_fox: CS_Gather_Classified_19 went from 256 VGPRs plus spills to 144 (the console's count).
  • Two hardening changes over the original port:
    • No fold when the branch's other side is itself a back edge (a continue of an outer loop keeps its own count).
    • live_edges no longer takes the folded branch's condition as known on its edges, so values joined at the exit are not zeroed as dead.
  • Behaviour change: a lane stopped by the limit now continues after the loop instead of returning (a pixel is no longer discarded there). This only affects runaway loops that hit the limit (128 pixel, 256 vertex/mesh, 4096 compute iterations).

LARP_JOIN_EDGES

Module::skip_empty_edges removes empty edge blocks (no phi, no instruction, only a branch) before single_latches. A loop whose exits all lead to one join then has one exit block, as DXC writes it.

  • Measured in cool_fox: CS 8cb27ccf went from 144 to 72 VGPRs and from 5 to 10 waves; 57724872 went from 96 to 45 VGPRs.
  • Exact: no instruction moves.

Verification

  • cargo test --release --locked -p larp-shader: 2 passed, including the new empty_edge_blocks_are_left_out.
  • cargo check --release --locked -p larp: no new warnings.
  • Offline larp translate <shaders.rpf> --validate with LARP_SHADER_REPLACE=0 and the Windows SDK validator, under three settings: both switches =0, defaults, and both =1.
    • All 26,084 programs translated, with identical validated counts and identical pre-existing failures in every run.
    • Temporary counters showed about 61k folded latches and 816k skipped edge blocks in a partial run, so both paths are exercised.
  • VGPR counts on larp's translations have not been re-measured on hardware; the numbers above are from cool_fox. The change is not yet A/B'd in-game on this branch.
**@⁠ambrosia-works** on GitHub · 2026-12-05 22:08 UTC · [original](https://github.com/gamingwithhomie/larp/pull/247) `ambrosia-works:perf/amd-loop-exit-join-edges` → `amd-test` · +316 −21 · 7 files · 1 commits · merged 2026-12-05 23:28 UTC ## Summary Two shader-translator changes that cut register pressure in AMD's shader compiler. Both are ported from the cool_fox fork (`6becc5fc2`, `1e316adbe`), where they were measured on an RX 7900 XT under Windows. They target this branch because the gain is AMD-specific. Both are **on by default on Windows** and **off under Wine/Proton**, where they were never tested against vkd3d-proton. `LARP_LOOP_EXIT=0|1` and `LARP_JOIN_EDGES=0|1` override the default. Both names are in `larp_shader::SWITCHES`, and their effective values are hashed into the shader cache's build key, so the translation cache rebuilds once. ### `LARP_LOOP_EXIT` A counted loop that reached its iteration limit used to return from the program inside the loop. Because of that return, AMD's compiler kept the whole program's values live through the loop. - Now the limit test is folded into the branch before the latch, and the loop leaves through its own exit. - Measured in cool_fox: `CS_Gather_Classified_19` went from 256 VGPRs plus spills to 144 (the console's count). - Two hardening changes over the original port: - No fold when the branch's other side is itself a back edge (a `continue` of an outer loop keeps its own count). - `live_edges` no longer takes the folded branch's condition as known on its edges, so values joined at the exit are not zeroed as dead. - Behaviour change: a lane stopped by the limit now continues after the loop instead of returning (a pixel is no longer discarded there). This only affects runaway loops that hit the limit (128 pixel, 256 vertex/mesh, 4096 compute iterations). ### `LARP_JOIN_EDGES` `Module::skip_empty_edges` removes empty edge blocks (no phi, no instruction, only a branch) before `single_latches`. A loop whose exits all lead to one join then has one exit block, as DXC writes it. - Measured in cool_fox: CS `8cb27ccf` went from 144 to 72 VGPRs and from 5 to 10 waves; `57724872` went from 96 to 45 VGPRs. - Exact: no instruction moves. ## Verification - `cargo test --release --locked -p larp-shader`: 2 passed, including the new `empty_edge_blocks_are_left_out`. - `cargo check --release --locked -p larp`: no new warnings. - Offline `larp translate <shaders.rpf> --validate` with `LARP_SHADER_REPLACE=0` and the Windows SDK validator, under three settings: both switches `=0`, defaults, and both `=1`. - All 26,084 programs translated, with identical validated counts and identical pre-existing failures in every run. - Temporary counters showed about 61k folded latches and 816k skipped edge blocks in a partial run, so both paths are exercised. - VGPR counts on larp's translations have not been re-measured on hardware; the numbers above are from cool_fox. The change is not yet A/B'd in-game on this branch.
LARP_LOOP_EXIT: a counted loop whose back edge is a latch block of its own
(reached from one branch whose other side leaves the loop) meets its
iteration limit in that branch and leaves through the loop's own exit,
instead of returning from the program (abort block) at the latch. The
return inside each loop made AMD's compiler keep the whole program's
values live through its loops (CS_Gather_Classified_19: 256 VGPRs and
spills -> 144). count_iteration is split into count_ahead (the count and
its compare) and the push to the header's phi; the loop report
(LARP_LOOP_REPORT) still runs and the phi is pushed with self.cur after
it. Not folded where the branch's other side is itself a back edge (a
"continue" of an outer loop keeps its own count). live_edges no longer
takes the folded branch's condition as known on its edges: its exit side
also takes the lanes the limit stops, so values joined there are not
zeroed as dead. A lane stopped by the limit now goes on after the loop
(a pixel lane is no longer discarded there).

LARP_JOIN_EDGES: Module::skip_empty_edges leaves empty edge blocks (no
phi, no instruction, only a branch on) out of the module before
single_latches, so a loop whose exits all lead to one join has one exit
block as DXC writes it (CS 8cb27ccf 144 -> 72 VGPRs, 57724872 96 -> 45).
Exact: no instruction moves. Adds Module::successors and the
empty_edge_blocks_are_left_out unit test.

Both default on on Windows and off under Wine (ntdll's
wine_get_version, as larp-gpu's host::on_wine), since they were measured
on an RX 7900 XT under Windows only; `0` / `1` override. Both names are
in larp_shader::SWITCHES and their effective values are hashed into the
shader cache's build key (the default depends on the host, not only the
environment).

Ported from cool_fox 6becc5fc2 (LOOP_EXIT, product change only, without
the register probes) and 1e316adbe (JOIN_EDGES only, without
UNIFORM_LOADS).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 22:13:37 +00:00
Author
Owner

@⁠gamingwithhomie on GitHub · 2026-12-05 23:08 UTC · original

Queued for AMD review round: 1,037 lines of translated-loop register work (LARP_LOOP_EXIT/LARP_JOIN_EDGES) needs an RDNA test report (which card, before/after registers + fps) before we can merge it into the AMD track. The idea targets exactly the RDNA device-hang family, so its worth doing carefully.

**@⁠gamingwithhomie** on GitHub · 2026-12-05 23:08 UTC · [original](https://github.com/gamingwithhomie/larp/pull/247#issuecomment-7447341958) Queued for AMD review round: 1,037 lines of translated-loop register work (LARP_LOOP_EXIT/LARP_JOIN_EDGES) needs an RDNA test report (which card, before/after registers + fps) before we can merge it into the AMD track. The idea targets exactly the RDNA device-hang family, so its worth doing carefully.
github-bot changed target branch from amd-test to gh-pr/247/base 2026-12-05 23:37:02 +00:00
github manually merged commit ca64b8f7f1 into gh-pr/247/base 2026-12-06 01:08:16 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.