shader: support mixed indirect image candidates and bounded keys #852
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!852
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/852/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?
@tototomate123 on GitHub · 2026-09-26 16:13 UTC · original
tototomate123:fix/hfw-indirect-image-candidates→main· +1980 −595 · 6 files · 12 commits · closed without mergingDepends on #811. This follow-up handles image descriptor candidates that differ between 2D and 3D textures and lets indirect mappings serve dimension queries and image reads. It builds on #811 s address backed indirect descriptor tracking. Until #811 merges, GitHubs diff against
mainalso includes the commits from #811.Changes
Manual result and remaining issue
With local build
b2c394d, Horizon Forbidden West (PPSA01521) gets past the earlier shader tracking and materialization failures and consistently renders the loading screen after New Game. It remained on that screen for at least five minutes in more than two manual runs; no new shader or fatal error appeared.i3STzxuwPx0[Rudp_v1][Rudp_v1.1][Func]is called repeatedly but remains unresolved. The cause of the loading screen wait is not yet known.Validation
cmake --build _Build/linux --target resource_tracking_tests resource_materialization_tests shader_recompiler_compute_tests kyty_emulator -j 4passed after merging upstreammainatae39466.ctest --test-dir _Build/linux --output-on-failure -R '^(resource_tracking|resource_materialization|shader_recompiler_compute)$'passed after that merge (3 tests).clang-formatpre-commit hook.b2c394d; no game run has been performed after the upstreammainmerge.AI assistance was used to investigate the crashes, implement the shader changes, review the C++ changes, write regression tests, and run local checks. I manually tested the game and reviewed the resulting behavior, crash logs and parts of the code.
@coderabbitai[bot] on GitHub · 2026-09-26 16:25 UTC · original · edited 2026-09-30 13:46 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
Resource tracking now recognizes address-key, buffer-record, and loop-derived indirect-image selectors. Materialization enumerates selector keys, builds candidate mappings, and validates candidate compatibility. It supports simple 2D/3D candidate combinations when the image metadata permits them. The SPIR-V emitter uses candidate-specific operations for sampling, dimension queries, and reads, and limits coordinates to supplied address components. Tests cover selector tracking, materialization, and emitted image operations.
Suggested reviewers:
nmzik,senaxxPriority: ⬇️ Low
Change: Feature
Merge Risk: 🟡 Moderate · up to
32e6bFor some indirect texture selectors, shaders can sample the wrong texture. This happens when a bounded loop selector has a large member offset, or when bounded and unbounded uses share one source. Fix both before merging.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
32e6bThe new bounded image-selection rules can merge distinct selection bounds or inspect the wrong slots, potentially selecting the wrong image. Guest-memory checks and descriptor validation remain in place; no host-memory escape was demonstrated.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 4.49% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 89 functions across 5 files. (1 skipped: 1 too large.)
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-09-26 16:25 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
2c975fd3-aa87-4151-8757-a8c7839a5057📥 Commits
Reviewing files that changed from the base of the PR and between
16b83a034candae39466e14.📒 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 10 included reviews per hour; 9 remain after this review.
@ -740,2 +815,3 @@(!a.selector_mask.IsEmpty() &&!EquivalentValue(m_program, a.selector_mask, b.selector_mask))) continue;!EquivalentValue(m_program, a.selector_mask, b.selector_mask)))continue;@coderabbitai[bot] on GitHub · 2026-09-26 16:25 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Compare
selector_limitwhen you intern indirect image sources.InternSourcenow compares the new key metadata:record_key,address_key,address_key_count,key_scaleandkey_bias. It does not compareselector_limit.TryMakeIndirectImagesetsselector_limitonly when the selector's loop bound isSMin32(x, cap).Consider two handles that read the same material and table with the same stride and offsets. If only one of them is in an
SMin32-bounded loop, both handles intern to the sameDescriptorSource. The metadata of the first handle wins.AddImagekeys bysource, so both handles also share oneImageResourceand one key mapping.If the bounded handle comes first,
MaterializeIndirectImageprobes onlyselector_limitrecords. Keys that only the unbounded handle can reach are then missing from the mapping. At runtime,EmitImageCandidateSwitchsends a missing key to candidate 0, which samples the wrong texture.🐛 Proposed fix
📝 Committable suggestion
@tototomate123 on GitHub · 2026-09-26 18:43 UTC · original · edited 2026-09-26 21:17 UTC
HFW loading investigation update
The latest contributor-run build (
ae39466-dirty) reaches VS 11 / PS 9 / CS 55 after a local AMM allocator fix. The previous loading stall was caused by an observable allocation failure rather than slow shader compilation.The current stopping point is a separate audio assertion after unresolved
eDFeTyi+G3Y(sceAjmDecMp3ParseFrame).These are local follow-up changes and are not part of this PR. The shader changes described in the PR body remain the scope of #852.
Follow-up investigation
sceAjmDecMp3ParseFrame(eDFeTyi+G3Y) and the metadata the game's caller expects. This has not yet been tested in-game.Validation and limits
kyty_emulatorrebuilt successfully.git diff --checkpassed.The AJM NID/output layout was cross-checked against shadPS4's AJM implementation and MP3 parser, as well as the local guest call site.
AI assistance was used for the investigation, implementation, tests and this update. I performed the game runs and supplied the logs
@ -1424,0 +1911,4 @@(ImmediateU32(bound_inst->Arg(0), bound_cap) ||ImmediateU32(bound_inst->Arg(1), bound_cap)) &&bound_cap > 0u && bound_cap <= INT32_MAX) {indirect.selector_limit = bound_cap;@coderabbitai[bot] on GitHub · 2026-09-30 13:41 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Keep the unreduced member offset when you set
selector_limit.Lines 1903-1905 replace
indirect.selector_offsetwith its residue modulostep = gcd(selector_stride, 2^32). That value is correct only for the unbounded branch inMaterializeIndirectImage. That branch enumerates the full residue class in steps ofstep.The new
selector_limitbranch inResourceMaterialization.cpp(lines 356-377) enumeratesselector_offset + index * selector_strideinstead. It steps byselector_stride, not bystep. If the member offset is at leaststep, the enumerated offsets differ from the offsets the shader reads.Example:
stride = 224givesstep = 32. A member offset of36is reduced to4. The shader reads36 + i*224, but materialization probes4 + i*224. Withstride = 2and member3, the reduced offset is0, so the probes miss every odd-aligned read. The key mapping then does not contain the keys that the shader loads. At runtime, the candidate switch sends each missing key to candidate 0, so the shader samples the wrong texture.The overflow check in the bounded branch also uses the reduced offset. As a result, it does not prove that
member + (cap-1)*stridestays below2^32.Fix: when you set
selector_limit, store the original member offset plus the aligned immediate.ReadScalarTablealigns each probe with& ~3. Addingmemory->offset & ~3is a multiple of 4, so(member + i*stride + imm_al) & ~3equals((member + i*stride) & ~3) + imm_al. The materialization overflow check then correctly rules out U32 wraparound. The current tests do not catch this bug. The bounded fixture puts the member offset inmemory.offset, and thesplit_offsetcases have no loop bound. Add a bounded-loop fixture with anIAdd32member offset that is at leaststep.🐛 Proposed fix
The existing check
static_cast<uint64_t>(indirect.selector_offset) + memory->offset > UINT32_MAXat line 1896 already prevents overflow in the new sum.@coderabbitai[bot] on GitHub · 2026-09-30 13:41 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
391db8b9-48e6-4878-a3e8-8202fe8ac4f6📥 Commits
Reviewing files that changed from the base of the PR and between
ae39466e14and32e6b2a0c4.📒 Files selected for processing (5)
src/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; 7 remain after this review.
Pull request closed