shader: skip image remapping for eliminated image instructions #1112
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!1112
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1112/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?
@Nawid3333 on GitHub · 2026-10-06 18:47 UTC · original
Nawid3333:fix/unused-image-remap→main· +50 −2 · 2 files · 1 commits · closed without mergingProblem
A shader whose image instruction ends up unused can abort the whole shader compile with
in
ImageRemap::operator[], called fromApplyResourceSpecialization(ResourceMaterialization.cpp).Cause
memory_infoentry per memory instruction. For an image,resourcestarts as the descriptor's SGPR number divided by 4.memory_infoentries stay in the list.ApplyResourceSpecializationthen remaps every image entry. A stale value at or past the number of specialized images tripsEXIT_IF(index >= source_count), and the compile aborts.Any shader can reach this when one of its image results is unused after Kyty's own optimization and the stale value is large enough, e.g. a compute shader whose only image instruction is an unused
image_load, or a pixel shader that exports one sample and also has an unusedimage_loadfroms[8:15]. I haven't seen a game log with this abort, so this is a robustness fix found through the in-tree tests.Fix
While the existing per-instruction loop visits image instructions, record which
memory_infoentries live image instructions reference, and remap only those. The marking happens before the FMASK branch cancontinue, so a live FMASK read is still marked.GetImageResourceflags, buffer image aliases, sampled pairs and indirect roots always refer to live resources and are remapped exactly as before. TheEXIT_IFstays in place for live instructions, so a wrong index on a live image still fails loudly.I checked every other reader of
memory_infoon currentmain(SPIR-V emitter,BindingLayout,Program,SrtWalker,Tessellation,ShaderRecompiler): all of them index it through a live instruction'sMemoryFlags, so nothing reads the entries this change leaves alone.How to reproduce
TestNewShaderRecompilerUnusedImageInstructions(added totests/shaderCfgTests.cpp) covers both cases above:With this PR it passes. With only the source change reverted (test kept), it stops with the
EXIT_IFabove.Commit
One commit: the fix (+8/−2 in
ResourceMaterialization.cpp) and the test (+42). Only the changed lines follow the repo's clang-format hook; the rest of the file is left as it is onmain.Testing
Windows 11, clang-cl 19.1.5, Release, AMD RX 9070 XT, on
maind2413fc2:shader_cfg,resource_materialization,resource_trackingpass.ctestrun (53 tests) plus every--xxx-onlymode ofshader_recompiler_compute_tests(107 modes), this branch vs.main: identical results.Before/after on Windows, macOS and Linux (fork CI, https://github.com/Nawid3333/KytyPS5/actions/runs/37545499813): with the source change reverted, the new test stops with the
EXIT_IFabove on all three; with it, the test passes.CI on this PR: Windows, Linux and macOS pass (they run
resource_trackingandresource_materialization).Related PRs
live_image_accessvector in 9ab3d7bb, inside "bindless textures behind --bindless"), credit to @itsmemac. It is part of a 51-commit PR that currently conflicts withmainand has no regression test for this case; this PR is the standalone version against currentmain.if (memory.resource < image_remap.indices.size()). That stops the abort, but it would also silently skip a live image with a bad index, which theEXIT_IFis there to catch; this PR only skips entries of deleted instructions.If you'd rather fix this at the source instead (for example, marking unpatched image entries dead in resource tracking), I'm happy to rework it that way.
AI use (per the README's AI policy): Claude (Anthropic) diagnosed the root cause, wrote the fix and the test, and ran the testing above on my machine; a second AI pass reviewed the fix adversarially. I reviewed the change and the results before marking this PR ready.
🤖 Generated with Claude Code
@Nawid3333 on GitHub · 2026-10-06 20:50 UTC · original
@coderabbitai review
@coderabbitai[bot] on GitHub · 2026-10-06 20:51 UTC · original · edited 2026-10-06 20:54 UTC
✅ Action performed
Review finished.
@coderabbitai[bot] on GitHub · 2026-10-06 20:54 UTC · original · edited 2026-10-07 15:25 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
2d91173c-3946-43b8-8012-0d4cbed8167f📥 Commits
Reviewing files that changed from the base of the PR and between 97849ee350745af1f3f2fb1bc0efdfc95bdff86d and f016017a3c34895c2e8da75fa9f7621c78d33421.
📒 Files selected for processing (1)
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
ApplyResourceSpecializationnow remaps image memory entries only when image instructions reference them, and only when they are image resources that are not planning-only. New tests check resource counts for unused image loads in compute and pixel shaders. Both tests validate SPIR-V.Priority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
f0160No confirmed merge-blocking issue remains; the change is ready for normal merge checks.
🚥 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.Pull request closed