Shaders: combine consecutive constant AND masks #3734

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3734 into main
andrewpozdnakov7-jpg commented 2026-11-28 13:07:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T13:07:06Z.


Combine two consecutive 32-bit ANDs with constant masks as (x & a) & b → x & (a & b), with either operand order. Other readers can still use the intermediate value. Existing liveness drops it when there are no readers. LLVM integer AND.

Generated compute shader DXIL instructions, main → change DXIL bytes, main → change
Two masks 36 → 35 2,332 → 2,336
Two masks with a shared intermediate 36 → 36 2,332 → 2,340
Twelve masks 46 → 35 2,400 → 2,360

Microsoft WARP 1.0.22 with Agility 1.620.2 matched the integer reference and reproduced the same 6,174 output words on both builds. The committed test verifies the combined mask, either operand order, and liveness of a shared intermediate. All 13 bitcode tests passed, with the existing benchmark ignored. Strict all-feature shader Clippy and the asset policy passed. The counts and sizes are from emitted DXIL. Game performance was unmeasured.

#1646 and #1716 cover constant operands and identity operations. This fold handles a live input flowing through a chain of constant masks.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5540424194 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3734). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T13:07:06Z. --- Combine two consecutive 32-bit ANDs with constant masks as `(x & a) & b → x & (a & b)`, with either operand order. Other readers can still use the intermediate value. Existing liveness drops it when there are no readers. [LLVM integer AND](https://llvm.org/docs/LangRef.html#and-instruction). | Generated compute shader | DXIL instructions, main → change | DXIL bytes, main → change | |---|---:|---:| | Two masks | 36 → 35 | 2,332 → 2,336 | | Two masks with a shared intermediate | 36 → 36 | 2,332 → 2,340 | | Twelve masks | 46 → 35 | 2,400 → 2,360 | Microsoft WARP 1.0.22 with Agility 1.620.2 matched the integer reference and reproduced the same 6,174 output words on both builds. The committed test verifies the combined mask, either operand order, and liveness of a shared intermediate. All 13 bitcode tests passed, with the existing benchmark ignored. Strict all-feature shader Clippy and the asset policy passed. The counts and sizes are from emitted DXIL. Game performance was unmeasured. #1646 and #1716 cover constant operands and identity operations. This fold handles a live input flowing through a chain of constant masks. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 13:11:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T13:11:17Z.


Windows CI passed on e61d843, including the workspace tests and both Clippy configurations. The combined run with #1716 matched all WARP outputs and confirmed the same 11-instruction reduction in the 12-mask fixture. Combined result.

The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7239756523 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3734#issuecomment-7239756523). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T13:11:17Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46148006756/job/140988191254) passed on `e61d843`, including the workspace tests and both Clippy configurations. The combined run with #1716 matched all WARP outputs and confirmed the same 11-instruction reduction in the 12-mask fixture. [Combined result](https://github.com/Marvisak/VIctory/pull/1716#issuecomment-7239746461). The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-28 13:23:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T13:23:39Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3734 at head e61d8432a0fde173b4c398829fe0c0ead0f01f4a, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::consecutive_constant_and_masks_share_the_original_value --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (1 file, +56/-0).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only bitcode emitter test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7239903993 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3734#issuecomment-7239903993). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T13:23:39Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3734 at head `e61d8432a0fde173b4c398829fe0c0ead0f01f4a`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::consecutive_constant_and_masks_share_the_original_value --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check 63bcca4 HEAD` clean (1 file, +56/-0). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only bitcode emitter test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
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/3734:upstream-pr/3734'
git switch 'upstream-pr/3734'

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/3734'
git switch 'upstream-pr/3734'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3734'
git switch 'upstream-pr/3734'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3734'
git switch 'main'
git merge --squash 'upstream-pr/3734'
git switch 'main'
git merge --ff-only 'upstream-pr/3734'
git switch 'main'
git merge 'upstream-pr/3734'
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
Marvisak/VIctory!3734
No description provided.