shader: select per-material T#s through their record's pointer chain (Guardians of the Galaxy, #1004) #1457
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!1457
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1457"
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?
@overlordxrz-source on GitHub · 2026-10-12 16:11 UTC · original
overlordxrz-source:fix/gotg-material-chain→main· +420 −12 · 4 files · 1 commits · openSummary
Marvel's Guardians of the Galaxy (PPSA01748) pixel shader
0x4a260221f9feeae6picks a material record with a flat interpolant and reads its textures and samplers through pointers stored in that record. Resource tracking can't follow those pointers, so on main (dad900c6, with #1438 and #1444 applied to get this far) the game stops at:This PR tracks such descriptors as a pointer chain from the record table's V#. On the host it enumerates every record that V# bounds, and the GPU's material index selects the image through the existing key mapping.
Refs #1004
The shader
hackerinfo89's dump in #1004 (disassembly, CFG and native IR before resource tracking) shows:
In the IR, the 15
GetImageResources and 15GetSamplerResources (13 distinct T#s and 6 distinct S#s) all haveLoadAddressU32DWORDs whose address is itself aLoadAddressU32ofGetAddressResource(ReadConstBuffer(V#, ReadFirstLane(key) << 3)). The constants V# is already handled by the GPU-selected scalar buffer path, and so are the address loads. Only the images and samplers are refused.The existing indirect paths (
MatchDescriptorTable,MatchUniformizedMaterialKey,MatchScalarMaterialKey, the bounded V# table) all need the descriptor table's base address to be a host value. Here that base is per material.Change
Resource tracking.
TryMakeMaterialChainmatches a T# or S# whose DWORDs are consecutives_loadDWORDs of one address. That address comes from up to four 64-bit pointer loads, and the chain ends at a pair ofReadConstBuffers from a runtime V# atkey * stride + offset. The descriptor source records:selector(stride and offset of the pointer),IndirectDescriptor::chain,table_offset.The GPU key is the record index. Descriptor DWORDs used only by their handles become planning reads, as in the other indirect paths. The match is refused when the shader has memory writes.
Materialization.
indirect_search_iterations). The SPIR-V side is unchanged.material records A and B select different samplers at table offset N.material table has N records of S bytes.Limits
MaterializeResourcesEXIT_IF inpipelineCache.cpp.Testing
resource_tracking_testshas a new case,TestMaterialPointerChainImages, built from this shader's IR shape: the flat interpolant,ReadFirstLane, V# record table, record → image/sampler table pointers at +160/+168, a constants V# at +208, and two sampled T#/S# slots. It checks:pc=0x000001d8 GetImageResource dword 0 is not a valid runtime value, which matches the reported error. With the change, the whole suite passes (aarch64 Linux, zig 0.17 clang).ResourceTracking.cpp,ResourceMaterialization.cpp,spirvEmitterImage.cppandShaderRecompiler.cpp, plus-fsyntax-onlyonShaderRecompilerComputeTests.cppandResourceMaterializationTests.cpp. There are no new warnings.resource_materialization_testsand the GPU tests were not run (no x86 or Vulkan host here).Relation to other PRs
InternSource's descriptor comparison, where both PRs add a field.Thanks to hackerinfo89 for testing main with #1438 and #1444 and attaching the full shader log for
0x4a260221f9feeae6in #1004. The test fixture is built from that IR.AI-assisted: yes. The analysis, code and tests were written with an AI assistant. The unit tests above were run; behaviour in the game is untested.
@coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original · edited 2026-10-16 02:43 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
b015d5b5-5b2f-4d03-8237-3be5c4bf19b8📥 Commits
Reviewing files that changed from the base of the PR and between 7ae505944683982043f1c3dc1c3dbaece79f74a3 and
466cf4888d.📒 Files selected for processing: 4
src/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
📝 Walkthrough
The change adds pointer-chain metadata to indirect descriptors. Resource tracking recognizes image and sampler descriptors reached through up to four pointer hops and records selector metadata. Resource materialization follows and caches the chains, reads image descriptors from material records, and handles chain-backed samplers. Tests cover null records, differing sampler contents, and oversized tables.
Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Bug fix
Merge Risk: 🟠 High · up to
466cfSome draws can terminate the process when a material table has differing samplers, or when an untaken sampler branch encounters an invalid table. Resolve these failures before merging.
Pre-merge checks:
4 ·
1
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.@ -519,0 +616,4 @@}}return true;}@coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
A sampler difference in any record of the material table aborts the draw.
MaterializeChainSamplerreads every record in the V# (up to 65,536 records), not only the records that the draw selects. It returnsSpecializationFailwhen two readable, nonzero S#s differ. Different materials in one table commonly use different samplers, for example different wrap or filter modes. When that happens,MaterializeResourcesreturnsfalse, andFindPermutationinsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppstops the process throughEXIT_IF. The PR description lists this as a possible specialization failure. In the production caller, that failure is a crash, not a fallback.The image path already maps each record to a candidate. The finite-sampler path already supports
SamplerResource::indirect_resources. Use one of these approaches:indirect_resources, as the image path does with its candidate mapping.EXIT_IF.@coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 1335 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Respect
active_sourcesbefore you materialize a chain sampler.Image materialization skips an inactive indirect source (Line 1302:
if (!active.empty() && !active[image.source]) continue;). Direct and finite samplers go throughevaluate, which also returns a zero descriptor for an inactive source. The new chain-sampler branch callsMaterializeChainSamplerwithout this check.If a material-chain sample is in a block that is uniformly not taken,
ReadMaterialChainstill does these things:MaxIndirectDescriptorProbesrecords.MaterializeResourcesthen returnsfalse.FindPermutationinsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cpptreats this as fatal throughEXIT_IF(!MaterializeResources(...)). A draw that never runs the sample can therefore abort. The draw can also record unnecessary specialization reads.TestConditionalIndirectImageMaterializationrequires that an untaken indirect image branch does not probe its table. The sampler path should follow the same contract.Proposed fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
f8490245-89ff-4e47-8532-8a8c90af7086📥 Commits
Reviewing files that changed from the base of the PR and between
df5b9b92beand 7ae505944683982043f1c3dc1c3dbaece79f74a3.📒 Files selected for processing (4)
src/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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.