shader: bound the vertex entry mask by the highest running lane #2201

Open
github-bot wants to merge 4 commits from github-bot/gh-2201 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-11-10 22:03 UTC · original
Nawid3333:shader/vertex-entry-lane-bound → main · +236 −3 · 7 files · 4 commits · open

The NGG prologue of most vertex shaders (720 of the 770 stored vertex modules that contain a select, table below) rebuilds EXEC from the vertex count in s3: exec = -1 >> (-s3 & 63) (e.g. d3e1ae284c4dea3b, already a fixture in CheckRasterization). The vertex entry fills that count with popcount(Ballot(true)). Every vector write after the prologue is then select(own bit of that mask, new, old), and constant propagation cannot remove the select, because nothing says that a running lane lies below the count. AMD's shader compiler keeps it as well (below).

I extracted the SPIR-V modules from the shader stores of five games and counted the OpSelect whose condition is that bit:

game vertex modules with the pattern their selects on the bit share of their function-body instructions
Demon's Souls (PPSA01341) 28 2,400 8.3 %
ASTRO BOT (PPSA21564) 86 28,842 9.1 %
STAR WARS Jedi: Fallen Order (PPSA02198) 88 12,390 8.5 %
Assassin's Creed Black Flag Resynced (PPSA28183) 47 12,051 11.4 %
Ghost of Yōtei (PPSA26344) 471 124,304 6.9 %

All 720 modules build the mask in the same way: a 64-bit right shift of all ones by a constant minus the count, and the word chosen by lane < 32.

Changes.

  • New IR value LaneBound: one past the highest running subgroup lane, capped at the guest wave size (OpGroupNonUniformBallotFindMSB of Ballot(true), plus one, UMin). The vertex entry puts it into s3 in place of the popcount. When the running lanes are a dense prefix the two are equal, so s3, the EXEC words and every scalar reader keep their values (a wave32 program on a 64-lane subgroup with 40 running lanes gets 32 either way). When they are not dense, the popcount put running lanes outside the prefix; the bound cannot.
  • LaneMaskProjection folds the own-lane bit of a mask to true when the mask depends only on LaneBound and immediates and covers lanes 0..bound-1 for every bound from 1 to the wave size. It evaluates the mask words for each bound (and, or, 32-bit subtract and right shift, bit-field extract, 64-bit right shift and word extract) instead of matching one instruction shape, so the & 0xff, 64 - count and 0 - count variants of the prologue need no separate rule; anything it cannot evaluate stays as it is. In wave64 the word must be selected by LaneId < 32.
  • With the bit folded, the selects fold to their new value, exports lose their EXEC branch, and a shader that reads s3 nowhere else has no subgroup instruction left.

A full-wave constant in s3 would fold as well, but it leaves EXEC word bits for lanes that do not run, which the partial-wave waterfall case of CheckRasterization (3, 6 and 33 vertices) rules out.

In the game. Demon's Souls (PPSA01341) on an RX 9070 XT, one run with main 782a85c62 and one with the first commit of this branch (both with my lab input player on top): both boot and draw the logo screens without a fatal error; the main run also reached the language selection. Six vertex shaders were compiled by both runs. Paired by the instructions the fold cannot touch (stores, access chains, float arithmetic, conversions, image accesses, extended instructions other than UMin), and compiled with AMD's offline compiler (rga -s vk-spv-offline -c gfx1201):

main first commit change
SPIR-V function-body instructions 984 688 -30.1 %
OpSelect 96 17
native instructions 683 531 -22.3 %

Per shader, native: 73 -> 55, 81 -> 62, 100 -> 82, 140 -> 111, 111 -> 82, 178 -> 139. The changed modules showed that each still read the lane id: the prologue also builds a first mask from the count in s3[15:8] with a bit-field extract. The second commit evaluates that form too and the third adds test cases for it; the second is covered by the tests below and has not run in a game.

On larger shaders the share is smaller. The same compiler on 12 stored vertex modules per game, taken evenly over the size-sorted modules that have the pattern, as stored and with the one condition replaced by true: Demon's Souls 7,509 -> 6,500 native instructions (-13.4 %), ASTRO BOT 26,553 -> 22,694 (-14.5 %), Fallen Order 10,650 -> 9,305 (-12.6 %).

Tests.

  • TestVertexEntryMaskCoversRunningLanes (shader_cfg_tests) compiles the captured prologue in wave32 and wave64 with one register written under each of its two masks: the module reads no lane id and has no subgroup instruction; a shader that exports s3 keeps BallotFindMSB; a mask one lane short of the bound and an EXEC write after the prologue stay predicated. On main with only this test it fails at a running vertex lane stayed predicated by the entry mask of its own lane bound.
  • TestLaneMaskProjection gains three covering masks (all fold: 0 - bound, the s3[15:8] count with 64 - count, and a bit-field extract of the bound itself), and masks that must stay: one that in wave32 misses only bound 1, one that misses only the last bound, a wave64 word selected at lane 31, prefixes of half the bound built with a bit-field extract at bit 1 and with a 32-bit shift by 1, and a prefix of the bound's lowest bit (a 1-bit extract). Six deliberate bugs (loop from 2, loop without the last bound, selector constant ignored, extract offset ignored, extract width ignored, shift amount ignored) each fail one of them.
  • RX 9070 XT, shader_recompiler_compute_tests: --polygon-mode-only passes (it contains the waterfall case in both wave sizes); the full run has the same 1,057 passing checks and the same 22 failing checks as main 782a85c62. Both runs need lab-only patches to start on this GPU (#2038, optional feedback-loop state, D24S8 replaced by D32S8, one skipped case that crashes the driver); they are not part of the PR.

Written with Claude Code, OpenAI Codex and GLM (AI): the change, the tests and the measurements, run on my PC; reviewed by me.

**@⁠Nawid3333** on GitHub · 2026-11-10 22:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2201) `Nawid3333:shader/vertex-entry-lane-bound` → `main` · +236 −3 · 7 files · 4 commits · open The NGG prologue of most vertex shaders (720 of the 770 stored vertex modules that contain a select, table below) rebuilds EXEC from the vertex count in `s3`: `exec = -1 >> (-s3 & 63)` (e.g. d3e1ae284c4dea3b, already a fixture in `CheckRasterization`). The vertex entry fills that count with `popcount(Ballot(true))`. Every vector write after the prologue is then `select(own bit of that mask, new, old)`, and constant propagation cannot remove the select, because nothing says that a running lane lies below the count. AMD's shader compiler keeps it as well (below). I extracted the SPIR-V modules from the shader stores of five games and counted the `OpSelect` whose condition is that bit: | game | vertex modules with the pattern | their selects on the bit | share of their function-body instructions | |---|---|---|---| | Demon's Souls (PPSA01341) | 28 | 2,400 | 8.3 % | | ASTRO BOT (PPSA21564) | 86 | 28,842 | 9.1 % | | STAR WARS Jedi: Fallen Order (PPSA02198) | 88 | 12,390 | 8.5 % | | Assassin's Creed Black Flag Resynced (PPSA28183) | 47 | 12,051 | 11.4 % | | Ghost of Yōtei (PPSA26344) | 471 | 124,304 | 6.9 % | All 720 modules build the mask in the same way: a 64-bit right shift of all ones by a constant minus the count, and the word chosen by `lane < 32`. **Changes.** - New IR value `LaneBound`: one past the highest running subgroup lane, capped at the guest wave size (`OpGroupNonUniformBallotFindMSB` of `Ballot(true)`, plus one, `UMin`). The vertex entry puts it into `s3` in place of the popcount. When the running lanes are a dense prefix the two are equal, so `s3`, the EXEC words and every scalar reader keep their values (a wave32 program on a 64-lane subgroup with 40 running lanes gets 32 either way). When they are not dense, the popcount put running lanes outside the prefix; the bound cannot. - `LaneMaskProjection` folds the own-lane bit of a mask to true when the mask depends only on `LaneBound` and immediates and covers lanes `0..bound-1` for every bound from 1 to the wave size. It evaluates the mask words for each bound (and, or, 32-bit subtract and right shift, bit-field extract, 64-bit right shift and word extract) instead of matching one instruction shape, so the `& 0xff`, `64 - count` and `0 - count` variants of the prologue need no separate rule; anything it cannot evaluate stays as it is. In wave64 the word must be selected by `LaneId < 32`. - With the bit folded, the selects fold to their new value, exports lose their EXEC branch, and a shader that reads `s3` nowhere else has no subgroup instruction left. A full-wave constant in `s3` would fold as well, but it leaves EXEC word bits for lanes that do not run, which the partial-wave waterfall case of `CheckRasterization` (3, 6 and 33 vertices) rules out. **In the game.** Demon's Souls (PPSA01341) on an RX 9070 XT, one run with main 782a85c62 and one with the first commit of this branch (both with my lab input player on top): both boot and draw the logo screens without a fatal error; the main run also reached the language selection. Six vertex shaders were compiled by both runs. Paired by the instructions the fold cannot touch (stores, access chains, float arithmetic, conversions, image accesses, extended instructions other than `UMin`), and compiled with AMD's offline compiler (`rga -s vk-spv-offline -c gfx1201`): | | main | first commit | change | |---|---|---|---| | SPIR-V function-body instructions | 984 | 688 | -30.1 % | | `OpSelect` | 96 | 17 | | | native instructions | 683 | 531 | -22.3 % | Per shader, native: 73 -> 55, 81 -> 62, 100 -> 82, 140 -> 111, 111 -> 82, 178 -> 139. The changed modules showed that each still read the lane id: the prologue also builds a first mask from the count in `s3[15:8]` with a bit-field extract. The second commit evaluates that form too and the third adds test cases for it; the second is covered by the tests below and has not run in a game. On larger shaders the share is smaller. The same compiler on 12 stored vertex modules per game, taken evenly over the size-sorted modules that have the pattern, as stored and with the one condition replaced by true: Demon's Souls 7,509 -> 6,500 native instructions (-13.4 %), ASTRO BOT 26,553 -> 22,694 (-14.5 %), Fallen Order 10,650 -> 9,305 (-12.6 %). **Tests.** - `TestVertexEntryMaskCoversRunningLanes` (shader_cfg_tests) compiles the captured prologue in wave32 and wave64 with one register written under each of its two masks: the module reads no lane id and has no subgroup instruction; a shader that exports `s3` keeps `BallotFindMSB`; a mask one lane short of the bound and an EXEC write after the prologue stay predicated. On main with only this test it fails at `a running vertex lane stayed predicated by the entry mask of its own lane bound`. - `TestLaneMaskProjection` gains three covering masks (all fold: `0 - bound`, the `s3[15:8]` count with `64 - count`, and a bit-field extract of the bound itself), and masks that must stay: one that in wave32 misses only bound 1, one that misses only the last bound, a wave64 word selected at lane 31, prefixes of half the bound built with a bit-field extract at bit 1 and with a 32-bit shift by 1, and a prefix of the bound's lowest bit (a 1-bit extract). Six deliberate bugs (loop from 2, loop without the last bound, selector constant ignored, extract offset ignored, extract width ignored, shift amount ignored) each fail one of them. - RX 9070 XT, `shader_recompiler_compute_tests`: `--polygon-mode-only` passes (it contains the waterfall case in both wave sizes); the full run has the same 1,057 passing checks and the same 22 failing checks as main 782a85c62. Both runs need lab-only patches to start on this GPU (#2038, optional feedback-loop state, D24S8 replaced by D32S8, one skipped case that crashes the driver); they are not part of the PR. Written with Claude Code, OpenAI Codex and GLM (AI): the change, the tests and the measurements, run on my PC; reviewed by me.
The vertex entry gave the guest the number of running subgroup lanes as its
vertex count. The NGG prologue turns that count into a prefix mask for EXEC,
so every later vector write is selected by the own-lane bit of that mask.

The count is now one past the highest running lane, capped at the wave size.
It equals the old value whenever running lanes are a dense prefix, and no
running lane falls outside the prefix otherwise. Constant propagation
evaluates a mask that depends only on this bound for every possible bound
and folds the own-lane bit to true when all of them cover it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Captured prologues build a first mask from the count in s3[15:8], through a
32-bit shift or a bit-field extract. Its own-lane bit kept the lane id and
the subgroup ballot alive in every vertex shader of the Demon's Souls run.
The projection now evaluates both forms, in one switch that reads operands
on demand.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:16:45 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-10 22:11 UTC · original · edited 2026-11-11 01:52 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Vertex entry initialization now uses LaneBound to set the low lane-bound bits in SGPR3. The SPIR-V emitter computes the bound from a subgroup ballot and caps it at the configured wave size. Constant propagation evaluates supported lane-mask expressions across possible bounds and folds comparisons when each active lane is covered. Tests exercise vertex entry masks and lane-mask projection for wave32 and wave64.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Minimal · up to 166b7

The change bounds the vertex entry lane mask by the highest running lane and folds covering lane-mask predicates. No concrete merge-blocking risk was identified. The author reports hardware results that were not independently verified here.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: bounding the vertex entry mask by the highest running lane.
Description check Passed The description directly explains the LaneBound and LaneMaskProjection changes, their purpose, tests, performance results, and validation.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 5 files. (1 skipped: 1 too large.)

Resolution

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

Warning

Some tools did not complete. Review the errors below.

Cppcheck (2.22.0)

tests/shaderCfgTests.cpp

Cppcheck timed out; analysis of this file is incomplete

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7a896f229fbe329e3cf0d168e0f9fdf99abedcf0 and 166b7923fb.

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 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-10 22:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2201#issuecomment-6780671917) · edited 2026-11-11 01:52 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/2201?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> Vertex entry initialization now uses `LaneBound` to set the low lane-bound bits in SGPR3. The SPIR-V emitter computes the bound from a subgroup ballot and caps it at the configured wave size. Constant propagation evaluates supported lane-mask expressions across possible bounds and folds comparisons when each active lane is covered. Tests exercise vertex entry masks and lane-mask projection for wave32 and wave64. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"166b7923fbdfcd2b1d6b10ae3838c98110b4aa34" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>166b7</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `166b7` --> <!-- final_review_risk_coverage:{"sourceCommitId":"166b7923fbdfcd2b1d6b10ae3838c98110b4aa34","coveredCommitId":"166b7923fbdfcd2b1d6b10ae3838c98110b4aa34","kind":"reviewed"} --> The change bounds the vertex entry lane mask by the highest running lane and folds covering lane-mask predicates. No concrete merge-blocking risk was identified. The author reports hardware results that were not independently verified here. <!-- 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> <br> <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 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… | 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> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: bounding the vertex entry mask by the highest running lane. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the LaneBound and LaneMaskProjection changes, their purpose, tests, performance results, and validation. | | 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. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> <br> **Explanation** Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 5 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 --> <!-- operational_warnings_start --> <!-- This is an auto-generated comment: all tool run failures by coderabbit.ai --> > [!WARNING] > Some tools did not complete. Review the errors below. > > <details> > <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench.svg" width="16" height="16" align="absmiddle" alt=""></picture> Cppcheck (2.22.0)</strong></summary> > <dl> > <dd> > <br> > > <details> > <summary><strong>tests/shaderCfgTests.cpp</strong></summary> > <dl> > <dd> > <br> > > Cppcheck timed out; analysis of this file is incomplete > > </dd> > </dl> > </details> > > </dd> > </dl> > </details> <!-- end of auto-generated comment: all tool run failures by coderabbit.ai --> <!-- operational_warnings_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2201)! 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> <br> - [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> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/7d4e0d9b3bdd2b44c6d99c087d361e8640eed2ee/.coderabbit.yaml>) - **Commit**: [7d4e0d9](<https://github.com/KytyPS5/KytyPS5/commit/7d4e0d9b3bdd2b44c6d99c087d361e8640eed2ee>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `1e870eeb-176e-456a-8e8f-610103bcea71` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 7a896f229fbe329e3cf0d168e0f9fdf99abedcf0 and 166b7923fbdfcd2b1d6b10ae3838c98110b4aa34. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</strong></summary> <dl> <dd> <br> * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp` * `tests/shaderCfgTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-11 01:55 UTC · original

Rebased onto current main (7d4e0d9b3) and added one commit that hardens the evaluator. The prologue forms fold as before.

Fourth commit. The projection now accepts one LaneBound instruction per mask, evaluates at most 64 new nodes per bound, and rejects a CompositeExtractU64 index other than 0 or 1. Two tests: a mask built from two different lane bounds and a mask behind an 81-step chain both stay instructions. Before this commit a hand-built mask of two different LaneBound values could fold wrongly; the translator emits exactly one per vertex program and none in other stages, so no real shader was affected.

More checks on real shaders, without game runs. I recompiled 1,041 guest programs dumped from Demon's Souls, ASTRO BOT, Ghost of Yōtei and Assassin's Creed Black Flag Resynced with main and with this branch, using the test fixture's default options:

  • Compute (634 programs that translate) and pixel (273): the IR text is identical.
  • Vertex (127 programs, wave size 64 and 32): every instruction with an effect keeps its count. As a cross-check I put a brute-force version of the fold into main (evaluate each own-lane bit for every lane bound and every lane below it, replace it by true when it is always true). Its IR is byte-identical to this branch's in 234 of 254 cases; 12 differ only in the operand order of one INotEqual32; in 8 the count keeps a reader (three of the shaders of point 2 below, and one shader that reads bits 27:24).
  • The translate phase is not slower: its summed time is within 1 % for compute and pixel and about 3 % lower for vertex.
  • shader_recompiler_compute_tests on an RX 9070 XT gives the same result list as main.
  • shader_cfg_tests, which CI does not build or run, passes with this branch on Windows and Linux fork runners. On the macOS runner it stops in TestGpuProducedWritableDescriptor on main and on this branch alike, after this PR's two tests have passed.

Two points for your decision.

  1. The line this PR replaces carried the comment "ESVertCount describes input vertices, independently of lane ordinals". With dense subgroups the bound equals that count, so nothing changes. The two differ only when the running lanes are not a dense prefix; the count then leaves running lanes outside the guest's prefix mask. In the 770 stored vertex modules of five games no shader uses the count for anything but masks (two read only bits 27:24).
  2. Not solved by this PR: 6 of those 770 modules (5 ASTRO BOT, 1 Black Flag) carry the entry mask through a loop and repeat while it is non-zero (remaining &= ~ballot(handled)). On a host with non-dense vertex lanes that mask keeps the bit of a lane that does not run, with the count and with the bound alike, so the loop cannot end there. Whether any real driver gives vertex shaders such subgroups I have not measured.
**@⁠Nawid3333** on GitHub · 2026-11-11 01:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2201#issuecomment-6784691680) Rebased onto current main (7d4e0d9b3) and added one commit that hardens the evaluator. The prologue forms fold as before. **Fourth commit.** The projection now accepts one `LaneBound` instruction per mask, evaluates at most 64 new nodes per bound, and rejects a `CompositeExtractU64` index other than 0 or 1. Two tests: a mask built from two different lane bounds and a mask behind an 81-step chain both stay instructions. Before this commit a hand-built mask of two different `LaneBound` values could fold wrongly; the translator emits exactly one per vertex program and none in other stages, so no real shader was affected. **More checks on real shaders, without game runs.** I recompiled 1,041 guest programs dumped from Demon's Souls, ASTRO BOT, Ghost of Yōtei and Assassin's Creed Black Flag Resynced with main and with this branch, using the test fixture's default options: - Compute (634 programs that translate) and pixel (273): the IR text is identical. - Vertex (127 programs, wave size 64 and 32): every instruction with an effect keeps its count. As a cross-check I put a brute-force version of the fold into main (evaluate each own-lane bit for every lane bound and every lane below it, replace it by true when it is always true). Its IR is byte-identical to this branch's in 234 of 254 cases; 12 differ only in the operand order of one `INotEqual32`; in 8 the count keeps a reader (three of the shaders of point 2 below, and one shader that reads bits 27:24). - The translate phase is not slower: its summed time is within 1 % for compute and pixel and about 3 % lower for vertex. - `shader_recompiler_compute_tests` on an RX 9070 XT gives the same result list as main. - `shader_cfg_tests`, which CI does not build or run, passes with this branch on Windows and Linux fork runners. On the macOS runner it stops in `TestGpuProducedWritableDescriptor` on main and on this branch alike, after this PR's two tests have passed. **Two points for your decision.** 1. The line this PR replaces carried the comment "ESVertCount describes input vertices, independently of lane ordinals". With dense subgroups the bound equals that count, so nothing changes. The two differ only when the running lanes are not a dense prefix; the count then leaves running lanes outside the guest's prefix mask. In the 770 stored vertex modules of five games no shader uses the count for anything but masks (two read only bits 27:24). 2. Not solved by this PR: 6 of those 770 modules (5 ASTRO BOT, 1 Black Flag) carry the entry mask through a loop and repeat while it is non-zero (`remaining &= ~ballot(handled)`). On a host with non-dense vertex lanes that mask keeps the bit of a lane that does not run, with the count and with the bound alike, so the loop cannot end there. Whether any real driver gives vertex shaders such subgroups I have not measured.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-11 01:57 UTC · original

Game tests are following

**@⁠Nawid3333** on GitHub · 2026-11-11 01:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2201#issuecomment-6784729805) Game tests are following
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-11 17:52 UTC · original

Game tests of the final head 166b7923f against its base 7d4e0d9b3, on an RX 9070 XT (Windows 11, driver 26.10.1). Both builds carry the same local input-player commits, so each game got the same scripted input with both (logs: Source build dfc78dc = this branch, dfc78dc-dirty = the same tree with the six changed files from 7d4e0d9b3):

  • Demon's Souls (PPSA01341)
  • STAR WARS Jedi: Fallen Order (PPSA02198)
  • Assassin's Creed Black Flag Resynced (PPSA28183)

No run crashed or stopped early: all six were ended by the time limit, none of the logs has a fatal error, and all six show GPU work.

I compared the SPIR-V modules in each run's shader store byte by byte, per stage (base / this branch / byte-identical):

Game vertex pixel compute
Demon's Souls 8 / 3 / 0 16 / 11 / 11 134 / 123 / 123
Fallen Order 90 / 153 / 0 150 / 341 / 150 69 / 71 / 69
AC Black Flag 94 / 84 / 0 185 / 173 / 173 419 / 411 / 411

Every pixel and compute module that both builds produced is byte-identical, and so are the few modules of other stages; the remaining ones are in only one of the two stores. Every vertex module differs, which is the change of this PR. So in these three games the branch changes vertex shaders only, and no game stopped with it.

Not covered: a pixel-by-pixel comparison of the rendered frames.

**@⁠Nawid3333** on GitHub · 2026-11-11 17:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2201#issuecomment-6803201841) Game tests of the final head 166b7923f against its base 7d4e0d9b3, on an RX 9070 XT (Windows 11, driver 26.10.1). Both builds carry the same local input-player commits, so each game got the same scripted input with both (logs: `Source build dfc78dc` = this branch, `dfc78dc-dirty` = the same tree with the six changed files from 7d4e0d9b3): - Demon's Souls (PPSA01341) - STAR WARS Jedi: Fallen Order (PPSA02198) - Assassin's Creed Black Flag Resynced (PPSA28183) No run crashed or stopped early: all six were ended by the time limit, none of the logs has a fatal error, and all six show GPU work. I compared the SPIR-V modules in each run's shader store byte by byte, per stage (base / this branch / byte-identical): | Game | vertex | pixel | compute | |---|---|---|---| | Demon's Souls | 8 / 3 / 0 | 16 / 11 / 11 | 134 / 123 / 123 | | Fallen Order | 90 / 153 / 0 | 150 / 341 / 150 | 69 / 71 / 69 | | AC Black Flag | 94 / 84 / 0 | 185 / 173 / 173 | 419 / 411 / 411 | Every pixel and compute module that both builds produced is byte-identical, and so are the few modules of other stages; the remaining ones are in only one of the two stores. Every vertex module differs, which is the change of this PR. So in these three games the branch changes vertex shaders only, and no game stopped with it. Not covered: a pixel-by-pixel comparison of the rendered frames.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2201/head:github-bot/gh-2201'
git switch 'github-bot/gh-2201'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2201'
git switch 'github-bot/gh-2201'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2201'
git switch 'github-bot/gh-2201'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2201'
git switch 'main'
git merge --squash 'github-bot/gh-2201'
git switch 'main'
git merge --ff-only 'github-bot/gh-2201'
git switch 'main'
git merge 'github-bot/gh-2201'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.