feat(shader): keep direct VGPR accesses direct outside indexed-write slots #27862

Merged
MauriceSirius merged 2 commits from upstream-pr/27862 into main 2026-11-29 11:25:27 +00:00
MauriceSirius commented 2026-11-27 16:16:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MauriceSirius on 2026-11-27T16:16:49Z.


What

Relative VGPR indexing put every access to a windowed register through the indexed window array as soon as any relative write existed, so a program whose lowest relative write sits at a high base register pays an array indirection for every direct access below it. Killzone: Liberation (PPSA11142) has 104 relative accesses over 154 registers with dynamic indices UMin32(IAdd32(0x39 | 0x3a | 0, ReadFirstLane(<window register>)), 0x97), and its 1,730 constant-indexed VGPR accesses all went through a 152-register OpVariable array, costing ~6 FPS in its PSP vertex programs.

The translation scan now records, beside the window base, the lowest base register each relative read and each relative write addresses as window slots (vectorWindowIndexedReadSlot, vectorWindowIndexedWriteSlot). The register IR builder uses them as floors:

  • a direct read of a slot below the lowest relative write base reads the SSA register value instead of the window array;
  • a direct write of a slot at or above the lower of the two floors updates both the SSA value and the window storage, so a relative read or a window sync still observes it;
  • a direct write below both floors stays pure SSA;
  • the scoped-window block syncs start at the lower floor, since no relative access reaches a slot below it.

Every relative access is still served by the window array, loops, branches and mixed direct/indexed accesses on aliased slots keep the load-merge-store semantics, and programs whose relative write starts at the window base keep the previous behaviour unchanged. This composes with the existing slot narrowing instead of replacing it.

Tested

  • agc_vector_window (recompiler SSA-shape tests, three new): an indexed write above the window base keeps direct accesses to lower registers in SSA values; direct accesses below a window's lowest relative write shrink its SPIR-V (fewer OpAccessChain, fewer words) against one whose relative write spans the window; a direct access under a relative write's base register stays in SSA inside the write's loop.
  • GPU execution on the Vulkan backend: agc_driver_vector_window_direct_access, agc_driver_vector_window_liveness, agc_driver_vector_window_narrowing, agc_driver_vector_window_region, agc_driver_relative_ancillary, agc_driver_relative_dpp, agc_driver_relative_indexing, agc_driver_relative_indexing_bounded_values, agc_driver_relative_indexing_known_bits, agc_driver_relative_stage_inputs — 12/12 passed wave32/wave64 with validation-layer runs on Intel Iris Xe.
  • Khronos validation A/B (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation over -R agc_driver_vector_window -V): this PR and 15a9e02acbc both log the layer insert in all four test processes, zero "was not found", zero VUID- messages.
  • No scene trace attached: the change is verified at the recompiler (unit SPIR-V shape) and GPU-execution level; a Killzone bring-up trace on identical hardware was not captured.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: #27373
  • Unblocks: none
  • GPUs tested: Intel(R) Iris(R) Xe Graphics (vendor 0x8086, device 0x9a49), Vulkan driver version 1661810, Windows 11
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of indexed vector-register reads and writes, including accesses inside loops and direct reads from lower registers.
  • Performance
    • Refined vector-window handling for indexed writes, with regression coverage comparing generated shader output for different register targets.
  • Documentation
    • Added technical notes on vector-register window behavior, boundary handling, and performance observations.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5529770442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27862). Originally posted by [MauriceSirius](https://github.com/MauriceSirius) on 2026-11-27T16:16:49Z. --- ### What Relative VGPR indexing put every access to a windowed register through the indexed window array as soon as any relative write existed, so a program whose lowest relative write sits at a high base register pays an array indirection for every direct access below it. Killzone: Liberation (PPSA11142) has 104 relative accesses over 154 registers with dynamic indices `UMin32(IAdd32(0x39 | 0x3a | 0, ReadFirstLane(<window register>)), 0x97)`, and its 1,730 constant-indexed VGPR accesses all went through a 152-register `OpVariable` array, costing ~6 FPS in its PSP vertex programs. The translation scan now records, beside the window base, the lowest base register each relative read and each relative write addresses as window slots (`vectorWindowIndexedReadSlot`, `vectorWindowIndexedWriteSlot`). The register IR builder uses them as floors: - a direct read of a slot below the lowest relative write base reads the SSA register value instead of the window array; - a direct write of a slot at or above the lower of the two floors updates both the SSA value and the window storage, so a relative read or a window sync still observes it; - a direct write below both floors stays pure SSA; - the scoped-window block syncs start at the lower floor, since no relative access reaches a slot below it. Every relative access is still served by the window array, loops, branches and mixed direct/indexed accesses on aliased slots keep the load-merge-store semantics, and programs whose relative write starts at the window base keep the previous behaviour unchanged. This composes with the existing slot narrowing instead of replacing it. ### Tested - `agc_vector_window` (recompiler SSA-shape tests, three new): an indexed write above the window base keeps direct accesses to lower registers in SSA values; direct accesses below a window's lowest relative write shrink its SPIR-V (fewer `OpAccessChain`, fewer words) against one whose relative write spans the window; a direct access under a relative write's base register stays in SSA inside the write's loop. - GPU execution on the Vulkan backend: `agc_driver_vector_window_direct_access`, `agc_driver_vector_window_liveness`, `agc_driver_vector_window_narrowing`, `agc_driver_vector_window_region`, `agc_driver_relative_ancillary`, `agc_driver_relative_dpp`, `agc_driver_relative_indexing`, `agc_driver_relative_indexing_bounded_values`, `agc_driver_relative_indexing_known_bits`, `agc_driver_relative_stage_inputs` — 12/12 passed wave32/wave64 with validation-layer runs on Intel Iris Xe. - Khronos validation A/B (`ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` over `-R agc_driver_vector_window -V`): this PR and `15a9e02acbc` both log the layer insert in all four test processes, zero "was not found", zero `VUID-` messages. - No scene trace attached: the change is verified at the recompiler (unit SPIR-V shape) and GPU-execution level; a Killzone bring-up trace on identical hardware was not captured. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: #27373 - [x] Unblocks: none - [x] GPUs tested: Intel(R) Iris(R) Xe Graphics (vendor 0x8086, device 0x9a49), Vulkan driver version 1661810, Windows 11 - [x] AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of indexed vector-register reads and writes, including accesses inside loops and direct reads from lower registers. * **Performance** * Refined vector-window handling for indexed writes, with regression coverage comparing generated shader output for different register targets. * **Documentation** * Added technical notes on vector-register window behavior, boundary handling, and performance observations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
JJenkx commented 2026-11-27 16:39:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T16:39:08Z.

Review: COMMENTED


I reproduced a failure in the new SPIR-V shape assertion at 489c05c43f02 on Linux GCC 16.2.1 Release with bundled SPIRV-Tools enabled. The official agc_vector_window fixture reports 674 words and 4 access chains for the v6 write, versus 677 words and 4 chains for v4. It fails the strict access-chain comparison.

Using identical inputs on its main parent 15a9e02acbc8, v6 produced 682 words and 4 chains. The v4 control produced 677 words and 4 chains on both builds. The optimized v6 program therefore does get smaller in this configuration. The stage-input test passed on both builds.

Changing the shape check to require fewer words and no increase in access chains passes the full fixture against the same PR recompiler. The separate SSA tests still check the routing directly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6091089664 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27862#pullrequestreview-6091089664). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T16:39:08Z. **Review:** COMMENTED --- I reproduced a failure in the new SPIR-V shape assertion at `489c05c43f02` on Linux GCC 16.2.1 Release with bundled SPIRV-Tools enabled. The official `agc_vector_window` fixture reports 674 words and 4 access chains for the v6 write, versus 677 words and 4 chains for v4. It fails the strict access-chain comparison. Using identical inputs on its main parent `15a9e02acbc8`, v6 produced 682 words and 4 chains. The v4 control produced 677 words and 4 chains on both builds. The optimized v6 program therefore does get smaller in this configuration. The stage-input test passed on both builds. Changing the shape check to require fewer words and **no increase** in access chains passes the full fixture against the same PR recompiler. The separate SSA tests still check the routing directly.
MarcZX10 commented 2026-11-27 16:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T16:50:59Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected IR routing and window sync floors are consistent with the new per-access base slots, and the author reports GPU validation runs that I did not perform.

What I ran

Reviewed head 489c05c43f0235162dc426378b2c37932477d097. No tests or builds were run. I read all five changed files listed as reviewed in the manifest and inspected the relevant translation, control-flow, and SPIR-V emitter code. The author-reported test results are not my runs.

Results

Check Result Note
Changed code review passed All five changed files read
Tests and build not run No local execution
Author-reported GPU checks not run Reported as passed in the description

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the listed unit or GPU tests, validate the shaders, or capture a Killzone scene trace. No files were excluded according to the review manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6091211307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27862#pullrequestreview-6091211307). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T16:50:59Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected IR routing and window sync floors are consistent with the new per-access base slots, and the author reports GPU validation runs that I did not perform. ## What I ran Reviewed head `489c05c43f0235162dc426378b2c37932477d097`. No tests or builds were run. I read all five changed files listed as `reviewed` in the manifest and inspected the relevant translation, control-flow, and SPIR-V emitter code. The author-reported test results are not my runs. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All five changed files read | | Tests and build | not run | No local execution | | Author-reported GPU checks | not run | Reported as passed in the description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run the listed unit or GPU tests, validate the shaders, or capture a Killzone scene trace. No files were excluded according to the review manifest. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-28 14:06:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T14:06:07Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the source and test additions reviewed; the submitted test results are author-reported and were not run here.

What I ran

Reviewed head 0550c95d45e0ff35bc6c6b391d8d51482b3c62f4 using repo_read.py. I read description.md, commits.md, manifest.json, diff.patch, and all five changed files listed in the manifest. No tests or builds were run.

Results

Check Result Note
Diff and changed source review passed Five changed files read
Build and tests not run Reported test runs are author-supplied

Findings

Blocking

None identified in the changed code reviewed.

Non-blocking

None.

Not verified

The reported recompiler and Vulkan test runs were not independently run or confirmed. No unchanged callers or other repository files were inspected. files.json was not available through the review reader, so I could not check for excluded files; the manifest lists five changed files, all marked included.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6098283583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27862#pullrequestreview-6098283583). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T14:06:07Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the source and test additions reviewed; the submitted test results are author-reported and were not run here. ## What I ran Reviewed head `0550c95d45e0ff35bc6c6b391d8d51482b3c62f4` using `repo_read.py`. I read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and all five changed files listed in the manifest. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source review | passed | Five changed files read | | Build and tests | not run | Reported test runs are author-supplied | ## Findings ### Blocking None identified in the changed code reviewed. ### Non-blocking None. ## Not verified The reported recompiler and Vulkan test runs were not independently run or confirmed. No unchanged callers or other repository files were inspected. `files.json` was not available through the review reader, so I could not check for excluded files; the manifest lists five changed files, all marked included. ## To get this to a good state Nothing is required.
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!27862
No description provided.