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

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3264 into main
fuzeofficlal commented 2026-11-26 15:00:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:00:09Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5512354193 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3264). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T15:00:09Z. --- ## 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.
Dukestar69 commented 2026-11-26 15:09:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:09:05Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6076493180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3264#pullrequestreview-6076493180). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T15:09:05Z. **Review:** APPROVED --- 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).
oni-swr commented 2026-11-26 16:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T15:28:25Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196315462 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3264#issuecomment-7196315462). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T15:28:25Z. --- **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.
futurepro62 commented 2026-11-26 23:16:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T23:16:06Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, oni-swr, since none of them names a GPU run. Tested exact head 6ac0afc (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: buffer_cache_invalidations_have_no_register_effects, buffer_cache_invalidations_do_not_create_phantom_phis.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7205397346 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3264#issuecomment-7205397346). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T23:16:06Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, oni-swr, since none of them names a GPU run. Tested exact head `6ac0afc` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `buffer_cache_invalidations_have_no_register_effects`, `buffer_cache_invalidations_do_not_create_phantom_phis`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/3264:upstream-pr/3264'
git switch 'upstream-pr/3264'

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