Shaders: a lane write or read finds its lane where not every lane runs (#111) #219

Open
github-bot wants to merge 2 commits from github-bot/gh-219 into main AGit
Owner

@⁠Alexr03 on GitHub · 2026-11-24 22:40 UTC · original
Alexr03:fix/writelane-outside-exec → main · +329 −0 · 4 files · 2 commits · open

Fixes #111. Overlaps with #119 and #139; see "How this differs" below.

What was wrong

v_writelane_b32 and v_readlane_b32 ignore EXEC on the console. The write was lowered as the lane's own, so it was lost when the lane named was outside EXEC or had left the block, and a later read gave the old value.

What the title's shaders actually do

Measured over the whole shader pack, translated for a 32-lane host:

  • 40 compute programs keep lane writes after unspill (5,423 writes). All 40 are 32-lane programs, and all are ray-tracing trace programs: shadowmask:CS_TraceShadowRays_*, rtdirectionalshadows:*, sr_tracing:CS_Raytrace*, the screen-probe tracers.
  • They keep a small array of scalars in the lanes of one VGPR: written by constant lane, read by a computed one (v_readlane_b32 s22, v29, s22). The VGPR is an ordinary temporary elsewhere, so unspill leaves it.
  • Every one of those writes has no guard and stands in a block that not every lane runs. The lane written is simply not there once it has left through an early-out.
  • No 64-lane program keeps a lane write. The 14 CS_ShadowRenderTiled* programs of #62 are not among the 40, so this is not what is wrong with them.

The change

  • A lane write, or a lane read of a VGPR that lane writes fill, in a block only some lanes run is refused there (LANE_ELSEWHERE), naming the block.
  • emit then has the wave take the branches around it together (widen), so every lane is present. Where the host's waves are the console's, as for all 40 programs, that costs no barrier. A console wave run as two host waves goes through its forms without skips instead.
  • Under a guard, the lane takes the scalar when some lane of the console wave is in EXEC, with or without its own bit. Two host waves of 32 exchange their answers.
  • If the branches cannot be taken together, the program is translated exactly as before (with_lanes_as_they_stand). No program stops translating.

How this differs from #119 and #139

Both fix the guarded write and the two-host-wave case, which is what the synthetic test in #111 exercises, and this PR does the same there. As far as I can tell from their descriptions, neither changes anything for a write with no guard in a program whose waves are the host's, which is all 40 programs in this title. This PR adds that route, the matching rule for reads, and the fallback. #139 asks for a run over a title's shaders; the numbers below are that run for this change.

The first commit is the failing test from #111's branch, by its author.

Results

RTX 5080 (32-lane waves), Windows 11.

before after
compute programs emitted, of 2,682 2,669 2,669
compute programs validated (dxil.dll) 2,669 2,669
of the 40: translate / validate / get a pipeline 36 / 36 / 36 36 / 36 / 36
of those 36: branches taken wave-wide 0 25
of those 36: translated as before 36 11
  • The 4 of the 40 that do not translate stop on "a descriptor read only as data", before and after.
  • The 11 left as before stop wave-wide on "a descriptor's address or format read as data" (10) and "a constant buffer's descriptor read as data" (1). VICTORY_WAVE_WHY=1 prints LANE-ELSEWHERE ... with the reason.
  • The 25 take 6 to 131 branches wave-wide each.

Tests, both run on the card:

  • a_lane_write_reaches_its_lane_outside_exec (no longer ignored): a console wave of 64 on a 32-lane host gives 5, 5, 7 in both forms without skips; as it is, the program is refused and handed to those forms.
  • a_lane_array_is_written_and_read_with_the_skip_wave_wide (new): a 32-lane wave with the trace programs' pattern, including the computed lane read and the fallback.

cargo test --workspace passes, cargo clippy -p victory-shader --all-targets is clean, cargo xtask policy is ok.

Not done

  • Not checked in the game. The 25 programs' GPU cost with their branches wave-wide is not measured, nor whether their results change. Ray tracing lights nothing yet.
  • Not run on a 64-lane card.
  • The expected values are the instruction's documented behaviour, not a console measurement.
  • The 11 programs left as before. Keeping the lanes of such a VGPR as scalars in ir::unspill would settle those too, at no cost per frame.
  • Under a guard, "the wave is here" is read as "some lane is in EXEC"; a wave that walks on with EXEC empty and no skip writes too on the console. Marked shortcut: in the code.

Details are in docs/fork-writelane-outside-exec.md. Nothing from the game is attached: counts and program names only.

**@⁠Alexr03** on GitHub · 2026-11-24 22:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/219) `Alexr03:fix/writelane-outside-exec` → `main` · +329 −0 · 4 files · 2 commits · open Fixes #111. Overlaps with #119 and #139; see "How this differs" below. ## What was wrong `v_writelane_b32` and `v_readlane_b32` ignore EXEC on the console. The write was lowered as the lane's own, so it was lost when the lane named was outside EXEC or had left the block, and a later read gave the old value. ## What the title's shaders actually do Measured over the whole shader pack, translated for a 32-lane host: - **40 compute programs** keep lane writes after `unspill` (5,423 writes). All 40 are **32-lane** programs, and all are ray-tracing trace programs: `shadowmask:CS_TraceShadowRays_*`, `rtdirectionalshadows:*`, `sr_tracing:CS_Raytrace*`, the screen-probe tracers. - They keep a small array of scalars in the lanes of one VGPR: written by constant lane, read by a computed one (`v_readlane_b32 s22, v29, s22`). The VGPR is an ordinary temporary elsewhere, so `unspill` leaves it. - **Every one of those writes has no guard and stands in a block that not every lane runs.** The lane written is simply not there once it has left through an early-out. - No 64-lane program keeps a lane write. The 14 `CS_ShadowRenderTiled*` programs of #62 are not among the 40, so this is not what is wrong with them. ## The change - A lane write, or a lane read of a VGPR that lane writes fill, in a block only some lanes run is refused there (`LANE_ELSEWHERE`), naming the block. - `emit` then has the wave take the branches around it together (`widen`), so every lane is present. Where the host's waves are the console's, as for all 40 programs, that costs no barrier. A console wave run as two host waves goes through its forms without skips instead. - Under a guard, the lane takes the scalar when some lane of the console wave is in EXEC, with or without its own bit. Two host waves of 32 exchange their answers. - If the branches cannot be taken together, the program is translated exactly as before (`with_lanes_as_they_stand`). No program stops translating. ## How this differs from #119 and #139 Both fix the guarded write and the two-host-wave case, which is what the synthetic test in #111 exercises, and this PR does the same there. As far as I can tell from their descriptions, neither changes anything for a write with no guard in a program whose waves are the host's, which is all 40 programs in this title. This PR adds that route, the matching rule for reads, and the fallback. #139 asks for a run over a title's shaders; the numbers below are that run for this change. The first commit is the failing test from #111's branch, by its author. ## Results RTX 5080 (32-lane waves), Windows 11. | | before | after | |---|---|---| | compute programs emitted, of 2,682 | 2,669 | 2,669 | | compute programs validated (`dxil.dll`) | 2,669 | 2,669 | | of the 40: translate / validate / get a pipeline | 36 / 36 / 36 | 36 / 36 / 36 | | of those 36: branches taken wave-wide | 0 | 25 | | of those 36: translated as before | 36 | 11 | - The 4 of the 40 that do not translate stop on "a descriptor read only as data", before and after. - The 11 left as before stop wave-wide on "a descriptor's address or format read as data" (10) and "a constant buffer's descriptor read as data" (1). `VICTORY_WAVE_WHY=1` prints `LANE-ELSEWHERE ...` with the reason. - The 25 take 6 to 131 branches wave-wide each. Tests, both run on the card: - `a_lane_write_reaches_its_lane_outside_exec` (no longer ignored): a console wave of 64 on a 32-lane host gives 5, 5, 7 in both forms without skips; as it is, the program is refused and handed to those forms. - `a_lane_array_is_written_and_read_with_the_skip_wave_wide` (new): a 32-lane wave with the trace programs' pattern, including the computed lane read and the fallback. `cargo test --workspace` passes, `cargo clippy -p victory-shader --all-targets` is clean, `cargo xtask policy` is ok. ## Not done - **Not checked in the game.** The 25 programs' GPU cost with their branches wave-wide is not measured, nor whether their results change. Ray tracing lights nothing yet. - Not run on a 64-lane card. - The expected values are the instruction's documented behaviour, not a console measurement. - The 11 programs left as before. Keeping the lanes of such a VGPR as scalars in `ir::unspill` would settle those too, at no cost per frame. - Under a guard, "the wave is here" is read as "some lane is in EXEC"; a wave that walks on with EXEC empty and no skip writes too on the console. Marked `shortcut:` in the code. Details are in `docs/fork-writelane-outside-exec.md`. Nothing from the game is attached: counts and program names only.
A synthetic wave64 program run on the card: a lane write inside a per-lane
branch whose target lane is not in EXEC is lost in every form, although the
instruction ignores EXEC. The test is ignored until the lowering is fixed;
docs/fork-writelane-outside-exec.md says how to reproduce it and what a fix
must do.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
v_writelane_b32 and v_readlane_b32 ignore EXEC on the console. The write was
lowered as the lane's own, so it was lost when the lane named was outside
EXEC or had left the block, and a later read gave the old value.

In this title's pack 40 compute programs keep lane writes after unspill, all
32-lane ray-tracing trace programs: a small array of scalars in the lanes of
one VGPR, written by constant lane and read by a computed one. Every such
write stands in a block only some lanes run.

A lane write, or a lane read of a VGPR that lane writes fill, in such a block
is now refused there, and emit has the wave take the branches around it
together (widen), so every lane is present; where the host's waves are the
console's that costs no barrier. Under a guard the lane takes the scalar when
some lane of the console wave is in EXEC; two host waves of 32 exchange their
answers. A program whose branches cannot be taken together is translated as
before, so none stops translating.

On the pack for a 32-lane host: 2,669 of 2,682 compute programs emitted and
validated before and after. Of the 40, 36 translate either way and get a
pipeline on an RTX 5080: 25 with their branches wave-wide, 11 as before.

The known-failure test is no longer ignored, and a second one covers the
32-lane pattern. Not checked in the game.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:42 +00:00
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 06:56 UTC · original

Offline check on the retail shader pack: no program gained or lost, but 25 programs' DXIL changes.

victory translate --validate --list over the title's full shader pack (26,084 programs) on an RTX 5090, main 310c6eb against this head merged onto it. I added a local DXIL hash on each validated line (two runs of one build hash the same):

  • Validated: 25,382 in both, none lost.
  • DXIL: 25 of those programs emit different DXIL. So this changes the code of that many of the title's shaders, and they all still pass the validator.

I have not looked at what changes in them or checked it in game.

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

**@⁠JRamos1993** on GitHub · 2026-11-25 06:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/219#issuecomment-7155316819) **Offline check on the retail shader pack: no program gained or lost, but 25 programs' DXIL changes.** `victory translate --validate --list` over the title's full shader pack (26,084 programs) on an RTX 5090, `main` `310c6eb` against this head merged onto it. I added a local DXIL hash on each validated line (two runs of one build hash the same): - **Validated:** 25,382 in both, none lost. - **DXIL:** **25** of those programs emit different DXIL. So this changes the code of that many of the title's shaders, and they all still pass the validator. I have not looked at what changes in them or checked it in game. AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 19:29 UTC · original

RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main d510ee4: both new tests pass on the card with this PR. No other test changed. Run table: #129 (#129).

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 19:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/219#issuecomment-7172380960) RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main `d510ee4`: both new tests pass on the card with this PR. No other test changed. Run table: #129 (https://git.gtahub.st/github/fxceless--victory-fork/pulls/129).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.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/219/head:github-bot/gh-219'
git switch 'github-bot/gh-219'

Merge

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