Shaders/lower: fix mesh all-lane barriers, SMEM UAV loads, same-target branch edges, and readfirstlane offsets #714

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

@⁠AscilCH on GitHub · 2026-11-25 05:20 UTC · original
AscilCH:fix/shader-lower-mesh-barrier-smem-uav-edges-and-readfirstlane → main · +338 −32 · 1 files · 1 commits · open

Summary

Fixes four DXIL lowering bugs in crates/victory-shader/src/emit/lower.rs:

  1. Mesh shader no_barrier stripped all barriers on all-lane GS_ALLOC_REQ:
    • Lower::new previously collected every block containing s_sendmsg(GS_ALLOC_REQ) into alloc and added every block it dominated to no_barrier. When GS_ALLOC_REQ sits in an all-lane block (e.g. entry block 0), it dominates the entire CFG and deleted every s_barrier in the mesh shader.
    • Now filters alloc with all_lane_blocks(x.st) (!a[b]) so only divergent single-lane GS_ALLOC_REQ blocks suppress dominated barriers.
  2. Scalar buffer loads (smem / descriptor_data) mishandled UAVs as CBVs:
    • smem() previously only checked ResourceType::Srv, falling through to CBV cbufferLoadLegacy (props = (13, 0x1_0000)) for ResourceType::Uav (corrupting table UAV reads and rejecting root UAVs with "a typed root view"). descriptor_data() similarly rejected UAVs read only by Smem.
    • Both now accept ResourceType::Srv | ResourceType::Uav with raw SRV/UAV handles ((if uav { 0x100b } else { 11 }, 0) / ((11 | u, 0), None)).
  3. Same-target conditional branch overwrote Lower::edges entry:
    • When CondBr had taken == not_taken, the second self.edge(b, not_taken) call overwrote self.edges[(b, to)], causing fill_phis, descriptor_phi, and lane_heap_index to emit duplicate predecessor blocks and omit the first edge block.
    • Lower::edges is now keyed by (from, to, second) so both critical-edge blocks are tracked distinctly.
  4. Missing waveReadLaneFirst.i32 for VGPR inputs/phis and Source::Built dynamic offsets:
    • resource.rs unwraps v_readfirstlane_b32 back to its VGPR source in Address::dynamic. code_smem() only checked instruction writes (missing program-input VGPRs and VGPR phis), and built_offset() never emitted waveReadLaneFirst.i32 at all.
    • Added is_vgpr_value() (checking p.inputs, phi_at, and def_block) and scalar_dynamic(), used by both code_smem() and built_offset().

Verification

  • cargo test -p victory-shader --locked -- emit::lower::tests emit::diff_tests emit::waterfall_tests emit::wave64_tests: 31 passed, 0 failed, 1 ignored (including 4 new regression tests: all_lane_mesh_gs_alloc_req_preserves_lds_barrier, smem_uav_uses_raw_buffer_load_not_cbuffer, same_target_conditional_branch_keeps_both_edge_blocks, and scalar_dynamic_offset_wraps_vgpr_input_and_phi_in_wave_read_lane_first)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean (0 warnings)
  • cargo xtask policy: 169 files ok

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/714) `AscilCH:fix/shader-lower-mesh-barrier-smem-uav-edges-and-readfirstlane` → `main` · +338 −32 · 1 files · 1 commits · open ### Summary Fixes four DXIL lowering bugs in `crates/victory-shader/src/emit/lower.rs`: 1. **Mesh shader `no_barrier` stripped all barriers on all-lane `GS_ALLOC_REQ`**: - `Lower::new` previously collected every block containing `s_sendmsg(GS_ALLOC_REQ)` into `alloc` and added every block it dominated to `no_barrier`. When `GS_ALLOC_REQ` sits in an all-lane block (e.g. entry block `0`), it dominates the entire CFG and deleted every `s_barrier` in the mesh shader. - Now filters `alloc` with `all_lane_blocks(x.st)` (`!a[b]`) so only divergent single-lane `GS_ALLOC_REQ` blocks suppress dominated barriers. 2. **Scalar buffer loads (`smem` / `descriptor_data`) mishandled UAVs as CBVs**: - `smem()` previously only checked `ResourceType::Srv`, falling through to CBV `cbufferLoadLegacy` (`props = (13, 0x1_0000)`) for `ResourceType::Uav` (corrupting table UAV reads and rejecting root UAVs with `"a typed root view"`). `descriptor_data()` similarly rejected UAVs read only by `Smem`. - Both now accept `ResourceType::Srv | ResourceType::Uav` with raw SRV/UAV handles (`(if uav { 0x100b } else { 11 }, 0)` / `((11 | u, 0), None)`). 3. **Same-target conditional branch overwrote `Lower::edges` entry**: - When `CondBr` had `taken == not_taken`, the second `self.edge(b, not_taken)` call overwrote `self.edges[(b, to)]`, causing `fill_phis`, `descriptor_phi`, and `lane_heap_index` to emit duplicate predecessor blocks and omit the first edge block. - `Lower::edges` is now keyed by `(from, to, second)` so both critical-edge blocks are tracked distinctly. 4. **Missing `waveReadLaneFirst.i32` for VGPR inputs/phis and `Source::Built` dynamic offsets**: - `resource.rs` unwraps `v_readfirstlane_b32` back to its VGPR source in `Address::dynamic`. `code_smem()` only checked instruction writes (missing program-input VGPRs and VGPR phis), and `built_offset()` never emitted `waveReadLaneFirst.i32` at all. - Added `is_vgpr_value()` (checking `p.inputs`, `phi_at`, and `def_block`) and `scalar_dynamic()`, used by both `code_smem()` and `built_offset()`. ### Verification - `cargo test -p victory-shader --locked -- emit::lower::tests emit::diff_tests emit::waterfall_tests emit::wave64_tests`: **31 passed, 0 failed, 1 ignored** (including 4 new regression tests: `all_lane_mesh_gs_alloc_req_preserves_lds_barrier`, `smem_uav_uses_raw_buffer_load_not_cbuffer`, `same_target_conditional_branch_keeps_both_edge_blocks`, and `scalar_dynamic_offset_wraps_vgpr_input_and_phi_in_wave_read_lane_first`) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean (0 warnings) - `cargo xtask policy`: `169 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
Fixes four DXIL lowering bugs in `crates/victory-shader/src/emit/lower.rs`:
1. Mesh shader `no_barrier`: only treat `s_sendmsg(GS_ALLOC_REQ)` blocks as
   barrier-suppressing dominators when `!all_lane_blocks(x.st)[b]` (divergent
   single-lane allocation). An all-lane `GS_ALLOC_REQ` in block 0 previously
   dominated the whole CFG and stripped every `s_barrier` in the mesh shader.
2. `smem()` & `descriptor_data()`: handle `ResourceType::Uav` alongside
   `ResourceType::Srv` using raw UAV handles (`0x100b` / `11 | u`) and
   `rawBufferLoad.f32`, instead of falling through to CBV `cbufferLoadLegacy`
   (which corrupted table UAVs and rejected root UAVs as typed root views).
3. Same-target conditional branches (`taken == not_taken`): key `Lower::edges`
   by `(from, to, second)` so both critical-edge blocks are preserved instead
   of overwriting the first entry and emitting duplicate PHI predecessors in
   `fill_phis`, `descriptor_phi`, and `lane_heap_index`.
4. `v_readfirstlane_b32`-unwrapped VGPR offsets: add `is_vgpr_value()` (which
   checks program inputs, VGPR phis, and instruction writes) and
   `scalar_dynamic()` so `waveReadLaneFirst.i32` (+ `flags::WAVE_OPS`) is
   emitted in both `code_smem()` and `built_offset()`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:30 +00:00
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-25 05:35 UTC · original

Linux coverage check: #714 produced byte-identical DXIL for all 725 distinct shader hashes named in the operation records from our frame 2256 (323 compute, 102 vertex, 202 pixel, 98 mesh). This is the frame where we saw geometry in intermediate targets but not in the presented image in #599.

I matched each recorded hash against the full source container, then built separate native translators and Cargo targets from clean 310c6eb and PR head 2491d55. Each called emit::translate directly with host max wave 32; no disk shader cache. All 725 emitted on both revisions; I compared the actual DXIL files, and Microsoft's Linux dxv accepted all 725 PR outputs. The PR head's full victory-shader --lib suite also passed locally: 175 passed, 0 failed, 2 ignored, including the four new tests.

The synthetic tests and this result answer different questions. The fixes have focused coverage, but none changed the shader bytes in this recorded set. I wouldn't use a rerun of this frame as the first visual test of #714. The list excludes shaders that were never recorded (including earlier dropped draws); it does not cover the whole title, host pipeline creation, execution, or the contents of the composite input.

AI disclosure: Hermes Agent ran the offline comparison and tests and wrote this comment on ArturoWolff’s behalf.

**@⁠ArturoWolff** on GitHub · 2026-11-25 05:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/714#issuecomment-7153927533) Linux coverage check: **#714 produced byte-identical DXIL for all 725 distinct shader hashes named in the operation records from our frame 2256** (323 compute, 102 vertex, 202 pixel, 98 mesh). This is the frame where we saw geometry in intermediate targets but not in the presented image [in #599](https://git.gtahub.st/github/fxceless--victory-fork/issues/599). I matched each recorded hash against the full source container, then built separate native translators and Cargo targets from clean `310c6eb` and PR head `2491d55`. Each called `emit::translate` directly with host max wave 32; no disk shader cache. All 725 emitted on both revisions; I compared the actual DXIL files, and Microsoft's Linux `dxv` accepted all 725 PR outputs. The PR head's full `victory-shader --lib` suite also passed locally: 175 passed, 0 failed, 2 ignored, including the four new tests. The synthetic tests and this result answer different questions. The fixes have focused coverage, but none changed the shader bytes in this recorded set. I wouldn't use a rerun of this frame as the first visual test of #714. The list excludes shaders that were never recorded (including earlier dropped draws); it does not cover the whole title, host pipeline creation, execution, or the contents of the composite input. AI disclosure: Hermes Agent ran the offline comparison and tests and wrote this comment on ArturoWolff’s behalf.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-714'
git switch 'github-bot/gh-714'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-714'
git switch 'github-bot/gh-714'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-714'
git switch 'main'
git merge --squash 'github-bot/gh-714'
git switch 'main'
git merge --ff-only 'github-bot/gh-714'
git switch 'main'
git merge 'github-bot/gh-714'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.