Repository navigation
fix(shader): bound image-table snapshots by table-key ranges - #7684
fdfawef324 wants to merge 2 commits into
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
Not tested: Demon's Souls (PPSA01342), so the claim that the table shape is fixed for the title is unchecked. The range analysis in AI-assisted: yes. Written with AI assistance and reviewed by me. |
|
Tested on Marvel's Guardians of the Galaxy (PPSA01748) for #7362: main 659230f + 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
The T# address here is also loaded through a pointer ( Tested and written by Claude (AI assistant) on a contributor's machine. |
… reach An image table key with no key domain kept every record of the snapshot domain: 65,536 records for a T# column read by s_load through a 64-bit pointer, whether or not a lane could select them. Demon's Souls (PPSA01342) pixel shader 0x248a7e700 walks a 32-bit set of lanes with s_ff1_i32_b32 and loads the T# at key * 32 from its table, so the hardware reads records 0-31 at most. Every capture still read 2 MiB of records and resolved each distinct decodable record as a table element; in run ds-tsharp-c01 the suspect-record report log, which stops at 1,000 reports per kind (both kinds reached it), held 1,978 distinct records of the three shaders with this loop (0x248a7e700, 0x248a8fa00, 0x248a8bc00), 4 of them below 32. The tracker now also bounds a key by its value range (KeyRange): s_ff1 is 0-31 or -1 (0-63 or -1 for a 64-bit source), s_flbit is 32 or -1 (the hardware returns 0-31 or -1; the bound takes 31 - msb before the select against -1) and 64 or -1 for a 64-bit source (63 - msb), a bit count 0-32 or 0-64, and the bound follows masks, minimums, shifts by constants, adds, multiplies by and subtractions from constants, selects and phis. Each rule holds for every u32 value. Cross-lane reads are not followed, since the lane they read may be inactive, and a value that depends on itself through a loop stays unbounded. The column keeps the smaller of this bound and the known-bits bound. A key that can be -1 (TableColumn::allOnesKey) selects a record past the snapshot. It keeps the fault check only where that record can fault: for an address column, and for a V# heap column when the offset of key -1 (addend - stride, modulo 2^32, plus the instruction's immediate offset) lies inside the V#. Past the V# the lane reads the column's outside record and raises no fault, so a heap keyed by s_ff1 does not turn on fault checks, completion callbacks or recipe exclusion that main does not have. The guarantee covers a column whose every access carries the bound: mergeTableKey drops allOnesKey when another access to the same column has no bound, and that column then raises no fault check for key -1, as on main (documented in docs/dev/debt/shader.md). A table read at (key << n) & mask selects the record key & (mask >> n), which is at most mask >> n for every key, including -1. Such a column is bounded by that record instead of the unmasked key: mask >> n when the key can be -1, the smaller of that and the key's bound otherwise, and it carries no allOnesKey. Bounding the unmasked key refused a record the hardware reads, for example (s_ff1 << 5) & 0x1fe0 of an empty set, which loads entry 255. The flag is part of the plan's disk-cache encoding, and APS5_TRACE_IMAGE_TABLE prints each column's key bound. Records inside the bound are still snapshotted whether or not a lane selects them. The four suspect records below 32 in that run (11, 13 and 15 of 0x248a7e700, 11 of 0x248a8fa00) have invalid format fields, so they are poisoned and never become textures. Keys made uniform by v_readfirstlane, the more common shape in the same title's cache, stay unbounded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Codex <noreply@openai.com>
|
@klosixgaming-arch thank you for the RTX 5090 test report and the removal controls. I am keeping those results attributed to your @Tamalero the remaining stop is consistent with this PR's conservative boundary. A AI-assisted: yes (Codex) Co-Authored-By: Codex noreply@openai.com |
Adapt the range regressions to per-column descriptor storage and advance the plan codec format for allOnesKey. Co-Authored-By: Codex <noreply@openai.com>
df6aa65 to
cbc4606
Compare
|
Rebased to 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 The external RTX 5090 report remains attributed to the earlier AI-assisted: yes |
|
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 Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
The UHD 770 failure is the descriptor-limit refusal that #6647 addresses, and AI-assisted: yes (Claude Code) |
|
First AMD-on-Linux (RADV) run of this PR. Merged onto 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 ( 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 |
XairRrR
left a comment
There was a problem hiding this comment.
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 break main's first-lane table path if it is resolved naively.
What I ran
- PR head:
cbc4606a7906e51c379f8d9552449584398e9e31 main:b433c40f2f46aa2e59e19806010a839ac8572d64- PR base (merge-base):
676d423968a1a8fcc79c6247020ce22090a8e0d4
The merge into main conflicted, 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.
git fetch -q origin main pull/7684/head:refs/review/7684
git checkout -q --detach origin/main
git merge -q --no-ff --no-edit refs/review/7684 # conflicts, aborted
git checkout -q --detach refs/review/7684
git diff --check origin/main...refs/review/7684
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target agc_shader_memory_tests agc_shader_disk_cache_tests agc_driver_image_table_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
ctest --test-dir build -j4 -V --output-on-failure \
-R '^(agc_shader_memory|agc_shader_bindless|agc_shader_disk_cache|agc_driver_image_table)$'
# negative control: head + ResourceTracker.cpp and ResourceMaterializer.cpp from 676d423968a1, rebuild, same ctest
# comparison: 676d423968a1 checked out, rebuild, same ctestMachine: 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
| Check | Result |
|---|---|
Merge into main b433c40f2f |
Conflicts in core/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 reports CONFLICTING) |
git diff --check |
clean |
check_conventions.py --base origin/main |
All conventions checks passed. |
| Build of the three test targets at the head | OK |
agc_shader_bindless, agc_shader_memory, agc_shader_disk_cache, agc_driver_image_table at the head |
4/4 passed, longest 1.70 s |
| Validation layer loaded | yes, on both the head and the base (Inserted device layer "VK_LAYER_KHRONOS_validation"); no was not found but was requested by env var VK_INSTANCE_LAYERS |
VUID- lines, head vs base 676d423968a1 |
both runs: 2 × VUID-vkCmdDispatch-magFilter-04553 in agc_driver_image_table, so the error already exists at the base and the PR adds none |
Conflict hunks (excerpt)
ShaderDiskCache.hpp
<<<<<<< HEAD
inline constexpr std::uint32_t FormatVersion = 49;
=======
inline constexpr std::uint32_t FormatVersion = 41;
>>>>>>> refs/review/7684
ResourceTracker.cpp
<<<<<<< HEAD
if (!MatchMaskedOffset(offset, key, stride) && (address || !MatchFirstLaneOffset(offset, key, stride))) {
=======
if (!MatchMaskedOffset(offset, key, stride, recordMask)) {
>>>>>>> refs/review/7684
docs/dev/debt/shader.md: main's "Image table pointer indexing ... propagates 32-bit value bounds
through ReadFirstLane and SelectU32" paragraph against the PR's rewritten key-bound paragraphs.
ctest at the head
1/4 Test #336: agc_shader_bindless .............. Passed 0.06 sec
2/4 Test #355: agc_shader_memory ................ Passed 0.19 sec
3/4 Test #368: agc_shader_disk_cache ............ Passed 1.12 sec
4/4 Test #580: agc_driver_image_table ........... Passed 1.70 sec
100% tests passed out of 4
Negative control
The new tests use the new TableColumn::allOnesKey field, so restoring every production file from the base does not compile (TableColumn has no member allOnesKey). I kept the PR's ControlFlowInfo.hpp and ShaderDiskCache.* and reverted only ResourceTracker.cpp and ResourceMaterializer.cpp to 676d423968a1. Three of the four tests then fail:
Failures with the range analysis reverted
336: image table masked offset: the record mask did not bound the loaded key
355: image table bit-scan heap: the column lost its bit-scan bound or affine offset
580: AGC graphics: pointer image table set-bit key: the snapshot read entries an s_ff1 key cannot select
25% tests passed, 3 tests failed out of 4
agc_shader_disk_cache still 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 df6aa653d head, now checked on cbc4606a79 on Linux.
Findings
Blocking
- The branch conflicts with
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.- #10228 added a first-lane offset path to the same branch in
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.- The
ShaderMemory.cpptest conflict is in the same table-test area, so the new cases need re-running on the rebased tree.
Non-blocking
- The checklist's
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 KeyRange transfer rules at the head and found no defect:
- AND/UMin take the minimum of the tops, and OR smears.
- Constant shifts, adds and multiplies go to unbounded on 64-bit overflow, and a left shift or multiply of a
-1-capable key is unbounded. c - xrequiresx.max <= cand givesc + 1for the sentinel.- Phi/Select join, and a cycle reads the unbounded placeholder.
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
- The rebased tree: the merge conflicts, so nothing here was built or run on top of
b433c40f2f. - The other regression suites in the description (
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. - Demon's Souls itself; I did not run the title.
VUID-comparison against currentmain(only against the PR's base,676d423968a1).
To get this to a good state
- Rebase onto current
main, and bumpFormatVersionabove 49. - Resolve the
MakeTableColumnbranch so thatMatchFirstLaneOffsetcolumns do not go throughboundMaskedTableKeywith an unsetrecordMask, and add a test for that case. - Reconcile the debt and architecture text with
main's ReadFirstLane/SelectU32 bounds (#7388). - Re-run the focused tests on the rebased head, and post the head and
mainSHAs. - Fix the title ID / discussion on the
Unblocksline.
|
Data point for this PR from Demon's Souls (PPSA01341), measured on a fork, not on main. The tutorial "zoo" scene has a CPU-path indirect draw whose pixel shader picks a T# with We tried a narrower local change, bounding columns whose every key site is Those numbers come from our fork (main AI-assisted: yes (Claude Code) |
|
@fdfawef324 thanks for #7684. XairRrR reproduced it on Linux with the validation layer (4/4 tests pass, no new |
|
@fdfawef324 an update on the carry I offered here: I did not push a merge of |
|
@fdfawef324, this no longer merges with main: it conflicts in |
|
Overlap coordination for #21586: I have a minimal TryMakeTableColumn fix that peels an outer constant addend before the masked-offset fallback, with synthetic pointer-image and buffer-sampler table coverage. On pinned main e4caa07, the new regression fails with a missing-table/runtime-value error; the narrow correction passes the seven focused tests. Your PR adds recordMask to MatchMaskedOffset at the same call site. The changes address different behavior: the combined call would be MatchMaskedOffset(SplitImmediateAddend(offset, addend), key, stride, recordMask), retaining your mask-bound handling rather than discarding it. #9457 also changes the surrounding fallback block. I am not proposing a parallel implementation of the key-range analysis. For landing order, I can keep the addend correction as a narrow follow-up and adapt it if this PR lands first. Alternatively, would you prefer to incorporate it and the synthetic coverage here? This is coordination before publication, not a merge request or a verified-gameplay claim; raw title data stays private. |
MarcZX10
left a comment
There was a problem hiding this comment.
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 through repo_read.py.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Core range and snapshot logic inspected |
| Tests | not run | Runs described in the PR body were not independently run |
| Full-file review | not run | Manifest and bundle reads were partial |
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.json was 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.
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 noreply@openai.com