perf(agc): reuse image-table elements whose descriptors repeat #6223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6223"
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 Thunderhawkk on 2026-10-15T05:04:34Z.
What
An image-table build resolves every element through the texture cache even when one record of the table changed, or when the same descriptors appear in another table of the same submission. This reuses the resolved texture of an element whose descriptor repeats, inside the safety envelope the whole-table reuse already uses.
cleanflag and its surface generation, so a table with one non-clean element is still remembered (today one bad element discards the whole table).fullyCleanflag set when the table was remembered.TextureKeyover the clean elements of the tables remembered in the current state: an element reuses a donor while its texture is still the cache's entry for the key, its surface is unchanged at the donor's generation and no pending work overlaps it; anything else resolves fresh.elementsReused,elementsResolved) and the[textures]report line carries them.Cross-submission (cross-epoch) reuse is not in this change. Making donors cross epochs safely needs the write watch on every element range; I proposed that direction on #5961 and can measure it if the maintainers want it.
Tested
Windows 11 (26200), RTX 5070 Ti 16 GiB, NVIDIA 617.42, MinGW GCC 15.2.0:
agc_driver_image_table_reuse_testspasses. The "two tables that differ in one record" case now also asserts element counters: 47 of 48 elements reused per-element, 143 reused / 49 resolved over the case. The table-level expectations are unchanged (whole-table reuses count asreused, per-element builds asresolved).agc_driver_graphics_testspasses.--windows,APS5_PROFILE_DRAW=1, the same 421,247-word compute dispatch (program0x11d0323c00) on the same machine: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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T05:04:51Z.
Thank you for your contribution! Authors with no pull requests merged into
maincan have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:57:57Z.
Thanks for this: per-element reuse is a real gap (
mainstill only reuses whole tables), and the Wolverine numbers are a strong motivation. The branch is about 1,400 commits behindmainand conflicts inShaderResources.cppand the debt file, so it needs a rebase. A few points to cover in it.1. Filter donors by state and device explicitly. At your head the donors are same-state only because
FindReusedTableruns just before the donor index is built and erases every remembered table whoseTableStatediffers. The donor loop itself doesn't check it, even though the comment says "the remembered tables of this state". On currentmain,resolveImageTablesskipsFindReusedTablefor tables the shader stores to (storageTable ? nullptr : FindReusedTable(...), from the image-store-through-tables change). After a straight rebase, a storage-table build would therefore index donors from a list that was never pruned to the current state, and could reuse textures from an older epoch, which your own debt entry says isn't covered. Please checkremembered.state == stateandremembered.device == context.devicein the donor loop.2. No donors from storage elements. Elements with
imageWrittenset go through the storage-table path onmain. They must never be recorded as clean donors, and a table that has one should not befullyClean.3. Negative tests for the donor path. The added assertion counts elements in an existing scenario (143 reused, 49 resolved), but none of the donor path's three guards is tested. Please add cases where an element repeats in a different table after its donor resolved, and:
Each should fail with its guard removed (
UnchangedSinceat the donor generation,AnyPendingOverlaps, the cache-entry identity check).4. Re-measure on the rebased head.
ShaderResources.cpphas changed about 30 times onmainsince your base (descriptor-cache publication, DCC key presync, texture-cache reclaim, storage budget). Please repeat the Wolverine (PPSA03671) resource-build measurement on the rebased head.5. The remembered-table LRU. Tables that aren't fully clean are now remembered too, so they take slots in the 4-entry
ReusedTableslist and can evict fully clean tables, which lowers whole-table reuse. Please report the[textures] image tables N reused, M resolvedcounts before and after on a scene that already reused whole tables, to show whole-table reuse doesn't drop. If it does, a separate donor list, or remembering only tables with at least one clean element, may help.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:52:32Z.
Review: COMMENTED
Points on 6223:
Comments in code.
ShaderResources.cppgains several comment blocks ("Elements a table build bound without a fresh lookup...", "Elements of the remembered tables of this state, by key..."). The rule is no comments except#endifand namespace ends.Per-build donor scan. Each table build constructs a fresh
donorsunordered_mapby walkingReusedTables()and everyentryin every remembered table, wheneverstate.epoch != 0. That is work proportional to all remembered elements, paid on every build, to save lookups on a hit. What boundsReusedTables()and how many elements does it hold in the scene you measured? If a title builds many tables per frame this scan could cost more than the lookups it saves.Speed claim. The PR is
perf; the counters (tableElementsReused/tableElementsResolved) show hit rate, not time. Please attachtools/trace_digest.pysummaries of main and the change from the same machine and scene.Negative control. The
UnchangedSinceguard is the only thing preventing a stale donor from being reused when guest memory under a repeating descriptor changes. Is there a test that rewrites the backing bytes and fails when that guard is removed?Pull request closed