shader: issue BDA loads without a branch per access #1296

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

@⁠NeySlim on GitHub · 2026-10-09 10:52 UTC · original
NeySlim:perf/bda-branchless → main · +792 −108 · 12 files · 7 commits · closed without merging

Depends on #1294 (fault buffer summary): the deferred fault records use its RecordBdaFault.

Problem

Shaders that read guest memory through BDA (FLAT and GLOBAL loads, scalar loads from a computed address, buffer loads whose descriptor is read at run time) translate every dword through the page table. The emitted code branches on the page-table entry before the data load: a missing page skips the load and records a fault. The branch needs the entry, so each dword waits for its lookup, and the next load cannot issue before that. A shader that reads 100 dwords waits for 100 page-table lookups in sequence.

In God of War Ragnarök (PPSA08332) most of the expensive compute passes read their descriptors and data this way. In the compiled code of four of the hottest ones, each has 1072 to 1268 branches and 815 to 879 s_waitcnt, mostly from these lookups.

Change

  • Outside the conditional constructs the emitter creates, a load reads its page-table entry and selects the page base without a branch. A missing page reads a zeroed page whose address is stored after the last page-table entry, so the load still returns zero. Addresses outside the cached range also read the zero page instead of indexing past the table.
  • The fault is checked later: each load keeps its missing page (or none) in a register, and one branch per block, or per eight loads, records the faults of all of them. The bound keeps the extra live registers small.
  • FLAT and GLOBAL loads, and buffer loads through run-time descriptors, fold EXEC and their bounds into that guard instead of branching around the load. Inactive lanes and out-of-bounds dwords run the lookup but never record a fault and read zero.
  • Loads still emitted inside a conditional construct (the dword after an unaligned FLAT address, formatted loads through run-time descriptors) keep the checked lookup.
  • The buffer cache creates the zero page and publishes its address before the first BDA access. A page without a buffer must have a zero entry to read it: #1294 now clears the page table when it is created.

For addresses inside the cached range, the values read and the pages reported are unchanged.

Test

  • BdaLoadsLookUpPagesWithoutBranches: s_load_dwordx4 from a computed address and a FLAT load from an unmapped page. The values and the fault are checked, and the SPIR-V keeps one checked lookup (the unaligned FLAT path) instead of six.
  • IndirectBufferLoadsLookUpPagesWithoutBranches: the existing run-time descriptor case (11 descriptors, in and out of bounds, unbound) with no checked lookup left.
  • FlatLoadOfInactiveLaneRecordsNoFault: a FLAT load from an unmapped page by a lane disabled in EXEC keeps the old value and records no fault (new harness field fault_free_pages).
  • The first two fail without the change; the third fails if the guard is left out of the fault check.
  • The harness maps the zero page like the buffer cache.

Validation

  • Linux, Radeon 8060S (RADV, Mesa 26.2.3).
  • shader_recompiler_compute_tests, one case per process (with the fault buffer summary change): identical results to origin/main apart from the new passing cases. The 10 cases that already fail on origin/main with this driver fail the same way.
  • In game, one session alternating the old and new code every 5 s (opening cutscene and first gameplay), paired periods: GPU busy time per frame -1.6 ms (± 0.35) in the cutscene and -1.7 ms (± 0.33) in gameplay, about -4 %. The same four shaders drop to 508 to 602 branches and 687 to 752 s_waitcnt. Screenshots are unchanged.
  • Not tested on Windows. The change is in the SPIR-V emitter and the buffer cache, with no platform-specific code.

AI use

I used Claude Code (AI agent) to profile the GPU time and the compiled code of the hottest shaders, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-09 10:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296) `NeySlim:perf/bda-branchless` → `main` · +792 −108 · 12 files · 7 commits · closed without merging Depends on #1294 (fault buffer summary): the deferred fault records use its `RecordBdaFault`. ## Problem Shaders that read guest memory through BDA (FLAT and GLOBAL loads, scalar loads from a computed address, buffer loads whose descriptor is read at run time) translate every dword through the page table. The emitted code branches on the page-table entry before the data load: a missing page skips the load and records a fault. The branch needs the entry, so each dword waits for its lookup, and the next load cannot issue before that. A shader that reads 100 dwords waits for 100 page-table lookups in sequence. In God of War Ragnarök (PPSA08332) most of the expensive compute passes read their descriptors and data this way. In the compiled code of four of the hottest ones, each has 1072 to 1268 branches and 815 to 879 `s_waitcnt`, mostly from these lookups. ## Change - Outside the conditional constructs the emitter creates, a load reads its page-table entry and selects the page base without a branch. A missing page reads a zeroed page whose address is stored after the last page-table entry, so the load still returns zero. Addresses outside the cached range also read the zero page instead of indexing past the table. - The fault is checked later: each load keeps its missing page (or none) in a register, and one branch per block, or per eight loads, records the faults of all of them. The bound keeps the extra live registers small. - FLAT and GLOBAL loads, and buffer loads through run-time descriptors, fold EXEC and their bounds into that guard instead of branching around the load. Inactive lanes and out-of-bounds dwords run the lookup but never record a fault and read zero. - Loads still emitted inside a conditional construct (the dword after an unaligned FLAT address, formatted loads through run-time descriptors) keep the checked lookup. - The buffer cache creates the zero page and publishes its address before the first BDA access. A page without a buffer must have a zero entry to read it: #1294 now clears the page table when it is created. For addresses inside the cached range, the values read and the pages reported are unchanged. ## Test - `BdaLoadsLookUpPagesWithoutBranches`: `s_load_dwordx4` from a computed address and a FLAT load from an unmapped page. The values and the fault are checked, and the SPIR-V keeps one checked lookup (the unaligned FLAT path) instead of six. - `IndirectBufferLoadsLookUpPagesWithoutBranches`: the existing run-time descriptor case (11 descriptors, in and out of bounds, unbound) with no checked lookup left. - `FlatLoadOfInactiveLaneRecordsNoFault`: a FLAT load from an unmapped page by a lane disabled in EXEC keeps the old value and records no fault (new harness field `fault_free_pages`). - The first two fail without the change; the third fails if the guard is left out of the fault check. - The harness maps the zero page like the buffer cache. ## Validation - Linux, Radeon 8060S (RADV, Mesa 26.2.3). - `shader_recompiler_compute_tests`, one case per process (with the fault buffer summary change): identical results to origin/main apart from the new passing cases. The 10 cases that already fail on origin/main with this driver fail the same way. - In game, one session alternating the old and new code every 5 s (opening cutscene and first gameplay), paired periods: GPU busy time per frame -1.6 ms (± 0.35) in the cutscene and -1.7 ms (± 0.33) in gameplay, about -4 %. The same four shaders drop to 508 to 602 branches and 687 to 752 `s_waitcnt`. Screenshots are unchanged. - Not tested on Windows. The change is in the SPIR-V emitter and the buffer cache, with no platform-specific code. ## AI use I used Claude Code (AI agent) to profile the GPU time and the compiled code of the hottest shaders, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:52:00 +00:00
github-bot closed this pull request 2026-11-26 09:52:00 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · edited 2026-10-13 23:06 UTC

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 39355fe3-44f9-4386-b5ff-8c93cf155921
📥 Commits

Reviewing files that changed from the base of the PR and between 09d6a7e95da3cbb2509d35c90058dba10695fb55 and 4c365e380b.

📒 Files selected for processing: 12
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.h
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/shaders/fault_buffer_process.comp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.cpp

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9672798b-5484-4ba3-98f1-f14d0400b63d
📥 Commits

Reviewing files that changed from the base of the PR and between 5242e8c9e2a3eedeb70e8f7ee3fbbd5ddab9f09a and 09d6a7e95da3cbb2509d35c90058dba10695fb55.

📒 Files selected for processing: 5
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.cpp

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

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to 09d6a

The previously identified GPU test setup issues are addressed, and the inspected BDA and fault-processing paths show no remaining merge-blocking issue.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 22.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 9 files. (2 skipped: … 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: removing per-access branching from BDA loads.
Description check Passed The description is directly related to the changeset. It explains the BDA load optimization, deferred fault handling, zero-page support, tests, and validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

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

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

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

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#issuecomment-6079523375) · edited 2026-10-13 23:06 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1296?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 --> <!-- This is an auto-generated comment: rate limited by coderabbit.ai --> > [!WARNING] > ## Review limit reached > > You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. > > **Next included review available in 16 minutes.** > > [Check out review usage here](https://app.coderabbit.ai/dashboard/review-capacity?orgId=d7cf2749-f181-4119-ba0c-ad79606afdfe). > > <details> > <summary><strong>View limit details</strong></summary> > <dl> > <dd> > > **Limit details:** You’ve used all 8 included reviews currently available. > > [Learn how review limits work](https://docs.coderabbit.ai/management/plans#rate-limits). > > **Review configuration:** > > <details> > <summary><strong>⚙️ Run configuration</strong></summary> > <dl> > <dd> > > - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml > - **Review profile**: CHILL > - **Plan**: Advanced > - **Run ID**: `39355fe3-44f9-4386-b5ff-8c93cf155921` > > </dd> > </dl> > </details> > > <details> > <summary><strong>📥 Commits</strong></summary> > <dl> > <dd> > > Reviewing files that changed from the base of the PR and between 09d6a7e95da3cbb2509d35c90058dba10695fb55 and 4c365e380bf97d157d6d155c568a804530169bc4. > > </dd> > </dl> > </details> > > <details> > <summary><strong>📒 Files selected for processing: 12</strong></summary> > <dl> > <dd> > > * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` > * `src/graphics/host_gpu/renderer/cache/bufferCache.h` > * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` > * `src/graphics/host_gpu/renderer/cache/streamBuffer.cpp` > * `src/graphics/host_gpu/renderer/cache/streamBuffer.h` > * `src/graphics/host_gpu/renderer/renderContext.cpp` > * `src/graphics/host_gpu/shaders/fault_buffer_process.comp` > * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` > * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp` > * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` > * `tests/ShaderRecompilerComputeTests.cpp` > * `tests/shaderCfgTests.cpp` > > </dd> > </dl> > </details> > > </dd> > </dl> > </details> <!-- end of auto-generated comment: rate limited by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9672798b-5484-4ba3-98f1-f14d0400b63d` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 5242e8c9e2a3eedeb70e8f7ee3fbbd5ddab9f09a and 09d6a7e95da3cbb2509d35c90058dba10695fb55. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 5</strong></summary> <dl> <dd> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp` * `tests/ShaderRecompilerComputeTests.cpp` * `tests/shaderCfgTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"09d6a7e95da3cbb2509d35c90058dba10695fb55" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>09d6a</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `09d6a` --> <!-- final_review_risk_coverage:{"sourceCommitId":"09d6a7e95da3cbb2509d35c90058dba10695fb55","coveredCommitId":"09d6a7e95da3cbb2509d35c90058dba10695fb55","kind":"reviewed"} --> The previously identified GPU test setup issues are addressed, and the inspected BDA and fault-processing paths show no remaining merge-blocking issue. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 22.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 9 files. (2 skipped: … | 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: removing per-access branching from BDA loads. | | 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 BDA load optimization, deferred fault handling, zero-page support, tests, and validation results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 22.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 9 files. (2 skipped: 2 too large.) </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1296)! 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 -->
@ -5457,0 +5644,4 @@
"test pages share fault words");
words.push_back(page >> 5);
words.push_back(summary);
scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · edited 2026-10-09 11:39 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect fault-buffer construction and initialization on the PR branch.
fd -i 'faultManager.cpp' -x rg -n -C 8 'FaultManager::FaultManager|m_fault_buffer|fillBuffer'

Repository: KytyPS5/KytyPS5

Length of output: 2804


🏁 Script executed:

set -e
printf '%s\n' '--- CheckFaultBufferSummary and nearby test setup ---'
rg -n -F -- 'CheckFaultBufferSummary' tests/ShaderRecompilerComputeTests.cpp
sed -n '5170,5285p' tests/ShaderRecompilerComputeTests.cpp
printf '%s\n' '--- FaultManager constructor and processing context ---'
sed -n '1,180p' src/emulator/playstation/graphics/gnm/FaultManager.cpp 2>/dev/null || true
rg -n -F -- 'class Buffer' src tests | head -40
rg -n -F -- 'Buffer::Buffer' src tests
rg -n -F -- 'MemoryUsage::DeviceLocal' src/emulator src/core tests | head -80

Repository: KytyPS5/KytyPS5

Length of output: 9330


🏁 Script executed:

set -e
printf '%s\n' '--- Buffer implementation ---'
sed -n '1,145p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
sed -n '1,120p' src/graphics/host_gpu/renderer/cache/streamBuffer.h
printf '%s\n' '--- FaultManager implementation ---'
sed -n '1,180p' src/graphics/host_gpu/renderer/cache/faultManager.cpp
sed -n '1,120p' src/graphics/host_gpu/renderer/cache/faultManager.h

Repository: KytyPS5/KytyPS5

Length of output: 19817


🏁 Script executed:

set -e
rg -n -F -- 'void Buffer::Fill' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
sed -n '140,220p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4618


Clear the fault buffer before writing the summary fixture.

Buffer::Buffer does not initialize device-local allocations. CheckFaultBufferSummary writes only selected words before ProcessFaultBuffer() scans the buffer. Unwritten summary words may therefore trigger unrelated bitmap scans.

Suggested fix
     auto &cache = context.GetBufferCache();
     auto &faults = *cache.GetFaultBuffer();
+    faults.Fill(0, faults.Size(), 0);
     std::vector<uint64_t> words;

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229372758) · edited 2026-10-09 11:39 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect fault-buffer construction and initialization on the PR branch. fd -i 'faultManager.cpp' -x rg -n -C 8 'FaultManager::FaultManager|m_fault_buffer|fillBuffer' ``` Repository: KytyPS5/KytyPS5 Length of output: 2804 --- 🏁 Script executed: ```bash set -e printf '%s\n' '--- CheckFaultBufferSummary and nearby test setup ---' rg -n -F -- 'CheckFaultBufferSummary' tests/ShaderRecompilerComputeTests.cpp sed -n '5170,5285p' tests/ShaderRecompilerComputeTests.cpp printf '%s\n' '--- FaultManager constructor and processing context ---' sed -n '1,180p' src/emulator/playstation/graphics/gnm/FaultManager.cpp 2>/dev/null || true rg -n -F -- 'class Buffer' src tests | head -40 rg -n -F -- 'Buffer::Buffer' src tests rg -n -F -- 'MemoryUsage::DeviceLocal' src/emulator src/core tests | head -80 ``` Repository: KytyPS5/KytyPS5 Length of output: 9330 --- 🏁 Script executed: ```bash set -e printf '%s\n' '--- Buffer implementation ---' sed -n '1,145p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp sed -n '1,120p' src/graphics/host_gpu/renderer/cache/streamBuffer.h printf '%s\n' '--- FaultManager implementation ---' sed -n '1,180p' src/graphics/host_gpu/renderer/cache/faultManager.cpp sed -n '1,120p' src/graphics/host_gpu/renderer/cache/faultManager.h ``` Repository: KytyPS5/KytyPS5 Length of output: 19817 --- 🏁 Script executed: ```bash set -e rg -n -F -- 'void Buffer::Fill' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp sed -n '140,220p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4618 --- </details> **Clear the fault buffer before writing the summary fixture.** `Buffer::Buffer` does not initialize device-local allocations. `CheckFaultBufferSummary` writes only selected words before `ProcessFaultBuffer()` scans the buffer. Unwritten summary words may therefore trigger unrelated bitmap scans. <details> <summary>Suggested fix</summary> ```diff auto &cache = context.GetBufferCache(); auto &faults = *cache.GetFaultBuffer(); + faults.Fill(0, faults.Size(), 0); std::vector<uint64_t> words; ``` </details> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:1230321fbe6cd0cea69d0ea9 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠NeySlim <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6c5da140-0e54-49a9-854d-a75ecc28d32e
📥 Commits

Reviewing files that changed from the base of the PR and between 7b9997baea and 1a0056db14f6e97a269ad02f1f65b7e405fa3e80.

📒 Files selected for processing (10)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/shaders/fault_buffer_process.comp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 10:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#pullrequestreview-5469134723) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `6c5da140-0e54-49a9-854d-a75ecc28d32e` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 and 1a0056db14f6e97a269ad02f1f65b7e405fa3e80. </details> <details> <summary>📒 Files selected for processing (10)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/shaders/fault_buffer_process.comp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp` * `tests/ShaderRecompilerComputeTests.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=10404503-c556-4a63-b17d-d0c16b48d896 attempt=1c90e00a-f26f-496a-be7e-46c15157c303 batch=1/1 -->
@ -5457,0 +5644,4 @@
"test pages share fault words");
words.push_back(page >> 5);
words.push_back(summary);
scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 11:30 UTC · original

Agreed, and the gap was in the renderer too: the production fault buffer and the BDA page table were never cleared at creation. Both are now cleared when the buffer cache creates them, in #1294 (de6966b1 for the fault buffer in FaultManager, ccfcb32a for the page table in BufferCache), each with its own submission because the command scheduler is not bound yet. FaultBufferStartsCleared and BdaPageTableStartsCleared create a renderer whose new device memory has every bit set, and fail without the clears. FaultBufferSummary also clears the buffer before writing its fixture, as suggested. This branch is rebased on top.

**@⁠NeySlim** on GitHub · 2026-10-09 11:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229625193) Agreed, and the gap was in the renderer too: the production fault buffer and the BDA page table were never cleared at creation. Both are now cleared when the buffer cache creates them, in #1294 (de6966b1 for the fault buffer in `FaultManager`, ccfcb32a for the page table in `BufferCache`), each with its own submission because the command scheduler is not bound yet. `FaultBufferStartsCleared` and `BdaPageTableStartsCleared` create a renderer whose new device memory has every bit set, and fail without the clears. `FaultBufferSummary` also clears the buffer before writing its fixture, as suggested. This branch is rebased on top.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 11:36 UTC · original · edited 2026-10-09 12:03 UTC
On tests/ShaderRecompilerComputeTests.cpp line 5261 (outdated):

@@ -5198,6 +5210,226 @@ class VulkanHarness {
     std::printf("[gpu]     %-32s ok\n", name);
   }
 
+  // Runs `body` with renderer allocations whose new device memory has every bit set: device
+  // memory contents are undefined, and memory reused from freed allocations is often nonzero.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    struct Dirtier {
+      VulkanHarness *harness;
+      const char *name;
+    } dirtier{this, name};
+    VmaDeviceMemoryCallbacks callbacks{};
+    callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory,
+                               VkDeviceSize size, void *user) {
+      const auto &self = *static_cast<const Dirtier *>(user);
+      self.harness->FillDeviceMemory(self.name, type, memory, size);
+    };
+    callbacks.pUserData = &dirtier;
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    VmaAllocatorCreateInfo allocator_info{};
+    allocator_info.instance = m_instance;
+    allocator_info.physicalDevice = m_physical_device;
+    allocator_info.device = m_device;
+    allocator_info.pVulkanFunctions = &functions;
+    allocator_info.vulkanApiVersion = VK_API_VERSION_1_3;
+    allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
+    allocator_info.pDeviceMemoryCallbacks = &callbacks;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    vmaDestroyAllocator(dirty);
+  }
+
+  void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory,
+                        vk::DeviceSize size) {
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};
+    buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst;
+    vk::Buffer buffer = nullptr;
+    RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer),
+              "vkCreateBuffer");
+    vk::MemoryRequirements requirements{};
+    m_device.getBufferMemoryRequirements(buffer, &requirements);
+    // Memory that no transfer buffer can bind holds no renderer buffer either.
+    if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) {
+      RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0),

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
git diff --unified=30 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 a67c0014f4de90e61264ec26ff563cf805725ff1 -- tests/ShaderRecompilerComputeTests.cpp
printf '%s\n' '--- symbols ---'
rg -n -F -- 'FillDeviceMemory' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'WithDirtyDeviceMemory' tests/ShaderRecompilerComputeTests.cpp
printf '%s\n' '--- relevant source ---'
sed -n '5180,5305p' tests/ShaderRecompilerComputeTests.cpp
printf '%s\n' '--- allocation declarations/usages ---'
rg -n -F -- 'VmaAllocation' tests/ShaderRecompilerComputeTests.cpp tests | head -80

Repository: KytyPS5/KytyPS5

Length of output: 42457


Do not bind the temporary buffer to dedicated memory.

If VMA returns a dedicated allocation for a renderer buffer or image, bindBufferMemory cannot bind the new temporary buffer to that allocation. The dirty-memory fixture can therefore fail during setup before it checks the cleared state.

Fill the renderer allocation through its already-bound resource, or make the fixture handle dedicated allocations explicitly.

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229665275) · edited 2026-10-09 12:03 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 5261 (outdated): ```diff @@ -5198,6 +5210,226 @@ class VulkanHarness { std::printf("[gpu] %-32s ok\n", name); } + // Runs `body` with renderer allocations whose new device memory has every bit set: device + // memory contents are undefined, and memory reused from freed allocations is often nonzero. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + struct Dirtier { + VulkanHarness *harness; + const char *name; + } dirtier{this, name}; + VmaDeviceMemoryCallbacks callbacks{}; + callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory, + VkDeviceSize size, void *user) { + const auto &self = *static_cast<const Dirtier *>(user); + self.harness->FillDeviceMemory(self.name, type, memory, size); + }; + callbacks.pUserData = &dirtier; + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + VmaAllocatorCreateInfo allocator_info{}; + allocator_info.instance = m_instance; + allocator_info.physicalDevice = m_physical_device; + allocator_info.device = m_device; + allocator_info.pVulkanFunctions = &functions; + allocator_info.vulkanApiVersion = VK_API_VERSION_1_3; + allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; + allocator_info.pDeviceMemoryCallbacks = &callbacks; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + vmaDestroyAllocator(dirty); + } + + void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory, + vk::DeviceSize size) { + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; + buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst; + vk::Buffer buffer = nullptr; + RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer), + "vkCreateBuffer"); + vk::MemoryRequirements requirements{}; + m_device.getBufferMemoryRequirements(buffer, &requirements); + // Memory that no transfer buffer can bind holds no renderer buffer either. + if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) { + RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0), ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -eu git diff --unified=30 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 a67c0014f4de90e61264ec26ff563cf805725ff1 -- tests/ShaderRecompilerComputeTests.cpp printf '%s\n' '--- symbols ---' rg -n -F -- 'FillDeviceMemory' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'WithDirtyDeviceMemory' tests/ShaderRecompilerComputeTests.cpp printf '%s\n' '--- relevant source ---' sed -n '5180,5305p' tests/ShaderRecompilerComputeTests.cpp printf '%s\n' '--- allocation declarations/usages ---' rg -n -F -- 'VmaAllocation' tests/ShaderRecompilerComputeTests.cpp tests | head -80 ``` Repository: KytyPS5/KytyPS5 Length of output: 42457 --- </details> **Do not bind the temporary buffer to dedicated memory.** If VMA returns a dedicated allocation for a renderer buffer or image, `bindBufferMemory` cannot bind the new temporary buffer to that allocation. The dirty-memory fixture can therefore fail during setup before it checks the cleared state. Fill the renderer allocation through its already-bound resource, or make the fixture handle dedicated allocations explicitly. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a956cd0fae60a08c7bc14ac5 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠NeySlim <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 11:36 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e2537fca-4631-41e1-ae58-6c3575d2937c
📥 Commits

Reviewing files that changed from the base of the PR and between 1a0056db14f6e97a269ad02f1f65b7e405fa3e80 and a67c0014f4de90e61264ec26ff563cf805725ff1.

📒 Files selected for processing (5)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.h
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#pullrequestreview-5469489548) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `e2537fca-4631-41e1-ae58-6c3575d2937c` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 1a0056db14f6e97a269ad02f1f65b7e405fa3e80 and a67c0014f4de90e61264ec26ff563cf805725ff1. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` * `src/graphics/host_gpu/renderer/cache/streamBuffer.cpp` * `src/graphics/host_gpu/renderer/cache/streamBuffer.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=542a9f72-9fff-40ec-9e9f-a9741412157e attempt=3a1c18c0-1a36-4419-a202-fc553be440ac batch=1/1 -->
@ -5457,0 +5644,4 @@
"test pages share fault words");
words.push_back(page >> 5);
words.push_back(summary);
scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 11:39 UTC · original

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match 'CheckFaultBufferSummary|FaultBufferStartsCleared|BdaPageTableStartsCleared'
ast-grep outline src/graphics/host_gpu/renderer/cache/faultManager.cpp --match FaultManager
ast-grep outline src/graphics/host_gpu/renderer/cache/bufferCache.cpp --match BufferCache
rg -n -C 12 'void CheckFaultBufferSummary\(|faults\.Fill\(|FaultBufferStartsCleared|BdaPageTableStartsCleared' tests/ShaderRecompilerComputeTests.cpp
rg -n -C 10 'm_fault_buffer.*Fill|Submit|FAULT_BUFFER_SIZE' src/graphics/host_gpu/renderer/cache/faultManager.cpp
rg -n -C 10 'm_page_table.*Fill|page_table.*Fill|Submit' src/graphics/host_gpu/renderer/cache/bufferCache.cpp

Length of output: 13430


@NeySlim Thanks for the clarification. I verified that CheckFaultBufferSummary clears the full fault buffer before writing its fixture.

Both constructors also clear their buffers with separate submissions. The dirty-memory regression tests are present; I did not run them.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1296
File: tests/ShaderRecompilerComputeTests.cpp:5356-5356
Timestamp: 2026-10-09T11:39:14.076Z
Learning: In KytyPS5's C++ renderer, FaultManager in src/graphics/host_gpu/renderer/cache/faultManager.cpp and BufferCache in src/graphics/host_gpu/renderer/cache/bufferCache.cpp initialize the fault buffer and BDA page table before guest commands bind the command scheduler. Constructor initialization therefore uses Buffer::Fill with m_scheduler.BeginCommand(), followed by a separate m_scheduler.Submit(), rather than the Fill overload that uses the scheduler's current command buffer.

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.


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

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229692115) <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash set -euo pipefail ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match 'CheckFaultBufferSummary|FaultBufferStartsCleared|BdaPageTableStartsCleared' ast-grep outline src/graphics/host_gpu/renderer/cache/faultManager.cpp --match FaultManager ast-grep outline src/graphics/host_gpu/renderer/cache/bufferCache.cpp --match BufferCache rg -n -C 12 'void CheckFaultBufferSummary\(|faults\.Fill\(|FaultBufferStartsCleared|BdaPageTableStartsCleared' tests/ShaderRecompilerComputeTests.cpp rg -n -C 10 'm_fault_buffer.*Fill|Submit|FAULT_BUFFER_SIZE' src/graphics/host_gpu/renderer/cache/faultManager.cpp rg -n -C 10 'm_page_table.*Fill|page_table.*Fill|Submit' src/graphics/host_gpu/renderer/cache/bufferCache.cpp ``` Length of output: 13430 --- </details> `@NeySlim` Thanks for the clarification. I verified that `CheckFaultBufferSummary` clears the full fault buffer before writing its fixture. Both constructors also clear their buffers with separate submissions. The dirty-memory regression tests are present; I did not run them. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1296 File: tests/ShaderRecompilerComputeTests.cpp:5356-5356 Timestamp: 2026-10-09T11:39:14.076Z Learning: In KytyPS5's C++ renderer, FaultManager in src/graphics/host_gpu/renderer/cache/faultManager.cpp and BufferCache in src/graphics/host_gpu/renderer/cache/bufferCache.cpp initialize the fault buffer and BDA page table before guest commands bind the command scheduler. Constructor initialization therefore uses Buffer::Fill with m_scheduler.BeginCommand(), followed by a separate m_scheduler.Submit(), rather than the Fill overload that uses the scheduler's current command buffer. ``` > 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> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Uninitialized%20device%20memory%20can%20trigger%20bogus%20fault%20scans.%20%40coderabbitai%20flagged%20it%3A%20clear%20fault%20buffers%20and%20BDA%20page%20tables%20at%20creation%2C%20then%20test%20the%20fix.%20Try%20%40coderabbitai%20%F0%9F%9A%80&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1296%23discussion_r4229372758)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 11:54 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 5261 (outdated):

@@ -5198,6 +5210,226 @@ class VulkanHarness {
     std::printf("[gpu]     %-32s ok\n", name);
   }
 
+  // Runs `body` with renderer allocations whose new device memory has every bit set: device
+  // memory contents are undefined, and memory reused from freed allocations is often nonzero.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    struct Dirtier {
+      VulkanHarness *harness;
+      const char *name;
+    } dirtier{this, name};
+    VmaDeviceMemoryCallbacks callbacks{};
+    callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory,
+                               VkDeviceSize size, void *user) {
+      const auto &self = *static_cast<const Dirtier *>(user);
+      self.harness->FillDeviceMemory(self.name, type, memory, size);
+    };
+    callbacks.pUserData = &dirtier;
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    VmaAllocatorCreateInfo allocator_info{};
+    allocator_info.instance = m_instance;
+    allocator_info.physicalDevice = m_physical_device;
+    allocator_info.device = m_device;
+    allocator_info.pVulkanFunctions = &functions;
+    allocator_info.vulkanApiVersion = VK_API_VERSION_1_3;
+    allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
+    allocator_info.pDeviceMemoryCallbacks = &callbacks;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    vmaDestroyAllocator(dirty);
+  }
+
+  void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory,
+                        vk::DeviceSize size) {
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};
+    buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst;
+    vk::Buffer buffer = nullptr;
+    RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer),
+              "vkCreateBuffer");
+    vk::MemoryRequirements requirements{};
+    m_device.getBufferMemoryRequirements(buffer, &requirements);
+    // Memory that no transfer buffer can bind holds no renderer buffer either.
+    if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) {
+      RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0),

Right: the registered guest buffer (shader device address) gets a dedicated allocation, and the fixture bound a temporary buffer to it. Fixed in 7ed6cc3d: the test allocator now wraps vkAllocateMemory and poisons only memory allocated without VkMemoryDedicatedAllocateInfo. Its block size is large enough for the page table and the fault buffer to be block allocations, and both checks require a poisoned block that can hold their buffer. Both still fail without the clears.

**@⁠NeySlim** on GitHub · 2026-10-09 11:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229816408) On `tests/ShaderRecompilerComputeTests.cpp` line 5261 (outdated): ```diff @@ -5198,6 +5210,226 @@ class VulkanHarness { std::printf("[gpu] %-32s ok\n", name); } + // Runs `body` with renderer allocations whose new device memory has every bit set: device + // memory contents are undefined, and memory reused from freed allocations is often nonzero. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + struct Dirtier { + VulkanHarness *harness; + const char *name; + } dirtier{this, name}; + VmaDeviceMemoryCallbacks callbacks{}; + callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory, + VkDeviceSize size, void *user) { + const auto &self = *static_cast<const Dirtier *>(user); + self.harness->FillDeviceMemory(self.name, type, memory, size); + }; + callbacks.pUserData = &dirtier; + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + VmaAllocatorCreateInfo allocator_info{}; + allocator_info.instance = m_instance; + allocator_info.physicalDevice = m_physical_device; + allocator_info.device = m_device; + allocator_info.pVulkanFunctions = &functions; + allocator_info.vulkanApiVersion = VK_API_VERSION_1_3; + allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; + allocator_info.pDeviceMemoryCallbacks = &callbacks; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + vmaDestroyAllocator(dirty); + } + + void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory, + vk::DeviceSize size) { + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; + buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst; + vk::Buffer buffer = nullptr; + RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer), + "vkCreateBuffer"); + vk::MemoryRequirements requirements{}; + m_device.getBufferMemoryRequirements(buffer, &requirements); + // Memory that no transfer buffer can bind holds no renderer buffer either. + if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) { + RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0), ``` Right: the registered guest buffer (shader device address) gets a dedicated allocation, and the fixture bound a temporary buffer to it. Fixed in 7ed6cc3d: the test allocator now wraps `vkAllocateMemory` and poisons only memory allocated without `VkMemoryDedicatedAllocateInfo`. Its block size is large enough for the page table and the fault buffer to be block allocations, and both checks require a poisoned block that can hold their buffer. Both still fail without the clears.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 12:03 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 5261 (outdated):

@@ -5198,6 +5210,226 @@ class VulkanHarness {
     std::printf("[gpu]     %-32s ok\n", name);
   }
 
+  // Runs `body` with renderer allocations whose new device memory has every bit set: device
+  // memory contents are undefined, and memory reused from freed allocations is often nonzero.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    struct Dirtier {
+      VulkanHarness *harness;
+      const char *name;
+    } dirtier{this, name};
+    VmaDeviceMemoryCallbacks callbacks{};
+    callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory,
+                               VkDeviceSize size, void *user) {
+      const auto &self = *static_cast<const Dirtier *>(user);
+      self.harness->FillDeviceMemory(self.name, type, memory, size);
+    };
+    callbacks.pUserData = &dirtier;
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    VmaAllocatorCreateInfo allocator_info{};
+    allocator_info.instance = m_instance;
+    allocator_info.physicalDevice = m_physical_device;
+    allocator_info.device = m_device;
+    allocator_info.pVulkanFunctions = &functions;
+    allocator_info.vulkanApiVersion = VK_API_VERSION_1_3;
+    allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
+    allocator_info.pDeviceMemoryCallbacks = &callbacks;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    vmaDestroyAllocator(dirty);
+  }
+
+  void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory,
+                        vk::DeviceSize size) {
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};
+    buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst;
+    vk::Buffer buffer = nullptr;
+    RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer),
+              "vkCreateBuffer");
+    vk::MemoryRequirements requirements{};
+    m_device.getBufferMemoryRequirements(buffer, &requirements);
+    // Memory that no transfer buffer can bind holds no renderer buffer either.
+    if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) {
+      RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0),

@NeySlim Thanks for fixing this in 7ed6cc3d. Excluding memory allocated with VkMemoryDedicatedAllocateInfo addresses the invalid temporary-buffer binding. Requiring a sufficiently large poisoned block keeps the initialization checks meaningful. Your reported failures without the clears confirm that the checks still detect missing initialization.


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

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 12:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#discussion_r4229881126) On `tests/ShaderRecompilerComputeTests.cpp` line 5261 (outdated): ```diff @@ -5198,6 +5210,226 @@ class VulkanHarness { std::printf("[gpu] %-32s ok\n", name); } + // Runs `body` with renderer allocations whose new device memory has every bit set: device + // memory contents are undefined, and memory reused from freed allocations is often nonzero. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + struct Dirtier { + VulkanHarness *harness; + const char *name; + } dirtier{this, name}; + VmaDeviceMemoryCallbacks callbacks{}; + callbacks.pfnAllocate = [](VmaAllocator, uint32_t type, VkDeviceMemory memory, + VkDeviceSize size, void *user) { + const auto &self = *static_cast<const Dirtier *>(user); + self.harness->FillDeviceMemory(self.name, type, memory, size); + }; + callbacks.pUserData = &dirtier; + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + VmaAllocatorCreateInfo allocator_info{}; + allocator_info.instance = m_instance; + allocator_info.physicalDevice = m_physical_device; + allocator_info.device = m_device; + allocator_info.pVulkanFunctions = &functions; + allocator_info.vulkanApiVersion = VK_API_VERSION_1_3; + allocator_info.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT; + allocator_info.pDeviceMemoryCallbacks = &callbacks; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + vmaDestroyAllocator(dirty); + } + + void FillDeviceMemory(const char *name, uint32_t type, vk::DeviceMemory memory, + vk::DeviceSize size) { + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; + buffer_info.usage = vk::BufferUsageFlagBits::eTransferDst; + vk::Buffer buffer = nullptr; + RequireVk(name, "dirty memory", m_device.createBuffer(&buffer_info, nullptr, &buffer), + "vkCreateBuffer"); + vk::MemoryRequirements requirements{}; + m_device.getBufferMemoryRequirements(buffer, &requirements); + // Memory that no transfer buffer can bind holds no renderer buffer either. + if (((requirements.memoryTypeBits >> type) & 1u) != 0 && requirements.size <= size) { + RequireVk(name, "dirty memory", m_device.bindBufferMemory(buffer, memory, 0), ``` `@NeySlim` Thanks for fixing this in `7ed6cc3d`. Excluding memory allocated with `VkMemoryDedicatedAllocateInfo` addresses the invalid temporary-buffer binding. Requiring a sufficiently large poisoned block keeps the initialization checks meaningful. Your reported failures without the clears confirm that the checks still detect missing initialization. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=%40coderabbitai%20caught%20a%20Vulkan%20test%20bug%3A%20temp%20buffers%20can%E2%80%99t%20bind%20dedicated%20VMA%20allocations.%20The%20fixture%20now%20poisons%20eligible%20block%20allocations%20and%20verifies%20clears.%20Try%20it%20for%20sharper%20reviews!%20%F0%9F%9B%A0%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1296%23discussion_r4229665275)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-19 19:09 UTC · original

Closing this one. Main now emits the raw indirect buffer loads as shared function bodies (c1f6838e4), so the branch-free load would have to be redone on top of that rather than rebased. I'll come back with a new PR if the lookup chains still show up in the hot passes after that.

**@⁠NeySlim** on GitHub · 2026-10-19 19:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1296#issuecomment-6275111602) Closing this one. Main now emits the raw indirect buffer loads as shared function bodies (c1f6838e4), so the branch-free load would have to be redone on top of that rather than rebased. I'll come back with a new PR if the lookup chains still show up in the hot passes after that.

Pull request closed

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