Shaders: refuse the image instructions DXIL has no form of #2068

Open
0xkn0wh3r3 wants to merge 3 commits from upstream-pr/2070 into main
0xkn0wh3r3 commented 2026-11-25 04:21:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T04:21:35Z.


The problem

Four kinds of console image instruction were translated into DXIL operations that the validator rejects, and that a driver may refuse or run wrongly. DXIL has no form of them, so refusing them is the right outcome:

instruction validator error
a gather (image_gather4_lz, _l, _lz_o, _l_o) from a 1D or 3D image "gather requires resource declared as texture/2D/Cube/2DArray/CubeArray"
a gather with offsets (_o) from a cube or cube array "out of bound offset must be undef"
a comparison sample (image_sample_c_lz and the like) of a 3D image "samplec requires resource declared as texture1D/2D/Cube/1DArray/2DArray/CubeArray"
image_load_mip from a UAV, which is one level of its resource "uav load don't support mipLevel/sampleIndex" (and the typed-UAV-load flag was left out, so "Flags must match usage" too)

Found by validating random programs (the generator of #1335, with a validation pass, validator 1.6): 5 of 16,207 programs that translated out of 200,000. The 3D comparison sample (second commit) was found over 2,000,000 more random programs. With this and #2056 every one of them validates.

The fix

In emit/lower.rs, each case is now refused before anything is emitted, as the gathers DXIL cannot do already are ("a gather with implicit level", "a gather of several channels"):

  • gathers only from 2D textures, cubes and their arrays: otherwise "a gather from a 1D or 3D image";
  • gathers with offsets only from the 2D ones: otherwise "a gather with offsets from a cube";
  • comparison samples of every kind but 3D: otherwise "a comparison sample of a 3D image";
  • image_load_mip not from a UAV: otherwise "a load at a mip level from a UAV".

Testing

  • New test emit::lower::tests::image_instructions_dxil_lacks_are_refused. It lowers each refused instruction with its result written to LDS, so the refusal ends the translation, and checks the refusal reason. Next to them, the 2D gather, the 2D comparison sample and the plain UAV load still lower. It fails on main, and with any one of the new checks removed.
  • cargo test --release -p victory-shader --lib on an RTX 5070 Ti: 245 passed; the 3 failures (emit::stride_tests::* x2, emit::synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on main on this GPU (#1835).
  • cargo clippy -p victory-shader --all-targets --features host: clean.

Not covered

Not checked against title shaders (no game data here); real compilers are unlikely to emit these forms.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5485119423 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T04:21:35Z. --- ## The problem Four kinds of console image instruction were translated into DXIL operations that the validator rejects, and that a driver may refuse or run wrongly. DXIL has no form of them, so refusing them is the right outcome: | instruction | validator error | |---|---| | a gather (`image_gather4_lz`, `_l`, `_lz_o`, `_l_o`) from a 1D or 3D image | "gather requires resource declared as texture/2D/Cube/2DArray/CubeArray" | | a gather with offsets (`_o`) from a cube or cube array | "out of bound offset must be undef" | | a comparison sample (`image_sample_c_lz` and the like) of a 3D image | "samplec requires resource declared as texture1D/2D/Cube/1DArray/2DArray/CubeArray" | | `image_load_mip` from a UAV, which is one level of its resource | "uav load don't support mipLevel/sampleIndex" (and the typed-UAV-load flag was left out, so "Flags must match usage" too) | Found by validating random programs (the generator of #1335, with a validation pass, validator 1.6): 5 of 16,207 programs that translated out of 200,000. The 3D comparison sample (second commit) was found over 2,000,000 more random programs. With this and #2056 every one of them validates. ## The fix In `emit/lower.rs`, each case is now refused before anything is emitted, as the gathers DXIL cannot do already are ("a gather with implicit level", "a gather of several channels"): - gathers only from 2D textures, cubes and their arrays: otherwise "a gather from a 1D or 3D image"; - gathers with offsets only from the 2D ones: otherwise "a gather with offsets from a cube"; - comparison samples of every kind but 3D: otherwise "a comparison sample of a 3D image"; - `image_load_mip` not from a UAV: otherwise "a load at a mip level from a UAV". ## Testing - New test `emit::lower::tests::image_instructions_dxil_lacks_are_refused`. It lowers each refused instruction with its result written to LDS, so the refusal ends the translation, and checks the refusal reason. Next to them, the 2D gather, the 2D comparison sample and the plain UAV load still lower. It fails on `main`, and with any one of the new checks removed. - `cargo test --release -p victory-shader --lib` on an RTX 5070 Ti: 245 passed; the 3 failures (`emit::stride_tests::*` x2, `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`) fail the same way on `main` on this GPU (#1835). - `cargo clippy -p victory-shader --all-targets --features host`: clean. ## Not covered Not checked against title shaders (no game data here); real compilers are unlikely to emit these forms.
DenRakEiw commented 2026-11-25 04:31:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:31:08Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib image_instructions_dxil_lacks_are_refused — passed
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean explicit refusal of gather and UAV image load forms that DXIL lacks, with targeted regression test coverage. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051882788 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#pullrequestreview-6051882788). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:31:08Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib image_instructions_dxil_lacks_are_refused` — passed - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean explicit refusal of gather and UAV image load forms that DXIL lacks, with targeted regression test coverage. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 04:33:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:33:53Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. Gathers and UAV loads DXIL has no form of refused (+1 test) — explicit rejection instead of silent miscompile; good defensive lowering.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051901684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#pullrequestreview-6051901684). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:33:53Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 145 passed / 0 failed / 2 ignored. Gathers and UAV loads DXIL has no form of refused (+1 test) — explicit rejection instead of silent miscompile; good defensive lowering.
jeremygold02 commented 2026-11-25 05:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:25:40Z.


Triage verdict — Ready on the reviewed DXIL boundaries (0cd10cd)

Evidence

  • @0xkn0wh3r3 refuses gathers from unsupported dimensions, cube gathers with offsets, and mip-level loads from UAVs before emitting DXIL the validator rejects. #2056 addresses a separate integer-flag problem from the same generator. Lowering guards · DXIL gather rules

Checks and limits

  • The focused exact-head regression passed. A disposable extension required DXIL validation for 2D and 2D-array gathers with and without offsets, a cube gather without offsets, and a 2D SRV mip load. All validated. The added 3D negative control returned the expected refusal.
  • These are translation and validation results. No GPU draw or dispatch was required.

Next step

  • Keep the guards. The positive array, cube, and SRV controls would be useful permanent coverage if the image lowering is extended.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152832486 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#issuecomment-7152832486). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:25:40Z. --- **Triage verdict — Ready on the reviewed DXIL boundaries** (`0cd10cd`) **Evidence** - @0xkn0wh3r3 refuses gathers from unsupported dimensions, cube gathers with offsets, and mip-level loads from UAVs before emitting DXIL the validator rejects. #2056 addresses a separate integer-flag problem from the same generator. [Lowering guards](https://github.com/Marvisak/VIctory/blob/0cd10cdafb5693cef90cd34f2a76a8a4fd9ab3ef/crates/victory-shader/src/emit/lower.rs#L8225-L8282) · [DXIL gather rules](https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/DxilValidation/DxilValidation.cpp#L450-L499) **Checks and limits** - The focused exact-head regression passed. A disposable extension required DXIL validation for 2D and 2D-array gathers with and without offsets, a cube gather without offsets, and a 2D SRV mip load. All validated. The added 3D negative control returned the expected refusal. - These are translation and validation results. No GPU draw or dispatch was required. **Next step** - Keep the guards. The positive array, cube, and SRV controls would be useful permanent coverage if the image lowering is extended. This verification was AI-assisted.
upstream-sync changed title from [PR #2070] Shaders: refuse the gathers and UAV loads DXIL has no form of to [PR #2070] Shaders: refuse the image instructions DXIL has no form of 2026-11-25 06:02:15 +00:00
sinan-cmyk commented 2026-11-25 10:07:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:16:10Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 01a09f6c onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158101956 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#issuecomment-7158101956). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:16:10Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 01a09f6c onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 11:05:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:26:15Z.


Automated triage for the maintainers.

Merge candidate (re-checked on 1f14099). The checks in crates/victory-shader/src/emit/lower.rs (image lowering) are unchanged. They refuse four forms:

  • gathers from anything but DXIL kinds 2/5/7/9 (2D, cube and their arrays);
  • gathers with offsets from a cube;
  • comparison samples of kind 4 (3D);
  • image_load_mip from a UAV.

The kind numbers match the dim -> DXIL kind mapping in the same function and DXIL's resource kinds. The only change is that the test now lives in its own file, emit/lower/tests/image_refusals.rs, loaded by mod image_refusals; inside lower.rs's inline mod tests. The test checks each refusal reason and that the 2D gather, the 2D comparison sample and the plain UAV load still lower. A tester reports it passing on RDNA2 and RDNA3 at the previous head.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159693308 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#issuecomment-7159693308). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:26:15Z. --- <!-- victory-triage v1 head=1f1409954e3a2c8cb974fb47e65392e479e97186 verdict=merge-candidate at=2026-11-26T01:20:46Z --> Automated triage for the maintainers. **Merge candidate (re-checked on `1f14099`).** The checks in `crates/victory-shader/src/emit/lower.rs` (image lowering) are unchanged. They refuse four forms: - gathers from anything but DXIL kinds 2/5/7/9 (2D, cube and their arrays); - gathers with offsets from a cube; - comparison samples of kind 4 (3D); - `image_load_mip` from a UAV. The kind numbers match the `dim` -> DXIL kind mapping in the same function and DXIL's resource kinds. The only change is that the test now lives in its own file, `emit/lower/tests/image_refusals.rs`, loaded by `mod image_refusals;` inside `lower.rs`'s inline `mod tests`. The test checks each refusal reason and that the 2D gather, the 2D comparison sample and the plain UAV load still lower. A tester reports it passing on RDNA2 and RDNA3 at the previous head. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
bvtterbroot commented 2026-11-25 19:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bvtterbroot on 2026-11-25T18:40:14Z.


AMD check at 01a09f6 (base 940d32f), on an RDNA3 and an RDNA2 GPU:

  • Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware adapter of the shader test host with a local patch that is not part of this PR. WARP runs in each pass as well.
  • cargo test -p victory-shader -p victory-gpu --locked: 391 passed, 0 failed, 5 ignored, on both GPUs. That includes its new test (image_instructions_dxil_lacks_are_refused).

Synthetic tests only, no game files. Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171230021 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#issuecomment-7171230021). Originally posted by [bvtterbroot](https://github.com/bvtterbroot) on 2026-11-25T18:40:14Z. --- AMD check at `01a09f6` (base `940d32f`), on an RDNA3 and an RDNA2 GPU: - Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware adapter of the shader test host with a local patch that is not part of this PR. WARP runs in each pass as well. - `cargo test -p victory-shader -p victory-gpu --locked`: **391 passed, 0 failed**, 5 ignored, on both GPUs. That includes its new test (`image_instructions_dxil_lacks_are_refused`). Synthetic tests only, no game files. _Tested with AI assistance (Claude Code)._
fuzeofficlal commented 2026-11-26 19:06:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:06:51Z.

Review: APPROVED


Verified locally merged onto origin/main (63bcca43, Windows 11 x64, Rust 1.98.1 MSVC, RTX 5090 & WARP + dxil.dll):

  • cargo test --locked -p victory-shader --lib emit::lower::tests:: (VICTORY_WARP=0 and VICTORY_WARP=1) — 34 passed, 0 failed on both adapters (including image_refusals::image_instructions_dxil_lacks_are_refused)
  • cargo test --locked -p victory-shader --lib constant_color_validates — 1 passed, 0 failed
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) — 0 warnings
  • rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower/tests/image_refusals.rs — clean
  • cargo xtask policy — ok (192 files ok)

Review notes

  • All four guards (3D comparison sample, gathers on non-2D/cube resource kinds, cube/cube-array gathers with offset operands, and mip-level loads from UAVs) match DXIL validation rules without falsely rejecting legal SM 6.6 image operations; all seven MIMG encodings in image_refusals.rs decode as documented, and emit/lower.rs sits at 521,420 B (< 524,288 B).
<!-- greyfinch-sync:Marvisak/VIctory:review:6079319694 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2070#pullrequestreview-6079319694). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:06:51Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`63bcca43`, Windows 11 x64, Rust 1.98.1 MSVC, RTX 5090 & WARP + `dxil.dll`): - `cargo test --locked -p victory-shader --lib emit::lower::tests::` (`VICTORY_WARP=0` and `VICTORY_WARP=1`) — **34 passed, 0 failed** on both adapters (including `image_refusals::image_instructions_dxil_lacks_are_refused`) - `cargo test --locked -p victory-shader --lib constant_color_validates` — **1 passed, 0 failed** - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings - `rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower/tests/image_refusals.rs` — clean - `cargo xtask policy` — ok (`192 files ok`) ### Review notes - All four guards (3D comparison sample, gathers on non-2D/cube resource kinds, cube/cube-array gathers with offset operands, and mip-level loads from UAVs) match DXIL validation rules without falsely rejecting legal SM 6.6 image operations; all seven MIMG encodings in `image_refusals.rs` decode as documented, and `emit/lower.rs` sits at 521,420 B (< 524,288 B).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2070:upstream-pr/2070'
git switch 'upstream-pr/2070'

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 'upstream-pr/2070'
git switch 'upstream-pr/2070'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2070'
git switch 'upstream-pr/2070'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2070'
git switch 'main'
git merge --squash 'upstream-pr/2070'
git switch 'main'
git merge --ff-only 'upstream-pr/2070'
git switch 'main'
git merge 'upstream-pr/2070'
git push origin 'main'
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.

Reference
Marvisak/VIctory!2068
No description provided.