graphics: cut per-draw CPU cost on the GPU command thread #1211

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

@⁠NeySlim on GitHub · 2026-10-08 13:17 UTC · original
NeySlim:perf/gpu-command-thread → main · +123 −104 · 3 files · 4 commits · closed without merging

Problem

In God of War Ragnarök (PPSA08332, 05.005) the frame rate is bound by the GPU command thread (GuestGpu::ThreadRun). On main, a perf profile of that thread during the opening cutscene shows two per-draw costs that do no useful work:

  • RenderExecutor::CommitBindings walks the bound images and looks each one up in the texture cache again for every scalar read of every bound shader, to collect the ranges those images write. The list is the same for the whole draw.
  • The SRT walker (MaterializeResources) spends a large share of its time in tiny IR::Value/IR::Inst accessors (Resolve, Arg, IsIdentity, U32, operator==, ...). They are defined in Value.cpp, so they cannot be inlined into the walker without LTO.
GPU thread, cutscene, main ms per frame
Whole thread 82.7
MaterializeResources (inclusive) 42.0
IR::Value/IR::Inst accessors (self) 12.0
CommitBindings (inclusive) 11.0

Change

  • CommitBindings collects the ranges written by bound images once per draw, then checks every scalar read against that list. Same checks, same EXIT messages.
  • The small IR::Value/IR::Inst accessors and Value::operator== move inline into Value.h. Resolve follows identity chains in a loop instead of recursing (same result). ResolveInstruction still fails fast when an identity resolves to something that is not an instruction.

No behavior change intended.

Test

  • shader_recompiler_compute_tests, one case per process: 775 cases, the same 50 failures as main on this RADV setup, no new failure.
  • resource_tracking_tests, resource_materialization_tests, scalar_provenance_tests: pass.

Validation

Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4.

Main (d58aefde4) against this branch, both with #1165 merged: without it main stops in this game shortly after the opening cutscene, on the short file read that #1165 fixes. New game from the menu, same inputs, frame rate from a uprobe on GuestGpu::SuspendPoint, warm pipeline cache, runs alternated main / PR three times:

Scene main this PR
Opening cutscene 8.75 / 8.58 / 8.49 = 8.61 fps 9.77 / 9.45 / 9.45 = 9.56 fps (+11%)
Sled 7.32 / 7.21 / 7.65 = 7.39 fps 8.43 / 8.41 / 8.73 = 8.52 fps (+15%)
Freya fight 6.04 / 6.40 / 6.50 = 6.31 fps 6.79 / 6.80 / 7.19 = 6.93 fps (+10%)

The sled numbers leave out a stall of about 130 s that both builds hit at the same point while a compute shader is translated (FoldWorklist::QueueUsers); it is not related to this change. A fourth pair with perf attached gives the same picture (8.40 / 7.62 / 6.51 against 9.15 / 8.82 / 7.26 fps).

GPU thread profile in that fourth pair (20 s, cutscene):

ms per frame main this PR
Whole thread 82.7 66.7
MaterializeResources (inclusive) 42.0 33.6
IR::Value/IR::Inst accessors (self) 12.0 1.8
CommitBindings (inclusive) 11.0 5.5

In the Freya fight the same counters go from 18.5 to 3.2 ms (accessors) and from 17.5 to 6.8 ms (CommitBindings). No new error or device loss in the logs on either side.

Not tested on Windows/macOS; the changes are platform-independent.

AI use

I used Claude Code (AI agent) to profile the emulator, write the changes, measure the frame rate and run the tests above on my machine. I reviewed the diff and the results before updating this PR.

**@⁠NeySlim** on GitHub · 2026-10-08 13:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211) `NeySlim:perf/gpu-command-thread` → `main` · +123 −104 · 3 files · 4 commits · closed without merging ## Problem In God of War Ragnarök (PPSA08332, 05.005) the frame rate is bound by the GPU command thread (`GuestGpu::ThreadRun`). On main, a `perf` profile of that thread during the opening cutscene shows two per-draw costs that do no useful work: - `RenderExecutor::CommitBindings` walks the bound images and looks each one up in the texture cache again for every scalar read of every bound shader, to collect the ranges those images write. The list is the same for the whole draw. - The SRT walker (`MaterializeResources`) spends a large share of its time in tiny `IR::Value`/`IR::Inst` accessors (`Resolve`, `Arg`, `IsIdentity`, `U32`, `operator==`, ...). They are defined in `Value.cpp`, so they cannot be inlined into the walker without LTO. | GPU thread, cutscene, main | ms per frame | |---|---| | Whole thread | 82.7 | | `MaterializeResources` (inclusive) | 42.0 | | `IR::Value`/`IR::Inst` accessors (self) | 12.0 | | `CommitBindings` (inclusive) | 11.0 | ## Change - `CommitBindings` collects the ranges written by bound images once per draw, then checks every scalar read against that list. Same checks, same EXIT messages. - The small `IR::Value`/`IR::Inst` accessors and `Value::operator==` move inline into `Value.h`. `Resolve` follows identity chains in a loop instead of recursing (same result). `ResolveInstruction` still fails fast when an identity resolves to something that is not an instruction. No behavior change intended. ## Test - `shader_recompiler_compute_tests`, one case per process: 775 cases, the same 50 failures as main on this RADV setup, no new failure. - `resource_tracking_tests`, `resource_materialization_tests`, `scalar_provenance_tests`: pass. ## Validation Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.4. Main (d58aefde4) against this branch, both with #1165 merged: without it main stops in this game shortly after the opening cutscene, on the short file read that #1165 fixes. New game from the menu, same inputs, frame rate from a uprobe on `GuestGpu::SuspendPoint`, warm pipeline cache, runs alternated main / PR three times: | Scene | main | this PR | |---|---|---| | Opening cutscene | 8.75 / 8.58 / 8.49 = 8.61 fps | 9.77 / 9.45 / 9.45 = 9.56 fps (+11%) | | Sled | 7.32 / 7.21 / 7.65 = 7.39 fps | 8.43 / 8.41 / 8.73 = 8.52 fps (+15%) | | Freya fight | 6.04 / 6.40 / 6.50 = 6.31 fps | 6.79 / 6.80 / 7.19 = 6.93 fps (+10%) | The sled numbers leave out a stall of about 130 s that both builds hit at the same point while a compute shader is translated (`FoldWorklist::QueueUsers`); it is not related to this change. A fourth pair with `perf` attached gives the same picture (8.40 / 7.62 / 6.51 against 9.15 / 8.82 / 7.26 fps). GPU thread profile in that fourth pair (20 s, cutscene): | ms per frame | main | this PR | |---|---|---| | Whole thread | 82.7 | 66.7 | | `MaterializeResources` (inclusive) | 42.0 | 33.6 | | `IR::Value`/`IR::Inst` accessors (self) | 12.0 | 1.8 | | `CommitBindings` (inclusive) | 11.0 | 5.5 | In the Freya fight the same counters go from 18.5 to 3.2 ms (accessors) and from 17.5 to 6.8 ms (`CommitBindings`). No new error or device loss in the logs on either side. Not tested on Windows/macOS; the changes are platform-independent. ## AI use I used Claude Code (AI agent) to profile the emulator, write the changes, measure the frame rate and run the tests above on my machine. I reviewed the diff and the results before updating this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:56 +00:00
github-bot closed this pull request 2026-11-26 09:47:56 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 13:23 UTC · original · edited 2026-10-17 07: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: 05ed8da90cdc516ed3b154825f87f4f69b296907
  • Latest commit, not reviewed: 857bf8c503

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: af756038-1d41-4994-b67d-54b243d52b23
📥 Commits

Reviewing files that changed from the base of the PR and between 3468a996cc2f1b1b269c2b8619d729e14760e1e5 and 05ed8da90cdc516ed3b154825f87f4f69b296907.

📒 Files selected for processing: 5
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/shader/recompiler/ir/Value.h
  • tests/ShaderRecompilerComputeTests.cpp

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

📝 Walkthrough

MemoryTracker tracks CPU-dirty generation changes. BufferCache uses the generation and registration epoch when deciding whether to scan upload ranges. RenderContext can skip a mapped-range sweep when its synchronization key and mapping epoch are unchanged. CommitBindings gathers image write ranges once per call. Value and Inst accessors are now defined inline in Value.h. Tests cover generation changes and BDA synchronization after remapping.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Refactor

Merge Risk: ⚪ Minimal · up to 05ed8

No identified synchronization or accessor issue remains that should block merging after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 10 files. (2 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 summarizes the primary change: reducing per-draw CPU cost on the GPU command thread. It is concise and directly related to the optimization work.
Description check Passed The description is directly related to the changeset. It explains the performance problem, implementation changes, tests, validation results, and intended behavior preservation.
Full details: Docstring Coverage

Explanation

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

Resolution

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

  • Autopilot · 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-08 13:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#issuecomment-6060837740) · edited 2026-10-17 07:55 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/1211?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: 05ed8da90cdc516ed3b154825f87f4f69b296907 > - Latest commit, not reviewed: 857bf8c503545c115c3316226e2e036ca23620a3 > > 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><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `af756038-1d41-4994-b67d-54b243d52b23` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 3468a996cc2f1b1b269c2b8619d729e14760e1e5 and 05ed8da90cdc516ed3b154825f87f4f69b296907. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 5</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/shader/recompiler/ir/Value.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> MemoryTracker tracks CPU-dirty generation changes. BufferCache uses the generation and registration epoch when deciding whether to scan upload ranges. RenderContext can skip a mapped-range sweep when its synchronization key and mapping epoch are unchanged. CommitBindings gathers image write ranges once per call. Value and Inst accessors are now defined inline in Value.h. Tests cover generation changes and BDA synchronization after remapping. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"05ed8da90cdc516ed3b154825f87f4f69b296907" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>05ed8</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `05ed8` --> <!-- final_review_risk_coverage:{"sourceCommitId":"05ed8da90cdc516ed3b154825f87f4f69b296907","coveredCommitId":"05ed8da90cdc516ed3b154825f87f4f69b296907","kind":"reviewed"} --> No identified synchronization or accessor issue remains that should block merging after normal checks. <!-- 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 8.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 10 files. (2 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 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 summarizes the primary change: reducing per-draw CPU cost on the GPU command thread. It is concise and directly related to the optimization work. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset. It explains the performance problem, implementation changes, tests, validation results, and intended behavior preservation. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 10 files. (2 skipped: 1 unsupported, 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">Autopilot</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=1211)! 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-08 13:23 UTC · original · edited 2026-10-08 13:26 UTC
On src/graphics/shader/recompiler/ir/Value.h line 212 (outdated):

@@ -177,4 +177,110 @@ class Inst {
 
 static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased");
 
+// Hot accessors of the resource walker are defined inline; they need the full Inst.
+inline bool Value::IsEmpty() const {
+	return type == Type::Void;
+}
+
+inline bool Value::IsImmediate() const {
+	return type != Type::Opaque;
+}
+
+inline bool Value::IsIdentity() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity;
+}
+
+inline bool Value::IsPhi() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi;
+}
+
+inline Inst* Value::TryInstruction() const {
+	return type == Type::Opaque ? inst : nullptr;
+}
+
+inline Value Value::Resolve() const {
+	// Identity chains are followed iteratively; the walker resolves every operand it visits.
+	Value value = *this;
+	while (value.IsIdentity()) {
+		value = value.inst->Arg(0);
+	}
+	return value;
+}
+
+inline Inst* Value::ResolveInstruction() const {
+	EXIT_IF(type != Type::Opaque);
+	return Resolve().inst;

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '165,290p' src/graphics/shader/recompiler/ir/Value.h
rg -n 'ResolveInstruction\(|SetIdentity|Identity|Resolve\(' src/graphics/shader/recompiler/ir | head -100
git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | head -110

Repository: KytyPS5/KytyPS5

Length of output: 17272


🏁 Script executed:

set -eu

printf '%s\n' '--- Value declarations and constructors ---'
sed -n '1,180p' src/graphics/shader/recompiler/ir/Value.h
printf '%s\n' '--- Value.cpp construction and argument validation ---'
sed -n '1,190p' src/graphics/shader/recompiler/ir/Value.cpp
printf '%s\n' '--- opcode metadata ---'
cat src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc

printf '%s\n' '--- ResolveInstruction callers ---'
rg -n -F -- 'ResolveInstruction()' src/graphics/shader/recompiler/ir
printf '%s\n' '--- relevant caller blocks ---'
sed -n '50,85p' src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp
sed -n '255,305p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '420,485p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '850,910p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

printf '%s\n' '--- base/head diff for Value implementation ---'
git diff --no-ext-diff --unified=80 4865dd92ca6b6bb907748f125883093af038f53b 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a -- \
  src/graphics/shader/recompiler/ir/Value.h \
  src/graphics/shader/recompiler/ir/Value.cpp

printf '%s\n' '--- base Value.h and Value.cpp relevant definitions ---'
git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.h | sed -n '1,260p'
git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | sed -n '1,190p'

Repository: KytyPS5/KytyPS5

Length of output: 41650


🏁 Script executed:

set -eu
printf '%s\n' '--- Value declarations and implementation ---'
sed -n '1,180p' src/graphics/shader/recompiler/ir/Value.h
sed -n '1,190p' src/graphics/shader/recompiler/ir/Value.cpp
printf '%s\n' '--- Identity opcode and argument construction sites ---'
cat src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc
rg -n -F -- 'ValueOpcode::Identity' src/graphics/shader/recompiler/ir
rg -n -F -- 'SetArg(' src/graphics/shader/recompiler/ir
printf '%s\n' '--- ResolveInstruction callers ---'
rg -n -F -- 'ResolveInstruction()' src/graphics/shader/recompiler/ir
printf '%s\n' '--- base/head diff ---'
git diff --no-ext-diff --unified=40 4865dd92ca6b6bb907748f125883093af038f53b 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a -- src/graphics/shader/recompiler/ir/Value.h src/graphics/shader/recompiler/ir/Value.cpp

Repository: KytyPS5/KytyPS5

Length of output: 41810


🏁 Script executed:

set -eu
printf '%s\n' '--- caller blocks ---'
sed -n '55,82p' src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp
sed -n '262,300p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '425,482p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '862,895p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
sed -n '380,402p' src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
sed -n '1578,1598p' src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
printf '%s\n' '--- exact implementation line ranges ---'
nl -ba src/graphics/shader/recompiler/ir/Value.h | sed -n '184,216p'
nl -ba src/graphics/shader/recompiler/ir/Value.cpp | sed -n '104,158p'
printf '%s\n' '--- base ResolveInstruction with line numbers ---'
git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | nl -ba | sed -n '42,66p'

Repository: KytyPS5/KytyPS5

Length of output: 11914


Check the resolved value before reading instruction storage.

Inst::SetArg does not enforce the Identity operand type. ReplaceUsesWith can create an Identity whose operand is an immediate. The current ResolveInstruction() then reads that immediate's union storage as Inst*.

The base implementation rejected this path through EXIT_IF. Do not return nullptr: ReadLaneElimination dereferences the result without a null check. Preserve the existing fail-fast contract while validating the resolved value:

Suggested fix
--- "a/src/graphics/shader/recompiler/ir/Value.h"
+++ "b/src/graphics/shader/recompiler/ir/Value.h"
@@ -207,10 +207,10 @@
 	return value;
 }
 
 inline Inst* Value::ResolveInstruction() const {
 	EXIT_IF(type != Type::Opaque);
-	return Resolve().inst;
+	return Resolve().Instruction();
 }
 
 inline bool Value::U1() const {
 	EXIT_IF(type != Type::U1);
📝 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.

inline Inst* Value::ResolveInstruction() const {
	EXIT_IF(type != Type::Opaque);
	return Resolve().Instruction();

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 13:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#discussion_r4219473431) · edited 2026-10-08 13:26 UTC On `src/graphics/shader/recompiler/ir/Value.h` line 212 (outdated): ```diff @@ -177,4 +177,110 @@ class Inst { static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased"); +// Hot accessors of the resource walker are defined inline; they need the full Inst. +inline bool Value::IsEmpty() const { + return type == Type::Void; +} + +inline bool Value::IsImmediate() const { + return type != Type::Opaque; +} + +inline bool Value::IsIdentity() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity; +} + +inline bool Value::IsPhi() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi; +} + +inline Inst* Value::TryInstruction() const { + return type == Type::Opaque ? inst : nullptr; +} + +inline Value Value::Resolve() const { + // Identity chains are followed iteratively; the walker resolves every operand it visits. + Value value = *this; + while (value.IsIdentity()) { + value = value.inst->Arg(0); + } + return value; +} + +inline Inst* Value::ResolveInstruction() const { + EXIT_IF(type != Type::Opaque); + return Resolve().inst; ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '165,290p' src/graphics/shader/recompiler/ir/Value.h rg -n 'ResolveInstruction\(|SetIdentity|Identity|Resolve\(' src/graphics/shader/recompiler/ir | head -100 git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | head -110 ``` Repository: KytyPS5/KytyPS5 Length of output: 17272 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- Value declarations and constructors ---' sed -n '1,180p' src/graphics/shader/recompiler/ir/Value.h printf '%s\n' '--- Value.cpp construction and argument validation ---' sed -n '1,190p' src/graphics/shader/recompiler/ir/Value.cpp printf '%s\n' '--- opcode metadata ---' cat src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc printf '%s\n' '--- ResolveInstruction callers ---' rg -n -F -- 'ResolveInstruction()' src/graphics/shader/recompiler/ir printf '%s\n' '--- relevant caller blocks ---' sed -n '50,85p' src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp sed -n '255,305p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '420,485p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '850,910p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- base/head diff for Value implementation ---' git diff --no-ext-diff --unified=80 4865dd92ca6b6bb907748f125883093af038f53b 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a -- \ src/graphics/shader/recompiler/ir/Value.h \ src/graphics/shader/recompiler/ir/Value.cpp printf '%s\n' '--- base Value.h and Value.cpp relevant definitions ---' git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.h | sed -n '1,260p' git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | sed -n '1,190p' ``` Repository: KytyPS5/KytyPS5 Length of output: 41650 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- Value declarations and implementation ---' sed -n '1,180p' src/graphics/shader/recompiler/ir/Value.h sed -n '1,190p' src/graphics/shader/recompiler/ir/Value.cpp printf '%s\n' '--- Identity opcode and argument construction sites ---' cat src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc rg -n -F -- 'ValueOpcode::Identity' src/graphics/shader/recompiler/ir rg -n -F -- 'SetArg(' src/graphics/shader/recompiler/ir printf '%s\n' '--- ResolveInstruction callers ---' rg -n -F -- 'ResolveInstruction()' src/graphics/shader/recompiler/ir printf '%s\n' '--- base/head diff ---' git diff --no-ext-diff --unified=40 4865dd92ca6b6bb907748f125883093af038f53b 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a -- src/graphics/shader/recompiler/ir/Value.h src/graphics/shader/recompiler/ir/Value.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 41810 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- caller blocks ---' sed -n '55,82p' src/graphics/shader/recompiler/ir/passes/ReadLaneElimination.cpp sed -n '262,300p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '425,482p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '862,895p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp sed -n '380,402p' src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp sed -n '1578,1598p' src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp printf '%s\n' '--- exact implementation line ranges ---' nl -ba src/graphics/shader/recompiler/ir/Value.h | sed -n '184,216p' nl -ba src/graphics/shader/recompiler/ir/Value.cpp | sed -n '104,158p' printf '%s\n' '--- base ResolveInstruction with line numbers ---' git show 4865dd92ca6b6bb907748f125883093af038f53b:src/graphics/shader/recompiler/ir/Value.cpp | nl -ba | sed -n '42,66p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11914 --- </details> **Check the resolved value before reading instruction storage.** `Inst::SetArg` does not enforce the `Identity` operand type. `ReplaceUsesWith` can create an `Identity` whose operand is an immediate. The current `ResolveInstruction()` then reads that immediate's union storage as `Inst*`. The base implementation rejected this path through `EXIT_IF`. Do not return `nullptr`: `ReadLaneElimination` dereferences the result without a null check. Preserve the existing fail-fast contract while validating the resolved value: <details> <summary>Suggested fix</summary> ```diff --- "a/src/graphics/shader/recompiler/ir/Value.h" +++ "b/src/graphics/shader/recompiler/ir/Value.h" @@ -207,10 +207,10 @@ return value; } inline Inst* Value::ResolveInstruction() const { EXIT_IF(type != Type::Opaque); - return Resolve().inst; + return Resolve().Instruction(); } inline bool Value::U1() const { EXIT_IF(type != Type::U1); ``` </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 inline Inst* Value::ResolveInstruction() const { EXIT_IF(type != Type::Opaque); return Resolve().Instruction(); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:e0cbd1f360798e15fafb972b --> <!-- 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-08 13:23 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: 6adcf627-6b0e-4d24-ac9b-13addfe01f18
📥 Commits

Reviewing files that changed from the base of the PR and between 4865dd92ca and 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a.

📒 Files selected for processing (11)
  • src/graphics/host_gpu/memoryTracker.cpp
  • src/graphics/host_gpu/memoryTracker.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/streamBuffer.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/Value.cpp
  • src/graphics/shader/recompiler/ir/Value.h
  • tests/MemoryTrackerTests.cpp
💤 Files with no reviewable changes (1)
  • src/graphics/shader/recompiler/ir/Value.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 13:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#pullrequestreview-5457262194) · **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**: `6adcf627-6b0e-4d24-ac9b-13addfe01f18` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 4865dd92ca6b6bb907748f125883093af038f53b and 5a359cf4222e003e3c746728b4d9f8bdd67a5b9a. </details> <details> <summary>📒 Files selected for processing (11)</summary> * `src/graphics/host_gpu/memoryTracker.cpp` * `src/graphics/host_gpu/memoryTracker.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/streamBuffer.h` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/Value.cpp` * `src/graphics/shader/recompiler/ir/Value.h` * `tests/MemoryTrackerTests.cpp` </details> <details> <summary>💤 Files with no reviewable changes (1)</summary> * src/graphics/shader/recompiler/ir/Value.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=7e53df56-c2c9-4637-92e8-9031abeff362 attempt=f00a021e-4d6a-447f-8ff3-a1b60c5416b4 batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-08 13:26 UTC · original
On src/graphics/shader/recompiler/ir/Value.h line 212 (outdated):

@@ -177,4 +177,110 @@ class Inst {
 
 static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased");
 
+// Hot accessors of the resource walker are defined inline; they need the full Inst.
+inline bool Value::IsEmpty() const {
+	return type == Type::Void;
+}
+
+inline bool Value::IsImmediate() const {
+	return type != Type::Opaque;
+}
+
+inline bool Value::IsIdentity() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity;
+}
+
+inline bool Value::IsPhi() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi;
+}
+
+inline Inst* Value::TryInstruction() const {
+	return type == Type::Opaque ? inst : nullptr;
+}
+
+inline Value Value::Resolve() const {
+	// Identity chains are followed iteratively; the walker resolves every operand it visits.
+	Value value = *this;
+	while (value.IsIdentity()) {
+		value = value.inst->Arg(0);
+	}
+	return value;
+}
+
+inline Inst* Value::ResolveInstruction() const {
+	EXIT_IF(type != Type::Opaque);
+	return Resolve().inst;

Agreed, fixed in cecf901: ResolveInstruction checks the resolved value again and keeps the fail-fast EXIT_IF of the recursive version when an identity forwards a non-instruction, instead of reading the union as Inst*. resource_materialization and resource_tracking pass.

**@⁠NeySlim** on GitHub · 2026-10-08 13:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#discussion_r4219509440) On `src/graphics/shader/recompiler/ir/Value.h` line 212 (outdated): ```diff @@ -177,4 +177,110 @@ class Inst { static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased"); +// Hot accessors of the resource walker are defined inline; they need the full Inst. +inline bool Value::IsEmpty() const { + return type == Type::Void; +} + +inline bool Value::IsImmediate() const { + return type != Type::Opaque; +} + +inline bool Value::IsIdentity() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity; +} + +inline bool Value::IsPhi() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi; +} + +inline Inst* Value::TryInstruction() const { + return type == Type::Opaque ? inst : nullptr; +} + +inline Value Value::Resolve() const { + // Identity chains are followed iteratively; the walker resolves every operand it visits. + Value value = *this; + while (value.IsIdentity()) { + value = value.inst->Arg(0); + } + return value; +} + +inline Inst* Value::ResolveInstruction() const { + EXIT_IF(type != Type::Opaque); + return Resolve().inst; ``` Agreed, fixed in cecf901: `ResolveInstruction` checks the resolved value again and keeps the fail-fast `EXIT_IF` of the recursive version when an identity forwards a non-instruction, instead of reading the union as `Inst*`. `resource_materialization` and `resource_tracking` pass.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 13:27 UTC · original
On src/graphics/shader/recompiler/ir/Value.h line 212 (outdated):

@@ -177,4 +177,110 @@ class Inst {
 
 static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased");
 
+// Hot accessors of the resource walker are defined inline; they need the full Inst.
+inline bool Value::IsEmpty() const {
+	return type == Type::Void;
+}
+
+inline bool Value::IsImmediate() const {
+	return type != Type::Opaque;
+}
+
+inline bool Value::IsIdentity() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity;
+}
+
+inline bool Value::IsPhi() const {
+	return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi;
+}
+
+inline Inst* Value::TryInstruction() const {
+	return type == Type::Opaque ? inst : nullptr;
+}
+
+inline Value Value::Resolve() const {
+	// Identity chains are followed iteratively; the walker resolves every operand it visits.
+	Value value = *this;
+	while (value.IsIdentity()) {
+		value = value.inst->Arg(0);
+	}
+	return value;
+}
+
+inline Inst* Value::ResolveInstruction() const {
+	EXIT_IF(type != Type::Opaque);
+	return Resolve().inst;

@NeySlim Thanks for the fix in cecf901. The resolved-value check preserves the fail-fast contract and prevents reading an immediate as Inst*. Thanks for confirming that resource_materialization and resource_tracking pass.


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 13:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#discussion_r4219513929) On `src/graphics/shader/recompiler/ir/Value.h` line 212 (outdated): ```diff @@ -177,4 +177,110 @@ class Inst { static_assert(sizeof(Inst) <= 112, "Inst operand storage unintentionally increased"); +// Hot accessors of the resource walker are defined inline; they need the full Inst. +inline bool Value::IsEmpty() const { + return type == Type::Void; +} + +inline bool Value::IsImmediate() const { + return type != Type::Opaque; +} + +inline bool Value::IsIdentity() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Identity; +} + +inline bool Value::IsPhi() const { + return type == Type::Opaque && inst->GetOpcode() == ValueOpcode::Phi; +} + +inline Inst* Value::TryInstruction() const { + return type == Type::Opaque ? inst : nullptr; +} + +inline Value Value::Resolve() const { + // Identity chains are followed iteratively; the walker resolves every operand it visits. + Value value = *this; + while (value.IsIdentity()) { + value = value.inst->Arg(0); + } + return value; +} + +inline Inst* Value::ResolveInstruction() const { + EXIT_IF(type != Type::Opaque); + return Resolve().inst; ``` `@NeySlim` Thanks for the fix in `cecf901`. The resolved-value check preserves the fail-fast contract and prevents reading an immediate as `Inst*`. Thanks for confirming that `resource_materialization` and `resource_tracking` pass. --- <!-- 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=Validate%20resolved%20shader%20IR%20values%20before%20reading%20instruction%20storage%3A%20an%20Identity%20may%20forward%20an%20immediate.%20Keep%20fail-fast%20checks%20to%20prevent%20invalid%20union%20reads.%20Try%20%40coderabbitai%20%F0%9F%9B%A1%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1211%23discussion_r4219473431)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

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

I added a commit, gpu: sweep BDA buffers after memory is mapped again (378f66f3), for a case the skip in PrepareBda missed.

Gap: the skip compared the CPU-dirty generation and the buffer registration epoch, but the sweep only visits mapped ranges. UnmapMemory leaves a range CPU-dirty and unprotected, and the sweep after it skips these pages. If the guest then writes them (no fault, they are unprotected) and maps the range again, nothing in the key changes: the next sweep is skipped and a shader reads the buffer's stale copy through its device address. Before this PR the sweep ran before every draw, so this could not happen.

Fix: MapMemory advances a mapping epoch after adding the range, and PrepareBda compares it too before skipping. It is read before the sweep like the rest of the key, so a mapping that lands during a sweep makes the next one run. Unmapping needs nothing more: it invalidates the range, which already advances the generation. Mappings are rare compared to draws, so the skip keeps its gain.

Test: new BdaSweepAfterRemap (--bda-remap-only, ctest buffer_cache_bda_remap, also in the default run). A buffer over mapped memory is uploaded by a first sweep; part of it is unmapped and swept, written without a fault and mapped again; the next sweep must upload the new word. Without the fix it fails at "mapped again" (the GPU copy keeps the old word).

Validation: Linux, Radeon 8060S, Mesa RADV 26.2.3. memory_tracker, buffer_cache_dirty_gc and the new test pass (buffer_cache_ranges fails on main too on this setup). shader_recompiler_compute_tests, one case per process: 594 of 603 cases pass, the same 9 failures as on main.

As for the rest of this PR, I used Claude Code (AI agent) to find the gap, write the fix and the test, and run the tests; I reviewed the change and the results.

**@⁠NeySlim** on GitHub · 2026-10-09 07:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#issuecomment-6076413055) I added a commit, `gpu: sweep BDA buffers after memory is mapped again` (378f66f3), for a case the skip in `PrepareBda` missed. **Gap:** the skip compared the CPU-dirty generation and the buffer registration epoch, but the sweep only visits mapped ranges. `UnmapMemory` leaves a range CPU-dirty and unprotected, and the sweep after it skips these pages. If the guest then writes them (no fault, they are unprotected) and maps the range again, nothing in the key changes: the next sweep is skipped and a shader reads the buffer's stale copy through its device address. Before this PR the sweep ran before every draw, so this could not happen. **Fix:** `MapMemory` advances a mapping epoch after adding the range, and `PrepareBda` compares it too before skipping. It is read before the sweep like the rest of the key, so a mapping that lands during a sweep makes the next one run. Unmapping needs nothing more: it invalidates the range, which already advances the generation. Mappings are rare compared to draws, so the skip keeps its gain. **Test:** new `BdaSweepAfterRemap` (`--bda-remap-only`, ctest `buffer_cache_bda_remap`, also in the default run). A buffer over mapped memory is uploaded by a first sweep; part of it is unmapped and swept, written without a fault and mapped again; the next sweep must upload the new word. Without the fix it fails at "mapped again" (the GPU copy keeps the old word). **Validation:** Linux, Radeon 8060S, Mesa RADV 26.2.3. `memory_tracker`, `buffer_cache_dirty_gc` and the new test pass (`buffer_cache_ranges` fails on main too on this setup). `shader_recompiler_compute_tests`, one case per process: 594 of 603 cases pass, the same 9 failures as on main. As for the rest of this PR, I used Claude Code (AI agent) to find the gap, write the fix and the test, and run the tests; I reviewed the change and the results.
Author
Owner

@⁠ZrDaniel07 on GitHub · 2026-10-26 20:35 UTC · original

@⁠NeySlim Windows/NVIDIA data point for this PR. Setup: RTX 5090, Windows 11, ASTRO BOT's Garden level, on main f90a8b15 + #838 + a local mesh slicing patch. Details are in the #745 report.

  • The PR no longer applies cleanly: the first commit conflicts in CommitBindings, because main now uses m_slot_images[id] instead of try_get(id). Keeping main's access plus your gather-once loop builds fine, and the other three commits apply as-is.
  • With a warm pipeline cache, at the same spots, draw throughput went from 37.0–37.6k to 41.0k draws/s in the flamingo flight (6.2–6.4 → 7.0 FPS). Other dense views: 41.0k → 43.2k, and up to 45.8k on the main path.
  • That is +5–11% in the dense scenes, close to your God of War numbers. Light scenes (~900–1100 draws/frame) didn't change clearly.
  • No new errors or device loss in one run.

AI use: Claude Code rebased the commits and compared the overlay numbers with me; I ran the game.

**@⁠ZrDaniel07** on GitHub · 2026-10-26 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1211#issuecomment-6426709094) @⁠NeySlim Windows/NVIDIA data point for this PR. Setup: RTX 5090, Windows 11, ASTRO BOT's Garden level, on `main` `f90a8b15` + #838 + a local mesh slicing patch. Details are in the [#745 report](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/745). - The PR no longer applies cleanly: the first commit conflicts in `CommitBindings`, because `main` now uses `m_slot_images[id]` instead of `try_get(id)`. Keeping `main`'s access plus your gather-once loop builds fine, and the other three commits apply as-is. - With a warm pipeline cache, at the same spots, draw throughput went from 37.0–37.6k to 41.0k draws/s in the flamingo flight (6.2–6.4 → 7.0 FPS). Other dense views: 41.0k → 43.2k, and up to 45.8k on the main path. - That is +5–11% in the dense scenes, close to your God of War numbers. Light scenes (~900–1100 draws/frame) didn't change clearly. - No new errors or device loss in one run. AI use: Claude Code rebased the commits and compared the overlay numbers with me; I ran the game.

Pull request closed

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