Skip to content

Shaders: derivative sampling is pixel-only at validator version 1.6 - #1948

Open
Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:shaders/non-pixel-sample
Open

Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:shaders/non-pixel-sample

Conversation

@Luislariosss

Copy link
Copy Markdown
Contributor

Why

The translator declares validator version 1.6 (emit/shader.rs). Before 1.8, DXC takes Sample, SampleBias, SampleCmp, CalculateLOD and the derivative ops as pixel-only. lower.rs already limited image_sample_c and image_get_lod to pixel shaders, but image_sample, image_sample_o and image_sample_b were emitted in any stage.

So a compute (or mesh) program using them is invalid DXIL by construction. The validator's text is the generic "Function uses features incompatible with the shader stage (cs)", with no line naming a rule, which is what hid the cause. Running the validator over one title's shader pack, this accounts for the compute class of rejections (735 programs on 42363ab). A minimal Texture2D.Sample in [numthreads(32,1,1)] compiled with dxc -validator-version 1.6 or 1.7 gives the same text, and 1.8 accepts it.

What

image_sample, image_sample_o and image_sample_b follow the same rule as image_sample_c: allowed when self.s.pixel, refused with the existing "does not translate" path otherwise. No new state. The comment says why, and that a later change could lower them to SampleGrad with gradients taken from quad lanes.

This does not make those programs render; it makes them refuse with a reason instead of reaching the driver as invalid DXIL (the runtime-side safety net for the same class is #1936).

Tests

  • New: all three ops in compute are refused with Unsupported naming the op; image_sample_lz in compute still lowers and validates.
  • New: all three still translate in a pixel program, and validate when dxil.dll is present.
  • Changed: image_addresses_of_16_bits_and_clamps had a "biased" program that ran image_sample_b in compute; it would now be refused, so that program and its cases are removed (comment points at the new test). The a16 bias address layout therefore has no compute coverage left; the pixel path only checks that it translates.
  • cargo test -p victory-shader --locked: 248 passed, 3 ignored (246 + 2 new on this machine's main).
  • cargo build --release -p victory --locked: clean.

No game data, hashes or program names are included (asset policy).

The translator declares validator version 1.6. At that version DXC
treats Sample, SampleBias, SampleCmp, CalculateLOD and the derivative
ops as pixel-only; 1.8 lifts that. image_sample_c and image_get_lod
were already gated on the pixel stage, but image_sample, image_sample_o
and image_sample_b were emitted in any stage, so wrapped compute (and
mesh) programs using them were rejected by the DXIL validator with the
generic "Function uses features incompatible with the shader stage"
message.

These three now follow the same rule: outside a pixel shader they
return the instruction's name as the refusal, reusing the path
image_sample_c already takes, so the program is reported as not
translatable with a reason instead of producing invalid DXIL. A later
change could lower them to SampleGrad with gradients derived through
QuadOp.

Tests: compute refuses the three samples (an explicit-level sample
still lowers) and a pixel program still translates and validates them.
image_addresses_of_16_bits_and_clamps lost its biased-sample program,
which exercised image_sample_b in compute; its gather and gradient
programs are unchanged.
@Luislariosss
Luislariosss force-pushed the shaders/non-pixel-sample branch from d3f09b2 to 0a4d90b Compare November 25, 2026 02:06

@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. Derivatives are pixel-only at validator version 1.6 (+1 test) — version-gated derivative validation; relates to #1065's DXIL 1.8 derivative compute work (already approved).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work.

The PR makes image_sample, image_sample_o and image_sample_b pixel-only in Lower (crates/victory-shader/src/emit/lower.rs, the MIMG op match). Outside pixel shaders they are now refused, and the change removes the compute case of image_addresses_of_16_bits_and_clamps that used them.

On main, that removed case is the evidence that compute works. image_addresses_of_16_bits_and_clamps (emit/valu_tests.rs) lowers an image_sample_b compute program without validation, with the comment "The 1.6 validator refuses implicit derivatives in compute (1.8 takes them); the host runs them". It then runs that program on the hardware adapter and on WARP and checks the selected levels for five bias values. The runtime never runs the validator: the container hash is ours, and pipeline accepts it. The module declares shader model 6.6, which supports derivatives in compute. So the change turns compute programs that work and are tested today (735 by the PR's own count) into refusals, and deletes the test that showed they work.

What would change the verdict:

  • Keep compute as it is, and keep the biased compute case in image_addresses_of_16_bits_and_clamps.
  • If there is a real problem in other stages, limit the refusal to them. Derivatives never work in vertex shaders. In mesh shaders they are an optional host feature (DerivativesInMeshAndAmplificationShadersSupported), so that case could check the feature.
  • Show evidence that those stages fail on the host, not only that the 1.6 validator rejects them.

CI: check passes.


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 0a4d90b 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.

740 programs that fail on both change their 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).

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.

4 participants