fix(shader): bound image-table snapshots by table-key ranges #7684
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7684"
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 fdfawef324 on 2026-10-18T22:51:10Z.
What
A 32-bit bit-scan key can select image-table records 0–31 or the all-ones sentinel, but capture still visits up to 65,536 records. Unreachable entries can then become invalid resources. Bound snapshots using conservative unsigned ranges through bit scans, bit counts and arithmetic. Masked offsets bound the final record rather than the unmasked key; shared columns retain the larger bound.
Keep the existing fault behavior for address columns and for a sentinel whose wrapped offset lies inside a heap. Records inside the proven bound are still captured and validated. Instruction execution semantics are unchanged. Cross-lane reads and cyclic values remain unbounded by the new range analysis. Serialize the sentinel flag alongside current selection and pointer-hop metadata. This rebase retains main's
SharedValues/Sealstorage and uses disk cache format 41 after main 40, with a naturally regenerated source fingerprint.This addresses one table shape used by Demon's Souls (PPSA01342). The unbounded waterfall family, remaining giant-texture allocations and device loss need separate work.
Overlap review found a textual conflict with #7395's nested-table capture refactor, which depends on #7223. Its author agreed to merge #7684 first, then preserve both metadata fields, the sentinel predicate, parent budget and unbounded merged-pointer guard when moving capture into
ReadColumn, followed by their combined table tests. There is no build dependency on those PRs. #7388 changes cross-lane known-bit propagation consumed by the existing bits bound; combined masked/empty-exec behavior has not been tested, and needs review before composing them. No defect in that PR is claimed.Tested
Windows, GCC 15.2 Release/O3, exact head
cbc4606a7906based on main676d423968a1:agc_shader_bindless,agc_shader_memory,agc_shader_disk_cache, 3/3 passed without skips in 6.25 seconds. Cases cover masked bit counts with record masks 255 and 31, bit-scan sentinels, heap versus pointer faults, arithmetic overflow, merged columns and cache round trips. The rebase adapts three snapshot-word accesses to main's per-column storage.df6aa653d1d7head: removing the range proof failed the heap-bound assertion; removing the masked non-sentinel minimum failed the BitCount32 assertion. That exact range-analysis production code is retained through this rebase. Those removal runs are historical evidence; the CPU/GPU checks here were rerun on the current head. A separate independent source review checked unsigned transfer rules, sentinels, overflow, shifts, select/Phi cycles and current memo reuse; unknown/cross-lane cases remain conservative.agc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_cache_bounds,agc_driver_image_table_reuse,agc_driver_bindless_images,agc_driver_graphics,agc_driver_compute_table_calls, 7/7 passed without skips in 16.04 seconds. Five suites execute Vulkan on the RTX 3060; graphics and image-table-cache use CPU/mock paths.ANYPS5_REQUIRE_VULKAN=1was set; executable/library hashes were checked before and after this exact-head run.72a3d9f2a49dchecked separately; execution above is the stated 676-based candidate. Later main adds separate F16 conversion, optimizer input-validation and kernel stack changes; the combined merge was not executed. Linux execution was not run.Encoded shaders are handwritten synthetic extensions of existing project fixtures; no game shader bytes are included. A prior private DS integration on a different stack completed its 3001.5-second cap and traced 32 records for the bit-scan column. That is historical integration evidence, not a controlled FPS, memory or timing comparison for this head. No title performance improvement is claimed.
Checklist
main; no other open PR implements the same functionsNotImplemented_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)Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T00:52:17Z.
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
df6aa653dmerged onto currentmain(a373e85e5); the merge is clean.agc_shader_memory,agc_shader_bindlessandagc_driver_image_tablepass with the change (17 tests of theagc_shader_*group that I built all pass; the ones that were not built here were not run).mainwith only this PR's three test files,agc_driver_image_tableandagc_shader_memoryfail withGetImageResource dword 0 is not a valid runtime value; chain: Phi(ReadConstBuffer@pc=0x00000028(..., so the new cases do depend on the change.Not tested: Demon's Souls (PPSA01342), so the claim that the table shape is fixed for the title is unchecked. The range analysis in
ResourceTracker.cpp(about 190 lines) I did not review closely, and it decides which table records are captured; I would want a second reviewer on the range arithmetic through bit scans and masked offsets. The description's note on the agreed merge order with #7395 is useful. I am not approving; this is a test report only.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-19T04:18:30Z.
Tested on Marvel's Guardians of the Galaxy (PPSA01748) for #7362: main
659230f7b+ the fix commit of #6606 + this PR (92e37f735). It still stops at the same place, about 4.5 minutes in after the opening menus (language, brightness, adjustments → Start Game):From reading
KeyRange::Compute, I think two things keep this key unbounded, so it never gets the 0–31 / −1 bound:ReadFirstLane, andReadFirstLanefalls through todefault(unbounded).Phiarm of theSelectU32carriesBitCastU32F32(FPMax32(...)), a float's bit pattern, not a bit-scan result.The T# address here is also loaded through a pointer (
LoadAddressU32of aGetAddressResource) rather than read directly from the image table, so this might be outside the PR's scope anyway. No regression seen up to the stop (one run).Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-19T04:48:37Z.
@klosixgaming-arch thank you for the RTX 5090 test report and the removal controls. I am keeping those results attributed to your
df6aa653dcomposition. An independent review of the bit-scan, mask and wrapping-arithmetic bounds is in progress alongside the rebase onto676d42396; the update also preserves main's shared column snapshots and resolution reuse. I will include the exact updated-head checks with that update.@Tamalero the remaining stop is consistent with this PR's conservative boundary. A
ReadFirstLanewrapper or a value arm with an unbounded float bit pattern does not establish the bounded integer key this analysis needs. Pointer-based descriptor addressing also needs its own supported plan. I am retaining those refusals during the rebase; your run does not establish a Guardians milestone or a regression from this change. Thank you for recording that limit.AI-assisted: yes (Codex)
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-19T05:17:00Z.
Rebased to
cbc4606a7906e51c379f8d9552449584398e9e31on main676d423968a1, preserving the newer per-columnSharedValues/Sealimplementation and refreshing the three affected snapshot-word test accesses. The serialized sentinel field now uses format 41 after main 40; source/cache and clean revision identities were regenerated normally.The requested second source review found no defect in the conservative unsigned transfer rules, sentinel handling, overflow/shift bounds, select/Phi cycle handling or current memo reuse. Current CPU suites pass 3/3; the sequential regression batch passes 7/7 in 16.04 seconds (five actual Vulkan cases and two CPU/mock cases) on the RTX 3060. The earlier exact removal controls are retained and qualified by their earlier head. A clean merge into
72a3d9f2a49dis checked separately from this runtime result.The external RTX 5090 report remains attributed to the earlier
df6aa653d1d7plus its stated main. The Guardians report does not establish a regression or a new boot here: cross-lane values, mixed float/Phi cases and pointer chains without a proof remain unbounded. #7395's agreed landing order and the fields/guards to preserve during its follow-up rebase remain in the description.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T07:45:58Z.
Intel and AMD Windows data: with this PR, the 18 tests built from its test files pass on an AMD RX 9070 XT. On an Intel UHD 770, all pass except
agc_driver_image_table, which fails there onmaintoo.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This headcbc4606a7merged intomain6b8228b2b.tests/ShaderDiskCache.cpp,tests/ShaderMemory.cppandtests/execution/ImageTable.cppagc_driver_image_tablefails:sampler tables need runtimeDescriptorArray and descriptorBindingPartiallyBound, which the device lacksThe UHD 770 failure is the descriptor-limit refusal that #6647 addresses, and
mainalone fails the same way.tests/ShaderMemory.cpphas changed onmainsince this branch's base, so I have no clean before-run.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T15:44:29Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main43a2abaf7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1636/1638 with this PR, against 1636/1638 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The PR adds no new ctest entry; every existing test it touches passed.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:34:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
At its own base the range analysis looks sound and its tests depend on it, but the branch no longer merges into current
main: it conflicts in four files, and one of the conflicts would silently breakmain's first-lane table path if it is resolved naively.What I ran
cbc4606a7906e51c379f8d9552449584398e9e31main:b433c40f2f46aa2e59e19806010a839ac8572d64676d423968a1a8fcc79c6247020ce22090a8e0d4The merge into
mainconflicted, so I built and tested the PR head itself, compared it with its base for validation output, and ran a negative control on the head.Machine: Arch Linux 7.2.11-zen, GCC 16.2.1 Release, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08).
Results
mainb433c40f2fcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp,core/shader/recompiler/Optimization/src/ResourceTracker.cpp,core/shader/recompiler/ShaderDiskCache.hpp,docs/dev/debt/shader.md(GitHub also reportsCONFLICTING)git diff --checkcheck_conventions.py --base origin/mainAll conventions checks passed.agc_shader_bindless,agc_shader_memory,agc_shader_disk_cache,agc_driver_image_tableat the headInserted device layer "VK_LAYER_KHRONOS_validation"); nowas not found but was requested by env var VK_INSTANCE_LAYERSVUID-lines, head vs base676d423968a1VUID-vkCmdDispatch-magFilter-04553inagc_driver_image_table, so the error already exists at the base and the PR adds noneConflict hunks (excerpt)
ctest at the head
Negative control
The new tests use the new
TableColumn::allOnesKeyfield, so restoring every production file from the base does not compile (TableColumnhas no memberallOnesKey). I kept the PR'sControlFlowInfo.hppandShaderDiskCache.*and reverted onlyResourceTracker.cppandResourceMaterializer.cppto676d423968a1. Three of the four tests then fail:Failures with the range analysis reverted
agc_shader_disk_cachestill passes in this control, as expected: the encoder lines it round-trips were kept. After the control I restored the PR's files.This agrees with the removal results that klosixgaming-arch reported on the earlier
df6aa653dhead, now checked oncbc4606a79on Linux.Findings
Blocking
main.mainhas moved on in the same code since676d423968a1:ShaderDiskCache.hpp:16is at format 49. EncodingallOnesKeyneeds a fresh bump on top of that (50 or later), not 41.MakeTableColumn(ResourceTracker.cpp:812-815onmain). That path also setsmasked = true, butMatchFirstLaneOffsetnever writes a record mask. The obvious resolution isif (!MatchMaskedOffset(offset, key, stride, recordMask) && (address || !MatchFirstLaneOffset(offset, key, stride))). Combined withif (masked) boundMaskedTableKey(column, key, recordMask), that resolution would send first-lane columns intoboundMaskedTableKeywithrecordMask == 0. TheirmaxKeywould become 0, so the snapshot would keep only record 0, and every other key would read the outside record. It still compiles, and nothing in the current test set obviously guards against it. Please keep the first-lane path on its own bound, eitherboundTableKeyor main'spossibleU32Bits, rather than the masked one, and add a case for a first-lane column to the PR's tests.docs/dev/debt/shader.mdonmainnow has the ReadFirstLane/SelectU32 bound paragraph from #7388. Two lines of the PR still say a key with no bound includes "a lane value made uniform byv_readfirstlane": its debt paragraph, and itsARCHITECTURE.mdline (ARCHITECTURE.md:159, which auto-merges). Both need to matchmain's behaviour after the rebase.ShaderMemory.cpptest conflict is in the same table-test area, so the new cases need re-running on the rebased tree.Non-blocking
Unblocks: PPSA01342 #1283points at discussion #1283, whose title is "Demon's Souls (PPSA01341)". Please use the title ID of the build you tested and its discussion, or say why the two IDs refer to the same title.docs/dev/debt/shader.md:37ends a sentence with "Main behaves the same way." Once merged, this paragraph is main, so the sentence only makes sense as part of a PR description. I suggest dropping it, or saying the gap predates the key-range bound.On the code itself, I checked the
KeyRangetransfer rules at the head and found no defect:-1-capable key is unbounded.c - xrequiresx.max <= cand givesc + 1for the sentinel.FindUMsb64gives{63, -1}, which matchesEmitFindUMsb64, ands_ff1_i32_b64'shighLsb + 32gives 63.boundTableKeydrops the sentinel when known bits exclude0xffffffff.boundMaskedTableKeybounds byrecordMaskwhen the key can be-1.Not verified
b433c40f2f.agc_driver_image_table_cache*,agc_driver_image_table_reuse,agc_driver_bindless_images,agc_driver_graphics,agc_driver_compute_table_calls); I did not build them.VUID-comparison against currentmain(only against the PR's base,676d423968a1).To get this to a good state
main, and bumpFormatVersionabove 49.MakeTableColumnbranch so thatMatchFirstLaneOffsetcolumns do not go throughboundMaskedTableKeywith an unsetrecordMask, and add a test for that case.main's ReadFirstLane/SelectU32 bounds (#7388).mainSHAs.Unblocksline.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:36:54Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes support the stated bounded image-table snapshot behavior; no concrete blocking defect was found in the source read.
What I ran
Reviewed head
cbc4606a7906e51c379f8d9552449584398e9e31. No commands or tests were run. Read the prepared description, commits, manifest, diff, and targeted source ranges throughrepo_read.py.Results
Findings
Blocking
None in the inspected code.
Non-blocking
None.
Not verified
The manifest was read only through its first 200 lines of 524, and the diff only through line 599 of 690; therefore the complete changed-file list, remaining diff, and whether every changed file was reviewed are not verified.
review/files.jsonwas unavailable through the reader. No repository tests, build, merge preview, Linux run, or hardware behavior were independently verified.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.