shader: bind both buffers when an atomic uses a descriptor chosen by a Phi #2219

Closed
github-bot wants to merge 2 commits from gh-pr/2219/head into gh-pr/2219/base
Owner

@⁠Nawid3333 on GitHub · 2026-11-11 18:30 UTC · original
Nawid3333:shader/finite-buffer-atomic-r2 → main · +256 −28 · 8 files · 2 commits · closed without merging

Fixes #2204.

Cause

A register can hold one of two buffer descriptors, depending on a branch the GPU takes. In Ghost of Yōtei's compute shader 0xc37d0172087dc1a6 the register s20 is loaded from the resource table before a loop (pc 0x8c) and again on a conditional path inside it (pc 0x660); the BUFFER_ATOMIC_ADD at pc 0x980, after the loop, uses whichever was loaded last. In the IR the descriptor is a Phi of the two loads.

Resource tracking already plans a descriptor of that kind (TryMakeFiniteDescriptor: one of a few known descriptors, picked by a Phi or a select), but only for image and sampler descriptors. For a buffer descriptor it stops with buffer descriptor is not a valid runtime value.

Change

  • TryMakeFiniteDescriptor also takes a buffer descriptor when every use of it is a 32-bit buffer atomic, and PlanIndirectDescriptors sends buffer atomics to it. Both descriptors become candidates of one resource and a key (0 or 1, the Phi of the branch) selects between them. Loads from a descriptor chosen this way keep main's path for GPU-selected descriptors. A 64-bit atomic on such a descriptor still stops with the message above.
  • Materialization keeps the candidates of a finite plan as they are. NormalizeIndirectBuffer is made for rows of a table the GPU indexes and would reject ordinary descriptors (a swizzle, another stride).
  • EmitAtomicAccess emits through EmitBufferAccess, like loads and stores do, so the atomic runs on the candidate the key selects, with that candidate's stride and offset. For a buffer without candidates it emits the same instructions as before; the element index is now computed after the resource access is prepared, so their order changes.
  • The emitter recognised an empty candidate by packed_stride == 0 on a buffer with an indirect source. A raw buffer picked by a Phi has stride 0 and such a source too, so the new EmptyIndirectBufferCandidate also requires that the source has no finite list.

#1939 is an open PR for the same message. It sends BufferAtomicIAdd32 down the path of loads from a descriptor the GPU computes; its test shape (userdata + i in a loop) is not this one, where the choice is between two descriptors that both sit in the resource table.

Tests

  • resource_tracking_tests, TestFiniteBufferAtomic: a Phi of two user-data descriptors under a 32-bit atomic gives one finite source with two entries and a key Phi of 0 and 1; after specialization both candidates exist and are atomic; a 64-bit atomic on the same shape still stops.
  • shader_cfg_tests, TestBufferAtomicOnPhiOfTwoDescriptors: guest code with two S_LOAD_DWORDX4 into s20 around a branch on a value loaded from a buffer, then BUFFER_ATOMIC_ADD. Two layouts (both raw; stride 0 and stride 4); the SPIR-V validates and the second layout has one atomic per candidate.
  • shader_recompiler_compute_tests, BufferAtomicOnPhiOfTwoDescriptors (selector --buffer-atomic-phi-only): runs that shape on the GPU with two descriptors of stride 4 and 8, and with two of stride 4 (the path where both candidates share one binding array), each once for each side of the branch, and reads back that the add landed in the selected buffer at the selected stride and that the old value was returned.

With main's src/ (bc934ef) under these tests, the first two fail with the issue's message (pc=0x00000980 and pc=0x00000020 buffer descriptor is not a valid runtime value) and the GPU test fails at pc 0x2c. With the change all three pass. Two deliberate bugs in the change (always the first candidate; the index taken from the root's stride) each make the GPU test's second case fail at readback; a third (the shared binding array always indexed at the root's slot) makes only the equal-stride second case fail.

The GPU test was run on an RX 9070 XT (Windows 11, clang-cl) with the local harness changes described in #2193; with the change the full suite has 22 failed checks, the same 22 as main 782a85c on this machine (failures of the harness on this driver that were known before). The first two tests also pass in the fork's CI on Windows, Linux and macOS (run 43014871201, on this commit before the GPU test was added, with a workflow step that runs shader_cfg_tests, which the upstream workflow does not run). The fork CI run on this head (run 43085179853) passed on Windows, Linux and macOS.

Offline, the shader dumps I have from four games (1,041 compute, pixel and vertex programs) were recompiled with main and with the change: one outcome differs, the shader above, which no longer stops in resource tracking. The IR is identical wherever both translate; of the 86 SPIR-V modules both write, 82 are byte-identical and 4 contain the same instructions in another order.

Costs

None for shaders that translate today, apart from the instruction order in shaders with buffer atomics. A shader of this shape binds both buffers and gets one branch per candidate at the atomic.

In a game

Ghost of Yōtei (PPSA26344) on an RX 9070 XT (Windows 11). On this GPU main (bc934ef) stops earlier, at descriptorHeap.cpp:55 (!Allocate(layout, fresh_batch)); #1758 gets past that, so both builds below also carry #1758.

  • main + #1758: the game stops with the message of the issue at shader 0xc37d0172087dc1a6, pc 0x980, after 147 translated compute shaders.
  • this change + #1758: the shader translates and its SPIR-V is emitted, the message does not appear, and the game keeps running until the run is ended (203 translated compute shaders by then).

Written with Claude Code (AI): Claude Code traced the shader, wrote the change and the tests and ran them; GLM reviewed the diff.

**@⁠Nawid3333** on GitHub · 2026-11-11 18:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219) `Nawid3333:shader/finite-buffer-atomic-r2` → `main` · +256 −28 · 8 files · 2 commits · closed without merging Fixes #2204. ## Cause A register can hold one of two buffer descriptors, depending on a branch the GPU takes. In Ghost of Yōtei's compute shader `0xc37d0172087dc1a6` the register `s20` is loaded from the resource table before a loop (pc 0x8c) and again on a conditional path inside it (pc 0x660); the `BUFFER_ATOMIC_ADD` at pc 0x980, after the loop, uses whichever was loaded last. In the IR the descriptor is a Phi of the two loads. Resource tracking already plans a descriptor of that kind (`TryMakeFiniteDescriptor`: one of a few known descriptors, picked by a Phi or a select), but only for image and sampler descriptors. For a buffer descriptor it stops with `buffer descriptor is not a valid runtime value`. ## Change - `TryMakeFiniteDescriptor` also takes a buffer descriptor when every use of it is a 32-bit buffer atomic, and `PlanIndirectDescriptors` sends buffer atomics to it. Both descriptors become candidates of one resource and a key (0 or 1, the Phi of the branch) selects between them. Loads from a descriptor chosen this way keep main's path for GPU-selected descriptors. A 64-bit atomic on such a descriptor still stops with the message above. - Materialization keeps the candidates of a finite plan as they are. `NormalizeIndirectBuffer` is made for rows of a table the GPU indexes and would reject ordinary descriptors (a swizzle, another stride). - `EmitAtomicAccess` emits through `EmitBufferAccess`, like loads and stores do, so the atomic runs on the candidate the key selects, with that candidate's stride and offset. For a buffer without candidates it emits the same instructions as before; the element index is now computed after the resource access is prepared, so their order changes. - The emitter recognised an empty candidate by `packed_stride == 0` on a buffer with an indirect source. A raw buffer picked by a Phi has stride 0 and such a source too, so the new `EmptyIndirectBufferCandidate` also requires that the source has no finite list. #1939 is an open PR for the same message. It sends `BufferAtomicIAdd32` down the path of loads from a descriptor the GPU computes; its test shape (`userdata + i` in a loop) is not this one, where the choice is between two descriptors that both sit in the resource table. ## Tests - `resource_tracking_tests`, `TestFiniteBufferAtomic`: a Phi of two user-data descriptors under a 32-bit atomic gives one finite source with two entries and a key Phi of 0 and 1; after specialization both candidates exist and are atomic; a 64-bit atomic on the same shape still stops. - `shader_cfg_tests`, `TestBufferAtomicOnPhiOfTwoDescriptors`: guest code with two `S_LOAD_DWORDX4` into `s20` around a branch on a value loaded from a buffer, then `BUFFER_ATOMIC_ADD`. Two layouts (both raw; stride 0 and stride 4); the SPIR-V validates and the second layout has one atomic per candidate. - `shader_recompiler_compute_tests`, `BufferAtomicOnPhiOfTwoDescriptors` (selector `--buffer-atomic-phi-only`): runs that shape on the GPU with two descriptors of stride 4 and 8, and with two of stride 4 (the path where both candidates share one binding array), each once for each side of the branch, and reads back that the add landed in the selected buffer at the selected stride and that the old value was returned. With main's `src/` (bc934ef) under these tests, the first two fail with the issue's message (`pc=0x00000980` and `pc=0x00000020 buffer descriptor is not a valid runtime value`) and the GPU test fails at pc 0x2c. With the change all three pass. Two deliberate bugs in the change (always the first candidate; the index taken from the root's stride) each make the GPU test's second case fail at readback; a third (the shared binding array always indexed at the root's slot) makes only the equal-stride second case fail. The GPU test was run on an RX 9070 XT (Windows 11, clang-cl) with the local harness changes described in #2193; with the change the full suite has 22 failed checks, the same 22 as main 782a85c on this machine (failures of the harness on this driver that were known before). The first two tests also pass in the fork's CI on Windows, Linux and macOS ([run 43014871201](https://github.com/Nawid3333/KytyPS5/actions/runs/43014871201), on this commit before the GPU test was added, with a workflow step that runs `shader_cfg_tests`, which the upstream workflow does not run). The fork CI run on this head ([run 43085179853](https://github.com/Nawid3333/KytyPS5/actions/runs/43085179853)) passed on Windows, Linux and macOS. Offline, the shader dumps I have from four games (1,041 compute, pixel and vertex programs) were recompiled with main and with the change: one outcome differs, the shader above, which no longer stops in resource tracking. The IR is identical wherever both translate; of the 86 SPIR-V modules both write, 82 are byte-identical and 4 contain the same instructions in another order. ## Costs None for shaders that translate today, apart from the instruction order in shaders with buffer atomics. A shader of this shape binds both buffers and gets one branch per candidate at the atomic. ## In a game Ghost of Yōtei (PPSA26344) on an RX 9070 XT (Windows 11). On this GPU main (bc934ef) stops earlier, at `descriptorHeap.cpp:55` (`!Allocate(layout, fresh_batch)`); #1758 gets past that, so both builds below also carry #1758. - main + #1758: the game stops with the message of the issue at shader `0xc37d0172087dc1a6`, pc 0x980, after 147 translated compute shaders. - this change + #1758: the shader translates and its SPIR-V is emitted, the message does not appear, and the game keeps running until the run is ended (203 translated compute shaders by then). Written with Claude Code (AI): Claude Code traced the shader, wrote the change and the tests and ran them; GLM reviewed the diff.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:16:59 +00:00
github-bot closed this pull request 2026-11-26 10:16:59 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 18:41 UTC · original · edited 2026-11-11 19:15 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Resource tracking now plans finite buffer descriptors for 32-bit atomics that use selected descriptors. Materialization skips indirect-buffer normalization for descriptors with explicit sources. The SPIR-V emitter uses a shared predicate for empty indirect-buffer candidates and routes atomic access through EmitBufferAccess. New tests cover descriptor planning, SPIR-V generation, and compute execution.

Suggested reviewers: nmzik

Change: Bug fix · Severity of issue fixed: High

Merge Risk: Minimal · up to 96832

This change adds support for buffer atomics on descriptors selected between two candidates. No actionable merge-blocking risk remains in the supplied evidence. The author did not report that Ghost of Yōtei reaches the main menu, though its shader now translates.

Pre-merge checks: Passed 3 · Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #2204 requires the game to boot to the main menu. The change addresses the reported buffer descriptor is not a valid runtime value failure and adds focused resource-tracking, CFG, and compute … Establish whether the reviewed build boots to the main menu. If it does not, address the remaining blocker before claiming full compliance with issue #2204.
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: 3 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: binding both candidate buffers when a buffer atomic uses a descriptor selected by a Phi.
Description check Passed The description is directly related to the changeset. It explains the cause, implementation, tests, known limitations, and observed results.
Out of Scope Changes check Passed The changes stay within issue #2204. They extend finite descriptor tracking for 32-bit buffer atomics, preserve the existing failure for unsupported buffer uses, update atomic buffer emission, and add…
Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2204. They extend finite descriptor tracking for 32-bit buffer atomics, preserve the existing failure for unsupported buffer uses, update atomic buffer emission, and add tests for the affected Phi-selected descriptors. The emitter and materialization changes support this behavior.

Full details: Linked Issues check

Explanation

Issue #2204 requires the game to boot to the main menu. The change addresses the reported buffer descriptor is not a valid runtime value failure and adds focused resource-tracking, CFG, and compute tests. The PR report states that the game continues running after the target shader translates, but it does not establish that the game reaches the main menu.

Resolution

Establish whether the reviewed build boots to the main menu. If it does not, address the remaining blocker before claiming full compliance with issue #2204.

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 6 files. (1 skipped: 1 too large.)

Resolution

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

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 f563cfe1c9 and 9683292638.

Files selected for processing: 1

  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 18:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#issuecomment-6804277815) · edited 2026-11-11 19:15 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/2219?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> Resource tracking now plans finite buffer descriptors for 32-bit atomics that use selected descriptors. Materialization skips indirect-buffer normalization for descriptors with explicit sources. The SPIR-V emitter uses a shared predicate for empty indirect-buffer candidates and routes atomic access through `EmitBufferAccess`. New tests cover descriptor planning, SPIR-V generation, and compute execution. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"9683292638ac01e85cdca7fb13b1cc0150652346" --> <!-- change_assessment_priority:{"version":1,"urgency":"p1","manual":false} --> **Change:** Bug fix · **Severity of issue fixed:** High <!-- 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>96832</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `96832` --> <!-- final_review_risk_coverage:{"sourceCommitId":"9683292638ac01e85cdca7fb13b1cc0150652346","coveredCommitId":"9683292638ac01e85cdca7fb13b1cc0150652346","kind":"reviewed"} --> This change adds support for buffer atomics on descriptors selected between two candidates. No actionable merge-blocking risk remains in the supplied evidence. The author did not report that Ghost of Yōtei reaches the main menu, though its shader now translates. <!-- 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> 3 · <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> 2</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: 2 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :----------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Issue `#2204` requires the game to boot to the main menu. The change addresses the reported `buffer descriptor is not a valid runtime value` failure and adds focused resource-tracking, CFG, and compute … | Establish whether the reviewed build boots to the main menu. If it does not, address the remaining blocker before claiming full compliance with issue `#2204`. | | 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: 3 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: binding both candidate buffers when a buffer atomic uses a descriptor selected by a Phi. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset. It explains the cause, implementation, tests, known limitations, and observed results. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes stay within issue `#2204`. They extend finite descriptor tracking for 32-bit buffer atomics, preserve the existing failure for unsupported buffer uses, update atomic buffer emission, and add… | <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> <br> **Explanation** The changes stay within issue `#2204`. They extend finite descriptor tracking for 32-bit buffer atomics, preserve the existing failure for unsupported buffer uses, update atomic buffer emission, and add tests for the affected Phi-selected descriptors. The emitter and materialization changes support this behavior. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> <br> **Explanation** Issue `#2204` requires the game to boot to the main menu. The change addresses the reported `buffer descriptor is not a valid runtime value` failure and adds focused resource-tracking, CFG, and compute tests. The PR report states that the game continues running after the target shader translates, but it does not establish that the game reaches the main menu. **Resolution** Establish whether the reviewed build boots to the main menu. If it does not, address the remaining blocker before claiming full compliance with issue `#2204`. </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 6 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 --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2219)! 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/bc934ef03410b760fbf8e49db1d79485e7e5f887/.coderabbit.yaml>) - **Commit**: [bc934ef](<https://github.com/KytyPS5/KytyPS5/commit/bc934ef03410b760fbf8e49db1d79485e7e5f887>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `19b08faf-9714-4839-8391-a8483d16b9c6` </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 f563cfe1c928e7d70b35fe5dbaff537b6792a6dd and 9683292638ac01e85cdca7fb13b1cc0150652346. </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: 1</strong></summary> <dl> <dd> <br> * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
@ -1668,1 +1667,3 @@
value, source->indirect_descriptor->indexed, base);
return !source->indirect_descriptor->sources.empty() ||
NormalizeIndirectBuffer(
value, source->indirect_descriptor->indexed, base);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 18:41 UTC · original · edited 2026-11-11 19:28 UTC

Minor · Data Integrity & Integration · Heavy lift

Supported by static analysis

Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline \
  src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp \
  --match ApplyResourceSpecialization --view expanded

rg -n -C 6 \
  'zero_stride_oob|indirect_resources|NumRecords\(|OutOfBounds\(' \
  src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 42203


Script executed:

rg -n 'NormalizeIndirectBuffer|CalculateBufferAddress|EmitAtomicAccess|ApplyResourceSpecialization|OutOfBounds\(\)|struct BufferDescriptor' src/graphics/shader/recompiler src/graphics | grep -E 'ResourceMaterialization|spirvEmitterMemory|BufferDescriptor|Graphic' 
cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1510,1702p;1828,1858p;1940,2035p'
cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '580,735p'

Repository: KytyPS5/KytyPS5

Length of output: 32852


Script executed:

rg -n 'NormalizeIndirectBuffer|CalculateBufferAddress|EmitAtomicAccess|ApplyResourceSpecialization|OutOfBounds\(\)|struct BufferDescriptor' src/graphics/shader/recompiler src/graphics | grep -E 'ResourceMaterialization|spirvEmitterMemory|BufferDescriptor|Graphic'
cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1510,1702p;1828,1858p;1940,2035p'
cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '580,735p'

Repository: KytyPS5/KytyPS5

Length of output: 32852


Script executed:

cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '1,165p'
cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '200,255p'
rg -n 'MaterializeIndirectDescriptor|indirect\.sources|EmitBufferAccess|EmitMemoryElementInBounds|BufferIndexInBounds' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp
rg -n -i 'num_records|numrecords|out.of.bounds|outofbounds' tests/ShaderRecompilerComputeTests.cpp tests/resourceTrackingTests.cpp src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | grep -E 'index|bounds|record|OutOfBounds' | sed -n '1,100p'

Repository: KytyPS5/KytyPS5

Length of output: 19997


Script executed:

cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '546,650p;250,266p'
cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '220,380p'
cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp | sed -n '135,190p;285,365p'
rg -n 'FiniteBufferAtomic|BufferAtomicOnPhiOfTwoDescriptors|sources\.push_back|sources = ' tests src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp

Repository: KytyPS5/KytyPS5

Length of output: 37246


Script executed:

rg -n 'sources\)|sources\]|: sources|sources\.' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1,100p'
cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '800,920p'
cat -n src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '3865,3960p'
cat -n tests/ResourceTrackingTests.cpp | sed -n '8095,8190p'
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '35890,36045p'

Repository: KytyPS5/KytyPS5

Length of output: 26985


Enforce candidate bounds before the atomic address wraps.

For a mode-0 candidate with stride 16 and one record, index 0x10000000 wraps the byte address to zero. The atomic can then modify record zero instead of discarding the out-of-bounds write. Check the original index against the selected descriptor’s bounds before emitting the atomic.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 18:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#discussion_r4541888321) · edited 2026-11-11 19:28 UTC <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Data Integrity & Integration** · **Heavy lift** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> <br> Script executed: ```bash #!/bin/bash set -euo pipefail ast-grep outline \ src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp \ --match ApplyResourceSpecialization --view expanded rg -n -C 6 \ 'zero_stride_oob|indirect_resources|NumRecords\(|OutOfBounds\(' \ src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 42203 --- Script executed: ```bash rg -n 'NormalizeIndirectBuffer|CalculateBufferAddress|EmitAtomicAccess|ApplyResourceSpecialization|OutOfBounds\(\)|struct BufferDescriptor' src/graphics/shader/recompiler src/graphics | grep -E 'ResourceMaterialization|spirvEmitterMemory|BufferDescriptor|Graphic' cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1510,1702p;1828,1858p;1940,2035p' cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '580,735p' ``` Repository: KytyPS5/KytyPS5 Length of output: 32852 --- Script executed: ```bash rg -n 'NormalizeIndirectBuffer|CalculateBufferAddress|EmitAtomicAccess|ApplyResourceSpecialization|OutOfBounds\(\)|struct BufferDescriptor' src/graphics/shader/recompiler src/graphics | grep -E 'ResourceMaterialization|spirvEmitterMemory|BufferDescriptor|Graphic' cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1510,1702p;1828,1858p;1940,2035p' cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '580,735p' ``` Repository: KytyPS5/KytyPS5 Length of output: 32852 --- Script executed: ```bash cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '1,165p' cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '200,255p' rg -n 'MaterializeIndirectDescriptor|indirect\.sources|EmitBufferAccess|EmitMemoryElementInBounds|BufferIndexInBounds' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp rg -n -i 'num_records|numrecords|out.of.bounds|outofbounds' tests/ShaderRecompilerComputeTests.cpp tests/resourceTrackingTests.cpp src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | grep -E 'index|bounds|record|OutOfBounds' | sed -n '1,100p' ``` Repository: KytyPS5/KytyPS5 Length of output: 19997 --- Script executed: ```bash cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '546,650p;250,266p' cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp | sed -n '220,380p' cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp | sed -n '135,190p;285,365p' rg -n 'FiniteBufferAtomic|BufferAtomicOnPhiOfTwoDescriptors|sources\.push_back|sources = ' tests src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 37246 --- Script executed: ```bash rg -n 'sources\)|sources\]|: sources|sources\.' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1,100p' cat -n src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '800,920p' cat -n src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '3865,3960p' cat -n tests/ResourceTrackingTests.cpp | sed -n '8095,8190p' cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '35890,36045p' ``` Repository: KytyPS5/KytyPS5 Length of output: 26985 --- </dd> </dl> </details> **Enforce candidate bounds before the atomic address wraps.** For a mode-0 candidate with stride 16 and one record, index `0x10000000` wraps the byte address to zero. The atomic can then modify record zero instead of discarding the out-of-bounds write. Check the original index against the selected descriptor’s bounds before emitting the atomic. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8a291bf5d65f086114caf0b5 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 18:41 UTC · original · reviewed

Actionable comments posted: 1

Nitpick comments: 1

tests/shaderCfgTests.cpp: 1

7229-7229: Trivial · Maintainability & Code Quality · Quick win

Test equal-stride selection at runtime.

The CFG test checks the atomic count but not the selected buffer. The GPU test uses different strides, so it does not exercise the shared-resource path. Add an equal-stride GPU case for both selections and check the changed buffer and returned value.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bc934ef034 and f563cfe1c9.

Files selected for processing: 8

  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.cpp
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 18:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#pullrequestreview-5863761056) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/brush-cleaning.svg" width="16" height="16" align="absmiddle" alt=""></picture> Nitpick comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>tests/shaderCfgTests.cpp: 1</summary><blockquote> <dl> <dd> <br> `7229-7229`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/neutral-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Trivial** · **Maintainability & Code Quality** · **Quick win** **Test equal-stride selection at runtime.** The CFG test checks the atomic count but not the selected buffer. The GPU test uses different strides, so it does not exercise the shared-resource path. Add an equal-stride GPU case for both selections and check the changed buffer and returned value. <!-- cr-comment:v1:c9c1a771632da11e3e51e034 --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><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</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/bc934ef03410b760fbf8e49db1d79485e7e5f887/.coderabbit.yaml>) - **Commit**: [bc934ef](<https://github.com/KytyPS5/KytyPS5/commit/bc934ef03410b760fbf8e49db1d79485e7e5f887>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `627fdf11-36d6-4ac0-b844-f5cc39f8049e` </dd> </dl> </details> <details> <summary><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</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between bc934ef03410b760fbf8e49db1d79485e7e5f887 and f563cfe1c928e7d70b35fe5dbaff537b6792a6dd. </dd> </dl> </details> <details> <summary><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: 8</summary> <dl> <dd> <br> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.cpp` * `tests/ShaderRecompilerComputeTests.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; 8 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=d0a78c5c-e531-49a3-bade-927b2fe79fde attempt=c01548de-a8e1-4d66-a3b3-4c64b963f493 batch=1/1 -->
@ -1668,1 +1667,3 @@
value, source->indirect_descriptor->indexed, base);
return !source->indirect_descriptor->sources.empty() ||
NormalizeIndirectBuffer(
value, source->indirect_descriptor->indexed, base);
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-11 19:28 UTC · original

@⁠coderabbitai The wrap is real, but this PR does not introduce it, and it is not specific to atomics. CalculateBufferAddress in spirvEmitterMemory.cpp computes index * stride + offset in 32 bits for every indexed buffer access. After that, the wrapped address is only checked as an element index against the binding length (EmitMemoryElementInBounds / EmitStorageElementInBounds). An atomic on a single descriptor on main takes the same path (DwordIndex + EmitMemoryElementInBounds), and loads use the same address with EmitStorageElementInBounds, so index 0x10000000 with stride 16 reaches record zero there too. Only descriptors read from an indexed table compare the original index before the multiplication (BufferIndexInBounds). This PR routes the Phi-selected atomic through the same path as an atomic on one descriptor. A record-index check for all indexed loads, stores and atomics belongs in that shared address path, so it will be a separate change.

The equal-stride GPU case from the nitpick is added in 968329263: BufferAtomicOnPhiOfTwoDescriptors also runs with both strides equal, which takes the shared-binding path, for both selections, and checks the changed buffer and the returned value.

**@⁠Nawid3333** on GitHub · 2026-11-11 19:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#discussion_r4542350549) @⁠coderabbitai The wrap is real, but this PR does not introduce it, and it is not specific to atomics. `CalculateBufferAddress` in `spirvEmitterMemory.cpp` computes `index * stride + offset` in 32 bits for every indexed buffer access. After that, the wrapped address is only checked as an element index against the binding length (`EmitMemoryElementInBounds` / `EmitStorageElementInBounds`). An atomic on a single descriptor on `main` takes the same path (`DwordIndex` + `EmitMemoryElementInBounds`), and loads use the same address with `EmitStorageElementInBounds`, so index `0x10000000` with stride 16 reaches record zero there too. Only descriptors read from an indexed table compare the original index before the multiplication (`BufferIndexInBounds`). This PR routes the Phi-selected atomic through the same path as an atomic on one descriptor. A record-index check for all indexed loads, stores and atomics belongs in that shared address path, so it will be a separate change. The equal-stride GPU case from the nitpick is added in 968329263: `BufferAtomicOnPhiOfTwoDescriptors` also runs with both strides equal, which takes the shared-binding path, for both selections, and checks the changed buffer and the returned value.
@ -1668,1 +1667,3 @@
value, source->indirect_descriptor->indexed, base);
return !source->indirect_descriptor->sources.empty() ||
NormalizeIndirectBuffer(
value, source->indirect_descriptor->indexed, base);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-11 19:29 UTC · original

Analysis chain

Script executed:

#!/bin/bash
set -u
memory="src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp"
helpers="src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp"
tests="tests/ShaderRecompilerComputeTests.cpp"

echo '=== HEAD and available base references ==='
git rev-parse HEAD
git branch -r
base=$(gh pr view 2219 --repo KytyPS5/KytyPS5 --json baseRefOid --jq .baseRefOid 2>/dev/null || true)
echo "PR base: ${base:-unavailable}"
if [ -z "$base" ]; then base=$(git merge-base HEAD origin/main 2>/dev/null || true); fi

echo '=== HEAD outlines ==='
ast-grep outline "$memory" --items all --match 'CalculateBufferAddress|DwordIndex|EmitAtomicAccess|EmitBufferAccess|EmitStorageElementInBounds|EmitMemoryElementInBounds' --view expanded
ast-grep outline "$helpers" --items all --match 'BufferIndexInBounds|SharedIndirectBufferResource' --view expanded
ast-grep outline "$tests" --items all --match 'BufferAtomicOnPhiOfTwoDescriptors' --view expanded

echo '=== HEAD emitter relevant source ==='
cat -n "$memory" | sed -n '1,170p;220,380p;580,740p'
echo '=== HEAD helper relevant source ==='
rg -n -C 12 '\b(BufferIndexInBounds|SharedIndirectBufferResource)\s*\(' "$helpers" "$memory"
echo '=== equal stride test ==='
line=$(rg -n 'void BufferAtomicOnPhiOfTwoDescriptors\s*\(' "$tests" | head -1 | cut -d: -f1)
if [ -n "$line" ]; then end=$((line+150)); cat -n "$tests" | sed -n "${line},${end}p"; fi
rg -n -C 4 'BufferAtomicOnPhiOfTwoDescriptors|buffer-atomic-phi-only' "$tests"

echo '=== base emitter ==='
if [ -n "$base" ]; then
  if ! git show "${base}:${memory}" > /tmp/base-spirvEmitterMemory.cpp 2>/dev/null; then
    gh api "repos/KytyPS5/KytyPS5/contents/${memory}?ref=${base}" --jq .content 2>/dev/null | base64 -d > /tmp/base-spirvEmitterMemory.cpp || true
  fi
  if [ -s /tmp/base-spirvEmitterMemory.cpp ]; then
    rg -n -C 14 '\b(CalculateBufferAddress|DwordIndex|EmitAtomicAccess|EmitStorageElementInBounds|EmitMemoryElementInBounds)\s*\(' /tmp/base-spirvEmitterMemory.cpp
  else
    echo 'Base source unavailable'
  fi
  echo '=== emitter changes from base ==='
  git diff "$base" HEAD -- "$memory" | sed -n '1,240p' || true
else
  echo 'Base revision unavailable'
fi

Length of output: 87892


Script executed:

#!/bin/bash
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --items all --match BufferAtomicOnPhiOfTwoDescriptors --view expanded
ast-grep outline src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp --items all --match SharedIndirectBufferResource --view expanded
cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '35921,36015p'
cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp | sed -n '141,163p'

Length of output: 7822


@Nawid3333 You’re right. The base implementation already uses 32-bit address multiplication before the atomic bounds check. I withdraw the finding as a PR-specific regression.

I also checked the equal-stride test. It covers both selections and checks the changed buffer and returned value. I did not run it.

Would you like me to open a follow-up issue for the shared bounds check?

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-11 19:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#discussion_r4542364724) <!-- coderabbit-ai-generated:v1 --> <details> <summary>Analysis chain</summary> <dl> <dd> <br> Script executed: ```shell #!/bin/bash set -u memory="src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp" helpers="src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp" tests="tests/ShaderRecompilerComputeTests.cpp" echo '=== HEAD and available base references ===' git rev-parse HEAD git branch -r base=$(gh pr view 2219 --repo KytyPS5/KytyPS5 --json baseRefOid --jq .baseRefOid 2>/dev/null || true) echo "PR base: ${base:-unavailable}" if [ -z "$base" ]; then base=$(git merge-base HEAD origin/main 2>/dev/null || true); fi echo '=== HEAD outlines ===' ast-grep outline "$memory" --items all --match 'CalculateBufferAddress|DwordIndex|EmitAtomicAccess|EmitBufferAccess|EmitStorageElementInBounds|EmitMemoryElementInBounds' --view expanded ast-grep outline "$helpers" --items all --match 'BufferIndexInBounds|SharedIndirectBufferResource' --view expanded ast-grep outline "$tests" --items all --match 'BufferAtomicOnPhiOfTwoDescriptors' --view expanded echo '=== HEAD emitter relevant source ===' cat -n "$memory" | sed -n '1,170p;220,380p;580,740p' echo '=== HEAD helper relevant source ===' rg -n -C 12 '\b(BufferIndexInBounds|SharedIndirectBufferResource)\s*\(' "$helpers" "$memory" echo '=== equal stride test ===' line=$(rg -n 'void BufferAtomicOnPhiOfTwoDescriptors\s*\(' "$tests" | head -1 | cut -d: -f1) if [ -n "$line" ]; then end=$((line+150)); cat -n "$tests" | sed -n "${line},${end}p"; fi rg -n -C 4 'BufferAtomicOnPhiOfTwoDescriptors|buffer-atomic-phi-only' "$tests" echo '=== base emitter ===' if [ -n "$base" ]; then if ! git show "${base}:${memory}" > /tmp/base-spirvEmitterMemory.cpp 2>/dev/null; then gh api "repos/KytyPS5/KytyPS5/contents/${memory}?ref=${base}" --jq .content 2>/dev/null | base64 -d > /tmp/base-spirvEmitterMemory.cpp || true fi if [ -s /tmp/base-spirvEmitterMemory.cpp ]; then rg -n -C 14 '\b(CalculateBufferAddress|DwordIndex|EmitAtomicAccess|EmitStorageElementInBounds|EmitMemoryElementInBounds)\s*\(' /tmp/base-spirvEmitterMemory.cpp else echo 'Base source unavailable' fi echo '=== emitter changes from base ===' git diff "$base" HEAD -- "$memory" | sed -n '1,240p' || true else echo 'Base revision unavailable' fi ``` Length of output: 87892 --- Script executed: ```shell #!/bin/bash ast-grep outline tests/ShaderRecompilerComputeTests.cpp --items all --match BufferAtomicOnPhiOfTwoDescriptors --view expanded ast-grep outline src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp --items all --match SharedIndirectBufferResource --view expanded cat -n tests/ShaderRecompilerComputeTests.cpp | sed -n '35921,36015p' cat -n src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp | sed -n '141,163p' ``` Length of output: 7822 --- </dd> </dl> </details> `@Nawid3333` You’re right. The base implementation already uses 32-bit address multiplication before the atomic bounds check. I withdraw the finding as a PR-specific regression. I also checked the equal-stride test. It covers both selections and checks the changed buffer and returned value. I did not run it. Would you like me to open a follow-up issue for the shared bounds check? <!-- <review_comment_withdrawn> --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-12 03:39 UTC · original

Ben-Dash ran this PR's Windows build (fork build 9683292, the head of this PR) with Ghost of Yōtei and posted the log in #2204 (comment):

  • His earlier log, on the official build 7d4e0d9, ends with the message of the issue at shader 0xc37d0172087dc1a6, pc 0x980, after Shaders: VS 19 | PS 46 | CS 157.
  • With this build the message does not appear. The game reaches Shaders: VS 138 | PS 151 | CS 467 and then stops at image heaps exceed 65536 resident images (imageHeap.cpp:389), a limit this PR does not change.

This build does not include #1758; on his system main reaches this shader without it.

**@⁠Nawid3333** on GitHub · 2026-11-12 03:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2219#issuecomment-6813678770) Ben-Dash ran this PR's Windows build (fork build 9683292, the head of this PR) with Ghost of Yōtei and posted the log in #2204 ([comment](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2204)): - His earlier log, on the official build 7d4e0d9, ends with the message of the issue at shader `0xc37d0172087dc1a6`, pc 0x980, after `Shaders: VS 19 | PS 46 | CS 157`. - With this build the message does not appear. The game reaches `Shaders: VS 138 | PS 151 | CS 467` and then stops at `image heaps exceed 65536 resident images` (`imageHeap.cpp:389`), a limit this PR does not change. This build does not include #1758; on his system main reaches this shader without it.

Pull request closed

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