gpu: scan only summarized words of the BDA fault buffer #1294

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

@⁠NeySlim on GitHub · 2026-10-09 10:52 UTC · original
NeySlim:perf/fault-summary → main · +426 −28 · 5 files · 4 commits · open

Problem

Shaders that access guest memory through BDA (FLAT, GLOBAL and scalar address loads) record a fault bit when a page has no GPU buffer yet. After every submission that ran such a shader, FaultManager::ProcessFaultBuffer dispatches one invocation per 32 pages of the whole cached address space: 3,145,728 invocations that read the complete 12 MiB bitmap and write every word back to zero, even when no fault was recorded.

In God of War Ragnarök (PPSA08332) the pass runs about 13 times per frame. GPU timestamps around each recorded operation put it at 1.06 ms per frame in gameplay and 1.08 ms in the opening cutscene.

Change

  • Recording a fault also sets one summary bit per 64 bitmap words (2048 pages). The 1536 summary words follow the bitmap in the same buffer. Both bits are set with an atomic OR, so concurrent faults on neighbouring pages keep every bit.
  • The processing pass runs one invocation per summary word (24 workgroups) and reads only the bitmap words that a summary bit names. It clears the words and summary bits it reports.
  • When the download area is full, the bits that were not reported stay set for the next pass instead of being cleared, and the host clamps the fault counter so it never reads past the area.

The set of reported pages is unchanged: a fault is still recorded by the access that misses, and reported by the next pass.

main now clears the fault buffer and the BDA page table when the buffer cache creates them (4644c5292), so this PR no longer does. It keeps two checks for those clears: a stale bitmap or summary bit would make the pass report pages that never faulted, and a stale page-table entry would send BDA accesses to a garbage address instead of the fault path.

Test

  • FlatLoadRecordsFaultSummary (compute case): a FLAT load from an unmapped page reads zero and sets both its page bit and its summary bit. It fails without the emitter change.
  • FaultBufferSummary (renderer check): faults recorded with their summary bits are reported (the pages get a buffer) and cleared, and a page bit without a summary bit is left untouched. It fails with the previous full scan.
  • FaultBufferStartsCleared and BdaPageTableStartsCleared (renderer checks): a renderer is created with an allocator that sets every bit of each new device memory block not dedicated to one resource, with blocks large enough to hold the page table. The new fault buffer must read zero, the page-table entries of unregistered pages must be zero, and a registered buffer's pages must translate. Each fails without main's clear.
  • FaultBufferSummary clears the fault buffer before writing its fixture.
  • The harness allocates the fault buffer with the new size.

Validation

  • Linux, Radeon 8060S (RADV, Mesa 26.2.3).
  • shader_recompiler_compute_tests, one case per process: identical results to origin/main apart from the four new passing cases. The 10 cases that already fail on origin/main with this driver fail the same way.
  • In game (opening cutscene and first gameplay, about 13 passes per frame): the pass takes 0.03 to 0.04 ms of GPU time per frame instead of 1.06 to 1.11 ms. The screenshots are unchanged.
  • Not tested on Windows. The change is in a compute shader, 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 of each recorded operation, 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/1294) `NeySlim:perf/fault-summary` → `main` · +426 −28 · 5 files · 4 commits · open ## Problem Shaders that access guest memory through BDA (FLAT, GLOBAL and scalar address loads) record a fault bit when a page has no GPU buffer yet. After every submission that ran such a shader, `FaultManager::ProcessFaultBuffer` dispatches one invocation per 32 pages of the whole cached address space: 3,145,728 invocations that read the complete 12 MiB bitmap and write every word back to zero, even when no fault was recorded. In God of War Ragnarök (PPSA08332) the pass runs about 13 times per frame. GPU timestamps around each recorded operation put it at 1.06 ms per frame in gameplay and 1.08 ms in the opening cutscene. ## Change - Recording a fault also sets one summary bit per 64 bitmap words (2048 pages). The 1536 summary words follow the bitmap in the same buffer. Both bits are set with an atomic OR, so concurrent faults on neighbouring pages keep every bit. - The processing pass runs one invocation per summary word (24 workgroups) and reads only the bitmap words that a summary bit names. It clears the words and summary bits it reports. - When the download area is full, the bits that were not reported stay set for the next pass instead of being cleared, and the host clamps the fault counter so it never reads past the area. The set of reported pages is unchanged: a fault is still recorded by the access that misses, and reported by the next pass. main now clears the fault buffer and the BDA page table when the buffer cache creates them (4644c5292), so this PR no longer does. It keeps two checks for those clears: a stale bitmap or summary bit would make the pass report pages that never faulted, and a stale page-table entry would send BDA accesses to a garbage address instead of the fault path. ## Test - `FlatLoadRecordsFaultSummary` (compute case): a FLAT load from an unmapped page reads zero and sets both its page bit and its summary bit. It fails without the emitter change. - `FaultBufferSummary` (renderer check): faults recorded with their summary bits are reported (the pages get a buffer) and cleared, and a page bit without a summary bit is left untouched. It fails with the previous full scan. - `FaultBufferStartsCleared` and `BdaPageTableStartsCleared` (renderer checks): a renderer is created with an allocator that sets every bit of each new device memory block not dedicated to one resource, with blocks large enough to hold the page table. The new fault buffer must read zero, the page-table entries of unregistered pages must be zero, and a registered buffer's pages must translate. Each fails without main's clear. - `FaultBufferSummary` clears the fault buffer before writing its fixture. - The harness allocates the fault buffer with the new size. ## Validation - Linux, Radeon 8060S (RADV, Mesa 26.2.3). - `shader_recompiler_compute_tests`, one case per process: identical results to origin/main apart from the four new passing cases. The 10 cases that already fail on origin/main with this driver fail the same way. - In game (opening cutscene and first gameplay, about 13 passes per frame): the pass takes 0.03 to 0.04 ms of GPU time per frame instead of 1.06 to 1.11 ms. The screenshots are unchanged. - Not tested on Windows. The change is in a compute shader, 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 of each recorded operation, 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:51:54 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 10:55 UTC · original · edited 2026-10-21 06:55 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: c53f8fcc8102dd05f2c49da376a74efff6f112d9
  • Latest commit, not reviewed: 9490d7beb8

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

The fault buffer now contains a page bitmap and a summary bitmap. BDA fault recording atomically updates both. Fault processing uses the summary bitmap to find page words, appends fault addresses for download, and restores unprocessed faults when the download limit is reached. The change also initializes the BDA page table and fault buffer to zero. Compute tests check initialization, bitmap state, and fault processing.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to c53f8

The fault-buffer scanning change itself shows no concrete defect. The risk is confined to the new compute-test harness, which may abort on GPUs with a small maximum buffer size, and a possible missing transfer barrier in one readback check. Address both before merge, or accept them knowingly.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 6 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: processing only summarized words in the BDA fault buffer.
Description check Passed The description directly explains the problem, implementation, tests, validation, and performance impact of the BDA fault-buffer changes.
Full details: Docstring Coverage

Explanation

Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 6 files. (1 skipped: 1 too large.)

Resolution

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

  • 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:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#issuecomment-6079482742) · edited 2026-10-21 06:55 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/1294?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: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: c53f8fcc8102dd05f2c49da376a74efff6f112d9 > - Latest commit, not reviewed: 9490d7beb801f1ddbfbdbb0f00ab7911713d671c > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The fault buffer now contains a page bitmap and a summary bitmap. BDA fault recording atomically updates both. Fault processing uses the summary bitmap to find page words, appends fault addresses for download, and restores unprocessed faults when the download limit is reached. The change also initializes the BDA page table and fault buffer to zero. Compute tests check initialization, bitmap state, and fault processing. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c53f8fcc8102dd05f2c49da376a74efff6f112d9" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🔵 Low</strong> · up to <code>c53f8</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `c53f8` --> <!-- final_review_risk_coverage:{"sourceCommitId":"c53f8fcc8102dd05f2c49da376a74efff6f112d9","coveredCommitId":"c53f8fcc8102dd05f2c49da376a74efff6f112d9","kind":"reviewed"} --> The fault-buffer scanning change itself shows no concrete defect. The risk is confined to the new compute-test harness, which may abort on GPUs with a small maximum buffer size, and a possible missing transfer barrier in one readback check. Address both before merge, or accept them knowingly. <!-- 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 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 6 files. (1 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 | | :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------- | | 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. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: processing only summarized words in the BDA fault buffer. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the problem, implementation, tests, validation, and performance impact of the BDA fault-buffer changes. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 6 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- 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=1294)! 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 -->
Author
Owner

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

@@ -5198,6 +5200,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),
+                "vkBindBufferMemory");

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

git diff --no-ext-diff --unified=80 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 ccfcb32a42afa49418f30848150e6ee8ee816946 -- tests/ShaderRecompilerComputeTests.cpp
printf '\n--- FillDeviceMemory references ---\n'
rg -n -F -- 'FillDeviceMemory' tests/ShaderRecompilerComputeTests.cpp
printf '\n--- allocation and target buffer references ---\n'
rg -n -F -- 'm_fault_buffer' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'page_table' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 42099


🏁 Script executed:

sed -n '5100,5295p' tests/ShaderRecompilerComputeTests.cpp
sed -n '18780,19030p' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'CreateDeviceBuffer(' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'vmaCreateBuffer' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT' .
rg -n -F -- 'VMA_MEMORY_USAGE_AUTO' .

Repository: KytyPS5/KytyPS5

Length of output: 22117


🏁 Script executed:

rg -n -F -- 'GetBdaPageTableBuffer' src tests
rg -n -F -- 'GetFaultBuffer' src tests
rg -n -F -- 'with_bda' src tests
sed -n '1,130p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
rg -n -F -- 'm_runtime_context.allocator' tests/ShaderRecompilerComputeTests.cpp
rg -n -F -- 'GraphicContext' tests/ShaderRecompilerComputeTests.cpp | head -20

Repository: KytyPS5/KytyPS5

Length of output: 6549


🏁 Script executed:

sed -n '1,180p' src/graphics/host_gpu/renderer/cache/bufferCache.h
sed -n '1,220p' src/graphics/host_gpu/renderer/cache/faultManager.h
rg -n -F -- 'm_bda_pagetable_buffer' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'm_fault_buffer' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'eShaderDeviceAddress' src/graphics/host_gpu/renderer/cache

Repository: KytyPS5/KytyPS5

Length of output: 11373


🏁 Script executed:

sed -n '205,245p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp
sed -n '1,52p' src/graphics/host_gpu/renderer/cache/faultManager.cpp
rg -n -F -- 'constexpr vk::BufferUsageFlags AllFlags' src/graphics/host_gpu/renderer/cache

Repository: KytyPS5/KytyPS5

Length of output: 4326


🏁 Script executed:

sed -n '25,42p' src/graphics/host_gpu/renderer/cache/streamBuffer.h

Repository: KytyPS5/KytyPS5

Length of output: 792


🏁 Script executed:

sed -n '350,405p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp
sed -n '1,130p' src/graphics/host_gpu/renderer/cache/streamBuffer.h

Repository: KytyPS5/KytyPS5

Length of output: 8187


Do not bind a temporary buffer to dedicated memory.

The new page-table check creates a guest buffer with eShaderDeviceAddress. VMA marks that allocation as dedicated. FillDeviceMemory then binds the allocation to a different temporary buffer. Dedicated memory can be bound only to its designated resource. This can make the initialization tests fail on devices that use dedicated allocations.

Poison eligible memory through the designated buffer or another valid path instead. The page-table and fault buffers themselves use AllFlags, which does not request dedicated allocation.

✅ Addressed in commits 7ed6cc3 to 95cddd3

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229675485) · edited 2026-10-09 11:58 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 5252 (outdated): ```diff @@ -5198,6 +5200,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), + "vkBindBufferMemory"); ``` **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash git diff --no-ext-diff --unified=80 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 ccfcb32a42afa49418f30848150e6ee8ee816946 -- tests/ShaderRecompilerComputeTests.cpp printf '\n--- FillDeviceMemory references ---\n' rg -n -F -- 'FillDeviceMemory' tests/ShaderRecompilerComputeTests.cpp printf '\n--- allocation and target buffer references ---\n' rg -n -F -- 'm_fault_buffer' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'page_table' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 42099 --- 🏁 Script executed: ```bash sed -n '5100,5295p' tests/ShaderRecompilerComputeTests.cpp sed -n '18780,19030p' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'CreateDeviceBuffer(' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'vmaCreateBuffer' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT' . rg -n -F -- 'VMA_MEMORY_USAGE_AUTO' . ``` Repository: KytyPS5/KytyPS5 Length of output: 22117 --- 🏁 Script executed: ```bash rg -n -F -- 'GetBdaPageTableBuffer' src tests rg -n -F -- 'GetFaultBuffer' src tests rg -n -F -- 'with_bda' src tests sed -n '1,130p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp rg -n -F -- 'm_runtime_context.allocator' tests/ShaderRecompilerComputeTests.cpp rg -n -F -- 'GraphicContext' tests/ShaderRecompilerComputeTests.cpp | head -20 ``` Repository: KytyPS5/KytyPS5 Length of output: 6549 --- 🏁 Script executed: ```bash sed -n '1,180p' src/graphics/host_gpu/renderer/cache/bufferCache.h sed -n '1,220p' src/graphics/host_gpu/renderer/cache/faultManager.h rg -n -F -- 'm_bda_pagetable_buffer' src/graphics/host_gpu/renderer/cache rg -n -F -- 'm_fault_buffer' src/graphics/host_gpu/renderer/cache rg -n -F -- 'eShaderDeviceAddress' src/graphics/host_gpu/renderer/cache ``` Repository: KytyPS5/KytyPS5 Length of output: 11373 --- 🏁 Script executed: ```bash sed -n '205,245p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp sed -n '1,52p' src/graphics/host_gpu/renderer/cache/faultManager.cpp rg -n -F -- 'constexpr vk::BufferUsageFlags AllFlags' src/graphics/host_gpu/renderer/cache ``` Repository: KytyPS5/KytyPS5 Length of output: 4326 --- 🏁 Script executed: ```bash sed -n '25,42p' src/graphics/host_gpu/renderer/cache/streamBuffer.h ``` Repository: KytyPS5/KytyPS5 Length of output: 792 --- 🏁 Script executed: ```bash sed -n '350,405p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp sed -n '1,130p' src/graphics/host_gpu/renderer/cache/streamBuffer.h ``` Repository: KytyPS5/KytyPS5 Length of output: 8187 --- </details> **Do not bind a temporary buffer to dedicated memory.** The new page-table check creates a guest buffer with `eShaderDeviceAddress`. VMA marks that allocation as dedicated. `FillDeviceMemory` then binds the allocation to a different temporary buffer. Dedicated memory can be bound only to its designated resource. This can make the initialization tests fail on devices that use dedicated allocations. Poison eligible memory through the designated buffer or another valid path instead. The page-table and fault buffers themselves use `AllFlags`, which does not request dedicated allocation. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:29da201f921eef2883843529 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 7ed6cc3 to 95cddd3
@ -5495,0 +5735,4 @@
auto readback =
CreateHostBuffer(name, faults.Size(), vk::BufferUsageFlagBits::eTransferDst, {});
const vk::BufferCopy copy{0, 0, faults.Size()};
scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy);
Author
Owner

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- changed lines and nearby test code ---'
nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5230,5335p;5360,5435p'
printf '%s\n' '--- fault-buffer definitions and uses ---'
rg -n -F -- 'GetFaultBuffer' tests/ShaderRecompilerComputeTests.cpp src include || test "$?" -eq 1
rg -n -F -- 'FAULT_BUFFER_SIZE' . --glob '!build/**' --glob '!dist/**' || test "$?" -eq 1
printf '%s\n' '--- synchronization calls in the test ---'
rg -n -F -- 'pipelineBarrier' tests/ShaderRecompilerComputeTests.cpp || test "$?" -eq 1
printf '%s\n' '--- head/base diff for the test ---'
git diff --unified=35 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 ccfcb32a42afa49418f30848150e6ee8ee816946 -- tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 11743


🏁 Script executed:

set -eu
printf '%s\n' '--- fault manager and buffer definitions ---'
nl -ba src/graphics/host_gpu/renderer/cache/faultManager.h | sed -n '1,220p'
rg -n -F -- 'class Buffer' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer | head -40
rg -n -F -- 'void Fill(' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer | head -40
printf '%s\n' '--- relevant complete test block ---'
nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5316,5382p;5394,5421p'
printf '%s\n' '--- fault manager construction and initialization ---'
rg -n -F -- 'FaultManager' src tests
rg -n -F -- 'm_fault_buffer' src/graphics/host_gpu/renderer/cache
printf '%s\n' '--- scheduler finish and command setup declarations ---'
rg -n -F -- 'class CommandScheduler' src/graphics/host_gpu/renderer
rg -n -F -- 'BeginCommands' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 12422


🏁 Script executed:

set -eu
printf '%s\n' '--- fault manager implementation ---'
nl -ba src/graphics/host_gpu/renderer/cache/faultManager.cpp | sed -n '1,145p'
printf '%s\n' '--- stream buffer declarations and implementation ---'
nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.h | sed -n '1,120p'
rg -n -F -- 'Buffer::Fill' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer
printf '%s\n' '--- command scheduler implementation ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.h | sed -n '1,180p'
rg -n -F -- 'CommandScheduler::BeginCommand' src/graphics/host_gpu/renderer
rg -n -F -- 'CommandScheduler::Begin(' src/graphics/host_gpu/renderer
rg -n -F -- 'CommandScheduler::Finish' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 19674


🏁 Script executed:

set -eu
printf '%s\n' '--- scheduler implementation ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '130,225p;300,365p'
printf '%s\n' '--- command buffer submit path ---'
rg -n -F -- 'CommandBuffer::Submit' src/graphics/host_gpu/renderer
rg -n -F -- 'Submit(SubmitInfo' src/graphics/host_gpu/renderer
nl -ba src/graphics/host_gpu/renderer/commandBuffer.cpp 2>/dev/null | sed -n '1,180p' || true
printf '%s\n' '--- Buffer::Fill implementation ---'
nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.cpp | sed -n '175,220p'
printf '%s\n' '--- test scheduler helpers ---'
nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '18720,18790p'

Repository: KytyPS5/KytyPS5

Length of output: 5845


🏁 Script executed:

set -eu
printf '%s\n' '--- complete scheduler submission and begin-next path ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '340,430p'
rg -n -F -- 'void CommandScheduler::BeginNext' src/graphics/host_gpu/renderer/commandScheduler.cpp
printf '%s\n' '--- command buffer declaration and implementation files ---'
rg --files src/graphics/host_gpu/renderer | rg 'command(Buffer|Scheduler)'
rg -n -F -- 'class CommandBuffer' src/graphics/host_gpu/renderer
rg -n -F -- 'CommandBuffer::Begin' src/graphics/host_gpu/renderer
rg -n -F -- 'CommandBuffer::End' src/graphics/host_gpu/renderer
printf '%s\n' '--- Buffer::Fill implementation ---'
nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.cpp | sed -n '185,215p'

Repository: KytyPS5/KytyPS5

Length of output: 5492


🌐 Web query:

official Vulkan specification same queue submissions implicit memory dependency queue submission order buffer transfer write later transfer read

💡 Result:

**No.** The official Vulkan specification says same-queue *submission order* establishes an order for synchronization scopes, but “does not itself define any execution or memory dependencies.” So submitting a buffer transfer write before a transfer read does **not**, by order alone, guarantee the read sees the write. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html))

For this read-after-write hazard, insert a memory dependency—typically a pipeline barrier between the copies, with transfer-write as the source access and transfer-read as the destination access. The specification says read-after-write hazards need an appropriate memory dependency. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html))

Citations:

- 1: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html
- 2: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html

🌐 Web query:

site:github.khronos.org/Vulkan-Site/spec/latest synchronization vkCmdPipelineBarrier first synchronization scope commands submitted before command buffer later queue submission

💡 Result:

Yes. For `vkCmdPipelineBarrier`, the Vulkan spec says its first synchronization scope includes commands that occur **earlier in submission order** (when recorded outside a render pass), limited by `srcStageMask`. Submission order spans command buffers and queue submissions on the **same queue**; it is not limited to commands in the barrier’s command buffer. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html?utm_source=openai))

So a barrier can synchronize earlier-submitted work from a prior queue submission on that same queue. It does **not** by itself reach work on another queue.

Citations:

- 1: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html?utm_source=openai

Synchronize the fault-buffer initialization before copying.

FaultManager submits the zero fill separately. Same-queue submission order does not create a memory dependency. Add a transfer-write-to-transfer-read dependency before copyBuffer.

🐛 Suggested fix
       auto readback =
           CreateHostBuffer(name, faults.Size(), vk::BufferUsageFlagBits::eTransferDst, {});
       const vk::BufferCopy copy{0, 0, faults.Size()};
+      vk::MemoryBarrier written{};
+      written.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
+      written.dstAccessMask = vk::AccessFlagBits::eTransferRead;
+      scheduler.Current().Handle().pipelineBarrier(
+          vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 1,
+          &written, 0, nullptr, 0, nullptr);
       scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy);
📝 Committable suggestion

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

      vk::MemoryBarrier written{};
      written.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
      written.dstAccessMask = vk::AccessFlagBits::eTransferRead;
      scheduler.Current().Handle().pipelineBarrier(
          vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 1,
          &written, 0, nullptr, 0, nullptr);
      scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy);
**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229675496) · edited 2026-10-09 11:58 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -eu printf '%s\n' '--- changed lines and nearby test code ---' nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5230,5335p;5360,5435p' printf '%s\n' '--- fault-buffer definitions and uses ---' rg -n -F -- 'GetFaultBuffer' tests/ShaderRecompilerComputeTests.cpp src include || test "$?" -eq 1 rg -n -F -- 'FAULT_BUFFER_SIZE' . --glob '!build/**' --glob '!dist/**' || test "$?" -eq 1 printf '%s\n' '--- synchronization calls in the test ---' rg -n -F -- 'pipelineBarrier' tests/ShaderRecompilerComputeTests.cpp || test "$?" -eq 1 printf '%s\n' '--- head/base diff for the test ---' git diff --unified=35 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 ccfcb32a42afa49418f30848150e6ee8ee816946 -- tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 11743 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- fault manager and buffer definitions ---' nl -ba src/graphics/host_gpu/renderer/cache/faultManager.h | sed -n '1,220p' rg -n -F -- 'class Buffer' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer | head -40 rg -n -F -- 'void Fill(' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer | head -40 printf '%s\n' '--- relevant complete test block ---' nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5316,5382p;5394,5421p' printf '%s\n' '--- fault manager construction and initialization ---' rg -n -F -- 'FaultManager' src tests rg -n -F -- 'm_fault_buffer' src/graphics/host_gpu/renderer/cache printf '%s\n' '--- scheduler finish and command setup declarations ---' rg -n -F -- 'class CommandScheduler' src/graphics/host_gpu/renderer rg -n -F -- 'BeginCommands' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 12422 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- fault manager implementation ---' nl -ba src/graphics/host_gpu/renderer/cache/faultManager.cpp | sed -n '1,145p' printf '%s\n' '--- stream buffer declarations and implementation ---' nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.h | sed -n '1,120p' rg -n -F -- 'Buffer::Fill' src/graphics/host_gpu/renderer/cache src/graphics/host_gpu/renderer printf '%s\n' '--- command scheduler implementation ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.h | sed -n '1,180p' rg -n -F -- 'CommandScheduler::BeginCommand' src/graphics/host_gpu/renderer rg -n -F -- 'CommandScheduler::Begin(' src/graphics/host_gpu/renderer rg -n -F -- 'CommandScheduler::Finish' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 19674 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- scheduler implementation ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '130,225p;300,365p' printf '%s\n' '--- command buffer submit path ---' rg -n -F -- 'CommandBuffer::Submit' src/graphics/host_gpu/renderer rg -n -F -- 'Submit(SubmitInfo' src/graphics/host_gpu/renderer nl -ba src/graphics/host_gpu/renderer/commandBuffer.cpp 2>/dev/null | sed -n '1,180p' || true printf '%s\n' '--- Buffer::Fill implementation ---' nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.cpp | sed -n '175,220p' printf '%s\n' '--- test scheduler helpers ---' nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '18720,18790p' ``` Repository: KytyPS5/KytyPS5 Length of output: 5845 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- complete scheduler submission and begin-next path ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '340,430p' rg -n -F -- 'void CommandScheduler::BeginNext' src/graphics/host_gpu/renderer/commandScheduler.cpp printf '%s\n' '--- command buffer declaration and implementation files ---' rg --files src/graphics/host_gpu/renderer | rg 'command(Buffer|Scheduler)' rg -n -F -- 'class CommandBuffer' src/graphics/host_gpu/renderer rg -n -F -- 'CommandBuffer::Begin' src/graphics/host_gpu/renderer rg -n -F -- 'CommandBuffer::End' src/graphics/host_gpu/renderer printf '%s\n' '--- Buffer::Fill implementation ---' nl -ba src/graphics/host_gpu/renderer/cache/streamBuffer.cpp | sed -n '185,215p' ``` Repository: KytyPS5/KytyPS5 Length of output: 5492 --- 🌐 Web query: `official Vulkan specification same queue submissions implicit memory dependency queue submission order buffer transfer write later transfer read` 💡 Result: ``` **No.** The official Vulkan specification says same-queue *submission order* establishes an order for synchronization scopes, but “does not itself define any execution or memory dependencies.” So submitting a buffer transfer write before a transfer read does **not**, by order alone, guarantee the read sees the write. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html)) For this read-after-write hazard, insert a memory dependency—typically a pipeline barrier between the copies, with transfer-write as the source access and transfer-read as the destination access. The specification says read-after-write hazards need an appropriate memory dependency. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html)) Citations: - 1: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html - 2: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html ``` --- 🌐 Web query: `site:github.khronos.org/Vulkan-Site/spec/latest synchronization vkCmdPipelineBarrier first synchronization scope commands submitted before command buffer later queue submission` 💡 Result: ``` Yes. For `vkCmdPipelineBarrier`, the Vulkan spec says its first synchronization scope includes commands that occur **earlier in submission order** (when recorded outside a render pass), limited by `srcStageMask`. Submission order spans command buffers and queue submissions on the **same queue**; it is not limited to commands in the barrier’s command buffer. ([github.khronos.org](https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html?utm_source=openai)) So a barrier can synchronize earlier-submitted work from a prior queue submission on that same queue. It does **not** by itself reach work on another queue. Citations: - 1: https://github.khronos.org/Vulkan-Site/spec/latest/chapters/synchronization.html?utm_source=openai ``` --- </details> **Synchronize the fault-buffer initialization before copying.** `FaultManager` submits the zero fill separately. Same-queue submission order does not create a memory dependency. Add a transfer-write-to-transfer-read dependency before `copyBuffer`. <details> <summary>🐛 Suggested fix</summary> ```diff auto readback = CreateHostBuffer(name, faults.Size(), vk::BufferUsageFlagBits::eTransferDst, {}); const vk::BufferCopy copy{0, 0, faults.Size()}; + vk::MemoryBarrier written{}; + written.srcAccessMask = vk::AccessFlagBits::eTransferWrite; + written.dstAccessMask = vk::AccessFlagBits::eTransferRead; + scheduler.Current().Handle().pipelineBarrier( + vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 1, + &written, 0, nullptr, 0, nullptr); scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy); ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion vk::MemoryBarrier written{}; written.srcAccessMask = vk::AccessFlagBits::eTransferWrite; written.dstAccessMask = vk::AccessFlagBits::eTransferRead; scheduler.Current().Handle().pipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer, {}, 1, &written, 0, nullptr, 0, nullptr); scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:899de0901fd66502d89a18fd --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 11:37 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: 95098f0d-d7d9-42ab-ad29-a0dc97d51596
📥 Commits

Reviewing files that changed from the base of the PR and between ed221b64b108ee2e9a14152787948a6aab26b98b and ccfcb32a42afa49418f30848150e6ee8ee816946.

📒 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; 3 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#pullrequestreview-5469501595) · **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**: `95098f0d-d7d9-42ab-ad29-a0dc97d51596` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between ed221b64b108ee2e9a14152787948a6aab26b98b and ccfcb32a42afa49418f30848150e6ee8ee816946. </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; 3 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=331f27c8-77b7-4dfe-949f-a7de0196f533 attempt=7940e126-5401-444f-be4d-ec408a8dc7a6 batch=1/1 -->
Author
Owner

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

@@ -5198,6 +5200,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),
+                "vkBindBufferMemory");

Same fix as on #1296, in 7ed6cc3d: memory dedicated to a resource is no longer poisoned through another buffer. The fixture wraps vkAllocateMemory and skips allocations with VkMemoryDedicatedAllocateInfo, and the block size keeps the page table and fault buffer in poisoned blocks (checked by the tests).

**@⁠NeySlim** on GitHub · 2026-10-09 11:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229816611) On `tests/ShaderRecompilerComputeTests.cpp` line 5252 (outdated): ```diff @@ -5198,6 +5200,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), + "vkBindBufferMemory"); ``` Same fix as on #1296, in 7ed6cc3d: memory dedicated to a resource is no longer poisoned through another buffer. The fixture wraps `vkAllocateMemory` and skips allocations with `VkMemoryDedicatedAllocateInfo`, and the block size keeps the page table and fault buffer in poisoned blocks (checked by the tests).
@ -5495,0 +5735,4 @@
auto readback =
CreateHostBuffer(name, faults.Size(), vk::BufferUsageFlagBits::eTransferDst, {});
const vk::BufferCopy copy{0, 0, faults.Size()};
scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy);
Author
Owner

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

The dependency is already there: Buffer::Fill ends with a barrier from transfer write to all commands, memory read and write, recorded in the clear submission. The second scope of a pipeline barrier covers every later command in submission order on the queue, later submissions included, so the copy here and the first shader that uses the buffer are ordered after the clear. 95cddd30 states this in the comment next to the clear.

**@⁠NeySlim** on GitHub · 2026-10-09 11:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229816825) The dependency is already there: `Buffer::Fill` ends with a barrier from transfer write to all commands, memory read and write, recorded in the clear submission. The second scope of a pipeline barrier covers every later command in submission order on the queue, later submissions included, so the copy here and the first shader that uses the buffer are ordered after the clear. 95cddd30 states this in the comment next to the clear.
Author
Owner

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

@@ -5198,6 +5200,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),
+                "vkBindBufferMemory");

@NeySlim Thanks for the clarification. The fix in 7ed6cc3d addresses this finding: allocations with VkMemoryDedicatedAllocateInfo are excluded from poisoning through a temporary buffer. The block-size checks preserve poisoning coverage for the page table and fault buffer.


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:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229844212) On `tests/ShaderRecompilerComputeTests.cpp` line 5252 (outdated): ```diff @@ -5198,6 +5200,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), + "vkBindBufferMemory"); ``` `@NeySlim` Thanks for the clarification. The fix in `7ed6cc3d` addresses this finding: allocations with `VkMemoryDedicatedAllocateInfo` are excluded from poisoning through a temporary buffer. The block-size checks preserve poisoning coverage for the page table and fault buffer. --- <!-- 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=Dedicated%20Vulkan%20memory%20must%20stay%20with%20its%20designated%20buffer%E2%80%94poisoning%20it%20through%20a%20temporary%20buffer%20can%20break%20tests.%20%40coderabbitai%20catches%20subtle%20bugs%20like%20this%3B%20give%20it%20a%20try!%20%F0%9F%94%8D&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1294%23discussion_r4229675485)? 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 -->
@ -5495,0 +5735,4 @@
auto readback =
CreateHostBuffer(name, faults.Size(), vk::BufferUsageFlagBits::eTransferDst, {});
const vk::BufferCopy copy{0, 0, faults.Size()};
scheduler.Current().Handle().copyBuffer(faults.Handle(), readback.buffer, 1, &copy);
Author
Owner

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
ast-grep outline src/graphics/host_gpu/renderer/cache/streamBuffer.cpp --match Fill --view expanded
ast-grep outline src/graphics/host_gpu/renderer/cache/faultManager.cpp --match FaultManager --view expanded
rg -n -A35 -B3 'void Buffer::Fill\(' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp
rg -n -A18 -B12 'm_fault_buffer.*Fill|BeginCommand|Submit' src/graphics/host_gpu/renderer/cache/faultManager.cpp

Length of output: 4843


@NeySlim You are correct. Buffer::Fill already records a transfer-write-to-all-commands barrier with memory-read and memory-write destination access. Its second scope covers later commands on the same queue, including later submissions.

I missed that existing dependency. The additional barrier before copyBuffer is unnecessary. I withdraw this finding. Thanks for the clarification.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1294
File: tests/ShaderRecompilerComputeTests.cpp:5428-5428
Timestamp: 2026-10-09T11:59:22.745Z
Learning: In KytyPS5's C++ Vulkan renderer, Buffer::Fill in src/graphics/host_gpu/renderer/cache/streamBuffer.cpp ends with a buffer barrier from transfer write to all commands, with memory-read and memory-write destination access. This barrier covers later accesses to the filled range in subsequent submissions on the same queue. FaultManager initialization in src/graphics/host_gpu/renderer/cache/faultManager.cpp uses this Fill operation before submitting the clear, so tests/ShaderRecompilerComputeTests.cpp does not need another transfer-write-to-transfer-read barrier before copying the initialized fault 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.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 11:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4229852860) <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash set -eu ast-grep outline src/graphics/host_gpu/renderer/cache/streamBuffer.cpp --match Fill --view expanded ast-grep outline src/graphics/host_gpu/renderer/cache/faultManager.cpp --match FaultManager --view expanded rg -n -A35 -B3 'void Buffer::Fill\(' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp rg -n -A18 -B12 'm_fault_buffer.*Fill|BeginCommand|Submit' src/graphics/host_gpu/renderer/cache/faultManager.cpp ``` Length of output: 4843 --- </details> `@NeySlim` You are correct. `Buffer::Fill` already records a transfer-write-to-all-commands barrier with memory-read and memory-write destination access. Its second scope covers later commands on the same queue, including later submissions. I missed that existing dependency. The additional barrier before `copyBuffer` is unnecessary. I withdraw this finding. Thanks for the clarification. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1294 File: tests/ShaderRecompilerComputeTests.cpp:5428-5428 Timestamp: 2026-10-09T11:59:22.745Z Learning: In KytyPS5's C++ Vulkan renderer, Buffer::Fill in src/graphics/host_gpu/renderer/cache/streamBuffer.cpp ends with a buffer barrier from transfer write to all commands, with memory-read and memory-write destination access. This barrier covers later accesses to the filled range in subsequent submissions on the same queue. FaultManager initialization in src/graphics/host_gpu/renderer/cache/faultManager.cpp uses this Fill operation before submitting the clear, so tests/ShaderRecompilerComputeTests.cpp does not need another transfer-write-to-transfer-read barrier before copying the initialized fault 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> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-13 22:31 UTC · original · edited 2026-10-13 23:06 UTC
On tests/ShaderRecompilerComputeTests.cpp line 5514 (outdated):

@@ -5454,6 +5456,247 @@ 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.
+  // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is,
+  // so blocks are made large enough to hold the page table.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    functions.vkAllocateMemory = &AllocatePoisonedMemory;
+    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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    s_poisoning = this;
+    s_poisoning_name = name;
+    m_largest_poisoned_memory = 0;
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    s_poisoning = nullptr;
+    vmaDestroyAllocator(dirty);
+  }
+
+  static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory(
+      VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks,
+      VkDeviceMemory *memory) {
+    const auto result =
+        VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory);
+    for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr;
+         next = next->pNext) {
+      if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) {
+        const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next);
+        if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) {
+          return result;
+        }
+      }
+    }
+    if (result == VK_SUCCESS && s_poisoning != nullptr) {
+      s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize);
+    }
+    return result;
+  }
+
+  void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) {
+    const char *name = s_poisoning_name;
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -u
rg -n -F -e 'PoisonDeviceMemory' -e 'pfnAllocate' -e 'preferredLargeHeapBlockSize' -e 'preferredBlockSize' -e 'VmaAllocatorCreateInfo' -e 'maxBufferSize' -- tests/ src/ || test "$?" -eq 1
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --view expanded | head -n 200
sed -n '5480,5540p' tests/ShaderRecompilerComputeTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 15622


🏁 Script executed:

# Check BufferCache::BDA_PAGETABLE_SIZE and related constants
rg -n -A2 'BDA_PAGETABLE_SIZE|FAULT_BUFFER_SIZE' -- src/ tests/ | head -30

# Get the full context of PoisonDeviceMemory and the allocation failure path
sed -n '5490,5550p' tests/ShaderRecompilerComputeTests.cpp

# Check if there's any maxBufferSize handling elsewhere in the codebase
rg -n 'maxBufferSize|maxMemoryAllocationSize' -- src/ tests/ || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 5359


🏁 Script executed:

# Find CACHING_NUMPAGES definition
rg -n 'CACHING_NUMPAGES' -- src/graphics/host_gpu/renderer/cache/ | head -20

# Calculate the size: need to understand the actual value
rg -n -B2 -A2 'constexpr.*CACHING_NUMPAGES' -- src/graphics/host_gpu/renderer/cache/bufferCache.h

Repository: KytyPS5/KytyPS5

Length of output: 1395


🏁 Script executed:

# Find LOWER_ADDRESS_SIZE and kExtendedMemorySize definitions
rg -n 'LOWER_ADDRESS_SIZE|kExtendedMemorySize' -- src/graphics/host_gpu/renderer/cache/bufferCache.h

# Also need these to compute actual sizes
rg -n -B1 -A1 'LOWER_ADDRESS_SIZE\s*=' -- src/

# Get a full picture of buffer.h context
sed -n '1,50p' src/graphics/host_gpu/renderer/cache/bufferCache.h

Repository: KytyPS5/KytyPS5

Length of output: 2856


🏁 Script executed:

# Find kExtendedMemorySize definition
rg -n 'kExtendedMemorySize\s*=' -- src/

# Calculate actual sizes via a small Python script
python3 <<'EOF'
# Constants from regionDefinitions.h
LOWER_ADDRESS_SIZE = 1 << 40  # 1 TiB
CACHING_PAGEBITS = 14
CACHING_PAGESIZE = 1 << CACHING_PAGEBITS  # 16 KiB

# We need kExtendedMemorySize - let's search for it
print(f"LOWER_ADDRESS_SIZE = {LOWER_ADDRESS_SIZE:,} bytes = {LOWER_ADDRESS_SIZE / (1024**3):.2f} GiB")
print(f"CACHING_PAGESIZE = {CACHING_PAGESIZE:,} bytes = {CACHING_PAGESIZE / 1024:.1f} KiB")
EOF

Repository: KytyPS5/KytyPS5

Length of output: 354


🏁 Script executed:

# Calculate exact sizes
python3 <<'EOF'
LOWER_ADDRESS_SIZE = 1 << 40  # 1 TiB
kExtendedMemorySize = 512 * 1024 * 1024 * 1024  # 512 GiB
CACHING_PAGEBITS = 14

CACHING_NUMPAGES = (LOWER_ADDRESS_SIZE + kExtendedMemorySize) >> CACHING_PAGEBITS
BDA_PAGETABLE_SIZE = CACHING_NUMPAGES * 8
FAULT_BITMAP_WORDS = CACHING_NUMPAGES // 32
FAULT_SUMMARY_SPAN = 64
FAULT_SUMMARY_WORDS = FAULT_BITMAP_WORDS // FAULT_SUMMARY_SPAN // 32
FAULT_BUFFER_SIZE = (FAULT_BITMAP_WORDS + FAULT_SUMMARY_WORDS) * 4

print(f"CACHING_NUMPAGES = {CACHING_NUMPAGES:,}")
print(f"BDA_PAGETABLE_SIZE = {BDA_PAGETABLE_SIZE:,} bytes = {BDA_PAGETABLE_SIZE / (1024**2):.1f} MiB")
print(f"2 * BDA_PAGETABLE_SIZE = {2 * BDA_PAGETABLE_SIZE:,} bytes = {2 * BDA_PAGETABLE_SIZE / (1024**3):.2f} GiB")
print(f"FAULT_BUFFER_SIZE = {FAULT_BUFFER_SIZE:,} bytes = {FAULT_BUFFER_SIZE / (1024**2):.1f} MiB")
print(f"\nPreferred block size (2 * BDA_PAGETABLE_SIZE) exceeds 1 GiB device maxBufferSize: {2 * BDA_PAGETABLE_SIZE > (1024**3)}")
EOF

# Check the Buffer::Fill overload mentioned in PR summary
rg -n 'Buffer::Fill|class Buffer' -- src/graphics/host_gpu/renderer/ | head -30

Repository: KytyPS5/KytyPS5

Length of output: 1326


🏁 Script executed:

# Check the Buffer::Fill overloads
sed -n '197,215p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp

# Check the full streamBuffer.h definition
rg -n -A5 'class Buffer' -- src/graphics/host_gpu/renderer/cache/streamBuffer.h | head -60

# Look for any chunked fill patterns in the codebase
rg -n 'for.*fillBuffer|while.*fillBuffer|chunked' -- src/graphics/host_gpu/renderer/cache/ || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 1377


Chunk the temporary buffer to fit the device's maximum buffer size.

PoisonDeviceMemory creates a single buffer with the full allocation size at line 5514. The harness sets VMA's preferredLargeHeapBlockSize to 2 * BufferCache::BDA_PAGETABLE_SIZE (line 5476), which equals 1.50 GiB. On a device with a maxBufferSize of 1 GiB, this exceeds the limit and causes vkCreateBuffer to fail, aborting the test with RequireVk.

Fill the allocation in chunks that do not exceed the device's maximum buffer size. Query VkPhysicalDeviceMaintenance4Properties::maxBufferSize (or use a safe fallback such as 1 GiB) and issue multiple fillBuffer commands across aligned chunks.

🐛 Suggested approach

Modify PoisonDeviceMemory to:

  1. Retrieve the device's maxBufferSize limit.
  2. For each chunk up to that size, create a temporary buffer and call fillBuffer.
  3. Destroy each buffer after use.

Alternatively, create a single buffer up to maxBufferSize and issue multiple fillBuffer commands on overlapping or sequential ranges to cover the full allocation.

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-13 22:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4264754415) · edited 2026-10-13 23:06 UTC On `tests/ShaderRecompilerComputeTests.cpp` line 5514 (outdated): ```diff @@ -5454,6 +5456,247 @@ 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. + // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is, + // so blocks are made large enough to hold the page table. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + functions.vkAllocateMemory = &AllocatePoisonedMemory; + 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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + s_poisoning = this; + s_poisoning_name = name; + m_largest_poisoned_memory = 0; + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + s_poisoning = nullptr; + vmaDestroyAllocator(dirty); + } + + static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory( + VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks, + VkDeviceMemory *memory) { + const auto result = + VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory); + for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr; + next = next->pNext) { + if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) { + const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next); + if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) { + return result; + } + } + } + if (result == VK_SUCCESS && s_poisoning != nullptr) { + s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize); + } + return result; + } + + void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) { + const char *name = s_poisoning_name; + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -u rg -n -F -e 'PoisonDeviceMemory' -e 'pfnAllocate' -e 'preferredLargeHeapBlockSize' -e 'preferredBlockSize' -e 'VmaAllocatorCreateInfo' -e 'maxBufferSize' -- tests/ src/ || test "$?" -eq 1 ast-grep outline tests/ShaderRecompilerComputeTests.cpp --view expanded | head -n 200 sed -n '5480,5540p' tests/ShaderRecompilerComputeTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 15622 --- 🏁 Script executed: ```bash # Check BufferCache::BDA_PAGETABLE_SIZE and related constants rg -n -A2 'BDA_PAGETABLE_SIZE|FAULT_BUFFER_SIZE' -- src/ tests/ | head -30 # Get the full context of PoisonDeviceMemory and the allocation failure path sed -n '5490,5550p' tests/ShaderRecompilerComputeTests.cpp # Check if there's any maxBufferSize handling elsewhere in the codebase rg -n 'maxBufferSize|maxMemoryAllocationSize' -- src/ tests/ || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 5359 --- 🏁 Script executed: ```bash # Find CACHING_NUMPAGES definition rg -n 'CACHING_NUMPAGES' -- src/graphics/host_gpu/renderer/cache/ | head -20 # Calculate the size: need to understand the actual value rg -n -B2 -A2 'constexpr.*CACHING_NUMPAGES' -- src/graphics/host_gpu/renderer/cache/bufferCache.h ``` Repository: KytyPS5/KytyPS5 Length of output: 1395 --- 🏁 Script executed: ```bash # Find LOWER_ADDRESS_SIZE and kExtendedMemorySize definitions rg -n 'LOWER_ADDRESS_SIZE|kExtendedMemorySize' -- src/graphics/host_gpu/renderer/cache/bufferCache.h # Also need these to compute actual sizes rg -n -B1 -A1 'LOWER_ADDRESS_SIZE\s*=' -- src/ # Get a full picture of buffer.h context sed -n '1,50p' src/graphics/host_gpu/renderer/cache/bufferCache.h ``` Repository: KytyPS5/KytyPS5 Length of output: 2856 --- 🏁 Script executed: ```bash # Find kExtendedMemorySize definition rg -n 'kExtendedMemorySize\s*=' -- src/ # Calculate actual sizes via a small Python script python3 <<'EOF' # Constants from regionDefinitions.h LOWER_ADDRESS_SIZE = 1 << 40 # 1 TiB CACHING_PAGEBITS = 14 CACHING_PAGESIZE = 1 << CACHING_PAGEBITS # 16 KiB # We need kExtendedMemorySize - let's search for it print(f"LOWER_ADDRESS_SIZE = {LOWER_ADDRESS_SIZE:,} bytes = {LOWER_ADDRESS_SIZE / (1024**3):.2f} GiB") print(f"CACHING_PAGESIZE = {CACHING_PAGESIZE:,} bytes = {CACHING_PAGESIZE / 1024:.1f} KiB") EOF ``` Repository: KytyPS5/KytyPS5 Length of output: 354 --- 🏁 Script executed: ```bash # Calculate exact sizes python3 <<'EOF' LOWER_ADDRESS_SIZE = 1 << 40 # 1 TiB kExtendedMemorySize = 512 * 1024 * 1024 * 1024 # 512 GiB CACHING_PAGEBITS = 14 CACHING_NUMPAGES = (LOWER_ADDRESS_SIZE + kExtendedMemorySize) >> CACHING_PAGEBITS BDA_PAGETABLE_SIZE = CACHING_NUMPAGES * 8 FAULT_BITMAP_WORDS = CACHING_NUMPAGES // 32 FAULT_SUMMARY_SPAN = 64 FAULT_SUMMARY_WORDS = FAULT_BITMAP_WORDS // FAULT_SUMMARY_SPAN // 32 FAULT_BUFFER_SIZE = (FAULT_BITMAP_WORDS + FAULT_SUMMARY_WORDS) * 4 print(f"CACHING_NUMPAGES = {CACHING_NUMPAGES:,}") print(f"BDA_PAGETABLE_SIZE = {BDA_PAGETABLE_SIZE:,} bytes = {BDA_PAGETABLE_SIZE / (1024**2):.1f} MiB") print(f"2 * BDA_PAGETABLE_SIZE = {2 * BDA_PAGETABLE_SIZE:,} bytes = {2 * BDA_PAGETABLE_SIZE / (1024**3):.2f} GiB") print(f"FAULT_BUFFER_SIZE = {FAULT_BUFFER_SIZE:,} bytes = {FAULT_BUFFER_SIZE / (1024**2):.1f} MiB") print(f"\nPreferred block size (2 * BDA_PAGETABLE_SIZE) exceeds 1 GiB device maxBufferSize: {2 * BDA_PAGETABLE_SIZE > (1024**3)}") EOF # Check the Buffer::Fill overload mentioned in PR summary rg -n 'Buffer::Fill|class Buffer' -- src/graphics/host_gpu/renderer/ | head -30 ``` Repository: KytyPS5/KytyPS5 Length of output: 1326 --- 🏁 Script executed: ```bash # Check the Buffer::Fill overloads sed -n '197,215p' src/graphics/host_gpu/renderer/cache/streamBuffer.cpp # Check the full streamBuffer.h definition rg -n -A5 'class Buffer' -- src/graphics/host_gpu/renderer/cache/streamBuffer.h | head -60 # Look for any chunked fill patterns in the codebase rg -n 'for.*fillBuffer|while.*fillBuffer|chunked' -- src/graphics/host_gpu/renderer/cache/ || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 1377 --- </details> **Chunk the temporary buffer to fit the device's maximum buffer size.** `PoisonDeviceMemory` creates a single buffer with the full allocation size at line 5514. The harness sets VMA's `preferredLargeHeapBlockSize` to `2 * BufferCache::BDA_PAGETABLE_SIZE` (line 5476), which equals 1.50 GiB. On a device with a `maxBufferSize` of 1 GiB, this exceeds the limit and causes `vkCreateBuffer` to fail, aborting the test with `RequireVk`. Fill the allocation in chunks that do not exceed the device's maximum buffer size. Query `VkPhysicalDeviceMaintenance4Properties::maxBufferSize` (or use a safe fallback such as 1 GiB) and issue multiple `fillBuffer` commands across aligned chunks. <details> <summary>🐛 Suggested approach</summary> Modify `PoisonDeviceMemory` to: 1. Retrieve the device's `maxBufferSize` limit. 2. For each chunk up to that size, create a temporary buffer and call `fillBuffer`. 3. Destroy each buffer after use. Alternatively, create a single buffer up to `maxBufferSize` and issue multiple `fillBuffer` commands on overlapping or sequential ranges to cover the full allocation. </details> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:aeeebe1fa1bdda07c5413dcf --> <!-- 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-13 22:31 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: 173fe7de-9372-4e81-9b38-be3130a9fed6
📥 Commits

Reviewing files that changed from the base of the PR and between 6a8e69b982e44b2cecf31df28de3cb0cc28c14e4 and c53f8fcc8102dd05f2c49da376a74efff6f112d9.

📒 Files selected for processing: 2
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • tests/ShaderRecompilerComputeTests.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-13 22:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#pullrequestreview-5510840850) · **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**: `173fe7de-9372-4e81-9b38-be3130a9fed6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 6a8e69b982e44b2cecf31df28de3cb0cc28c14e4 and c53f8fcc8102dd05f2c49da376a74efff6f112d9. </details> <details> <summary>📒 Files selected for processing: 2</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `tests/ShaderRecompilerComputeTests.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=19d24886-88ec-4f08-9c8a-820422f75f27 attempt=f8b2679c-9c07-4598-962c-b36756d732c4 batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-13 23:06 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 5514 (outdated):

@@ -5454,6 +5456,247 @@ 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.
+  // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is,
+  // so blocks are made large enough to hold the page table.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    functions.vkAllocateMemory = &AllocatePoisonedMemory;
+    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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    s_poisoning = this;
+    s_poisoning_name = name;
+    m_largest_poisoned_memory = 0;
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    s_poisoning = nullptr;
+    vmaDestroyAllocator(dirty);
+  }
+
+  static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory(
+      VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks,
+      VkDeviceMemory *memory) {
+    const auto result =
+        VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory);
+    for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr;
+         next = next->pNext) {
+      if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) {
+        const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next);
+        if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) {
+          return result;
+        }
+      }
+    }
+    if (result == VK_SUCCESS && s_poisoning != nullptr) {
+      s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize);
+    }
+    return result;
+  }
+
+  void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) {
+    const char *name = s_poisoning_name;
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};

Fixed in d3b2d3d16: the block is now filled through buffers bound at successive offsets, each at most maxBufferSize (Maintenance4). Checked with a forced 64 MiB chunk: the page table poisoning still catches a missing clear.

**@⁠NeySlim** on GitHub · 2026-10-13 23:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4264992456) On `tests/ShaderRecompilerComputeTests.cpp` line 5514 (outdated): ```diff @@ -5454,6 +5456,247 @@ 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. + // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is, + // so blocks are made large enough to hold the page table. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + functions.vkAllocateMemory = &AllocatePoisonedMemory; + 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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + s_poisoning = this; + s_poisoning_name = name; + m_largest_poisoned_memory = 0; + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + s_poisoning = nullptr; + vmaDestroyAllocator(dirty); + } + + static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory( + VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks, + VkDeviceMemory *memory) { + const auto result = + VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory); + for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr; + next = next->pNext) { + if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) { + const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next); + if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) { + return result; + } + } + } + if (result == VK_SUCCESS && s_poisoning != nullptr) { + s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize); + } + return result; + } + + void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) { + const char *name = s_poisoning_name; + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; ``` Fixed in d3b2d3d16: the block is now filled through buffers bound at successive offsets, each at most maxBufferSize (Maintenance4). Checked with a forced 64 MiB chunk: the page table poisoning still catches a missing clear.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-13 23:06 UTC · original
On tests/ShaderRecompilerComputeTests.cpp line 5514 (outdated):

@@ -5454,6 +5456,247 @@ 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.
+  // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is,
+  // so blocks are made large enough to hold the page table.
+  template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) {
+    EnsureRuntimeContext();
+    VmaVulkanFunctions functions{};
+    functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr;
+    functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr;
+    functions.vkAllocateMemory = &AllocatePoisonedMemory;
+    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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE;
+    VmaAllocator dirty = nullptr;
+    RequireVk(name, "dirty allocator",
+              static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)),
+              "vmaCreateAllocator");
+    s_poisoning = this;
+    s_poisoning_name = name;
+    m_largest_poisoned_memory = 0;
+    auto *const original = std::exchange(m_runtime_context.allocator, dirty);
+    body();
+    m_runtime_context.allocator = original;
+    s_poisoning = nullptr;
+    vmaDestroyAllocator(dirty);
+  }
+
+  static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory(
+      VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks,
+      VkDeviceMemory *memory) {
+    const auto result =
+        VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory);
+    for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr;
+         next = next->pNext) {
+      if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) {
+        const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next);
+        if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) {
+          return result;
+        }
+      }
+    }
+    if (result == VK_SUCCESS && s_poisoning != nullptr) {
+      s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize);
+    }
+    return result;
+  }
+
+  void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) {
+    const char *name = s_poisoning_name;
+    vk::BufferCreateInfo buffer_info{};
+    buffer_info.size = size & ~vk::DeviceSize{3};

@NeySlim Thanks for the fix in d3b2d3d16. Buffers bound at successive offsets, each limited to maxBufferSize, address the size-limit concern. Your forced 64 MiB chunk check also confirms that poisoning still detects a missing page-table clear.


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-13 23:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1294#discussion_r4264996608) On `tests/ShaderRecompilerComputeTests.cpp` line 5514 (outdated): ```diff @@ -5454,6 +5456,247 @@ 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. + // Memory dedicated to one resource cannot be bound to the poisoning buffer and stays as is, + // so blocks are made large enough to hold the page table. + template <typename Body> void WithDirtyDeviceMemory(const char *name, Body &&body) { + EnsureRuntimeContext(); + VmaVulkanFunctions functions{}; + functions.vkGetInstanceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr; + functions.vkGetDeviceProcAddr = VULKAN_HPP_DEFAULT_DISPATCHER.vkGetDeviceProcAddr; + functions.vkAllocateMemory = &AllocatePoisonedMemory; + 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.preferredLargeHeapBlockSize = 2 * BufferCache::BDA_PAGETABLE_SIZE; + VmaAllocator dirty = nullptr; + RequireVk(name, "dirty allocator", + static_cast<vk::Result>(vmaCreateAllocator(&allocator_info, &dirty)), + "vmaCreateAllocator"); + s_poisoning = this; + s_poisoning_name = name; + m_largest_poisoned_memory = 0; + auto *const original = std::exchange(m_runtime_context.allocator, dirty); + body(); + m_runtime_context.allocator = original; + s_poisoning = nullptr; + vmaDestroyAllocator(dirty); + } + + static VKAPI_ATTR VkResult VKAPI_CALL AllocatePoisonedMemory( + VkDevice device, const VkMemoryAllocateInfo *info, const VkAllocationCallbacks *callbacks, + VkDeviceMemory *memory) { + const auto result = + VULKAN_HPP_DEFAULT_DISPATCHER.vkAllocateMemory(device, info, callbacks, memory); + for (auto *next = static_cast<const VkBaseInStructure *>(info->pNext); next != nullptr; + next = next->pNext) { + if (next->sType == VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO) { + const auto *dedicated = reinterpret_cast<const VkMemoryDedicatedAllocateInfo *>(next); + if (dedicated->buffer != VK_NULL_HANDLE || dedicated->image != VK_NULL_HANDLE) { + return result; + } + } + } + if (result == VK_SUCCESS && s_poisoning != nullptr) { + s_poisoning->PoisonDeviceMemory(info->memoryTypeIndex, *memory, info->allocationSize); + } + return result; + } + + void PoisonDeviceMemory(uint32_t type, vk::DeviceMemory memory, vk::DeviceSize size) { + const char *name = s_poisoning_name; + vk::BufferCreateInfo buffer_info{}; + buffer_info.size = size & ~vk::DeviceSize{3}; ``` `@NeySlim` Thanks for the fix in `d3b2d3d16`. Buffers bound at successive offsets, each limited to `maxBufferSize`, address the size-limit concern. Your forced 64 MiB chunk check also confirms that poisoning still detects a missing page-table clear. --- <!-- 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=Chunking%20%60PoisonDeviceMemory%60%20buffers%20to%20Vulkan%E2%80%99s%20%60maxBufferSize%60%20prevents%20%60vkCreateBuffer%60%20failures%20on%201%20GiB-limited%20devices%20while%20preserving%20the%20poisoning%20check.%20Try%20%40coderabbitai%20for%20sharp%2C%20actionable%20reviews!%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1294%23discussion_r4264754415)? 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 -->
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/shaders/fault_buffer_process.comp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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