graphics: cache the memory at DMA base addresses before the shader runs #925

Closed
github-bot wants to merge 1 commit from gh-pr/925/head into gh-pr/925/base
Owner

@⁠TheCruZ on GitHub · 2026-09-29 21:11 UTC · original
pr/dma-base-cache → main · +208 −1 · 7 files · 1 commits · closed without merging

Summary

Fixes missing characters in the boot legal notice of Grand Theft Auto V (PPSA04263). Only scattered letters of the text are drawn.

Problem

The text pixel shader (ps e26a052be0fc3e49) samples a 2048x4096 R8 glyph atlas. A compute shader (cs e9e4f0b919d80844) fills that atlas one glyph per dispatch, copying the bitmap the CPU rasterized into a staging ring with FLAT_LOAD_UBYTE from s[12:13] + lane offset.

DMA only reaches memory that already has a cached buffer. Any other access records a fault and reads zero, and the buffer is created only after the dispatch has run.
So the first glyphs copied from each 16 KiB staging page were stored blank, and since each glyph is uploaded once, they stayed blank.

Change

This change makes resource tracking record the user-data register pairs that DMA addresses are offset from (the low dword derives from register N and the high dword from N + 1; only value operands are followed, not lane masks or loaded data).

Before a DMA draw or dispatch, the host caches the mapped memory in the 16 KiB (BufferCache::CACHING_PAGESIZE) starting at each such base, so the shader reads the guest's bytes on its first access. A false positive only costs a FindBuffer on mapped memory.

Before After
image image

Testing

  • Grand Theft Auto V (PPSA04263): the boot legal notice is drawn completely.
  • resource_tracking_tests passes, including the new TestDmaBaseRegisters case (checks that the registers of the lane offset are not reported as a base).
  • Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090.

AI usage

AI (Claude Opus 5.5) was used to investigate the issue (shader dumps and resource-tracking analysis) and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.

**@⁠TheCruZ** on GitHub · 2026-09-29 21:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925) `pr/dma-base-cache` → `main` · +208 −1 · 7 files · 1 commits · closed without merging ## Summary Fixes missing characters in the boot legal notice of Grand Theft Auto V (PPSA04263). Only scattered letters of the text are drawn. ## Problem The text pixel shader (`ps e26a052be0fc3e49`) samples a 2048x4096 R8 glyph atlas. A compute shader (`cs e9e4f0b919d80844`) fills that atlas one glyph per dispatch, copying the bitmap the CPU rasterized into a staging ring with `FLAT_LOAD_UBYTE` from `s[12:13]` + lane offset. DMA only reaches memory that already has a cached buffer. Any other access records a fault and reads zero, and the buffer is created only after the dispatch has run. So the first glyphs copied from each 16 KiB staging page were stored blank, and since each glyph is uploaded once, they stayed blank. ## Change This change makes resource tracking record the user-data register pairs that DMA addresses are offset from (the low dword derives from register N and the high dword from N + 1; only value operands are followed, not lane masks or loaded data). Before a DMA draw or dispatch, the host caches the mapped memory in the 16 KiB (`BufferCache::CACHING_PAGESIZE`) starting at each such base, so the shader reads the guest's bytes on its first access. A false positive only costs a `FindBuffer` on mapped memory. | **Before** | **After** | :-------------------------:|:-------------------------: <img width="1286" height="762" alt="image" src="https://github.com/user-attachments/assets/bd2e8df8-d778-4643-b8c4-023839f1afa0" /> | <img width="1284" height="762" alt="image" src="https://github.com/user-attachments/assets/fb652b20-673f-415b-b094-66e19c9d37ee" /> ## Testing - Grand Theft Auto V (PPSA04263): the boot legal notice is drawn completely. - `resource_tracking_tests` passes, including the new `TestDmaBaseRegisters` case (checks that the registers of the lane offset are not reported as a base). - Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090. ## AI usage AI (Claude Opus 5.5) was used to investigate the issue (shader dumps and resource-tracking analysis) and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my [GTA V fork](https://github.com/TheCruZ/KytyPS5-GTA), i will be bringing PRs here after test them enough.
GTA V (PPSA04263) draws only scattered characters of its boot legal
notice. Its text shader (ps e26a052be0fc3e49) samples a 2048x4096 R8 glyph
atlas that a compute shader (cs e9e4f0b919d80844) fills one glyph per
dispatch, copying the bitmap the CPU rasterized into a staging ring with
FLAT_LOAD_UBYTE from s[12:13] + lane offset. DMA reaches only memory that
has a cached buffer; any other access records a fault and reads zero, and
the fault creates the buffer only after the dispatch has run. The first
glyphs copied from each 16 KB staging page were therefore stored blank,
and as each glyph is uploaded once, they stayed blank.

Resource tracking now records the user-data register pairs that DMA
addresses offset from: the low dword derives from register N and the high
dword from N + 1 (walking value operands, not lane masks or loaded data;
a constant-index extract of a composite constructor follows only the
selected operand).
Before a DMA draw or dispatch, the host caches the mapped memory in the
16 KiB (BufferCache::CACHING_PAGESIZE) that starts at each such base, so
the shader reads the guest's bytes on its first access. The registers
of an access that never runs may hold stale data, so a base whose window
would overflow the address space is skipped.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:37:00 +00:00
github-bot closed this pull request 2026-11-26 09:37:00 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-29 21:15 UTC · original · edited 2026-10-05 23:02 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.

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2825a8be-53b1-4c1c-8b85-b0d09a49ece8
📥 Commits

Reviewing files that changed from the base of the PR and between 0e5cc69b4700a037b777b2ce4177f6a124aec4dc and bcccd431ba6df20d27bb794be924b742139a1f7d.

📒 Files selected for processing (6)
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.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.


📝 Walkthrough

Walkthrough

Resource tracking traces address operands and records DMA base register pairs in ShaderInfo. Graphics binding preparation and direct and indirect compute dispatch use this metadata to cache mapped address ranges. Tests check the recorded registers for FLAT and GLOBAL address operations, including composite addresses and a 256-instruction traversal boundary.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🟡 Moderate · up to bcccd

This change fixes missing text in the GTA V legal notice by preparing memory that compute shaders read through DMA. One earlier concern remains unresolved: an unusual base address near the top of the address space could still stop rendering. Confirm that case before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to bcccd

The change prepares mapped guest memory earlier and retains existing address checks. No introduced security vulnerability was established, but memory-boundary alignment and concurrent invalidation remain incompletely verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Guest shader expressions and runtime register contents influence eager cache discovery within the rendering process. Each accepted pair directly probes a 16 KiB window intersected with mapped ranges; subsequent alignment, overlap merging and existing stream-growth reservation can produce a larger registered buffer.

Trust Boundaries and Controls

  • observed — The new preparation step skips invalid register pairs and overflowing address windows, holds the mapped-range shared lock, and passes only mapped intersections to FindBuffer. Flexible, fixed direct and runtime allocation paths provide 16 KiB alignment counterevidence, although partial-unmap behavior prevents treating all mapped intersections as conclusively page-aligned.
  • observed — The existing BDA translation path remains the shader-access mechanism: absent page-table entries record a fault and return a zero pointer. Buffer alignment and stream-growth widening predate this PR; their presence alone is not evidence that this PR introduced a boundary bypass.

Resilience and Maintainability Implications

  • observed — Repeated discovery reuses an existing in-bounds cache owner; overlaps use the existing merge and deferred-deletion lifecycle. Unmap routes through synchronous GPU commands and waits active work before subtracting mappings, while garbage collection waits dirty-buffer downloads before releasing ownership. These controls support lifecycle compatibility, but concurrent invalidation and partial-failure coverage remain incomplete.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: caching memory at DMA base addresses before shader execution.
Description check ✅ Passed The description explains the GTA V issue, the DMA base-address caching change, and the reported tests. It is directly related to the changeset.
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.

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-09-29 21:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-5899053934) · edited 2026-10-05 23:02 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/925?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></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. > > 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 --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `2825a8be-53b1-4c1c-8b85-b0d09a49ece8` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 0e5cc69b4700a037b777b2ce4177f6a124aec4dc and bcccd431ba6df20d27bb794be924b742139a1f7d. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.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> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Resource tracking traces address operands and records DMA base register pairs in `ShaderInfo`. Graphics binding preparation and direct and indirect compute dispatch use this metadata to cache mapped address ranges. Tests check the recorded registers for FLAT and GLOBAL address operations, including composite addresses and a 256-instruction traversal boundary. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"bcccd431ba6df20d27bb794be924b742139a1f7d" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `bcccd` <!-- final_review_risk_coverage:{"sourceCommitId":"bcccd431ba6df20d27bb794be924b742139a1f7d","coveredCommitId":"bcccd431ba6df20d27bb794be924b742139a1f7d","kind":"reviewed"} --> This change fixes missing text in the GTA V legal notice by preparing memory that compute shaders read through DMA. One earlier concern remains unresolved: an unusual base address near the top of the address space could still stop rendering. Confirm that case before merging. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `bcccd` The change prepares mapped guest memory earlier and retains existing address checks. No introduced security vulnerability was established, but memory-boundary alignment and concurrent invalidation remain incompletely verified. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — Guest shader expressions and runtime register contents influence eager cache discovery within the rendering process. Each accepted pair directly probes a 16 KiB window intersected with mapped ranges; subsequent alignment, overlap merging and existing stream-growth reservation can produce a larger registered buffer. **Trust Boundaries and Controls** - _observed_ — The new preparation step skips invalid register pairs and overflowing address windows, holds the mapped-range shared lock, and passes only mapped intersections to FindBuffer. Flexible, fixed direct and runtime allocation paths provide 16 KiB alignment counterevidence, although partial-unmap behavior prevents treating all mapped intersections as conclusively page-aligned. - _observed_ — The existing BDA translation path remains the shader-access mechanism: absent page-table entries record a fault and return a zero pointer. Buffer alignment and stream-growth widening predate this PR; their presence alone is not evidence that this PR introduced a boundary bypass. **Resilience and Maintainability Implications** - _observed_ — Repeated discovery reuses an existing in-bounds cache owner; overlaps use the existing merge and deferred-deletion lifecycle. Unmap routes through synchronous GPU commands and waits active work before subtracting mappings, while garbage collection waits dirty-buffer downloads before releasing ownership. These controls support lifecycle compatibility, but concurrent invalidation and partial-failure coverage remain incomplete. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 7 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly summarizes the main change: caching memory at DMA base addresses before shader execution. | | Description check | ✅ Passed | The description explains the GTA V issue, the DMA base-address caching change, and the reported tests. It is directly related to the changeset. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=925)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -126,0 +141,4 @@
// DMA reaches only memory with a cached buffer; any other access records a fault and
// reads zero, and the buffer arrives after the shader has run. That loses data the guest
// writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas.
m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE,
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-29 21:15 UTC · original · edited 2026-10-08 20:53 UTC

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,130p' src/graphics/host_gpu/rangeSet.h
sed -n '110,150p' src/graphics/host_gpu/renderer/renderContext.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4753


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- changed paths/stat ---'
git diff --stat 05057c9441dbf3972d49f9143b90213a43a01a00 0873b6ce4c52f86535df354461060c6b886b2c09 -- src/graphics/host_gpu
printf '%s\n' '--- CacheDmaBases and related symbols ---'
rg -n -C 5 'CacheDmaBases|dma_base_registers|user_data_base|struct ShaderStageRuntime|class ShaderStageRuntime|user_data' src/graphics/host_gpu/renderer src/graphics/host_gpu | head -n 500
printf '%s\n' '--- register/access masking terms ---'
rg -n -C 4 'masked|mask|dma.*base|base.*dma|user.?data|user_data' src/graphics/host_gpu | head -n 700
printf '%s\n' '--- exact PR diff for relevant files ---'
git diff --unified=30 05057c9441dbf3972d49f9143b90213a43a01a00 0873b6ce4c52f86535df354461060c6b886b2c09 -- src/graphics/host_gpu/renderer/renderContext.cpp src/graphics/host_gpu/rangeSet.h | sed -n '1,500p'

Repository: KytyPS5/KytyPS5

Length of output: 41493


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact dma_base_registers declarations and assignments ---'
rg -n -C 12 'dma_base_registers' .
printf '%s\n' '--- ShaderStageRuntime and resource construction ---'
rg -n -C 15 'struct ShaderStageRuntime|ShaderStageRuntime[[:space:]]*[({]|resources[[:space:]]*=|user_data[[:space:]]*=' src | head -n 1000
printf '%s\n' '--- DMA and address-use analysis ---'
rg -n -C 8 'uses_dma|Dma|DMA|dma' src/graphics/shader src/graphics/host_gpu | head -n 1200
printf '%s\n' '--- user-data snapshot/population paths ---'
rg -n -C 12 'user_data' src/graphics/host_gpu/renderer | head -n 1200

Repository: KytyPS5/KytyPS5

Length of output: 42504


Reject overflowing DMA base ranges before querying mappings.

RangeSet::ForEachInRange computes its endpoint before it checks mapped ranges. A base near UINT64_MAX can therefore call RangeSet::End and terminate the draw or dispatch.

CacheDmaBases processes every statically collected DMA base without an access-mask check. If an inactive access leaves stale user-data words, those words can form an overflowing base.

Validate the endpoint before calling ForEachInRange. Clamp the interval and skip a zero-length result.

Suggested fix
 		const auto base = user_data[index] | (static_cast<uint64_t>(user_data[index + 1u]) << 32u);
+		const auto size = std::min<uint64_t>(BufferCache::CACHING_PAGESIZE, UINT64_MAX - base);
+		if (size == 0) {
+			continue;
+		}
 		// DMA reaches only memory with a cached buffer; any other access records a fault and
 		// reads zero, and the buffer arrives after the shader has run. That loses data the guest
 		// writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas.
-		m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE,
+		m_mapped_ranges.ForEachInRange(base, size,

✅ Confirmed as addressed by @⁠TheCruZ

**@⁠coderabbitai[bot]** on GitHub · 2026-09-29 21:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4138405493) · edited 2026-10-08 20:53 UTC _🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '1,130p' src/graphics/host_gpu/rangeSet.h sed -n '110,150p' src/graphics/host_gpu/renderer/renderContext.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4753 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- changed paths/stat ---' git diff --stat 05057c9441dbf3972d49f9143b90213a43a01a00 0873b6ce4c52f86535df354461060c6b886b2c09 -- src/graphics/host_gpu printf '%s\n' '--- CacheDmaBases and related symbols ---' rg -n -C 5 'CacheDmaBases|dma_base_registers|user_data_base|struct ShaderStageRuntime|class ShaderStageRuntime|user_data' src/graphics/host_gpu/renderer src/graphics/host_gpu | head -n 500 printf '%s\n' '--- register/access masking terms ---' rg -n -C 4 'masked|mask|dma.*base|base.*dma|user.?data|user_data' src/graphics/host_gpu | head -n 700 printf '%s\n' '--- exact PR diff for relevant files ---' git diff --unified=30 05057c9441dbf3972d49f9143b90213a43a01a00 0873b6ce4c52f86535df354461060c6b886b2c09 -- src/graphics/host_gpu/renderer/renderContext.cpp src/graphics/host_gpu/rangeSet.h | sed -n '1,500p' ``` Repository: KytyPS5/KytyPS5 Length of output: 41493 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- exact dma_base_registers declarations and assignments ---' rg -n -C 12 'dma_base_registers' . printf '%s\n' '--- ShaderStageRuntime and resource construction ---' rg -n -C 15 'struct ShaderStageRuntime|ShaderStageRuntime[[:space:]]*[({]|resources[[:space:]]*=|user_data[[:space:]]*=' src | head -n 1000 printf '%s\n' '--- DMA and address-use analysis ---' rg -n -C 8 'uses_dma|Dma|DMA|dma' src/graphics/shader src/graphics/host_gpu | head -n 1200 printf '%s\n' '--- user-data snapshot/population paths ---' rg -n -C 12 'user_data' src/graphics/host_gpu/renderer | head -n 1200 ``` Repository: KytyPS5/KytyPS5 Length of output: 42504 --- </details> **Reject overflowing DMA base ranges before querying mappings.** `RangeSet::ForEachInRange` computes its endpoint before it checks mapped ranges. A base near `UINT64_MAX` can therefore call `RangeSet::End` and terminate the draw or dispatch. `CacheDmaBases` processes every statically collected DMA base without an access-mask check. If an inactive access leaves stale user-data words, those words can form an overflowing base. Validate the endpoint before calling `ForEachInRange`. Clamp the interval and skip a zero-length result. <details> <summary>Suggested fix</summary> ```diff const auto base = user_data[index] | (static_cast<uint64_t>(user_data[index + 1u]) << 32u); + const auto size = std::min<uint64_t>(BufferCache::CACHING_PAGESIZE, UINT64_MAX - base); + if (size == 0) { + continue; + } // DMA reaches only memory with a cached buffer; any other access records a fault and // reads zero, and the buffer arrives after the shader has run. That loses data the guest // writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas. - m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE, + m_mapped_ranges.ForEachInRange(base, size, ``` </details> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a6713d95b1f765a27a6d8c0e --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠TheCruZ <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-29 21:15 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: 48ceff8b-d509-4aed-9ee9-9abebb4bb9a9

📥 Commits

Reviewing files that changed from the base of the PR and between 05057c9441 and 0873b6ce4c52f86535df354461060c6b886b2c09.

📒 Files selected for processing (7)
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.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-09-29 21:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#pullrequestreview-5358568722) · **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**: `48ceff8b-d509-4aed-9ee9-9abebb4bb9a9` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 05057c9441dbf3972d49f9143b90213a43a01a00 and 0873b6ce4c52f86535df354461060c6b886b2c09. </details> <details> <summary>📒 Files selected for processing (7)</summary> * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.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 -->
@ -126,0 +141,4 @@
// DMA reaches only memory with a cached buffer; any other access records a fault and
// reads zero, and the buffer arrives after the shader has run. That loses data the guest
// writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas.
m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE,
Author
Owner

@⁠TheCruZ on GitHub · 2026-09-29 21:37 UTC · original

Well thats right, teorically possible.

**@⁠TheCruZ** on GitHub · 2026-09-29 21:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4138584514) Well thats right, teorically possible.
Author
Owner

@⁠Nmzik on GitHub · 2026-09-30 09:31 UTC · original

@⁠TheCruZ that’s the first good and clean fix. Thanks. All previous attempts/PRs from other guys were basically hacks 👍

Looks very legit, I’ll take a look

**@⁠Nmzik** on GitHub · 2026-09-30 09:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-5908362051) @⁠TheCruZ that’s the first good and clean fix. Thanks. All previous attempts/PRs from other guys were basically hacks 👍 Looks very legit, I’ll take a look
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-01 23:46 UTC · original · edited 2026-10-02 07:27 UTC
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 85 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Apply the visit limit to processed instructions, not queued instructions.

When adding an operand makes visited.size() equal 256, the next iteration stops before processing that operand or the remaining queue. A low-dword graph with exactly 256 instructions can therefore omit its terminal GetUserData, even though the graph fits the stated limit. CollectDmaBase then misses the base pair.

Limit processing with next &lt; MaxVisited. Bound operand insertion separately if the queue must also remain capped. Add a boundary case with the base source at the final permitted instruction.

✅ Confirmed as addressed by @⁠TheCruZ

**@⁠coderabbitai[bot]** on GitHub · 2026-10-01 23:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4161598342) · edited 2026-10-02 07:27 UTC On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 85 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { ``` _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ **Apply the visit limit to processed instructions, not queued instructions.** When adding an operand makes `visited.size()` equal 256, the next iteration stops before processing that operand or the remaining queue. A low-dword graph with exactly 256 instructions can therefore omit its terminal `GetUserData`, even though the graph fits the stated limit. `CollectDmaBase` then misses the base pair. Limit processing with `next &lt; MaxVisited`. Bound operand insertion separately if the queue must also remain capped. Add a boundary case with the base source at the final permitted instruction. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:00497fcbe58337f4f39a0c51 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠TheCruZ <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-01 23:46 UTC · original · edited 2026-10-02 07:26 UTC
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 100 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {
+		const auto* inst = visited[next];
+		const auto  op   = inst->GetOpcode();
+		if (op == ValueOpcode::GetUserData) {
+			if (inst->Arg(0).GetType() == Type::ScalarReg) {
+				registers.push_back(RegIndex(inst->Arg(0).ScalarRegister()));
+			}
+			continue;
+		}
+		if (BufferAccessOf(op) != BufferAccess::None ||
+		    AddressOpcodeInfoOf(op).access != AddressAccess::None ||
+		    ImageOpcodeInfoOf(op).access != ImageAccess::None) {
+			continue;
+		}
+		for (size_t i = 0; i < inst->NumArgs(); i++) {
+			const auto* arg = inst->Arg(i).Resolve().TryInstruction();

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve component provenance when tracing composite extracts.

For an address whose dwords extract components 0 and 1 from CompositeConstructU32x4(GetUserData(s12), GetUserData(s13), 0, 0), this walk follows every component of the composite. Both source sets become {12, 13}.

CollectDmaBase then rejects register 12 because register 13 appears in the low sources. The renderer does not cache this valid base, so an uncached DMA read still returns zero.

For a constant-index extract from a composite constructor, follow only the selected component. Add this address shape to TestDmaBaseRegisters.

✅ Confirmed as addressed by @⁠TheCruZ

**@⁠coderabbitai[bot]** on GitHub · 2026-10-01 23:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4161598345) · edited 2026-10-02 07:26 UTC On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 100 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { + const auto* inst = visited[next]; + const auto op = inst->GetOpcode(); + if (op == ValueOpcode::GetUserData) { + if (inst->Arg(0).GetType() == Type::ScalarReg) { + registers.push_back(RegIndex(inst->Arg(0).ScalarRegister())); + } + continue; + } + if (BufferAccessOf(op) != BufferAccess::None || + AddressOpcodeInfoOf(op).access != AddressAccess::None || + ImageOpcodeInfoOf(op).access != ImageAccess::None) { + continue; + } + for (size_t i = 0; i < inst->NumArgs(); i++) { + const auto* arg = inst->Arg(i).Resolve().TryInstruction(); ``` _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ **Preserve component provenance when tracing composite extracts.** For an address whose dwords extract components 0 and 1 from `CompositeConstructU32x4(GetUserData(s12), GetUserData(s13), 0, 0)`, this walk follows every component of the composite. Both source sets become `{12, 13}`. `CollectDmaBase` then rejects register 12 because register 13 appears in the low sources. The renderer does not cache this valid base, so an uncached DMA read still returns zero. For a constant-index extract from a composite constructor, follow only the selected component. Add this address shape to `TestDmaBaseRegisters`. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:230894c517c9b01a560257da --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠TheCruZ <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-01 23:46 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: e4fd6247-e682-434c-8d64-5b2346e04f1d

📥 Commits

Reviewing files that changed from the base of the PR and between 353653947b92880b1071de54954e1e948e9bacef and 1606bf8f91f20f8b0a406275ea9102f4fde3a962.

📒 Files selected for processing (6)
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.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-01 23:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#pullrequestreview-5386873663) · **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**: `e4fd6247-e682-434c-8d64-5b2346e04f1d` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 353653947b92880b1071de54954e1e948e9bacef and 1606bf8f91f20f8b0a406275ea9102f4fde3a962. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.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 -->
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-02 07:19 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 85 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {

Fixed in 0e5cc69: the walk now bounds the instructions it queues (and therefore processes) instead of stopping once the queue reaches the limit, so a graph of exactly 256 instructions is fully processed. TestDmaBaseRegisters covers a base register that is the 256th instruction of its chain (it fails with the previous loop).

**@⁠TheCruZ** on GitHub · 2026-10-02 07:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4163633432) On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 85 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { ``` Fixed in 0e5cc69: the walk now bounds the instructions it queues (and therefore processes) instead of stopping once the queue reaches the limit, so a graph of exactly 256 instructions is fully processed. `TestDmaBaseRegisters` covers a base register that is the 256th instruction of its chain (it fails with the previous loop).
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-02 07:19 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 100 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {
+		const auto* inst = visited[next];
+		const auto  op   = inst->GetOpcode();
+		if (op == ValueOpcode::GetUserData) {
+			if (inst->Arg(0).GetType() == Type::ScalarReg) {
+				registers.push_back(RegIndex(inst->Arg(0).ScalarRegister()));
+			}
+			continue;
+		}
+		if (BufferAccessOf(op) != BufferAccess::None ||
+		    AddressOpcodeInfoOf(op).access != AddressAccess::None ||
+		    ImageOpcodeInfoOf(op).access != ImageAccess::None) {
+			continue;
+		}
+		for (size_t i = 0; i < inst->NumArgs(); i++) {
+			const auto* arg = inst->Arg(i).Resolve().TryInstruction();

Fixed in 0e5cc69: a constant-index CompositeExtractU32x2/3/4 of a CompositeConstructU32x2/3/4 now follows only the selected operand, so the dwords of a pair built with CompositeConstruct keep their own sources. Added the suggested shape (CompositeConstructU32x4(s12, s13, 0, 0) with extracts 0 and 1) to TestDmaBaseRegisters; it records s12 and failed before the change.

**@⁠TheCruZ** on GitHub · 2026-10-02 07:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4163633712) On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 100 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { + const auto* inst = visited[next]; + const auto op = inst->GetOpcode(); + if (op == ValueOpcode::GetUserData) { + if (inst->Arg(0).GetType() == Type::ScalarReg) { + registers.push_back(RegIndex(inst->Arg(0).ScalarRegister())); + } + continue; + } + if (BufferAccessOf(op) != BufferAccess::None || + AddressOpcodeInfoOf(op).access != AddressAccess::None || + ImageOpcodeInfoOf(op).access != ImageAccess::None) { + continue; + } + for (size_t i = 0; i < inst->NumArgs(); i++) { + const auto* arg = inst->Arg(i).Resolve().TryInstruction(); ``` Fixed in 0e5cc69: a constant-index `CompositeExtractU32x2/3/4` of a `CompositeConstructU32x2/3/4` now follows only the selected operand, so the dwords of a pair built with `CompositeConstruct` keep their own sources. Added the suggested shape (`CompositeConstructU32x4(s12, s13, 0, 0)` with extracts 0 and 1) to `TestDmaBaseRegisters`; it records s12 and failed before the change.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 07:26 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 100 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {
+		const auto* inst = visited[next];
+		const auto  op   = inst->GetOpcode();
+		if (op == ValueOpcode::GetUserData) {
+			if (inst->Arg(0).GetType() == Type::ScalarReg) {
+				registers.push_back(RegIndex(inst->Arg(0).ScalarRegister()));
+			}
+			continue;
+		}
+		if (BufferAccessOf(op) != BufferAccess::None ||
+		    AddressOpcodeInfoOf(op).access != AddressAccess::None ||
+		    ImageOpcodeInfoOf(op).access != ImageAccess::None) {
+			continue;
+		}
+		for (size_t i = 0; i < inst->NumArgs(); i++) {
+			const auto* arg = inst->Arg(i).Resolve().TryInstruction();

@TheCruZ, thanks for the fix. The supplied code preserves separate low- and high-dword sources for the reported composite address. The regression case you added covers the original failure.


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-02 07:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4163684879) On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 100 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { + const auto* inst = visited[next]; + const auto op = inst->GetOpcode(); + if (op == ValueOpcode::GetUserData) { + if (inst->Arg(0).GetType() == Type::ScalarReg) { + registers.push_back(RegIndex(inst->Arg(0).ScalarRegister())); + } + continue; + } + if (BufferAccessOf(op) != BufferAccess::None || + AddressOpcodeInfoOf(op).access != AddressAccess::None || + ImageOpcodeInfoOf(op).access != ImageAccess::None) { + continue; + } + for (size_t i = 0; i < inst->NumArgs(); i++) { + const auto* arg = inst->Arg(i).Resolve().TryInstruction(); ``` `@TheCruZ`, thanks for the fix. The supplied code preserves separate low- and high-dword sources for the reported composite address. The regression case you added covers the original failure. --- <!-- 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=Composite%20extracts%20should%20trace%20only%20the%20selected%20operand%E2%80%94or%20valid%20DMA%20bases%20go%20uncached%20and%20reads%20return%20zero.%20%40coderabbitai%20caught%20it%3B%20try%20CodeRabbit%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F925%23discussion_r4161598345)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 07:27 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp line 85 (outdated):

@@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) {
 	return lower > 0x00008000u && upper < 0xffff7fffu;
 }
 
+// The user-data registers an address dword derives from, within a bounded walk of its
+// operands. Lane masks and conditions (U1 operands) select between values rather than compute
+// them, and memory results are data, so the walk does not follow them.
+std::vector<uint32_t> AddressUserDataSources(Value root) {
+	constexpr size_t         MaxVisited = 256;
+	std::vector<uint32_t>    registers;
+	std::vector<const Inst*> visited;
+	if (const auto* inst = root.Resolve().TryInstruction()) {
+		visited.push_back(inst);
+	}
+	for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) {

@TheCruZ, thanks for fixing this. The updated loop processes all queued instructions, including the 256th instruction. The boundary case in TestDmaBaseRegisters covers the reported failure.


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-02 07:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4163686866) On `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` line 85 (outdated): ```diff @@ -72,6 +72,41 @@ bool IsNoncanonicalFlatAddress(Value high, Value active) { return lower > 0x00008000u && upper < 0xffff7fffu; } +// The user-data registers an address dword derives from, within a bounded walk of its +// operands. Lane masks and conditions (U1 operands) select between values rather than compute +// them, and memory results are data, so the walk does not follow them. +std::vector<uint32_t> AddressUserDataSources(Value root) { + constexpr size_t MaxVisited = 256; + std::vector<uint32_t> registers; + std::vector<const Inst*> visited; + if (const auto* inst = root.Resolve().TryInstruction()) { + visited.push_back(inst); + } + for (size_t next = 0; next < visited.size() && visited.size() < MaxVisited; next++) { ``` `@TheCruZ`, thanks for fixing this. The updated loop processes all queued instructions, including the 256th instruction. The boundary case in `TestDmaBaseRegisters` covers the reported failure. --- <!-- 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=CodeRabbit%20caught%20a%20boundary%20bug%3A%20a%20256-instruction%20graph%20could%20skip%20%60GetUserData%60%20and%20miss%20DMA%20base%20pairs.%20The%20review%20pinpointed%20the%20fix%20and%20regression%20test.%20Try%20%40coderabbitai%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F925%23discussion_r4161598342)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-02 09:37 UTC · original

@⁠Nmzik i have rebased the change to fix conflicts, about the pull requests i see that you have a lot of work to review and i have doubts of how to push all my changes from my fork I don't want to bury you in work, but with my custom branch, many of the changes are substantial yet yield major performance improvements in GTA V hitting 40 fps in densely populated areas where the original emulator barely manages 12 apart of crash fixes and basic ray tracing support.

Should I just send everything over and wait for you to review it at some point, or should I hold off until the first three commits are ready or would you like to take a look at it separately? they are around 30 PRs

Maybe alternatively you can check them on my fork and take ideas/implement the ones you want etc and just give me some credits. I squash every fix/change to a single commit to have them easy to bisect later.

**@⁠TheCruZ** on GitHub · 2026-10-02 09:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-5949369662) @⁠Nmzik i have rebased the change to fix conflicts, about the pull requests i see that you have a lot of work to review and i have doubts of how to push all my changes from my fork I don't want to bury you in work, but with my custom branch, many of the changes are substantial yet yield major performance improvements in GTA V hitting 40 fps in densely populated areas where the original emulator barely manages 12 apart of crash fixes and basic ray tracing support. Should I just send everything over and wait for you to review it at some point, or should I hold off until the first three commits are ready or would you like to take a look at it separately? they are around 30 PRs Maybe alternatively you can [check them on my fork](https://github.com/TheCruZ/KytyPS5-GTA) and take ideas/implement the ones you want etc and just give me some credits. I squash every fix/change to a single commit to have them easy to bisect later.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-02 13:34 UTC · original · edited 2026-10-02 13:35 UTC

@⁠TheCruZ I'll take a look at your repo, thanks ofc credit you

**@⁠Nmzik** on GitHub · 2026-10-02 13:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-5953553246) · edited 2026-10-02 13:35 UTC @⁠TheCruZ I'll take a look at your repo, thanks ofc credit you
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-02 14:26 UTC · original

@⁠Nmzik about fidelity its working and it has ray casting using regular shader cores, not rt cores but the speed is around 7fps, not caused by ray casting but by some other existing bottleneck, i will look fidelity mode performance soon, for now i just focused in the performance mode to get those 30-40 fps to make the game playable

**@⁠TheCruZ** on GitHub · 2026-10-02 14:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-5954622057) @⁠Nmzik about fidelity its working and it has ray casting using regular shader cores, not rt cores but the speed is around 7fps, not caused by ray casting but by some other existing bottleneck, i will look fidelity mode performance soon, for now i just focused in the performance mode to get those 30-40 fps to make the game playable
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-05 22:35 UTC · original

Validated this locally (read the diff, rebased, built, tested):

  • Rebased onto current main (cdb64bf): one conflict in PrepareGraphicsBindings (pipeline/descriptors.cpp). main refactored FindBuffers to batch-span mode, so the per-stage FindBuffers(*stage) from this PR no longer applies; resolution keeps the batch call and adds the per-stage CacheDmaBases loop:
FindBuffers(stages);
for (auto* stage : stages) {
    if (stage->runtime->program->info.uses_dma) {
        m_context.CacheDmaBases(*stage->runtime);
        uses_dma = true;
    }
}

Happy to push the rebased branch somewhere if useful.

  • kyty_emulator (x86_64 macOS no-Qt Release) links clean.
  • resource_tracking, shader_cfg, memory_tracker all pass. GPU-harness tests not runnable here (no Vulkan loader — same pre-existing env failure as clean main).

On the fix itself: caching DMA bases before the shader runs (both graphics in PrepareGraphicsBindings and compute in DispatchDirect/DispatchIndirect) instead of faulting mid-dispatch and reading zero is clearly the right ordering — the GTA V glyph-atlas symptom (first glyphs of each 16KB staging page blank) matches a too-late fault-created buffer exactly. Small, targeted, and the new ResourceTracking coverage comes with it. Looks good to me once rebased.

**@⁠overlordxrz-source** on GitHub · 2026-10-05 22:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-6004565065) Validated this locally (read the diff, rebased, built, tested): - Rebased onto current `main` (`cdb64bf`): one conflict in `PrepareGraphicsBindings` (`pipeline/descriptors.cpp`). `main` refactored `FindBuffers` to batch-span mode, so the per-stage `FindBuffers(*stage)` from this PR no longer applies; resolution keeps the batch call and adds the per-stage `CacheDmaBases` loop: ```cpp FindBuffers(stages); for (auto* stage : stages) { if (stage->runtime->program->info.uses_dma) { m_context.CacheDmaBases(*stage->runtime); uses_dma = true; } } ``` Happy to push the rebased branch somewhere if useful. - `kyty_emulator` (x86_64 macOS no-Qt Release) links clean. - `resource_tracking`, `shader_cfg`, `memory_tracker` all pass. GPU-harness tests not runnable here (no Vulkan loader — same pre-existing env failure as clean main). On the fix itself: caching DMA bases before the shader runs (both graphics in `PrepareGraphicsBindings` and compute in `DispatchDirect`/`DispatchIndirect`) instead of faulting mid-dispatch and reading zero is clearly the right ordering — the GTA V glyph-atlas symptom (first glyphs of each 16KB staging page blank) matches a too-late fault-created buffer exactly. Small, targeted, and the new `ResourceTracking` coverage comes with it. Looks good to me once rebased.
@ -126,0 +141,4 @@
// DMA reaches only memory with a cached buffer; any other access records a fault and
// reads zero, and the buffer arrives after the shader has run. That loses data the guest
// writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas.
m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE,
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-08 20:53 UTC · original

Fixed in 19cc54d: CacheDmaBases skips a base whose caching-page window would pass the end of the address space (base > UINT64_MAX - CACHING_PAGESIZE) before calling ForEachInRange. Mapped memory never reaches the top of the address space, so nothing valid is lost.

**@⁠TheCruZ** on GitHub · 2026-10-08 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4224020725) Fixed in 19cc54d: `CacheDmaBases` skips a base whose caching-page window would pass the end of the address space (`base > UINT64_MAX - CACHING_PAGESIZE`) before calling `ForEachInRange`. Mapped memory never reaches the top of the address space, so nothing valid is lost.
@ -126,0 +141,4 @@
// DMA reaches only memory with a cached buffer; any other access records a fault and
// reads zero, and the buffer arrives after the shader has run. That loses data the guest
// writes for a single dispatch, such as the glyph bitmaps GTA V copies into its font atlas.
m_mapped_ranges.ForEachInRange(base, BufferCache::CACHING_PAGESIZE,
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 20:53 UTC · original

@TheCruZ, thanks for the fix and clarification. The guard prevents an overflowing window from reaching ForEachInRange. Given the mapped-memory limit, skipping that window does not lose valid memory.


✏️ Learnings added
Learnt from: TheCruZ
Repo: KytyPS5/KytyPS5 PR: 925
File: src/graphics/host_gpu/renderer/renderContext.cpp:144-144
Timestamp: 2026-10-08T20:53:27.126Z
Learning: In KytyPS5, guest mapped memory never reaches the top of the 64-bit address space. In src/graphics/host_gpu/renderer/renderContext.cpp, RenderContext::CacheDmaBases can therefore skip DMA caching windows that would overflow the address space without excluding valid mapped memory.

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


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

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#discussion_r4224025082) `@TheCruZ`, thanks for the fix and clarification. The guard prevents an overflowing window from reaching `ForEachInRange`. Given the mapped-memory limit, skipping that window does not lose valid memory. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: TheCruZ Repo: KytyPS5/KytyPS5 PR: 925 File: src/graphics/host_gpu/renderer/renderContext.cpp:144-144 Timestamp: 2026-10-08T20:53:27.126Z Learning: In KytyPS5, guest mapped memory never reaches the top of the 64-bit address space. In src/graphics/host_gpu/renderer/renderContext.cpp, RenderContext::CacheDmaBases can therefore skip DMA caching windows that would overflow the address space without excluding valid mapped memory. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=%40coderabbitai%20caught%20a%20DMA%20edge%20case%3A%20overflowing%20base%20ranges%20could%20terminate%20a%20draw%20or%20dispatch.%20The%20fix%20skips%20them%20before%20mapping%20checks%E2%80%94try%20CodeRabbit%20for%20sharp%20reviews%20that%20catch%20stability%20bugs.%20%F0%9F%A9%BA%E2%9A%A1&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F925%23discussion_r4138405493)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-19 15:43 UTC · original

@⁠TheCruZ I saw you closed this today. Do you plan to send it again in another form (maybe with more of your fork's changes), or would you be fine with someone rebasing it onto current main with you as the author?

I checked current main (0cad4672): it still has no equivalent. Nothing reads the DMA base user-data registers before a draw or dispatch, and PrepareBda -> SynchronizeBda only re-syncs buffers that already exist in the pending ranges. If you resubmit, I can help with tests.

Written with Claude Code (AI): it compared your commit with main; I checked the code before posting.

**@⁠Nawid3333** on GitHub · 2026-10-19 15:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-6271191851) @⁠TheCruZ I saw you closed this today. Do you plan to send it again in another form (maybe with more of your fork's changes), or would you be fine with someone rebasing it onto current main with you as the author? I checked current main (0cad4672): it still has no equivalent. Nothing reads the DMA base user-data registers before a draw or dispatch, and `PrepareBda` -> `SynchronizeBda` only re-syncs buffers that already exist in the pending ranges. If you resubmit, I can help with tests. Written with Claude Code (AI): it compared your commit with main; I checked the code before posting.
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-19 16:46 UTC · original

@⁠TheCruZ I saw you closed this today. Do you plan to send it again in another form (maybe with more of your fork's changes), or would you be fine with someone rebasing it onto current main with you as the author?

I checked current main (0cad467): it still has no equivalent. Nothing reads the DMA base user-data registers before a draw or dispatch, and PrepareBda -> SynchronizeBda only re-syncs buffers that already exist in the pending ranges. If you resubmit, I can help with tests.

Written with Claude Code (AI): it compared your commit with main; I checked the code before posting.

yes i know, i had too many PRs open and was hard to keep all them up without being merged, i ask @⁠Nmzik to check my fork when he had time and he can merge the changes from there when he want with the credits

in my fork i keep them clean to be merged without conflicts

**@⁠TheCruZ** on GitHub · 2026-10-19 16:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/925#issuecomment-6272348666) > @⁠TheCruZ I saw you closed this today. Do you plan to send it again in another form (maybe with more of your fork's changes), or would you be fine with someone rebasing it onto current main with you as the author? > > I checked current main ([0cad467](https://github.com/KytyPS5/KytyPS5/commit/0cad4672e948b92b92e1aaf6e9bb5b144d8075ac)): it still has no equivalent. Nothing reads the DMA base user-data registers before a draw or dispatch, and `PrepareBda` -> `SynchronizeBda` only re-syncs buffers that already exist in the pending ranges. If you resubmit, I can help with tests. > > Written with Claude Code (AI): it compared your commit with main; I checked the code before posting. yes i know, i had too many PRs open and was hard to keep all them up without being merged, i ask @⁠Nmzik to check my fork when he had time and he can merge the changes from there when he want with the credits in my fork i keep them clean to be merged without conflicts

Pull request closed

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