shader/dxil: add pack/unpack and Call folding peepholes plus pure CBV CSE #515

Open
hingeowl wants to merge 1 commit from hingeowl/Darner:pr/dxil-peepholes-cbv-cse into Main
Contributor

What it changes

  • The problem on main: DXIL bitcode emission leaves redundant 16-bit half-word pack/unpack patterns, idempotent nested DXIL intrinsic calls (Saturate/FAbs/UMin), and immutable constants_raw rawBufferLoad instructions un-CSE'd across UAV stores and loops.
  • Ported from ReTerryDavis/ReVIctory (91ba689490f565ab710e60663c35bc07f097e736):
    • Folds 16-bit half-word pack/unpack Trunc(Or(..., Shl(..., 16))) and Trunc(LShr(Or(...), 16)) patterns (emit/bitcode/opt.rs).
    • Folds idempotent/nested DXIL Op::Call patterns: Saturate(Saturate(x)), FAbs(FAbs|Saturate(x)), and UMin(UMin(x, k1), k2).
    • Tracks immutable constants_raw rawBufferLoad instructions in Module::pure_reads so they CSE across UAV stores and loops as Effect::Pure.

How it was tested

  • Tested revision: 649e2af (based on main c8258f9)
  • Commands and results:
    • cargo xtask policy — pass
    • cargo clippy --workspace --all-targets --locked -- -D warnings — pass
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — pass
    • cargo test -p darner-shader --locked -- opt:: — pass (includes GPU bit-exact parity tests)
  • Changes a default: yes (optimizer pass runs during DXIL emission).
  • A/B result: not yet benchmarked standalone in isolation; validated in-game on cam-city60 (RTX 4090 + Ryzen 9 7950X3D, Series X, HW RT) as part of our integration branch with clean visuals.
  • Gates run on that revision: cargo xtask policy, both workspace clippy gates, cargo test -p darner-shader --locked -- opt::.
  • Hardware dependence: likely general.
  • Coverage gaps: standalone A/B FPS comparison not yet recorded for this commit in isolation.

Checklist

  • I ran this change in the game.
  • 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
  • Replaces or overlaps: none found
## What it changes - The problem on main: DXIL bitcode emission leaves redundant 16-bit half-word pack/unpack patterns, idempotent nested DXIL intrinsic calls (`Saturate`/`FAbs`/`UMin`), and immutable `constants_raw` `rawBufferLoad` instructions un-CSE'd across UAV stores and loops. - Ported from `ReTerryDavis/ReVIctory` (`91ba689490f565ab710e60663c35bc07f097e736`): - Folds 16-bit half-word pack/unpack `Trunc(Or(..., Shl(..., 16)))` and `Trunc(LShr(Or(...), 16))` patterns (`emit/bitcode/opt.rs`). - Folds idempotent/nested DXIL `Op::Call` patterns: `Saturate(Saturate(x))`, `FAbs(FAbs|Saturate(x))`, and `UMin(UMin(x, k1), k2)`. - Tracks immutable `constants_raw` `rawBufferLoad` instructions in `Module::pure_reads` so they CSE across UAV stores and loops as `Effect::Pure`. ## How it was tested - Tested revision: `649e2af` (based on `main` `c8258f9`) - Commands and results: - `cargo xtask policy` — pass - `cargo clippy --workspace --all-targets --locked -- -D warnings` — pass - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — pass - `cargo test -p darner-shader --locked -- opt::` — pass (includes GPU bit-exact parity tests) - Changes a default: yes (optimizer pass runs during DXIL emission). - A/B result: not yet benchmarked standalone in isolation; validated in-game on `cam-city60` (RTX 4090 + Ryzen 9 7950X3D, Series X, HW RT) as part of our integration branch with clean visuals. - Gates run on that revision: `cargo xtask policy`, both workspace `clippy` gates, `cargo test -p darner-shader --locked -- opt::`. - Hardware dependence: likely general. - Coverage gaps: standalone A/B FPS comparison not yet recorded for this commit in isolation. ## Checklist - [x] I ran this change in the game. - [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 - Replaces or overlaps: none found
Port DXIL optimizer improvements from ReVIctory:
- Fold 16-bit half-word pack/unpack Trunc(Or(..., Shl(..., 16))) and Trunc(LShr(Or(...), 16)) patterns.
- Fold idempotent/nested DXIL Op::Call patterns: Saturate(Saturate(x)), FAbs(FAbs|Saturate(x)), and UMin(UMin(x, k1), k2).
- Track immutable constants_raw rawBufferLoad instructions in Module::pure_reads so they CSE across UAV stores and loops as Effect::Pure.

Upstream-Repository: https://github.com/ReTerryDavis/ReVIctory
Upstream-Commit: 91ba689490f565ab710e60663c35bc07f097e736
Integration-Base: 5f694dd
Validation: cargo test --locked -p darner-shader --lib emit::bitcode::opt (31 passed, 0 failed, incl. GPU bit-exact parity)
Contributor

Standalone A/B from an RTX 4080, since the PR has none yet: no change in card time or frame time in this scene.

PC: RTX 4080 16 GB (driver 621.40), i7-13700K, 64 GB, Windows 11 26300. Series X profile, 1440p with DLSS Quality, frame generation off, hardware ray tracing on, Reflex off (so the card is the limit here), DARNER_ALIAS_SHARE=1, DARNER_D3D12_BACKGROUND=0.
Builds: A = main 9b288a7 + #303 + #457. B = A + this PR (649e2af), merged cleanly.
Method: the opening scene of one save, entered the same way every run (no input after the start screen); medians of per-second values from the host log in three 45-second windows from the moment the world appears. B had two warm-up runs first (new translations); A's pipelines were warm. Order: B, A, B, A.

A (2 runs) B (2 runs)
card time in the title's lists, ms a frame 22.9 / 22.9 / 23.0 and 23.1 / 22.9 / 22.9 23.0 / 23.0 / 23.0 and 23.0 / 22.9 / 23.0
frame time, ms 26.2 / 26.1 / 25.9 and 26.5 / 26.1 / 26.1 25.5 / 25.3 / 25.4 and 26.6 / 26.4 / 26.2

The run-to-run spread of the frame time here is about 1 ms, so only the card time says something: the same within 0.1 ms. The lit living room 20 to 100 s in looks the same as A's. This scene is indoors and light on half-precision work, so it says nothing about shaders that use the folded pack/unpack patterns a lot.

Not tested: other cards, other scenes, the gates.

Standalone A/B from an RTX 4080, since the PR has none yet: no change in card time or frame time in this scene. **PC:** RTX 4080 16 GB (driver 621.40), i7-13700K, 64 GB, Windows 11 26300. Series X profile, 1440p with DLSS Quality, frame generation off, hardware ray tracing on, Reflex off (so the card is the limit here), `DARNER_ALIAS_SHARE=1`, `DARNER_D3D12_BACKGROUND=0`. **Builds:** A = main 9b288a7 + #303 + #457. B = A + this PR (649e2af), merged cleanly. **Method:** the opening scene of one save, entered the same way every run (no input after the start screen); medians of per-second values from the host log in three 45-second windows from the moment the world appears. B had two warm-up runs first (new translations); A's pipelines were warm. Order: B, A, B, A. | | A (2 runs) | B (2 runs) | |---|---|---| | card time in the title's lists, ms a frame | 22.9 / 22.9 / 23.0 and 23.1 / 22.9 / 22.9 | 23.0 / 23.0 / 23.0 and 23.0 / 22.9 / 23.0 | | frame time, ms | 26.2 / 26.1 / 25.9 and 26.5 / 26.1 / 26.1 | 25.5 / 25.3 / 25.4 and 26.6 / 26.4 / 26.2 | The run-to-run spread of the frame time here is about 1 ms, so only the card time says something: the same within 0.1 ms. The lit living room 20 to 100 s in looks the same as A's. This scene is indoors and light on half-precision work, so it says nothing about shaders that use the folded pack/unpack patterns a lot. Not tested: other cards, other scenes, the gates.
TrustNo1 changed title from [pr-performance][shaders] shader/dxil: add pack/unpack and Call folding peepholes plus pure CBV CSE to shader/dxil: add pack/unpack and Call folding peepholes plus pure CBV CSE 2026-12-06 03:27:47 +00:00
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 'pr/dxil-peepholes-cbv-cse:hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'hingeowl-pr/dxil-peepholes-cbv-cse'

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 'hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'hingeowl-pr/dxil-peepholes-cbv-cse'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'hingeowl-pr/dxil-peepholes-cbv-cse'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'Main'
git merge --squash 'hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'Main'
git merge --ff-only 'hingeowl-pr/dxil-peepholes-cbv-cse'
git switch 'Main'
git merge 'hingeowl-pr/dxil-peepholes-cbv-cse'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!515
No description provided.