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

Open
AscilCH wants to merge 1 commit from upstream-pr/714 into main
AscilCH commented 2026-11-25 05:20:44 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T05:20:44Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597795813 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/714). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T05:20:44Z. --- ### 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.)*
ArturoWolff commented 2026-11-25 06:06:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ArturoWolff on 2026-11-25T05:35:09Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153927533 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/714#issuecomment-7153927533). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-25T05:35:09Z. --- 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://github.com/fxceless/victory-fork/issues/599#issuecomment-7152302455). 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 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/714:upstream-pr/714'
git switch 'upstream-pr/714'

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