[pr-performance][shaders][AMD] shader: add DARNER_LOOP_EXIT and DARNER_JOIN_EDGES to reduce loop VGPR pressure #713

Open
ggwp wants to merge 1 commit from ggwp/Darner:perf/amd-loop-regs into post-merge
Contributor

Contributor role (optional)

  • Fluxer ID: FomalhautCusimanse#7381

What it changes

Port of gamingwithhomie/larp PR #247 (12eddd4d, originally by ambrosia-works / cool_fox, adapted to Darner post-merge):

  • The problem on post-merge: Two patterns in translated DXIL cause AMD's shader compiler (amdxc64) to keep excessive live values across loops and emit high VGPR counts / register spills:

    1. Counted loops whose back edge is a dedicated latch block previously branched to an abort ret inside the loop when hitting the iteration cap, forcing amdxc64 to keep values live through the loop (CS_Gather_Classified_19: 256 VGPRs + spills -> 144 VGPRs in upstream measurement).
    2. Empty forward edge blocks emitted before loop joins prevented the compiler from seeing a single exit block (CS 8cb27ccf: 144 -> 72 VGPRs, 57724872: 96 -> 45 VGPRs in upstream measurement).
  • Fix:

    • DARNER_LOOP_EXIT (default on on Windows, off under Wine; 0/1 overrides): folds the iteration limit into the branch leading into a dedicated latch so lanes leave through the loop's own exit instead of an abort return.
    • DARNER_JOIN_EDGES (default on on Windows, off under Wine; 0/1 overrides): Module::skip_empty_edges removes empty phi-less pass-through edge blocks before single_latches (exact IR transform, pinned by unit test empty_edge_blocks_are_left_out).
    • Both switches are added to darner_shader::SWITCHES and their effective values are hashed into shader_cache.rs.

How it was tested

  • Tested revision: b948640 (based on post-merge 28a9b42; also run in-game in a combined AMD build with #676 and #684)
  • Commands and results:
    • cargo test --offline -p darner-shader --lib — 1 passed (emit::bitcode::tests::empty_edge_blocks_are_left_out), 0 failed
    • cargo clippy --offline -p darner-shader --tests — passed
    • cargo check --offline -p darner-gpu — passed
    • cargo build --offline --release -p darner — succeeded (combined build)
  • Changes a default: yes, on native Windows (off by default under Wine; overridable with DARNER_LOOP_EXIT=0 / DARNER_JOIN_EDGES=0).
  • A/B result: Tested in-game on AMD Radeon 8060S (RDNA 3.5) and AMD Radeon RX 9070 XT (RDNA 4) inside a combined test build (with #676 and #684 required for AMD rendering/startup). Upstream PR #247 measured VGPR reductions on RX 7900 XT (CS_Gather_Classified_19 256 + spills -> 144, 8cb27ccf 144 -> 72, 57724872 96 -> 45). No standalone isolated A/B FPS table recorded on post-merge alone.
  • Checks run on b948640: cargo test, cargo clippy, cargo check (all passed).
  • Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build.
  • Hardware dependence: Primarily improves AMD RDNA shader occupancy (measured on RX 7900 XT upstream; tested on RDNA 3.5 and RDNA 4); defaults off under Wine.
  • Coverage gaps: Untested on NVIDIA, Intel, and Wine/Proton.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on post-merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #684 (touches lower.rs in descriptor_data/handle, different hunks, no conflict).
  • Replaces or overlaps: none found.
## Contributor role (optional) - Fluxer ID: FomalhautCusimanse#7381 ## What it changes Port of `gamingwithhomie/larp` PR #247 (`12eddd4d`, originally by `ambrosia-works` / `cool_fox`, adapted to Darner `post-merge`): - **The problem on `post-merge`:** Two patterns in translated DXIL cause AMD's shader compiler (`amdxc64`) to keep excessive live values across loops and emit high VGPR counts / register spills: 1. Counted loops whose back edge is a dedicated latch block previously branched to an abort `ret` inside the loop when hitting the iteration cap, forcing `amdxc64` to keep values live through the loop (`CS_Gather_Classified_19`: 256 VGPRs + spills -> 144 VGPRs in upstream measurement). 2. Empty forward edge blocks emitted before loop joins prevented the compiler from seeing a single exit block (`CS 8cb27ccf`: 144 -> 72 VGPRs, `57724872`: 96 -> 45 VGPRs in upstream measurement). - **Fix:** - `DARNER_LOOP_EXIT` (default on on Windows, off under Wine; `0`/`1` overrides): folds the iteration limit into the branch leading into a dedicated latch so lanes leave through the loop's own exit instead of an abort return. - `DARNER_JOIN_EDGES` (default on on Windows, off under Wine; `0`/`1` overrides): `Module::skip_empty_edges` removes empty phi-less pass-through edge blocks before `single_latches` (exact IR transform, pinned by unit test `empty_edge_blocks_are_left_out`). - Both switches are added to `darner_shader::SWITCHES` and their effective values are hashed into `shader_cache.rs`. ## How it was tested - Tested revision: `b948640` (based on `post-merge` `28a9b42`; also run in-game in a combined AMD build with #676 and #684) - Commands and results: - `cargo test --offline -p darner-shader --lib` — 1 passed (`emit::bitcode::tests::empty_edge_blocks_are_left_out`), 0 failed - `cargo clippy --offline -p darner-shader --tests` — passed - `cargo check --offline -p darner-gpu` — passed - `cargo build --offline --release -p darner` — succeeded (combined build) - Changes a default: yes, on native Windows (off by default under Wine; overridable with `DARNER_LOOP_EXIT=0` / `DARNER_JOIN_EDGES=0`). - A/B result: Tested in-game on AMD Radeon 8060S (RDNA 3.5) and AMD Radeon RX 9070 XT (RDNA 4) inside a combined test build (with #676 and #684 required for AMD rendering/startup). Upstream PR #247 measured VGPR reductions on RX 7900 XT (`CS_Gather_Classified_19` 256 + spills -> 144, `8cb27ccf` 144 -> 72, `57724872` 96 -> 45). No standalone isolated A/B FPS table recorded on `post-merge` alone. - Checks run on `b948640`: `cargo test`, `cargo clippy`, `cargo check` (all passed). - Gameplay: AMD Radeon 8060S (64 GB) and AMD Radeon RX 9070 XT (16 GB), Series X, combined build. - Hardware dependence: Primarily improves AMD RDNA shader occupancy (measured on RX 7900 XT upstream; tested on RDNA 3.5 and RDNA 4); defaults off under Wine. - Coverage gaps: Untested on NVIDIA, Intel, and Wine/Proton. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `post-merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #684 (touches `lower.rs` in `descriptor_data`/`handle`, different hunks, no conflict). - Replaces or overlaps: none found.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/amd-loop-regs:ggwp-perf/amd-loop-regs'
git switch 'ggwp-perf/amd-loop-regs'

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 'post-merge'
git merge --no-ff 'ggwp-perf/amd-loop-regs'
git switch 'ggwp-perf/amd-loop-regs'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'ggwp-perf/amd-loop-regs'
git switch 'ggwp-perf/amd-loop-regs'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'ggwp-perf/amd-loop-regs'
git switch 'post-merge'
git merge --squash 'ggwp-perf/amd-loop-regs'
git switch 'post-merge'
git merge --ff-only 'ggwp-perf/amd-loop-regs'
git switch 'post-merge'
git merge 'ggwp-perf/amd-loop-regs'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!713
No description provided.