shader: preserve live predicates through whole-quad expansion #801

Manually merged
github merged 1 commit from gh-pr/801/head into gh-pr/801/base 2026-11-26 09:32:56 +00:00
Owner

@⁠neodouglas on GitHub · 2026-09-24 07:12 UTC · original
neodouglas:fix/entry-wqm-lane-test → main · +136 −8 · 3 files · 1 commits · merged 2026-09-24 08:02 UTC

ASTRO BOT’s NV12-to-RGB pixel shader lost its known-live lane predicate after S_WQM, leaving redundant runtime selects around its color arithmetic. Preserve the source-live predicate alongside the expanded scalar mask: WQM can activate lanes but cannot deactivate a source lane. Entry predicates then fold naturally through the existing IR passes, including masks saved in SGPRs.

The translation retains RDNA2 B32/B64 mask values, SCC updates, untouched destination halves, and raw-source/cross-half behavior. Explicit branches and descriptive names keep the WQM path readable. No instruction pre-scan, opcode-name matching, shader-specific case, or new backend operation is needed.

Validation:

  • Built kyty_emulator, shader_cfg_tests, and shader_recompiler_compute_tests using the existing CMake configuration.
  • shader_cfg_tests and shader_recompiler_compute_tests --wave64-only passed after the readability revision.
  • Regression cases cover entry pixel masks for wave32/wave64 and B32/B64, direct/saved masks, cross-half copies, and scalar/high-word sources.
  • ASTRO BOT PPSA21564 was run through launch.json with --game-patch and Vulkan validation disabled; RenderDoc capture was triggered after 15 seconds on an RTX 5080 Laptop GPU.
  • Independent correctness and compactness/readability audits passed.
**@⁠neodouglas** on GitHub · 2026-09-24 07:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/801) `neodouglas:fix/entry-wqm-lane-test` → `main` · +136 −8 · 3 files · 1 commits · merged 2026-09-24 08:02 UTC ASTRO BOT’s NV12-to-RGB pixel shader lost its known-live lane predicate after `S_WQM`, leaving redundant runtime selects around its color arithmetic. Preserve the source-live predicate alongside the expanded scalar mask: WQM can activate lanes but cannot deactivate a source lane. Entry predicates then fold naturally through the existing IR passes, including masks saved in SGPRs. The translation retains RDNA2 B32/B64 mask values, SCC updates, untouched destination halves, and raw-source/cross-half behavior. Explicit branches and descriptive names keep the WQM path readable. No instruction pre-scan, opcode-name matching, shader-specific case, or new backend operation is needed. Validation: - Built `kyty_emulator`, `shader_cfg_tests`, and `shader_recompiler_compute_tests` using the existing CMake configuration. - `shader_cfg_tests` and `shader_recompiler_compute_tests --wave64-only` passed after the readability revision. - Regression cases cover entry pixel masks for wave32/wave64 and B32/B64, direct/saved masks, cross-half copies, and scalar/high-word sources. - ASTRO BOT PPSA21564 was run through `launch.json` with `--game-patch` and Vulkan validation disabled; RenderDoc capture was triggered after 15 seconds on an RTX 5080 Laptop GPU. - Independent correctness and compactness/readability audits passed.
Keep the source-live predicate when WQM expands a scalar mask, so entry masks remain known live without an instruction pre-scan. Preserve scalar mask values, SCC, half writes, and raw-source behavior.

Cover entry pixel masks, cross-half copies, and scalar/high-word sources with existing shader regression suites.

Co-authored-by: Douglas <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:32:54 +00:00
github manually merged commit 5bbd1ba9d4 into gh-pr/801/base 2026-11-26 09:32:56 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 07:25 UTC · original · edited 2026-09-24 07:35 UTC

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: cea4608b-4789-46bd-bea8-a18666b76693

📥 Commits

Reviewing files that changed from the base of the PR and between 7d3bb69dd52c80a7fa944e10c2855cb62386259d and 60366b2e2cfa34578b8e2262845d53c162273089.

📒 Files selected for processing (1)
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

For pixel shaders, translation scans decoded instructions for an eligible entry S_WQM_B32 or S_WQM_B64 instruction and passes its PC to each block translator. The scan stops if it encounters specified EXEC writes, control-flow instructions, or disqualifying opcode names. At the matching PC, both WQM paths set EXEC to true. Other shader stages use UINT32_MAX.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 60366

No actionable merge-blocking issue remains from the reviewed change; normal checks can proceed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: folding the lane test after a pixel shader's entry S_WQM instruction.
Description check ✅ Passed The description directly explains the implementation, scope, rationale, and validation for the changeset.
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.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-09-24 07:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/801#issuecomment-5809719866) · edited 2026-09-24 07:35 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/801"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `cea4608b-4789-46bd-bea8-a18666b76693` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7d3bb69dd52c80a7fa944e10c2855cb62386259d and 60366b2e2cfa34578b8e2262845d53c162273089. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * src/graphics/shader/recompiler/frontend/translate/Translate.cpp </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough For pixel shaders, translation scans decoded instructions for an eligible entry `S_WQM_B32` or `S_WQM_B64` instruction and passes its PC to each block translator. The scan stops if it encounters specified EXEC writes, control-flow instructions, or disqualifying opcode names. At the matching PC, both WQM paths set EXEC to true. Other shader stages use `UINT32_MAX`. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"60366b2e2cfa34578b8e2262845d53c162273089" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `60366` <!-- final_review_risk_coverage:{"sourceCommitId":"60366b2e2cfa34578b8e2262845d53c162273089","coveredCommitId":"60366b2e2cfa34578b8e2262845d53c162273089","kind":"reviewed"} --> No actionable merge-blocking issue remains from the reviewed change; normal checks can proceed. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------ | | Title check | ✅ Passed | The title clearly summarizes the main change: folding the lane test after a pixel shader's entry S_WQM instruction. | | Description check | ✅ Passed | The description directly explains the implementation, scope, rationale, and validation for the changeset. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 07:25 UTC · original · edited 2026-09-24 07:32 UTC
On src/graphics/shader/recompiler/frontend/translate/Translate.cpp line 918 (outdated):

@@ -901,6 +903,30 @@ void ValidateTranslateOptions(const TranslateOptions& options) {
 	}
 }
 
+// The PC of `s_wqm exec, exec` when it is the first thing to touch EXEC, before any branch.
+// Anything that might write EXEC or leave the entry block first disqualifies it.
+uint32_t FindEntryWqmPc(const Decoder::Program& decoded) {
+	using Decoder::Opcode;
+	using Decoder::OperandKind;
+	for (const auto& inst: decoded.instructions) {
+		if ((inst.opcode == Opcode::S_WQM_B64 || inst.opcode == Opcode::S_WQM_B32) &&
+		    inst.dst.kind == OperandKind::ExecLo && inst.src0.kind == OperandKind::ExecLo) {
+			return inst.pc;
+		}
+		const auto name = magic_enum::enum_name(inst.opcode);
+		if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi ||
+		    Decoder::IsConditionalBranch(inst.opcode) || Decoder::IsDirectBranch(inst.opcode) ||

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '900,940p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
sed -n '305,335p' src/graphics/shader/recompiler/frontend/translate/Control.cpp
rg -n 'V_ADD_CO_U32|dst2|SetExec' src/graphics/shader/recompiler/frontend/{decode,translate}

Repository: KytyPS5/KytyPS5

Length of output: 7294


🏁 Script executed:

sed -n '1635,1690p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
sed -n '80,125p' src/graphics/shader/recompiler/frontend/translate/Control.cpp
sed -n '270,325p' src/graphics/shader/recompiler/frontend/translate/Control.cpp
sed -n '280,320p' src/graphics/shader/recompiler/frontend/translate/Integer.cpp
sed -n '1,65p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
rg -n -C 3 'V_ADD_CO_U32|ADD_U32|DecodeScalarDestination|enum class OperandKind|ExecLo|ExecHi' src/graphics/shader/recompiler/frontend/decode src/graphics/shader/recompiler/frontend/translate

Repository: KytyPS5/KytyPS5

Length of output: 42284


🏁 Script executed:

rg -n -C 5 'V_ADD_CO_U32|V_ADD_CO|V_ADDC_U32|vop3b_carry_out|carry_out|UsesScalarDestination|IsVop3' src/graphics/shader/recompiler/frontend/decode src/graphics/shader/recompiler/frontend/translate
sed -n '1,45p' src/graphics/shader/recompiler/frontend/translate/Vector.cpp
sed -n '1,190p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
sed -n '1080,1185p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
sed -n '600,735p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
sed -n '220,280p' src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h

Repository: KytyPS5/KytyPS5

Length of output: 37382


Reject EXEC writes through inst.dst2 before selecting the entry WQM.

The decoder represents the V_ADD_CO_U32 carry-out form as Decoder::Opcode::V_ADD_I32. Its VOP3B scalar destination is stored in inst.dst2, and DecodeScalarDestination accepts ExecLo and ExecHi. Translator::ADD_U32 then writes exec & carry through WriteMask(inst.dst2, ...).

Therefore, a carry result can clear EXEC before s_wqm exec, exec. FindEntryWqmPc does not detect this because it checks only inst.dst. The selected entry WQM then sets EXEC to constant true, which can enable later VALU writes for lanes that should remain inactive.

Suggested fix
-		if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi ||
+		if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi ||
+		    inst.dst2.kind == OperandKind::ExecLo || inst.dst2.kind == OperandKind::ExecHi ||
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi ||
		    inst.dst2.kind == OperandKind::ExecLo || inst.dst2.kind == OperandKind::ExecHi ||
		    Decoder::IsConditionalBranch(inst.opcode) || Decoder::IsDirectBranch(inst.opcode) ||

✅ Addressed in commit 60366b2

**@⁠coderabbitai[bot]** on GitHub · 2026-09-24 07:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/801#discussion_r4090992521) · edited 2026-09-24 07:32 UTC On `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` line 918 (outdated): ```diff @@ -901,6 +903,30 @@ void ValidateTranslateOptions(const TranslateOptions& options) { } } +// The PC of `s_wqm exec, exec` when it is the first thing to touch EXEC, before any branch. +// Anything that might write EXEC or leave the entry block first disqualifies it. +uint32_t FindEntryWqmPc(const Decoder::Program& decoded) { + using Decoder::Opcode; + using Decoder::OperandKind; + for (const auto& inst: decoded.instructions) { + if ((inst.opcode == Opcode::S_WQM_B64 || inst.opcode == Opcode::S_WQM_B32) && + inst.dst.kind == OperandKind::ExecLo && inst.src0.kind == OperandKind::ExecLo) { + return inst.pc; + } + const auto name = magic_enum::enum_name(inst.opcode); + if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi || + Decoder::IsConditionalBranch(inst.opcode) || Decoder::IsDirectBranch(inst.opcode) || ``` _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '900,940p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp sed -n '305,335p' src/graphics/shader/recompiler/frontend/translate/Control.cpp rg -n 'V_ADD_CO_U32|dst2|SetExec' src/graphics/shader/recompiler/frontend/{decode,translate} ``` Repository: KytyPS5/KytyPS5 Length of output: 7294 --- 🏁 Script executed: ```bash sed -n '1635,1690p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp sed -n '80,125p' src/graphics/shader/recompiler/frontend/translate/Control.cpp sed -n '270,325p' src/graphics/shader/recompiler/frontend/translate/Control.cpp sed -n '280,320p' src/graphics/shader/recompiler/frontend/translate/Integer.cpp sed -n '1,65p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp rg -n -C 3 'V_ADD_CO_U32|ADD_U32|DecodeScalarDestination|enum class OperandKind|ExecLo|ExecHi' src/graphics/shader/recompiler/frontend/decode src/graphics/shader/recompiler/frontend/translate ``` Repository: KytyPS5/KytyPS5 Length of output: 42284 --- 🏁 Script executed: ```bash rg -n -C 5 'V_ADD_CO_U32|V_ADD_CO|V_ADDC_U32|vop3b_carry_out|carry_out|UsesScalarDestination|IsVop3' src/graphics/shader/recompiler/frontend/decode src/graphics/shader/recompiler/frontend/translate sed -n '1,45p' src/graphics/shader/recompiler/frontend/translate/Vector.cpp sed -n '1,190p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp sed -n '1080,1185p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp sed -n '600,735p' src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp sed -n '220,280p' src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h ``` Repository: KytyPS5/KytyPS5 Length of output: 37382 --- </details> **Reject EXEC writes through `inst.dst2` before selecting the entry WQM.** The decoder represents the `V_ADD_CO_U32` carry-out form as `Decoder::Opcode::V_ADD_I32`. Its VOP3B scalar destination is stored in `inst.dst2`, and `DecodeScalarDestination` accepts `ExecLo` and `ExecHi`. `Translator::ADD_U32` then writes `exec & carry` through `WriteMask(inst.dst2, ...)`. Therefore, a carry result can clear EXEC before `s_wqm exec, exec`. `FindEntryWqmPc` does not detect this because it checks only `inst.dst`. The selected entry WQM then sets EXEC to constant `true`, which can enable later VALU writes for lanes that should remain inactive. <details> <summary>Suggested fix</summary> ```diff - if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi || + if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi || + inst.dst2.kind == OperandKind::ExecLo || inst.dst2.kind == OperandKind::ExecHi || ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if (inst.dst.kind == OperandKind::ExecLo || inst.dst.kind == OperandKind::ExecHi || inst.dst2.kind == OperandKind::ExecLo || inst.dst2.kind == OperandKind::ExecHi || Decoder::IsConditionalBranch(inst.opcode) || Decoder::IsDirectBranch(inst.opcode) || ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:def7181c3a87f1abc8a308e6 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 60366b2
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 07:25 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: fe21597c-12d7-423b-a72f-a4289e356365

📥 Commits

Reviewing files that changed from the base of the PR and between 3dc3fd0197 and 7d3bb69dd52c80a7fa944e10c2855cb62386259d.

📒 Files selected for processing (3)
  • src/graphics/shader/recompiler/frontend/translate/Control.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translator.h

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-24 07:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/801#pullrequestreview-5301144797) · **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**: `fe21597c-12d7-423b-a72f-a4289e356365` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 3dc3fd0197ae361add9007f5cddeb552246c3d10 and 7d3bb69dd52c80a7fa944e10c2855cb62386259d. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/shader/recompiler/frontend/translate/Control.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠neodouglas on GitHub · 2026-09-24 07:44 UTC · original

Before/after video of the Astro Bot (PPSA21567) intro on Windows with an RTX 5090. The first part is with this change, the second part is without it:
https://youtu.be/qtIIslPr3QI

**@⁠neodouglas** on GitHub · 2026-09-24 07:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/801#issuecomment-5809972526) Before/after video of the Astro Bot (PPSA21567) intro on Windows with an RTX 5090. The first part is with this change, the second part is without it: https://youtu.be/qtIIslPr3QI
This discussion has been locked. Commenting is limited to contributors.
No description provided.