shader: leave planning-only reads out of the empty-table and zero-stride folds (Ghost of Yōtei) #2230
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!2230
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2230"
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-11-12 16:02 UTC · original
Nawid3333:fix/planning-reads-specialization→main· +39 −2 · 2 files · 1 commits · openCompiling Ghost of Yōtei's compute shader
386c6a44da561c0dreads past the end of the buffer vectors inApplyResourceSpecialization: the empty scalar-table fold indexesspecialization.buffersandprogram.info.bufferswithmemory.resource17, past the end of both. Usually that reads whatever follows the vectors on the heap; in an offline recompile of the shader it crashed with an access violation in 3 of 100 runs (ApplyResourceSpecialization←CompileProgram).Cause. Resource tracking assigns no buffer to planning-only memory (it returns before
AddMemoryPatch), soresourcekeeps the translator's value, the descriptor's SGPR index divided by 4. The emitter skips planning-only scalar reads, andResourceControlFlowandCollectShaderInfoskip planning-only memory; the empty scalar-table fold and the zero-stride fold inApplyResourceSpecializationdo not. With a larger index they read out of bounds; with a smaller one they read an unrelated buffer and can fold the planning reads through it.In 172 Ghost of Yōtei programs (a capture recompiled offline, guest memory read as zeros), 4 have planning-only scalar reads: 2 index out of bounds on every compile (
386c6a44da561c0d,b920ac9e14cb5fb8), and 2 name an unrelated buffer: in69ba1a07c7a95510the index 5 is an empty scalar table, so all 8 planning reads are folded to zero there; in3d82c2913cac198dthe index 3 is not empty, so nothing is folded.Change. Both folds skip planning-only memory, as
ResourceControlFlowandCollectShaderInfodo. A planning read is not a resource, so neither fold can tell which table it reads.Tests.
TestPlanningReadsSkipBufferFolds(a planning scalar-table read, and a planningLoadBufferU32x4of a descriptor) runs with the raw index 0, which names an unrelated empty scalar table / zero-stride buffer, and with 2, past the end of the one-entry buffer lists. On main it fails withplanning-only table read was folded through an unrelated empty scalar table; without either of the two checks it fails with that check's own message; with the fix all cases pass.386c6a44da561c0deach, main crashed once and the fix not at all._MSVC_STL_HARDENING=1), with the AMD device profile, main stops at the bounds check on386c6a44da561c0dandb920ac9e14cb5fb8on every compile, and nowhere else in the 172 programs; with the fix all 172 compile without a report.tests/BvhMirrorGpuTests.inc(154,25): error: expected unqualified-id(#2229 fixes that).Written with Claude Code (AI): it found the crash in an offline recompile of the game's shaders, traced it to this read, wrote the change and the test, and ran them on my PC; reviewed by me.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-12 16:05 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
ApplyResourceSpecializationnow skips empty-scalar-buffer replacement and native zero-stride out-of-bounds handling for planning-only resources. Tests check that planning-only scalar and vector buffer reads remain after specialization across both table types and raw indices 0 and 2.Suggested reviewers:
nmzik,claxten10Change: Bug fix
Merge Risk:
Minimal · up to
bf55cThe change stops planning-only buffer reads from being folded using an unrelated or out-of-range buffer, which can cause crashes during shader compilation. No merge-blocking risk is evident from the supplied review context.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: planning-only reads are excluded from the empty scalar-table and zero-stride folds in ApplyResourceSpecialization. The raw summary and objectives both describe this change, so the title matches the changeset.
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
2533bc42-d1a8-48ea-9586-a7db0aae6116Reviewing files that changed from the base of the PR and between
0a016e91a0andbf55cb7e7f.src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceMaterializationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.