shader: queue transitive fold users once per round #1585

Closed
github-bot wants to merge 1 commit from gh-pr/1585/head into gh-pr/1585/base
Owner

@⁠NeySlim on GitHub · 2026-10-17 08:01 UTC · original
NeySlim:perf/fold-worklist → main · +60 −8 · 3 files · 1 commits · closed without merging

Problem

In God of War Ragnarök (PPSA08332, 05.005) the game stops rendering for about 135 s during the sled sequence. The GPU command thread is busy translating compute shaders, and almost all of that time is in ConstantPropagationPass, in FoldWorklist::QueueUsers.

Since df08b8328, every fold that changes an instruction walks the whole transitive closure of its users. The walk runs once per change, even when nearly every visited instruction is already queued. In a large shader one fold near the top revisits the rest of the program, and there are thousands of folds, so the pass is quadratic in practice. The stall is not one shader: about 50 compute shader translations of 1 to 4.4 s each (each hash is translated 9 times), plus pixel shaders.

Change

A change now only records its direct users. Once the current round of the worklist (what was queued when the round started) has been processed, a single walk queues the transitive users of all of that round's changes, visiting each instruction once.

Coverage is unchanged: every transitive user of a change is still revisited, including cyclic Phi edges, and nothing is capped or depth-limited. Only the number of walks changes, from one per change to one per round.

Test

  • New TestConstantPropagationSharedUsers in shaderCfgTests.cpp: a chain of 4096 dynamic XORs where each link has an identity fold, so every fold has the rest of the chain as transitive users. It checks the folded chain and that the pass revisits at most 2 users per link (ConstantPropagationStats::revisited_users, returned by the pass). With this change it revisits 1 per link; without it the check fails.
  • ctest: shader_cfg passes; the other failures (GPU tests on this RADV setup) are the same as on main.
  • shader_recompiler_compute_tests, one case per process: 779 cases, the same 52 failures as main, no new failure.

Validation

Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4.

Translation output: I dumped the translation inputs (code, user data, stage input info) of every shader translated during a run from the menu to the Freya fight (1913 translations, CS/PS/VS) and replayed them offline with main and with this branch. The IR dump after translation and the SPIR-V are byte-identical for all of them. Same result on a second, shorter set of 345 translations.

Translation time, same replay, single thread:

main this PR
Slowest compute shader (0x2bbe19f271202135) 3.9 to 4.4 s 0.10 to 0.14 s
All 261 translations of the sled sequence 143.8 s 11.1 s
... compute shaders only 110.3 s 3.9 s

In game: new game from the menu, same scripted inputs, frame count from a uprobe on GuestGpu::SuspendPoint. Main and this branch both have #1165 merged (main alone stops earlier in this game).

Sled sequence main this PR
Seconds without a single frame 134 / 135 3 / 0 / 3
Average fps over the sequence 2.26 / 2.25 7.46 / 7.39 / 7.37
Average fps outside the stall 7.66 / 7.76 7.58 / 7.39 / 7.49

The opening cutscene is unchanged (8.6 against 8.8 fps). With this change, a few stalls of 3 to 12 s remain later in the run; a profile of the GPU thread puts them in TrackResources and MaterializeResources, not in constant propagation.

Not tested on Windows/macOS; the change is platform-independent.

AI use

I used Claude Code (AI agent) to profile the stall, write the change and the test, build the dump/replay check and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-17 08:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585) `NeySlim:perf/fold-worklist` → `main` · +60 −8 · 3 files · 1 commits · closed without merging ## Problem In God of War Ragnarök (PPSA08332, 05.005) the game stops rendering for about 135 s during the sled sequence. The GPU command thread is busy translating compute shaders, and almost all of that time is in `ConstantPropagationPass`, in `FoldWorklist::QueueUsers`. Since df08b8328, every fold that changes an instruction walks the whole transitive closure of its users. The walk runs once per change, even when nearly every visited instruction is already queued. In a large shader one fold near the top revisits the rest of the program, and there are thousands of folds, so the pass is quadratic in practice. The stall is not one shader: about 50 compute shader translations of 1 to 4.4 s each (each hash is translated 9 times), plus pixel shaders. ## Change A change now only records its direct users. Once the current round of the worklist (what was queued when the round started) has been processed, a single walk queues the transitive users of all of that round's changes, visiting each instruction once. Coverage is unchanged: every transitive user of a change is still revisited, including cyclic Phi edges, and nothing is capped or depth-limited. Only the number of walks changes, from one per change to one per round. ## Test - New `TestConstantPropagationSharedUsers` in `shaderCfgTests.cpp`: a chain of 4096 dynamic XORs where each link has an identity fold, so every fold has the rest of the chain as transitive users. It checks the folded chain and that the pass revisits at most 2 users per link (`ConstantPropagationStats::revisited_users`, returned by the pass). With this change it revisits 1 per link; without it the check fails. - `ctest`: `shader_cfg` passes; the other failures (GPU tests on this RADV setup) are the same as on main. - `shader_recompiler_compute_tests`, one case per process: 779 cases, the same 52 failures as main, no new failure. ## Validation Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4. Translation output: I dumped the translation inputs (code, user data, stage input info) of every shader translated during a run from the menu to the Freya fight (1913 translations, CS/PS/VS) and replayed them offline with main and with this branch. The IR dump after translation and the SPIR-V are byte-identical for all of them. Same result on a second, shorter set of 345 translations. Translation time, same replay, single thread: | | main | this PR | |---|---|---| | Slowest compute shader (0x2bbe19f271202135) | 3.9 to 4.4 s | 0.10 to 0.14 s | | All 261 translations of the sled sequence | 143.8 s | 11.1 s | | ... compute shaders only | 110.3 s | 3.9 s | In game: new game from the menu, same scripted inputs, frame count from a uprobe on `GuestGpu::SuspendPoint`. Main and this branch both have #1165 merged (main alone stops earlier in this game). | Sled sequence | main | this PR | |---|---|---| | Seconds without a single frame | 134 / 135 | 3 / 0 / 3 | | Average fps over the sequence | 2.26 / 2.25 | 7.46 / 7.39 / 7.37 | | Average fps outside the stall | 7.66 / 7.76 | 7.58 / 7.39 / 7.49 | The opening cutscene is unchanged (8.6 against 8.8 fps). With this change, a few stalls of 3 to 12 s remain later in the run; a profile of the GPU thread puts them in `TrackResources` and `MaterializeResources`, not in constant propagation. Not tested on Windows/macOS; the change is platform-independent. ## AI use I used Claude Code (AI agent) to profile the stall, write the change and the test, build the dump/replay check and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:58 +00:00
github-bot closed this pull request 2026-11-26 10:00:58 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 08:05 UTC · original · edited 2026-10-17 08:38 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: afc10a0d-4698-4916-afca-87ad5983980f
📥 Commits

Reviewing files that changed from the base of the PR and between d4abdf5f37773c66003e9ddb37baf1baa02b6258 and 8dafd56455.

📒 Files selected for processing: 3
  • src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp
  • src/graphics/shader/recompiler/ir/passes/ConstantPropagation.h
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The constant propagation pass now processes pending instructions in rounds and queues affected consumers at round boundaries. It returns a ConstantPropagationStats value with the count of revisited users. A regression test checks dependencies in a 4,096-link XOR chain and asserts that the revisit count is at most twice the chain length.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8dafd

The slow-runner test failure has been removed, and no remaining issue is established. The change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: queuing transitive fold users once per worklist round.
Description check Passed The description directly explains the performance problem, implementation change, test coverage, validation results, and platform scope.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 08:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#issuecomment-6231536905) · edited 2026-10-17 08:38 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1585?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `afc10a0d-4698-4916-afca-87ad5983980f` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between d4abdf5f37773c66003e9ddb37baf1baa02b6258 and 8dafd56455b96e776d426234292eb5fd2a969288. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 3</strong></summary> <dl> <dd> * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp` * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.h` * `tests/shaderCfgTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The constant propagation pass now processes pending instructions in rounds and queues affected consumers at round boundaries. It returns a `ConstantPropagationStats` value with the count of revisited users. A regression test checks dependencies in a 4,096-link XOR chain and asserts that the revisit count is at most twice the chain length. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"8dafd56455b96e776d426234292eb5fd2a969288" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>8dafd</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `8dafd` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8dafd56455b96e776d426234292eb5fd2a969288","coveredCommitId":"8dafd56455b96e776d426234292eb5fd2a969288","kind":"reviewed"} --> The slow-runner test failure has been removed, and no remaining issue is established. The change is mergeable after normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: queuing transitive fold users once per worklist round. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the performance problem, implementation change, test coverage, validation results, and platform scope. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1585)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 08:05 UTC · original · edited 2026-10-17 08:39 UTC
On tests/shaderCfgTests.cpp line 12927 (outdated):

@@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() {
         "an ungrounded Phi cycle acquired a constant");
 }
 
+void TestConstantPropagationSharedUsers() {
+  using namespace ShaderRecompiler::IR;
+  // Every identity fold below changes one link of a long dynamic chain, so all later links
+  // are its transitive users. Walking them once per fold is quadratic in the chain length.
+  constexpr uint32_t length = 1u << 16;
+  Block block;
+  IREmitter ir(&block);
+  const auto input = ir.GetUserData(static_cast<ScalarReg>(0));
+  std::vector<Value> sources;
+  std::vector<Value> links;
+  U32 chain = input;
+  for (uint32_t index = 0; index < length; ++index) {
+    // A private source per link keeps every use list short.
+    sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input}));
+    const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u)));
+    chain = ir.BitwiseXor(chain, link);
+    links.push_back(chain);
+  }
+  const auto begin = std::chrono::steady_clock::now();
+  ConstantPropagationPass({&block});
+  const auto elapsed = std::chrono::steady_clock::now() - begin;
+  bool folded = true;
+  for (size_t index = 0; index < links.size(); ++index) {
+    const auto *link = links[index].Resolve().TryInstruction();
+    const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve();
+    folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 &&
+              link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index];
+  }
+  Check(folded, "identity folds did not reach every link of a shared user chain");
+  Check(elapsed < std::chrono::seconds(2),

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --stat b82512be065b2fa2432cfa4e5a8c779604236299 d4abdf5f37773c66003e9ddb37baf1baa02b6258 -- tests/shaderCfgTests.cpp
git diff --unified=80 b82512be065b2fa2432cfa4e5a8c779604236299 d4abdf5f37773c66003e9ddb37baf1baa02b6258 -- tests/shaderCfgTests.cpp
printf '%s\n' '--- Check definitions/usages ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'Check(' -e 'TestConstantPropagationSharedUsers' tests src 2>/dev/null || true
printf '%s\n' '--- nearby final source ---'
sed -n '12840,12960p' tests/shaderCfgTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 45669


Keep the performance limit out of the required correctness test.

TestConstantPropagationSharedUsers() runs from main, and Check aborts the test process when elapsed time exceeds two seconds. A slower or instrumented runner can therefore fail shader_cfg even when the fold assertions pass. Keep the correctness checks in this test. Move the timing threshold to a separate performance test with an appropriate platform-specific threshold.

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 08:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#discussion_r4301992335) · edited 2026-10-17 08:39 UTC On `tests/shaderCfgTests.cpp` line 12927 (outdated): ```diff @@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() { "an ungrounded Phi cycle acquired a constant"); } +void TestConstantPropagationSharedUsers() { + using namespace ShaderRecompiler::IR; + // Every identity fold below changes one link of a long dynamic chain, so all later links + // are its transitive users. Walking them once per fold is quadratic in the chain length. + constexpr uint32_t length = 1u << 16; + Block block; + IREmitter ir(&block); + const auto input = ir.GetUserData(static_cast<ScalarReg>(0)); + std::vector<Value> sources; + std::vector<Value> links; + U32 chain = input; + for (uint32_t index = 0; index < length; ++index) { + // A private source per link keeps every use list short. + sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input})); + const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u))); + chain = ir.BitwiseXor(chain, link); + links.push_back(chain); + } + const auto begin = std::chrono::steady_clock::now(); + ConstantPropagationPass({&block}); + const auto elapsed = std::chrono::steady_clock::now() - begin; + bool folded = true; + for (size_t index = 0; index < links.size(); ++index) { + const auto *link = links[index].Resolve().TryInstruction(); + const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve(); + folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 && + link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index]; + } + Check(folded, "identity folds did not reach every link of a shared user chain"); + Check(elapsed < std::chrono::seconds(2), ``` **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- diff ---' git diff --stat b82512be065b2fa2432cfa4e5a8c779604236299 d4abdf5f37773c66003e9ddb37baf1baa02b6258 -- tests/shaderCfgTests.cpp git diff --unified=80 b82512be065b2fa2432cfa4e5a8c779604236299 d4abdf5f37773c66003e9ddb37baf1baa02b6258 -- tests/shaderCfgTests.cpp printf '%s\n' '--- Check definitions/usages ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'Check(' -e 'TestConstantPropagationSharedUsers' tests src 2>/dev/null || true printf '%s\n' '--- nearby final source ---' sed -n '12840,12960p' tests/shaderCfgTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 45669 --- </details> **Keep the performance limit out of the required correctness test.** `TestConstantPropagationSharedUsers()` runs from `main`, and `Check` aborts the test process when elapsed time exceeds two seconds. A slower or instrumented runner can therefore fail `shader_cfg` even when the fold assertions pass. Keep the correctness checks in this test. Move the timing threshold to a separate performance test with an appropriate platform-specific threshold. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d4f1253045508244b0295d96 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠NeySlim <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 08:05 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aaba6ba6-4149-4a38-81ee-407f1811dadf
📥 Commits

Reviewing files that changed from the base of the PR and between b82512be06 and d4abdf5f37773c66003e9ddb37baf1baa02b6258.

📒 Files selected for processing: 2
  • src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 08:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#pullrequestreview-5556948580) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `aaba6ba6-4149-4a38-81ee-407f1811dadf` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b82512be065b2fa2432cfa4e5a8c779604236299 and d4abdf5f37773c66003e9ddb37baf1baa02b6258. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=f119cd1b-e280-4918-bb70-4f87a0991084 attempt=7918d949-7793-40ad-8572-098571ab12ad batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-17 08:32 UTC · original
On tests/shaderCfgTests.cpp line 12927 (outdated):

@@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() {
         "an ungrounded Phi cycle acquired a constant");
 }
 
+void TestConstantPropagationSharedUsers() {
+  using namespace ShaderRecompiler::IR;
+  // Every identity fold below changes one link of a long dynamic chain, so all later links
+  // are its transitive users. Walking them once per fold is quadratic in the chain length.
+  constexpr uint32_t length = 1u << 16;
+  Block block;
+  IREmitter ir(&block);
+  const auto input = ir.GetUserData(static_cast<ScalarReg>(0));
+  std::vector<Value> sources;
+  std::vector<Value> links;
+  U32 chain = input;
+  for (uint32_t index = 0; index < length; ++index) {
+    // A private source per link keeps every use list short.
+    sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input}));
+    const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u)));
+    chain = ir.BitwiseXor(chain, link);
+    links.push_back(chain);
+  }
+  const auto begin = std::chrono::steady_clock::now();
+  ConstantPropagationPass({&block});
+  const auto elapsed = std::chrono::steady_clock::now() - begin;
+  bool folded = true;
+  for (size_t index = 0; index < links.size(); ++index) {
+    const auto *link = links[index].Resolve().TryInstruction();
+    const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve();
+    folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 &&
+              link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index];
+  }
+  Check(folded, "identity folds did not reach every link of a shared user chain");
+  Check(elapsed < std::chrono::seconds(2),

Fair point. Replaced the time limit with a count: the pass now returns how many users it revisited, and the test checks it's at most 2 per link. It's 1 per link with this change and quadratic without it, so the test still fails on main. The chain is down to 4096 links, so it's cheap too.

**@⁠NeySlim** on GitHub · 2026-10-17 08:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#discussion_r4302058327) On `tests/shaderCfgTests.cpp` line 12927 (outdated): ```diff @@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() { "an ungrounded Phi cycle acquired a constant"); } +void TestConstantPropagationSharedUsers() { + using namespace ShaderRecompiler::IR; + // Every identity fold below changes one link of a long dynamic chain, so all later links + // are its transitive users. Walking them once per fold is quadratic in the chain length. + constexpr uint32_t length = 1u << 16; + Block block; + IREmitter ir(&block); + const auto input = ir.GetUserData(static_cast<ScalarReg>(0)); + std::vector<Value> sources; + std::vector<Value> links; + U32 chain = input; + for (uint32_t index = 0; index < length; ++index) { + // A private source per link keeps every use list short. + sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input})); + const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u))); + chain = ir.BitwiseXor(chain, link); + links.push_back(chain); + } + const auto begin = std::chrono::steady_clock::now(); + ConstantPropagationPass({&block}); + const auto elapsed = std::chrono::steady_clock::now() - begin; + bool folded = true; + for (size_t index = 0; index < links.size(); ++index) { + const auto *link = links[index].Resolve().TryInstruction(); + const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve(); + folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 && + link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index]; + } + Check(folded, "identity folds did not reach every link of a shared user chain"); + Check(elapsed < std::chrono::seconds(2), ``` Fair point. Replaced the time limit with a count: the pass now returns how many users it revisited, and the test checks it's at most 2 per link. It's 1 per link with this change and quadratic without it, so the test still fails on main. The chain is down to 4096 links, so it's cheap too.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 08:39 UTC · original
On tests/shaderCfgTests.cpp line 12927 (outdated):

@@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() {
         "an ungrounded Phi cycle acquired a constant");
 }
 
+void TestConstantPropagationSharedUsers() {
+  using namespace ShaderRecompiler::IR;
+  // Every identity fold below changes one link of a long dynamic chain, so all later links
+  // are its transitive users. Walking them once per fold is quadratic in the chain length.
+  constexpr uint32_t length = 1u << 16;
+  Block block;
+  IREmitter ir(&block);
+  const auto input = ir.GetUserData(static_cast<ScalarReg>(0));
+  std::vector<Value> sources;
+  std::vector<Value> links;
+  U32 chain = input;
+  for (uint32_t index = 0; index < length; ++index) {
+    // A private source per link keeps every use list short.
+    sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input}));
+    const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u)));
+    chain = ir.BitwiseXor(chain, link);
+    links.push_back(chain);
+  }
+  const auto begin = std::chrono::steady_clock::now();
+  ConstantPropagationPass({&block});
+  const auto elapsed = std::chrono::steady_clock::now() - begin;
+  bool folded = true;
+  for (size_t index = 0; index < links.size(); ++index) {
+    const auto *link = links[index].Resolve().TryInstruction();
+    const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve();
+    folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 &&
+              link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index];
+  }
+  Check(folded, "identity folds did not reach every link of a shared user chain");
+  Check(elapsed < std::chrono::seconds(2),

@⁠NeySlim Thanks for the update. The revised test removes the runner-speed dependency and retains the fold assertions. The revisit-count limit checks algorithmic work without a wall-clock threshold. This addresses my concern.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 08:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#discussion_r4302077284) On `tests/shaderCfgTests.cpp` line 12927 (outdated): ```diff @@ -12894,6 +12895,39 @@ void TestLateConstantPropagation() { "an ungrounded Phi cycle acquired a constant"); } +void TestConstantPropagationSharedUsers() { + using namespace ShaderRecompiler::IR; + // Every identity fold below changes one link of a long dynamic chain, so all later links + // are its transitive users. Walking them once per fold is quadratic in the chain length. + constexpr uint32_t length = 1u << 16; + Block block; + IREmitter ir(&block); + const auto input = ir.GetUserData(static_cast<ScalarReg>(0)); + std::vector<Value> sources; + std::vector<Value> links; + U32 chain = input; + for (uint32_t index = 0; index < length; ++index) { + // A private source per link keeps every use list short. + sources.push_back(ir.Emit(ValueOpcode::BitwiseNot32, {input})); + const auto link = ir.IAdd(U32(sources.back()), U32(Value(0u))); + chain = ir.BitwiseXor(chain, link); + links.push_back(chain); + } + const auto begin = std::chrono::steady_clock::now(); + ConstantPropagationPass({&block}); + const auto elapsed = std::chrono::steady_clock::now() - begin; + bool folded = true; + for (size_t index = 0; index < links.size(); ++index) { + const auto *link = links[index].Resolve().TryInstruction(); + const auto previous = index == 0 ? Value(input) : links[index - 1].Resolve(); + folded &= link != nullptr && link->GetOpcode() == ValueOpcode::BitwiseXor32 && + link->Arg(0).Resolve() == previous && link->Arg(1).Resolve() == sources[index]; + } + Check(folded, "identity folds did not reach every link of a shared user chain"); + Check(elapsed < std::chrono::seconds(2), ``` @⁠NeySlim Thanks for the update. The revised test removes the runner-speed dependency and retains the fold assertions. The revisit-count limit checks algorithmic work without a wall-clock threshold. This addresses my concern. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Keep%20correctness%20tests%20reliable%3A%20don%E2%80%99t%20make%20them%20depend%20on%20wall-clock%20timing.%20Count%20revisited%20users%20instead%20to%20catch%20quadratic%20regressions%20deterministically.%20Try%20%40coderabbitai%20for%20actionable%20code%20reviews.%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1585%23discussion_r4301992335)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-17 10:34 UTC · original

Closing: f6f1ac8b4 on main does the same thing (one walk over the union of affected users per drain instead of one per change). The deterministic test from this PR passes on main as well, so there's nothing left here.

**@⁠NeySlim** on GitHub · 2026-10-17 10:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1585#issuecomment-6232874026) Closing: f6f1ac8b4 on main does the same thing (one walk over the union of affected users per drain instead of one per change). The deterministic test from this PR passes on main as well, so there's nothing left here.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.