Shaders: keep pixel helper lanes out of wave-first loops and quad permutes #895

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

@⁠sagouindupm on GitHub · 2026-11-25 12:07 UTC · original
sagouindupm:pixel-helper-lanes → main · +198 −3 · 3 files · 1 commits · open

Ports two complementary pixel-shader helper-lane fixes onto main (f85101b), both from GPL-3.0-or-later upstreams/forks:

  1. Quad reads in pixel shaders (helpers_read): In ds_swizzle_b32 and DPP instructions, pixel quad permutations (quad) now lower through quad_pick (dx.op.quadReadLaneAt.i32) instead of wave-wide waveReadLaneAt, regardless of whether the shader has discards. At triangle edges, neighboring lanes of a 2x2 quad are helper lanes that quad reads see cleanly whereas wave reads exclude them. (Adapted from Belobug/VIctory-Belobug-AMD commit 03629f3f.)
  2. Helper lanes in v_readfirstlane_b32 (helper_reads_own): Guard v_readfirstlane_b32 results in pixel shaders with dx.op.isHelperLane.i1 (SM 6.6 opcode 221) so helper lanes read their own value instead of spinning when only helper lanes remain in a waterfall loop (WaveReadLaneFirst ignoring helper lanes). Computes remain unchanged. (Ported from Marvisak/VIctory PR #1733 / commit 0601955 by Vax.)

Summary of changes

  • crates/victory-shader/src/emit/lower.rs: Add helpers_read and helper_reads_own; apply helpers_read(quad) in ds_swizzle_b32 and dpp, and wrap v_readfirstlane_b32 results (including VICTORY_FIRSTLANE_OWN=1 path) with helper_reads_own.
  • crates/victory-shader/src/emit/bitcode.rs & crates/victory-shader/src/emit/mod.rs: Expose #[cfg(test)] Module::func_names() and Lowered::funcs, and add unit tests pixel_readfirstlane_uses_is_helper_lane_and_compute_does_not and pixel_quad_swizzle_without_discards_uses_quad_read_lane_at validated through dxil.dll.

Attribution

  • Vax / Marvisak/VIctory PR #1733 (0601955, GPL-3.0-or-later)
  • Belobug/VIctory-Belobug-AMD commit 03629f3f (GPL-3.0-or-later)

Verification

Run on Windows 11 Pro (x86_64-pc-windows-msvc, Rust 1.98.1, dxil.dll present):

  • cargo test --release -j 6 -p victory-shader -- barycentric_tests --test-threads=1 -> 10 passed; 0 failed (including both new tests + dxil.dll validation).
  • cargo test --release -j 6 -p victory-shader -- waterfall_tests --test-threads=1 -> all passed; 0 failed.
  • cargo test --release -j 6 -p victory-shader -- wave64_tests --test-threads=1 -> 6 passed; 0 failed.
  • cargo clippy -j 6 -p victory-shader --all-targets --no-deps -- -D warnings -> 0 warnings, exit 0.
  • cargo run -j 6 -p xtask -- policy -> asset policy: 175 files ok.

AI-assisted: ported to origin/main (f85101b), tested with dxil.dll validation, and written with AI assistance.

**@⁠sagouindupm** on GitHub · 2026-11-25 12:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/895) `sagouindupm:pixel-helper-lanes` → `main` · +198 −3 · 3 files · 1 commits · open Ports two complementary pixel-shader helper-lane fixes onto `main` (`f85101b`), both from `GPL-3.0-or-later` upstreams/forks: 1. **Quad reads in pixel shaders (`helpers_read`):** In `ds_swizzle_b32` and DPP instructions, pixel quad permutations (`quad`) now lower through `quad_pick` (`dx.op.quadReadLaneAt.i32`) instead of wave-wide `waveReadLaneAt`, regardless of whether the shader has `discard`s. At triangle edges, neighboring lanes of a 2x2 quad are helper lanes that quad reads see cleanly whereas wave reads exclude them. *(Adapted from `Belobug/VIctory-Belobug-AMD` commit `03629f3f`.)* 2. **Helper lanes in `v_readfirstlane_b32` (`helper_reads_own`):** Guard `v_readfirstlane_b32` results in pixel shaders with `dx.op.isHelperLane.i1` (SM 6.6 opcode `221`) so helper lanes read their own value instead of spinning when only helper lanes remain in a waterfall loop (`WaveReadLaneFirst` ignoring helper lanes). Computes remain unchanged. *(Ported from `Marvisak/VIctory` PR `#1733` / commit `0601955` by `Vax`.)* ### Summary of changes - **`crates/victory-shader/src/emit/lower.rs`:** Add `helpers_read` and `helper_reads_own`; apply `helpers_read(quad)` in `ds_swizzle_b32` and `dpp`, and wrap `v_readfirstlane_b32` results (including `VICTORY_FIRSTLANE_OWN=1` path) with `helper_reads_own`. - **`crates/victory-shader/src/emit/bitcode.rs` & `crates/victory-shader/src/emit/mod.rs`:** Expose `#[cfg(test)] Module::func_names()` and `Lowered::funcs`, and add unit tests `pixel_readfirstlane_uses_is_helper_lane_and_compute_does_not` and `pixel_quad_swizzle_without_discards_uses_quad_read_lane_at` validated through `dxil.dll`. ### Attribution - `Vax` / `Marvisak/VIctory` PR `#1733` (`0601955`, `GPL-3.0-or-later`) - `Belobug/VIctory-Belobug-AMD` commit `03629f3f` (`GPL-3.0-or-later`) ### Verification Run on Windows 11 Pro (x86_64-pc-windows-msvc, Rust 1.98.1, `dxil.dll` present): - `cargo test --release -j 6 -p victory-shader -- barycentric_tests --test-threads=1` -> **10 passed; 0 failed** (including both new tests + `dxil.dll` validation). - `cargo test --release -j 6 -p victory-shader -- waterfall_tests --test-threads=1` -> **all passed; 0 failed**. - `cargo test --release -j 6 -p victory-shader -- wave64_tests --test-threads=1` -> **6 passed; 0 failed**. - `cargo clippy -j 6 -p victory-shader --all-targets --no-deps -- -D warnings` -> **0 warnings, exit 0**. - `cargo run -j 6 -p xtask -- policy` -> **`asset policy: 175 files ok`**. AI-assisted: ported to `origin/main` (`f85101b`), tested with `dxil.dll` validation, and written with AI assistance.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:24 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 14:03 UTC · original

Ran this on AMD with 64-lane waves, since the description only has Windows test runs.

Setup: RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14, diagnostics build. Tree: f85101b merged into myokex/victory-amd, with #737 and #917, and this PR's f1d44b2 picked on top (no conflict).

  • Ten minutes from boot through the intro into the first room, no skip list: no device loss, no refused pipeline that the same tree without this PR doesn't also refuse, no error line.
  • Frame time is the same within noise: 275 ms median against 266 ms without it at about 4,800 draws a frame (another program was using the card during both runs, so don't read anything into the 9 ms).
  • I compared the same frame numbers of both runs in the first room by eye and saw no difference, so I can't show a before and after for the triangle edges here. If someone has a scene where the helper lanes show, tell me which and I'll capture it.

So nothing breaks on RADV with it; whether it fixes something visible I couldn't tell from these scenes.

**@⁠UwUCammie** on GitHub · 2026-11-25 14:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/895#issuecomment-7164683064) Ran this on AMD with 64-lane waves, since the description only has Windows test runs. Setup: RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14, diagnostics build. Tree: `f85101b` merged into myokex/victory-amd, with #737 and #917, and this PR's `f1d44b2` picked on top (no conflict). - Ten minutes from boot through the intro into the first room, no skip list: no device loss, no refused pipeline that the same tree without this PR doesn't also refuse, no error line. - Frame time is the same within noise: 275 ms median against 266 ms without it at about 4,800 draws a frame (another program was using the card during both runs, so don't read anything into the 9 ms). - I compared the same frame numbers of both runs in the first room by eye and saw no difference, so I can't show a before and after for the triangle edges here. If someone has a scene where the helper lanes show, tell me which and I'll capture it. So nothing breaks on RADV with it; whether it fixes something visible I couldn't tell from these scenes.
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 22:42 UTC · original

/kee review — the two fixes look right in isolation; what's missing is the measure of how much emission they change.

Scope. helpers_read(quad) returns quad && self.s.pixel, so mesh_quad || self.helpers_read(quad) now routes every pixel shader's ds_swizzle_b32 and DPP quad reads through quadReadLaneAt, not only shaders with discard. That is the intended fix, but it is a whole-pipeline change to emitted DXIL with no count of how many shaders change, and no before/after on a capture. #995 in this repo answers exactly this — "the emitted code changed for 18,136 of those previously valid shaders" — and that is the sentence this PR needs.

Second path. helper_reads_own is applied at both v_readfirstlane_b32 sites, including the non-waterfall one, so a pixel shader whose helper lanes read first-lane values outside a loop also changes. The module comment explains the waterfall loop; say why the general path is also right, or narrow it to the loop.

Tests. The body's -- barycentric_tests filter does match both new tests, so those counts are real. The oddity is the module name: quad swizzle and first-lane reads are not barycentric, so barycentric_tests is now a grab bag that hides them from anyone looking for first-lane coverage. The assertions themselves are good: func_names() is a real check that the intrinsic was declared, and validate through dxil.dll is the right gate.

Attribution to #1733/03629f3f is clear.

**@⁠HailLucifer666** on GitHub · 2026-11-25 22:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/895#issuecomment-7176700586) `/kee` review — the two fixes look right in isolation; what's missing is the measure of how much emission they change. **Scope.** `helpers_read(quad)` returns `quad && self.s.pixel`, so `mesh_quad || self.helpers_read(quad)` now routes **every** pixel shader's `ds_swizzle_b32` and DPP quad reads through `quadReadLaneAt`, not only shaders with `discard`. That is the intended fix, but it is a whole-pipeline change to emitted DXIL with no count of how many shaders change, and no before/after on a capture. #995 in this repo answers exactly this — "the emitted code changed for 18,136 of those previously valid shaders" — and that is the sentence this PR needs. **Second path.** `helper_reads_own` is applied at both `v_readfirstlane_b32` sites, including the non-waterfall one, so a pixel shader whose helper lanes read first-lane values outside a loop also changes. The module comment explains the waterfall loop; say why the general path is also right, or narrow it to the loop. **Tests.** The body's `-- barycentric_tests` filter does match both new tests, so those counts are real. The oddity is the module name: quad swizzle and first-lane reads are not barycentric, so `barycentric_tests` is now a grab bag that hides them from anyone looking for first-lane coverage. The assertions themselves are good: `func_names()` is a real check that the intrinsic was declared, and `validate` through `dxil.dll` is the right gate. Attribution to #1733/`03629f3f` is clear.
Author
Owner

@⁠gmankab on GitHub · 2026-11-26 08:01 UTC · original

I ported the original #1733 first-lane change to our Wine-free Linux branch, preserving Vax's author credit. The native regression translates a source-built pixel shader, checks for both the wave read and helper-lane test, and creates its host graphics pipeline. Microsoft’s DXIL validator and Vulkan validation accepted it on RADV and Lavapipe. This covers the first-lane change separately from the quad-read changes in this PR. Native test branch

In the headless Lavapipe title run, the last captured frame was 800 and still showed illustrated loading. Both the control and this build exited at the same title-side null write, roughly five minutes after launch. I have no open-world performance measurement from this experiment.

Tested-on: Radeon RX 6800 and Lavapipe, Fedora Linux 45, native vkd3d-proton with Vulkan validation
Assisted-by: gpt-6.2 sol xhigh

**@⁠gmankab** on GitHub · 2026-11-26 08:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/895#issuecomment-7186096498) I ported the original #1733 first-lane change to our Wine-free Linux branch, preserving Vax's author credit. The native regression translates a source-built pixel shader, checks for both the wave read and helper-lane test, and creates its host graphics pipeline. Microsoft’s DXIL validator and Vulkan validation accepted it on RADV and Lavapipe. This covers the first-lane change separately from the quad-read changes in this PR. [Native test branch](https://github.com/gmankab/marvisak-victory/tree/test/native-pixel-helper-lanes) In the headless Lavapipe title run, the last captured frame was 800 and still showed illustrated loading. Both the control and this build exited at the same title-side null write, roughly five minutes after launch. I have no open-world performance measurement from this experiment. Tested-on: Radeon RX 6800 and Lavapipe, Fedora Linux 45, native vkd3d-proton with Vulkan validation Assisted-by: gpt-6.2 sol xhigh
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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