Skip to content

GPU: hand-written replacements for translated shaders (VICTORY_SHADER_OVERRIDES) - #725

Open
KyleS98 wants to merge 1 commit into
fxceless:mainfrom
KyleS98:feat/shader-overrides
Open

KyleS98 wants to merge 1 commit into
fxceless:mainfrom
KyleS98:feat/shader-overrides

Conversation

@KyleS98

@KyleS98 KyleS98 commented Nov 25, 2026

Copy link
Copy Markdown

A small, opt-in mechanism for running a hand-written DXIL shader in place of the translator's output for a given shader. It's aimed at the handful of compute shaders that cost the most GPU time because of the generic translation (wave64 emulation on 32-lane hosts, lane-mask bookkeeping). A hand-written equivalent compiled by dxc can do the same work in less time, without changing anything else the host builds.

How it works

  • VICTORY_SHADER_OVERRIDES=<folder>: a shader whose console container hashes to <hash> (the same 16 hex digits that "first bind", "shader does not translate" and the GPU timing lines print) runs <folder>\<hash>.dxil instead of the translated code.
  • Only the code is replaced. The translation's root signature, user-data dwords, immediate samplers, root views and heap views are kept. So a replacement is written against the translation's own register layout, which its disassembly shows: victory translate --list with VICTORY_EMIT_DUMP=<dir>, then dxc -dumpbin.
  • Applied after the shader cache, so the cache keeps the translation and the folder can change between runs. It's looked up once per hash.
  • A file that isn't a DXIL container (wrong magic, wrong size, no DXIL part) is ignored with a warning, and the translation runs.
  • Nothing changes when the variable is unset. A README row documents the switch.

Testing

  • 3 unit tests (shader_override::tests): the container check accepts a DXIL part and refuses other parts and truncated files, and the lookup by hash in a folder finds a good file, ignores a bad one and handles a missing one. All pass.
  • cargo clippy -p victory-gpu --all-targets adds no new warnings.
  • Not yet exercised with a real replacement in-game. The first candidates I found by GPU timing turned out to be memory-bound, where a rewrite wouldn't help. I'll follow up with a measured replacement once I have one.

AI-assisted (Claude Code, Claude Opus 5.5). No game data attached.

🤖 Generated with Claude Code

…_OVERRIDES)

VICTORY_SHADER_OVERRIDES=<folder>: a shader whose console container
hashes to <hash> (the 16 hex digits runs name shaders by) runs the DXIL
container in <folder>\<hash>.dxil instead of the translator's code.

Only the code is replaced. The translation's root signature, user-data
dwords, immediate samplers, root views and heap views are kept, so a
replacement is written against the translation's own register layout
(its disassembly shows it: `victory translate --list` with
VICTORY_EMIT_DUMP, then `dxc -dumpbin`). The point is the shaders that
cost the most on the card for reasons of the generic translation (wave64
emulation, lane-mask bookkeeping): a hand-written equivalent compiled by
dxc can do the same work faster.

The replacement is applied after the shader cache (the cache keeps the
translation; the folder can change between runs) and looked up once per
hash. A file that is not a DXIL container is ignored with a warning and
the translation runs.

Three unit tests: the container check (accepts a DXIL part, refuses
others and truncated files) and the lookup by hash in a folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KyleS98
KyleS98 force-pushed the feat/shader-overrides branch from 6f018c4 to a59cfdd Compare November 25, 2026 06:32
@KyleS98

KyleS98 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto 8dd30ab. The only conflict was host_shader, which now passes &build() under the new cache key. The override is still applied after the cache lookup, so the cache keeps the translation itself.

In-game test of this branch (RTX 3090 Ti, Windows 11, diag build, retail title, Series X profile), done end to end with an identity replacement:

  • I dumped the translation of cfd83392ec9ae408 (indirect_light_probes:CS_Primary_GatherCopy, which runs every world frame) with this build (victory translate --list with VICTORY_EMIT_DUMP), and put it in a folder as cfd83392ec9ae408.dxil.
  • With VICTORY_SHADER_OVERRIDES=<that folder>, a 300 s run logs shader override: the replacement runs hash=cfd83392ec9ae408. It reaches the world (≈5,000 draws per frame, 4.0 fps on this base) and renders the cell normally, with no crash or device loss.
  • Unit tests: cargo test -p victory-gpu --lib shader_override passes 3 of 3.

That shows the replacement path loads a container, keeps the translation's bindings, and runs on a card. A replacement that actually differs from its translation, measured for speed, will follow separately.

AI-assisted (Claude Code, Claude Opus 5.5). No game data attached.

@KyleS98
KyleS98 force-pushed the feat/shader-overrides branch from a59cfdd to 94da4cf Compare November 25, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant