shader: merge multiple loop back edges into one latch and raise pipeline stack #737

Open
powplusplus wants to merge 1 commit from upstream-pr/737 into main
powplusplus commented 2026-11-25 06:06:50 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by powplusplus on 2026-11-25T06:06:50Z.


Summary

Fixes vkd3d-proton hangs and stack overflows during D3D12 pipeline creation on large ray-tracing traversal shaders under Wine/Linux:

  1. Single latch per loop header (Module::single_latches): vkd3d-proton's DXIL-to-SPIR-V converter keeps a single back edge per loop header and treats additional back edges as forward edges, recursing indefinitely over the resulting cycle in shaders with wave shuffles. Module::single_latches() runs before Module::write() and routes any loop header with 2+ back edges through a single synthetic latch block that joins their phi values (matching DXC output).
  2. 256 MiB pipeline worker stack (PIPELINE_STACK): Large traversal shaders overflow the default 2 MiB thread stack during vkd3d-proton's recursive DXIL conversion; under Wine the overflow hangs the worker thread instead of failing. Both victory-gpu pipeline workers (pipeline/make.rs) and victory translate workers (apps/victory/src/translate.rs) now reserve a 256 MiB stack (pages committed on demand).

Verification

  • Unit tests: cargo test -p victory-shader --lib (172 passed, 0 failed, including new a_header_with_two_back_edges_gets_one test).
  • Windows-target clippy (victory-shader -- -D warnings) and workspace check clean on 8dd30ab.
  • Hardware test (NVIDIA RTX 3080 12 GB, GE-Proton11-14 / vkd3d-proton, VICTORY_HOST_MAX_WAVE=32): all 6 previously timing-out ray-tracing shadow shaders now validate with dxil.dll and create D3D12 pipelines (6/6 created, 0 timeouts).
  • Live in-game verification: 893 shaders translated in-game with 0 pipeline worker hangs or stack overflows.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6598357655 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/737). Originally posted by [powplusplus](https://github.com/powplusplus) on 2026-11-25T06:06:50Z. --- ## Summary Fixes vkd3d-proton hangs and stack overflows during D3D12 pipeline creation on large ray-tracing traversal shaders under Wine/Linux: 1. **Single latch per loop header (`Module::single_latches`)**: vkd3d-proton's DXIL-to-SPIR-V converter keeps a single back edge per loop header and treats additional back edges as forward edges, recursing indefinitely over the resulting cycle in shaders with wave shuffles. `Module::single_latches()` runs before `Module::write()` and routes any loop header with 2+ back edges through a single synthetic latch block that joins their phi values (matching DXC output). 2. **256 MiB pipeline worker stack (`PIPELINE_STACK`)**: Large traversal shaders overflow the default 2 MiB thread stack during vkd3d-proton's recursive DXIL conversion; under Wine the overflow hangs the worker thread instead of failing. Both `victory-gpu` pipeline workers (`pipeline/make.rs`) and `victory translate` workers (`apps/victory/src/translate.rs`) now reserve a 256 MiB stack (pages committed on demand). ## Verification - Unit tests: `cargo test -p victory-shader --lib` (172 passed, 0 failed, including new `a_header_with_two_back_edges_gets_one` test). - Windows-target clippy (`victory-shader -- -D warnings`) and workspace check clean on `8dd30ab`. - Hardware test (NVIDIA RTX 3080 12 GB, GE-Proton11-14 / vkd3d-proton, `VICTORY_HOST_MAX_WAVE=32`): all 6 previously timing-out ray-tracing shadow shaders now validate with `dxil.dll` and create D3D12 pipelines (6/6 created, 0 timeouts). - Live in-game verification: 893 shaders translated in-game with 0 pipeline worker hangs or stack overflows.
chatgpt-codex-connector[bot commented 2026-11-25 07:06:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T06:07:04Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T06:12:46.532839Z acd5702 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154458573 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/737#issuecomment-7154458573). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T06:07:04Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"acd5702c38775595901fc828dd1e58a140ff6860","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T06:12:46.532839Z">2026-11-25T06:12:46.532839Z</relative-time> | `acd5702` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
UwUCammie commented 2026-11-25 12:07:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T11:59:38Z.


Tested on AMD under Linux, since the description only has an NVIDIA result.

Setup: RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14, diagnostics build. Tree: main 9376fd6 merged into myokex/victory-amd, plus #857, myokex/victory-amd#6 and this PR picked on top.

Without this PR three compute pipelines never come back here: 559d9f0184e15fe3, a1b20bc47e3c9597, e8c962358d862e3f. Each keeps a worker busy until the run ends, so I have been skipping them with VICTORY_SKIP_PIPELINES.

With it, and no skip list, all three get a host pipeline. Two runs of about ten minutes each, from the start of the game into the first room (one with an empty shader cache, one warm). No hang, no device loss, and the picture of the first room is complete in both.

I didn't measure how long the three compiles take, and I haven't tried the two changes separately, so I can't say whether the latch or the bigger stack is what fixes it on this card.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7161776770 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/737#issuecomment-7161776770). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T11:59:38Z. --- Tested on AMD under Linux, since the description only has an NVIDIA result. Setup: RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22 with vkd3d-proton from GE-Proton11-14, diagnostics build. Tree: main `9376fd6` merged into myokex/victory-amd, plus #857, myokex/victory-amd#6 and this PR picked on top. Without this PR three compute pipelines never come back here: `559d9f0184e15fe3`, `a1b20bc47e3c9597`, `e8c962358d862e3f`. Each keeps a worker busy until the run ends, so I have been skipping them with `VICTORY_SKIP_PIPELINES`. With it, and no skip list, all three get a host pipeline. Two runs of about ten minutes each, from the start of the game into the first room (one with an empty shader cache, one warm). No hang, no device loss, and the picture of the first room is complete in both. I didn't measure how long the three compiles take, and I haven't tried the two changes separately, so I can't say whether the latch or the bigger stack is what fixes it on this card.
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/737:upstream-pr/737'
git switch 'upstream-pr/737'

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