fix(agc): accept bindless image tables with entries wider than 32 bytes #5620
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5620"
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?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T01:25:45Z.
What
The bindless image-table planner only recognised a T# table whose entries are exactly 32 bytes apart (
key << 5orkey * 32). Resident Evil 4 (PPSA07411) loads its T# from a table with 48-byte entries, the T# in the last 32 bytes (key * 48, load offset 16). The descriptor therefore stayed aReadConstBufferand the recompiler stopped withGetImageResource dword 0 is not a valid runtime value.DescriptorSource::IndirectImagenow carriesentryStride(default 32).MatchTableOffsetaccepts a multiplier that is a multiple of 4 and at least 32; the planner requires the eight T# dwords to lie inside one entry;ResourceMaterializeruses the stride for the entry count, the partial-descriptor check and the entry address.ShaderDiskCache.cpp) writes and readsentryStride; without it a stored plan would reset the stride to 32, andmaindoes not build with the new field until the encoder is updated (static_assert ... IndirectImage changed: update the plan encoder).uniform table imagecase intests/ShaderMemory.cpp) stay direct images; only records it cannot evaluate become a table.New test cases:
agc_shader_bindless(inagc_shader_memory_tests) gets a 48-byte table; the round-trip case ofagc_shader_disk_cachenow uses a table with stride 48.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2, Release,
ninja -j 4of the sevenagc_shader_*test targets, ctest called directly in PowerShell. Headee950660358c6d199a23131ad00de6f96db50fba(three commits) onmain63fb0cd92e83eaba3b3d1ac88fc532c7dd32ae58;git merge-treeagainstmain5a6ad0ed36893e86022929b808ac547672445cd9(later) reports no conflict:ninjaexit 0;ctest -R agc_shader_bindlessexits 0 (1 of 1);ctest -R agc_shader_exits 8, 14 of 15 passed. The one failure isagc_shader_disk_cachewithcannot remove the shader cache test directory: Zugriff verweigertafter all of its round-trip checks printed; the same test fails with the same message onmain23be5a02b075bd05c7c27d8b18a3d47ead6fd0e5without this change (run alone; not re-run on63fb0cd92), so it is not caused by this PR.agc_shader_memorypasses (ctest -V -R ^agc_shader_memory$exits 0; ctest prints only the test name, theuniform table imagecase is in its source,tests/ShaderMemory.cpp).ResourceMaterializer.cppandResourceTracker.cpptaken back tomain; tests, header field and disk cache encoder unchanged):ctest -R agc_shader_bindlessexits 8, 0 of 1, withGetImageResource dword 0 is not a valid runtime value.python tools/check_conventions.py --base upstream/mainpasses.maind1670009f(logPPSA07411_rB/run_022642.err) ends withShaderRegistry.cpp:782 ... Shader 0x2060e9c100 could not be prepared after registration: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value.mainand without the disk cache change; no picture was checked, so nothing is claimed about the rendered image. Not re-run on the rebased head.agc_shader_*tests above), AMD.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T02:10:04Z.
Review: COMMENTED
Carrying the stride through the plan and the disk-cache encoder is the right shape, and requiring the eight dwords to sit inside one entry keeps the matcher safe. The new partial-descriptor check in
resolveTableImageis too strict for strides other than 32, though:This requires the heap to end exactly at the end of the last T#. That holds for RE4 only because its T# is the last 32 bytes of the entry (
16 + 32 == 48). Take a table with 64-byte entries and the T# first (offset 0), with a V# that covers whole entries (heapSize = 64 * n, the natural size):(64n - 32) % 64 == 32, so it throws "bindless heap contains a partial descriptor" although every descriptor is complete. The same happens for any layout where data follows the T# in the entry.A descriptor is only partial when the heap ends inside a T#. With
tail = (heapSize - entryOffset) % entryStride, that istail != 0 && tail < TableEntryBytes. The entry count stays(heapSize - entryOffset - TableEntryBytes) / entryStride + 1, as written. For stride 32 this reduces to the old check, so 32-byte tables still behave as onmain. A 64-byte/offset-0 case inagc_shader_bindless, next to the 48-byte one, would cover it.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T03:34:08Z.
Thanks, you are right: with
heapSize = 64 * n, a 64-byte entry and the T# at offset 0, the check(heapSize - entryOffset - 32) % entryStride != 0throws although every descriptor is complete. Fixed in98afd6bf2(an additional commit, no rebase): the heap is partial only when it ends inside a T#, i.e.(heapSize - entryOffset) % entryStrideis non-zero and below 32. The entry count is unchanged, and 32-byte tables keep the old behaviour.agc_shader_bindlessnow has a 64-byte/offset-0 case next to the 48-byte one.Windows 10 (19045), MinGW-w64 GCC 15.2, Release,
ninja -j 4, ctest called directly, head98afd6bf2d24a32b01d11be5a303ca6d33f71230(based55f7e25a):ctest -R agc_shader_bindlessexits 0;ctest -R agc_shader_exits 0, 12 of 12. WithResourceMaterializer.cpptaken back tod55f7e25a(new test kept)ctest -R agc_shader_bindlessexits 8 withbindless heap contains a partial descriptor. Logs: stride_r7_fix.log and stride_r7_nofix.log. Not tested: Linux, console, a title run of the new commit.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T07:30:09Z.
Title evidence for this pull request: PRAGMATA (PPSA02530), Windows 10 (19045), RTX 4080 SUPER, one 90 s run per state, no picture checked.
7cf13d706=main+ #54571243f067b+ #5550cd1757e03): 32 linesGetImageResource dword 0 is not a valid runtime value(first one at line 114), then the abortwhat(): shader 0x211145e100 stage 5: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00000568(...(line 207) and FATAL,PPSA02530_rR/run_092439.err.98afd6bf2) added (local merge treea57296147=main+ #5457 + this pull request + #5550): 0 such lines, nowhat()and no FATAL in the 90 s run,PPSA02530_rR/run_091659.err.return false at line 548(I attribute these to the shared-T# case that #5550 addresses; the log line itself does not say so); earlier runs of that state (PPSA02530_rP/run_073233.err,run_090831.err) show 2 linesGetImageResource dword 0each, not fatal in 90 s. So the title needs this change (stride 48) and #5550 (shared T#).Test conditions: the merge trees are local and not pushed (the base
maincommit was not recorded by me; the #5550 merge needed a local conflict resolution intests/ShaderMemory.cpp, which does not touch the libraries).ninja -j 8 libsexit 0, 128.prx(libSceAgcDriver.prxrebuilt for each run, oldest.prx2026-10-13 09:50 not rebuilt),nid_patcher2026-10-14 08:00:09;libSceConvertKeycode.prxreplaced by a local stub (without itmainstops insceConvertKeycodeGetCharacter); title executableapp.exeof 2026-10-14 07:36:44 relinked by another session (relinker version and relink command not recorded by me); run withrun_title.ps1, one game at a time.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T08:59:31Z.
AMD and NVIDIA runs for this PR at head
98afd6bf2. Windows 11 Pro 26200, WinLibs GCC 15.2.0 (MinGW-w64), Release, one machine with two GPUs, each picked withANYPS5_GPU:1002:13c0, RDNA 2), driver 32.0.21036.18ctest -R "agc|shader|video_out" -j 8(506 tests, including the ones this PR adds or changes):agc_driver_lds_mixed_width_atomics,agc_driver_pixel_interlockandagc_driver_layered_volume_vertex_no_gpl. These three fail the same way on currentmain(872f52320) on this GPU and pass there on the RTX 5070; they are the three of #5271, so not caused by this PR.No title run. AI-assisted: yes (Claude Code ran the builds and tests).
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-14T10:00:42Z.
Data point from another title. Marvel's Wolverine (PPSA03671, 01.001.005), Linux, RTX 3080 Ti (NVIDIA 615.71.09): merged on top of
main43349d433together with #5188, #5550 and #5473 it builds and runs. Compute shaders that used to fail earlier now reach the table: the remaining drops arestatic bindless image capacity exceeded(4 shaders) andbindless image table has 6948 entries (0 materials), limit 16(the game's bindless table has about 7000 entries). FYI: #5089 and this PR conflict inResourceMaterializer.cpp(both change how the table entry stride is computed), so they cannot be tested together without a manual merge. More in https://github.com/boykopovar/AnyPS5/discussions/5516.AI-assisted; the runs are from my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T10:26:27Z.
Title evidence: Onimusha: Way of the Sword (PPSA27836 01.000.001, RE Engine), Windows 11 Pro 26200, RTX 5070. On
main0b97f8b9fplus the start-up fixes listed in #5769, it stops preparing pixel programs that read their T# from 48-byte records at +16 (s_buffer_load_dwordx8atkey * 0x30), the key loaded through areadfirstlaneinside a bit-mask loop:A later program reads the same table T# for two image operations. With #5620 and #5550 both merged, both pass and the title stops next at
static bindless image capacity exceeded(#5720). Not run with only one of the two.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T12:30:47Z.
Title run on the rebased head: Resident Evil 4 (PPSA07411), Windows 10 (19045), RTX 4080 SUPER, one run of 120 s requested, no picture checked.
On head
d7e6318af8ead231863fa2e8b4c1dcb6553f80c8(merge tree = branch head,mainbase97eab6e63):PPSA07411_rY/run_142109.errhas 93 lines (counted with Python), 0 lines withGetImageResource dword 0 is not a valid runtime value, and nowhat(),FATAL,terminateorVulkan result. Lines 6 to 81 are 76 notesShaderRegistry.cpp:692 ... could not be prepared at registration (its s_swappc_b64 at program counter 0x74 calls a computed target); preparing it when it is used, which are not a stop; the log then continues with shader-disk-cache lines to its end.Before this change the same title stopped at that
GetImageResourcemessage (PPSA07411_rT1/run_110620.errline 93 on an earliermain).Test conditions: all 128
.prxrebuilt (ninjaexit 0, 14:19:03 to 14:20:57 local time); title executablePPSA07411_rY/app.exe, a hardlink of thePPSA07411_rHone dated 2026-10-14 07:38:51 (relinked by another session; relinker commit and relink command not recorded by me); run throughrun_title.ps1, one game at a time; script start 14:21:07, end 14:27:45 (includes the wait for the game lock). One run only.Not tested: Linux, other GPUs, a longer run, a second run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T12:46:16Z.
Heads-up: rebased onto current
main(9a3e2ac4d), this PR breaksagc_shader_memory, which gained #5188'sverifyUniformTableImagein the meantime:That test reads its T# with
s_buffer_load_dwordx8ats2 * 48 + 16, a key from user data that the SRT walk evaluates per capture. With 48-byte records accepted,TryMakeTableImagenow plans it as a bindless table first. Onmainit was safe only because the stride was 48. One way out would be to keep the table path for keys the walk cannot evaluate (aReadFirstLane, a material read) and leave evaluable keys toGetHandle, but that is your call.Reproduced on Windows 11 with only this PR's two commits rebased onto
main(conflicts with #5089 inResourceMaterializer.cppandShaderDiskCache.cppresolved by keeping both). #5820 carries these commits and hits the same failure.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T13:01:52Z.
Thanks for the check. The head
d7e6318af8ead231863fa2e8b4c1dcb6553f80c8(pushed after your comment) already takes that way out: a record wider than 32 bytes whose T# the runtime walk can evaluate at each capture (theuniform table imagecase) stays a direct image, and only records it cannot evaluate become a table.On that head,
ctest -R agc_shader_on Windows 10 (19045) ran 15 tests: the only failure wasagc_shader_disk_cache(cannot remove ... Zugriff verweigert, the same onmainwithout this change), soagc_shader_memorypassed (stride_r8_fix.log, 14 to 16 local time on 14 October; without the changeagc_shader_bindlessfails withGetImageResource dword 0 is not a valid runtime value). I have not run the newverifyUniformTableImageof #5188 on a rebase onto the latestmainyet;mainhas moved again and this PR needs another rebase, which I will do and report.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T13:24:25Z.
Title evidence for the evaluable-key case above. Onimusha (PPSA27836) has a draw whose T# is read from the same 48-byte table, at a key the SRT walk can evaluate (
ReadConst(GetSrtResource, 0x82) * 0x30). With this PR it is planned as a whole bindless table and the first presentation stops:Locally,
TryMakeTableImagereturningfalsewhenSrtWalker{}.ValidateRuntimeValue(m_program.Resources(), key)holds, right afterMatchTableOffset, sends that T# toGetHandleagain. With it,verifyUniformTableImage(#5188) passes, the title gets past this draw, and its material tables (keys throughreadfirstlane) are still planned as bindless tables (mode M, 1 keysinAPS5_TRACE_BINDLESS). I have not proposed it separately since it belongs to this change; feel free to take it.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T13:36:19Z.
Follow-up to my earlier reply: the head is now
ee950660358c6d199a23131ad00de6f96db50fba(three commits onmain63fb0cd92; #5089 was reverted in #5824, so theindexedfield is no longer part of this change).I checked your
uniform table imagefinding on this head withcteston Windows 10 (19045): with the third commit (a record wider than 32 bytes whose T# the runtime walk can evaluate stays a direct image)ctest -R ^agc_shader_memory$exits 0; withResourceTracker.cpptaken back to the second commit,agc_shader_memoryfails withuniform table image: the T# read from a constant buffer was not planned as one image(red3.log). The first of the two runs was not repeated, one run each.agc_shader_bindlessexits 0 with the change and 8 without it (GetImageResource dword 0 is not a valid runtime value).ctestprints only the test name, not the single case, so the case itself is not shown in the pass log.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T13:41:49Z.
Baseline for the title run above, on a recent
mainwithout this pull request: Resident Evil 4 (PPSA07411), Windows 10 (19045), RTX 4080 SUPER, one run of 120 s requested.maine736e5bdb18e72ed717014c02c62c616701a7cf8(clean worktree, no local patches according to the session that ran it; it contains #5550, #5189, #5555 and #5188):PPSA07411_rL/run_153844.err(574 lines, counted with Python) ends in line 93 withwhat(): shader 0x206d076700 stage 5: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00001b24(GetBufferResource(ReadConst(GetSrtResource, Immediate), ..., followed byFATAL: abort() (SIGABRT)in line 96. The earlier baseline on an oldermain(PPSA07411_rT1/run_110620.errline 93) is the same stop with a different shader.With this pull request (head
ee950660358c6d199a23131ad00de6f96db50fba; first run on an earlier head, see above) the same title ran without that stop. Differentmainbases, one run each; libraries rebuilt for each run (ninja libsexit 0 for both); executables are relinked ones from another session (relinker commit and command not recorded by me); no picture checked.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T13:56:00Z.
Thanks for the Onimusha (PPSA27836) report. I compared your local fix (return
falsefromTryMakeTableImageright afterMatchTableOffsetwhenSrtWalker{}.ValidateRuntimeValue(m_program.Resources(), key)holds) with the third commit of this PR (headee950660358c6d199a23131ad00de6f96db50fba).What the third commit does (
core/shader/recompiler/Optimization/src/ResourceTracker.cpp, inTryMakeTableImage,if (entryStride != 32u)at line 551, after the entry-offset check): for a stride other than 32 it builds the directDescriptorSourceof the handle (MakeSource(handle, 8u, false, false, direct)) and returnsfalsewhenValidateSource(direct, badDword)holds.ValidateSource(ResourceTracker.cpp:229-240) runsSrtWalker::ValidateRuntimeValueon each of the eight T# dwords. A T# dword that is aReadConstBuffervalidates its arguments recursively (SrtRuntimeValidator.cpp:111-143,ValidateArguments), so the heap offsetkey * 0x30 + immediateis validated, which includes the key; for your keyReadConst(GetSrtResource, 0x82)theReadConstcase (SrtRuntimeValidator.cpp:43) accepts aGetSrtResourceread with an immediate slot.Difference to your fix:
IsRawReadand aGetBufferResourcehandle), yours validates only the key. For a key that is a plain SRT read the two should agree; I have not found a case in the code where yours returnsfalseand mine does not, but I did not prove equivalence.61890ae7astates that this is the existing behaviour). Your fix would move those toGetHandletoo.Does the head cover your case? By the code, yes: a 48-byte stride (
* 0x30) with a key fromReadConst(GetSrtResource, 0x82)takes the newreturn falsepath and the T# goes toGetHandle. Tests:verifyUniformTableImageintests/ShaderMemory.cppcovers a 48-byte record with the T# at +16 and a key read from user data (it fails withuniform table image: the T# read from a constant buffer was not planned as one imagewithout the third commit and passes with it;red3.log,ctest -R agc_shader_memory). There is no test with a key that is an SRT read (GetSrtResourceslot 0x82), and I did not run Onimusha, so that exact shape is not covered by a test. If you can share the shader or a test case with that key shape, I will add it.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T14:52:43Z.
@xXPBSXx thanks for the comparison. Your head covers the Onimusha (PPSA27836) case in practice. On my local branch I replaced my fix with
ee9506603(reverted my commit, cherry-picked yours, nothing else changed). On Windows with the RTX 5070, the title prepares the same programs and stops at the same later point as with my fix: the first presentation, which now fails with "a color target's sample count differs from the rasterizer's" (checkerboard rendering, after #5861). No bindless table error. So I'm dropping my local fix in favour of your commit.I'd rather not post the title's shader binary. The shape is a 48-byte stride (
* 0x30) whose key isReadConst(GetSrtResource, 0x82): a dword the programs_loads through the SRT pointer at slot 0x82, not user data directly. A test likeverifyUniformTableImagewith the key loaded through an SRT pointer would cover it; I can write that if it helps.#5820 is now rebuilt on your head
ee9506603, andagc_shader_memorypasses there,verifyUniformTableImageincluded.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T15:43:39Z.
Windows measurement for PRAGMATA (PPSA02530), with and without this PR. One 200 s run each, RTX 4080 SUPER, Windows 10, same
app.exerelinked once against the libs of each build; no picture was checked.upstream/main84b01f9cd+ #5776 head378ac6178, the six files of this PR reverted to84b01f9cd):PPSA02530_rU1/run_173936.err(753 lines). First shader error at line 111 and the stop at line 269:what(): shader 0x2234462c00 stage 5: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00000568(...), then line 272FATAL: abort() (SIGABRT). 52 lines containGetImageResource.70383a292, parents:ade05983b=84b01f9cd+ this PR's headee9506603, and378ac6178):PPSA02530_rU1/run_173119.err(311 lines). 0 lines containGetImageResource. The stop is now line 124what(): shader 0x2111d34600 stage 5: ShaderRecompiler::Recompile: static bindless image capacity exceededand line 127FATAL: abort() (SIGABRT), which is the capacity limit tracked in #5720.So in these two runs this PR removes the
GetImageResource dword 0stop for PRAGMATA and the title reaches the next stop. Not tested: Linux, other GPUs, a second run per side, a picture, and PRAGMATA without #5776 (on plainmainit stops earlier atsceConvertKeycodeGetCharacter, #5726).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T16:19:46Z.
Closing as superseded by
d9e47d1e9(feat(agc): implement image and sampler tables indexed at runtime offsets) and34525fdf7(feat(agc): implement image tables loaded through 64-bit pointers), which are now onmain. They replaceDescriptorSource::IndirectImagebyTableColumnwith astrideand anaddend(ControlFlowInfo.hpp), andMatchAffineOffsetinResourceTracker.cppaccepts any multiplier that is at least 4 and a multiple of 4, so the 48-byte entries this PR was written for (Resident Evil 4, PPSA07411:key * 48, load offset 16) are planned without it. The PR no longer applies (conflicts inResourceMaterializer.cpp,ResourceTracker.cpp,ControlFlowInfo.hpp,ShaderDiskCache.cppand its test).Title evidence on
mainwithout this PR: PPSA07411, Windows 10 (19045), MinGW-w64 GCC 15.2, Release, NVIDIA GeForce RTX 4080 SUPER.maine34c479210c78d7b160d7054f3e72de422b23d7a(no other PR merged in),ninja -j 8 libsexit 0 (script times 18:02:44 to 18:08:30),run_title.ps1, 120 s requested, script times 18:08:46 to 18:10:57, one run:PPSA07411_rY/run_180850.err(line count by Python) has noGetImageResource dword 0 is not a valid runtime value, nowhat()and no FATAL; the log ends with shader disk cache lines. Before:maind1670009f,PPSA07411_rB/run_022642.errended with that error (quoted in the PR description). Title executablePPSA07411_rY/app.exe(hardlink ofPPSA07411_rH, dated 2026-10-14 07:38:51); relinker commit and command for it are not recorded in my notes. No picture was checked. Not tested: Linux, a second run, other GPUs.Second title (PRAGMATA, PPSA02530, whose
GetImageResource dword 0chain here is aReadConstBufferread, not a 48-byte stride):maine34c479210c78d7b160d7054f3e72de422b23d7a+ #5776 (378ac61788f1ee2065909a3360e43f12cd9a0cda) merged (merge treeb072851e208728569ada2bd9516810972b7fa3df), without this PR;ninja -j 8 libsexit 0 (script times 18:14:11 to 18:15:02); 200 s requested, script times 18:15:19 to 18:17:41, one run;PPSA02530_rV2/run_181522.err: noGetImageResourceline. The title now stops later, at line 124:what(): shader 0x2107e05900 stage 5: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x141866064128 stage=2 opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation. Title executablePPSA02530_rV2/app.exe(hardlink ofPPSA02530_rH, dated 2026-10-14 07:32:23); relinker commit and command not recorded in my notes.AI-assisted (Claude Code).
Pull request closed