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

Open
github-bot wants to merge 1 commit from github-bot/gh-344 into main AGit
Owner

@⁠Caasares on GitHub · 2026-11-24 23:43 UTC · original
Caasares:fix/dxil-static-sampler-cmp-dedup → main · +429 −10 · 1 files · 1 commits · open

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.

**@⁠Caasares** on GitHub · 2026-11-24 23:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/344) `Caasares:fix/dxil-static-sampler-cmp-dedup` → `main` · +429 −10 · 1 files · 1 commits · open 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.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:16 +00:00
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 01:02 UTC · original

Duplicate of #276?

**@⁠kaayzouee** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/344#issuecomment-7149151052) Duplicate of #276?
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/344/head:github-bot/gh-344'
git switch 'github-bot/gh-344'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-344'
git switch 'github-bot/gh-344'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-344'
git switch 'github-bot/gh-344'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-344'
git switch 'main'
git merge --squash 'github-bot/gh-344'
git switch 'main'
git merge --ff-only 'github-bot/gh-344'
git switch 'main'
git merge 'github-bot/gh-344'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.