Repository navigation
fix(shader): accept a nested S# whose V# gives the key of a sibling V#'s T# array - #15555
hugodearaujo wants to merge 165 commits into
Conversation
…ed record pointer A T# loaded through a record pointer was still refused with "GetImageResource dword 0 is not a valid runtime value" when the pointer's low word passed ANDs with lane masks, as a waterfall loop that copies EXEC into the pointer's SGPR builds them, or when its high word was a Phi of the record's high word read under several keys. For a pointer-keyed column, the walk of the low word now takes an AND with a lane-mask operand (a Ballot word, or an AND or Phi of only Ballot words and immediates) and keeps walking its other operand, so its record reads must still match the column and anything else still refuses. The high word is walked the same way: its record reads must be the record word at the low word's offset plus 4. A high word that is one read still gives the column its table and record offset, as before. Otherwise the table comes from a record read whose V# words are defined before the descriptor load, and the record offset from the high word, which the GPU does not read for a pointer-keyed column. A high-word arm read from another buffer, such as one whose V# is loaded through a pointer, stays refused. A shader that planned before plans the same way, so the disk-cache format does not change.
… a pointer-keyed record pointer A T# loaded through a record pointer was still refused with "GetImageResource dword 0 is not a valid runtime value" when a Phi of the pointer's low word merged the record read, a zero, and the waterfall's lane mask with the handled lane's bit cleared, BitwiseAnd32(CompositeExtractU32x4(Ballot(...), 0), BitwiseNot32(ShiftLeftLogical32(1, index))), as s_ff1, s_lshl and s_not with s_and, or s_andn2, build it in the SGPR the pointer reuses. The walk took only Ballot words and ANDs of them as lane masks, so it walked into the NOT and refused. A lane-mask operand is now a Ballot word or the loop's lane bit, a shift of 1 by an index from FindILsb32, FindUMsb32 or ReadFirstLane (through the AND, add, subtract and select that s_ff1_i32_b64, s_bitset0 and the shift's own mask put around it), or an AND, OR, NOT or Phi of only those and immediates. An arm of the pointer that is entirely such an operand is skipped. An AND with a record read in it still has the read matched against the column, and anything else still refuses. agc_driver_pointer_phi_lane_not_table builds that shape in a wave64 waterfall: the low word's Phis merge the record read at +0, a zero and the lane mask without the handled lane's bit, cleared by s_not and s_and and by s_andn2, and the high word is one read at +4. Each lane samples the T# of its record, and every masked word faults outside the snapshot. agc_driver_pointer_vsharp_select_table reads a record keyed by ReadFirstLane(SelectU32(LogicalAnd, IAdd32, Phi)), a pointer from it, a V# through the pointer and the T# through the V#; it passes without this change and keeps that chain checked, including a record pointer moved to the other V# without a recompile. Shaders that planned before plan the same way, and a refusal is never cached, so the disk-cache format does not change.
…keyed records A pointer-keyed record pointer now also takes lane-mask ANDs, the waterfall loop's lane bit and its OR and NOT forms, and a high word merged from the record's next word. A high word read from a second buffer stays refused.
The low and high words of a pointer-keyed record pointer were walked separately, so a high-word arm on a path whose low word is a lane mask refused the plan even though that pair is no pointer. Ratchet & Clank: Rift Apart (PPSA01474) stops this way at LoadAddressU32@pc=0x9a30: one high-word arm reads a second buffer, and on that edge the low word is a lane mask, the waterfall loop reusing the SGPR pair. Walk the two words together. Where both are Phis of one block, each low-word edge takes the high word of the same predecessor. An edge whose low word is a constant or a lane mask is skipped with its high word. A record low word still needs every high word it can meet to be a constant, a lane mask or the same record column at offset + 4, so a second-buffer high word paired with the record word stays refused. agc_driver_pointer_phi_high_second_lane_table adds the lane-mask low word to the second-buffer arm: it plans, each group samples the T# its record selects, and that arm faults outside the snapshot.
…nter The two words of the pointer are now walked edge by edge, and an edge whose low word is a constant or a lane mask is skipped with its high word. A high word read from a second buffer stays refused on an edge whose low word is the record word.
…ane-masks Brings boykopovar#7395's merge of main bd4d801, with boykopovar#8991. It merged without conflicts.
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.
…andles as nested children Marvel's Spider-Man 2 (PPSA03016) stops at 131 s on boykopovar#9457 in a compute shader whose record pointer, at dwords 2-3 of a waterfall-keyed record with its low word merged by a Phi with a constant, leads to a V# that two GetBufferResource handles read: a T# at offset 0 and a T# at 0x4c0, each sampled. The nested branch of TryMakeTableColumn refused the first T# because the V#'s words also fed the second handle, whose reads belong to the other T#. A parent V# whose word reads feed several GetBufferResource handles is now accepted when every other handle has the same words and its uses are only reads whose users are T# or S# descriptor handles. Each descriptor plans its child column from its own handle; both walks reach the same reads, so the parent interns to one source, the materializer reads its records once (NestedColumn takes them from Column()), and each child keeps its own offset. A handle with any other use still refuses, and a sibling descriptor that cannot be planned still refuses the shader, as its words are not runtime values. T# or S# words that have other users stay refused. Planning keeps those reads in the program: PlanTableColumnPass marks a read planning-only only when every user is a planned handle (ResourceTracker.cpp:1770-1781). But they read through the V# handle, whose arguments Run() replaces with the column offset and the parent pointer words (:154-160), and whose own word loads become planning-only once every handle over them is planned, so LoadAddress emits nothing for them (SpirvMemoryInstructions.cpp:599-601). The kept read would address a V# that only the snapshot holds. Allowing those uses in this shape, where the second T#'s dwords 0 and 1 reach the pointer registers on one edge before a later s_load, crashes lavapipe in the dispatch. Taking it needs that V# kept alive for those reads: an unrewritten copy of the handle and real loads of its words through the record pointer. Shape from hugodearaujo's IR on boykopovar#8939 (issuecomment-6340144242).
…d other instructions Marvel's Spider-Man 2 (PPSA03016) still stops at pc 0x8fa0 with the shared-V# planning alone: its shader moves dwords 0 and 1 of the second T# read through the pointer-loaded V# into the record pointer's registers, so those reads have Phi users. The nested branch of TryMakeTableColumn refused that T#, and the first T# with it, because the sibling handle's reads were not only descriptor words. d132754 added the refusal after such a read crashed lavapipe: the read stayed in the program but went through the V# handle that Run() rewrites to the column offset and parent pointer words, while the V#'s own word loads became planning-only and were not emitted, so it read a garbage address. A planned nested child's T# or S# read with other users now goes through an unrewritten copy of the V# GetBufferResource. PlanTableColumnPass keeps a read real while any planned handle using it has a use that stays real, so the V#'s four loads through the record pointer are emitted for the copy, and the descriptor handles still take the snapshot. No kept read goes through a rewritten handle, so the other users read the guest's V# and descriptor words at dispatch. The copy needs the V#'s words to be loads through the record pointer that the program emits. Any other V#, and a data read through a handle on the V#'s words, remain refused. The shared-V# reuse test now checks both T#s per group and the word the later s_load reads behind T#2's dwords 0 and 1, which the test backs with a snapshot at that address. The T# and S# consumer cases that d132754 refused now check the real descriptor word. A data read through a third handle and a T# consumer whose V# comes from a keyed table record stay refused. Shape from hugodearaujo's IR on boykopovar#8939 (issuecomment-6340144242).
… the same buffer Marvel's Spider-Man 2 (PPSA03016) on boykopovar#9790 stops at 135 s in compute 0x11e2b40f00 at ReadConstBuffer@pc=0x9a50, a T# read through a pointer-loaded V# at (word >> 16) * 32, where the word is a data read through the same V#, next to an S# read through that V#. hugodearaujo's run: boykopovar#9790 (comment) On boykopovar#9790 the T# plans as a nested child with an unkeyed domain, but the S# is refused: the key read's handle shares the V#'s words with the S#'s handle, and DescriptorWordReads takes only descriptor words, so the S# falls to GetHandle and its dword 0 is not a valid runtime value. A sibling read is now taken as a child key word when it is a scalar read at an immediate offset through a rereadable V# and its uses only reach the offsets of T# or S# reads through the same V#, as scale * ((word >> s) & m) + c. The key read keeps its handle and the V#'s loads, so the dispatch reads the guest's word. The T# or S# column gets a child key domain (offset, shift, mask): the snapshot reads that word from each child buffer and maps only the entry it selects. possibleU32Bits follows a right shift by a constant, so the child table spans at most min(num_records / stride, the key's range), 65,536 entries for a 16-bit field. A key the dispatch reads differently from the snapshot faults outside the key domain, and a key past num_records reads a null T#, as s_buffer_load_dwordx8 does past num_records. A store through a handle on the V#'s words, keys from two words or from a word at a runtime offset, and other data reads through the V# stay refused. KeyDomain gains child, shift and mask, so the shader disk cache format moves to 50. The test reads a key word at 0x14 and an S# at 0x20 of each child buffer and checks keys 2, 5, 17, 30 and 47 (the last of the V#'s 48 T#s), both S#s, a moved record pointer, null T#s for keys 48 and 65535, a fault for a key the dispatch reads differently from the snapshot, and the refusals above. This does not make the title pass: the same IR also merges the 0x4c0 T#'s dwords 0 and 1 into the record pointer, which stays refused here.
…ed V#'s record pointer In hugodearaujo's IR for Marvel's Spider-Man 2 (PPSA03016), compute 0x11e2b40f00 reloads the V# at pc 0x9a3c through a record pointer whose two words are Phis: record dwords 2 and 3 on most edges, and dwords 0 and 1 of the T# read at 0x4c0 through the same V# on the edge from $353. boykopovar#9790 (comment) The T# read at ReadConstBuffer@pc=0x9a50 through that V# is refused with "GetImageResource dword 0 is not a valid runtime value", whatever its offset: TryMakeIndirectColumn walked a merged V# pointer with PointerRecordReads, which takes only the record read and constants on the low word, and it needed the high word to be the record read itself. A merged V# pointer now goes through PointerRecordPairs, the edge-paired walk that a pointer-keyed T# already uses, and a word read as part of a T# or S# is a pointer-free arm there, like a constant or a lane mask. The child is looked up by the actual 64-bit pointer, so that arm, which the snapshot never captures, faults outside the snapshot when a lane takes it instead of reading a T#. The record reads on every edge must still be one read per word for a V#. The test samples the T# at 0x4c0, moves its dwords 0 and 1 into the record pointer under a condition, reloads the V# behind that Phi, and reads the key word, the T# at the key and the S# through it, as the IR does. It checks the three reads per lane with the arm not taken, and a group that takes the arm faulting outside the snapshot. That last run replaces the key read with a constant: a data read through a V# loaded from an unmapped pointer crashes lavapipe on boykopovar#9790 as well, as its shared-V# reuse shader does with an unmapped record pointer. On boykopovar#9790, and with the previous commit alone, the test is refused with the text above. This does not claim the title passes.
A scalar memory load ignores the two low bits of its address. The emitter cleared them in the offset and the immediate of an s_load through an SGPR pair, but kept them in the 64-bit base, so a base whose low word ends in 01, 10 or 11 read past the dword the hardware reads. A record pointer taken from a T#'s first word therefore read up to three bytes too far and faulted when those bytes were not mapped. The base pair's low word is now cleared like the offset's. A read through a user-data anchor translates from the cleared base, and ImageTableAbi::ScalarAddressDword, which the materializer uses to read the records behind such pointers and to plan their read ranges, clears the base the same way. The SRT walker already did. agc_driver_bda_anchor_reads runs two scalar loads through a user-data base with low bits 01, 10 and 11, and the scalar address rule in agc_shader_memory checks the same bases on the CPU. The pointer image table case that expected a table base off a dword boundary to leave every record unmapped now expects the records at its dword, the same as the aligned base.
… every platform The reuse case builds a record pointer from T#2's first word, the texel address shifted right by 8, so its low two bits are bits 8 and 9 of wherever the linker put the texel array: set on macOS, clear on Linux. The texels now sit 0x100 and 0x300 bytes into a 1024-aligned array, so the two T#s' first words end in 01 and 11 everywhere and the scalar load through the pointer always has to ignore them.
…ution memo footprint ImageTableColumnSnapshot keeps its read ranges, four words each, and ColumnRecords::Footprint already counts them. resolutionFootprint did not, so a resolution memo entry could hold more than ResolutionMemoWords. Count them for the tables and the nested tables. The plan round trip now resolves a nested fixture's snapshot twice with 2^21 read ranges on a table, then on a nested table: four words each fill the memo budget, so the entry must not be kept.
…th immediates The pointer walk skips an edge whose low word is an immediate, as a waterfall loop's Phi gives one beside the record column read. Where the pointer's two words are Phis of one block, an edge on which both are immediates is a constant pointer that no record holds, such as a null pointer, so the walk now refuses the column there instead of planning it.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this change based on the implementation and tests inspected; I could not complete a full review because one changed file was excluded from the review bundle.
What I ran
Inspected the prepared diff and relevant code at head fd3c021c15930639fdc8aafbcd316e3f5365f767. No test commands were run; reported test results below are author supplied.
Results
| Check | Result | Note |
|---|---|---|
| Targeted code review | passed | Core paths and selected tests inspected |
| Reported validation | not run | Author reports GPU and CI runs |
| Full changed-file review | not run | One file was excluded for size |
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was excluded from files/; only its changed diff hunks and targeted head ranges were available. I did not read all changed lines across every reviewed file or run the reported commands. The reported rendering output for Spider-Man 2 was not verified.
Files read: description.md, commits.md, manifest.json, diff.patch; targeted ranges of ResourceTracker.cpp, ResourceMaterializer.cpp, ImageTable.cpp, and ShaderMemory.cpp; plus changed hunks in ShaderDiskCache.cpp, BdaAnchorReads.cpp, ImageTableAbi.hpp, resource metadata, cache serialization, SPIR-V emitters, CMake test registration, and docs/dev/debt/shader.md. ShaderMemory.cpp's full changed file was excluded by size.
To get this to a good state
Nothing is required. The focused implementation review found no concrete defect; the full test file and reported test commands remain unverified.
Moves this branch's FormatVersion from 95 to 98, above boykopovar#8939's 97.
…sharp-reuse Moves this branch's FormatVersion from 98 to 101, above boykopovar#9457's 98.
Moves this branch's FormatVersion from 99 to 102, above boykopovar#9790's 101.
|
Merged #9969's current head |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head 215d1820e3ef6ccf1b14437e146573acff74064f using the prepared diff and the pinned repo_read.py reader. No tests or builds were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Recompiler, materializer, and BDA paths inspected |
| Automated checks | not run | No commands or tests executed |
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
ShaderMemory.cpp is excluded from the review bundle because it is too large; its changed lines were not read. The remaining changed files listed in manifest.json were read through the diff and/or targeted head source ranges; no full-file audit was performed. Runtime behavior and the author-reported test results were not independently verified.
To get this to a good state
Nothing is required.
ligmaSec
left a comment
There was a problem hiding this comment.
The trial merge onto c1601e56d5 conflicts in the image-table test source and registration and in ShaderDiskCache.hpp. I verified that this exact head is an ancestor of #18106. Preserve the fixture where a nested sampler’s buffer provides the key for a sibling image descriptor and also supplies the sampler data. Testing either use alone could miss the shared provenance change. Reconcile this cache schema before running the stack’s shader-memory and execution fixtures.
AI-assisted: yes.
What
Marvel's Spider-Man 2 (PPSA03016 01.004.003), with #9969 applied, stops on a compute shader whose S# the recompiler refuses:
The same block also appears 0xbb8 higher, at pc 0x9a78 / 0x99fc. The shape, from the IR posted on #9790 on 2026-11-02:
#9969 handles a key word whose T# reads go through the same V#. Here the key read through A indexes B.
ChildKeyWordrequired the T# reads to use the key's own handle, soDescriptorWordReadsrefused A's key read, and with it the S# column read through A.ChildKeyWordnow also accepts T# reads through a sibling V# whenDescriptorWordReadsasks on behalf of a V# that is read again at dispatch. A sibling is aGetBufferResourcewhose four words areLoadAddressU32s from the same, or an equivalent,GetAddressResourceas the key's V#. Nothing else changes:MatchChildKeystill requires the same handle, so the column falls back toMatchKeyDomain: B's table binds every key the key's known bits allow, up to B's num_records. Narrowing it would need the materializer to read the key from the other V#'s buffer.The debt entry for nested image tables records this form and its limits.
Tested
Arch Linux (kernel 7.2.14), AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.6), Release. The branch is #9969's head
5f70ec884eplus the three commits of this PR, joined by a merge (77b4696698).New test
agc_driver_pointer_vsharp_sibling_key_table(agc_driver_image_table_tests --pointer-vsharp-sibling-key). It uses #9969's child-key shader with the T# array in a second V# loaded through the same record pointer. A's buffer holds the key and the S#. B's buffer holds the T# array, plus a decoy key and the opposite S# at the same offsets, so reading A's words from B would show up. It checks:None of these recompile the shader.
Paired validation of the 21
agc_driver_(nested_image_table.*|nested_sampler_table|pointer_.*_table|image_table)tests, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=layer:VUID-linesResourceTracker.cppfrom5f70ec884eOn the base, the new test fails the way the title does:
The validation layer was inserted in every test of both runs. The 63
^shader|^agc_shadertests pass on this branch. These results are from the merge of5f70ec884e(2026-11-10), built withmaineaec74e merged on top locally; the same pair on the earlier bases0ef70b4bcb,ce65f496e6,5a8c3cc229,c147aa8647and9e7ac69470gave the same counts.Title: Spider-Man 2, relinked with
--module-dir . --registry, fresh shader cache, Cross every 30 s, until the first stop. Base:main4f41f4c + #99699e7ac69470+ #893958ebe4b440+ #1364617770dd69f+ #153997a9ecdc365. #13646 keeps the bindless table's textures inside VRAM, and #15399 stops an intermittentruntime resource snapshot did not stabilize.RenderFrameIndexat 5683. The refusing runs stopped at frame 1460 (this base) and at frames 4856 and 5015 (the earlier head).device-local heap 1 uses 16314 of its 16304 MiB budget), and my memory guard stopped it at 161 s. That fill comes from the bindless table (Marvel's Spider-Man 2 (PPSA03016) #10195), not from this change.Not verified: the picture. On this machine the bench's screenshots of this title are black after about 60 s in every run, with or without this change, so I can't judge the rendering. The new test checks the selected T# and S# against the guest's own.
On current
main. The head,215d1820e3, merges #9969's current head78bdc14492and thenmainbfcd717 into this branch. The disk cache format is #9969's, 102, abovemain's 96; this branch changes no encoded structure itself. Thewindowsjob's GCC error inpossibleU32BitsDepthfrom the 11-14 merge ofmainstays fixed: theShiftRightLogical32case callspossibleU32BitsDepth, as on #9969. With the validation layer andctest -V -R '^(agc_driver_(image_table|nested|pointer)|agc_shader_(disk_cache|memory|nested_sampler|sampler_limits)|spanned_uniformity|shader_memory_decoder_tolerance)'on the RX 9070 XT, it gives 58 tests: 57 pass andagc_driver_image_table_vouched_lookupsskips (the device reports written imported pages). Onmainbfcd717 the same command gives 45 tests: 44 pass and the same skip. No log has aVUID-line or "was not found but was requested".Runs by others.
77b4696698merged ontomain07ae6af, CachyOS (Linux 7.3.1), GCC 16.2.1, Release,ctest -R '^(agc|video_out|shader)'without the validation layer, compared withmainon the same machine. On an NVIDIA RTX 3070 Ti (615.78.08) and an Intel UHD Graphics 630 (Mesa 26.2.6) there is no difference frommain, and the 18 new tests pass on both.77b4696698and its merge base3eb7a74e1c,agc_shader_disk_cache_tests,agc_shader_memory_testsandagc_driver_image_table_tests, 3 runs each, Release. Ubuntu 26.04.1 with an RTX 4070 Ti (NVIDIA 615.71.09, GCC 15.2), and a Windows 11 VM with a GeForce GT 1030 (NVIDIA 582.78, WinLibs GCC 15.2 UCRT). The 18 new tests pass 3 of 3 on both machines, and no other test differs between the base and the head. On the Windows VM, 16agc_driver_image_table_*tests fail 3 of 3 on both sides.77b4696698merged ontomainc5488026ab, Windows 10 22H2, AMD Radeon RX 6750 XT (Adrenalin 26.10.1), WinLibs GCC 15.2 UCRT, Release, no validation layer. The 22^(agc_driver_(nested|pointer)_.*|agc_shader_nested_.*)$tests, the 18 new ones included, pass 3 of 3. In three full^(agc_|windows_write_watch$)runs (1,601 tests), compared per test withmainon the same card: one run had a start-up crash inagc_driver_draw_cache_reuse_entry_verify(replace guest placeholder with private memory, in code this PR doesn't change; AGC: agc_driver_direct_write_completion fails on Windows since #13159 #15564 records it onmain), and one, slowed by other work on the machine, had three GPU waits time out. Neither came back in the other runs or when run alone.main56c80b0917+ mrfelek's lazy image tables (9db1fcd707) + this PR at77b4696698, and the same build without this PR, one run each, RTX 4090 (NVIDIA 620.70.06), GCC 16.2.1, Release, fresh shader cache, Cross on the black screen about every 30 s. Both builds carry a local switch that drops a refused compute dispatch instead of stopping. Without this PR, the one dropped program refuses at pc 0x84bc (LoadAddressU32@0x84a8← the record at0x1fc4), and bindless table 0 is never resolved. With it, the dropped program refuses at pc 0xa5b0 instead, the next stop in my runs too (fix(shader): let a re-read nested V#'s words and keys be spilled to VGPR lanes #18106), and table 0 is resolved after the presses.77b4696698merged ontomain510d0bf986, Windows 11 Pro, Radeon Vega iGPU (GCN, Ryzen 5 7530U), AMD driver 23.19.24.04, WinLibs GCC 16.2.0, Release, with the validation layer. The newagc_driver_pointer_vsharp_sibling_key_tablepasses 3 of 3, with noVUID-line.d38090f95bmerged ontomain40206fe50d, Arch Linux, RTX 4090 (NVIDIA 620.70.06), GCC 16.2.1, Release, layer 1.4.363.1, the command above.main40 of 40, this PR 58 of 58, none skipped; noVUID-line, and the layer is inserted.Checklist
main; no other open PR implements the same functions (fix(shader): index a pointer-loaded V#'s T# array by a word read from the same buffer #9969 and fix(shader): plan several T#s read through one pointer-loaded V#, keeping the V# real for their other uses #9790 handle a key read through the T#'s own V#; this is the sibling-V# form neither covers)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)mainalso shows fix(shader): index a pointer-loaded V#'s T# array by a word read from the same buffer #9969's chain)