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

Closed
JurajSimicevic wants to merge 4 commits from upstream-pr/2011 into main
JurajSimicevic commented 2026-11-29 07:13:40 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by JurajSimicevic on 2026-11-29T07:13:40Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5548541423 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011). Originally posted by [JurajSimicevic](https://github.com/JurajSimicevic) on 2026-11-29T07:13:40Z. --- 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)
ArturoWolff commented 2026-11-29 07:30:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ArturoWolff on 2026-11-29T07:30:34Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7252515598 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7252515598). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-29T07:30:34Z. --- 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).
JurajSimicevic commented 2026-11-29 09:54:16 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by JurajSimicevic on 2026-11-29T09:54:16Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254075477 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7254075477). Originally posted by [JurajSimicevic](https://github.com/JurajSimicevic) on 2026-11-29T09:54:16Z. --- 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 commented 2026-11-29 10:18:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by JurajSimicevic on 2026-11-29T10:18:22Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7254345520 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2011#issuecomment-7254345520). Originally posted by [JurajSimicevic](https://github.com/JurajSimicevic) on 2026-11-29T10:18:22Z. --- 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

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
trustno1-coder/VIctory-NVIDIA!2011
No description provided.