Skip to content

fix(shader): read a chased pointer's high word at its own offset - #115

Open
Thimo188 wants to merge 119 commits into
mainfrom
upstream-pr/9749
Open

Thimo188 wants to merge 119 commits into
mainfrom
upstream-pr/9749

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#9749, originally opened by EagleBearerYS.

Source commit: df176da31de9e15179bd53bca81054013c103a24. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

This is stacked on boykopovar#9633.

With boykopovar#9633, Ratchet & Clank: Rift Apart (PPSA01474) got past its 0x10b84 stop. It then stopped at the next T# load, in compute 0x116bb67100 (Tamalero's run):

ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x00013bc0(GetAddressResource(Phi(...

Ratchet & Clank: Rift Apart (PPSA01474), 11-13: this PR got the title past 0x13bc0 in Tamalero's run of 10-22 (see Tested). On current main the title doesn't stop there. boykopovar#14636 removed the title's pc=0x62d4 GetSamplerResource refusal: with boykopovar#14636's merge reverted, main f57c971 aborts on it again (dantdmdarealguy's run). Tamalero's run of main 4e2acc2 with boykopovar#18522, on RADV with APS5_MAX_COMPUTE_SPIRV_WORDS=2000000 and APS5_SKIP_REFUSED_DISPATCHES=1 (which skips and logs any compute shader whose recompile fails, code), reaches the first gameplay; the only shaders it skipped were two dropped for size (comment). main still refuses this PR's shape: on main fb542a2, which has boykopovar#14636, agc_driver_pointer_chase_split_table fails 3 of 3 with boykopovar#9633 merged and passes 3 of 3 with this PR merged (llvmpipe, a cloud Linux machine).

Tamalero's trace of the same shader (comment) shows a third chase step:

  • the V# is at the pointer plus 0x110;
  • the next pointer is dword 5 (low, 0x54) and dword 11 (high, 0x6c) of one s_buffer_load_dwordx16 from 0x40.

boykopovar#9633's chase arm required the high word at the low word's immediate + 4, so the walk refused this step. Its V# offset and its depth (3 of 4) were already covered. boykopovar#9633's 2c1a650 already gives each word pair through a V# its own chase site, so the new high immediate becomes part of that site.

The change:

The chased V#'s base (52ae654): on a diagnostic build of this PR, Tamalero's run stopped after 781 s on AGC driver: invalid shader memory read address (comment), on a V# read as 4f81f1f 0 ffffffff 0. TableSnapshotter::Chase() checked the four words it reads as a V#, but not the alignment of the address it then reads through that V#, and the driver's shader memory reader throws on an unaligned address. Chase() now treats an unaligned base as unresolved, as the snapshot's other runtime-address reads do. That step isn't captured, so a dispatch that takes it faults as outside the snapshot, like a link to memory the snapshot can't read.

Overlap:

Tested

Checklist

EagleBearerYS and others added 30 commits October 21, 2026 21:36
TryMakeIndirectColumn refused every pointer hop once the record's
pointer words were merged, so a T# read through a pointer loaded from a
pointer-keyed record pointer stayed unplanned (Gran Turismo 7's World
Map compute shaders, issue boykopovar#6191). Only buffer handles still refuse hops:
the materializer keys the records by the innermost pointer before it
follows the hops, and the plan's parent pointer is that innermost one.
…one-key child

From hugodearaujo's change on boykopovar#8939 (Marvel's Spider-Man 2, PPSA03016).
Spider-Man 2's shape: a record keyed by a first-lane read, its dwords
2-3 a pointer, a V# loaded at that pointer plus 0xa0, and the T# read at
offset 0 or 0x40 of that V#'s buffer with no second key. Two records
point at V#s of different T#s; a moved record pointer and a moved V#
must change the result without recompiling.
… pointer-keyed record pointer

A T# read at a pointer that a shader chases conditionally from a
pointer-keyed record pointer, loading a V# at a fixed offset of the
pointer and reading the next pointer from that buffer, stayed unplanned:
the merged pointer's chase arms read another buffer at another offset
than the record word, so PointerRecordRead refused them (Ratchet & Clank:
Rift Apart stops at compute LoadAddressU32 with this shape).

The walk now takes such an arm when its V# is read from a pointer that is
the record pointer or another chase arm, records each distinct chase as a
hop of the column, and refuses a chase that reaches itself or a depth
over 4. The snapshot then also captures every record pointer's chase
closure up to that depth as pointer-keyed entries, each with the T# at
its own offset, so the GPU's lookup finds the pointer the shader reached.
PointerRecordPairs found an existing chase site by its V# alone. A
second chase arm that reads its next pointer through the same V# at
other words therefore kept the first arm's PointerChase, and the
snapshot never followed the second arm: a T# behind a node whose V#
holds two links (words 0 and 1, words 2 and 3), each taken in its own
lanes, faulted as outside the snapshot when the second link was taken.

Sites are now keyed by the V# and the whole PointerChase, so each word
pair of one V# is its own chase in the column and in the snapshot's
closure. This follows the chase work for Ratchet & Clank: Rift Apart
(PPSA01474); its trace has not shown this shape yet.
A pointer chase arm whose next pointer is rebuilt from two words that
are not adjacent stayed unplanned: ChaseHighRead took the high word only
at the low word's immediate plus 4, so the walk refused the arm.
Ratchet & Clank: Rift Apart (PPSA01474) stops this way at compute
LoadAddressU32@pc=0x13bc0 with "GetImageResource dword 0 is not a valid
runtime value": after two chase steps through a V# at the pointer plus
0x60, its third step loads a V# at the pointer plus 0x110, reads 16
dwords from 0x40 with one s_buffer_load_dwordx16 and rebuilds the next
pointer from dword 5 (0x54) and dword 11 (0x6c).

PointerChase now keeps the high word's own immediate, readHighImmediate.
The walk takes a high read through the low read's V# (or an equivalent
one) at the same buffer offset when its immediate is 4-aligned and
differs from the low word's, and the snapshot reads the next pointer's
high word at that immediate. The shader disk cache stores the field and
refuses a plan whose high immediate is unaligned or equals the low one
(format 48).

Suggested by Tamalero's trace on boykopovar#9633 (issuecomment-6338256607), which
also proposed the readHighImmediate field.
… base

Chase() decoded four words at the chased pointer as a V# and read the
next pointer at its base plus the load's offsets, checking only that the
address was accessible. When those words are not a buffer descriptor,
the base can be unaligned, and the read threw "invalid shader memory
read address" for the whole capture. Ratchet & Clank: Rift Apart
(PPSA01474) stopped this way after 781 s, on a V# read as
4f81f1f 0 ffffffff 0. Every other runtime-address read in
TableSnapshotter treats an unaligned address as unresolved; Chase() now
does too, so the step is not captured, and a dispatch that takes it
faults as outside the snapshot, like a link to memory the snapshot
cannot read.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
…at, 53

The format ladder along the stack is boykopovar#8939 51 and this PR 53, so a cache
written by boykopovar#8939's recompiler is not read as this one's.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
#	core/shader/recompiler/ShaderDiskCache.hpp
…at, 55

The format ladder along the stack is boykopovar#9457 53 and this PR 55, so a cache
written by boykopovar#9457's recompiler is not read as this one's.
…ds-on-c2

# Conflicts:
#	core/libs/prx/libSceAgcDriver/CMakeLists.txt
…ords-on-c2

Takes boykopovar#9633's FormatVersion 82, which is above this branch's 72; the next commit gives this branch its own number.
…at, 83

boykopovar#9633 now takes 82, above this PR's 72, so this PR takes 83, the lowest number above it that no open PR uses, and a cache written by another branch's recompiler is not read as this one's.
Moves this branch's FormatVersion to 95, above boykopovar#8939's 94.
Moves this branch's FormatVersion to 96, above boykopovar#9457's 95.
…ords-on-c2

Moves this branch's FormatVersion to 97, above boykopovar#9633's 96.
Moves this branch's FormatVersion from 95 to 98, above boykopovar#8939's 97.
Moves this branch's FormatVersion from 96 to 99, above boykopovar#9457's 98.
…ords-on-c2

Moves this branch's FormatVersion from 97 to 100, above boykopovar#9633's 99.
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants