gpu: make guarded address ranges resident before the shader runs #1506
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!1506
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1506"
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?
@NeySlim on GitHub · 2026-10-14 11:56 UTC · original
NeySlim:fix/bda-range-residency→main· +607 −0 · 9 files · 2 commits · openTested in God of War Ragnarok (PPSA08332, 05.005).
On the first boot, the first shot of the intro video (after "Sony Interactive Entertainment presents") plays as green and magenta blocks, and so does the God of War recap video started from the menu, until the next cut. Later shots are clean, and playing the recap a second time in the same session is clean too.
Cause: the Bink decoder runs on the GPU. Its DC prediction pass (CS 0x5c046e9ef798f2bc) reads a bit table with
global_load_dword v19, v13, s[0:1], base from user data, offset((row >> 5) + 8) << 4withrow = step - lane, behind an EXEC guardrow < height(v_cmp_gt_u32+s_and_saveexec). The page holding the table has no buffer in the buffer cache yet, so the BDA read returns 0 and sets a fault bit. The fault path creates the buffer after the dispatch, a few frames later. The key frame is predicted from a zero table and the P frames carry the error until the next key frame.Change:
ExtractResourcePlanrecords, for each Global/Flat/ScalarAddress access whose base the host can evaluate, an upper bound of its 32-bit offset. The bound comes from the shape of the offset (add, mul, immediate shifts, and/min/max, or, bfe, lane id, a select whose condition is implied by the access predicate) or from an unsigned compare that the access predicate requires (the EXEC guard). Leaves are values the host already evaluates (user data, SRT reads). No proof means no range, and the access keeps the fault path.MaterializeResourcesevaluates the bounds with the strict reader (no read outside the mapping). A result that does not fit in 32 bits gets no range, since the shader offset could wrap. The ranges go intoResourceSnapshot::address_ranges.RenderExecutor::FindBufferscalls the newRenderContext::MakeAddressRangeResidentfor them, before the descriptor buffers:FindBufferon the GPU-mapped parts of each range. Ranges above 256 MiB are skipped, like unbounded descriptor ranges.This is not the GPU-side scalar load change that was reverted (
5b68a26c, reverted in1c301c9abecause it hung the GPU on this same shader), and not #1344, which made those scalar loads resident: no load moves from the host to the GPU here. The vector load already uses BDA on main; the host only creates buffers before the dispatch for ranges it can bound from the access itself, and anything it cannot prove stays exactly as on main.Limits: accesses through a 64-bit per-lane pointer, and offsets that cannot be bounded (loop counters, values read from memory), still go through the fault path and read 0 the first time.
Testing (Linux, Radeon 8060S, RADV 26.2.3):
AddressRangeResidency(--address-range-residency-only): real direct memory andRenderContext,DispatchDirectof a shader shaped like the game's (s_load,row = step - lane,v_cmp_gt_u32,s_and_saveexec, SADDRglobal_load_dword,buffer_store). Without the change: "lane 9 read 0 instead of 4127".TestAddressRangesFollowAccessGuards(resource_materialization): exact range, no range without the guard, no range when the bound can overflow.FindBufferonly on the end of the range is caught too, as the table straddles a cache page.Not tested on Windows. The change has no platform-specific code.
Before (left) and after (right):
AI use
I used Claude Code to write the change and the tests and to run the measurements above. I reviewed the code and the results before opening the PR.
@coderabbitai[bot] on GitHub · 2026-10-14 12:03 UTC · original · edited 2026-10-16 15:44 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
42975da8-9cb2-4a62-9a6d-d7473e00e86b📥 Commits
Reviewing files that changed from the base of the PR and between 130dd657af34168edb97d199dbc32383ab2aa66f and
0a6c8eab2d.📒 Files selected for processing: 2
src/graphics/host_gpu/renderer/renderContext.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
The shader recompiler plans bounded address ranges for eligible shader accesses and records evaluated ranges in runtime resources. The renderer makes mapped portions of those ranges resident before resolving buffer descriptors. Tests cover guarded accesses, offset bounds, and guarded global table loads.
Suggested reviewers:
shadowbeat070Priority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
0a6c8The change makes guarded GPU-mapped address ranges resident before shader dispatch, which fixes the reported video glitches. The supplied context shows no remaining merge-blocking risk. It was not tested on Windows.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 7 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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.@coderabbitai[bot] on GitHub · 2026-10-14 12:03 UTC · original · edited 2026-10-14 22:22 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 1537 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12544
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42102
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 45669
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41993
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 40967
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42508
Restore specialization flags after address-range planning.
AddressRangePlannercan clone a validLoadBufferU32used in an address-resource base or bounded offset.Clonethen sets both specialization flags afterMarkCleanReadshas completed. This can makeMaterializeResourcesreturnfalsewhenread_specialization_memoryis null. If the stage has existing SRT reads, the late capture flag can also capture those reads and makeCommitBindingsabort for a pipeline with address writes.SrtWalker ranges(program, CleanRuntime(runtime))can evaluate the cloned leaf when the callback exists, so the range plan does not require these flags to remain set.Suggested fix
✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-14 12:03 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
c319bd78-349b-4588-a42f-318d419770dc📥 Commits
Reviewing files that changed from the base of the PR and between
9e41d8320aand c8bfd94569dd16db428a4db70d87b89fa0eb4969.📒 Files selected for processing: 9
CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/shader/recompiler/ir/ResourceSnapshot.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceMaterializationTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@NeySlim on GitHub · 2026-10-14 22:22 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 1537 (outdated):Right, a LoadBufferU32 in a range base or limit set both flags after the capture pass. Range reads go through their own strict walker, so the flags are now restored after planning (99f5a2ea2). TestAddressRangesFollowAccessGuards has a buffered-limit case that fails without it.
@coderabbitai[bot] on GitHub · 2026-10-14 22:22 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 1537 (outdated):@NeySlim, thanks for the fix. The supplied code restores both specialization flags after address-range planning, so range-only reads no longer enable specialization requirements or capture. The reported buffered-limit regression case covers the triggering path.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-16 02:33 UTC · original · reviewed
🧹 Nitpick comments: 1
ℹ️ Review info
⚙️ Run configuration
c59cff09-e32e-42f1-991c-fdfba809be5b📥 Commits
Reviewing files that changed from the base of the PR and between 99f5a2ea2b5cebedf9bc56049da99b8bbe735a5b and a58ae1b852b5a6439cbf561eeddc2f2e3b42f1f0.
📒 Files selected for processing: 6
CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceMaterializationTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@NeySlim on GitHub · 2026-10-16 03:31 UTC · original
Moved the table so the rows straddle a cache page (c383cabcc). The end-only
FindBuffermutation now fails at lane 29.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.