fix(agc): snapshot misaligned draw inputs from the offset the shader reads #202

Merged
oneandonlydean merged 1 commit from upstream-pr/202 into main 2026-10-01 08:31:31 +00:00
oneandonlydean commented 2026-10-01 03:11:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-01T03:11:59Z.


What

Follows 3dec6ced and 9f1c680b.

3dec6ced binds a guest buffer view whose offset is off minStorageBufferOffsetAlignment from the aligned offset below it, and the shader adds the difference (the push constant patch) to every access. 9f1c680b's ShaderResources::PrepareDrawBindings copies a read-only in-place draw input into a fresh buffer, but that snapshot starts at the view itself and is bound at offset 0. So for a misaligned view, the patched shader read the snapshot 4, 8 or 12 bytes past the view's data.

The snapshot now covers [address - adjustment, address + size), so the shader's offset into it lands on the view's first byte again. Aligned views (adjustment 0) are unchanged.

In PPSA21564 this showed up as intermittent single-frame flicker whenever a per-frame constant block landed off the 16-byte alignment: the title screen's nebula haze vanished, the NEW GAME menu washed blue and the world map planet turned purple for a frame.

Tested

  • Linux (CachyOS, RTX 4090, NVIDIA 610.57): new misalignedSnapshotTests in agc_driver_recorder_tests binds an aligned view and a view 4 bytes into it in one guest buffer array over a host import, checks the push constant patch is the 4-byte adjustment, and checks the draw snapshot holds the view's bytes at the offset the shader reads. Without the fix it fails with "a draw snapshot ends before the bytes the shader reads"; with it the whole binary passes. It skips itself without host imports or with an alignment outside 8 to 256.
  • Exercised in PPSA21564 on our integration branch: the flicker frames are gone.
  • ctest --test-dir build: 79/79 pass on current main with this branch. agc_driver_recorder_tests and agc_driver_graphics_tests 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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4698747078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/202). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-01T03:11:59Z. --- ### What Follows 3dec6ced and 9f1c680b. 3dec6ced binds a guest buffer view whose offset is off `minStorageBufferOffsetAlignment` from the aligned offset below it, and the shader adds the difference (the push constant patch) to every access. 9f1c680b's `ShaderResources::PrepareDrawBindings` copies a read-only in-place draw input into a fresh buffer, but that snapshot starts at the view itself and is bound at offset 0. So for a misaligned view, the patched shader read the snapshot 4, 8 or 12 bytes past the view's data. The snapshot now covers `[address - adjustment, address + size)`, so the shader's offset into it lands on the view's first byte again. Aligned views (adjustment 0) are unchanged. In PPSA21564 this showed up as intermittent single-frame flicker whenever a per-frame constant block landed off the 16-byte alignment: the title screen's nebula haze vanished, the NEW GAME menu washed blue and the world map planet turned purple for a frame. ### Tested - Linux (CachyOS, RTX 4090, NVIDIA 610.57): new `misalignedSnapshotTests` in `agc_driver_recorder_tests` binds an aligned view and a view 4 bytes into it in one guest buffer array over a host import, checks the push constant patch is the 4-byte adjustment, and checks the draw snapshot holds the view's bytes at the offset the shader reads. Without the fix it fails with "a draw snapshot ends before the bytes the shader reads"; with it the whole binary passes. It skips itself without host imports or with an alignment outside 8 to 256. - Exercised in PPSA21564 on our integration branch: the flicker frames are gone. - `ctest --test-dir build`: 79/79 pass on current main with this branch. `agc_driver_recorder_tests` and `agc_driver_graphics_tests` 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: none - [x] AI-assisted: yes
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!202
No description provided.