Shaders: require EXEC coverage when tracing VALU address operands #2921

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

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:13:06Z.


Problem

In crates/victory-shader/src/resource.rs, Tracer::lane_value already calls Tracer::runs(site, known) to verify that every lane reaching a consumer actually executed each guarded VALU write. However, vorigin, vadd, carried (v_add_co_ci_u32), lane_term, and sum followed guarded v_mov_b32 / v_add_co_u32 / v_add_nc_u32 / v_add_co_ci_u32 definitions without checking lanes.guards.

When a shader updates a VGPR offset (or high-half address carry) under narrowed EXEC (e.g. v_cmp_* + s_and_saveexec_b32), restores EXEC, and executes a global_load_* / global_store_* / global_atomic_*:

  • flat_address folded the guarded add/move into a static Address::offset for every lane, so lanes skipped while EXEC == 0 silently read or wrote at the wrong offset.
  • A guarded v_add_co_ci_u32 high-half carry after EXEC restore was still attributed to the root parameter instead of falling back to MEMORY.

Changes

  • Added Tracer::site_known and Tracer::runs_value in crates/victory-shader/src/resource.rs, threading lane conditions (known: &[(Bool, bool)]) and guard tracking (unguarded: &mut bool) through vorigin, vterm, vadd, sum / sum_tracked, carried, flat_address, address, traced_address, smem_address, lane_term, fetched, and waterfall.
  • Restricted Tracer::sums memoization to sums traced without encountering any EXEC guard (local == true), preventing guarded and unguarded uses of the same SSA Value (or its ancestors) from poisoning each other regardless of visit order while still allowing unguarded siblings to cache.
  • Left emit/lower.rs untouched.

Verification

All tests use synthetic GFX10 encodings (no external files):

  • Added 3 unit tests in crates/victory-shader/src/resource.rs:
    • a_guarded_move_is_folded_only_for_lanes_that_run_it (same guard folds, s_xor_b32 else-arm and post-restore copy stay dynamic)
    • sums_with_guarded_terms_are_not_cached_in_either_order (checks both visit orders and verifies Tracer::sums stays unpopulated for guarded ancestors)
    • a_guarded_high_half_carry_requires_exec_coverage (guarded v_add_co_ci_u32 folds inside guard and falls back to MEMORY after restore)
  • Added end-to-end DXIL + GPU test emit::synthetic_tests::global_stores_keep_each_lanes_offset_after_exec_is_restored: verified with Windows SDK 10.0.26100.0 dxil.dll, NVIDIA GeForce RTX 5090 (hardware), and D3D12 WARP (VICTORY_WARP=1).
  • cargo test --locked -p victory-shader --lib -- resource::tests emit::lower::tests emit::flow_tests emit::waterfall_tests global_stores_keep_each_lanes_offset_after_exec_is_restored: 78/78 passed on RTX 5090, and global_stores_keep_each_lanes_offset_after_exec_is_restored passed on WARP.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) and cargo xtask policy (191 files ok): clean.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6616478522 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2923). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:13:06Z. --- ### Problem In `crates/victory-shader/src/resource.rs`, `Tracer::lane_value` already calls `Tracer::runs(site, known)` to verify that every lane reaching a consumer actually executed each guarded VALU write. However, `vorigin`, `vadd`, `carried` (`v_add_co_ci_u32`), `lane_term`, and `sum` followed guarded `v_mov_b32` / `v_add_co_u32` / `v_add_nc_u32` / `v_add_co_ci_u32` definitions without checking `lanes.guards`. When a shader updates a VGPR offset (or high-half address carry) under narrowed `EXEC` (e.g. `v_cmp_*` + `s_and_saveexec_b32`), restores `EXEC`, and executes a `global_load_*` / `global_store_*` / `global_atomic_*`: - `flat_address` folded the guarded add/move into a static `Address::offset` for every lane, so lanes skipped while `EXEC == 0` silently read or wrote at the wrong offset. - A guarded `v_add_co_ci_u32` high-half carry after `EXEC` restore was still attributed to the root parameter instead of falling back to `MEMORY`. ### Changes - Added `Tracer::site_known` and `Tracer::runs_value` in `crates/victory-shader/src/resource.rs`, threading lane conditions (`known: &[(Bool, bool)]`) and guard tracking (`unguarded: &mut bool`) through `vorigin`, `vterm`, `vadd`, `sum` / `sum_tracked`, `carried`, `flat_address`, `address`, `traced_address`, `smem_address`, `lane_term`, `fetched`, and `waterfall`. - Restricted `Tracer::sums` memoization to sums traced without encountering any `EXEC` guard (`local == true`), preventing guarded and unguarded uses of the same SSA `Value` (or its ancestors) from poisoning each other regardless of visit order while still allowing unguarded siblings to cache. - Left `emit/lower.rs` untouched. ### Verification All tests use synthetic GFX10 encodings (no external files): - Added 3 unit tests in `crates/victory-shader/src/resource.rs`: - `a_guarded_move_is_folded_only_for_lanes_that_run_it` (same guard folds, `s_xor_b32` else-arm and post-restore copy stay dynamic) - `sums_with_guarded_terms_are_not_cached_in_either_order` (checks both visit orders and verifies `Tracer::sums` stays unpopulated for guarded ancestors) - `a_guarded_high_half_carry_requires_exec_coverage` (guarded `v_add_co_ci_u32` folds inside guard and falls back to `MEMORY` after restore) - Added end-to-end DXIL + GPU test `emit::synthetic_tests::global_stores_keep_each_lanes_offset_after_exec_is_restored`: verified with Windows SDK 10.0.26100.0 `dxil.dll`, NVIDIA GeForce RTX 5090 (`hardware`), and D3D12 WARP (`VICTORY_WARP=1`). - `cargo test --locked -p victory-shader --lib -- resource::tests emit::lower::tests emit::flow_tests emit::waterfall_tests global_stores_keep_each_lanes_offset_after_exec_is_restored`: **78/78 passed** on RTX 5090, and `global_stores_keep_each_lanes_offset_after_exec_is_restored` passed on WARP. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) and `cargo xtask policy` (`191 files ok`): clean.
kotekompotek commented 2026-11-26 01:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:27:38Z.

Review: COMMENTED


Scoped review: requiring EXEC coverage for VALU address operands is the same discipline the descriptor tracking needed — an address operand produced under a mask the store doesn't honor is undefined input. The test's divergent-add-then-restore case is exactly the shape that distinguishes real per-lane tracking from mask-blind analysis. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066905443 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2923#pullrequestreview-6066905443). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:27:38Z. **Review:** COMMENTED --- Scoped review: requiring EXEC coverage for VALU address operands is the same discipline the descriptor tracking needed — an address operand produced under a mask the store doesn't honor is undefined input. The test's divergent-add-then-restore case is exactly the shape that distinguishes real per-lane tracking from mask-blind analysis. LGTM.
Jackster commented 2026-11-26 02:06:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T01:08:59Z.


Independent verification on Windows 11 26100, AMD Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010), Rust 1.100.0, Windows SDK 10.0.26100.0 (dxil.dll):

cargo test --locked -p victory-shader --lib -- resource::tests emit::lower::tests emit::flow_tests emit::waterfall_tests global_stores_keep_each_lanes_offset_after_exec_is_restored
→ 78 passed; 0 failed (1.23 s)

All three new resource::tests pass, and global_stores_keep_each_lanes_offset_after_exec_is_restored runs on both backends:

  • hardware: verified narrowed and restored EXEC stores
  • VICTORY_WARP=1: WARP: verified narrowed and restored EXEC stores

DXIL validation ran with the SDK's dxil.dll (Validator::default_path selects 10.0.26100.0\x64\dxil.dll).

cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean. cargo xtask policy: 191 files ok.

No game files. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179482018 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2923#issuecomment-7179482018). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T01:08:59Z. --- Independent verification on Windows 11 26100, AMD Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010), Rust 1.100.0, Windows SDK 10.0.26100.0 (`dxil.dll`): ``` cargo test --locked -p victory-shader --lib -- resource::tests emit::lower::tests emit::flow_tests emit::waterfall_tests global_stores_keep_each_lanes_offset_after_exec_is_restored → 78 passed; 0 failed (1.23 s) ``` All three new `resource::tests` pass, and `global_stores_keep_each_lanes_offset_after_exec_is_restored` runs on both backends: - `hardware: verified narrowed and restored EXEC stores` - `VICTORY_WARP=1`: `WARP: verified narrowed and restored EXEC stores` DXIL validation ran with the SDK's `dxil.dll` (`Validator::default_path` selects `10.0.26100.0\x64\dxil.dll`). `cargo clippy --locked -p victory-shader --all-targets -- -D warnings`: clean. `cargo xtask policy`: 191 files ok. No game files. AI-assisted.
Marvisak commented 2026-11-26 05:04:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:22:52Z.


Automated triage for the maintainers.

Merge candidate. This fixes a real hole in victory-shader/src/resource.rs: vorigin, vadd, carried and sum followed v_mov_b32 / v_add_* / v_add_co_ci_u32 definitions written under narrowed EXEC without the runs() coverage check lane_value already makes, so lanes that skipped the write got a wrong static offset. The new site_known / runs_value threading through flat_address, address, traced_address, smem_address, lane_term and waterfall reads correctly, and restricting the sums cache to unguarded traces is right. The end-to-end test's expected values follow from EXEC semantics. Note for the maintainer: the descriptor-from-memory path now passes an empty known, which is more conservative and can fall back to MEMORY where it used to resolve to a root parameter.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182544250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2923#issuecomment-7182544250). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:22:52Z. --- <!-- victory-triage v1 head=208ada7b953843163f75f0f6a337e9f1b11b584e verdict=merge-candidate at=2026-11-26T04:22:42Z --> Automated triage for the maintainers. **Merge candidate.** This fixes a real hole in `victory-shader/src/resource.rs`: `vorigin`, `vadd`, `carried` and `sum` followed `v_mov_b32` / `v_add_*` / `v_add_co_ci_u32` definitions written under narrowed EXEC without the `runs()` coverage check `lane_value` already makes, so lanes that skipped the write got a wrong static offset. The new `site_known` / `runs_value` threading through `flat_address`, `address`, `traced_address`, `smem_address`, `lane_term` and `waterfall` reads correctly, and restricting the `sums` cache to unguarded traces is right. The end-to-end test's expected values follow from EXEC semantics. Note for the maintainer: the descriptor-from-memory path now passes an empty `known`, which is more conservative and can fall back to MEMORY where it used to resolve to a root parameter. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 06:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:33:45Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Requiring EXEC coverage when folding VALU address operands in resource.rs (including high-half carries and uncached guarded-term sums) prevents narrowed-EXEC updates from leaking across lanes after EXEC is restored.
  • cargo test -p victory-shader resource::tests: 38 passed, 0 failed (including the new EXEC-coverage tests).
  • cargo test -p victory-shader --test resource_tracking: 3 passed, 0 failed.
  • cargo test -p victory-shader global_stores_keep_each_lanes_offset_after_exec_is_restored -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • 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:6069030012 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2923#pullrequestreview-6069030012). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:33:45Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Requiring EXEC coverage when folding VALU address operands in `resource.rs` (including high-half carries and uncached guarded-term sums) prevents narrowed-EXEC updates from leaking across lanes after EXEC is restored. - `cargo test -p victory-shader resource::tests`: 38 passed, 0 failed (including the new EXEC-coverage tests). - `cargo test -p victory-shader --test resource_tracking`: 3 passed, 0 failed. - `cargo test -p victory-shader global_stores_keep_each_lanes_offset_after_exec_is_restored -- --test-threads=1` (RTX 5090 & WARP): 1 passed, 0 failed on both. - `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).
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/2923:upstream-pr/2923'
git switch 'upstream-pr/2923'

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