fix(agc): keep a registered shader's register state as a sorted list #10727

Merged
milescoviello merged 4 commits from upstream-pr/10727 into main 2026-11-02 10:23:57 +00:00
milescoviello commented 2026-10-24 19:51:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-24T19:51:25Z.


What

A registered shader's RegisteredShaderState holds its shader, context and user config registers, each a Registers. Registers is dense: it keeps a value for every offset up to the highest one set, rounded up to 64, plus a presence bit per offset. A registration's user config state has two registers at 0x24a and 0x24b, and that comes to 2.5 KiB. Its context state starts from the ~300 initial context registers spread up to 0x3b8, about 4.1 KiB. In Ghost of Tsushima (PPSA02225), 172 s into the opening, the registry held 14,322 live states. Their register files came to at least 110.1 MiB in the dense layout, and they hold 33.1 MiB of offset and value pairs. A heap profile 900 s in had 52.7 MiB at InitialContextRegisters, 34.1 MiB at the user config initializer and 23.0 MiB at Registers::mark under RegisterShader.

RegisteredShaderState now stores each file as a RegisterList, the present registers as (offset, value) pairs in offset order.

Stacked on #10685

This branch holds #10685's commit (4f15f29b42) and then its own, which is the only one to review here. Both PRs add a type in front of RegisteredShaderState in ShaderRegistry.hpp, so they would conflict on their own.

How

  • ShaderRegistry.hpp: RegisterList is built from a Registers and expands back with Expand(), which sets the highest offset first so the dense array is sized once. It has find/end/at (binary search), ForEach, size, empty, emplace (keeps offset order, doesn't replace) and ==. Decoding still builds dense Registers, now in DecodedShaderState, and RegisteredShaderState is constructed from one, so the null and depth-copy programs and the ABI path that adjust or read the decoded registers are unchanged.
  • ShaderRegistry.cpp: DecodeRegisteredState returns a DecodedShaderState. The four places that copy a registered state into a QueueState expand it. DecodeFloatMode takes either form and reads RSRC1 with find, so a dispatch's float mode never expands a state.

Tested

Head 03449442ec (this commit on #10685's current head 22d82e41c4), merged with main 08a10d2253 (merge f0ab66231d, clean): a full cmake --build build succeeds, and the 85 tests matching the pattern below pass 3 of 3. Under the Khronos validation layer, 85 of 85 pass on main and on the merge, with no VUID- messages.

Earlier:

Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09. The change was tested alone as 7e8e229bdf on main 30be9b428b, and as this branch's head 7c940756fd on #10685. The 80 tests below pass 3 of 3 on both; the mutant, validation and Windows runs are on 7e8e229bdf.

  • New testRegisterList in agc_driver: a list keeps its registers (expands back to the same Registers), find hits and misses correctly, emplace keeps offset order without replacing a value, and a registered state keeps its decoded registers. With emplace appending out of order (a mutant), agc_driver fails 3 of 3: a register list is not kept in offset order, or a second emplace replaced a value. testRegisteredFloatMode reads RSRC1 through the new form.
  • agc_driver and its three modes plus the tests of every source that uses ShaderSnapshot (80 in all): 80 of 80 pass 3 of 3 on main and on this head.
  • Khronos validation 1.4.363 over the same 80, on main 30be9b428b and on 7e8e229bdf, each run as VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "$R" -V -j4: 80 of 80 pass on each, with no skipped test, 136 device selections (RTX 4070 Ti) on each and no layer-missing line. Both report the same 14 VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, and none is new in the head.
  • Windows 11 VM (GeForce GT 1030, 582.78, WinLibs GCC 15.2.0 r7, Release), main 30be9b428b vs 7e8e229bdf: the same pattern matches 81 tests there. They pass 3 of 3 on main, and on the head 2 of 3 with all 81. In the third run agc_driver_submit_progress failed once, then passed 10 of 10 on the same build (ctest --repeat until-fail:10). This change doesn't touch submission progress.
  • Ghost of Tsushima, live registry counts from a local diagnostic over the registry (got/g14, my local stack that gets the title through its opening, 16 GB cap): at 46,000 registrations, 3,324 states, dense 23.3 MiB against 7.7 MiB of pairs; at 94,000, 14,322 states, dense 110.1 MiB against 33.1 MiB. The dense figure counts each file's values and presence bits up to its highest offset, so it's a lower bound on what the vectors allocate.
  • Windows, NVIDIA and AMD (wachi35676, WinLibs GCC 15.2.0, Release, this head with #10685's commit merged onto main aeff26bd9): RTX 5070 Ti (621.01) and an AMD RDNA2 iGPU (proprietary 2026.04.17). The 39 agc_driver, prepared_*, registry and submit tests pass on both. The append-instead-of-insert mutant of RegisterList::emplace fails agc_driver with the ordering message. 285 agc_ tests fail the same way with and without the change.

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
  • 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: #10685 (both add types in front of RegisteredShaderState in ShaderRegistry.hpp; this branch carries #10685's commit, and the last commit is this change)
  • Fixes: none
  • Unblocks: none (it lowers the memory Ghost of Tsushima, PPSA02225, needs in its opening)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 615.71.09, Ubuntu 26.04.1; NVIDIA GeForce GT 1030, driver 582.78, Windows 11 VM; NVIDIA RTX 5070 Ti and AMD RDNA2 iGPU, Windows 11 (by wachi35676)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4998606119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10727). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-24T19:51:25Z. --- ### What A registered shader's `RegisteredShaderState` holds its shader, context and user config registers, each a `Registers`. `Registers` is dense: it keeps a value for every offset up to the highest one set, rounded up to 64, plus a presence bit per offset. A registration's user config state has two registers at 0x24a and 0x24b, and that comes to 2.5 KiB. Its context state starts from the ~300 initial context registers spread up to 0x3b8, about 4.1 KiB. In Ghost of Tsushima (PPSA02225), 172 s into the opening, the registry held 14,322 live states. Their register files came to at least 110.1 MiB in the dense layout, and they hold 33.1 MiB of offset and value pairs. A heap profile 900 s in had 52.7 MiB at `InitialContextRegisters`, 34.1 MiB at the user config initializer and 23.0 MiB at `Registers::mark` under `RegisterShader`. `RegisteredShaderState` now stores each file as a `RegisterList`, the present registers as (offset, value) pairs in offset order. ### Stacked on #10685 This branch holds #10685's commit (`4f15f29b42`) and then its own, which is the only one to review here. Both PRs add a type in front of `RegisteredShaderState` in `ShaderRegistry.hpp`, so they would conflict on their own. ### How - `ShaderRegistry.hpp`: `RegisterList` is built from a `Registers` and expands back with `Expand()`, which sets the highest offset first so the dense array is sized once. It has `find`/`end`/`at` (binary search), `ForEach`, `size`, `empty`, `emplace` (keeps offset order, doesn't replace) and `==`. Decoding still builds dense `Registers`, now in `DecodedShaderState`, and `RegisteredShaderState` is constructed from one, so the null and depth-copy programs and the ABI path that adjust or read the decoded registers are unchanged. - `ShaderRegistry.cpp`: `DecodeRegisteredState` returns a `DecodedShaderState`. The four places that copy a registered state into a `QueueState` expand it. `DecodeFloatMode` takes either form and reads RSRC1 with `find`, so a dispatch's float mode never expands a state. ### Tested **Head `03449442ec`** (this commit on #10685's current head `22d82e41c4`), merged with `main` `08a10d2253` (merge `f0ab66231d`, clean): a full `cmake --build build` succeeds, and the 85 tests matching the pattern below pass 3 of 3. Under the Khronos validation layer, 85 of 85 pass on `main` and on the merge, with no `VUID-` messages. **Earlier:** Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09. The change was tested alone as `7e8e229bdf` on `main` 30be9b428b, and as this branch's head `7c940756fd` on #10685. The 80 tests below pass 3 of 3 on both; the mutant, validation and Windows runs are on `7e8e229bdf`. - New `testRegisterList` in `agc_driver`: a list keeps its registers (expands back to the same `Registers`), `find` hits and misses correctly, `emplace` keeps offset order without replacing a value, and a registered state keeps its decoded registers. With `emplace` appending out of order (a mutant), `agc_driver` fails 3 of 3: `a register list is not kept in offset order, or a second emplace replaced a value`. `testRegisteredFloatMode` reads RSRC1 through the new form. - `agc_driver` and its three modes plus the tests of every source that uses `ShaderSnapshot` (80 in all): 80 of 80 pass 3 of 3 on `main` and on this head. - Khronos validation 1.4.363 over the same 80, on `main` 30be9b428b and on `7e8e229bdf`, each run as `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R "$R" -V -j4`: 80 of 80 pass on each, with no skipped test, 136 device selections (RTX 4070 Ti) on each and no layer-missing line. Both report the same 14 `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605`, and none is new in the head. - Windows 11 VM (GeForce GT 1030, 582.78, WinLibs GCC 15.2.0 r7, Release), `main` 30be9b428b vs `7e8e229bdf`: the same pattern matches 81 tests there. They pass 3 of 3 on `main`, and on the head 2 of 3 with all 81. In the third run `agc_driver_submit_progress` failed once, then passed 10 of 10 on the same build (`ctest --repeat until-fail:10`). This change doesn't touch submission progress. - Ghost of Tsushima, live registry counts from a local diagnostic over the registry (`got/g14`, my local stack that gets the title through its opening, 16 GB cap): at 46,000 registrations, 3,324 states, dense 23.3 MiB against 7.7 MiB of pairs; at 94,000, 14,322 states, dense 110.1 MiB against 33.1 MiB. The dense figure counts each file's values and presence bits up to its highest offset, so it's a lower bound on what the vectors allocate. - **Windows, NVIDIA and AMD** ([wachi35676](https://github.com/boykopovar/AnyPS5/pull/10727#issuecomment-6407516240), WinLibs GCC 15.2.0, Release, this head with #10685's commit merged onto `main` aeff26bd9): RTX 5070 Ti (621.01) and an AMD RDNA2 iGPU (proprietary 2026.04.17). The 39 `agc_driver`, `prepared_*`, registry and submit tests pass on both. The append-instead-of-insert mutant of `RegisterList::emplace` fails `agc_driver` with the ordering message. 285 `agc_` tests fail the same way with and without the change. ### 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](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: #10685 (both add types in front of `RegisteredShaderState` in `ShaderRegistry.hpp`; this branch carries #10685's commit, and the last commit is this change) - [x] Fixes: none - [x] Unblocks: none (it lowers the memory Ghost of Tsushima, PPSA02225, needs in its opening) - [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 VM; NVIDIA RTX 5070 Ti and AMD RDNA2 iGPU, Windows 11 (by wachi35676) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 20:05:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:05:27Z.

Review: COMMENTED


The paired register-state checks and the memory measurements are useful. Since this changes the AGC shader path, CONTRIBUTING requires the same focused run on main and the change with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The report confirms validation and says no layer-missing warning appeared, but it does not record whether the first two controls were set for the 80-test comparison. Could you add the exact environment/command, or rerun with those controls if they were not set? This will establish that both arms exercised Vulkan and did not reuse shader-cache results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639759080 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10727#pullrequestreview-5639759080). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:05:27Z. **Review:** COMMENTED --- The paired register-state checks and the memory measurements are useful. Since this changes the AGC shader path, CONTRIBUTING requires the same focused run on `main` and the change with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. The report confirms validation and says no layer-missing warning appeared, but it does not record whether the first two controls were set for the 80-test comparison. Could you add the exact environment/command, or rerun with those controls if they were not set? This will establish that both arms exercised Vulkan and did not reuse shader-cache results.
MarcZX10 commented 2026-10-24 20:25:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:25:15Z.

Review: APPROVED


Re-reviewed exact head 7c940756fd0d0d5306dbbb539377d8179cb3803f. The author clarified the comparison command and confirms ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_LAYER_KHRONOS_validation were set on both baseline and change; all 80 focused tests passed 3/3 on each arm with 136 RTX 4070 Ti device selections and no layer-missing warning. The functional review remains clean: RegisterList preserves offset order and values, expands only at queue-state boundaries, and float-mode reads avoid expansion. Windows data includes one transient unrelated submission-progress failure followed by 10/10 passes. Eligibility, conventions, intake, labels, and report are green; product jobs are skipped by policy. No blocking issue remains.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639816534 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10727#pullrequestreview-5639816534). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:25:15Z. **Review:** APPROVED --- Re-reviewed exact head `7c940756fd0d0d5306dbbb539377d8179cb3803f`. The author clarified the comparison command and confirms `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and `VK_LAYER_KHRONOS_validation` were set on both baseline and change; all 80 focused tests passed 3/3 on each arm with 136 RTX 4070 Ti device selections and no layer-missing warning. The functional review remains clean: `RegisterList` preserves offset order and values, expands only at queue-state boundaries, and float-mode reads avoid expansion. Windows data includes one transient unrelated submission-progress failure followed by 10/10 passes. Eligibility, conventions, intake, labels, and report are green; product jobs are skipped by policy. No blocking issue remains.
MarcZX10 commented 2026-10-25 02:53:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:53:18Z.

Review: DISMISSED


Reviewed current head 7c940756fd0d0d5306dbbb539377d8179cb3803f and refreshed the dependency state. The description says this branch contains #10685 commit 4f15f29b42 and is stacked on #10685, while that PR is still OPEN at the exact commit and this branch lists Depends on: none. CONTRIBUTING.md requires a PR that needs another one first to name it on the checklist and requires overlapping PR merge order to be declared. Please change the checklist to Depends on: #10685 (and keep the branch based on that PR until it lands); otherwise reviewers and merge automation can treat this stacked change as independently mergeable. The code review and focused Vulkan baseline/candidate evidence remain as in my prior approval; this request is only for the contradictory dependency metadata.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5641243509 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10727#pullrequestreview-5641243509). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T02:53:18Z. **Review:** DISMISSED --- Reviewed current head `7c940756fd0d0d5306dbbb539377d8179cb3803f` and refreshed the dependency state. The description says this branch contains #10685 commit `4f15f29b42` and is stacked on #10685, while that PR is still OPEN at the exact commit and this branch lists `Depends on: none`. CONTRIBUTING.md requires a PR that needs another one first to name it on the checklist and requires overlapping PR merge order to be declared. Please change the checklist to `Depends on: #10685` (and keep the branch based on that PR until it lands); otherwise reviewers and merge automation can treat this stacked change as independently mergeable. The code review and focused Vulkan baseline/candidate evidence remain as in my prior approval; this request is only for the contradictory dependency metadata.
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!10727
No description provided.