fix(agc): bind misaligned buffer views through copies of their own #122

Closed
oneandonlydean wants to merge 1 commit from upstream-pr/122 into main
oneandonlydean commented 2026-09-29 00:24:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T00:24:59Z.


What

A region decides its storage-buffer offset alignment by its first byte alone, so a V# inside it at a misaligned distance from the region's binding base fails Descriptor ("violates storage buffer offset alignment") and the draw or dispatch is skipped. This is separate from the misaligned regions main already copies out of imports: here the region itself is fine and one view inside it is not. Two shapes reach it: an element at an odd offset inside a region bound in place from an import, and the second of two overlapping allocations whose merged region starts at the first. The recompiled shaders index a binding from the V#'s base, so there is no per-binding offset to pass a remainder through.

Such views now bind an alias: a buffer holding the view's bytes from the view's address, bound at offset 0.

  • With an import and an active recorder the GPU fills it, recorded with the regions' copy-ins through recordGpuCopies, so the input snapshots for deferred copies (#94) apply to it like any copied region. A written alias is copied back into the import by RecordCopyBacks, or stored from its host-visible copy by WriteBack when the use records no copy-back.
  • Otherwise the CPU fills it from the region's bytes, and WriteBack stores only the bytes the GPU changed.
  • Overlapping misaligned views of one region at the same residue share one alias. The regions' copy-back, write-back and direct-write marks now cover only writes bound through the regions.

Still throws: written views bound through different bindings that overlap (one binding's copy-back would roll back the other's stores), naming both views. Builds with aliases are not reused (DirectRegions). The remaining alignment error names the view, its owner region, the binding base and its kind.

Tested

  • Linux (CachyOS, RTX 4090): agc_driver_recorder_tests with the new tests/ViewAliases.cpp (GPU copy path over a host import: odd view in a region bound in place with copy-back, overlapping allocations with no copy-back, rejected overlap of two written views). It is added to the agc_driver_recorder_tests target; that target is not under ctest because it needs a Vulkan device. With alias binding disabled it fails.
  • agc_driver_graphics_tests (BdaResources, CPU path) passes with #113 merged in, and fails with alias binding disabled.
  • Also built and tested merged with the write-watch branches: all pass.
  • Exercised in Astro Bot on our integration branch, where these views were skipping draws.
  • ctest: 57/57 pass.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: #113 (to build the BdaResources part of the test; the fix and the recorder test build without it)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4670911499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/122). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-29T00:24:59Z. --- ### What A region decides its storage-buffer offset alignment by its first byte alone, so a V# inside it at a misaligned distance from the region's binding base fails `Descriptor` ("violates storage buffer offset alignment") and the draw or dispatch is skipped. This is separate from the misaligned *regions* main already copies out of imports: here the region itself is fine and one view inside it is not. Two shapes reach it: an element at an odd offset inside a region bound in place from an import, and the second of two overlapping allocations whose merged region starts at the first. The recompiled shaders index a binding from the V#'s base, so there is no per-binding offset to pass a remainder through. Such views now bind an alias: a buffer holding the view's bytes from the view's address, bound at offset 0. - With an import and an active recorder the GPU fills it, recorded with the regions' copy-ins through `recordGpuCopies`, so the input snapshots for deferred copies (#94) apply to it like any copied region. A written alias is copied back into the import by `RecordCopyBacks`, or stored from its host-visible copy by `WriteBack` when the use records no copy-back. - Otherwise the CPU fills it from the region's bytes, and `WriteBack` stores only the bytes the GPU changed. - Overlapping misaligned views of one region at the same residue share one alias. The regions' copy-back, write-back and direct-write marks now cover only writes bound through the regions. Still throws: written views bound through different bindings that overlap (one binding's copy-back would roll back the other's stores), naming both views. Builds with aliases are not reused (`DirectRegions`). The remaining alignment error names the view, its owner region, the binding base and its kind. ### Tested - Linux (CachyOS, RTX 4090): `agc_driver_recorder_tests` with the new `tests/ViewAliases.cpp` (GPU copy path over a host import: odd view in a region bound in place with copy-back, overlapping allocations with no copy-back, rejected overlap of two written views). It is added to the `agc_driver_recorder_tests` target; that target is not under ctest because it needs a Vulkan device. With alias binding disabled it fails. - `agc_driver_graphics_tests` (BdaResources, CPU path) passes with #113 merged in, and fails with alias binding disabled. - Also built and tested merged with the write-watch branches: all pass. - Exercised in Astro Bot on our integration branch, where these views were skipping draws. - `ctest`: 57/57 pass. ### 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] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: #113 (to build the BdaResources part of the test; the fix and the recorder test build without it) - [x] AI-assisted: yes
oneandonlydean commented 2026-09-30 11:03:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-30T11:03:54Z.


Closing this one: 3dec6ced on main now binds misaligned views from the aligned offset below them and passes the difference to the shader, which covers what this PR was for. Main still throws for a remainder that is not a multiple of 4 bytes and for shaders whose shader data is a buffer; PPSA21564 has not hit either case, so there is nothing left here worth merging. If one of them shows up I will open a small PR on top of the current code. Thanks!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5909885946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/122#issuecomment-5909885946). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-30T11:03:54Z. --- Closing this one: 3dec6ced on main now binds misaligned views from the aligned offset below them and passes the difference to the shader, which covers what this PR was for. Main still throws for a remainder that is not a multiple of 4 bytes and for shaders whose shader data is a buffer; PPSA21564 has not hit either case, so there is nothing left here worth merging. If one of them shows up I will open a small PR on top of the current code. Thanks!

Pull request closed

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!122
No description provided.