GPU: an opt-in gate refuses a translated shader the DXIL validator rejects #1936

Open
github-bot wants to merge 1 commit from github-bot/gh-1936 into main AGit
Owner

@⁠Luislariosss on GitHub · 2026-11-25 01:13 UTC · original
Luislariosss:gpu/validate-translated-dxil → main · +301 −24 · 5 files · 1 commits · open

Why

Translated shaders reach D3D12 pipeline creation unvalidated, by design (emit/validator.rs: the container hash is ours, D3D12 accepts it). On one AMD card that is not free: the driver's shader compiler (amdxc64.dll) can fault (0xc0000005) on some translated programs, and the whole process dies 40-90 s into the world. A way to make the world survive is to drop the programs the official validator rejects before they reach the driver.

Running the validator over one title's shader pack rejects ~800 programs (736 compute: the 1.6 validator's "incompatible with the shader stage", which for compute is Sample/SampleBias at validator version 1.6; 72 mesh: the 32 KiB output budget, see #1961). Whether those programs are really invalid on the host is another question (the compute ones are not: the runtime accepts them, and #1948, now closed, was wrong to treat them as invalid). What matters here is only that on this card the driver's compiler faults on them and that refusing them keeps the run alive.

What (revised after the triage: the gate is now opt-in)

VICTORY_VALIDATE=1 turns on a gate in shader_cache::host_shader: each translation is validated once with dxil.dll and a rejection becomes a cached refusal with its reason (the DXIL validator rejects it: <first specific line>). Refusals already have a path: cached as VSHE + reason, logged by pipeline.rs with stage and hash, draws dropped. Off by default: no dxil.dll is loaded, nothing is keyed, nothing changes.

  • The validator lives in a thread_local, loaded on first use (Send, not Sync).
  • The cache key (and the pipeline library's tag) take the validator's identity (dll path, size, last write), so a cache filled without the gate is not served with it and the reverse. Swapping dxil.dll invalidates the shader cache and the pipeline library; that is intended and documented.
  • A missing dxil.dll with the gate on warns once and translates ungated.
  • A refusals count joins the periodic shader-cache line (rejected) and the pipeline-library summary.
  • first_specific_line (in emit/validator.rs) is shared by the gate and by translate --validate, which used to bucket by the generic "See other errors" summary.

Evidence on hardware

RX 9060 XT (RDNA4), amdxc64.dll 32.0.32015.7029, Windows 11, empty cache each time. With the gate on, five runs reached the world and stayed 5+ minutes with no 0xc0000005 from the compiler. Without it, the same build died in the compiler 40-90 s into the world. Lowering the compute Samples to SampleGrad instead did not help (two runs died at the same address after ~50 s), so the faults follow those programs, not the sample opcode. I have not run this on NVIDIA or Intel.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant: clean.
  • cargo test --workspace --locked: no failures (one unrelated frame test failed once and passed on re-run).
  • Tests: key changes with the validator identity and is stable for the same one; a refusal survives the encode/decode round trip and is a hit; first_specific_line (4 cases); with the DLL present, an invalid buffer is refused and then served from the cache.

No shader bytes, hashes or program names from any title (asset policy).

**@⁠Luislariosss** on GitHub · 2026-11-25 01:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1936) `Luislariosss:gpu/validate-translated-dxil` → `main` · +301 −24 · 5 files · 1 commits · open ### Why Translated shaders reach D3D12 pipeline creation unvalidated, by design (`emit/validator.rs`: the container hash is ours, D3D12 accepts it). On one AMD card that is not free: the driver's shader compiler (`amdxc64.dll`) can fault (`0xc0000005`) on some translated programs, and the whole process dies 40-90 s into the world. A way to make the world survive is to drop the programs the official validator rejects before they reach the driver. Running the validator over one title's shader pack rejects ~800 programs (736 compute: the 1.6 validator's "incompatible with the shader stage", which for compute is `Sample`/`SampleBias` at validator version 1.6; 72 mesh: the 32 KiB output budget, see #1961). Whether those programs are really invalid on the host is another question (the compute ones are not: the runtime accepts them, and #1948, now closed, was wrong to treat them as invalid). What matters here is only that on this card the driver's compiler faults on them and that refusing them keeps the run alive. ### What (revised after the triage: the gate is now opt-in) `VICTORY_VALIDATE=1` turns on a gate in `shader_cache::host_shader`: each translation is validated once with `dxil.dll` and a rejection becomes a cached refusal with its reason (`the DXIL validator rejects it: <first specific line>`). Refusals already have a path: cached as `VSHE` + reason, logged by `pipeline.rs` with stage and hash, draws dropped. **Off by default**: no `dxil.dll` is loaded, nothing is keyed, nothing changes. - The validator lives in a `thread_local`, loaded on first use (`Send`, not `Sync`). - The cache key (and the pipeline library's tag) take the validator's identity (dll path, size, last write), so a cache filled without the gate is not served with it and the reverse. Swapping `dxil.dll` invalidates the shader cache and the pipeline library; that is intended and documented. - A missing `dxil.dll` with the gate on warns once and translates ungated. - A refusals count joins the periodic shader-cache line (`rejected`) and the pipeline-library summary. - `first_specific_line` (in `emit/validator.rs`) is shared by the gate and by `translate --validate`, which used to bucket by the generic "See other errors" summary. ### Evidence on hardware RX 9060 XT (RDNA4), `amdxc64.dll` 32.0.32015.7029, Windows 11, empty cache each time. With the gate on, five runs reached the world and stayed 5+ minutes with no `0xc0000005` from the compiler. Without it, the same build died in the compiler 40-90 s into the world. Lowering the compute `Sample`s to `SampleGrad` instead did not help (two runs died at the same address after ~50 s), so the faults follow those programs, not the sample opcode. I have not run this on NVIDIA or Intel. ### Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant: clean. - `cargo test --workspace --locked`: no failures (one unrelated `frame` test failed once and passed on re-run). - Tests: key changes with the validator identity and is stable for the same one; a refusal survives the encode/decode round trip and is a hit; `first_specific_line` (4 cases); with the DLL present, an invalid buffer is refused and then served from the cache. No shader bytes, hashes or program names from any title (asset policy).
Translated shaders reach D3D12 pipeline creation unchecked, because the DXIL carries the container hash we compute ourselves. On one AMD card some translated compute programs (programs the stage does not allow, meshes whose output is too large) make the driver's compiler fault and kill the process.

With VICTORY_VALIDATE=1, host_shader runs dxil.dll's validator on a copy of each translation and refuses it with the validator's first specific error line (shared with the offline batch as emit::validator::first_specific_line). Refusals are cached with their reason like any other, so the offline batch (translate --cache) and the runtime share them. With the gate on, the world survives 5+ minutes on that card.

It is off by default and opt-in on purpose: the gate loads external code (dxil.dll) into the game process, and the validator is otherwise for tests and the offline tool. The validator is per thread (Send, not Sync); a missing dxil.dll with the gate on warns once and translates ungated. The DLL's path, size and modification time are part of the cache key and the pipeline library tag, so swapping dxil.dll invalidates the shader cache and the library, which is intended. The periodic shader line and the library summary count the refusals.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:19 +00:00
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-25 01:29 UTC · original

First end-to-end run of this branch, on hardware (RX 9060 XT, RDNA4, amdxc64.dll 32.0.32015.7029, Windows 11 26200), built on main 42363ab with dxil.dll from DXC 1.9.2609.5 via VICTORY_DXIL, empty shader cache, no VICTORY_SKIP_PIPELINES:

  • Reached the world and stayed there about 5 min 40 s until the harness ended the run (killed: True). No 0xc0000005, no device removal, no 0x887A… exit.
  • Without the gate, the same machine and same build died 42–90 s into the world in the runs without a skip-list; the previous best (with three hashes skipped by hand) was 4 min 38 s.
  • The gate refused 223 distinct compute programs during that run, each logged by the existing pipeline.rs line with stage, hash and the reason the DXIL validator rejects it: ….

One limit to be clear about: that run ended with a flood of E_OUTOFMEMORY (0x8007000E) warnings on small host-visible buffers (about 1 min 45 s after entering the world, with a 47.2 GB commit limit), so the world was running degraded. That is host memory, not the gate, and I am measuring it separately.

Cause of the compute rejections, found while testing this: the translator declares validator version 1.6 (emit/shader.rs), and for versions below 1.8 DXC treats Sample/SampleBias (and the other derivative opcodes) as pixel-only. emit/lower.rs already limits image_sample_c and image_get_lod to pixel shaders but emits image_sample/image_sample_b in any stage, so those compute and mesh programs are invalid by construction. That is why the validator text names no rule. I will send that as a separate change; this PR stays the safety net.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1936#issuecomment-7149602039) First end-to-end run of this branch, on hardware (RX 9060 XT, RDNA4, `amdxc64.dll` 32.0.32015.7029, Windows 11 26200), built on `main` `42363ab` with `dxil.dll` from DXC 1.9.2609.5 via `VICTORY_DXIL`, empty shader cache, no `VICTORY_SKIP_PIPELINES`: - Reached the world and stayed there about **5 min 40 s** until the harness ended the run (`killed: True`). No `0xc0000005`, no device removal, no `0x887A…` exit. - Without the gate, the same machine and same build died 42–90 s into the world in the runs without a skip-list; the previous best (with three hashes skipped by hand) was 4 min 38 s. - The gate refused **223 distinct compute programs** during that run, each logged by the existing `pipeline.rs` line with stage, hash and the reason `the DXIL validator rejects it: …`. One limit to be clear about: that run ended with a flood of `E_OUTOFMEMORY (0x8007000E)` warnings on small host-visible buffers (about 1 min 45 s after entering the world, with a 47.2 GB commit limit), so the world was running degraded. That is host memory, not the gate, and I am measuring it separately. Cause of the compute rejections, found while testing this: the translator declares validator version 1.6 (`emit/shader.rs`), and for versions below 1.8 DXC treats `Sample`/`SampleBias` (and the other derivative opcodes) as pixel-only. `emit/lower.rs` already limits `image_sample_c` and `image_get_lod` to pixel shaders but emits `image_sample`/`image_sample_b` in any stage, so those compute and mesh programs are invalid by construction. That is why the validator text names no rule. I will send that as a separate change; this PR stays the safety net. *AI-assisted.*
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 01:44 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 7dc12f3. victory-shader: 243 passed, with only #1744's 3 NVIDIA failures. victory-gpu: 143 passed, 2 failed, with only the two NVIDIA heap-cap failures main also has (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 01:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1936#issuecomment-7149906878) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `7dc12f3`. `victory-shader`: 243 passed, with only #1744's 3 NVIDIA failures. `victory-gpu`: 143 passed, 2 failed, with only the two NVIDIA heap-cap failures `main` also has (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`). Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:20 UTC · original · edited 2026-11-26 01:24 UTC

Automated triage for the maintainers.

Needs work: this needs the maintainer's decision. The code points from the last triage are addressed: the gate in shader_cache::host_shader is now opt-in (VICTORY_VALIDATE=1, via validator_path), off by default with no dxil.dll loaded; first_specific_line in emit/validator.rs is shared by the gate and translate --validate; the module docs say it is an opt-in run-time gate that loads external code; and the doc comment on validator_id says swapping dxil.dll invalidates the shader cache and the pipeline library. One commit, merges cleanly.

What is left is a decision for the maintainer: with the switch on, dxil.dll (from VICTORY_DXIL, the Windows SDK or the DLL search path) is loaded into the game process at run time, and rejected programs have their draws dropped. The root cause of most rejections (image_sample/image_sample_b lowered outside pixel shaders while declaring validator 1.6) is still meant to be fixed separately, in the lowering.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1936#issuecomment-7156899041) · edited 2026-11-26 01:24 UTC <!-- victory-triage v1 head=f9b9b3442acf696d2cd69ebb0d8d0059ea683c9b verdict=needs-work at=2026-11-26T01:24:03Z --> Automated triage for the maintainers. **Needs work: this needs the maintainer's decision.** The code points from the last triage are addressed: the gate in `shader_cache::host_shader` is now opt-in (`VICTORY_VALIDATE=1`, via `validator_path`), off by default with no `dxil.dll` loaded; `first_specific_line` in `emit/validator.rs` is shared by the gate and `translate --validate`; the module docs say it is an opt-in run-time gate that loads external code; and the doc comment on `validator_id` says swapping `dxil.dll` invalidates the shader cache and the pipeline library. One commit, merges cleanly. What is left is a decision for the maintainer: with the switch on, `dxil.dll` (from `VICTORY_DXIL`, the Windows SDK or the DLL search path) is loaded into the game process at run time, and rejected programs have their draws dropped. The root cause of most rejections (`image_sample`/`image_sample_b` lowered outside pixel shaders while declaring validator 1.6) is still meant to be fixed separately, in the lowering. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
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/1936/head:github-bot/gh-1936'
git switch 'github-bot/gh-1936'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1936'
git switch 'github-bot/gh-1936'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1936'
git switch 'github-bot/gh-1936'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1936'
git switch 'main'
git merge --squash 'github-bot/gh-1936'
git switch 'main'
git merge --ff-only 'github-bot/gh-1936'
git switch 'main'
git merge 'github-bot/gh-1936'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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
github/Marvisak--VIctory!1936
No description provided.