[pr-diagnostics][shaders] Opt-in external shader override and targeted DXIL dump loader #3

Open
Nyutt wants to merge 1 commit from nyutt/shader-overrides into rebar AGit
First-time contributor

What it changes

  • The problem on rebar: investigating or prototyping per-shader GPU optimizations and visual fixes (roadmap step 7) currently requires modifying the translator and invalidating the entire shader cache on every iteration.

This adds an opt-in, off-by-default external shader override and targeted dump loader strictly outside the repository (ensure_outside_repo rejects any path inside a Darner checkout):

  • DARNER_SHADER_OVERRIDE_DIR=<dir>: replaces HostShader::dxil after the normal shader-cache lookup (never polluting or invalidating the standard cache) from <hash16>.dxil, <hash16>.cso, or <hash16>.hlsl (compiled via dxcompiler.dll with SM 6.6, -enable-16bit-types, #include support in <dir>, optional // darner-entry: / // darner-target: / // darner-args: directives, cached in <dir>/.compiled/). Optional <hash16>.views sidecar overrides ray_queries.tlas_srvs and root_srvs on Darner's t230..=t241 slots.
  • DARNER_SHADER_DUMP_DIR=<dir> (+ optional DARNER_SHADER_DUMP_ONLY=<hash16,...>): dumps translated <hash16>.dxil, <hash16>.txt (binding metadata), and <hash16>.views (TLAS bindings) once per matching shader.

How it was tested

  • Tested revision: 540f024 (rebased onto lucid/rebar 48b9f9a)
  • Commands and results:
    • cargo test --locked --offline -p darner-gpu --lib shader_override: 7 passed, 0 failed (covers repo-path rejection, .dxil override keeping metadata, invalid-bytes fallback, HLSL header directives, targeted dump filtering, .views TLAS sidecar, and live DXC .hlsl + #include compilation with .compiled/ caching).
    • cargo clippy --locked --offline -p darner-gpu --lib --tests -- -D warnings: 0 warnings in all 4 touched files (15 pre-existing clippy errors on lucid/rebar in untouched files).
    • cargo xtask policy: asset policy: 576 files ok.
    • Release build (darner.exe, ThinLTO) succeeded cleanly.
  • Changes a default: no (both switches are off by default; zero overhead when unset).
  • Gates run on that revision: darner-gpu shader_override unit tests + cargo xtask policy.
  • Hardware dependence: general (DXC .hlsl compilation is Windows-only; .dxil/.cso works everywhere).
  • Coverage gaps: full workspace gates not run (pre-existing clippy errors on lucid/rebar).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). (Unit-tested including live DXC compilation and release build; off by default.)
  • This PR contains one change based on lucid/rebar.
  • 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 `rebar`: investigating or prototyping per-shader GPU optimizations and visual fixes (roadmap step 7) currently requires modifying the translator and invalidating the entire shader cache on every iteration. This adds an opt-in, off-by-default external shader override and targeted dump loader strictly outside the repository (`ensure_outside_repo` rejects any path inside a Darner checkout): - `DARNER_SHADER_OVERRIDE_DIR=<dir>`: replaces `HostShader::dxil` after the normal shader-cache lookup (never polluting or invalidating the standard cache) from `<hash16>.dxil`, `<hash16>.cso`, or `<hash16>.hlsl` (compiled via `dxcompiler.dll` with SM 6.6, `-enable-16bit-types`, `#include` support in `<dir>`, optional `// darner-entry:` / `// darner-target:` / `// darner-args:` directives, cached in `<dir>/.compiled/`). Optional `<hash16>.views` sidecar overrides `ray_queries.tlas_srvs` and `root_srvs` on Darner's `t230..=t241` slots. - `DARNER_SHADER_DUMP_DIR=<dir>` (+ optional `DARNER_SHADER_DUMP_ONLY=<hash16,...>`): dumps translated `<hash16>.dxil`, `<hash16>.txt` (binding metadata), and `<hash16>.views` (TLAS bindings) once per matching shader. ## How it was tested - Tested revision: `540f024` (rebased onto `lucid/rebar` `48b9f9a`) - Commands and results: - `cargo test --locked --offline -p darner-gpu --lib shader_override`: 7 passed, 0 failed (covers repo-path rejection, `.dxil` override keeping metadata, invalid-bytes fallback, HLSL header directives, targeted dump filtering, `.views` TLAS sidecar, and live DXC `.hlsl` + `#include` compilation with `.compiled/` caching). - `cargo clippy --locked --offline -p darner-gpu --lib --tests -- -D warnings`: 0 warnings in all 4 touched files (15 pre-existing clippy errors on `lucid/rebar` in untouched files). - `cargo xtask policy`: `asset policy: 576 files ok`. - Release build (`darner.exe`, ThinLTO) succeeded cleanly. - Changes a default: no (both switches are off by default; zero overhead when unset). - Gates run on that revision: `darner-gpu` `shader_override` unit tests + `cargo xtask policy`. - Hardware dependence: general (DXC `.hlsl` compilation is Windows-only; `.dxil`/`.cso` works everywhere). - Coverage gaps: full workspace gates not run (pre-existing clippy errors on `lucid/rebar`). ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). *(Unit-tested including live DXC compilation and release build; off by default.)* - [x] This PR contains one change based on `lucid/rebar`. - [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
Author
First-time contributor

End-to-end live in-game verification on cam-city60 (-Flight InGame, RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, Series X, 1080p->1440p, DLSS Quality, Frame Gen 2x, DARNER_HW_RT=1, 540f024):

  1. Targeted dump (PR3D) with DARNER_SHADER_DUMP_DIR=D:\darner-pr3-test + DARNER_SHADER_DUMP_ONLY=534b3645dd344ab2;fb515ca95d694c18;a55058c53fbc6406;7b2c3c1db2298f44;bd67937a6a9d342f — BENCH OK:
    • DARNER_SHADER_DUMP_DIR active dir=\\?\D:\darner-pr3-test only=Some(5)
    • dumped translated shader shader="7b2c3c1db2298f44" path=\\?\D:\darner-pr3-test\7b2c3c1db2298f44.dxil bytes=58172 (+ .txt binding summary).
  2. Live override (PR3O) with DARNER_SHADER_OVERRIDE_DIR=D:\darner-pr3-test — BENCH OK:
    • DARNER_SHADER_OVERRIDE_DIR active dir=\\?\D:\darner-pr3-test
    • shader override applied shader="7b2c3c1db2298f44" source=\\?\D:\darner-pr3-test\7b2c3c1db2298f44.dxil bytes=58172
    • Minor one-time pipeline compile on the first run for the overridden shader, 0 crashes, dropped_pf = 0.0, fps_med = 16.8.
  3. Switches OFF (PR30) on the same 540f024 build — BENCH OK, dropped_pf = 0.0, fps_med = 13.2.
End-to-end live in-game verification on `cam-city60` (`-Flight InGame`, RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, Series X, 1080p->1440p, DLSS Quality, Frame Gen 2x, `DARNER_HW_RT=1`, `540f024`): 1. **Targeted dump (`PR3D`)** with `DARNER_SHADER_DUMP_DIR=D:\darner-pr3-test` + `DARNER_SHADER_DUMP_ONLY=534b3645dd344ab2;fb515ca95d694c18;a55058c53fbc6406;7b2c3c1db2298f44;bd67937a6a9d342f` — `BENCH OK`: - `DARNER_SHADER_DUMP_DIR active dir=\\?\D:\darner-pr3-test only=Some(5)` - `dumped translated shader shader="7b2c3c1db2298f44" path=\\?\D:\darner-pr3-test\7b2c3c1db2298f44.dxil bytes=58172` (+ `.txt` binding summary). 2. **Live override (`PR3O`)** with `DARNER_SHADER_OVERRIDE_DIR=D:\darner-pr3-test` — `BENCH OK`: - `DARNER_SHADER_OVERRIDE_DIR active dir=\\?\D:\darner-pr3-test` - `shader override applied shader="7b2c3c1db2298f44" source=\\?\D:\darner-pr3-test\7b2c3c1db2298f44.dxil bytes=58172` - Minor one-time pipeline compile on the first run for the overridden shader, 0 crashes, `dropped_pf = 0.0`, `fps_med = 16.8`. 3. **Switches OFF (`PR30`)** on the same `540f024` build — `BENCH OK`, `dropped_pf = 0.0`, `fps_med = 13.2`.
Author
First-time contributor

Test report: external HLSL overrides, live in game (not a CI result)

Commit tested: 540f024 (feat/shader-overrides, on lucid/rebar 48b9f9a), release build. Hardware: RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, 31 GB RAM. Series X mode, 1080p→1440p DLSS Quality, DARNER_HW_RT=1, bench cam-city60 -Flight InGame, warm pipeline library.

What I did: used DARNER_SHADER_DUMP_DIR to dump translated programs, then used DARNER_SHADER_OVERRIDE_DIR to replace 15 hand-written compute programs with HLSL compiled live through dxcompiler.dll. The HLSL stays local and outside the repo (asset policy); nothing derived from the title is committed or attached here.

Results (one run per arm, not an AB/BA, so treat as indicative):

arm GPU ms/frame (card_lists_ms, median) fps_med (ab.py) dropped/frame failed PSOs
baseline, no override (2 runs) 28.3 – 29.3 15.1 0.0 0
15 compute overrides 24.4 (−4 ms, about −15 %) 17.6 0.0 0
37 overrides (15 + 22 ray-tracing/pixel) 24.7 15.5 1.0 2 graphics, 0x80070057
  • All 15 overrides were applied in game (shader override applied x15), 0 failed pipelines, 0 GPU errors.
  • Adding the 22 extra ray-tracing/pixel programs gave no further GPU gain and 2 graphics PSOs failed, so the 15-program set is the useful one.
  • worked_ms (CPU) is about 28–30 ms in this scene, so the route is CPU-bound and the 4 ms GPU saving only shows partly in fps. It should matter more when GPU-bound.
  • Not tested: visual comparison beyond eyeballing run 1, other scenes, other GPUs, a proper 2x2 AB/BA.

Overrides are opt-in and off by default; nothing changes for anyone who doesn't set the variables. Happy to run an AB/BA if wanted.

**Test report: external HLSL overrides, live in game (not a CI result)** Commit tested: `540f024` (`feat/shader-overrides`, on `lucid/rebar` `48b9f9a`), release build. Hardware: RTX 5070 Ti 16 GB, Ryzen 7 7800X3D, 31 GB RAM. Series X mode, 1080p→1440p DLSS Quality, `DARNER_HW_RT=1`, bench `cam-city60 -Flight InGame`, warm pipeline library. What I did: used `DARNER_SHADER_DUMP_DIR` to dump translated programs, then used `DARNER_SHADER_OVERRIDE_DIR` to replace 15 hand-written compute programs with HLSL compiled live through `dxcompiler.dll`. The HLSL stays local and outside the repo (asset policy); nothing derived from the title is committed or attached here. Results (one run per arm, **not** an AB/BA, so treat as indicative): | arm | GPU ms/frame (`card_lists_ms`, median) | fps_med (`ab.py`) | dropped/frame | failed PSOs | |---|---|---|---|---| | baseline, no override (2 runs) | 28.3 – 29.3 | 15.1 | 0.0 | 0 | | 15 compute overrides | 24.4 (−4 ms, about −15 %) | 17.6 | 0.0 | 0 | | 37 overrides (15 + 22 ray-tracing/pixel) | 24.7 | 15.5 | 1.0 | 2 graphics, `0x80070057` | - All 15 overrides were applied in game (`shader override applied` x15), 0 failed pipelines, 0 GPU errors. - Adding the 22 extra ray-tracing/pixel programs gave no further GPU gain and 2 graphics PSOs failed, so the 15-program set is the useful one. - `worked_ms` (CPU) is about 28–30 ms in this scene, so the route is CPU-bound and the 4 ms GPU saving only shows partly in fps. It should matter more when GPU-bound. - Not tested: visual comparison beyond eyeballing run 1, other scenes, other GPUs, a proper 2x2 AB/BA. Overrides are opt-in and off by default; nothing changes for anyone who doesn't set the variables. Happy to run an AB/BA if wanted.
This pull request has changes conflicting with the target branch.
  • crates/darner-gpu/src/hlsl.rs
  • crates/darner-gpu/src/shader_cache.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3/head:nyutt/shader-overrides'
git switch 'nyutt/shader-overrides'

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 'rebar'
git merge --no-ff 'nyutt/shader-overrides'
git switch 'nyutt/shader-overrides'
git rebase 'rebar'
git switch 'rebar'
git merge --ff-only 'nyutt/shader-overrides'
git switch 'nyutt/shader-overrides'
git rebase 'rebar'
git switch 'rebar'
git merge --no-ff 'nyutt/shader-overrides'
git switch 'rebar'
git merge --squash 'nyutt/shader-overrides'
git switch 'rebar'
git merge --ff-only 'nyutt/shader-overrides'
git switch 'rebar'
git merge 'nyutt/shader-overrides'
git push origin 'rebar'
Sign in to join this conversation.
No reviewers
No labels
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
Lucid/Darner!3
No description provided.