perf(shader): replay an image table column's decoded records when its content recurs #12051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12051"
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 SleglJan on 2026-10-27T17:38:40Z.
What
When the result memo misses and the table resolution reuse misses too, an image table column is resolved from its records: each record's decode is looked up in the decode memo (one global mutex per record), null descriptors are checked, each element is hashed and placed, and the map is written. On a scene with large tables the same column content comes back on most of these misses, read through image resources that agree in every field but the descriptor source, the first use and the table index. This PR keeps a column's decoded records and replays them when the same content recurs:
SharedValues::Hash), its key count and its records-outside-the-snapshot state, plus the usage: the image resource without its descriptor source, first use and table index, its runtime mode list and the reducing-sampler state. Columns of at least 64 keys, in the runtime resolution; the registration-timePopulatepath does not use the memo.APS5_TABLE_COLUMN_MEMO_WORDS, default 33,554,432 words of estimated host memory) and an entry count of 4,096.APS5_PROFILE_DRAWcounts hits, misses never seen and misses whose content changed; the last two keep one slot per usage (up to 131,072) under a mutex, only whileAPS5_PROFILE_DRAWis set.APS5_NO_TABLE_COLUMN_MEMO=1resolves every column from its records as before.APS5_VERIFY_TABLE_COLUMN_MEMO=1also resolves every replayed snapshot from its records and compares the map, elements, samplers, poison records and faults; the first twenty differences are printed and the count goes into the report line.APS5_TABLE_COLUMN_MEMO_DIAG=1extends that line with the distinct contents and usages of the window and, for the changed-content misses whose previous column is still pinned, the keys whose descriptor differs and the 1,024-key chunks holding them; it takes effect only withAPS5_PROFILE_DRAW.NeutralSwitches).agc_shader_table_column_memo(a replayed resolution equals a fresh one across a second variant, another first use and another descriptor source; a changed mode list or decode input misses; the hit and miss counters), with the verified, off, reported, diagnosed and diagnosed-unreported variants.dc1e7e5695addsagc_shader_table_column_memo_placement,_placement_beforeand_placement_off(thirty selected single-record tables and one merged column in one resolution, the merged column resolved after or before them; its narrowed domain binds its 65 keyed records and record 0, thirty of its records equal the selected tables' records and land on the same elements, 66 elements in all, equal to the plain resolution),_evicted_by_count(4,096 distinct contents, then the least recently used entry leaves first, read through hits and misses),_evicted_by_budget(APS5_TABLE_COLUMN_MEMO_WORDS=65536, 200 contents with the first replayed after every insertion: the newest and the first kept, the least recently used evicted) and_oversize_entry(APS5_TABLE_COLUMN_MEMO_WORDS=0x1: nothing kept), and nine_words*registrations (the same column resolved twice per value: kept on the second resolution under unset,1048576and0x100000; the first resolution fails with the variable's message for0,-1, empty,abc,12xand a 20-digit overflow).Related open PRs: #6340, #10193, #7642 and #10256 work on the driver's image table entries and device tables. #7223 (nested image tables through runtime pointers) changes the same resolution loop and adds child tables and the pointers that key them, which this memo does not cover: whichever lands second has to extend the key and the replay to them, or exclude nested columns from the memo. What the second to land changes is proposed on #7223 (https://github.com/boykopovar/AnyPS5/pull/7223#issuecomment-6475451084): keep the pointer-keyed parent column out of the memo (its child tables still go through the resolution as ordinary columns and stay eligible), or key the memo on the child content; the order itself is open with #7223's author.
Tested
CachyOS Linux (kernel 7.2.10), NVIDIA GeForce RTX 3080, driver 615.78.08, AMD Ryzen 9 7950X3D, 64 GB; GCC 16.2.1, CMake 4.4.4.
ctest -R "^agc"on this PR atdc1e7e5695: 1,073 passed, 10 skipped, 1 failed of 1,084. The one failure,agc_driver_mesh_barycentric_emulation, fails the same way on plainmainc547deaacbon this machine ("AGC graphics: the pixel shader did not emulate barycentrics", NVIDIA 615.78.08).ctest --test-dir build -R "^agc_shader_" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 37/37 onmainc547deaacb, 58/58 on this PR atdc1e7e5695(the 21 extra are the column memo tests). Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.What this change claims now: the
[recompile]Populate time is down onmain(171 / 169 / 172 ms per frame against 67 / 69 / 72 in the A/B below); no frame-rate gain onmainwithin the run spread (walk presents per second 0.369 / 0.369 / 0.341 against 0.358 / 0.326 / 0.371); the +11.5 % walk gain below was measured only on the local base and does not reproduce onmain.Capture pair, 007 First Light (PPSA11386), the walk after the resume of the first level:
mainat the PR's basec547deaacb(2026-10-28, 12:04 to 12:47 CET) and this PR at its headdc1e7e5695(12:51 to 13:34 CET), same machine and boot, a build and a test run in between,APS5_TRACE_FRAMES=1085:150on both sides. Not as the form asks:APS5_TRACE_EVENTS=4194304on both sides, because queue worker 0x0 records about 10,700 events per present here and the default buffer of 262,144 events (docs/dev/BUILD.md) holds about 25 presents;APS5_TRACE_DIRfor the output directory;APS5_TIME_SCALE=0.1and scripted input throughAPS5_PAD_INPUT_FILE, both visible in the lines'env; and, not visible there, the log written to a file, the NVIDIA shader disk cache on and pointed at a per-run directory copied from a seed run (a 16 GiB size cap, its cleanup skipped), the shader disk cache and the journal warm from that seed run rather than from a restart, and the title in a scope with swap turned off. No otherAPS5_TRACE_*switch and noAPS5_PROFILE_*switch is set. Both sides the same way:mainfrom its own seed; this PR from a copy of the PR's seed withmain's journal records (the journal header's source version set to the PR's), so the journal records and the NVIDIA cache are identical on both sides while the shader disk cache is each side's own, the shader cache source versions being 41abaa3b8f8b9199 onmainand 75f9ad0bc594cabf on this PR. The title executable is unedited.tools/trace_digest.pyoutput) and the two traces: pre-release https://github.com/SleglJan/AnyPS5/releases/tag/perf-traces-shader-column-memo on my fork, both files over the 25 MB attachment limit (31.7 and 32.4 MB), sha256 e44ae16fa69649761e15a3f5cd9a394f8089e4a51db7e34c59d2590ff518e6e5 (main) and 22b1ef75f9c6c30a4c75a5552866af2d790655ae1ede305a18e25a1f5e5d1fd7 (this PR).tools/performance_compare.pyon the lines: no configuration difference; this PR minusmain: frame p50 +170 ms (+6.3 %), p90 +162 (+5.0 %), p99 +507 (+12.7 %), max +2,610 (+59 %), mean frame +123 (+4.4 %), GPU busy per present +20 (+4.2 %); one pair, one run per side. HighestVmHWM24,371 against 25,134 MiB, both including the trace buffers (seven threads at 160 MiB each, 1,120 MiB, on both sides).main's run passes every check readable here (collapse is not readable; peak device memory used 9,550 MiB over the run, 9,042 MiB at the level load, every other figure under its limit), this change's run invalid: it peaks at 9,883 MiB at frame 1,036 (the level load, before the walk and outside the trace window), over our 9,850 MiB limit; its next-highest 1 s sample is 9,782 MiB at frame 1,248. First reading: both invalid, because the staging-shadow refusal lines count as unrecovered refusals there (main2, its full count; this change 4, a lower bound, four prints per run at most).mainc547deaacbwithAPS5_PROFILE_DRAW=1andAPS5_TRACE_SUMMARY_EVERY=60(three alternated pairs, 2026-10-27 22:41 to 2026-10-28 03:00 CET, this change atf5cf0db16c,mainat the PR's basec547deaacbwhilemainitself was 32 merges past it, journals unequal, the cache and swap settings as above): walk presents per second under the first reading, declared before the series (any unrecovered allocation refusal invalid), n = 1 / 1,main0.341 against this change 0.326; under the later reading, which counts staging-shadow refusal lines as handled and was declared after pair 1's results, which made both its runs invalid only through these lines, while pair 2's first run was running, n = 3 / 3,main0.369 / 0.369 / 0.341 (mean 0.360) against this change 0.358 / 0.326 / 0.371 (mean 0.352); four of the six runs differ between the two readings, all on that line.[recompile]Populate 171 / 169 / 172 against 67 / 69 / 72 ms per frame. HighestVmHWMper runmain23,651 / 24,614 / 24,036 MiB, this change 24,460 / 25,557 / 23,802 MiB.The earlier alternated A/B, the same title and walk, measured before this rebase on a local base, not on
main: upstreammain5357acd697plus #5372 (squashed, with its662a50bf7echange reverted) and #10423, plus local logging and scripted input, and the title's two feedback-wait limits widened in its executable as described in #6172 (local only). Both sides run withAPS5_WRITTEN_SHADOW_MAX_KIB=2048 APS5_NO_WRITTEN_SHADOW=1 APS5_PROFILE_DRAW=1and a warm shader disk cache from a seed run per side; 2026-10-27, six pairs alternated base / this change, 20 minutes each, the same machine and session.APS5_FLIP_INFLIGHT=0) cut the held-entry difference between the sides from 2.09x to 1.29x and showed no streaks, an observation from one pair, with no cause read from it.Populatems per frame, all sixAPS5_VERIFY_TABLE_COLUMN_MEMO=1, 106,481 hits and 7,958 misses over 92 ten-second lines (93.0 %), 29,618 replayed resolutions re-resolved from their records, 0 mismatches. Every miss was a column whose content changed; the memo held 323-402 entries.mainseries, the 1 s peak ofnvidia-smimemory used by all processes between the resume and frame 1,055, with the memory outside the texture caches read at the[gpu]budget line nearest that peak and the title's own device memory as the highestnvidia-smi pmonsample in that window. Local-base series: base 1,033-1,257 MiB against this change 1,206-2,528 MiB outside the caches, with first host placements in 3 of 6 runs against 1 of 6 (Fisher, one-sided, 0.27); the series had one seed per side (its own shader disk cache, frozen NVIDIA cache and journal) and the PR side loaded the smaller journal, so the cause there is not established. Onmainc547deaacb, each series in one session,mainalways from one seed, this change minusmain:main175)f5cf0db16cf5cf0db16cmainline 26 s from the peak)dc1e7e5695mainline 37 s from the peak)dc1e7e5695Over the eight shared-journal pairs the means are
main9,321 against this change 9,260 MiB; without the three-pair series' pair 3 (itsmainrun had six shader disk cache misses) 7 / 7, 9,384 against 9,298. Both groupings, 8 / 8 and 7 / 7, were declared before the five-pair series ran; both include that series' four runs which the same declaration's disk-cache rule makes invalid, and the declaration did not say how to treat them. The sign is not consistent across pairs; the one series with every pair higher on this change is the one with unequal journals. Four of the eight pairs have a run with 4 to 6 misses in the boot, none later (cause not chased); grouped after seeing the data, the four pairs without one give +445 / −541 / +83 / −434 MiB. Host placements by frame 1,055:mainin 2 of its 8 shared-journal runs ([bufferpool] at least 3 in one, at least 1 in the other), this change in 3 of 8 ([gpu] at least 3 with [bufferpool] at least 1 in one, [bufferpool] at least 1 in each of the other two); the capture pair: this change [gpu] at least 8,mainnone.Checklist
main(mainf8f5b24b77merged in atc5dcde982e, after the results above were posted); no other open PR implements the same functions.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T18:37:55Z.
Review: CHANGES_REQUESTED
Reviewed exact head
f5cf0db16c28ee4a7575c7cd1dda342fd01a9fe6and the updated PR discussion. The implementation has a focused verify mode and reports zero mismatches in the supplied run, but the remaining validation and overlap questions are material for this shader-driver change.The required performance report is still missing: the submitted A/B uses a local base with other PRs, local logging, and a modified title executable, and no
aps5-summary.jsonllines or trace pair/digest are attached.CONTRIBUTING.mdrequires captures from currentmainand this PR using the same title, scene, and machine, with the traces; theperflabel workflow also requests both summary lines andtools/trace_digest.pyoutput. The maintainer's request for a current-main A/B and max RSS is still unanswered with a compliant comparison. Please provide that evidence or remove the performance claim/label and resolve the maintainer's request explicitly.There is also an exact merge conflict with open #7223 in
ResourceMaterializer.cpp(git merge-tree --write-treereports a content conflict). The description recognizes that nested-table support must be extended or excluded depending on order, but the checklist saysDepends on: none. Please agree the order with #7223’s author, record the dependency/plan, and validate the combined behavior before merge.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T10:16:40Z.
Review: CHANGES_REQUESTED
Thanks for the verify mode and the exact content/usage comparison before a replay. Still open on this head:
perf, CONTRIBUTING): paste theaps5-summary.jsonllines of a capture on currentmainand one with this change, same title, scene and machine, plus thetools/trace_digest.pyoutput. The 007 A/B is on a local base (other PRs, local logging, a patched title executable), and its run-validity rule was changed after the first runs (1 valid run of 6 for this change), so it doesn't give a verdict.docs/dev/memory rules ask for the bound and peak RSS before/after on a big workload).APS5_TABLE_COLUMN_MEMO_WORDSparsing; please add them.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T17:50:52Z.
Review: CHANGES_REQUESTED
Thanks for the tests and the full report. The tests cover what was asked and the hash fix is right. What is still open is the case for the change itself:
main. Your own numbers: Populate drops 171 → 68 ms per frame, but frames are ~2.8 s and the A/B walk rate is 0.360 vs 0.352 presents/s (within spread). The only capture pair onmainhas this PR slower (p50 +6.3 %, p99 +12.7 %, max +59 %, GPU busy +4.2 %), one run per side. The +11.5 % figure was only on a local base. AperfPR needs a gain that reproduces onmain: more capture pairs (or a scene where Populate is on the critical path) showing it beats the spread, not one pair against three.ResourceMaterializer.cpp, a 128 MiB host budget, 4 env switches (APS5_NO_TABLE_COLUMN_MEMO,APS5_VERIFY_TABLE_COLUMN_MEMO,APS5_TABLE_COLUMN_MEMO_DIAG,APS5_TABLE_COLUMN_MEMO_WORDS) and 22 ctest entries. Without a frame-time gain that is not justified; if you can't show one, please close this or reduce it to what pays for itself.perfdoesn't change this: the memory and complexity cost needs a benefit that is measured.Pull request closed