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

Closed
Luislariosss wants to merge 1 commit from upstream-pr/1948 into main
Luislariosss commented 2026-11-25 01:38:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-25T01:38:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6595134619 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1948). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-25T01:38:12Z. --- ### 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).
catminou4 commented 2026-11-25 04:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:14:07Z.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6051314006 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1948#pullrequestreview-6051314006). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:14:07Z. **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. 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).
Marvisak commented 2026-11-25 09:06:12 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156888462 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1948#issuecomment-7156888462). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:19:40Z. --- <!-- victory-triage v1 head=0a4d90bbbe19e35d029c465173dd697f9b1d97d6 verdict=needs-work at=2026-11-25T08:19:31Z --> 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](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 12:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:12:05Z.


Offline measurement on a retail dump

Result: no count change against main.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160729071 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1948#issuecomment-7160729071). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:12:05Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 0a4d90bb 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).
upstream-sync closed this pull request 2026-11-25 21:02:10 +00:00
Luislariosss commented 2026-11-25 21:03:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-25T20:10:02Z.


Withdrawing this, and thank you for the careful read — you are right on the point that matters here.

  • The runtime never validates, the container hash is ours, and SM 6.6 takes derivatives in compute, so those compute programs are not invalid on the host; the 1.6 validator's refusal is a validator-version artifact. image_addresses_of_16_bits_and_clamps is the proof, and this PR deleted its biased case. I should not have turned working compute programs into refusals on that basis, and sinan-cmyk's measurement (no change in the validated count) shows the PR did not buy anything on the offline side either.

What I do have, for the record, is hardware data on one AMD card (RX 9060 XT, RDNA4, 15.2 GB, amdxc64.dll 32.0.32015.7029), because that is the case I was really chasing:

  • The driver's shader compiler faults (0xc0000005 inside amdxc64.dll, read 0x8) on some of the ~230 translated compute programs that use implicit-derivative sampling, and the process dies 40–90 s into the world.
  • Lowering them to SampleGrad with quad gradients (valid at 1.6, accepted by the validator) did not help: two runs died at the same address after ~50 s. So the problem on that card is the programs themselves reaching the compiler, not which sample opcode they use.
  • Refusing them keeps the world running for 5+ minutes in every run I did that way.

So the AMD case is not something this PR should decide. I will handle it as an opt-in safety net in #1936 (off by default, as you suggested) and keep the translation of these programs untouched. Closing this one.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173280087 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1948#issuecomment-7173280087). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-25T20:10:02Z. --- Withdrawing this, and thank you for the careful read — you are right on the point that matters here. - The runtime never validates, the container hash is ours, and SM 6.6 takes derivatives in compute, so those compute programs are not invalid on the host; the 1.6 validator's refusal is a validator-version artifact. `image_addresses_of_16_bits_and_clamps` is the proof, and this PR deleted its biased case. I should not have turned working compute programs into refusals on that basis, and sinan-cmyk's measurement (no change in the validated count) shows the PR did not buy anything on the offline side either. What I do have, for the record, is hardware data on one AMD card (RX 9060 XT, RDNA4, 15.2 GB, `amdxc64.dll` 32.0.32015.7029), because that is the case I was really chasing: - The driver's shader compiler faults (`0xc0000005` inside `amdxc64.dll`, read 0x8) on some of the ~230 translated compute programs that use implicit-derivative sampling, and the process dies 40–90 s into the world. - Lowering them to `SampleGrad` with quad gradients (valid at 1.6, accepted by the validator) did **not** help: two runs died at the same address after ~50 s. So the problem on that card is the programs themselves reaching the compiler, not which sample opcode they use. - Refusing them keeps the world running for 5+ minutes in every run I did that way. So the AMD case is not something this PR should decide. I will handle it as an opt-in safety net in #1936 (off by default, as you suggested) and keep the translation of these programs untouched. Closing this one. *AI-assisted.*

Pull request closed

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!1946
No description provided.