[pr-performance][shaders] Six translator levers on by default (+9 % fps, -5.0 ms of GPU time a frame, on an RTX 2080 Ti) #76

Open
cafe wants to merge 4 commits from cafe/shader-levers into main AGit
Contributor

Contributor role (optional)

  • Fluxer ID: Cafe#9189

What it changes

+9 % fps, -5.0 ms of GPU time a frame on an RTX 2080 Ti (same build, the six off against on).

Re-filed from CodeFloe PR 295 (that repo is gone; nothing was migrated). CodeFloe numbers are written without "#" here, since numbers restarted on this host. Brought up to main 1a5286a78 by merging main in, without conflicts.

Six translator changes, each measured on its own, on by default. Four are new, two change existing defaults. Each has a switch to turn it off by itself.

Setting (default now) What it does Measured on an RTX 2080 Ti
DARNER_LEGACY_FINITE=31 (new; before, only values proven bounded) A legacy multiply (0 x anything = 0) becomes a plain multiply when its factors come from constant buffers, textures, buffers, or sums and products of these, i.e. it takes those values as finite. -1.5 ms of the 3.9 ms the zero guards cost a frame
DARNER_MOVREL_WATERFALL (new, on unless 0) Waterfall loops over an M0 register index (v_movrels/v_movreld) run once per lane instead of once per distinct index, each pass a select over the whole register range. -0.3 ms
DARNER_LICM_CBUF=1 (new; 0 off, 2 also descriptor handles) Constant-buffer rows at constant indices leave loops even from blocks that run conditionally. The lighting gathers' ray march re-read 125 rows each step. -2.8 ms in game
DARNER_SHADER_OPT=511 (was 447) Adds the WIDE pass: up to 4 dwords of a console load in one call. -0.25 ms (replay)
DARNER_SHADER_LOOP_LIMIT_OF (new), default 7b2c3c1db2298f44:1024 Loop limits for single programs, named by the hash the log shows, keyed apart in the shader cache. CS_ShadowTileBalanceRTCost walks an index range whose loop ran toward the 4,096-round compute cap; 1,024 is 4 times what the scene needed. Empty removes it. -0.9 ms (replay)
Unfolded by default: CS_ShadowRenderTiled, CS_GenerateShadowMasks_HairOnly These run in the exact (unfolded) wave64 form on a 32-lane host, as lightAtlas already does. -1.3 ms (replay), -0.3 ms in game; hair masks -0.5 ms

LEGACY_FINITE, MOVREL_WATERFALL and LICM_CBUF are added to the shader cache key. The translated shaders change, so every player's pipelines are rebuilt once after this update.

How it was tested

  • Tested revision: 7e96ad684 (main 4a92569fb with the six merged in); main 1a5286a78 merged in since as 581ee600f, without conflicts and with no translator change between the two.
  • Gameplay: RTX 2080 Ti, Windows 10, Series S profile, 2560x1440 output, DLSS Performance, hardware ray tracing, no frame generation, the rest at Darner's defaults. Jason's house save, the same 30 s stretch after the world shows, pipelines warm, no other program using the card (checked per run).
  • Before and after, same build, two runs each: GPU time a frame 58.9 and 58.8 ms with the six at the old defaults, 53.5 and 54.1 ms with them on: -5.0 ms (-8.6 %). On this card that is 16.5 to 18.1 fps. In the opening top-down pan, a heavier view: 74.9/74.6 to 68.9/70.8 ms (-4.9 ms). Old defaults: DARNER_LEGACY_FINITE=0 DARNER_MOVREL_WATERFALL=0 DARNER_LICM_CBUF=0 DARNER_SHADER_OPT=447 DARNER_WAVE_FOLDED_SKIP=lightAtlas, and the loop limit pointed at no program.
  • Found and measured one by one on an earlier code base (boat save): +1.0 fps for the first two, +0.6 for the loop limit, WIDE and hair masks together, +1.4 for LICM_CBUF. The replayed frames' pictures were unchanged.
  • Picture in game: on in all our runs for three days, watched by eye; no picture fault traced to them. There was no separate eyes check for each one.
  • Shader wave sizes tested: 32 lanes (NVIDIA) only.
  • cargo test --release --locked -p darner-shader --lib: 490 passed, 68 failed; main alone: 488 passed and the same 68 failed (the 2 more are this change's tests). The 68 need a Shader Model 6.6 device, which this Windows 10 PC can't give a test program. -p darner-gpu --lib stops after 143 tests with exit code 3 here, the same on main alone.
  • Coverage gaps: AMD, Intel and other NVIDIA cards (the unfolded list is for 32-lane hosts; the others apply everywhere). Risk to watch: LEGACY_FINITE takes texture and buffer values as finite. If a game texture holds an infinity or NaN, 0 times it now gives NaN where it gave 0: look for black or bright specks. DARNER_LEGACY_FINITE=0 brings back the old behaviour.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • 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: none found here for these switches, loop limits or the unfolded list. On CodeFloe, near but different: PR 251 (three programs in the wide-fallback skip list), PRs 183 and 187 (other wave64 forms).
## Contributor role (optional) - Fluxer ID: `Cafe#9189` ## What it changes **+9 % fps, -5.0 ms of GPU time a frame** on an RTX 2080 Ti (same build, the six off against on). Re-filed from CodeFloe PR 295 (that repo is gone; nothing was migrated). CodeFloe numbers are written without "#" here, since numbers restarted on this host. Brought up to `main` 1a5286a78 by merging `main` in, without conflicts. Six translator changes, each measured on its own, on by default. Four are new, two change existing defaults. Each has a switch to turn it off by itself. | Setting (default now) | What it does | Measured on an RTX 2080 Ti | |---|---|---| | `DARNER_LEGACY_FINITE=31` (new; before, only values proven bounded) | A legacy multiply (0 x anything = 0) becomes a plain multiply when its factors come from constant buffers, textures, buffers, or sums and products of these, i.e. it takes those values as finite. | -1.5 ms of the 3.9 ms the zero guards cost a frame | | `DARNER_MOVREL_WATERFALL` (new, on unless `0`) | Waterfall loops over an M0 register index (`v_movrels`/`v_movreld`) run once per lane instead of once per distinct index, each pass a select over the whole register range. | -0.3 ms | | `DARNER_LICM_CBUF=1` (new; `0` off, `2` also descriptor handles) | Constant-buffer rows at constant indices leave loops even from blocks that run conditionally. The lighting gathers' ray march re-read 125 rows each step. | -2.8 ms in game | | `DARNER_SHADER_OPT=511` (was 447) | Adds the `WIDE` pass: up to 4 dwords of a console load in one call. | -0.25 ms (replay) | | `DARNER_SHADER_LOOP_LIMIT_OF` (new), default `7b2c3c1db2298f44:1024` | Loop limits for single programs, named by the hash the log shows, keyed apart in the shader cache. `CS_ShadowTileBalanceRTCost` walks an index range whose loop ran toward the 4,096-round compute cap; 1,024 is 4 times what the scene needed. Empty removes it. | -0.9 ms (replay) | | Unfolded by default: `CS_ShadowRenderTiled`, `CS_GenerateShadowMasks_HairOnly` | These run in the exact (unfolded) wave64 form on a 32-lane host, as `lightAtlas` already does. | -1.3 ms (replay), -0.3 ms in game; hair masks -0.5 ms | `LEGACY_FINITE`, `MOVREL_WATERFALL` and `LICM_CBUF` are added to the shader cache key. The translated shaders change, so every player's pipelines are rebuilt once after this update. ## How it was tested - Tested revision: 7e96ad684 (`main` 4a92569fb with the six merged in); `main` 1a5286a78 merged in since as 581ee600f, without conflicts and with no translator change between the two. - Gameplay: RTX 2080 Ti, Windows 10, Series S profile, 2560x1440 output, DLSS Performance, hardware ray tracing, no frame generation, the rest at Darner's defaults. Jason's house save, the same 30 s stretch after the world shows, pipelines warm, no other program using the card (checked per run). - Before and after, same build, two runs each: GPU time a frame 58.9 and 58.8 ms with the six at the old defaults, 53.5 and 54.1 ms with them on: -5.0 ms (-8.6 %). On this card that is 16.5 to 18.1 fps. In the opening top-down pan, a heavier view: 74.9/74.6 to 68.9/70.8 ms (-4.9 ms). Old defaults: `DARNER_LEGACY_FINITE=0 DARNER_MOVREL_WATERFALL=0 DARNER_LICM_CBUF=0 DARNER_SHADER_OPT=447 DARNER_WAVE_FOLDED_SKIP=lightAtlas`, and the loop limit pointed at no program. - Found and measured one by one on an earlier code base (boat save): +1.0 fps for the first two, +0.6 for the loop limit, `WIDE` and hair masks together, +1.4 for `LICM_CBUF`. The replayed frames' pictures were unchanged. - Picture in game: on in all our runs for three days, watched by eye; no picture fault traced to them. There was no separate eyes check for each one. - Shader wave sizes tested: 32 lanes (NVIDIA) only. - `cargo test --release --locked -p darner-shader --lib`: 490 passed, 68 failed; `main` alone: 488 passed and the same 68 failed (the 2 more are this change's tests). The 68 need a Shader Model 6.6 device, which this Windows 10 PC can't give a test program. `-p darner-gpu --lib` stops after 143 tests with exit code 3 here, the same on `main` alone. - Coverage gaps: AMD, Intel and other NVIDIA cards (the unfolded list is for 32-lane hosts; the others apply everywhere). Risk to watch: `LEGACY_FINITE` takes texture and buffer values as finite. If a game texture holds an infinity or NaN, 0 times it now gives NaN where it gave 0: look for black or bright specks. `DARNER_LEGACY_FINITE=0` brings back the old behaviour. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [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: none found here for these switches, loop limits or the unfolded list. On CodeFloe, near but different: PR 251 (three programs in the wide-fallback skip list), PRs 183 and 187 (other wave64 forms).
Measured on an RTX 2080 Ti (Series S, 1440p DLSS Performance, hardware RT,
house save): 18.57 -> 21.01 fps, GPU 51.2 -> 46.4 ms a frame.

- DARNER_LEGACY_FINITE=31 (new): a legacy multiply is plain when its factors
  come from constant buffers, textures, buffers, or sums and products of
  these (taken as finite). 0 proves each one as before.
- DARNER_MOVREL_WATERFALL (new, on unless 0): waterfall loops over an M0
  register index run once per lane.
- DARNER_LICM_CBUF=1 (new): constant-buffer rows at constant indices leave
  loops from conditional blocks too.
- DARNER_SHADER_OPT default 511: the WIDE pass runs too.
- DARNER_SHADER_LOOP_LIMIT_OF (new): loop limits of single programs, by the
  hash a run's log names them by, keyed apart in the shader cache; default
  7b2c3c1db2298f44:1024 (CS_ShadowTileBalanceRTCost), empty for none.
- CS_ShadowRenderTiled and CS_GenerateShadowMasks_HairOnly unfolded by
  default on 32-lane hosts, like lightAtlas.

LEGACY_FINITE, MOVREL_WATERFALL and LICM_CBUF are in the shader cache key.
# Conflicts:
#	crates/darner-gpu/src/shader_cache.rs
First-time contributor

Nice. @TrustNo1 merge it

Nice. @TrustNo1 merge it
Author
Contributor

Would love to get some feedback on this too btw for folks that are GPU bound (or otherwise, just give me gpu time if you can).

I do pretty extensive correctness test even on my own captures, but still only just with my hardware and my driver.
Most of those optis should at least not hurt anybody though, like worst thing that hoisting a constant can do is that the compiler still just decides to read it in the loop anyway. 🤷‍♂️

Would *love* to get some feedback on this too btw for folks that are GPU bound (or otherwise, just give me gpu time if you can). I do pretty extensive correctness test even on my own captures, but still only just with my hardware and my driver. Most of those optis should at least not hurt anybody though, like worst thing that hoisting a constant can do is that the compiler still just decides to read it in the loop anyway. 🤷‍♂️
First-time contributor

Sup Cafe! Just compiled your PR and tested it.

Specs : 3060 ti (8 gig) 11700k I7 and 48 gig of DDR4.

FPS before was around 17-19 (without FG of course) and after running your PR it just jumped up to 21-23. Frame gen time also dropped by 5-6ms.

Very impressive buddy! If you need any more info I'll keep my eyes out. I'm also testing some tweaks and modifications to the code but have come up with NOTHING like this!

Sup Cafe! Just compiled your PR and tested it. Specs : 3060 ti (8 gig) 11700k I7 and 48 gig of DDR4. FPS before was around 17-19 (without FG of course) and after running your PR it just jumped up to 21-23. Frame gen time also dropped by 5-6ms. Very impressive buddy! If you need any more info I'll keep my eyes out. I'm also testing some tweaks and modifications to the code but have come up with NOTHING like this!
First-time contributor

AMD numbers, as asked: RX 7900 XTX (24 GB, driver 32.0.32029.2010), Ryzen 7 7800X3D, Windows 11.

Card time in the title's lists: -2.5 ms a frame standing still (19.1 to 16.6 ms, -13 %), -2.3 ms on a walk. No fps change here: this PC is CPU-bound in this scene (the submitting thread 22-28 ms a frame), so the card's saving doesn't show as frame rate.

Setup: PR head 581ee600f built as is (diag profile), the same build both ways. Old defaults set as in your description (DARNER_LEGACY_FINITE=0 DARNER_MOVREL_WATERFALL=0 DARNER_LICM_CBUF=0 DARNER_SHADER_OPT=447 DARNER_WAVE_FOLDED_SKIP=lightAtlas, DARNER_SHADER_LOOP_LIMIT_OF pointed at no program; the "these programs' loops stop sooner" warning was in every on-run's log and in none of the off-runs). Series S profile (1920x1080, no upscaler), hardware ray tracing, no frame generation, frame rate uncapped, DARNER_RELAY=2 DARNER_PORT_CBV=1. A heavy downtown save, pipelines warmed for both arms beforehand, the last 120 s of each run measured, arms alternated. No device losses, no pipelines compiled during the measured part.

Standing still (same view every run, 5.5k draws a frame), two pairs (off, on, on, off):

Pair Card ms/frame (settled median), off -> on avg fps, off -> on draws/frame median, off -> on
1 18.9 -> 16.6 35.2 -> 34.4 5485 -> 5530
2 19.3 -> 16.6 33.1 -> 34.8 5610 -> 5518

Walking (a scripted 140 s walk; it wanders, so draws differ between runs by up to a third), three pairs (off, on, on, off, off, on):

Pair Card ms/frame (settled median), off -> on avg fps, off -> on draws/frame median, off -> on
1 20.3 -> 16.9 31.2 -> 32.5 7965 -> 7707
2 18.3 -> 17.5 33.7 -> 32.4 5587 -> 7598
3 19.6 -> 16.9 32.2 -> 33.6 7843 -> 6679

The card was faster with the six on in all five pairs. Pair 2 of the walk had the smallest gap; its off-run walked a lighter stretch (5.6k against 7.6k draws).

Not covered: I measured the levers together, not one by one. Nobody has checked the picture by eye on this card yet (the specks risk you mention for LEGACY_FINITE). I'll add a note here if we see any. I didn't check whether the unfolded list does anything on a wave64 AMD host; I'd expect it not to.

AMD numbers, as asked: **RX 7900 XTX** (24 GB, driver 32.0.32029.2010), Ryzen 7 7800X3D, Windows 11. **Card time in the title's lists: -2.5 ms a frame standing still (19.1 to 16.6 ms, -13 %), -2.3 ms on a walk.** No fps change here: this PC is CPU-bound in this scene (the submitting thread 22-28 ms a frame), so the card's saving doesn't show as frame rate. Setup: PR head 581ee600f built as is (diag profile), the same build both ways. Old defaults set as in your description (`DARNER_LEGACY_FINITE=0 DARNER_MOVREL_WATERFALL=0 DARNER_LICM_CBUF=0 DARNER_SHADER_OPT=447 DARNER_WAVE_FOLDED_SKIP=lightAtlas`, `DARNER_SHADER_LOOP_LIMIT_OF` pointed at no program; the "these programs' loops stop sooner" warning was in every on-run's log and in none of the off-runs). Series S profile (1920x1080, no upscaler), hardware ray tracing, no frame generation, frame rate uncapped, `DARNER_RELAY=2 DARNER_PORT_CBV=1`. A heavy downtown save, pipelines warmed for both arms beforehand, the last 120 s of each run measured, arms alternated. No device losses, no pipelines compiled during the measured part. **Standing still** (same view every run, 5.5k draws a frame), two pairs (off, on, on, off): | Pair | Card ms/frame (settled median), off -> on | avg fps, off -> on | draws/frame median, off -> on | |---|---|---|---| | 1 | 18.9 -> 16.6 | 35.2 -> 34.4 | 5485 -> 5530 | | 2 | 19.3 -> 16.6 | 33.1 -> 34.8 | 5610 -> 5518 | **Walking** (a scripted 140 s walk; it wanders, so draws differ between runs by up to a third), three pairs (off, on, on, off, off, on): | Pair | Card ms/frame (settled median), off -> on | avg fps, off -> on | draws/frame median, off -> on | |---|---|---|---| | 1 | 20.3 -> 16.9 | 31.2 -> 32.5 | 7965 -> 7707 | | 2 | 18.3 -> 17.5 | 33.7 -> 32.4 | 5587 -> 7598 | | 3 | 19.6 -> 16.9 | 32.2 -> 33.6 | 7843 -> 6679 | The card was faster with the six on in all five pairs. Pair 2 of the walk had the smallest gap; its off-run walked a lighter stretch (5.6k against 7.6k draws). Not covered: I measured the levers together, not one by one. Nobody has checked the picture by eye on this card yet (the specks risk you mention for `LEGACY_FINITE`). I'll add a note here if we see any. I didn't check whether the unfolded list does anything on a wave64 AMD host; I'd expect it not to.
First-time contributor
@TrustNo1
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 origin '+refs/pull/76/head:cafe/shader-levers'
git switch 'cafe/shader-levers'

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 'cafe/shader-levers'
git switch 'cafe/shader-levers'
git rebase 'main'
git switch 'main'
git merge --ff-only 'cafe/shader-levers'
git switch 'cafe/shader-levers'
git rebase 'main'
git switch 'main'
git merge --no-ff 'cafe/shader-levers'
git switch 'main'
git merge --squash 'cafe/shader-levers'
git switch 'main'
git merge --ff-only 'cafe/shader-levers'
git switch 'main'
git merge 'cafe/shader-levers'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
5 participants
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!76
No description provided.