perf(shader): mark SLOT_MEMORY directory loads pure and add global-buffer SRV CSE (#276) #396

Merged
Androtim merged 2 commits from upstream-pr/396 into main 2026-12-03 14:52:27 +00:00
Androtim commented 2026-12-03 13:45:07 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T13:45:07Z.


Summary

Ports two GPL-3.0 DXIL bitcode optimization passes into victory-shader cleanly and title-neutrally:

  1. Pure SLOT_MEMORY page-directory loads — ported from lobomfz/VIctory-xmem PR #166 (fd19a20, GPL-3.0):

    • Adds Module::pure_loads: HashSet<u32> and Module::mark_pure(&mut self, v: V) in crates/victory-shader/src/emit/bitcode.rs.
    • Updates class and has_effect in crates/victory-shader/src/emit/bitcode/opt.rs to treat marked pure calls as Effect::Pure.
    • Marks the SLOT_MEMORY page-directory rawBufferLoad.f32 result (entry) via self.s.m.mark_pure(entry) inside Lower::memory_entry (crates/victory-shader/src/emit/lower.rs), so conditional fault stores to SLOT_FAULTS do not break CSE across consecutive lookups of the same (lo, hi) page.
  2. Global-buffer-aware RawBuffer SRV CSE (DOM_LOADS = 128) — ported from ReTerryDavis/ReVIctory commit 40b5f9c (building on lobomfz/VIctory-xmem fd19a20, GPL-3.0):

    • Adds pub const DOM_LOADS: u32 = 128 (enabled by default in MODULE, ALL, and DEFAULT = 255, matching MiniVI's DEFAULT = ALL convention; VICTORY_SHADER_OPT=127 opts out of DOM_LOADS, and 63 opts out of both WIDE and DOM_LOADS).
    • Adds Key::BufferRead(usize, u32, Vec<V>), raw_srv_key (for RawBuffer SRVs, kind == 11), is_global_buffer_write (allowing non-aliasing LDS, private, mesh/primitive output ops including emitIndices, texture writes, and threadgroup-only barriers), and srv_memory_regions in crates/victory-shader/src/emit/bitcode/opt.rs.
    • Implements srv_memory_regions as a dataflow fixpoint over reachable blocks in RPO so cross-loop SRV CSE is preserved when loop back-edges have no global buffer writes/barriers, while strictly invalidating on UAV/global buffer stores, atomics, and device/group-UAV barriers (m & 6 != 0).

Refs #276

Change Map

  • crates/victory-shader/src/emit/bitcode.rs — Module::pure_loads, Module::mark_pure
  • crates/victory-shader/src/emit/lower.rs — self.s.m.mark_pure(entry) in Lower::memory_entry
  • crates/victory-shader/src/emit/bitcode/opt.rs — DOM_LOADS = 128, Key::BufferRead, pure_loads handling, is_global_buffer_write, fixpoint srv_memory_regions, raw_srv_key, merge updates, and 5 unit tests (a_read_marked_pure_is_reused_past_a_store_on_a_branch, raw_srv_reuse_requires_dominance_and_an_unbroken_memory_region, raw_srv_reuse_across_non_aliasing_writes_and_group_barriers, raw_srv_reuse_invalidated_by_uav_writes_atomics_and_device_barriers, pure_slot_memory_and_srv_cse_emit_valid_dxil_containers)
  • crates/victory-shader/src/emit/lower_tests.rs — 2 end-to-end lowering + dxil.dll validation tests (slot_memory_pure_load_reuses_directory_across_fault_branch_and_validates, raw_srv_cse_in_lowered_shader_preserves_lds_write_and_invalidates_on_uav_store)
  • crates/victory-shader/src/emit/mod.rs — shader_opt() docs (255, DOM_LOADS = 128, 127, 63) and the_clean_up_switch_parses_or_runs_every_pass

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings — passed (0 warnings)
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features --locked -- -D warnings — passed (0 warnings)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask --locked — 8 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy — asset policy: 351 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib -- --test-threads=1 bitcode::opt::tests the_clean_up_switch slot_memory_pure_load raw_srv_cse_in_lowered_shader — 21 passed; 0 failed (all 7 new positive/negative tests pass, including dxil.dll container validation)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib -- --test-threads=1 — 414 passed; 3 failed; 6 ignored locally against Windows SDK 10.0.22000.0 dxil.dll (the 3 failures — first_half_values_render_on_hardware_and_warp, rectangles_are_drawn_whole, the_rectangle_stage_is_a_geometry_shader — are pre-existing PSV0 mismatches on 10.0.22000.0 reproduced in unmodified baseline 407 passed; 3 failed; 6 ignored; verified in full on windows-latest CI below)
<!-- greyfinch-sync:Androtim/MiniVI:issue:5627716858 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/396). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T13:45:07Z. --- ## Summary Ports two GPL-3.0 DXIL bitcode optimization passes into `victory-shader` cleanly and title-neutrally: 1. **Pure `SLOT_MEMORY` page-directory loads** — ported from `lobomfz/VIctory-xmem` PR #166 (`fd19a20`, GPL-3.0): - Adds `Module::pure_loads: HashSet<u32>` and `Module::mark_pure(&mut self, v: V)` in `crates/victory-shader/src/emit/bitcode.rs`. - Updates `class` and `has_effect` in `crates/victory-shader/src/emit/bitcode/opt.rs` to treat marked pure calls as `Effect::Pure`. - Marks the `SLOT_MEMORY` page-directory `rawBufferLoad.f32` result (`entry`) via `self.s.m.mark_pure(entry)` inside `Lower::memory_entry` (`crates/victory-shader/src/emit/lower.rs`), so conditional fault stores to `SLOT_FAULTS` do not break CSE across consecutive lookups of the same `(lo, hi)` page. 2. **Global-buffer-aware `RawBuffer` SRV CSE (`DOM_LOADS = 128`)** — ported from `ReTerryDavis/ReVIctory` commit `40b5f9c` (building on `lobomfz/VIctory-xmem` `fd19a20`, GPL-3.0): - Adds `pub const DOM_LOADS: u32 = 128` (enabled by default in `MODULE`, `ALL`, and `DEFAULT = 255`, matching MiniVI's `DEFAULT = ALL` convention; `VICTORY_SHADER_OPT=127` opts out of `DOM_LOADS`, and `63` opts out of both `WIDE` and `DOM_LOADS`). - Adds `Key::BufferRead(usize, u32, Vec<V>)`, `raw_srv_key` (for `RawBuffer` SRVs, `kind == 11`), `is_global_buffer_write` (allowing non-aliasing LDS, private, mesh/primitive output ops including `emitIndices`, texture writes, and threadgroup-only barriers), and `srv_memory_regions` in `crates/victory-shader/src/emit/bitcode/opt.rs`. - Implements `srv_memory_regions` as a dataflow fixpoint over reachable blocks in RPO so cross-loop SRV CSE is preserved when loop back-edges have no global buffer writes/barriers, while strictly invalidating on UAV/global buffer stores, atomics, and device/group-UAV barriers (`m & 6 != 0`). Refs #276 ### Change Map - `crates/victory-shader/src/emit/bitcode.rs` — `Module::pure_loads`, `Module::mark_pure` - `crates/victory-shader/src/emit/lower.rs` — `self.s.m.mark_pure(entry)` in `Lower::memory_entry` - `crates/victory-shader/src/emit/bitcode/opt.rs` — `DOM_LOADS = 128`, `Key::BufferRead`, `pure_loads` handling, `is_global_buffer_write`, fixpoint `srv_memory_regions`, `raw_srv_key`, `merge` updates, and 5 unit tests (`a_read_marked_pure_is_reused_past_a_store_on_a_branch`, `raw_srv_reuse_requires_dominance_and_an_unbroken_memory_region`, `raw_srv_reuse_across_non_aliasing_writes_and_group_barriers`, `raw_srv_reuse_invalidated_by_uav_writes_atomics_and_device_barriers`, `pure_slot_memory_and_srv_cse_emit_valid_dxil_containers`) - `crates/victory-shader/src/emit/lower_tests.rs` — 2 end-to-end lowering + `dxil.dll` validation tests (`slot_memory_pure_load_reuses_directory_across_fault_branch_and_validates`, `raw_srv_cse_in_lowered_shader_preserves_lds_write_and_invalidates_on_uav_store`) - `crates/victory-shader/src/emit/mod.rs` — `shader_opt()` docs (`255`, `DOM_LOADS = 128`, `127`, `63`) and `the_clean_up_switch_parses_or_runs_every_pass` ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` — passed (0 warnings) - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --all-features --locked -- -D warnings` — passed (0 warnings) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask --locked` — `8 passed; 0 failed` - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` — `asset policy: 351 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib -- --test-threads=1 bitcode::opt::tests the_clean_up_switch slot_memory_pure_load raw_srv_cse_in_lowered_shader` — `21 passed; 0 failed` (all 7 new positive/negative tests pass, including `dxil.dll` container validation) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader --lib -- --test-threads=1` — `414 passed; 3 failed; 6 ignored` locally against Windows SDK `10.0.22000.0` `dxil.dll` (the 3 failures — `first_half_values_render_on_hardware_and_warp`, `rectangles_are_drawn_whole`, `the_rectangle_stage_is_a_geometry_shader` — are pre-existing PSV0 mismatches on `10.0.22000.0` reproduced in unmodified baseline `407 passed; 3 failed; 6 ignored`; verified in full on `windows-latest` CI below)
Androtim commented 2026-12-03 14:01:54 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T14:01:54Z.


Triage (7e615e6a, CI check PASS):

  • Clean GPL-3.0 shader compiler pass (+903/-17 across bitcode.rs, bitcode/opt.rs, lower.rs, lower_tests.rs, mod.rs): pure SLOT_MEMORY directory loads + global-buffer-aware RawBuffer SRV CSE (DOM_LOADS = 128, DEFAULT = 255, opt-out via VICTORY_SHADER_OPT=127; automatic translator/cache-key isolation via victory-gpu/build.rs + shader_opt()). Note file overlap in bitcode/opt.rs with #314.
  • Holding auto-merge for Gate 2 Deep Reasoning Audit (#282) (aliasing/barrier soundness in is_global_buffer_write & srv_memory_regions) + Gate 3 cold-cache plain --release A/B (0 DXIL errors / 0 DRED) + --features diagnostics visual PNG verification.
<!-- greyfinch-sync:Androtim/MiniVI:comment:7380776111 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/396#issuecomment-7380776111). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T14:01:54Z. --- Triage (`7e615e6a`, **CI `check` PASS**): - Clean GPL-3.0 shader compiler pass (`+903/-17` across `bitcode.rs`, `bitcode/opt.rs`, `lower.rs`, `lower_tests.rs`, `mod.rs`): pure `SLOT_MEMORY` directory loads + global-buffer-aware `RawBuffer` SRV CSE (`DOM_LOADS = 128`, `DEFAULT = 255`, opt-out via `VICTORY_SHADER_OPT=127`; automatic translator/cache-key isolation via `victory-gpu/build.rs` + `shader_opt()`). Note file overlap in `bitcode/opt.rs` with `#314`. - Holding auto-merge for **Gate 2 Deep Reasoning Audit (`#282`)** (aliasing/barrier soundness in `is_global_buffer_write` & `srv_memory_regions`) + **Gate 3 cold-cache plain `--release` A/B** (`0` DXIL errors / `0` DRED) + `--features diagnostics` visual PNG verification.
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
Androtim/MiniVI!396
No description provided.