Skip to content

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

Open
0xkn0wh3r3 wants to merge 3 commits into
Marvisak:mainfrom
0xkn0wh3r3:shaders/refuse-gathers-and-uav-mip-loads-dxil-lacks
Open

0xkn0wh3r3 wants to merge 3 commits into
Marvisak:mainfrom
0xkn0wh3r3:shaders/refuse-gathers-and-uav-mip-loads-dxil-lacks

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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.

@jeremygold02

Copy link
Copy Markdown
Contributor

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

Evidence

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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.

@0xkn0wh3r3 0xkn0wh3r3 changed the title Shaders: refuse the gathers and UAV loads DXIL has no form of Shaders: refuse the image instructions DXIL has no form of Nov 25, 2026
@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 01a09f6 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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@bvtterbroot

Copy link
Copy Markdown
Contributor

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).

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 25, 2026
Three image instructions translated into DXIL operations the validator
rejects (and a driver may refuse, or run wrongly), where refusing them
is the right outcome:

- 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";
- `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).

They are now refused with those reasons, as the gathers DXIL cannot do
already are ("a gather with implicit level", "a gather of several
channels").

Found by validating random programs (the generator of Marvisak#1335, with a
validation pass, validator 1.6): 5 of 16,207 programs that translated
out of 200,000; with this and Marvisak#2056 every one of them validates. The new
test lowers each into LDS, so the refusal ends the translation, and the
2D gather and the plain UAV load next to them, which still lower; it
fails on `main`, and without either of the checks.
`image_sample_c_lz` and the other comparison samples (`sampleCmp`,
`sampleCmpLevelZero`) of a 3D image translated into a DXIL operation the
validator rejects ("samplec requires resource declared as texture1D/2D/
Cube/1DArray/2DArray/CubeArray"): D3D compares samples of every kind of
texture but 3D. They are now refused, as the other image forms DXIL has
no form of.

Found by the same random-program validation, over 2,000,000 more
programs: 3 of 164,934 that translated. The image test now also lowers
the same comparison sample of a 2D image, and refuses it of a 3D one (it
translates on `main`).
@0xkn0wh3r3
0xkn0wh3r3 force-pushed the shaders/refuse-gathers-and-uav-mip-loads-dxil-lacks branch from 01a09f6 to baf47b2 Compare November 25, 2026 22:59
On current main the test took lower.rs past the repository's 512 KiB
source-file limit (CI's policy check). It moves unchanged into
lower/tests/image_refusals.rs, a child of lower's test module, so it
keeps its helpers.
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants