shader: select per-material T#s through their record's pointer chain (Guardians of the Galaxy, #1004) #1457

Open
github-bot wants to merge 1 commit from github-bot/gh-1457 into main AGit
Owner

@⁠overlordxrz-source on GitHub · 2026-10-12 16:11 UTC · original
overlordxrz-source:fix/gotg-material-chain → main · +420 −12 · 4 files · 1 commits · open

Summary

Marvel's Guardians of the Galaxy (PPSA01748) pixel shader 0x4a260221f9feeae6 picks 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:

shader resource tracking: hash=0x4a260221f9feeae6 stage=pixel pc=0x000001d8 GetImageResource dword 0 is not a valid runtime value

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:

v_interp_mov_f32 v20, 2, 2, 3 (flat);  v3 = v20[31:16]
v_readfirstlane_b32 vcc_lo, v3;  s_lshl_b32 vcc_lo, vcc_lo, 3
s_buffer_load_dwordx2 s[4:5], s[0:3], vcc_lo     ; material = records[index] (V# from user data)
s_load_dwordx4 s[72:75], s[4:5], 208             ; per-material constants V#
s_load_dwordx4 s[80:83], s[4:5], 160             ; image table pointer, sampler table pointer
s_load_dwordx16 / x8 from s[80:81]               ; 13 T#s at +0,32,64,96,160,...,416
s_load_dwordx16 / x8 from s[82:83]               ; 6 S#s at +0,16,32,48,64,80

In the IR, the 15 GetImageResources and 15 GetSamplerResources (13 distinct T#s and 6 distinct S#s) all have LoadAddressU32 DWORDs whose address is itself a LoadAddressU32 of GetAddressResource(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. TryMakeMaterialChain matches a T# or S# whose DWORDs are consecutive s_load DWORDs of one address. That address comes from up to four 64-bit pointer loads, and the chain ends at a pair of ReadConstBuffers from a runtime V# at key * stride + offset. The descriptor source records:

    • the root V# record as the selector (stride and offset of the pointer),
    • the pointer hop offsets in a new IndirectDescriptor::chain,
    • the descriptor offset as 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.

    • Every record the V# bounds is a key (at most 65536). Each record's chain is followed once per refresh and shared by all slots with the same chain.
    • Each image slot reads its T# from each record's table and is mapped with the existing sorted key/ordinal mapping (indirect_search_iterations). The SPIR-V side is unchanged.
    • A null pointer or unreadable table selects a null image.
    • Samplers bind as one S# per slot, so all readable, non-zero S#s across records must match. If they differ, specialization fails with material records A and B select different samplers at table offset N.
    • A record table over the bound fails with material table has N records of S bytes.

Limits

  • The host enumerates every record of the V#, not only the records the draw's vertices use. Large material tables mean one image candidate per distinct T# per slot and a key/ordinal mapping of 2N+1 words per slot in the flattened SRT.
  • Per-material samplers that really differ aren't supported. That would need runtime-sized sampler arrays, which main doesn't have.
  • I haven't run this in the game. I don't know the size of GotG's material table, or whether its records share samplers. So the next stop may be one of the two specialization messages above, through the MaterializeResources EXIT_IF in pipelineCache.cpp.

Testing

  • resource_tracking_tests has 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:
    • the tracked chain,
    • the GPU-selected constants buffer,
    • the materialized key → image mapping, including a null record,
    • deduplicated candidates,
    • the shared sampler, with a zeroed-sampler record skipped,
    • refusal of differing samplers and of an oversized record table.
  • On main without the change, the same fixture fails with 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).
  • x86_64-linux compile checks pass for ResourceTracking.cpp, ResourceMaterialization.cpp, spirvEmitterImage.cpp and ShaderRecompiler.cpp, plus -fsyntax-only on ShaderRecompilerComputeTests.cpp and ResourceMaterializationTests.cpp. There are no new warnings.
  • resource_materialization_tests and the GPU tests were not run (no x86 or Vulkan host here).
  • Not tested in the game. I don't have the title.

Relation to other PRs

  • #1444: independent. It's needed only to reach this shader in the game, and this patch applies cleanly on top of it.
  • #1438: independent.
  • #1257 (TheCruZ, GPU-indexed T# tables as image arrays) needs a host-known table base. It doesn't cover per-record table pointers or samplers. Both PRs touch the indirect planner and materializer.
  • #1255: one small textual conflict in InternSource's descriptor comparison, where both PRs add a field.
  • #1118: applies with a three-way merge, no conflict.

Thanks to hackerinfo89 for testing main with #1438 and #1444 and attaching the full shader log for 0x4a260221f9feeae6 in #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.

**@⁠overlordxrz-source** on GitHub · 2026-10-12 16:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1457) `overlordxrz-source:fix/gotg-material-chain` → `main` · +420 −12 · 4 files · 1 commits · open ## Summary Marvel's Guardians of the Galaxy (PPSA01748) pixel shader `0x4a260221f9feeae6` picks 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: ``` shader resource tracking: hash=0x4a260221f9feeae6 stage=pixel pc=0x000001d8 GetImageResource dword 0 is not a valid runtime value ``` 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: ``` v_interp_mov_f32 v20, 2, 2, 3 (flat); v3 = v20[31:16] v_readfirstlane_b32 vcc_lo, v3; s_lshl_b32 vcc_lo, vcc_lo, 3 s_buffer_load_dwordx2 s[4:5], s[0:3], vcc_lo ; material = records[index] (V# from user data) s_load_dwordx4 s[72:75], s[4:5], 208 ; per-material constants V# s_load_dwordx4 s[80:83], s[4:5], 160 ; image table pointer, sampler table pointer s_load_dwordx16 / x8 from s[80:81] ; 13 T#s at +0,32,64,96,160,...,416 s_load_dwordx16 / x8 from s[82:83] ; 6 S#s at +0,16,32,48,64,80 ``` In the IR, the 15 `GetImageResource`s and 15 `GetSamplerResource`s (13 distinct T#s and 6 distinct S#s) all have `LoadAddressU32` DWORDs whose address is itself a `LoadAddressU32` of `GetAddressResource(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.** `TryMakeMaterialChain` matches a T# or S# whose DWORDs are consecutive `s_load` DWORDs of one address. That address comes from up to four 64-bit pointer loads, and the chain ends at a pair of `ReadConstBuffer`s from a runtime V# at `key * stride + offset`. The descriptor source records: - the root V# record as the `selector` (stride and offset of the pointer), - the pointer hop offsets in a new `IndirectDescriptor::chain`, - the descriptor offset as `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.** - Every record the V# bounds is a key (at most 65536). Each record's chain is followed once per refresh and shared by all slots with the same chain. - Each image slot reads its T# from each record's table and is mapped with the existing sorted key/ordinal mapping (`indirect_search_iterations`). The SPIR-V side is unchanged. - A null pointer or unreadable table selects a null image. - Samplers bind as one S# per slot, so all readable, non-zero S#s across records must match. If they differ, specialization fails with `material records A and B select different samplers at table offset N`. - A record table over the bound fails with `material table has N records of S bytes`. ## Limits - The host enumerates every record of the V#, not only the records the draw's vertices use. Large material tables mean one image candidate per distinct T# per slot and a key/ordinal mapping of 2N+1 words per slot in the flattened SRT. - Per-material samplers that really differ aren't supported. That would need runtime-sized sampler arrays, which main doesn't have. - I haven't run this in the game. I don't know the size of GotG's material table, or whether its records share samplers. So the next stop may be one of the two specialization messages above, through the `MaterializeResources` EXIT_IF in `pipelineCache.cpp`. ## Testing - `resource_tracking_tests` has 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: - the tracked chain, - the GPU-selected constants buffer, - the materialized key → image mapping, including a null record, - deduplicated candidates, - the shared sampler, with a zeroed-sampler record skipped, - refusal of differing samplers and of an oversized record table. - On main without the change, the same fixture fails with `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). - x86_64-linux compile checks pass for `ResourceTracking.cpp`, `ResourceMaterialization.cpp`, `spirvEmitterImage.cpp` and `ShaderRecompiler.cpp`, plus `-fsyntax-only` on `ShaderRecompilerComputeTests.cpp` and `ResourceMaterializationTests.cpp`. There are no new warnings. - `resource_materialization_tests` and the GPU tests were not run (no x86 or Vulkan host here). - Not tested in the game. I don't have the title. ## Relation to other PRs - **#1444**: independent. It's needed only to reach this shader in the game, and this patch applies cleanly on top of it. - **#1438**: independent. - **#1257** (TheCruZ, GPU-indexed T# tables as image arrays) needs a host-known table base. It doesn't cover per-record table pointers or samplers. Both PRs touch the indirect planner and materializer. - **#1255**: one small textual conflict in `InternSource`'s descriptor comparison, where both PRs add a field. - **#1118**: applies with a three-way merge, no conflict. Thanks to hackerinfo89 for testing main with #1438 and #1444 and attaching the full shader log for `0x4a260221f9feeae6` in #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.
Guardians of the Galaxy's pixel shader 0x4a260221f9feeae6 selects a material
record with a flat interpolant (ReadFirstLane), reads the record's address from
a V# table in s[0:3], and loads its 13 T#s and 6 S#s through the image and
sampler table pointers stored in that record (s_load_dwordx4 at +160). The T#
DWORDs are not runtime values, so resource tracking failed with
"GetImageResource dword 0 is not a valid runtime value".

Track such descriptors as a pointer chain: the root V# record (stride and
offset of the 64-bit pointer), the byte offsets of the following 64-bit
pointer loads, and the descriptor offset in the last table. Materialization
enumerates every record the V# bounds (at most 65536), follows each chain once
per refresh, and maps the record index to its T# with the existing key
mapping, so the GPU key selects the image. Records without readable tables
select null images. The records must agree on each S#, which binds as one
sampler; zeroed S#s are skipped and differing ones fail specialization with a
message.

A record pointer read directly from the V# (no hop) is left to the nested
pointer-table planner, which bounds its key. A chain needs at least one
hop, and every read through a zero pointer must stay in the unmapped
first 16 KiB page, so zero pointers keep the null-image semantics.

Refs #1004
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:11 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original · edited 2026-10-16 02:43 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 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.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.cpp

Included 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: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🟠 High · up to 466cf

Some 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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: selecting per-material texture descriptors through pointer chains. It also identifies the relevant game and issue context.
Description check Passed The description directly explains the shader failure, pointer-chain tracking and materialization changes, limits, tests, and known gaps. It is fully related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 16:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1457#issuecomment-6128136060) · edited 2026-10-16 02:43 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1457?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b015d5b5-5b2f-4d03-8237-3be5c4bf19b8` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 7ae505944683982043f1c3dc1c3dbaece79f74a3 and 466cf4888db98f7d8479142546a000870e453ed9. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 4</strong></summary> <dl> <dd> * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> 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:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"466cf4888db98f7d8479142546a000870e453ed9" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🟠 High</strong> · up to <code>466cf</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟠 High** · up to `466cf` --> <!-- final_review_risk_coverage:{"sourceCommitId":"466cf4888db98f7d8479142546a000870e453ed9","coveredCommitId":"466cf4888db98f7d8479142546a000870e453ed9","kind":"reviewed"} --> Some 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the primary change: selecting per-material texture descriptors through pointer chains. It also identifies the relevant game and issue context. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the shader failure, pointer-chain tracking and materialization changes, limits, tests, and known gaps. It is fully related to the changeset. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1457)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -519,0 +616,4 @@
}
}
return true;
}
Author
Owner

@⁠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.

MaterializeChainSampler reads every record in the V# (up to 65,536 records), not only the records that the draw selects. It returns SpecializationFail when 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, MaterializeResources returns false, and FindPermutation in src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp stops the process through EXIT_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:

  • Map the chain sampler per record through indirect_resources, as the image path does with its candidate mapping.
  • If a per-record mapping is out of scope for this PR, give the caller a non-fatal fallback for this failure instead of EXIT_IF.
**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 16:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1457#discussion_r4250132019) **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** **A sampler difference in any record of the material table aborts the draw.** `MaterializeChainSampler` reads every record in the V# (up to 65,536 records), not only the records that the draw selects. It returns `SpecializationFail` when 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, `MaterializeResources` returns `false`, and `FindPermutation` in `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` stops the process through `EXIT_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: - Map the chain sampler per record through `indirect_resources`, as the image path does with its candidate mapping. - If a per-record mapping is out of scope for this PR, give the caller a non-fatal fallback for this failure instead of `EXIT_IF`. <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:bd26a09276aa3f59a44d34f6 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp line 1335 (outdated):

@@ -1214,12 +1329,18 @@ bool MaterializeResources(const ResourcePlan& program, const SrtRuntime& runtime
 		auto source = program.info.samplers[i].source;
 		if (source >= program.descriptor_sources.size()) return false;
 		const auto& descriptor = program.descriptor_sources[source];
-		if (descriptor.indirect_descriptor) {
-			if (descriptor.indirect_descriptor->sources.empty()) return false;
-			source = descriptor.indirect_descriptor->sources[0];
-		}
-		if (!evaluate(source, snapshot.samplers[i])) {
-			return false;
+		if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) {
+			if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, chains,
+			                             snapshot.samplers[i]))
+				return false;

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Respect active_sources before 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 through evaluate, which also returns a zero descriptor for an inactive source. The new chain-sampler branch calls MaterializeChainSampler without this check.

If a material-chain sample is in a block that is uniformly not taken, ReadMaterialChain still does these things:

  • It evaluates the record V#.
  • It reads every record pointer and follows every hop.
  • It fails if the record table is unreadable or has more than MaxIndirectDescriptorProbes records.

MaterializeResources then returns false. FindPermutation in src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp treats this as fatal through EXIT_IF(!MaterializeResources(...)). A draw that never runs the sample can therefore abort. The draw can also record unnecessary specialization reads. TestConditionalIndirectImageMaterialization requires that an untaken indirect image branch does not probe its table. The sampler path should follow the same contract.

Proposed fix
--- "a/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp"
+++ "b/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp"
@@ -1329,11 +1329,13 @@
 		auto source = program.info.samplers[i].source;
 		if (source >= program.descriptor_sources.size()) return false;
 		const auto& descriptor = program.descriptor_sources[source];
 		if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) {
-			if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, chains,
-			                             snapshot.samplers[i]))
+			if (!active.empty() && !active[source]) {
+				snapshot.samplers[i] = {.dword_count = 4u};
+			} else if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean,
+			                                    chains, snapshot.samplers[i]))
 				return false;
 		} else {
 			if (descriptor.indirect_descriptor) {
 				if (descriptor.indirect_descriptor->sources.empty()) return false;
 				source = descriptor.indirect_descriptor->sources[0];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) {
			if (!active.empty() && !active[source]) {
				snapshot.samplers[i] = {.dword_count = 4u};
			} else if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean,
			                                    chains, snapshot.samplers[i]))
				return false;
**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 16:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1457#discussion_r4250132027) On `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` line 1335 (outdated): ```diff @@ -1214,12 +1329,18 @@ bool MaterializeResources(const ResourcePlan& program, const SrtRuntime& runtime auto source = program.info.samplers[i].source; if (source >= program.descriptor_sources.size()) return false; const auto& descriptor = program.descriptor_sources[source]; - if (descriptor.indirect_descriptor) { - if (descriptor.indirect_descriptor->sources.empty()) return false; - source = descriptor.indirect_descriptor->sources[0]; - } - if (!evaluate(source, snapshot.samplers[i])) { - return false; + if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) { + if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, chains, + snapshot.samplers[i])) + return false; ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Respect `active_sources` before 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 through `evaluate`, which also returns a zero descriptor for an inactive source. The new chain-sampler branch calls `MaterializeChainSampler` without this check. If a material-chain sample is in a block that is uniformly not taken, `ReadMaterialChain` still does these things: - It evaluates the record V#. - It reads every record pointer and follows every hop. - It fails if the record table is unreadable or has more than `MaxIndirectDescriptorProbes` records. `MaterializeResources` then returns `false`. `FindPermutation` in `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` treats this as fatal through `EXIT_IF(!MaterializeResources(...))`. A draw that never runs the sample can therefore abort. The draw can also record unnecessary specialization reads. `TestConditionalIndirectImageMaterialization` requires that an untaken indirect image branch does not probe its table. The sampler path should follow the same contract. <details> <summary>Proposed fix</summary> ```diff --- "a/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp" +++ "b/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp" @@ -1329,11 +1329,13 @@ auto source = program.info.samplers[i].source; if (source >= program.descriptor_sources.size()) return false; const auto& descriptor = program.descriptor_sources[source]; if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) { - if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, chains, - snapshot.samplers[i])) + if (!active.empty() && !active[source]) { + snapshot.samplers[i] = {.dword_count = 4u}; + } else if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, + chains, snapshot.samplers[i])) return false; } else { if (descriptor.indirect_descriptor) { if (descriptor.indirect_descriptor->sources.empty()) return false; source = descriptor.indirect_descriptor->sources[0]; ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if (descriptor.indirect_descriptor && descriptor.indirect_descriptor->chain) { if (!active.empty() && !active[source]) { snapshot.samplers[i] = {.dword_count = 4u}; } else if (!MaterializeChainSampler(*descriptor.indirect_descriptor, observed, clean, chains, snapshot.samplers[i])) return false; ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:a4eca5f36f357ec55b725872 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-12 16:15 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8490245-89ff-4e47-8532-8a8c90af7086
📥 Commits

Reviewing files that changed from the base of the PR and between df5b9b92be and 7ae505944683982043f1c3dc1c3dbaece79f74a3.

📒 Files selected for processing (4)
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
  • tests/ResourceTrackingTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-12 16:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1457#pullrequestreview-5493417810) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f8490245-89ff-4e47-8532-8a8c90af7086` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between df5b9b92be7dfd463b47756b707d6d356a9f0550 and 7ae505944683982043f1c3dc1c3dbaece79f74a3. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp` * `tests/ResourceTrackingTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=c1c0efb1-dd20-4941-9fed-0eea26ae67f3 attempt=6f93cefe-d18c-4e4e-9793-431eed29c917 batch=1/1 -->
This pull request has changes conflicting with the target branch.
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp
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.
git fetch -u origin '+refs/pull/1457/head:github-bot/gh-1457'
git switch 'github-bot/gh-1457'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1457'
git switch 'github-bot/gh-1457'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1457'
git switch 'github-bot/gh-1457'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1457'
git switch 'main'
git merge --squash 'github-bot/gh-1457'
git switch 'main'
git merge --ff-only 'github-bot/gh-1457'
git switch 'main'
git merge 'github-bot/gh-1457'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.