shader: drop lane-dependent bits from a sampler border color word #1226

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

@⁠TheCruZ on GitHub · 2026-10-08 19:00 UTC · original
pr/sampler-border-color-word → main · +78 −4 · 2 files · 1 commits · closed without merging

Summary

Fixes the emulator exiting with GetSamplerResource dword 3 is not a valid runtime value in Grand Theft Auto V (PPSA04263) at the car dealership (mission with Franklin and Lamar). Pixel shader 0xf6b18542ea0e938a builds the last word of its sampler from data resource tracking cannot follow.

Problem

The shader ORs lane-dependent data into S# word 3 before sampling. Resource tracking requires every descriptor word to be a runtime value (user data or memory it can read on the host), so the shader was rejected and the emulator exited.

S# word 3 only holds the border color pointer and border color type, so sampling inside the texture does not depend on it. The same happened with the SampleAdjust scratch bits some shaders OR into that word, which were rejected too.

Change

When word 3 is the only untrackable word of an S#, GetHandle keeps the runtime-valid operand of the OR that mixes lane data into it (the user-data border fields), recursively through nested ORs, or uses zero (transparent black border) if no such operand exists, and prints a warning with the shader hash and pc. Any other untrackable sampler word still fails as before.

Testing

  • Grand Theft Auto V (PPSA04263): the car dealership scene renders and the mission continues; played in my fork with this change.
  • resource_tracking_tests: new TestUntrackableSamplerBorderWord (word 3 falls back to a transparent black border, an untrackable word 2 is still rejected); TestSampleAdjustSamplerScratch now checks that the user-data part of a scratch-ORed border word is kept instead of expecting a rejection. Passes.
  • resource_materialization_tests, memory_tracker_tests, page_manager_tests, shader_cfg_tests, virtual_memory_allocation_tests and the default run of shader_recompiler_compute_tests pass.
  • Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090.

AI usage

AI (Claude Opus 5.5) was used to investigate the issue 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-10-08 19:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226) `pr/sampler-border-color-word` → `main` · +78 −4 · 2 files · 1 commits · closed without merging ## Summary Fixes the emulator exiting with `GetSamplerResource dword 3 is not a valid runtime value` in Grand Theft Auto V (PPSA04263) at the car dealership (mission with Franklin and Lamar). Pixel shader `0xf6b18542ea0e938a` builds the last word of its sampler from data resource tracking cannot follow. ## Problem The shader ORs lane-dependent data into S# word 3 before sampling. Resource tracking requires every descriptor word to be a runtime value (user data or memory it can read on the host), so the shader was rejected and the emulator exited. S# word 3 only holds the border color pointer and border color type, so sampling inside the texture does not depend on it. The same happened with the `SampleAdjust` scratch bits some shaders OR into that word, which were rejected too. ## Change When word 3 is the only untrackable word of an S#, `GetHandle` keeps the runtime-valid operand of the OR that mixes lane data into it (the user-data border fields), recursively through nested ORs, or uses zero (transparent black border) if no such operand exists, and prints a warning with the shader hash and pc. Any other untrackable sampler word still fails as before. ## Testing - Grand Theft Auto V (PPSA04263): the car dealership scene renders and the mission continues; played in my fork with this change. - `resource_tracking_tests`: new `TestUntrackableSamplerBorderWord` (word 3 falls back to a transparent black border, an untrackable word 2 is still rejected); `TestSampleAdjustSamplerScratch` now checks that the user-data part of a scratch-ORed border word is kept instead of expecting a rejection. Passes. - `resource_materialization_tests`, `memory_tracker_tests`, `page_manager_tests`, `shader_cfg_tests`, `virtual_memory_allocation_tests` and the default run of `shader_recompiler_compute_tests` pass. - Tested on Windows 11 with AMD Ryzen 5900x and RTX 3090. ## AI usage AI (Claude Opus 5.5) was used to investigate the issue 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) pixel shader 0xf6b18542ea0e938a, drawn at the car
dealership, builds S# word 3 from data resource tracking cannot follow
("GetSamplerResource dword 3 is not a valid runtime value") and the
emulator exited. Word 3 only holds the border color pointer and type, so
sampling inside the texture does not depend on it.

When only word 3 is untrackable, keep the runtime-valid operand of an OR
that mixes lane data into it (the user-data border fields), or use a
transparent black border, and print a warning. SampleAdjust scratch bits
ORed into the word are dropped the same way instead of failing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:54 +00:00
github-bot closed this pull request 2026-11-26 09:48:54 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 19:05 UTC · original · edited 2026-10-08 21:10 UTC

Review in Change Stack →

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: 0ccd3a85-78ea-44ce-aa1b-c594087c2816
📥 Commits

Reviewing files that changed from the base of the PR and between dd69ead6997f55251b92ddfdda9449df56629745 and e52056b7c2.

📒 Files selected for processing (1)
  • tests/ResourceTrackingTests.cpp

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


📝 Walkthrough

Walkthrough

When sampler descriptor dword 3 is invalid, GetHandle uses a runtime-valid operand from a bitwise-OR expression when available, or immediate zero otherwise. It emits a warning. Tests cover this fallback, confirm that other untrackable descriptor words still fail, and update sampling expectations for lane-dependent bits in sampler dword 3.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to e5205

A nested sampler expression can still lose border-color fields. The fixture-lifetime issue is fixed; the remaining rendering risk should be addressed or explicitly accepted before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 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 and concisely summarizes the main change: dropping lane-dependent bits from a sampler border-color word.
Description check ✅ Passed The description directly explains the emulator issue, the sampler word 3 fallback, the preserved failure behavior for other words, and the reported tests.
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.
  • 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 19:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#issuecomment-6067071381) · edited 2026-10-08 21:10 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/1226?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 --> <!-- 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**: `0ccd3a85-78ea-44ce-aa1b-c594087c2816` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between dd69ead6997f55251b92ddfdda9449df56629745 and e52056b7c24c38efabb8556a48ca778941df0ce6. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `tests/ResourceTrackingTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough When sampler descriptor dword 3 is invalid, `GetHandle` uses a runtime-valid operand from a bitwise-OR expression when available, or immediate zero otherwise. It emits a warning. Tests cover this fallback, confirm that other untrackable descriptor words still fail, and update sampling expectations for lane-dependent bits in sampler dword 3. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"e52056b7c24c38efabb8556a48ca778941df0ce6" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🔵 Low** · up to `e5205` <!-- final_review_risk_coverage:{"sourceCommitId":"e52056b7c24c38efabb8556a48ca778941df0ce6","coveredCommitId":"e52056b7c24c38efabb8556a48ca778941df0ce6","kind":"reviewed"} --> A nested sampler expression can still lose border-color fields. The fixture-lifetime issue is fixed; the remaining rendering risk should be addressed or explicitly accepted before merging. <!-- final_review_risk_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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 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 and concisely summarizes the main change: dropping lane-dependent bits from a sampler border-color word. | | Description check | ✅ Passed | The description directly explains the emulator issue, the sampler word 3 fallback, the preserved failure behavior for other words, and the reported tests. | | 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 --> <!-- 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=1226)! 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 -->
@ -2085,0 +2103,4 @@
return a;
}
// Both sides keep runtime bits but the OR itself is not trackable: keep neither.
return Value(0u);
Author
Owner

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve validated operands from both OR subtrees.

For (GetUserData(3) | LaneId) | GetUserData(4), the recursive calls retain both user-data values. This branch then returns zero, although runtime-valid border fields remain. Retain at least one validated operand. If the runtime validator accepts a reconstructed OR, combine both operands to preserve all available fields. Add a nested-OR case to the test. This conflicts with the stated fallback behavior.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 19:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4223051208) · edited 2026-10-08 20:53 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Preserve validated operands from both OR subtrees.** For `(GetUserData(3) | LaneId) | GetUserData(4)`, the recursive calls retain both user-data values. This branch then returns zero, although runtime-valid border fields remain. Retain at least one validated operand. If the runtime validator accepts a reconstructed OR, combine both operands to preserve all available fields. Add a nested-OR case to the test. This conflicts with the stated fallback behavior. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:35879cc0de3c93f158606ffd --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 19:06 UTC · original · edited 2026-10-08 21:12 UTC
On tests/ResourceTrackingTests.cpp line 1413 (outdated):

@@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() {
   }
 }
 
+// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot
+// follow; only that word may fall back to a constant.
+void TestUntrackableSamplerBorderWord() {
+  const auto track = [](uint32_t lane_word) {
+    Fixture fixture;
+    std::array<Value, 8> words;
+    for (uint32_t word = 0; word < words.size(); ++word) {
+      words[word] = fixture.UserData(word);
+    }
+    const auto image = fixture.Image(words);
+    std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9),
+                                       fixture.UserData(10), fixture.UserData(11)};
+    sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId);
+    const auto sampler = fixture.Sampler(sampler_words);
+    MemoryInfo memory;
+    memory.kind = ResourceKind::Image;
+    memory.image_dimension = Decoder::ImageDimension::Dim2D;
+    fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()},
+                 fixture.AddMemory(memory, 0x80));
+    fixture.PlanAndTrack();
+    return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source];

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Inspect the descriptor before destroying the fixture.

The returned DescriptorSource still contains Value references to instructions owned by fixture. After this lambda returns, the check on border.dwords[0] resolves a dangling reference. This gives the new test undefined behavior and can fail under a memory sanitizer. Perform the descriptor checks inside the lambda, then return a plain result.

✅ Confirmed as addressed by @⁠TheCruZ

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 19:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4223051215) · edited 2026-10-08 21:12 UTC On `tests/ResourceTrackingTests.cpp` line 1413 (outdated): ```diff @@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() { } } +// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot +// follow; only that word may fall back to a constant. +void TestUntrackableSamplerBorderWord() { + const auto track = [](uint32_t lane_word) { + Fixture fixture; + std::array<Value, 8> words; + for (uint32_t word = 0; word < words.size(); ++word) { + words[word] = fixture.UserData(word); + } + const auto image = fixture.Image(words); + std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9), + fixture.UserData(10), fixture.UserData(11)}; + sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId); + const auto sampler = fixture.Sampler(sampler_words); + MemoryInfo memory; + memory.kind = ResourceKind::Image; + memory.image_dimension = Decoder::ImageDimension::Dim2D; + fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()}, + fixture.AddMemory(memory, 0x80)); + fixture.PlanAndTrack(); + return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source]; ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Inspect the descriptor before destroying the fixture.** The returned `DescriptorSource` still contains `Value` references to instructions owned by `fixture`. After this lambda returns, the check on `border.dwords[0]` resolves a dangling reference. This gives the new test undefined behavior and can fail under a memory sanitizer. Perform the descriptor checks inside the lambda, then return a plain result. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:0094e1935e7fa0be16209541 --> <!-- 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-08 19:06 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: 9b8113e3-c545-4e04-b5b2-441f3b3cd2ea
📥 Commits

Reviewing files that changed from the base of the PR and between 2f4b8a335d and dd69ead6997f55251b92ddfdda9449df56629745.

📒 Files selected for processing (2)
  • 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; 1 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 19:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#pullrequestreview-5461573667) · **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**: `9b8113e3-c545-4e04-b5b2-441f3b3cd2ea` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 2f4b8a335d5e27a5153bdea670bd877a061e37b1 and dd69ead6997f55251b92ddfdda9449df56629745. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `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; 1 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=ed491941-d131-4a60-9ebb-37cde8eecb84 attempt=ab260d22-ed1f-49f5-8cc7-254de78fb8f0 batch=1/1 -->
@ -2085,0 +2103,4 @@
return a;
}
// Both sides keep runtime bits but the OR itself is not trackable: keep neither.
return Value(0u);
Author
Owner

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

I'm keeping this one as is. When both sides of an untrackable OR still carry runtime bits, keeping both would mean creating a new BitwiseOr32 in the tracking pass just for this fallback, and keeping only one of them would produce a border word that is neither the guest's value nor a well-defined default. Falling back to zero (transparent black, as the description says) is the deliberate choice there: word 3 only selects the border color, so it can only matter for samples outside the texture with a border address mode. I haven't seen that nested shape in any shader (GTA V's is a single user data | lane data OR), so I'd rather not add the extra IR construction for a hypothetical case.

**@⁠TheCruZ** on GitHub · 2026-10-08 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4224021072) I'm keeping this one as is. When both sides of an untrackable OR still carry runtime bits, keeping both would mean creating a new `BitwiseOr32` in the tracking pass just for this fallback, and keeping only one of them would produce a border word that is neither the guest's value nor a well-defined default. Falling back to zero (transparent black, as the description says) is the deliberate choice there: word 3 only selects the border color, so it can only matter for samples outside the texture with a border address mode. I haven't seen that nested shape in any shader (GTA V's is a single `user data | lane data` OR), so I'd rather not add the extra IR construction for a hypothetical case.
@ -2085,0 +2103,4 @@
return a;
}
// Both sides keep runtime bits but the OR itself is not trackable: keep neither.
return Value(0u);
Author
Owner

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

@TheCruZ, thanks for clarifying the intended fallback. I withdraw this finding. When both OR subtrees retain runtime bits, zero provides the defined transparent-black default. Keeping only one operand would produce a partial border word. Reconstructing the OR is not required by this fallback policy.


✏️ Learnings added
Learnt from: TheCruZ
Repo: KytyPS5/KytyPS5 PR: 1226
File: src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp:2105-2106
Timestamp: 2026-10-08T20:53:29.528Z
Learning: In src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp, the C++ Tracker::RuntimeOrOperand sampler dword 3 fallback deliberately returns zero (transparent black) when both subtrees of an untrackable BitwiseOr32 retain nonzero runtime-valid values. This policy avoids constructing new IR solely for the fallback or selecting an arbitrary partial border word. Preserving both operands is not a requirement of this fallback.

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

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4224025178) `@TheCruZ`, thanks for clarifying the intended fallback. I withdraw this finding. When both OR subtrees retain runtime bits, zero provides the defined transparent-black default. Keeping only one operand would produce a partial border word. Reconstructing the OR is not required by this fallback policy. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: TheCruZ Repo: KytyPS5/KytyPS5 PR: 1226 File: src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp:2105-2106 Timestamp: 2026-10-08T20:53:29.528Z Learning: In src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp, the C++ Tracker::RuntimeOrOperand sampler dword 3 fallback deliberately returns zero (transparent black) when both subtrees of an untrackable BitwiseOr32 retain nonzero runtime-valid values. This policy avoids constructing new IR solely for the fallback or selecting an arbitrary partial border word. Preserving both operands is not a requirement of this fallback. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠TheCruZ on GitHub · 2026-10-08 21:08 UTC · original
On tests/ResourceTrackingTests.cpp line 1413 (outdated):

@@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() {
   }
 }
 
+// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot
+// follow; only that word may fall back to a constant.
+void TestUntrackableSamplerBorderWord() {
+  const auto track = [](uint32_t lane_word) {
+    Fixture fixture;
+    std::array<Value, 8> words;
+    for (uint32_t word = 0; word < words.size(); ++word) {
+      words[word] = fixture.UserData(word);
+    }
+    const auto image = fixture.Image(words);
+    std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9),
+                                       fixture.UserData(10), fixture.UserData(11)};
+    sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId);
+    const auto sampler = fixture.Sampler(sampler_words);
+    MemoryInfo memory;
+    memory.kind = ResourceKind::Image;
+    memory.image_dimension = Decoder::ImageDimension::Dim2D;
+    fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()},
+                 fixture.AddMemory(memory, 0x80));
+    fixture.PlanAndTrack();
+    return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source];

Fixed in e52056b: the test now inspects the sampler descriptor inside the lambda, while the fixture that owns its instructions is still alive, and returns a plain bool.

**@⁠TheCruZ** on GitHub · 2026-10-08 21:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4224147704) On `tests/ResourceTrackingTests.cpp` line 1413 (outdated): ```diff @@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() { } } +// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot +// follow; only that word may fall back to a constant. +void TestUntrackableSamplerBorderWord() { + const auto track = [](uint32_t lane_word) { + Fixture fixture; + std::array<Value, 8> words; + for (uint32_t word = 0; word < words.size(); ++word) { + words[word] = fixture.UserData(word); + } + const auto image = fixture.Image(words); + std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9), + fixture.UserData(10), fixture.UserData(11)}; + sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId); + const auto sampler = fixture.Sampler(sampler_words); + MemoryInfo memory; + memory.kind = ResourceKind::Image; + memory.image_dimension = Decoder::ImageDimension::Dim2D; + fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()}, + fixture.AddMemory(memory, 0x80)); + fixture.PlanAndTrack(); + return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source]; ``` Fixed in e52056b: the test now inspects the sampler descriptor inside the lambda, while the fixture that owns its instructions is still alive, and returns a plain bool.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 21:12 UTC · original
On tests/ResourceTrackingTests.cpp line 1413 (outdated):

@@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() {
   }
 }
 
+// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot
+// follow; only that word may fall back to a constant.
+void TestUntrackableSamplerBorderWord() {
+  const auto track = [](uint32_t lane_word) {
+    Fixture fixture;
+    std::array<Value, 8> words;
+    for (uint32_t word = 0; word < words.size(); ++word) {
+      words[word] = fixture.UserData(word);
+    }
+    const auto image = fixture.Image(words);
+    std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9),
+                                       fixture.UserData(10), fixture.UserData(11)};
+    sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId);
+    const auto sampler = fixture.Sampler(sampler_words);
+    MemoryInfo memory;
+    memory.kind = ResourceKind::Image;
+    memory.image_dimension = Decoder::ImageDimension::Dim2D;
+    fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()},
+                 fixture.AddMemory(memory, 0x80));
+    fixture.PlanAndTrack();
+    return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source];

@TheCruZ, thanks for the fix. The updated lambda checks the descriptor while fixture is alive and returns a plain bool. This removes the dangling-reference access.


🧠 Learnings used
Learnt from: TheCruZ
Repo: KytyPS5/KytyPS5 PR: 1226
File: src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp:2105-2106
Timestamp: 2026-10-08T20:53:32.955Z
Learning: In src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp, the C++ Tracker::RuntimeOrOperand sampler dword 3 fallback deliberately returns zero (transparent black) when both subtrees of an untrackable BitwiseOr32 retain nonzero runtime-valid values. This policy avoids constructing new IR solely for the fallback or selecting an arbitrary partial border word. Preserving both operands is not a requirement of this fallback.

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 21:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1226#discussion_r4224182014) On `tests/ResourceTrackingTests.cpp` line 1413 (outdated): ```diff @@ -1390,6 +1390,36 @@ void TestUniformizedMaterialImageKeys() { } } +// GTA V PS 0xf6b18542ea0e938a computes its sampler's border color word in a way tracking cannot +// follow; only that word may fall back to a constant. +void TestUntrackableSamplerBorderWord() { + const auto track = [](uint32_t lane_word) { + Fixture fixture; + std::array<Value, 8> words; + for (uint32_t word = 0; word < words.size(); ++word) { + words[word] = fixture.UserData(word); + } + const auto image = fixture.Image(words); + std::array<Value, 4> sampler_words{fixture.UserData(8), fixture.UserData(9), + fixture.UserData(10), fixture.UserData(11)}; + sampler_words[lane_word] = fixture.Emit(ValueOpcode::LaneId); + const auto sampler = fixture.Sampler(sampler_words); + MemoryInfo memory; + memory.kind = ResourceKind::Image; + memory.image_dimension = Decoder::ImageDimension::Dim2D; + fixture.Emit(ValueOpcode::ImageSampleRaw, {image, sampler, fixture.ImageAddress()}, + fixture.AddMemory(memory, 0x80)); + fixture.PlanAndTrack(); + return fixture.program.descriptor_sources[fixture.program.info.samplers[0].source]; ``` `@TheCruZ`, thanks for the fix. The updated lambda checks the descriptor while `fixture` is alive and returns a plain `bool`. This removes the dangling-reference access. --- <details> <summary>🧠 Learnings used</summary> ``` Learnt from: TheCruZ Repo: KytyPS5/KytyPS5 PR: 1226 File: src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp:2105-2106 Timestamp: 2026-10-08T20:53:32.955Z Learning: In src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp, the C++ Tracker::RuntimeOrOperand sampler dword 3 fallback deliberately returns zero (transparent black) when both subtrees of an untrackable BitwiseOr32 retain nonzero runtime-valid values. This policy avoids constructing new IR solely for the fallback or selecting an arbitrary partial border word. Preserving both operands is not a requirement of this fallback. ``` </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=Prevent%20UB%20from%20dangling%20instruction%20references%3A%20inspect%20descriptors%20while%20the%20fixture%20is%20alive%2C%20then%20return%20plain%20results.%20Try%20%40coderabbitai%20for%20sharp%20code%20reviews%20%F0%9F%A9%BA%E2%9A%A1&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1226%23discussion_r4223051215)? 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 -->

Pull request closed

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