shader: keep branches on written buffers unknown #1630

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

@⁠Nawid3333 on GitHub · 2026-10-18 04:11 UTC · original
Nawid3333:shader/written-buffer-control → main · +101 −1 · 2 files · 3 commits · closed without merging

Fixes #1660 (Demon's Souls, the same error on 099de8d; the earlier reports #1591 and #1637 are closed).

What is wrong

Since c2173801 ("shader: skip resources in proven empty unsigned loops"), Demon's Souls (PPSA01341) stops a few seconds after starting with scalar resource reads overlap a shader buffer write (descriptors.cpp:955 on 763d3be3). Five people reported it in #1591, the latest on fe3857a, and #1660 shows it on 099de8d; builds 5dec523 and d58aefd run the game without this error.

The shader is compute shader 0x02632cb15eb8128d from kavg13's log. Every lane loads an item count from a buffer (BUFFER_LOAD_DWORD, offset 0), branches on gid < count, and later updates the same buffer with BUFFER_ATOMIC_ADD. c2173801 lets ULessThan32 into the projected control predicates, so at draw time the walker now reads the count to try to prove the branch empty. That read becomes a specialization read, and because the same dispatch writes the buffer, CommitBindings rejects it. The check is right: the shader may change the value the host read. For gid < count the read can only prove the branch empty when the count is 0, and a value the shader itself writes is not a draw-time constant anyway.

What changes

ExtractResourcePlan leaves a predicate unknown (both sides reachable) when it depends on a vector load (LoadBufferU32) of a buffer the shader writes (info.buffers[...].written, which includes atomics and is the flag CommitBindings uses). Only predicates that depend on such a load change; c2173801's empty-loop proof for counts read from scalar memory works as before. Scalar ReadConstBuffer loads are not affected: the Writable case of TestConservativeBufferReachability expects branches on values loaded with ReadConstBuffer to stay projected. The change also covers comparisons such as count != 0, which were projected before c2173801 too: that case of the new test already fails on 56d03f16.

How I checked it without the game

The log has the shader's RDNA2 listing but not its binary, so I encoded its 58 instructions (78 dwords) from the listing; Kyty's decoder prints all 58 back exactly as the log shows them. Then I ran the recompiler's own planning path on the CPU (TranslateProgram, ExtractResourcePlan, MaterializeResources, CompileProgram) and applied CommitBindings' overlap rule:

  • 56d03f16 (parent of c2173801): no specialization reads, no EXIT;
  • c2173801 and 763d3be3: the count is read inside the written buffer, the same EXIT;
  • with this change: no read inside a written buffer.

The log does not contain the game's buffer descriptor, so the reconstruction assumes OOB_SELECT 0, which Kyty requires for indexed buffers and which all six buffer descriptor dumps I found in logs of other games have. A run of the game with this PR's build would confirm it. Saros (#1626) stops with the same error on the same builds; its log doesn't include the shader, so I can't tell whether it is the same case.

Tests

  • New TestBranchOnWrittenBufferNotCaptured (resource_materialization_tests): a branch lane < count or count != 0 on a count loaded with LoadBufferU32, for count 0 and 3. If the shader writes that buffer, no specialization read may land in it (fails on 763d3be3, passes with this change). If the buffer is read-only, the read must still be captured, so the projection stays on.
  • All CPU test programs that build on Windows pass (ctest), except kernel_file_system, which also fails on 763d3be3.
  • On my RX 9070 XT and Ryzen 7600X iGPU, native and with the harness forced to 32-wide subgroups (a local switch), the 807 compute-suite entries and the 30 graphics cases give the same pass/fail results as on 763d3be3.
  • Fork CI (build and tests on Windows, Linux and macOS) passes on 5ee50326 (this PR's head).

@⁠kavg13 @⁠Kassadd, if you have time, could you try the Windows build of this PR (the KytyPS5-Windows-x64 artifact of its CI run) with Demon's Souls?

If you'd like this done differently, tell me and I'll change it.

Written with Claude Code (AI): it traced the crash to c2173801 from the log, wrote the change and the test, and ran the tests on my PC (Windows 11, RX 9070 XT and Ryzen 7600X iGPU, AMD driver 26.8.1).

🤖 Generated with Claude Code

**@⁠Nawid3333** on GitHub · 2026-10-18 04:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630) `Nawid3333:shader/written-buffer-control` → `main` · +101 −1 · 2 files · 3 commits · closed without merging Fixes #1660 (Demon's Souls, the same error on 099de8d; the earlier reports #1591 and #1637 are closed). **What is wrong** Since c2173801 ("shader: skip resources in proven empty unsigned loops"), Demon's Souls (PPSA01341) stops a few seconds after starting with `scalar resource reads overlap a shader buffer write` (descriptors.cpp:955 on 763d3be3). Five people reported it in #1591, the latest on fe3857a, and #1660 shows it on 099de8d; builds 5dec523 and d58aefd run the game without this error. The shader is compute shader `0x02632cb15eb8128d` from kavg13's log. Every lane loads an item count from a buffer (`BUFFER_LOAD_DWORD`, offset 0), branches on `gid < count`, and later updates the same buffer with `BUFFER_ATOMIC_ADD`. c2173801 lets `ULessThan32` into the projected control predicates, so at draw time the walker now reads the count to try to prove the branch empty. That read becomes a specialization read, and because the same dispatch writes the buffer, CommitBindings rejects it. The check is right: the shader may change the value the host read. For `gid < count` the read can only prove the branch empty when the count is 0, and a value the shader itself writes is not a draw-time constant anyway. **What changes** `ExtractResourcePlan` leaves a predicate unknown (both sides reachable) when it depends on a vector load (`LoadBufferU32`) of a buffer the shader writes (`info.buffers[...].written`, which includes atomics and is the flag CommitBindings uses). Only predicates that depend on such a load change; c2173801's empty-loop proof for counts read from scalar memory works as before. Scalar `ReadConstBuffer` loads are not affected: the Writable case of `TestConservativeBufferReachability` expects branches on values loaded with `ReadConstBuffer` to stay projected. The change also covers comparisons such as `count != 0`, which were projected before c2173801 too: that case of the new test already fails on 56d03f16. **How I checked it without the game** The log has the shader's RDNA2 listing but not its binary, so I encoded its 58 instructions (78 dwords) from the listing; Kyty's decoder prints all 58 back exactly as the log shows them. Then I ran the recompiler's own planning path on the CPU (TranslateProgram, ExtractResourcePlan, MaterializeResources, CompileProgram) and applied CommitBindings' overlap rule: - 56d03f16 (parent of c2173801): no specialization reads, no EXIT; - c2173801 and 763d3be3: the count is read inside the written buffer, the same EXIT; - with this change: no read inside a written buffer. The log does not contain the game's buffer descriptor, so the reconstruction assumes OOB_SELECT 0, which Kyty requires for indexed buffers and which all six buffer descriptor dumps I found in logs of other games have. A run of the game with this PR's build would confirm it. Saros (#1626) stops with the same error on the same builds; its log doesn't include the shader, so I can't tell whether it is the same case. **Tests** - New `TestBranchOnWrittenBufferNotCaptured` (resource_materialization_tests): a branch `lane < count` or `count != 0` on a count loaded with `LoadBufferU32`, for count 0 and 3. If the shader writes that buffer, no specialization read may land in it (fails on 763d3be3, passes with this change). If the buffer is read-only, the read must still be captured, so the projection stays on. - All CPU test programs that build on Windows pass (ctest), except `kernel_file_system`, which also fails on 763d3be3. - On my RX 9070 XT and Ryzen 7600X iGPU, native and with the harness forced to 32-wide subgroups (a local switch), the 807 compute-suite entries and the 30 graphics cases give the same pass/fail results as on 763d3be3. - Fork CI (build and tests on Windows, Linux and macOS) passes on 5ee50326 (this PR's head). @⁠kavg13 @⁠Kassadd, if you have time, could you try the Windows build of this PR (the `KytyPS5-Windows-x64` artifact of its CI run) with Demon's Souls? If you'd like this done differently, tell me and I'll change it. Written with Claude Code (AI): it traced the crash to c2173801 from the log, wrote the change and the test, and ran the tests on my PC (Windows 11, RX 9070 XT and Ryzen 7600X iGPU, AMD driver 26.8.1). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A load from a buffer the shader writes is not a draw-time constant. Since c2173801, a branch
such as gid < count, with count loaded from such a buffer, was projected: the walker read
count, and CommitBindings exited because that read always lies in the written range (#1591,
Demon's Souls). Branches on vector loads of a buffer the shader writes now stay unknown,
which also covers comparisons such as count != 0 that were projected before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SrtRuntime has no read_memory since d7856753; the walker reads guest memory through
FakeGuestMemory, as the other tests in this file do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:02:02 +00:00
github-bot closed this pull request 2026-11-26 10:02:02 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:16 UTC · original · edited 2026-10-30 01:00 UTC

Review in Change Stack →

Walkthrough

Resource-plan extraction now scans predicate instruction graphs for LoadBufferU32 reads from buffers marked written. Predicates with those reads do not use the direct integer runtime-value path and instead use existing predicate-projection handling. Tests cover unsigned-bound and nonzero predicates with written and read-only buffers, including descriptor retention and specialization-read capture.

Suggested reviewers: nmzik

Priority: Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 9e7bb

The change preserves unknown written-buffer predicates. A test improvement is recommended, but no merge-blocking risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% 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: keeping branches dependent on shader-written buffers unknown.
Description check Passed The description directly explains the reported error, the implementation change, the added tests, and validation results. It is clearly related to the changeset.
Linked Issues check Passed Active issue #1660 requires Demon's Souls to pass the startup failure and reach gameplay without the emulator buffer-write overlap error. ExtractResourcePlan now leaves predicates that depend on `Lo…
Out of Scope Changes check Passed The changes stay within issue #1660. The source change limits resource planning for predicates that read shader-written buffers. The added test directly verifies the reported overlap case and the requ…
Full details: Linked Issues check

Explanation

Active issue #1660 requires Demon's Souls to pass the startup failure and reach gameplay without the emulator buffer-write overlap error. ExtractResourcePlan now leaves predicates that depend on LoadBufferU32 from a written buffer unknown. TestBranchOnWrittenBufferNotCaptured covers lane &lt; count and count != 0, with zero and nonzero values, and preserves capture for read-only buffers. The reported follow-up runs reached character creation or gameplay with this change. Closed issues #1591 and #1637 provide context only.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1660. The source change limits resource planning for predicates that read shader-written buffers. The added test directly verifies the reported overlap case and the required read-only behavior. No unrelated production behavior or unrelated test scope is shown.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff 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 3 functions across 2 files.

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#issuecomment-6245562559) · edited 2026-10-30 01:00 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/1630?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> Resource-plan extraction now scans predicate instruction graphs for `LoadBufferU32` reads from buffers marked written. Predicates with those reads do not use the direct integer runtime-value path and instead use existing predicate-projection handling. Tests cover unsigned-bound and nonzero predicates with written and read-only buffers, including descriptor retention and specialization-read capture. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong> <!-- change_assessment_commit:"9e7bb9d71fff802268bcee4fb8702e99f66c9323" --> **Change:** Bug fix · **Severity of issue fixed:** Medium <!-- 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>9e7bb</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `9e7bb` --> <!-- final_review_risk_coverage:{"sourceCommitId":"9e7bb9d71fff802268bcee4fb8702e99f66c9323","coveredCommitId":"9e7bb9d71fff802268bcee4fb8702e99f66c9323","kind":"reviewed"} --> The change preserves unknown written-buffer predicates. A test improvement is recommended, but no merge-blocking risk is established. <!-- 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-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff 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> | 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: keeping branches dependent on shader-written buffers unknown. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the reported error, the implementation change, the added tests, and validation results. It is clearly related to the changeset. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Active issue `#1660` requires Demon's Souls to pass the startup failure and reach gameplay without the emulator buffer-write overlap error. `ExtractResourcePlan` now leaves predicates that depend on `Lo… | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes stay within issue `#1660`. The source change limits resource planning for predicates that read shader-written buffers. The added test directly verifies the reported overlap case and the requ… | <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> **Explanation** Active issue `#1660` requires Demon's Souls to pass the startup failure and reach gameplay without the emulator buffer-write overlap error. `ExtractResourcePlan` now leaves predicates that depend on `LoadBufferU32` from a written buffer unknown. `TestBranchOnWrittenBufferNotCaptured` covers `lane &lt; count` and `count != 0`, with zero and nonzero values, and preserves capture for read-only buffers. The reported follow-up runs reached character creation or gameplay with this change. Closed issues `#1591` and `#1637` provide context only. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> **Explanation** The changes stay within issue `#1660`. The source change limits resource planning for predicates that read shader-written buffers. The added test directly verifies the reported overlap case and the required read-only behavior. No unrelated production behavior or unrelated test scope is shown. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff 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 3 functions across 2 files. **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=1630)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@⁠coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -1492,0 +1501,4 @@
const auto& memory = program.memory_info.at(inst->Flags<MemoryFlags>().index);
if (memory.kind == ResourceKind::Buffer &&
memory.resource < program.info.buffers.size() &&
program.info.buffers[memory.resource].written)
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:16 UTC · original · edited 2026-10-18 04:36 UTC

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --unified=35 763d3be3a9bc4e5a068d7cf52015030d6c03308f 5ee503269a37a2b92ba9b354d58d2917b905e511 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- target and related symbols ---'
rg -n -F --glob '*.{cpp,h,hpp,c,cc}' -e 'program.info.buffers' -e 'ResourceKind::Buffer' -e 'TestBranchOnWrittenBufferNotCaptured' -e 'written' src tests 2>/dev/null || true
printf '%s\n' '--- target source ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1300,1425p'
printf '%s\n' '--- test files ---'
rg -n -F --glob '*.{cpp,h,hpp}' -- 'TestBranchOnWrittenBufferNotCaptured' . || true

Repository: KytyPS5/KytyPS5

Length of output: 41530


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- added test ---'
nl -ba tests/ResourceMaterializationTests.cpp | sed -n '990,1105p'
printf '%s\n' '--- buffer metadata and resource assignment ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'struct BufferInfo' -e 'class BufferInfo' -e 'descriptor_index' -e 'descriptor.Base48' -e 'resources.buffers' src/graphics | head -220
printf '%s\n' '--- materialization dispatch buffer mapping ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1535,1610p'
printf '%s\n' '--- renderer buffer setup and overlap checks ---'
nl -ba src/graphics/host_gpu/renderer/renderCompute.cpp | sed -n '40,95p'
nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '710,775p'
nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '900,970p'

Repository: KytyPS5/KytyPS5

Length of output: 28392


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- metadata declarations ---'
nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '100,175p'
printf '%s\n' '--- control-read flow ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1440,1538p'
printf '%s\n' '--- buffer resource tracking and descriptor slots ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '3680,3760p'
nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp | sed -n '195,235p'
printf '%s\n' '--- alias/disjoint checks in relevant source ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'Disjoint' -e 'overlap' -e 'descriptor_index =' src/graphics/shader/recompiler src/graphics/host_gpu/renderer | head -220

Repository: KytyPS5/KytyPS5

Length of output: 22888


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- specialization read capture ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'class SrtReadCapture' -e 'struct SrtReadCapture' -e 'SrtReadCapture' -e 'specialization_reads' src/graphics/shader/recompiler src/graphics/host_gpu/renderer | head -240
printf '%s\n' '--- SRT walker buffer evaluation ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'LoadBufferU32' -e 'EvaluateDescriptor' -e 'ReadConstBuffer' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp src/graphics/shader/recompiler/ir/passes/SrtWalker.h src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6254


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- SrtReadCapture implementation ---'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.h | sed -n '1,55p'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '1,110p'
printf '%s\n' '--- SrtWalker load and read logic ---'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '300,340p'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '660,715p'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '775,810p'
printf '%s\n' '--- descriptor evaluation entry ---'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '1135,1175p'

Repository: KytyPS5/KytyPS5

Length of output: 14875


Account for writable buffer aliases across resource indices.

reads_written_buffer checks only the loaded resource’s written flag. Distinct buffer resources can receive separate descriptors that resolve to overlapping ranges. In that case, the direct predicate path can capture the buffer read, and the renderer can abort when it detects overlap with a written buffer range. Treat buffer-derived predicates as unknown whenever a writable buffer exists unless disjointness is established. Add a test with two resource indices whose descriptors overlap.

🐛 Suggested fix
+	const bool any_written_buffer =
+	    std::ranges::any_of(program.info.buffers, [](const auto& buffer) {
+		    return buffer.written;
+	    });
 	const auto reads_written_buffer = [&](Value value) {
...
 				if (memory.kind == ResourceKind::Buffer &&
 				    memory.resource < program.info.buffers.size() &&
-				    program.info.buffers[memory.resource].written)
+				    (program.info.buffers[memory.resource].written || any_written_buffer))
 					return true;
**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305691664) · edited 2026-10-18 04:36 UTC **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- diff ---' git diff --unified=35 763d3be3a9bc4e5a068d7cf52015030d6c03308f 5ee503269a37a2b92ba9b354d58d2917b905e511 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- target and related symbols ---' rg -n -F --glob '*.{cpp,h,hpp,c,cc}' -e 'program.info.buffers' -e 'ResourceKind::Buffer' -e 'TestBranchOnWrittenBufferNotCaptured' -e 'written' src tests 2>/dev/null || true printf '%s\n' '--- target source ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1300,1425p' printf '%s\n' '--- test files ---' rg -n -F --glob '*.{cpp,h,hpp}' -- 'TestBranchOnWrittenBufferNotCaptured' . || true ``` Repository: KytyPS5/KytyPS5 Length of output: 41530 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- added test ---' nl -ba tests/ResourceMaterializationTests.cpp | sed -n '990,1105p' printf '%s\n' '--- buffer metadata and resource assignment ---' rg -n -F --glob '*.{h,hpp,cpp}' -e 'struct BufferInfo' -e 'class BufferInfo' -e 'descriptor_index' -e 'descriptor.Base48' -e 'resources.buffers' src/graphics | head -220 printf '%s\n' '--- materialization dispatch buffer mapping ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1535,1610p' printf '%s\n' '--- renderer buffer setup and overlap checks ---' nl -ba src/graphics/host_gpu/renderer/renderCompute.cpp | sed -n '40,95p' nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '710,775p' nl -ba src/graphics/host_gpu/renderer/pipeline/descriptors.cpp | sed -n '900,970p' ``` Repository: KytyPS5/KytyPS5 Length of output: 28392 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- metadata declarations ---' nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '100,175p' printf '%s\n' '--- control-read flow ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1440,1538p' printf '%s\n' '--- buffer resource tracking and descriptor slots ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '3680,3760p' nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp | sed -n '195,235p' printf '%s\n' '--- alias/disjoint checks in relevant source ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'Disjoint' -e 'overlap' -e 'descriptor_index =' src/graphics/shader/recompiler src/graphics/host_gpu/renderer | head -220 ``` Repository: KytyPS5/KytyPS5 Length of output: 22888 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- specialization read capture ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'class SrtReadCapture' -e 'struct SrtReadCapture' -e 'SrtReadCapture' -e 'specialization_reads' src/graphics/shader/recompiler src/graphics/host_gpu/renderer | head -240 printf '%s\n' '--- SRT walker buffer evaluation ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'LoadBufferU32' -e 'EvaluateDescriptor' -e 'ReadConstBuffer' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp src/graphics/shader/recompiler/ir/passes/SrtWalker.h src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6254 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- SrtReadCapture implementation ---' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.h | sed -n '1,55p' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '1,110p' printf '%s\n' '--- SrtWalker load and read logic ---' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '300,340p' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '660,715p' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '775,810p' printf '%s\n' '--- descriptor evaluation entry ---' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '1135,1175p' ``` Repository: KytyPS5/KytyPS5 Length of output: 14875 --- </details> **Account for writable buffer aliases across resource indices.** `reads_written_buffer` checks only the loaded resource’s `written` flag. Distinct buffer resources can receive separate descriptors that resolve to overlapping ranges. In that case, the direct predicate path can capture the buffer read, and the renderer can abort when it detects overlap with a written buffer range. Treat buffer-derived predicates as unknown whenever a writable buffer exists unless disjointness is established. Add a test with two resource indices whose descriptors overlap. <details> <summary>🐛 Suggested fix</summary> ```diff + const bool any_written_buffer = + std::ranges::any_of(program.info.buffers, [](const auto& buffer) { + return buffer.written; + }); const auto reads_written_buffer = [&](Value value) { ... if (memory.kind == ResourceKind::Buffer && memory.resource < program.info.buffers.size() && - program.info.buffers[memory.resource].written) + (program.info.buffers[memory.resource].written || any_written_buffer)) return true; ``` </details> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f4aea9a675865065d11b9341 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:16 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3931fd86-4043-48bc-a3b6-e9b23eceb1ac
📥 Commits

Reviewing files that changed from the base of the PR and between 37df7f3278 and 5ee503269a.

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

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#pullrequestreview-5561400533) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3931fd86-4043-48bc-a3b6-e9b23eceb1ac` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 37df7f3278a41dde020a10daa74d8ae152ee8fb8 and 5ee503269a37a2b92ba9b354d58d2917b905e511. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `tests/ResourceMaterializationTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=0b5c07c8-fd7b-46ef-bf02-d2914001bbba attempt=3a1d90dd-3a10-4b37-a339-8b325d946db3 batch=1/1 -->
@ -1492,0 +1505,4 @@
return true;
}
for (size_t index = 0; index < inst->NumArgs(); ++index)
pending.push_back(inst->Arg(index));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:16 UTC · original · edited 2026-10-18 04:36 UTC

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --unified=80 763d3be3a9bc4e5a068d7cf52015030d6c03308f 5ee503269a37a2b92ba9b354d58d2917b905e511 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- relevant symbols ---'
rg -n -F --glob '*.cpp' --glob '*.h' -e 'srt_reads' -e 'ReadConst' -e 'LoadBufferU32' -e 'TestBranchOnWrittenBufferNotCaptured' src/graphics/shader/recompiler
printf '%s\n' '--- target context ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1280,1450p'

Repository: KytyPS5/KytyPS5

Length of output: 33971


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- Clone and ReadConst context ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1040,1110p;1240,1315p'
printf '%s\n' '--- SRT alias construction ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '840,955p'
printf '%s\n' '--- ReadConst validation and flattening ---'
nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '210,260p;370,410p'
printf '%s\n' '--- tests and call sites ---'
rg -n -F --glob '*' -e 'TestBranchOnWrittenBufferNotCaptured' -e 'ReadConst' -e 'srt_reads' tests src | sed -n '1,240p'

Repository: KytyPS5/KytyPS5

Length of output: 38100


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- scalar-read dependency traversal ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '730,855p'
printf '%s\n' '--- SRT alias materialization tests ---'
nl -ba tests/ResourceMaterializationTests.cpp | sed -n '740,835p'
printf '%s\n' '--- written-buffer regression test ---'
nl -ba tests/ResourceMaterializationTests.cpp | sed -n '990,1065p;1420,1460p'

Repository: KytyPS5/KytyPS5

Length of output: 18859


Follow flattened SRT aliases when scanning predicate dependencies.

reads_written_buffer follows direct instruction arguments but does not resolve ReadConst through program.srt_reads. If the aliased value depends on a LoadBufferU32 from a written buffer, the scan misses the dependency. Clone then expands the same alias, so the predicate can still take the integer-runtime-value path and capture the read.

Resolve ReadConst slots during this scan, with cycle protection consistent with the existing traversal. Add a regression test for this flattened-alias path.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305691665) · edited 2026-10-18 04:36 UTC **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- diff ---' git diff --unified=80 763d3be3a9bc4e5a068d7cf52015030d6c03308f 5ee503269a37a2b92ba9b354d58d2917b905e511 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- relevant symbols ---' rg -n -F --glob '*.cpp' --glob '*.h' -e 'srt_reads' -e 'ReadConst' -e 'LoadBufferU32' -e 'TestBranchOnWrittenBufferNotCaptured' src/graphics/shader/recompiler printf '%s\n' '--- target context ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1280,1450p' ``` Repository: KytyPS5/KytyPS5 Length of output: 33971 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- Clone and ReadConst context ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1040,1110p;1240,1315p' printf '%s\n' '--- SRT alias construction ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '840,955p' printf '%s\n' '--- ReadConst validation and flattening ---' nl -ba src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '210,260p;370,410p' printf '%s\n' '--- tests and call sites ---' rg -n -F --glob '*' -e 'TestBranchOnWrittenBufferNotCaptured' -e 'ReadConst' -e 'srt_reads' tests src | sed -n '1,240p' ``` Repository: KytyPS5/KytyPS5 Length of output: 38100 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- scalar-read dependency traversal ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp | sed -n '730,855p' printf '%s\n' '--- SRT alias materialization tests ---' nl -ba tests/ResourceMaterializationTests.cpp | sed -n '740,835p' printf '%s\n' '--- written-buffer regression test ---' nl -ba tests/ResourceMaterializationTests.cpp | sed -n '990,1065p;1420,1460p' ``` Repository: KytyPS5/KytyPS5 Length of output: 18859 --- </details> **Follow flattened SRT aliases when scanning predicate dependencies.** `reads_written_buffer` follows direct instruction arguments but does not resolve `ReadConst` through `program.srt_reads`. If the aliased value depends on a `LoadBufferU32` from a written buffer, the scan misses the dependency. `Clone` then expands the same alias, so the predicate can still take the integer-runtime-value path and capture the read. Resolve `ReadConst` slots during this scan, with cycle protection consistent with the existing traversal. Add a regression test for this flattened-alias path. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:620e393e3483a00fb84d0702 --> <!-- This is an auto-generated reply by CodeRabbit -->
@ -1492,0 +1501,4 @@
const auto& memory = program.memory_info.at(inst->Flags<MemoryFlags>().index);
if (memory.kind == ResourceKind::Buffer &&
memory.resource < program.info.buffers.size() &&
program.info.buffers[memory.resource].written)
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 04:36 UTC · original

Overlapping descriptors are a separate case, and they still fail loudly. If another buffer resource overlaps the one the count is read from, the read is still captured, and CommitBindings compares every captured read with the address range of every written buffer binding in all stages (descriptors.cpp, the check that prints this error), so it stops with the same error as on main today rather than using a stale value. Which descriptors overlap is only known at draw time, not when ExtractResourcePlan builds the plan. Making every branch on a buffer load unknown as soon as the shader writes any buffer would also give up those branches in shaders whose buffers can't overlap. This PR covers the case the game hits: the shader reads and writes the same buffer resource.

Written with Claude Code (AI): it checked the code paths; I read this reply before posting it.

**@⁠Nawid3333** on GitHub · 2026-10-18 04:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305738010) Overlapping descriptors are a separate case, and they still fail loudly. If another buffer resource overlaps the one the count is read from, the read is still captured, and CommitBindings compares every captured read with the address range of every written buffer binding in all stages (descriptors.cpp, the check that prints this error), so it stops with the same error as on main today rather than using a stale value. Which descriptors overlap is only known at draw time, not when `ExtractResourcePlan` builds the plan. Making every branch on a buffer load unknown as soon as the shader writes any buffer would also give up those branches in shaders whose buffers can't overlap. This PR covers the case the game hits: the shader reads and writes the same buffer resource. Written with Claude Code (AI): it checked the code paths; I read this reply before posting it.
@ -1492,0 +1505,4 @@
return true;
}
for (size_t index = 0; index < inst->NumArgs(); ++index)
pending.push_back(inst->Arg(index));
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 04:36 UTC · original

Following the ReadConst alias here wouldn't change the result. When the SRT is materialized, every slot of a reachable block is read (SrtWalker::RefreshFlatBuffer), whether or not a branch uses it, so if the slot's address depends on a load from a buffer the shader writes, that read is captured anyway and CommitBindings stops on it, as on main. I checked this with a version of the new test where the branch doesn't use the slot at all: the read inside the written buffer is still captured. Making the scan follow the alias (as Clone does) gave the same result, so I left it out. That case is outside this PR.

Written with Claude Code (AI): it wrote and ran the check; I read this reply before posting it.

**@⁠Nawid3333** on GitHub · 2026-10-18 04:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305738059) Following the `ReadConst` alias here wouldn't change the result. When the SRT is materialized, every slot of a reachable block is read (`SrtWalker::RefreshFlatBuffer`), whether or not a branch uses it, so if the slot's address depends on a load from a buffer the shader writes, that read is captured anyway and CommitBindings stops on it, as on main. I checked this with a version of the new test where the branch doesn't use the slot at all: the read inside the written buffer is still captured. Making the scan follow the alias (as `Clone` does) gave the same result, so I left it out. That case is outside this PR. Written with Claude Code (AI): it wrote and ran the check; I read this reply before posting it.
@ -1492,0 +1505,4 @@
return true;
}
for (size_t index = 0; index < inst->NumArgs(); ++index)
pending.push_back(inst->Arg(index));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:36 UTC · original

@⁠Nawid3333 Thanks for the clarification. I withdraw this finding.

ExtractResourcePlan already clones every program.srt_reads value. As you explained, SrtWalker::RefreshFlatBuffer evaluates every slot in a reachable block, even when the branch does not use that slot. Following the ReadConst alias in this scan therefore would not prevent the captured read or the later CommitBindings rejection. My comment incorrectly treated that existing limitation as a defect introduced by this PR.

Would you like a follow-up issue for the existing flattened-SRT limitation?


✏️ Learnings added
Learnt from: Nawid3333
Repo: KytyPS5/KytyPS5 PR: 1630
File: src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:1379-1380
Timestamp: 2026-10-18T04:36:35.179Z
Learning: In KytyPS5's C++ shader resource materialization, ExtractResourcePlan in src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp clones every program.srt_reads value. SrtWalker::RefreshFlatBuffer evaluates every SRT slot in a reachable block, independently of whether a branch uses the slot. If a slot's address depends on LoadBufferU32 from a shader-written buffer, that read is captured independently of predicate projection and CommitBindings rejects the overlap. Following ReadConst aliases only in the written-buffer predicate scan does not eliminate this capture.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305739118) @⁠Nawid3333 Thanks for the clarification. I withdraw this finding. `ExtractResourcePlan` already clones every `program.srt_reads` value. As you explained, `SrtWalker::RefreshFlatBuffer` evaluates every slot in a reachable block, even when the branch does not use that slot. Following the `ReadConst` alias in this scan therefore would not prevent the captured read or the later `CommitBindings` rejection. My comment incorrectly treated that existing limitation as a defect introduced by this PR. Would you like a follow-up issue for the existing flattened-SRT limitation? --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: Nawid3333 Repo: KytyPS5/KytyPS5 PR: 1630 File: src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:1379-1380 Timestamp: 2026-10-18T04:36:35.179Z Learning: In KytyPS5's C++ shader resource materialization, ExtractResourcePlan in src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp clones every program.srt_reads value. SrtWalker::RefreshFlatBuffer evaluates every SRT slot in a reachable block, independently of whether a branch uses the slot. If a slot's address depends on LoadBufferU32 from a shader-written buffer, that read is captured independently of predicate projection and CommitBindings rejects the overlap. Following ReadConst aliases only in the written-buffer predicate scan does not eliminate this capture. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -1492,0 +1501,4 @@
const auto& memory = program.memory_info.at(inst->Flags<MemoryFlags>().index);
if (memory.kind == ResourceKind::Buffer &&
memory.resource < program.info.buffers.size() &&
program.info.buffers[memory.resource].written)
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-18 04:36 UTC · original

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
ast-grep outline src/graphics/host_gpu/renderer/pipeline/descriptors.cpp --match 'CommitBindings' --view expanded
rg -n -C12 'scalar resource reads overlap|specialization_reads|CommitBindings\s*\(' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp

Length of output: 5816


@Nawid3333 Thanks for clarifying. I checked CommitBindings in descriptors.cpp. It compares captured specialization reads against written buffer ranges across all prepared stages and aborts on overlap.

My finding treated that existing rejection as a regression introduced by this PR. That was incorrect. The broader guard I suggested would also disable predicate projection for disjoint buffers.

I withdraw the finding. Cross-resource aliases do not require a change in this PR, which targets reads and writes through the same buffer resource.


✏️ Learnings added
Learnt from: Nawid3333
Repo: KytyPS5/KytyPS5 PR: 1630
File: src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:1374-1376
Timestamp: 2026-10-18T04:36:47.269Z
Learning: In KytyPS5, RenderExecutor::CommitBindings in src/graphics/host_gpu/renderer/pipeline/descriptors.cpp checks captured specialization reads against written buffer binding ranges across all prepared stages and aborts on overlap. Distinct resource indices do not establish disjointness; descriptor overlap is determined at draw or dispatch time. When reviewing ExtractResourcePlan in src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp, do not require all buffer-derived predicates to become unknown merely because any buffer is written: cross-resource overlap already has runtime rejection, while disjoint buffers can retain predicate projection.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-18 04:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#discussion_r4305739537) <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash ast-grep outline src/graphics/host_gpu/renderer/pipeline/descriptors.cpp --match 'CommitBindings' --view expanded rg -n -C12 'scalar resource reads overlap|specialization_reads|CommitBindings\s*\(' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp ``` Length of output: 5816 --- </details> `@Nawid3333` Thanks for clarifying. I checked `CommitBindings` in `descriptors.cpp`. It compares captured specialization reads against written buffer ranges across all prepared stages and aborts on overlap. My finding treated that existing rejection as a regression introduced by this PR. That was incorrect. The broader guard I suggested would also disable predicate projection for disjoint buffers. I withdraw the finding. Cross-resource aliases do not require a change in this PR, which targets reads and writes through the same buffer resource. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: Nawid3333 Repo: KytyPS5/KytyPS5 PR: 1630 File: src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:1374-1376 Timestamp: 2026-10-18T04:36:47.269Z Learning: In KytyPS5, RenderExecutor::CommitBindings in src/graphics/host_gpu/renderer/pipeline/descriptors.cpp checks captured specialization reads against written buffer binding ranges across all prepared stages and aborts on overlap. Distinct resource indices do not establish disjointness; descriptor overlap is determined at draw or dispatch time. When reviewing ExtractResourcePlan in src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp, do not require all buffer-derived predicates to become unknown merely because any buffer is written: cross-resource overlap already has runtime rejection, while disjoint buffers can retain predicate projection. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 21:02 UTC · original

Tested with the game on AMD hardware: volan3 ran Demon's Souls (PPSA01341, 01.007.000) on an RX 6700 XT (Ryzen 7 5700X, Windows) with two builds from my fork's CI. Both are 099de8d plus #1152, which removes an unrelated AMD driver crash on RDNA2 (#821):

  • 099de8d + #1152 (a59509e): stops with scalar resource reads overlap a shader buffer write (descriptors.cpp:955) right after Shaders: VS 2 | PS 5 | CS 111, the same point as the 099de8d log in #1660 (RTX 4070 SUPER). Log
  • the same plus this PR (f3996a4): no such error. The game shows its language selection at 35 fps (log and screenshot), and in a second run it gets through the intro into gameplay (VS 51 | PS 98 | CS 234) before a separate crash in the game's own code (a null pointer in a CPU function, not in the renderer; log).

Both builds pass the CI build and tests on Windows, Linux and macOS.

Written with Claude Code (AI): it prepared the two test builds and compared the logs; I read this before posting.

**@⁠Nawid3333** on GitHub · 2026-10-18 21:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#issuecomment-6255102896) Tested with the game on AMD hardware: volan3 ran Demon's Souls (PPSA01341, 01.007.000) on an RX 6700 XT (Ryzen 7 5700X, Windows) with two builds from my fork's CI. Both are 099de8d plus #1152, which removes an unrelated AMD driver crash on RDNA2 (#821): - 099de8d + #1152 ([a59509e](https://github.com/Nawid3333/KytyPS5/actions/runs/39159720793)): stops with `scalar resource reads overlap a shader buffer write` (descriptors.cpp:955) right after `Shaders: VS 2 | PS 5 | CS 111`, the same point as the 099de8d log in #1660 (RTX 4070 SUPER). [Log](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/821) - the same plus this PR ([f3996a4](https://github.com/Nawid3333/KytyPS5/actions/runs/39159723040)): no such error. The game shows its language selection at 35 fps ([log and screenshot](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/821)), and in a second run it gets through the intro into gameplay (`VS 51 | PS 98 | CS 234`) before a separate crash in the game's own code (a null pointer in a CPU function, not in the renderer; [log](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/821)). Both builds pass the CI build and tests on Windows, Linux and macOS. Written with Claude Code (AI): it prepared the two test builds and compared the logs; I read this before posting.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-21 21:33 UTC · original

Retested in the game on today's main (28648188, which includes 68d0ba5a): Demon's Souls (PPSA01341), RX 9070 XT, Windows, the same input script in every run.

  • main: stops after about 4 minutes with scalar resource reads overlap a shader buffer write (descriptors.cpp:950), right after compute shader 0x02632cb15eb8128d, at Shaders: VS 2 | PS 5 | CS 111 (the point reported in #1660).
  • main + this PR: no error in 11 minutes; the game reaches character creation at minute 8 (VS 25 | PS 55 | CS 152 at the end).
  • main + #1747: also no error in 11 minutes; same point, character creation at minute 8 (VS 23 | PS 47 | CS 160).

So on current main, either PR gets Demon's Souls past this stop.

**@⁠Nawid3333** on GitHub · 2026-10-21 21:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#issuecomment-6327049811) Retested in the game on today's main (28648188, which includes 68d0ba5a): Demon's Souls (PPSA01341), RX 9070 XT, Windows, the same input script in every run. - main: stops after about 4 minutes with `scalar resource reads overlap a shader buffer write` (descriptors.cpp:950), right after compute shader 0x02632cb15eb8128d, at `Shaders: VS 2 | PS 5 | CS 111` (the point reported in #1660). - main + this PR: no error in 11 minutes; the game reaches character creation at minute 8 (`VS 25 | PS 55 | CS 152` at the end). - main + #1747: also no error in 11 minutes; same point, character creation at minute 8 (`VS 23 | PS 47 | CS 160`). So on current main, either PR gets Demon's Souls past this stop.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-23 18:38 UTC · original

Tested in the game on NVIDIA too: alxtorrentazos ran Demon's Souls on an RTX 3080 (Ryzen 5900X, Windows) in #1746.

  • Official build 9dcff95: stops at VS 2 | PS 5 | CS 111 with scalar resource reads overlap a shader buffer write (#1746).
  • 9dcff95 plus this PR (fork build 3f05536): gets past that point and through the character creation, up to CS 233 (#1746). The crash there, in the fog after the intro, looks like the one volan3 had in #821 at the same point, which went away with "Windows SysV red zone crash protection" checked.
  • Asked to check that setting too, alxtorrentazos reports that the game now runs and is playable (#1746).
**@⁠Nawid3333** on GitHub · 2026-10-23 18:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#issuecomment-6372136032) Tested in the game on NVIDIA too: alxtorrentazos ran Demon's Souls on an RTX 3080 (Ryzen 5900X, Windows) in #1746. - Official build 9dcff95: stops at `VS 2 | PS 5 | CS 111` with `scalar resource reads overlap a shader buffer write` (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1746). - 9dcff95 plus this PR (fork build `3f05536`): gets past that point and through the character creation, up to `CS 233` (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1746). The crash there, in the fog after the intro, looks like the one volan3 had in #821 at the same point, which went away with "Windows SysV red zone crash protection" checked. - Asked to check that setting too, alxtorrentazos reports that the game now runs and is playable (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1746).
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 00:59 UTC · original · reviewed

Nitpick comments: 1
tests/ResourceMaterializationTests.cpp: 1

977-1052: Trivial · Functional Correctness · Quick win

Add a resource that is exclusive to the false branch.

The false branch is empty, so a one-sided projection can drop that branch without changing the current assertions. Add a second descriptor-backed buffer and access it only from program.blocks[2]. Assert that its descriptor is materialized when written is true, while retaining the existing true-branch access. This checks both branch sides without asserting a production failure.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5ee503269a and 9e7bb9d71f.

Files selected for processing: 2
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • tests/ResourceMaterializationTests.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-10-30 00:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#pullrequestreview-5706885958) · **reviewed** <!-- coderabbit-ai-generated:v1 --> <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> <details> <summary>tests/ResourceMaterializationTests.cpp: 1</summary><blockquote> <dl> <dd> `977-1052`: **<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** · **Functional Correctness** · **Quick win** **Add a resource that is exclusive to the false branch.** The false branch is empty, so a one-sided projection can drop that branch without changing the current assertions. Add a second descriptor-backed buffer and access it only from `program.blocks[2]`. Assert that its descriptor is materialized when `written` is true, while retaining the existing true-branch access. This checks both branch sides without asserting a production failure. <!-- cr-comment:v1:756322f9e4f6dd8ef556569d --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <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> - **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/3ad21e35cc739304812cbb0f741025a87d882e25/.coderabbit.yaml>) - **Commit**: [3ad21e3](<https://github.com/KytyPS5/KytyPS5/commit/3ad21e35cc739304812cbb0f741025a87d882e25>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3a9cc4e3-3277-4ecc-a6ac-6d6e0fd59c70` </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> Reviewing files that changed from the base of the PR and between 5ee503269a37a2b92ba9b354d58d2917b905e511 and 9e7bb9d71fff802268bcee4fb8702e99f66c9323. </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: 2</summary> <dl> <dd> * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `tests/ResourceMaterializationTests.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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=e2ae8136-22c1-4497-a835-8d99ad644f5b attempt=5a5074ad-dba2-428b-9908-183fe27b8ca0 batch=1/1 -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-30 19:38 UTC · original

Closing this: since eb3cb472 ("renderer: drop the per-draw scalar-read overlap guard") main no longer stops at "scalar resource reads overlap a shader buffer write" in CommitBindings, which is the stop this PR got Demon's Souls and Code Violet past. Demon's Souls now reaches gameplay on 4919fdb (#1660).

Branches on buffers the shader writes can still be specialized on main. If a game shows wrong rendering from that, I can reopen this with the case.

**@⁠Nawid3333** on GitHub · 2026-10-30 19:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1630#issuecomment-6531921268) Closing this: since eb3cb472 ("renderer: drop the per-draw scalar-read overlap guard") main no longer stops at "scalar resource reads overlap a shader buffer write" in `CommitBindings`, which is the stop this PR got Demon's Souls and Code Violet past. Demon's Souls now reaches gameplay on 4919fdb (#1660). Branches on buffers the shader writes can still be specialized on main. If a game shows wrong rendering from that, I can reopen this with the case.

Pull request closed

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