Shaders: key immediate sampler slots by descriptor and comparison mode #1476

Merged
geiyiliyabumo merged 1 commit from upstream-pr/1477 into main 2026-11-25 00:17:46 +00:00
geiyiliyabumo commented 2026-11-24 18:18:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T18:18:17Z.


Summary

Fixes immediate/static sampler slot reuse when the same immediate descriptor words are used by both non-comparison (\image_sample) and comparison (\image_sample_c\ / \image_sample_c_lz) instructions in one shader (tracking issue #1242, \VIC-BT-009).

Previously, \Lower::resource_handle\ keyed \self.samplers\ only on the 4 descriptor words and set \self.s.cmp_samplers |= 1 << n\ after emitting handles. If a non-comparison sample ran first, its \dx.op.annotateHandle\ encoded \SamplerKind = 0\ (\14), while a later comparison sample flipped the slot bit so \dx.resources\ declared \SamplerKind = 1\ (\Comparison), producing invalid DXIL. It also performed an unchecked \1u64 << n\ shift.

Changes

  • \crates/victory-shader/src/emit/lower.rs: Key immediate sampler slots by (words, comparison), guard against >= 64\ static sampler slots before shifting \cmp_samplers, and set the comparison bit on allocation before emitting \sampler_handle.
  • \crates/victory-shader/src/emit/mod.rs: Add synthetic regression test \immediate_sampler_slots_distinguish_comparison_uses\ exercising \image_sample, \image_sample_c, and \image_sample_c_lz\ with one immediate descriptor and verifying two distinct \static_samplers\ (non-comparison and comparison) plus optional \dxil.dll\ validation when present.

Verification

  • \cargo test -p victory-shader --lib emit::: 50 passed, 0 failed, 1 ignored.
  • \cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • \cargo xtask policy: 154 files OK.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588491993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1477). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T18:18:17Z. --- ## Summary Fixes immediate/static sampler slot reuse when the same immediate descriptor words are used by both non-comparison (\image_sample\) and comparison (\image_sample_c\ / \image_sample_c_lz\) instructions in one shader (tracking issue #1242, \VIC-BT-009\). Previously, \Lower::resource_handle\ keyed \self.samplers\ only on the 4 descriptor words and set \self.s.cmp_samplers |= 1 << n\ after emitting handles. If a non-comparison sample ran first, its \dx.op.annotateHandle\ encoded \SamplerKind = 0\ (\14\), while a later comparison sample flipped the slot bit so \dx.resources\ declared \SamplerKind = 1\ (\Comparison\), producing invalid DXIL. It also performed an unchecked \1u64 << n\ shift. ### Changes - \crates/victory-shader/src/emit/lower.rs\: Key immediate sampler slots by \(words, comparison)\, guard against \>= 64\ static sampler slots before shifting \cmp_samplers\, and set the comparison bit on allocation before emitting \sampler_handle\. - \crates/victory-shader/src/emit/mod.rs\: Add synthetic regression test \immediate_sampler_slots_distinguish_comparison_uses\ exercising \image_sample\, \image_sample_c\, and \image_sample_c_lz\ with one immediate descriptor and verifying two distinct \static_samplers\ (non-comparison and comparison) plus optional \dxil.dll\ validation when present. ### Verification - \cargo test -p victory-shader --lib emit::\: 50 passed, 0 failed, 1 ignored. - \cargo clippy -p victory-shader --all-targets -- -D warnings\: clean. - \cargo xtask policy\: 154 files OK. *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 19:03:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:12Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and were not run here; lowering/structure coverage only.

Immediate sampler slots are now keyed by (words, comparison-mode) instead of reusing one slot and OR-ing the comparison bit afterwards, so plain image_sample* and image_sample_c* on the same immediate sampler words get two static samplers (plain + filter | 0x80). The 64-slot guard is in place, and the in-tree test asserts [sampler, comparison] static samplers for the mixed-use shader (validator gated #[cfg(windows)], macOS-safe). 97 passed on macOS.

Note: this overlaps with #1493 (same problem statement) — #1493 currently breaks macOS compilation; whichever lands second should rebase.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045233504 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1477#pullrequestreview-6045233504). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T18:42:12Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 97 passed, 0 failed. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here; lowering/structure coverage only. Immediate sampler slots are now keyed by (words, comparison-mode) instead of reusing one slot and OR-ing the comparison bit afterwards, so plain `image_sample*` and `image_sample_c*` on the same immediate sampler words get two static samplers (plain + `filter | 0x80`). The 64-slot guard is in place, and the in-tree test asserts `[sampler, comparison]` static samplers for the mixed-use shader (validator gated `#[cfg(windows)]`, macOS-safe). 97 passed on macOS. Note: this overlaps with #1493 (same problem statement) — #1493 currently breaks macOS compilation; whichever lands second should rebase.
sinan-cmyk commented 2026-11-24 21:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:13:32Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 2286e03 onto main ffe310e (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: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143215780 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1477#issuecomment-7143215780). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:13:32Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 2286e03 onto `main` ffe310e (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: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:39 +00:00
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!1476
No description provided.