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

Manually merged
github merged 1 commit from gh-pr/1477/head into gh-pr/1477/base 2026-11-26 04:33:24 +00:00
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:18 UTC · original
geiyiliyabumo:fix/shader-static-sampler-cmp → main · +104 −8 · 2 files · 1 commits · merged 2026-11-25 00:17 UTC

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1477) `geiyiliyabumo:fix/shader-static-sampler-cmp` → `main` · +104 −8 · 2 files · 1 commits · merged 2026-11-25 00:17 UTC ## 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.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:22 +00:00
github manually merged commit 2286e038cc into gh-pr/1477/base 2026-11-26 04:33:24 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:13 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1477#issuecomment-7143215780) ### 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).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1477
No description provided.