Shaders/IR: give buffer_gl0_inv and buffer_gl1_inv no register effects #3264

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

@⁠fuzeofficlal on GitHub · 2026-11-26 15:00 UTC · original
fuzeofficlal:fix/ir-buffer-inv-no-register-effects → main · +96 −1 · 1 files · 1 commits · open

Summary

On GFX10/RDNA2, buffer_gl0_inv (MUBUF 0x071) and buffer_gl1_inv (MUBUF 0x072) are zero-operand cache invalidations (MUBUF_Invalidate in LLVM's BUFInstructions.td / gfx10_mubuf.txt): hardware ignores vdata, vaddr, srsrc, soffset, offen, idxen, lds, and EXEC.

Every other pass in victory-shader already handles them as operandless no-ops (gfx10/fields.rs, gfx10/sp3.rs, resource.rs, and emit/lower.rs), and the scalar cache invalidations (s_icache_inv, s_gl1_inv, s_dcache_inv, s_dcache_wb) already produce empty register effects in ir.rs. However, ir::effects still executed the generic Fields::Buffer operand path and the vector EXEC-read path on buffer_gl0_inv and buffer_gl1_inv. Because their standard encodings carry srsrc = 0 and soffset = 0, ir::build fabricated reads of s[0:3] and EXEC, polluting Program::inputs and synthesizing phantom SSA PHIs across branches and loops.

Changes

  • In crates/victory-shader/src/ir.rs (effects), skip Fields::Buffer operand reads and the vector EXEC read for buffer_gl0_inv and buffer_gl1_inv, matching the scalar cache invalidations while keeping the instructions in the IR for emit/lower.rs.
  • Add unit tests in ir::tests covering buffer_gl0_inv, buffer_gl1_inv, s_gl1_inv parity, a buffer_load_dword negative control, and a diamond CFG verifying no phantom s[0:3] or EXEC PHIs or inputs are created in either Wave32 or Wave64.

Verification

  • Verified new tests fail on unmodified main (buffer_gl0_inv fabricated reads of S(0)..S(3) and S(126) and 5 phantom PHIs at the merge block).
  • cargo test -p victory-shader --locked ir::tests (dev and --release): all passing.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passing.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 15:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3264) `fuzeofficlal:fix/ir-buffer-inv-no-register-effects` → `main` · +96 −1 · 1 files · 1 commits · open ## Summary On GFX10/RDNA2, `buffer_gl0_inv` (MUBUF `0x071`) and `buffer_gl1_inv` (MUBUF `0x072`) are zero-operand cache invalidations (`MUBUF_Invalidate` in LLVM's `BUFInstructions.td` / `gfx10_mubuf.txt`): hardware ignores `vdata`, `vaddr`, `srsrc`, `soffset`, `offen`, `idxen`, `lds`, and `EXEC`. Every other pass in `victory-shader` already handles them as operandless no-ops (`gfx10/fields.rs`, `gfx10/sp3.rs`, `resource.rs`, and `emit/lower.rs`), and the scalar cache invalidations (`s_icache_inv`, `s_gl1_inv`, `s_dcache_inv`, `s_dcache_wb`) already produce empty register effects in `ir.rs`. However, `ir::effects` still executed the generic `Fields::Buffer` operand path and the `vector` `EXEC`-read path on `buffer_gl0_inv` and `buffer_gl1_inv`. Because their standard encodings carry `srsrc = 0` and `soffset = 0`, `ir::build` fabricated reads of `s[0:3]` and `EXEC`, polluting `Program::inputs` and synthesizing phantom SSA PHIs across branches and loops. ## Changes - In `crates/victory-shader/src/ir.rs` (`effects`), skip `Fields::Buffer` operand reads and the `vector` `EXEC` read for `buffer_gl0_inv` and `buffer_gl1_inv`, matching the scalar cache invalidations while keeping the instructions in the IR for `emit/lower.rs`. - Add unit tests in `ir::tests` covering `buffer_gl0_inv`, `buffer_gl1_inv`, `s_gl1_inv` parity, a `buffer_load_dword` negative control, and a diamond CFG verifying no phantom `s[0:3]` or `EXEC` PHIs or inputs are created in either Wave32 or Wave64. ## Verification - Verified new tests fail on unmodified `main` (`buffer_gl0_inv` fabricated reads of `S(0)..S(3)` and `S(126)` and 5 phantom PHIs at the merge block). - `cargo test -p victory-shader --locked ir::tests` (dev and `--release`): all passing. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passing.
On GFX10/RDNA2, `buffer_gl0_inv` (MUBUF 0x071) and `buffer_gl1_inv` (MUBUF
0x072) are zero-operand cache invalidations: hardware ignores `vdata`,
`vaddr`, `srsrc`, `soffset`, `offen`, `idxen`, `lds`, and `EXEC`. The
decoder (`fields.rs`), SP3 printer (`sp3.rs`), resource tracker
(`resource.rs`), and DXIL lowerer (`emit/lower.rs`) already treat them as
operandless no-ops, and scalar cache invalidations (`s_gl1_inv`,
`s_dcache_inv`, `s_dcache_wb`, `s_icache_inv`) already produce empty
register effects in `ir.rs`.

`ir::effects`, however, still ran the generic `Fields::Buffer` operand
path and the `vector` `EXEC`-read path on `buffer_gl0_inv` and
`buffer_gl1_inv`. Because their standard encodings carry `srsrc = 0` and
`soffset = 0`, `ir::build` fabricated reads of `s[0:3]` and `EXEC`
(`exec_lo` / `exec_hi`), polluting `Program::inputs` and creating phantom
SSA PHIs across branches and loops.

Skip `Fields::Buffer` operand collection and the `vector` `EXEC` read for
`buffer_gl0_inv` and `buffer_gl1_inv`, matching the scalar cache
invalidations.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:02:27 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 15:09 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64:

  • Treating buffer_gl0_inv and buffer_gl1_inv as operandless / EXEC-independent in ir::effects matches the GFX10 MUBUF cache-invalidation semantics and prevents fabricating phantom register inputs and merge PHIs.
  • cargo test -p victory-shader --lib ir:: -- --test-threads=1: 11 passed, 0 failed (including buffer_cache_invalidations_have_no_register_effects and buffer_cache_invalidations_do_not_create_phantom_phis).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3264#pullrequestreview-6076493180) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Treating `buffer_gl0_inv` and `buffer_gl1_inv` as operandless / EXEC-independent in `ir::effects` matches the GFX10 MUBUF cache-invalidation semantics and prevents fabricating phantom register inputs and merge PHIs. - `cargo test -p victory-shader --lib ir:: -- --test-threads=1`: 11 passed, 0 failed (including `buffer_cache_invalidations_have_no_register_effects` and `buffer_cache_invalidations_do_not_create_phantom_phis`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 15:28 UTC · original

WARP verification of #3264 (test report only, no code changes)

Head 6ac0afc47449ddecc90060c74e8f9768114c8862, main 63bcca43c6a00a758510398fa43096ce7e4f7df0 (merge base = main).

Env: Windows 11, WARP only (adapter "Microsoft Basic Render Driver", d3d10warp.dll 10.0.26100.9818), VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0), cargo -j 4. No physical GPU used. Each test was run in its own process (<test> --exact), so one crashing test cannot hide the others. (With the old 10.0.19041 dxil.dll the validator tests crash with an access violation, on main too; unrelated to this PR.)

Commands (head, checked out detached):

  • cargo test -j 4 -p victory-shader --lib (features: none)
  • the new tests: ir::tests::buffer_cache_invalidations_have_no_register_effects, ir::tests::buffer_cache_invalidations_do_not_create_phantom_phis

Results:

  • New tests: 2/2 pass. The existing emit::lower::tests::buffer_cache_invalidations_lower_as_no_ops passes too.
  • victory-shader lib on head: 307 tests, 300 passed, 3 ignored, 4 failed. On main: 305 tests, 298 passed, 3 ignored, 4 failed. The same 4 fail on both: emit::synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}. So the PR adds +2 passes and no new failures.
  • Control: main with only the PR's two tests added (no ir.rs fix): both fail (buffer_gl0_inv reads s0..s3 and exec; phantom PHIs at the merge), the lower test passes. So the tests catch the bug the fix removes.

AI-assisted: verification by Claude Code (Claude Sonnet 5.5). Synthetic tests only; no game files, dumps, shader names or hashes.

**@⁠oni-swr** on GitHub · 2026-11-26 15:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3264#issuecomment-7196315462) **WARP verification of #3264** (test report only, no code changes) Head `6ac0afc47449ddecc90060c74e8f9768114c8862`, main `63bcca43c6a00a758510398fa43096ce7e4f7df0` (merge base = main). Env: Windows 11, WARP only (adapter "Microsoft Basic Render Driver", d3d10warp.dll 10.0.26100.9818), VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0), cargo -j 4. No physical GPU used. Each test was run in its own process (`<test> --exact`), so one crashing test cannot hide the others. (With the old 10.0.19041 dxil.dll the validator tests crash with an access violation, on main too; unrelated to this PR.) Commands (head, checked out detached): - `cargo test -j 4 -p victory-shader --lib` (features: none) - the new tests: `ir::tests::buffer_cache_invalidations_have_no_register_effects`, `ir::tests::buffer_cache_invalidations_do_not_create_phantom_phis` Results: - New tests: 2/2 pass. The existing `emit::lower::tests::buffer_cache_invalidations_lower_as_no_ops` passes too. - `victory-shader` lib on head: 307 tests, 300 passed, 3 ignored, 4 failed. On main: 305 tests, 298 passed, 3 ignored, 4 failed. The same 4 fail on both: `emit::synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}`. So the PR adds +2 passes and no new failures. - Control: main with only the PR's two tests added (no `ir.rs` fix): both fail (`buffer_gl0_inv` reads s0..s3 and exec; phantom PHIs at the merge), the lower test passes. So the tests catch the bug the fix removes. AI-assisted: verification by Claude Code (Claude Sonnet 5.5). Synthetic tests only; no game files, dumps, shader names or hashes.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3264'
git switch 'github-bot/gh-3264'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3264'
git switch 'github-bot/gh-3264'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3264'
git switch 'main'
git merge --squash 'github-bot/gh-3264'
git switch 'main'
git merge --ff-only 'github-bot/gh-3264'
git switch 'main'
git merge 'github-bot/gh-3264'
git push origin 'main'
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!3264
No description provided.