shader(dxil): include comparison flag in static sampler slot deduplication key #344

Open
Caasares wants to merge 1 commit from upstream-pr/344 into main
Caasares commented 2026-11-24 23:43:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Caasares on 2026-11-24T23:43:08Z.


Fixes #250

Root cause

In crates/victory-shader/src/emit/lower.rs, Lower::samplers deduplicated static sampler slots by the four sampler words [u32; 4] alone and updated Shader::cmp_samplers in place whenever a comparison sample (props.0 & 0x8000 != 0) reused an existing slot. When a shader used the same four sampler words for both ordinary (Sample) and comparison (SampleCmp) sampling:

  • Comparison-first order: the ordinary sample reused the comparison slot and received a comparison-annotated handle while dx.resources declared that slot as a comparison sampler.
  • Ordinary-first order: the earlier ordinary sample kept an ordinary-annotated handle while the later comparison use set the comparison bit on the shared slot, causing the slot's dx.resources sampler kind (1) and handle annotations to disagree with the ordinary sample.

Fix

  • Key Lower::samplers by ([u32; 4], bool) (the four sampler words together with cmp = props.0 & 0x8000 != 0) in crates/victory-shader/src/emit/lower.rs, setting the cmp_samplers bit when allocating a new comparison slot and stripping the flag back to [u32; 4] when constructing Lowered::samplers.
  • Verified downstream consumers (emit::shader::Shader::sampler_handle, Shader::finish, emit::mod::emit_program, victory-gpu root signature / shader cache) all key by slot index n and require no changes.
  • Added synthetic compute-shader unit tests in crates/victory-shader/src/emit/lower.rs (no game data) covering:
    • ordinary-first (Sample then SampleCmp) allocation of two distinct static sampler slots (s0 ordinary, s1 comparison) with matching annotateHandle properties and dx.resources sampler kinds;
    • comparison-first (SampleCmp then Sample) allocation of two distinct static sampler slots (s0 comparison, s1 ordinary) with matching annotations and dx.resources kinds;
    • deduplication of same-kind uses (Sample + Sample, SampleCmp + SampleCmp) to a single static sampler slot.
    • Confirmed the two mixed-order tests fail before the fix and pass after.

Verification

All checks run inside wt-vf-250 after the final edit:

  • cargo clippy --workspace --all-targets --locked -- -D warnings — passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — passed (0 warnings)
  • cargo test --workspace --locked — passed: 496 passed, 0 failed, 7 ignored (including 213 passed / 2 ignored in victory-shader, 4 passed in xtask policy checks)
  • rustfmt --edition 2024 --check crates\victory-shader\src\emit\lower.rs — 0 formatting diffs on new/modified lines
  • git status -s — only crates/victory-shader/src/emit/lower.rs modified

AI-assisted fix; contains no game files or assets.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593715425 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/344). Originally posted by [Caasares](https://github.com/Caasares) on 2026-11-24T23:43:08Z. --- Fixes #250 ## Root cause In `crates/victory-shader/src/emit/lower.rs`, `Lower::samplers` deduplicated static sampler slots by the four sampler words `[u32; 4]` alone and updated `Shader::cmp_samplers` in place whenever a comparison sample (`props.0 & 0x8000 != 0`) reused an existing slot. When a shader used the same four sampler words for both ordinary (`Sample`) and comparison (`SampleCmp`) sampling: - **Comparison-first order**: the ordinary sample reused the comparison slot and received a comparison-annotated handle while `dx.resources` declared that slot as a comparison sampler. - **Ordinary-first order**: the earlier ordinary sample kept an ordinary-annotated handle while the later comparison use set the comparison bit on the shared slot, causing the slot's `dx.resources` sampler kind (`1`) and handle annotations to disagree with the ordinary sample. ## Fix - Key `Lower::samplers` by `([u32; 4], bool)` (the four sampler words together with `cmp = props.0 & 0x8000 != 0`) in `crates/victory-shader/src/emit/lower.rs`, setting the `cmp_samplers` bit when allocating a new comparison slot and stripping the flag back to `[u32; 4]` when constructing `Lowered::samplers`. - Verified downstream consumers (`emit::shader::Shader::sampler_handle`, `Shader::finish`, `emit::mod::emit_program`, `victory-gpu` root signature / shader cache) all key by slot index `n` and require no changes. - Added synthetic compute-shader unit tests in `crates/victory-shader/src/emit/lower.rs` (no game data) covering: - ordinary-first (`Sample` then `SampleCmp`) allocation of two distinct static sampler slots (`s0` ordinary, `s1` comparison) with matching `annotateHandle` properties and `dx.resources` sampler kinds; - comparison-first (`SampleCmp` then `Sample`) allocation of two distinct static sampler slots (`s0` comparison, `s1` ordinary) with matching annotations and `dx.resources` kinds; - deduplication of same-kind uses (`Sample` + `Sample`, `SampleCmp` + `SampleCmp`) to a single static sampler slot. - Confirmed the two mixed-order tests fail before the fix and pass after. ## Verification All checks run inside `wt-vf-250` after the final edit: - `cargo clippy --workspace --all-targets --locked -- -D warnings` — passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — passed (0 warnings) - `cargo test --workspace --locked` — passed: 496 passed, 0 failed, 7 ignored (including 213 passed / 2 ignored in `victory-shader`, 4 passed in `xtask` policy checks) - `rustfmt --edition 2024 --check crates\victory-shader\src\emit\lower.rs` — 0 formatting diffs on new/modified lines - `git status -s` — only `crates/victory-shader/src/emit/lower.rs` modified --- *AI-assisted fix; contains no game files or assets.*
kaayzouee commented 2026-11-25 01:12:07 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:02:52Z.


Duplicate of #276?

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149151052 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/344#issuecomment-7149151052). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T01:02:52Z. --- Duplicate of #276?
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/344:upstream-pr/344'
git switch 'upstream-pr/344'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/344'
git switch 'upstream-pr/344'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/344'
git switch 'upstream-pr/344'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/344'
git switch 'main'
git merge --squash 'upstream-pr/344'
git switch 'main'
git merge --ff-only 'upstream-pr/344'
git switch 'main'
git merge 'upstream-pr/344'
git push origin 'main'
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
fxceless/victory-fork!344
No description provided.