shader: fix indirect light tables instead of tolerating stale slots #1255
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!1255
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1255"
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-08 20:26 UTC · original
NeySlim:fix/bitscan-mask-keys→main· +579 −12 · 4 files · 1 commits · openThis replaces #1119, which was rightly closed as a hack: instead of binding null images or downgrading errors for "stale" descriptor-table slots, it fixes why those slots were read. The error was reproduced on God of War Ragnarök (PPSA08332, 05.005) with the #1119 tolerances removed.
Part of the original PR landed on main in the meantime (
735a2292,652154ae,9bcf80bf), and main's dimension rules (b6da0683) now cover what the mixed-dimension commits did for this game, so they were dropped. What is left is the bit scan bound.shader: bound bit scan image keys by mask bits and table count
Error:
sampled image descriptor 17 uses unsupported format 2, theninvalid data image range: address=0x10391a700000(a 64-bit pointer read as a T#), from the clustered-lighting compute shaders (e.g.4579381eaaeeead7,2bbe19f271202135).Cause: the light tables are walked with a bit scan (
s_ff1_i32_b32/s_bitset0_b32) and the planner probed all 32 keys. The shader only visits the set bits of its mask, the mask is a 12-bit field (s_bfe_u32 ..., 0xc0010), and the loop exits atkey >= count, withcountread from the table (s_cmp_ge_u32directly or through a flags_cselect/s_or/s_cmp_lg_u32 0). Records pastcounthold unrelated data.Change: the plan keeps the scanned mask when it can be evaluated (
ScannedMask), its width (MaskWidth, kept as the descriptor'skey_limit), and akey < countbound proven on every edge that reaches the sample (ScanBound). Materialization enumerates the set bits within[0, min(count, width)), so the plan adds no instruction to the shader. The entry mask is used only when every back edge provably clears bits of it; that proof resolves a lane select to one arm only behind a uniform branch or an EXEC branch.Tests:
TestBitScanKeyRangeandTestBitScanMaskProofinresource_tracking_tests.TestBitScanKeyRangefails on main without this commit.Validation
Linux, Radeon 8060S, Mesa RADV 26.2.4, rebased on
42bb0da5.shader_recompiler_compute_testsone case per process: same 52 failures as main on this setup (out of 775).Not tested on Windows or macOS; the change is platform-independent recompiler code.
AI use
I used Claude Code (AI agent) to reproduce the errors without the tolerances, trace them to their causes in the shaders, write the changes and the tests, and run the tests and the game above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-08 20:33 UTC · original · edited 2026-10-17 07:55 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
d2759c64-91df-4757-b624-d721dfe13baa📥 Commits
Reviewing files that changed from the base of the PR and between f42dfe429c52c551e248d7a9ba9c1afe52aae0e3 and 06e6dc5d6e2aa53a1937c68a6e07a3b298a9aa72.
📒 Files selected for processing (6)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
📝 Walkthrough
📝 Walkthrough
Walkthrough
The image source path now uses a temporary upload buffer when the staging ring cannot map the requested range. Resource tracking derives bounds for bit-scan indirect image selectors and records image-use patterns. Materialization enumerates selected keys and checks candidate compatibility. The SPIR-V emitter limits coordinates to the instruction dimension. New tests cover oversized image uploads and indirect image tracking, materialization, and emission.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
06e6dThis change fixes indirect image light tables and adds a fallback upload path for oversized images, with test coverage for each fix. No outstanding issues were identified in the reviewed changes, and earlier review concerns have been addressed.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 31.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 6 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-08 20:33 UTC · original · edited 2026-10-08 21:50 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 652 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exclude multisampled candidates from
mixed_dimensions.mixed_dimensionsaccepts a candidate of any dimension.DescriptorDimensionmapskColor2DMsaaandkColor2DMsaaArraytoDim2DMsaaandDim2DMsaaArray. The normalize callback nulls a dimension mismatch only for bounded tables. It does not null mismatches for bit-scan tables or for explicitly selectedsources.Consider a heap that contains an MSAA render-target descriptor in a plain-sample table. That candidate now passes the check at Lines 669-671. Before this change, the check rejected it.
EmitSampleinspirvEmitterImage.cppthen emitsOpSampledImageandOpImageSample*on a multisampled image. SPIR-V does not allow either operation on an image with MS=1. The module is invalid and can fail pipeline creation or crash the driver.Reject multisampled candidates when their coordinates differ from the exemplar's.
🐛 Proposed fix
In the candidate check, add this condition:
✅ Addressed in commits 19a361f to cfe3000
@coderabbitai[bot] on GitHub · 2026-10-08 20:33 UTC · original · edited 2026-10-08 21:51 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 653 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23919
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24288
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12728
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2165
Do not reuse the root sampler for mixed numeric classes.
EmitSampleuses each candidate's image type but passes the samemem.samplerto every candidate.ApplyResourceSpecializationselects that sampler from the indirect root. Therefore, an integer candidate under a float root can use float border-color settings and linear filtering. The reverse case can also use integer-root settings, including point filtering forPointInteger.Restrict mixed numeric classes to candidates with the same
SamplerClass, or add per-class sampler variants for indirect candidates.🐛 Suggested fix
✅ Addressed in commits 19a361f to cfe3000
@coderabbitai[bot] on GitHub · 2026-10-08 20:33 UTC · original · reviewed
Actionable comments posted: 2
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
0596e6f3-da84-46a8-ac07-c5fc7e90edf4📥 Commits
Reviewing files that changed from the base of the PR and between
2f4b8a335dand 720d10cc976f28cc0af5f0bfa1857406017edc22.📒 Files selected for processing (6)
src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.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-08 21:46 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 652 (outdated):Agreed, fixed in 19a361f1. Once a plain sample accepted candidates of another dimension, a multisampled record in a bit scan table or in explicitly selected sources passed the check (only bounded tables drop a dimension mismatch), and
EmitSamplewould have emittedOpSampledImage/OpImageSample*on an MS=1 image. Indirect tables are only sampled, so a multisampled candidate now refuses the table on every table shape, whatever its coordinates. This also covers a table whose records are all multisampled, which was accepted before this PR and produced the same invalid module. Tests:TestBoundedImageViewEligibility(an explicitly selected 2D MSAA record) andTestBitScanKeyRange(a scanned 2D MSAA record) inresource_tracking_tests; both fail without the change.@NeySlim on GitHub · 2026-10-08 21:46 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 653 (outdated):Agreed, fixed in bfe34a23 by restricting the table rather than adding per-class samplers. I first checked what the game needs: the only float/uint mix in its light tables was the record past the table count, a 64-bit pointer read as a 2D 8_UINT T#, which fb72234e no longer reads. A 10-minute run from a new game with a trace on candidates of another class found none; a second 10-minute run with this change reports no
incompatible candidates. Candidates must already share their conversion format, so requiring the sameSamplerClassamounts to requiring the same numeric class: the table now keeps one numeric class, the root's sampler variant fits every candidate, and the per-candidate result type and bitcast inEmitSampleare gone. A record of another class gets the explicitincompatible candidateserror. Test:TestBoundedImageViewEligibilitynow refuses an explicitly selected record of another numeric class and fails without the change;IndirectImageMixedCandidatesis removed with the emitter path it covered. While checking the same rule I also excluded depth-compare samples from mixed dimensions in cfe30003, since there is no 3D comparison sample;TestBoundedImageViewEligibilitycovers it and fails without the change.@coderabbitai[bot] on GitHub · 2026-10-08 21:50 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 652 (outdated):@NeySlim, thanks for the clarification and fix. The unconditionalis_msaa(image.dimension)check inBuildResourceSpecializationcovers both mixed-dimension tables and tables whose candidates are all multisampled. This is stronger than my proposed coordinate-dependent check.The two reported regression tests cover explicitly selected and bit-scan candidates.
✏️ Learnings added
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:51 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 653 (outdated):@NeySlimThanks for the explanation and the fix. The suppliedBuildResourceSpecializationcode now rejects candidates with a different numeric class. With the existing conversion-format check, the root’s sampler variant fits every candidate. This addresses the sampler-reuse concern without per-class samplers.The code also excludes comparison samples from the mixed-dimension relaxation. Your reported
TestBoundedImageViewEligibilitycases cover both restrictions. I have not run the tests.✏️ Learnings added
🧠 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.
@NeySlim on GitHub · 2026-10-09 10:18 UTC · original
Follow-up to an independent review; each commit adds a test that fails without it:
image_sample_la 3D or array candidate took the LOD as its depth or slice. The emitter now reads only the coordinates the instruction supplies; the others are zero, as a plain sample already got them. (The game samples these tables with a 3Dimage_sample_lz.)image_sampleselects each record's own view; loads, gathers and queries read through the root's view. Mixed dimensions are now accepted only when every use of the table is a sample (ImageResource::sample_only, merged at tracking time).image_loadof a multisampled table works as before this PR.t = mask | bit; t & (c ? t : mask)in the test).s_cbranch_vccnzEXEC is unchanged and lanes with VCC clear also run the arm. Only uniform and EXEC edges resolve a select now.key_limitand applied at materialization, instead of aUMin32inserted into the shader per handle; an immediate count now bounds the scan too.@NeySlim on GitHub · 2026-10-09 11:01 UTC · original
Rebased on main after the CFG rework; tests adapted to the new IR structures: the bit scan tests set terminators and branch conditions on the blocks themselves (
Block::terminator,Block::condition) instead ofProgram::block_info, and the compute checks collect bindings withCollectShaderInfoinstead ofAllocateBindings. No change to the fixes. Each commit still builds, each new test still fails without its fix, andshader_recompiler_compute_testsone case per process gives the same results as main (598 of 608 pass, the other 10 fail on main too on this RADV setup).@coderabbitai[bot] on GitHub · 2026-10-09 11:08 UTC · original · edited 2026-10-09 12:14 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1377 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 40783
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5502
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42371
Remove sibling-phi substitution on loop back arms.
ScannedMaskpasses the update arm toClearsBitsOf, andClearsBitsOfcallsArmValuebefore checking the update. On a loop back arm,Sis the current-iteration value in the loop body. Replacing it withS.Arg(back)reads the value for the next iteration. This can makeClearsBitsOfaccept a mask update that can gain bits.The same substitution can make a sibling-phi predicate select the wrong arm.
🐛 Suggested fix
Add a
TestBitScanMaskProofvariant with a mask that swaps through a sibling phi.selector_maskmust remain empty.📝 Committable suggestion
✅ Addressed in commit f42dfe4
@coderabbitai[bot] on GitHub · 2026-10-09 11:08 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
e7cf2885-4bad-4343-839f-39866db5f5f1📥 Commits
Reviewing files that changed from the base of the PR and between cfe3000305cfa6f630b3fc96cd0330660ae5e303 and 9417f07924b3c58c617c3fcf2063fb62091a2502.
📒 Files selected for processing (6)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@NeySlim on GitHub · 2026-10-09 12:14 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1377 (outdated):Confirmed and fixed in f42dfe42. A mask whose back arm is a sibling header phi (the sibling starts from another word and takes the cleared mask on the back edge) was accepted and evaluated from its entry value.
ArmValueno longer substitutes sibling phis at all: on the entry arm the case cannot occur, since values from before the loop cannot reference a header phi, so there was nothing to keep.TestBitScanMaskProofhas aSwapsThroughSiblingvariant that fails without the fix.The game does not rely on it: I translated all 560 compute and pixel shaders dumped from the game (wave32 and wave64) with both versions. No bit scan proof ever reached a sibling phi, and every proof (including the light-table shaders) gives the same result.
@coderabbitai[bot] on GitHub · 2026-10-09 12:14 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1377 (outdated):@NeySlim, thanks for the fix and clarification. The suppliedArmValueimplementation no longer substitutes sibling header phis. Removing the substitution entirely is correct: pre-loop values cannot reference a header phi.The reported
SwapsThroughSiblingregression test covers the invalid proof. Your comparison of all 560 dumped shaders also indicates that this fix does not change the game’s bit-scan proof results.✏️ Learnings added
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.
@NeySlim on GitHub · 2026-10-09 18:52 UTC · original
Rebased on main after
71c72617(indirect texture dispatch shared with image loads). The sample changes now sit onEmitImageAccess. Since loads now fetch each candidate through its own view, the rules changed in one new commit (06e6dc5d):CoordF32andCoordU32: every candidate reads only the coordinates the instruction's dimension supplies, the others are zero. It now covers loads too: a 3D candidate of a 2Dimage_load_mipno longer takes the LOD as its depth, and on main a 2D array candidate of such a load read the LOD as its layer. Any other caller, such as the gathers and queries of #1320, gets the same rule.image_sampleand now also byimage_load. A load candidate of another dimension must not be a cube (no fetch through a cube view) and must be multisampled exactly when the instruction is. Gathers and queries still require one dimension; with #1320 they dispatch per candidate, so they could be allowed later if a game needs it.Tests:
TestIndirectImageTableOperationsnow accepts mixed loads and refuses a cube load candidate or a multisampled mismatch; new host testIndirectImageLoadCoordinates(2D load with a 3D candidate: depth 0, LOD kept; 2D MSAA array load with a 2D MSAA candidate: fragment index from the instruction). Each rule of the PR fails its test when removed (rechecked after the rebase). CPU suites pass; GPU suite one case per process: 603 of 613 pass, main 602 of 612, same 10 failures. Body updated.@NeySlim on GitHub · 2026-10-09 21:54 UTC · original
Rebased on current main and pushed 2ec8eeb5. The one-numeric-class rule from 874ed0fe was wrong for this game: a scene samples a sample-only table at pc
0x2c1cthat mixes a Uint 2D T# with Float cube and 2D array T#s, and the shader then stopped onincompatible candidates. The per-class sampler variants are needed after all. Sample-only tables may mix classes again: each candidate is sampled with its own image type, its result bitcast to the instruction's type, and the S# variant of its own class (the one a direct sample of that record gets), so the root's variant is no longer applied to other classes. Tables also read byimage_loadkeep one class. New tests:TestMixedCandidateSamplersand the GPU part ofIndirectImageMixedCandidates(each lane reads its record's texel bits and its own variant's border); both fail when the rule is removed.@NeySlim on GitHub · 2026-10-11 18:18 UTC · original
Rebased on main after
4c87dbeband984cfceb. The conflicts were in the sample path: I kept main's per-candidate texel offsets and the new EXEC operand, and re-applied the per-class sampler variant and the per-candidate sample type on top. Nothing was dropped: this PR never changed gathers, and gathers and queries still require one dimension and one numeric class. The tests now pass the EXEC operand ofImageSampleRaw/ImageGatherRaw.resource_tracking,resource_materialization,scalar_provenanceandshader_cfgpass; removing the bit scan bounds, the mask proof rules, the coordinate rule, the multisample rules or the per-class sampler variant still makes the matching test fail. GPU suite one case per process: 614 of 624, the same 10 failures as main (613 of 623).@NeySlim on GitHub · 2026-10-14 07:04 UTC · original
Rebased on main. Part of this landed in
735a2292,652154aeand9bcf80bf; what is left is the bit scan key bound, the coordinate fix for candidates of another dimension and the mixed-dimension tables, now split into three commits.@NeySlim on GitHub · 2026-10-17 07:55 UTC · original
Rebased on main (
42bb0da5). Afterb6da0683the mixed-dimension commit conflicts with main's rule (1D/2D mixing only for unfiltered loads and stores, and a 1D access must not take a 2D record), so I checked whether God of War still needs it.It doesn't. With the bit scan bounds in place, traced runs from a new game through the sled section planned 353 indirect image tables and every one had a single dimension: 250 all 3D under
image_sample_lz, 103 all cube underimage_sample_l. The cross-dimension record that motivated the rule was the record past the table count, which the bit scan commit no longer reads, and a cube/2D array mix is already covered by main's 2D/2D array rule.So I dropped "sample and load mixed-dimension indirect image candidates" and "read only the instruction's coordinates" from this PR. What's left is the bit scan bound (mask bits and table count). Main's finite bit mask worklists don't cover it:
TestBitScanKeyRangefails on main without this commit. resource_tracking, resource_materialization, scalar_provenance and shader_cfg pass; GPU suite one case per process: same 52 failures as main (out of 775).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.