fix(agc): bound registered shader preparation memory #9626

Merged
MarcZX10 merged 8 commits from upstream-pr/9626 into main 2026-10-29 09:40:34 +00:00
MarcZX10 commented 2026-10-22 04:58:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:58:04Z.


What

Bounds registration-time shader preparation by process-private memory. The default budget is half of physical RAM; APS5_REGISTRATION_PREPARE_COMMIT_GB overrides it in GiB, and 0 disables registration-time preparation. Both new registrations and queued work check the budget, deferring shader preparation until first use after the threshold is reached.

If the budget cannot be established, registration-time preparation is not bounded and behaves as before this change: when the physical memory size cannot be read (GlobalMemoryStatusEx failing on Windows, sysconf failing elsewhere) ReadPhysicalMemoryBytes returns no value and the default budget is unlimited, and when the process-private size cannot be read the check allows the work. Once the budget is reached, later registrations are prepared when their shader is first used instead of at registration, so a title can stall on its first draws that use those shaders; the first such deferral is logged once.

Tested

Before rebasing to current main, built libSceAgcDriver and the budget-test target with Ninja; the focused CTest passed (1/1). On the current head based on main da54c652e3, compiled and ran the standalone budget policy test with g++ (passed), ran python3 tools/check_conventions.py --base upstream/main --head HEAD (passed), and ran git diff --check (passed). This host has no /dev/dri device or vulkaninfo; the AGC GPU validation suite was not run. The repository's manual build workflow dispatch returned HTTP 403 because this account lacks the required repository admin permission. The other hosted build jobs are skipped.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • No unimplemented paths added
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behavior, not specific to one title
  • Depends on: none
  • Fixes: #6139
  • Unblocks: none
  • GPUs tested: no GPU test ran; this host has no GPU device or Vulkan tools
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4962340975 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9626). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:58:04Z. --- ### What Bounds registration-time shader preparation by process-private memory. The default budget is half of physical RAM; `APS5_REGISTRATION_PREPARE_COMMIT_GB` overrides it in GiB, and `0` disables registration-time preparation. Both new registrations and queued work check the budget, deferring shader preparation until first use after the threshold is reached. If the budget cannot be established, registration-time preparation is not bounded and behaves as before this change: when the physical memory size cannot be read (`GlobalMemoryStatusEx` failing on Windows, `sysconf` failing elsewhere) `ReadPhysicalMemoryBytes` returns no value and the default budget is unlimited, and when the process-private size cannot be read the check allows the work. Once the budget is reached, later registrations are prepared when their shader is first used instead of at registration, so a title can stall on its first draws that use those shaders; the first such deferral is logged once. ### Tested Before rebasing to current `main`, built `libSceAgcDriver` and the budget-test target with Ninja; the focused CTest passed (1/1). On the current head based on `main` `da54c652e3`, compiled and ran the standalone budget policy test with g++ (passed), ran `python3 tools/check_conventions.py --base upstream/main --head HEAD` (passed), and ran `git diff --check` (passed). This host has no `/dev/dri` device or `vulkaninfo`; the AGC GPU validation suite was not run. The repository's manual build workflow dispatch returned HTTP 403 because this account lacks the required repository admin permission. The other hosted build jobs are skipped. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] No unimplemented paths added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] Fixes: #6139 - [x] Unblocks: none - [x] GPUs tested: no GPU test ran; this host has no GPU device or Vulkan tools - [x] AI-assisted: yes
jotitadev commented 2026-10-22 07:03:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T07:03:20Z.

Review: COMMENTED


GPU run, since the description says the AGC suite was not run.

Machine: Ubuntu 26.04, i7-8700, 30 GiB RAM, GCC 15.2, Release, full build with BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3070 (driver 595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8). Head 769a25562 merged into main da54c652e.

ctest -R "^agc" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64" -j1 --timeout 30:

main this PR (default budget, half of RAM)
RTX 3070 857/861 859/862
lavapipe 860/861 861/862

The failures are the same on both trees: the three sample_order tests on the 3070 (the card has no 2x2 sample-location grid at 2 samples) and multisample_retirement on lavapipe. The fourth failure on main on the 3070 was agc_driver_sgpr_pattern_fill_keys, which is load-dependent (#9139). agc_driver_registration_prepare_budget passes.

To exercise the deferred path itself, I also ran the suite on the 3070 with APS5_REGISTRATION_PREPARE_COMMIT_GB=0. The budget message is logged once per process. Every draw and dispatch test still passes. The only new failures are 14 prepared_* / preparation_scope_settle tests that assert work done at registration, for example the null pixel program was not prepared at registration and the link did not wait for the vertex shader's registration preparation. That is expected with a zero budget. Seven of them pass under APS5_LAZY_SHADER_PREPARE=1 only because they check that variable. An invalid value (abc) stops with APS5_REGISTRATION_PREPARE_COMMIT_GB must be a non-negative number of GiB.

Not tested: a title that actually reaches the budget, Windows.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux), lavapipe

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5610393962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9626#pullrequestreview-5610393962). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T07:03:20Z. **Review:** COMMENTED --- GPU run, since the description says the AGC suite was not run. Machine: Ubuntu 26.04, i7-8700, 30 GiB RAM, GCC 15.2, Release, full build with `BUILD_TESTING=ON`. GPUs: NVIDIA GeForce RTX 3070 (driver 595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8). Head 769a25562 merged into `main` da54c652e. `ctest -R "^agc" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64" -j1 --timeout 30`: | | `main` | this PR (default budget, half of RAM) | |---|---|---| | RTX 3070 | 857/861 | 859/862 | | lavapipe | 860/861 | 861/862 | The failures are the same on both trees: the three `sample_order` tests on the 3070 (the card has no 2x2 sample-location grid at 2 samples) and `multisample_retirement` on lavapipe. The fourth failure on `main` on the 3070 was `agc_driver_sgpr_pattern_fill_keys`, which is load-dependent (#9139). `agc_driver_registration_prepare_budget` passes. To exercise the deferred path itself, I also ran the suite on the 3070 with `APS5_REGISTRATION_PREPARE_COMMIT_GB=0`. The budget message is logged once per process. Every draw and dispatch test still passes. The only new failures are 14 `prepared_*` / `preparation_scope_settle` tests that assert work done at registration, for example `the null pixel program was not prepared at registration` and `the link did not wait for the vertex shader's registration preparation`. That is expected with a zero budget. Seven of them pass under `APS5_LAZY_SHADER_PREPARE=1` only because they check that variable. An invalid value (`abc`) stops with `APS5_REGISTRATION_PREPARE_COMMIT_GB must be a non-negative number of GiB`. Not tested: a title that actually reaches the budget, Windows. GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux), lavapipe Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
adriadam10 commented 2026-10-22 18:57:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-22T18:57:57Z.

Review: CHANGES_REQUESTED


Checked the three registration paths (lazy, async, sync) and the background task: a null plan is handled in each, and an invalid APS5_REGISTRATION_PREPARE_COMMIT_GB fails with a clear message. Remaining points:

  • No measurement of the bound. #6139 is about commit growth during registration, so show peak process-private memory on a big registration workload with and without this change (default budget and a low APS5_REGISTRATION_PREPARE_COMMIT_GB), including what is kept for a deferred shader. Nothing here shows the budget stops the growth.
  • core/libs/prx/libSceAgcDriver/tests/RegistrationPrepareBudget.cpp:15-26 only tests processPrivateBytes < budget on a one-line helper. It exercises neither the env parsing (ShaderRegistry.cpp:1350-1366: 0, invalid text, overflow) nor that PlanRegistered (ShaderRegistry.cpp:916) and PrepareRegisteredInBackground (ShaderRegistry.cpp:1387) defer and leave prepared.deferred set. Please move the budget decision (budget parsing and the allow/defer choice) into the testable header and cover those cases, or add a registry-level test with a budget of 0.
  • As jotitadev's run shows, with a budget of 0 the 14 prepared_* / preparation_scope_settle tests that assert work at registration fail. Add a test that pins the deferred behaviour (entries empty, deferred set, shader prepared on first use) so the budget path is covered by default.
  • Please state in the description what happens on Windows when GlobalMemoryStatusEx fails (the budget becomes unlimited) and that the preparation moves to first use, so a title may stall on its first draws.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5619370706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9626#pullrequestreview-5619370706). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-22T18:57:57Z. **Review:** CHANGES_REQUESTED --- Checked the three registration paths (lazy, async, sync) and the background task: a null plan is handled in each, and an invalid `APS5_REGISTRATION_PREPARE_COMMIT_GB` fails with a clear message. Remaining points: - No measurement of the bound. #6139 is about commit growth during registration, so show peak process-private memory on a big registration workload with and without this change (default budget and a low `APS5_REGISTRATION_PREPARE_COMMIT_GB`), including what is kept for a deferred shader. Nothing here shows the budget stops the growth. - `core/libs/prx/libSceAgcDriver/tests/RegistrationPrepareBudget.cpp:15-26` only tests `processPrivateBytes < budget` on a one-line helper. It exercises neither the env parsing (`ShaderRegistry.cpp:1350-1366`: `0`, invalid text, overflow) nor that `PlanRegistered` (`ShaderRegistry.cpp:916`) and `PrepareRegisteredInBackground` (`ShaderRegistry.cpp:1387`) defer and leave `prepared.deferred` set. Please move the budget decision (budget parsing and the allow/defer choice) into the testable header and cover those cases, or add a registry-level test with a budget of `0`. - As jotitadev's run shows, with a budget of `0` the 14 `prepared_*` / `preparation_scope_settle` tests that assert work at registration fail. Add a test that pins the deferred behaviour (entries empty, `deferred` set, shader prepared on first use) so the budget path is covered by default. - Please state in the description what happens on Windows when `GlobalMemoryStatusEx` fails (the budget becomes unlimited) and that the preparation moves to first use, so a title may stall on its first draws.
adriadam10 commented 2026-10-23 22:51:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T22:51:07Z.

Review: CHANGES_REQUESTED


Thanks for moving the budget parsing into RegistrationPreparationBudget.hpp and testing it; the parsing/allow cases in tests/RegistrationPrepareBudget.cpp look right. Three points from the previous review are still open:

  • No measurement of the bound (a change that bounds memory needs peak RSS before/after). #6139 is about commit growth during registration, so please post peak process-private memory on a large registration workload on main vs this change, with the default budget and with a low APS5_REGISTRATION_PREPARE_COMMIT_GB.
  • The registry paths are untested: nothing exercises PlanRegistered (ShaderRegistry.cpp:1221) or PrepareRegisteredInBackground (ShaderRegistry.cpp:1740-1753) deferring. Add a registry-level test with a budget of 0 that pins the deferred behaviour (entries empty, prepared.deferred set, shader prepared on first use). With a budget of 0 the existing prepared_* / preparation_scope_settle tests that assert work at registration fail, so they need the same treatment or to run with a large budget.
  • Please state in the description what happens on Windows when GlobalMemoryStatusEx fails (PerformanceOverlay.cpp:450 returns nullopt, so the budget becomes unlimited) and that preparation moves to first use, so a title may stall on its first draws.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5635245859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9626#pullrequestreview-5635245859). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-23T22:51:07Z. **Review:** CHANGES_REQUESTED --- Thanks for moving the budget parsing into `RegistrationPreparationBudget.hpp` and testing it; the parsing/allow cases in `tests/RegistrationPrepareBudget.cpp` look right. Three points from the previous review are still open: - No measurement of the bound (a change that bounds memory needs peak RSS before/after). #6139 is about commit growth during registration, so please post peak process-private memory on a large registration workload on `main` vs this change, with the default budget and with a low `APS5_REGISTRATION_PREPARE_COMMIT_GB`. - The registry paths are untested: nothing exercises `PlanRegistered` (`ShaderRegistry.cpp:1221`) or `PrepareRegisteredInBackground` (`ShaderRegistry.cpp:1740-1753`) deferring. Add a registry-level test with a budget of `0` that pins the deferred behaviour (entries empty, `prepared.deferred` set, shader prepared on first use). With a budget of `0` the existing `prepared_*` / `preparation_scope_settle` tests that assert work at registration fail, so they need the same treatment or to run with a large budget. - Please state in the description what happens on Windows when `GlobalMemoryStatusEx` fails (`PerformanceOverlay.cpp:450` returns nullopt, so the budget becomes unlimited) and that preparation moves to first use, so a title may stall on its first draws.
adriadam10 commented 2026-10-27 01:45:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T01:45:45Z.

Review: CHANGES_REQUESTED


Thanks for the registry-level test (agc_driver_prepared_shaders_lazy_budget_zero), the negative control, the MinGW link fix and the description of the GlobalMemoryStatusEx failure case; those points are settled.

One point is still open:

  • No measurement of the bound. A change that bounds memory needs peak process-private memory (or peak RSS) before/after on a large registration workload. #6139 is about commit growth during registration, so please post it for main vs this change, with the default budget and with a low APS5_REGISTRATION_PREPARE_COMMIT_GB, from the same machine and scene. If you have no title to run, a registration of many large shaders in a test harness that prints the peak is enough.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661308817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9626#pullrequestreview-5661308817). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-27T01:45:45Z. **Review:** CHANGES_REQUESTED --- Thanks for the registry-level test (`agc_driver_prepared_shaders_lazy_budget_zero`), the negative control, the MinGW link fix and the description of the `GlobalMemoryStatusEx` failure case; those points are settled. One point is still open: - No measurement of the bound. A change that bounds memory needs peak process-private memory (or peak RSS) before/after on a large registration workload. #6139 is about commit growth during registration, so please post it for `main` vs this change, with the default budget and with a low `APS5_REGISTRATION_PREPARE_COMMIT_GB`, from the same machine and scene. If you have no title to run, a registration of many large shaders in a test harness that prints the peak is enough.
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!9626
No description provided.