fix(agc): share a table's rejection messages instead of copying each #10150

Merged
milescoviello merged 1 commit from upstream-pr/10150 into main 2026-10-26 21:53:43 +00:00
milescoviello commented 2026-10-23 10:50:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-23T10:50:48Z.


What

ShaderResources::rejectTableElement records a poison entry and a reason for each image or sampler table element the driver rejects. It kept that reason as its own std::string per element. A sampler table's rejections mostly repeat one reason (an opaque-black border, a border that needs numeric-class pairing), so a table with many such samplers held one heap copy of the same text per element. Building the image table faults copied every string again. Each cached ShaderResources keeps its tables, so these copies stay in memory.

In Ghost of Tsushima Director's Cut (PPSA02225), those strings and their copies were about 590 MiB of the heap in the opening.

How

  • TableStage::messages and BdaResources::ImageTableFaults::messages hold std::shared_ptr<const std::string> instead of std::string.
  • A rejection whose reason equals the previous rejection's reason shares that string. The copy into the image table faults now only bumps reference counts.
  • The recompiler's own poison entries, which have no driver reason, take a null pointer where they took an empty string. The fault report already skipped empty reasons and skips null ones the same way. Nothing in the report text changes.

Tested

Ubuntu 26.04.1 (kernel 7.0), GCC 15.2, NVIDIA RTX 4070 Ti, driver 615.71.09, Release.

Ghost of Tsushima Director's Cut (PPSA02225). main doesn't take this title through its opening yet, so these runs use a GoT stack on main 30ecc1b7b3: @EagleBearerYS's #9742 and #9717 (their branches merged with main 0db47b263d), #8121, #8213, #9318, #9396, #9989, #9991, #7803, #9129, and @EagleBearerYS's fix/agc-3d-view-committed-slices-v2 branch. The base and this change are that stack without and with this commit. This commit doesn't touch the recompiler, so both use the same warm shader cache. Each run is one jemalloc heap profile (lg_prof_sample 19) under a 20 GiB cap, until the cap ends the opening.

stack stack + this change
live heap at the last dump 8,191 MiB (516 s) 7,292 MiB (622 s)
under ShaderResources::rejectTableElement (< addSamplerTable) 394 MiB not in the top 30 (each of those is at least 23 MiB)
under ShaderResources::finishImageTables 198 MiB not in the top 30

Everything else in the top 10 is the same code in both runs: the NVIDIA driver, specialized modules, plan decoding, materialized results and shader registration. The run with this change has the smaller live heap at a later point.

Tests

  • A new case in tests/execution/ImageTable.cpp (agc_driver_image_table) rejects two sampler table entries, which differ only in MAX_LOD, for the same reason (an opaque-black border), and samples each one. Both faults must report the reason.
    • It passes on main and with this change.
    • With the shared string dropped for a repeated reason (a repeated rejection keeps a null pointer), it fails 3 of 3: "rejected S# 1 of two with the same reason did not report its entry rejection".
  • The 13 tests matching image_table|image_sample_border|emulated_color_compare|image_converted_unorm|image_sample_unnormalized|^agc_driver_graphics$|guest_sampler pass 3 of 3.
  • Khronos validation layer 1.4.363, main b3e42bd1eb against this branch over the same 13 tests: both pass, and neither reports a VUID.
  • Windows 11 VM (GeForce GT 1030, NVIDIA R580, WinLibs GCC 15.2, Release, ANYPS5_REQUIRE_VULKAN=1): the same 13 tests pass 3 of 3 on main b3e42bd1eb and 3 of 3 on this branch.

Overlap: #8963 (@EagleBearerYS) adds includes to BdaResources.hpp at the same line as this PR's #include <memory>. Whichever lands second keeps both.

Checklist

  • Based on current main; no other open PR implements the same functions (a textual include conflict with #8963: see Overlap)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.78, Windows 11
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4981608016 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10150). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-23T10:50:48Z. --- ### What `ShaderResources::rejectTableElement` records a poison entry and a reason for each image or sampler table element the driver rejects. It kept that reason as its own `std::string` per element. A sampler table's rejections mostly repeat one reason (an opaque-black border, a border that needs numeric-class pairing), so a table with many such samplers held one heap copy of the same text per element. Building the image table faults copied every string again. Each cached `ShaderResources` keeps its tables, so these copies stay in memory. In Ghost of Tsushima Director's Cut (PPSA02225), those strings and their copies were about 590 MiB of the heap in the opening. ### How - `TableStage::messages` and `BdaResources::ImageTableFaults::messages` hold `std::shared_ptr<const std::string>` instead of `std::string`. - A rejection whose reason equals the previous rejection's reason shares that string. The copy into the image table faults now only bumps reference counts. - The recompiler's own poison entries, which have no driver reason, take a null pointer where they took an empty string. The fault report already skipped empty reasons and skips null ones the same way. Nothing in the report text changes. ### Tested Ubuntu 26.04.1 (kernel 7.0), GCC 15.2, NVIDIA RTX 4070 Ti, driver 615.71.09, Release. **Ghost of Tsushima Director's Cut (PPSA02225).** `main` doesn't take this title through its opening yet, so these runs use a GoT stack on `main` 30ecc1b7b3: @EagleBearerYS's #9742 and #9717 (their branches merged with `main` 0db47b263d), #8121, #8213, #9318, #9396, #9989, #9991, #7803, #9129, and @EagleBearerYS's `fix/agc-3d-view-committed-slices-v2` branch. The base and this change are that stack without and with this commit. This commit doesn't touch the recompiler, so both use the same warm shader cache. Each run is one jemalloc heap profile (`lg_prof_sample` 19) under a 20 GiB cap, until the cap ends the opening. | | stack | stack + this change | |---|---|---| | live heap at the last dump | 8,191 MiB (516 s) | 7,292 MiB (622 s) | | under `ShaderResources::rejectTableElement` (< `addSamplerTable`) | 394 MiB | not in the top 30 (each of those is at least 23 MiB) | | under `ShaderResources::finishImageTables` | 198 MiB | not in the top 30 | Everything else in the top 10 is the same code in both runs: the NVIDIA driver, specialized modules, plan decoding, materialized results and shader registration. The run with this change has the smaller live heap at a later point. **Tests** - A new case in `tests/execution/ImageTable.cpp` (`agc_driver_image_table`) rejects two sampler table entries, which differ only in `MAX_LOD`, for the same reason (an opaque-black border), and samples each one. Both faults must report the reason. - It passes on `main` and with this change. - With the shared string dropped for a repeated reason (a repeated rejection keeps a null pointer), it fails 3 of 3: "rejected S# 1 of two with the same reason did not report its entry rejection". - The 13 tests matching `image_table|image_sample_border|emulated_color_compare|image_converted_unorm|image_sample_unnormalized|^agc_driver_graphics$|guest_sampler` pass 3 of 3. - Khronos validation layer 1.4.363, `main` b3e42bd1eb against this branch over the same 13 tests: both pass, and neither reports a VUID. - Windows 11 VM (GeForce GT 1030, NVIDIA R580, WinLibs GCC 15.2, Release, `ANYPS5_REQUIRE_VULKAN=1`): the same 13 tests pass 3 of 3 on `main` b3e42bd1eb and 3 of 3 on this branch. **Overlap:** #8963 (@EagleBearerYS) adds includes to `BdaResources.hpp` at the same line as this PR's `#include <memory>`. Whichever lands second keeps both. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions (a textual include conflict with #8963: see **Overlap**) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.78, Windows 11 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-23 11:00:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:00:03Z.

Review: CHANGES_REQUESTED


The correctness diff and focused regression are convincing, and hosted conventions/intake/label/report checks pass. Before approval, please resolve the open automated performance-report request: the PR’s jemalloc profiles are useful memory evidence, but the bot asks for aps5-summary.jsonl lines for main and this change on the same title, scene and machine, plus both traces and tools/trace_digest.py output. The performance-report template and repository policy require that capture format for a PR labeled perf. If the change is intended to claim memory reduction only and not a speed change, please clarify that with maintainers and have the perf labeling/request corrected; otherwise attach the requested comparable captures. I did not run local Vulkan tests; the description reports 13 focused tests on Linux and Windows, repeated three times, with validation-layer runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627306614 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10150#pullrequestreview-5627306614). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T11:00:03Z. **Review:** CHANGES_REQUESTED --- The correctness diff and focused regression are convincing, and hosted conventions/intake/label/report checks pass. Before approval, please resolve the open automated performance-report request: the PR’s jemalloc profiles are useful memory evidence, but the bot asks for `aps5-summary.jsonl` lines for `main` and this change on the same title, scene and machine, plus both traces and `tools/trace_digest.py` output. The performance-report template and repository policy require that capture format for a PR labeled `perf`. If the change is intended to claim memory reduction only and not a speed change, please clarify that with maintainers and have the `perf` labeling/request corrected; otherwise attach the requested comparable captures. I did not run local Vulkan tests; the description reports 13 focused tests on Linux and Windows, repeated three times, with validation-layer runs.
MarcZX10 commented 2026-10-23 11:04:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:04:13Z.

Review: APPROVED


Thanks for clarifying the claim and updating the title. The change reports heap reduction only, makes no frame-time claim, and the automatic perf/perf numbers missing labels are now absent, so the trace-format request does not apply. I reviewed the code and regression diff, and the author reports the focused 13-test Linux and Windows suites with validation-layer comparison. Hosted conventions, intake, labels and report checks pass; product jobs were skipped by policy. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627352210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10150#pullrequestreview-5627352210). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T11:04:13Z. **Review:** APPROVED --- Thanks for clarifying the claim and updating the title. The change reports heap reduction only, makes no frame-time claim, and the automatic `perf`/`perf numbers missing` labels are now absent, so the trace-format request does not apply. I reviewed the code and regression diff, and the author reports the focused 13-test Linux and Windows suites with validation-layer comparison. Hosted conventions, intake, labels and report checks pass; product jobs were skipped by policy. No blocking issue found.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10150
No description provided.