shader: deduplicate sampled-texture marks along dominated IR paths #2702

Manually merged
github merged 1 commit from github-bot/gh-2702 into gh-pr/2702/base 2026-11-30 14:17:03 +00:00 AGit
Owner

@⁠nidea1 on GitHub · 2026-11-29 16:17 UTC · original
nidea1:perf/dedup-sampled-marks-in-shader → main · +356 −11 · 2 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Deduplicates redundant SLOT_SAMPLED marking blocks emitted under VICTORY_SAMPLED_MARKS=1 along dominated IR paths in crates/victory-shader/src/emit/lower.rs.

Previously, every image_sample* / image_load* emitted its own 4-block WaveIsFirstLane + rawBufferLoad + atomicBinOp diamond into SLOT_SAMPLED, even when the exact same texture heap slot was sampled dozens of times in the same block or along a dominated path. On large Wave64-folded compute shaders with heavy texture sampling, this bloated DXIL basic blocks by >2.5x and added >200 KB of bitcode and >1,300 redundant per-wave UAV loads/branches.

Changes

  • Added canonical MarkKey (LoadedExpr, LoadedSite, FetchedSite, Select) and ir_dominates reusing Lower::idom.
  • Tracked marked_slots: HashMap<(MarkKey, bool), Vec<usize>> keyed by (MarkKey, per_lane) and skipped emitting duplicate mark_sampled blocks whenever a dominating IR block prev_b already marked the same slot and every SSA definition feeding MarkKey dominates prev_b (so loop-carried descriptor reloads still re-mark per iteration).
  • Preserved conservative marking for Source::Phi, Source::Lanes, Source::LanePhi, distinct slots, and non-dominated sibling if/else branches.
  • Added unit test sampled_marks_deduplicated_along_dominated_paths_only in crates/victory-shader/src/emit/waterfall_tests.rs covering same-block reload dedup, dominated-block dedup, sibling branch non-dedup, and distinct-slot marking, with dxil.dll validation.

Measured Impact (RTX 3060 Ti, VICTORY_SAMPLED_MARKS=1, cold CreateComputePipelineState)

Measured across the 10 largest Wave64-folded compute shaders (main 829188e9 vs this PR alone):

  • Largest shader (#1, ~29K console insts):
    • DXIL size: 1,808,720 B -> 1,601,164 B (-207.6 KB / -11.5%)
    • Basic blocks: 8,548 -> 2,988 (-65.0%)
    • SLOT_SAMPLED atomics: 1,547 -> 157 (-89.9%)
    • Cold PSO compile: 36,963 ms -> 26,460 ms (-28.4% / -10.5 s)
  • Top 3 cold PSO compile total: 87,039 ms -> 65,694 ms (-24.5% / -21.3 s)
  • Top 10 Wave64 totals: DXIL 8.45 MB -> 7.75 MB (-8.3%), blocks 41,896 -> 23,212 (-44.6%), translation time 4,697 ms -> 3,925 ms (-16.4%).
  • Combined with #2703 + #2623 + #2357 (same-session idle back-to-back uncached A/B vs main 55d06914): #1 cold PSO 29,080 ms -> 19,078 ms (-34.4% / 1.52x); top-3 total 66,055 ms -> 48,087 ms (-27.2% / 1.37x).

Verification

  • cargo test -p victory-shader -j 4 --lib — 463 passed, 0 failed (including DXIL validation + hardware/WARP GPU tests and new dedup test); combined with #2703 + #2623 + #2357 on main (55d06914): 470 passed, 0 failed, plus full pipeline preload (2,720/2,720 compiled cleanly) and live runtime validation (0 shader errors).
  • cargo clippy -p victory-shader -j 4 --tests — 0 new warnings.
  • cargo xtask policy --staged — clean.
**@⁠nidea1** on GitHub · 2026-11-29 16:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2702) `nidea1:perf/dedup-sampled-marks-in-shader` → `main` · +356 −11 · 2 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Deduplicates redundant `SLOT_SAMPLED` marking blocks emitted under `VICTORY_SAMPLED_MARKS=1` along dominated IR paths in `crates/victory-shader/src/emit/lower.rs`. Previously, every `image_sample*` / `image_load*` emitted its own 4-block `WaveIsFirstLane` + `rawBufferLoad` + `atomicBinOp` diamond into `SLOT_SAMPLED`, even when the exact same texture heap slot was sampled dozens of times in the same block or along a dominated path. On large Wave64-folded compute shaders with heavy texture sampling, this bloated DXIL basic blocks by >2.5x and added >200 KB of bitcode and >1,300 redundant per-wave UAV loads/branches. ### Changes - Added canonical `MarkKey` (`LoadedExpr`, `LoadedSite`, `FetchedSite`, `Select`) and `ir_dominates` reusing `Lower::idom`. - Tracked `marked_slots: HashMap<(MarkKey, bool), Vec<usize>>` keyed by `(MarkKey, per_lane)` and skipped emitting duplicate `mark_sampled` blocks whenever a dominating IR block `prev_b` already marked the same slot and every SSA definition feeding `MarkKey` dominates `prev_b` (so loop-carried descriptor reloads still re-mark per iteration). - Preserved conservative marking for `Source::Phi`, `Source::Lanes`, `Source::LanePhi`, distinct slots, and non-dominated sibling `if/else` branches. - Added unit test `sampled_marks_deduplicated_along_dominated_paths_only` in `crates/victory-shader/src/emit/waterfall_tests.rs` covering same-block reload dedup, dominated-block dedup, sibling branch non-dedup, and distinct-slot marking, with `dxil.dll` validation. ### Measured Impact (RTX 3060 Ti, `VICTORY_SAMPLED_MARKS=1`, cold `CreateComputePipelineState`) Measured across the 10 largest Wave64-folded compute shaders (`main` `829188e9` vs this PR alone): - **Largest shader (#1, ~29K console insts):** - DXIL size: `1,808,720 B` -> `1,601,164 B` (`-207.6 KB` / `-11.5%`) - Basic blocks: `8,548` -> `2,988` (`-65.0%`) - `SLOT_SAMPLED` atomics: `1,547` -> `157` (`-89.9%`) - Cold PSO compile: `36,963 ms` -> `26,460 ms` (**`-28.4%` / `-10.5 s`**) - **Top 3 cold PSO compile total:** `87,039 ms` -> `65,694 ms` (**`-24.5%` / `-21.3 s`**) - **Top 10 Wave64 totals:** DXIL `8.45 MB` -> `7.75 MB` (`-8.3%`), blocks `41,896` -> `23,212` (`-44.6%`), translation time `4,697 ms` -> `3,925 ms` (`-16.4%`). - **Combined with #2703 + #2623 + #2357 (same-session idle back-to-back uncached A/B vs `main` `55d06914`):** `#1` cold PSO `29,080 ms` -> **`19,078 ms`** (`-34.4%` / `1.52x`); top-3 total `66,055 ms` -> **`48,087 ms`** (`-27.2%` / `1.37x`). ### Verification - `cargo test -p victory-shader -j 4 --lib` — **463 passed, 0 failed** (including DXIL validation + hardware/WARP GPU tests and new dedup test); combined with `#2703` + `#2623` + `#2357` on `main` (`55d06914`): **470 passed, 0 failed**, plus full pipeline preload (**2,720/2,720** compiled cleanly) and live runtime validation (**0** shader errors). - `cargo clippy -p victory-shader -j 4 --tests` — 0 new warnings. - `cargo xtask policy --staged` — clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 16:21:12 +00:00
github-bot changed target branch from main to gh-pr/2702/base 2026-11-30 14:16:52 +00:00
github manually merged commit fc07cc517e into gh-pr/2702/base 2026-11-30 14:16:55 +00:00
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/trustno1-coder--VIctory-NVIDIA!2702
No description provided.