Shaders: wave64 compute as one host wave of two lanes per thread; heap buffer descriptors read as numbers #2011

Closed
github-bot wants to merge 4 commits from github-bot/gh-2011 into main AGit
Owner

@⁠JurajSimicevic on GitHub · 2026-11-29 07:13 UTC · original
JurajSimicevic:idea-a/two-slots → main · +2647 −16 · 11 files · 4 commits · closed without merging

On hosts with 32-lane waves (NVIDIA), a console wave64 compute program either runs as two host waves that meet at group barriers or, where no such form translates, as two independent half-waves (approximate). If neither works, it is refused and its dispatches are dropped. This PR adds an exact form that needs no barriers: two slots.

How it works

crates/victory-shader/src/two_slots.rs rewrites the machine code of a wave64 compute program whose thread group is whole console waves (64-1024 threads) into an equivalent wave32 program. Host thread h runs console lanes h and 32+h. The rest of the translator then sees an ordinary wave32 program.

  • Slot 0 keeps v0..vV-1 and the low dwords of the lane masks. Slot 1 uses v(V+n) and the high dwords. EXEC's high dword lives in a free SGPR (or a ttmp).
  • Each vector instruction runs once per slot. Slot 1 runs with EXEC's high dword swapped into exec_lo by s_mov only, so SCC is untouched. Runs of VGPR-only instructions share one swap.
  • 64-bit SALU bit operations (mov/cselect/logic, saveexec/wrexec, wqm) become two 32-bit ones, with SCC recomputed. Branches on EXEC/VCC test both halves.
  • Cross-lane instructions: readlane, readfirstlane, writelane (constant or SGPR lane), mbcnt and ds_bpermute pick the slot. DPP, permlane and ds_swizzle stay within a slot.
  • Constant tables in code (s_getpc) are kept after the rewrite. Branches out of 16-bit range become far jumps that keep SCC.
  • The result is structured with every mask branch wave-wide, as the console runs it. One host wave holds a console wave, so no group barrier is needed.

It is tried after the existing barrier forms and before anything approximate. VICTORY_TWO_SLOTS=0 turns it off; the switch is part of the shader cache key.

Supporting changes in lowering:

  • With two slots, the whole-wave section simulation and counted are off.
  • A mask read as a number is allowed where every lane is present.
  • s_wqm is exact via quad reads.
  • permlane accepts OP_SEL[3].
  • Resource tracking: copy propagation falls back to a monotone pass when the optimistic one does not settle (programs that settled before are unchanged), and equal compares count as one condition.

Also: buffers picked from the heap and read as numbers

Five compute programs (the shadow-ray tracer among them) pick a buffer descriptor from the resource heap by a computed index and read its dwords only as numbers. Before this PR they were refused ("a descriptor read only as data"). The host's per-slot table (SLOT_STRIDES) now also holds the first three V# dwords of each buffer view (SLOT_BUFFER_WORDS: address, high bits with stride, records). All five now translate. A program that reads dword 3 is still refused.

Results (game build 1.0.2.1, RTX 5080, translate with VICTORY_HOST_MAX_WAVE=32)

  • Wave64 compute programs that were approximate or refused: 79 -> 7 left.
    • Approximate: 41 -> 5.
    • Refused: 38 -> 2.
    • The other wave64 programs keep their form.
  • Left: 5 need more than 2 x 128 VGPRs; 1 waterfall descriptor (a per-lane descriptor written under EXEC); 1 other.
  • 18 new GPU tests (emit/two_slots_tests.rs) run on the card and check the console's results. They cover lane branches and loops, LDS across slots without a barrier, readfirstlane with slot 0 empty, mask-as-number, 2-D and multi-wave groups, bpermute, writelane, wqm, code tables, and far jumps. An f16 tree sum matches bit for bit with VICTORY_F16_NEAREST=1. The full suite passes (366 + host descriptor tests).
  • In game (2 sessions after -Preload):
    • No crash, ~21 fps (as before).
    • The player noticed fewer graphical glitches and less stutter.
    • Sun shadows are clean.

Known issues

  • One host pipeline is refused by the driver with E_OUTOFMEMORY (a weather-particle update program). It started with the far-jump commit, so it is probably one of the largest two-slot rewrites. A size limit for the rewrite (fall back to the old form) is the likely fix; not done yet.
  • cargo xtask policy flags emit/lower.rs for size. The file was already over the 640 KB limit before this PR (667 KB -> 673 KB).
  • The first start with an empty pipeline cache can trip the title's 30 s stall watchdog. This also happens without this PR; -Preload avoids it.

AI-assisted.

🤖 Generated with Claude Code

**@⁠JurajSimicevic** on GitHub · 2026-11-29 07:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011) `JurajSimicevic:idea-a/two-slots` → `main` · +2647 −16 · 11 files · 4 commits · closed without merging On hosts with 32-lane waves (NVIDIA), a console wave64 compute program either runs as two host waves that meet at group barriers or, where no such form translates, as two independent half-waves (approximate). If neither works, it is refused and its dispatches are dropped. This PR adds an exact form that needs no barriers: **two slots**. ## How it works `crates/victory-shader/src/two_slots.rs` rewrites the machine code of a wave64 compute program whose thread group is whole console waves (64-1024 threads) into an equivalent wave32 program. Host thread h runs console lanes h and 32+h. The rest of the translator then sees an ordinary wave32 program. - Slot 0 keeps v0..vV-1 and the low dwords of the lane masks. Slot 1 uses v(V+n) and the high dwords. EXEC's high dword lives in a free SGPR (or a ttmp). - Each vector instruction runs once per slot. Slot 1 runs with EXEC's high dword swapped into exec_lo by `s_mov` only, so SCC is untouched. Runs of VGPR-only instructions share one swap. - 64-bit SALU bit operations (mov/cselect/logic, saveexec/wrexec, wqm) become two 32-bit ones, with SCC recomputed. Branches on EXEC/VCC test both halves. - Cross-lane instructions: readlane, readfirstlane, writelane (constant or SGPR lane), mbcnt and ds_bpermute pick the slot. DPP, permlane and ds_swizzle stay within a slot. - Constant tables in code (s_getpc) are kept after the rewrite. Branches out of 16-bit range become far jumps that keep SCC. - The result is structured with every mask branch wave-wide, as the console runs it. One host wave holds a console wave, so no group barrier is needed. It is tried after the existing barrier forms and before anything approximate. `VICTORY_TWO_SLOTS=0` turns it off; the switch is part of the shader cache key. Supporting changes in lowering: - With two slots, the whole-wave section simulation and `counted` are off. - A mask read as a number is allowed where every lane is present. - `s_wqm` is exact via quad reads. - permlane accepts OP_SEL[3]. - Resource tracking: copy propagation falls back to a monotone pass when the optimistic one does not settle (programs that settled before are unchanged), and equal compares count as one condition. ## Also: buffers picked from the heap and read as numbers Five compute programs (the shadow-ray tracer among them) pick a buffer descriptor from the resource heap by a computed index and read its dwords only as numbers. Before this PR they were refused ("a descriptor read only as data"). The host's per-slot table (`SLOT_STRIDES`) now also holds the first three V# dwords of each buffer view (`SLOT_BUFFER_WORDS`: address, high bits with stride, records). All five now translate. A program that reads dword 3 is still refused. ## Results (game build 1.0.2.1, RTX 5080, `translate` with `VICTORY_HOST_MAX_WAVE=32`) - Wave64 compute programs that were approximate or refused: **79 -> 7 left**. - Approximate: 41 -> 5. - Refused: 38 -> 2. - The other wave64 programs keep their form. - Left: 5 need more than 2 x 128 VGPRs; 1 waterfall descriptor (a per-lane descriptor written under EXEC); 1 other. - 18 new GPU tests (`emit/two_slots_tests.rs`) run on the card and check the console's results. They cover lane branches and loops, LDS across slots without a barrier, readfirstlane with slot 0 empty, mask-as-number, 2-D and multi-wave groups, bpermute, writelane, wqm, code tables, and far jumps. An f16 tree sum matches bit for bit with `VICTORY_F16_NEAREST=1`. The full suite passes (366 + host descriptor tests). - In game (2 sessions after `-Preload`): - No crash, ~21 fps (as before). - The player noticed fewer graphical glitches and less stutter. - Sun shadows are clean. ## Known issues - **One host pipeline is refused by the driver with E_OUTOFMEMORY** (a weather-particle update program). It started with the far-jump commit, so it is probably one of the largest two-slot rewrites. A size limit for the rewrite (fall back to the old form) is the likely fix; not done yet. - `cargo xtask policy` flags `emit/lower.rs` for size. The file was already over the 640 KB limit before this PR (667 KB -> 673 KB). - The first start with an empty pipeline cache can trip the title's 30 s stall watchdog. This also happens without this PR; `-Preload` avoids it. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On hosts of 32-lane waves, a console wave of 64 ran as two host waves that meet at group
barriers or, where no such form translated, as two half-waves that do not exchange
(approximate) or not at all. `two_slots` rewrites such a program, whose thread group is
whole console waves, into an equivalent wave32 program: thread h runs the console's lanes h
and 32 + h. Vector instructions run once per slot (slot 1 with its VGPRs moved and EXEC's
high dword swapped into exec_lo by s_mov). 64-bit operations on masks become two 32-bit ones.
Branches on EXEC or VCC test both dwords. readlane, readfirstlane, mbcnt, bpermute and
writelane pick the slot. The rest of the translator sees an ordinary wave32 program,
structured with its mask branches wave-wide.

It is tried after the barrier forms and before anything approximate. VICTORY_TWO_SLOTS=0
turns it off; the switch is part of the shader cache key. Lowering of such programs: no
whole-wave section simulation (every lane is at every instruction), masks as numbers where
every lane is present, an exact s_wqm, and permlane with OP_SEL[3].

On the game's 26,177 programs (32-lane host), 64 of the 79 wave64 compute programs that
were approximate or refused now translate exactly (approximate 41 -> 13, refused 38 -> 2).
The other wave64 programs are unchanged. 17 tests run on the GPU (RTX 5080) and give the
console's results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A program of two slots can be past the 16-bit reach of a branch. Such branches become far
jumps (s_getpc, s_add, s_addc, s_setpc, the form the decoder follows), behind the opposite
branch when conditional. They land on a pad before the target that sets SCC again from a
copy taken before the jump. The console's own far jumps become branches to their target.

On the game's programs (32-lane host): 70 of the 79 wave64 compute programs that were
approximate or refused now translate exactly (approximate 41 -> 7, refused 38 -> 2). Five
of the rest need more than 2 x 128 VGPRs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copy propagation could go round without settling on a program of two slots: a phi took its
own origin and then its arguments' again, round after round (the copies of EXEC's high
dword kept around its loops). When the optimistic rounds do not settle, they are run again
with a phi that has become its own origin staying so. That always settles, with no more
copies found than are certain. Programs that settled before are tracked as before.

A descriptor picked by selects counts one condition where the compares behind them are
the same (one compare per dword, as two slots read a descriptor from the first lane). An
SCC kept in an SGPR and set again from it is the SCC it kept.

Two more of the game's wave64 compute programs translate exactly in two slots: 72 of 79.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Five of the game's compute programs (the shadow-ray tracer among them) pick a buffer's
descriptor from the resource heap by an index they compute and read its dwords only as
numbers: the buffer's address and records, to reach it by address. They did not translate
("a descriptor read only as data"), so their dispatches were dropped.

The host's table by view heap slot (SLOT_STRIDES) now holds, past the strides, four dwords
a slot: a buffer view's first three dwords as the console's buffer descriptor has them
(SLOT_BUFFER_WORDS: the title address, its high bits with the stride, the records), written
with the view. Such a program reads them by the slot it computes. A program that reads the
fourth dword (format and channel selects, which the host does not keep) is still refused.

All five now translate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 07:16:11 +00:00
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-29 07:30 UTC · original · edited 2026-11-29 08:16 UTC

Independent game-free validation of the original PR head f49427e2115852ebf1ce7f01d18f7cfb76069041 (clean detached checkout, not rebased onto current main). Thank you for the synthetic fixtures.

Host: desktop RTX 4060 8 GB, 16 GB RAM, Linux, NVIDIA 620.73.04, GE-Proton11-14 / vkd3d-proton 3.2.0 (cae8353ed7959c4+). Rust 1.98.1, locked MSVC release shader-library test executable. No game files mounted. VICTORY_F16_NEAREST=1 as in the PR description.

emit::two_slots_tests:: with --nocapture --test-threads=1: 18 passed, 0 failed, 0 ignored, 356 filtered out; 26.87 s. All 18 distinct test names were present, and Windows child and outer supervisor exited 0. I checked the complete console output for the shared helper’s explicit not run diagnostic on device/pipeline initialization failure; there were zero such lines. The runtime enumerated the physical RTX 4060 and llvmpipe, logged software-driver exclusion, and emitted 53 vkd3d initialization records. No host guard or kernel fault occurred.

This supports the GPU readback assertions in the provided direct-rewrite synthetic fixtures on a second NVIDIA generation under Proton. It does not establish that the complete production selection path, numeric buffer-descriptor changes, optional DXIL validator, or every title shader has been exercised. Nor does it resolve the reported large-pipeline allocation failure, prove correct gameplay, or demonstrate an FPS gain. The unmerged head still needs integration qualification against current main.

Integration follow-up (compile-only): I also made an isolated, uncommitted merge of the exact PR head onto e1f2eb60492d94dd0230606b453ba82b34e1b98d. Git reported two conflicts, in shader_cache.rs and emit/mod.rs. The resolution preserved main's existing cache switches and fallback/selection machinery and included the new switch/export. Both locked offline MSVC release library test builds (victory-shader and victory-gpu, --no-run) completed successfully. No integrated executable was run.

There are still integration questions before I would consider this candidate for execution: partial-dispatch/counting semantics, production route-selection tests, complete descriptor metadata lifecycle coverage, and the unconditional extra 32 MiB metadata table per non-sampler heap. The two-slots switch controls selection, not all independent changes in the PR, so switch-off alone is not an isolated A/B of the complete diff. Is a current-main rebase or separation of the shader rewrite from the descriptor extension planned? These are review concerns, not demonstrated runtime failures on the merged build. The original 18/18 fixture result above remains valid for the pinned original head only.

Narrow integration follow-up: The first three commits, through 60c7fbaf6eb481af9eb78fb1574f8bc6a1af95d1, can be integrated separately from the last descriptor-extension commit. In an isolated uncommitted candidate on the same main e1f2eb6, I retained the current cache keys, added the new key, and conservatively excluded counted-dispatch cases from the new rewrite route pending a complete partial-group correctness contract. The original counted lowering remains available. A native synthetic eligibility regression failed before this change and both the refusal and matched ordinary acceptance cases passed after it (2/2).

The narrow candidate's both library test builds also completed. On the same RTX 4060/GE-Proton11-14 setup as above, the byte-identical 18 incoming direct-rewrite fixtures returned 18 passed, 0 failed, 0 ignored, 405 filtered out, 26.82 s, no not run markers, child/outer exit 0, 53 SM 6.6 initialization records and software-driver exclusion. No game files mounted or guard/kernel fault. This verifies that the direct synthetic outputs survived our narrow integration; it is not a test of the full PR, the complete production selection path, switch-off equivalence, optional validator, or actual gameplay. I am retaining this as a diagnostic candidate, not recommending deployment yet.

Production selector follow-up (synthetic, CPU-only): Added an isolated integration test using three authored wave-OR fixtures through the ordinary public shader-emission path, with a host wave size of 32. Three native tests passed; separately ran six candidate and three baseline fresh-process comparisons. The noncounted SCC case selected the new form and emitted a 32×1×1 group instead of the baseline's 64×1×1 (the positive assertion deliberately failed on main). The case already handled by the earlier exact route retained the identical emitted record. The counted case declined the new rewrite and retained its original fallback and dispatch-count binding. Complete emitted HostShader records matched exact main for all three inputs when the new switch was off. The MSVC test executable also compiled, but was not executed. These checks qualify selection and limited switch-off parity, not the numerical correctness of the existing counted fallback, all independently changed lowering paths, cache isolation, or in-game rendering. No gameplay performance claim.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).

**@⁠ArturoWolff** on GitHub · 2026-11-29 07:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7252515598) · edited 2026-11-29 08:16 UTC Independent game-free validation of the original PR head `f49427e2115852ebf1ce7f01d18f7cfb76069041` (clean detached checkout, not rebased onto current main). Thank you for the synthetic fixtures. **Host:** desktop RTX 4060 8 GB, 16 GB RAM, Linux, NVIDIA 620.73.04, GE-Proton11-14 / vkd3d-proton 3.2.0 (`cae8353ed7959c4+`). Rust 1.98.1, locked MSVC release shader-library test executable. No game files mounted. `VICTORY_F16_NEAREST=1` as in the PR description. `emit::two_slots_tests::` with `--nocapture --test-threads=1`: **18 passed, 0 failed, 0 ignored, 356 filtered out; 26.87 s**. All 18 distinct test names were present, and Windows child and outer supervisor exited 0. I checked the complete console output for the shared helper’s explicit `not run` diagnostic on device/pipeline initialization failure; there were **zero** such lines. The runtime enumerated the physical RTX 4060 and llvmpipe, logged software-driver exclusion, and emitted 53 vkd3d initialization records. No host guard or kernel fault occurred. This supports the GPU readback assertions in the provided direct-rewrite synthetic fixtures on a second NVIDIA generation under Proton. It does not establish that the complete production selection path, numeric buffer-descriptor changes, optional DXIL validator, or every title shader has been exercised. Nor does it resolve the reported large-pipeline allocation failure, prove correct gameplay, or demonstrate an FPS gain. The unmerged head still needs integration qualification against current main. **Integration follow-up (compile-only):** I also made an isolated, uncommitted merge of the exact PR head onto `e1f2eb60492d94dd0230606b453ba82b34e1b98d`. Git reported two conflicts, in `shader_cache.rs` and `emit/mod.rs`. The resolution preserved main's existing cache switches and fallback/selection machinery and included the new switch/export. Both locked offline MSVC release library test builds (`victory-shader` and `victory-gpu`, `--no-run`) completed successfully. No integrated executable was run. There are still integration questions before I would consider this candidate for execution: partial-dispatch/counting semantics, production route-selection tests, complete descriptor metadata lifecycle coverage, and the unconditional extra 32 MiB metadata table per non-sampler heap. The two-slots switch controls selection, not all independent changes in the PR, so switch-off alone is not an isolated A/B of the complete diff. Is a current-main rebase or separation of the shader rewrite from the descriptor extension planned? These are review concerns, not demonstrated runtime failures on the merged build. The original 18/18 fixture result above remains valid for the pinned original head only. **Narrow integration follow-up:** The first three commits, through `60c7fbaf6eb481af9eb78fb1574f8bc6a1af95d1`, can be integrated separately from the last descriptor-extension commit. In an isolated uncommitted candidate on the same main `e1f2eb6`, I retained the current cache keys, added the new key, and conservatively excluded counted-dispatch cases from the new rewrite route pending a complete partial-group correctness contract. The original counted lowering remains available. A native synthetic eligibility regression failed before this change and both the refusal and matched ordinary acceptance cases passed after it (2/2). The narrow candidate's both library test builds also completed. On the same RTX 4060/GE-Proton11-14 setup as above, the byte-identical 18 incoming direct-rewrite fixtures returned **18 passed, 0 failed, 0 ignored, 405 filtered out, 26.82 s**, no `not run` markers, child/outer exit 0, 53 SM 6.6 initialization records and software-driver exclusion. No game files mounted or guard/kernel fault. This verifies that the direct synthetic outputs survived our narrow integration; it is not a test of the full PR, the complete production selection path, switch-off equivalence, optional validator, or actual gameplay. I am retaining this as a diagnostic candidate, not recommending deployment yet. **Production selector follow-up (synthetic, CPU-only):** Added an isolated integration test using three authored wave-OR fixtures through the ordinary public shader-emission path, with a host wave size of 32. Three native tests passed; separately ran six candidate and three baseline fresh-process comparisons. The noncounted SCC case selected the new form and emitted a 32×1×1 group instead of the baseline's 64×1×1 (the positive assertion deliberately failed on main). The case already handled by the earlier exact route retained the identical emitted record. The counted case declined the new rewrite and retained its original fallback and dispatch-count binding. Complete emitted `HostShader` records matched exact main for all three inputs when the new switch was off. The MSVC test executable also compiled, but was not executed. These checks qualify selection and limited switch-off parity, not the numerical correctness of the existing counted fallback, all independently changed lowering paths, cache isolation, or in-game rendering. No gameplay performance claim. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High).
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-29 09:54 UTC · original

Thanks for the independent run on a 4060 under Proton and for the trial merge, that's very helpful.

I'm out of my AI usage budget until Thursday, so I can't act on this before then. Plan for Thursday:

  • rebase onto current main;
  • split into two PRs: the two-slot rewrite, and the heap buffer-descriptor words (so VICTORY_TWO_SLOTS=0 is a clean A/B of the first);
  • allocate the extra per-slot table only when a translated shader asks for it, instead of always;
  • add a size limit for the rewrite (fall back to the previous form) for the pipeline the driver refuses;
  • answer the counting/partial-dispatch and route-selection test questions.

AI-assisted.

**@⁠JurajSimicevic** on GitHub · 2026-11-29 09:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7254075477) Thanks for the independent run on a 4060 under Proton and for the trial merge, that's very helpful. I'm out of my AI usage budget until Thursday, so I can't act on this before then. Plan for Thursday: - rebase onto current main; - split into two PRs: the two-slot rewrite, and the heap buffer-descriptor words (so `VICTORY_TWO_SLOTS=0` is a clean A/B of the first); - allocate the extra per-slot table only when a translated shader asks for it, instead of always; - add a size limit for the rewrite (fall back to the previous form) for the pipeline the driver refuses; - answer the counting/partial-dispatch and route-selection test questions. AI-assisted.
github-bot closed this pull request 2026-11-29 10:22:56 +00:00
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-29 10:18 UTC · original

Closing: main already has fold.rs (8f0a0c24, landed the day before this PR), the same two-lanes-per-host-lane approach. It covers more: VGPRs past 255, and descriptors read as data. Measured on the game's shaders with a 32-lane host, current main leaves 4 approximate and 1 refused wave64 compute program, against 5 and 2 here, and tracks resources for all programs. This branch was built on a base 1420 commits old; my mistake for not rebasing before opening it.

Thanks @⁠ArturoWolff for the independent run and the trial merge.

AI-assisted.

**@⁠JurajSimicevic** on GitHub · 2026-11-29 10:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7254345520) Closing: main already has `fold.rs` (8f0a0c24, landed the day before this PR), the same two-lanes-per-host-lane approach. It covers more: VGPRs past 255, and descriptors read as data. Measured on the game's shaders with a 32-lane host, current main leaves 4 approximate and 1 refused wave64 compute program, against 5 and 2 here, and tracks resources for all programs. This branch was built on a base 1420 commits old; my mistake for not rebasing before opening it. Thanks @⁠ArturoWolff for the independent run and the trial merge. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2011
No description provided.