shader: drop lane-dependent bits from a sampler border color word #1226
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1226
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1226/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TheCruZ on GitHub · 2026-10-08 19:00 UTC · original
pr/sampler-border-color-word→main· +78 −4 · 2 files · 1 commits · closed without mergingSummary
Fixes the emulator exiting with
GetSamplerResource dword 3 is not a valid runtime valuein Grand Theft Auto V (PPSA04263) at the car dealership (mission with Franklin and Lamar). Pixel shader0xf6b18542ea0e938abuilds 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
SampleAdjustscratch bits some shaders OR into that word, which were rejected too.Change
When word 3 is the only untrackable word of an S#,
GetHandlekeeps 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
resource_tracking_tests: newTestUntrackableSamplerBorderWord(word 3 falls back to a transparent black border, an untrackable word 2 is still rejected);TestSampleAdjustSamplerScratchnow 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_testsand the default run ofshader_recompiler_compute_testspass.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.
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.@coderabbitai[bot] on GitHub · 2026-10-08 19:05 UTC · original · edited 2026-10-08 21:10 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
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.cppIncluded 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,
GetHandleuses 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:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
e5205A 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)
✅ Passed checks (4 passed)
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 helpto get the list of available commands.@ -2085,0 +2103,4 @@return a;}// Both sides keep runtime bits but the OR itself is not trackable: keep neither.return Value(0u);@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 · edited 2026-10-08 21:12 UTC
On
tests/ResourceTrackingTests.cppline 1413 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Inspect the descriptor before destroying the fixture.
The returned
DescriptorSourcestill containsValuereferences to instructions owned byfixture. After this lambda returns, the check onborder.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 · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
9b8113e3-c545-4e04-b5b2-441f3b3cd2ea📥 Commits
Reviewing files that changed from the base of the PR and between
2f4b8a335dand dd69ead6997f55251b92ddfdda9449df56629745.📒 Files selected for processing (2)
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
@ -2085,0 +2103,4 @@return a;}// Both sides keep runtime bits but the OR itself is not trackable: keep neither.return Value(0u);@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
BitwiseOr32in 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 singleuser data | lane dataOR), 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);@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
✅ Review thread resolved.
You are interacting with an AI system.
@TheCruZ on GitHub · 2026-10-08 21:08 UTC · original
On
tests/ResourceTrackingTests.cppline 1413 (outdated):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.@coderabbitai[bot] on GitHub · 2026-10-08 21:12 UTC · original
On
tests/ResourceTrackingTests.cppline 1413 (outdated):@TheCruZ, thanks for the fix. The updated lambda checks the descriptor whilefixtureis alive and returns a plainbool. This removes the dangling-reference access.🧠 Learnings used
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.
Pull request closed