fix(agc): preserve proven base formatted buffer read extents #14944

Open
arcwiser wants to merge 1 commit from upstream-pr/14944 into main
arcwiser commented 2026-11-02 03:01:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by arcwiser on 2026-11-02T03:01:40Z.


What

A nonempty, stride-zero RGB32_FLOAT buffer with OOB_SELECT=2 can be bound as an SSBO with only NumRecords bytes. A base formatted read then returns X correctly while Vulkan robust access replaces Y and Z with zero.

This change carries a narrow static proof from the resource tracker to the driver. For read-only, non-atomic, descriptor-formatted base reads whose complete unpacked 32-bit element is proven, the driver binds at least that element's byte extent. Dynamic offsets, packed or typed loads, raw vector accesses, writes, atomics and empty descriptors keep the existing bound.

The new extent participates in resource identity, queued read ranges, alias checks, moved-buffer checks and shader-disk-cache serialization. The cache format moves from 50 to 51.

Original analysis, implementation and tests are by @lgqdaxia in #14439 and commit 5fb8b2c27e; this PR preserves that commit's authorship. The issue explicitly invited others to adopt or independently upstream the candidate.

Tested

Windows 11 10.0.26200, MSYS2 UCRT64 GCC 16.2.0, Release, BUILD_TESTING=ON, NVIDIA GeForce RTX 4070 SUPER, driver 610.88, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1.

Built agc_driver_buffer_format_oob2_stride_zero_tests, agc_driver_graphics_tests, agc_shader_disk_cache_tests and agc_shader_memory_tests.

Passed 5/5 focused CTests: agc_driver_buffer_format_oob2_stride_zero, agc_driver_buffer_read_extents, agc_driver_buffer_read_extents_all_written, agc_shader_disk_cache and agc_shader_base_formatted_read_extent.

The real Vulkan regression bound the exact stride-zero format-74 OOB2 descriptor. With NumRecords=1, it read {1.25f, -2.5f, 19.0f} as 3fa00000 c0200000 41980000; the output guard stayed deadbeef. The NumRecords=12 control returned the same values.

python tools/check_conventions.py --base origin/main and git diff --check origin/main...HEAD pass.

tools/pr_overlap.py --branch fix/ssbo-oob2-read-extent compared all 1,886 open PRs and reported expected line-level conflicts across shared AGC/recompiler files; it failed closed on several heads it could not confirm. Exact open-PR searches for bufferReadExtent, base formatted read extents and the stride-zero OOB2 SSBO case found no implementation of this behavior.

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: none
  • Fixes: #14439
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 610.88, Windows 11 10.0.26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5114279822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14944). Originally posted by [arcwiser](https://github.com/arcwiser) on 2026-11-02T03:01:40Z. --- ### What A nonempty, stride-zero `RGB32_FLOAT` buffer with `OOB_SELECT=2` can be bound as an SSBO with only `NumRecords` bytes. A base formatted read then returns X correctly while Vulkan robust access replaces Y and Z with zero. This change carries a narrow static proof from the resource tracker to the driver. For read-only, non-atomic, descriptor-formatted base reads whose complete unpacked 32-bit element is proven, the driver binds at least that element's byte extent. Dynamic offsets, packed or typed loads, raw vector accesses, writes, atomics and empty descriptors keep the existing bound. The new extent participates in resource identity, queued read ranges, alias checks, moved-buffer checks and shader-disk-cache serialization. The cache format moves from 50 to 51. Original analysis, implementation and tests are by @lgqdaxia in #14439 and commit `5fb8b2c27e`; this PR preserves that commit's authorship. The issue explicitly invited others to adopt or independently upstream the candidate. ### Tested Windows 11 10.0.26200, MSYS2 UCRT64 GCC 16.2.0, Release, `BUILD_TESTING=ON`, NVIDIA GeForce RTX 4070 SUPER, driver 610.88, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`. Built `agc_driver_buffer_format_oob2_stride_zero_tests`, `agc_driver_graphics_tests`, `agc_shader_disk_cache_tests` and `agc_shader_memory_tests`. Passed 5/5 focused CTests: `agc_driver_buffer_format_oob2_stride_zero`, `agc_driver_buffer_read_extents`, `agc_driver_buffer_read_extents_all_written`, `agc_shader_disk_cache` and `agc_shader_base_formatted_read_extent`. The real Vulkan regression bound the exact stride-zero format-74 OOB2 descriptor. With `NumRecords=1`, it read `{1.25f, -2.5f, 19.0f}` as `3fa00000 c0200000 41980000`; the output guard stayed `deadbeef`. The `NumRecords=12` control returned the same values. `python tools/check_conventions.py --base origin/main` and `git diff --check origin/main...HEAD` pass. `tools/pr_overlap.py --branch fix/ssbo-oob2-read-extent` compared all 1,886 open PRs and reported expected line-level conflicts across shared AGC/recompiler files; it failed closed on several heads it could not confirm. Exact open-PR searches for `bufferReadExtent`, base formatted read extents and the stride-zero OOB2 SSBO case found no implementation of this behavior. ### 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: none - [x] Fixes: #14439 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 610.88, Windows 11 10.0.26200 - [x] AI-assisted: yes
mashingaan commented 2026-11-02 11:23:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T11:23:36Z.

Review: CHANGES_REQUESTED


The exact hosted Windows run fails in agc_driver_key_miss. Its synthetic shader-key builder still emits the old format. Please update the fixture for the added bufferReadExtent length and tenth flags block, then rerun the focused hosted check.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5735796221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14944#pullrequestreview-5735796221). Originally posted by [mashingaan](https://github.com/mashingaan) on 2026-11-02T11:23:36Z. **Review:** CHANGES_REQUESTED --- The exact hosted Windows run fails in agc_driver_key_miss. Its synthetic shader-key builder still emits the old format. Please update the fixture for the added bufferReadExtent length and tenth flags block, then rerun the focused hosted check.
adriadam10 commented 2026-11-06 21:53:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T21:53:54Z.

Review: CHANGES_REQUESTED


Checked the diff against the exact-head Build run and current main:

  • agc_driver_key_miss fails on Windows (run 41380807522, ***Failed). LabelShaderKey now expects a tenth flags block and the bufferReadExtent length word, but the synthetic key in core/libs/prx/libSceAgcDriver/tests/KeyMiss.cpp:33 still pushes 9 flag blocks (flags < 9) and no extents. Update the fixture. This is the same point @mashingaan raised.
  • Conflicts with main: Graphics/include/ShaderResources.hpp, Graphics/src/ShaderResources.cpp, tests/ShaderMemory.cpp, core/shader/recompiler/ShaderDiskCache.cpp, ShaderDiskCache.hpp and docs/dev/debt/libSceAgcDriver.md. These are code conflicts in the buffer-size path (guestBufferBytes/addGuestBuffer) and the cache format, so please rebase and re-check that GuestBufferBytes is still used at every site that read descriptor.GetSize() on main. Also take the next free FormatVersion after the rebase.
  • After the rebase, rerun the focused tests (agc_driver_key_miss, agc_shader_disk_cache, the new read-extent tests) and push so the Build run covers the new head.

The design looks sound to me (static proof only for complete unpacked 32-bit base reads, existing bound kept for writes, atomics, packed or typed loads and dynamic offsets). Once the Build is green I will measure the OOB_SELECT=2 behaviour on the hardware oracle before merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5807548582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14944#pullrequestreview-5807548582). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-06T21:53:54Z. **Review:** CHANGES_REQUESTED --- Checked the diff against the exact-head Build run and current `main`: - **`agc_driver_key_miss` fails on Windows** (run 41380807522, `***Failed`). `LabelShaderKey` now expects a tenth flags block and the `bufferReadExtent` length word, but the synthetic key in `core/libs/prx/libSceAgcDriver/tests/KeyMiss.cpp:33` still pushes 9 flag blocks (`flags < 9`) and no extents. Update the fixture. This is the same point @mashingaan raised. - **Conflicts with `main`**: `Graphics/include/ShaderResources.hpp`, `Graphics/src/ShaderResources.cpp`, `tests/ShaderMemory.cpp`, `core/shader/recompiler/ShaderDiskCache.cpp`, `ShaderDiskCache.hpp` and `docs/dev/debt/libSceAgcDriver.md`. These are code conflicts in the buffer-size path (`guestBufferBytes`/`addGuestBuffer`) and the cache format, so please rebase and re-check that `GuestBufferBytes` is still used at every site that read `descriptor.GetSize()` on `main`. Also take the next free `FormatVersion` after the rebase. - After the rebase, rerun the focused tests (`agc_driver_key_miss`, `agc_shader_disk_cache`, the new read-extent tests) and push so the Build run covers the new head. The design looks sound to me (static proof only for complete unpacked 32-bit base reads, existing bound kept for writes, atomics, packed or typed loads and dynamic offsets). Once the Build is green I will measure the OOB_SELECT=2 behaviour on the hardware oracle before merging.
MarcZX10 commented 2026-11-18 21:31:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T21:31:28Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the requested read-extent behavior is supported by the inspected proof, descriptor-binding, and identity paths.

What I ran

Inspected the prepared diff and source context at head 43fba79d9ae67448076de73df413eb3c3af6bba4 using repo_read.py. No build or tests were run in this review.

Results

Check Result Note
Source review passed Core proof and binding paths inspected
Build and tests not run Reported test results are author supplied

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build, CTests, hardware Vulkan behavior, and the full contents of core/libs/prx/libSceAgcDriver/tests/Graphics.cpp and core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp were not verified in this review. The author reports five focused CTests passing on Windows 11 with an RTX 4070 SUPER. Read: WrittenBuffers.cpp, ShaderResources.hpp, Draw.cpp, ShaderResources.cpp, ShaderDiskCache.cpp, the changed CMake files, BufferFormatOob2StrideZero.cpp, Resources.hpp, DescriptorBindingBuilder.cpp, ResourceTracker.cpp, Recompiler.cpp, Recompiler.hpp, ShaderDiskCache.cpp (recompiler), ShaderDiskCache.hpp, and docs/dev/debt/libSceAgcDriver.md. Excluded from full-text review by bundle rule: Graphics.cpp and ShaderMemory.cpp.

To get this to a good state

Nothing is required. The author-reported hardware regression and test results are useful optional context.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5965498302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14944#pullrequestreview-5965498302). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T21:31:28Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the requested read-extent behavior is supported by the inspected proof, descriptor-binding, and identity paths. ## What I ran Inspected the prepared diff and source context at head `43fba79d9ae67448076de73df413eb3c3af6bba4` using `repo_read.py`. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Core proof and binding paths inspected | | Build and tests | not run | Reported test results are author supplied | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Build, CTests, hardware Vulkan behavior, and the full contents of `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` and `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` were not verified in this review. The author reports five focused CTests passing on Windows 11 with an RTX 4070 SUPER. Read: `WrittenBuffers.cpp`, `ShaderResources.hpp`, `Draw.cpp`, `ShaderResources.cpp`, `ShaderDiskCache.cpp`, the changed CMake files, `BufferFormatOob2StrideZero.cpp`, `Resources.hpp`, `DescriptorBindingBuilder.cpp`, `ResourceTracker.cpp`, `Recompiler.cpp`, `Recompiler.hpp`, `ShaderDiskCache.cpp` (recompiler), `ShaderDiskCache.hpp`, and `docs/dev/debt/libSceAgcDriver.md`. Excluded from full-text review by bundle rule: `Graphics.cpp` and `ShaderMemory.cpp`. ## To get this to a good state Nothing is required. The author-reported hardware regression and test results are useful optional context.
ligmaSec commented 2026-12-03 22:45:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:23Z.

Review: COMMENTED


The trial merge onto c1601e56d5 conflicts in ShaderResources.cpp, recompiler state, shader disk cache and fixture registration. Keep the static proof narrow after the rebase. Only a proven base, descriptor-formatted read should widen the range to a full element; offset, writable and atomic controls should first establish they do not get that wider read allowance. Reconcile the cache format and move the direct AGC debt edit into a fragment.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179948990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14944#pullrequestreview-6179948990). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:45:23Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` conflicts in `ShaderResources.cpp`, recompiler state, shader disk cache and fixture registration. Keep the static proof narrow after the rebase. Only a proven base, descriptor-formatted read should widen the range to a full element; offset, writable and atomic controls should first establish they do not get that wider read allowance. Reconcile the cache format and move the direct AGC debt edit into a fragment. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/14944:upstream-pr/14944'
git switch 'upstream-pr/14944'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/14944'
git switch 'upstream-pr/14944'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/14944'
git switch 'upstream-pr/14944'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/14944'
git switch 'main'
git merge --squash 'upstream-pr/14944'
git switch 'main'
git merge --ff-only 'upstream-pr/14944'
git switch 'main'
git merge 'upstream-pr/14944'
git push origin 'main'
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!14944
No description provided.