perf(agc): bind misaligned draw buffer regions in place through the view adjustment #2176

Merged
oneandonlydean merged 1 commit from upstream-pr/2176 into main 2026-10-09 21:49:13 +00:00
oneandonlydean commented 2026-10-09 10:41:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T10:41:56Z.


What

A draw build that is not address-based and whose every guest buffer element has a memory offset slot (a push constant byte, or a shader data byte inside its data buffer) binds a region whose offset in its host import is DWORD aligned in place (GuestBufferMemory::AllowAdjustedRegions, bindableInPlace), like a region at minStorageBufferOffsetAlignment:

  • Descriptor binds the view from the aligned offset below it and the shader gets the remainder through its memory offset slot, as it already does for misaligned views;
  • read-only views are snapshotted per draw by PrepareDrawBindings at address - adjustment;
  • the import serial keys the template and Revalidate proves it per use, as for aligned regions.

Dispatches keep the copy: they read in-place inputs at execution, not at record.

Why

Such a region was copied per build: a new buffer, an input snapshot, and a vkCmdCopyBuffer that ends the open render pass. DirectRegions also refused the build as a template. In the level measured below, binding them in place more than doubles the draws that continue an open render pass.

Tested

  • Linux (CachyOS, GCC 16.2, RTX 4090, NVIDIA 610.57), on main a8b032b236: ctest 495/495. tools/check_conventions.py passes.

  • agc_driver_recorder_tests, new misalignedRegionTests: a misaligned read-only draw region is read in place and the build is reusable (on main it is copied and the check fails); the push constant carries the adjustment; the per-draw snapshot starts at the aligned offset below the view and holds the view's bytes after a CPU store. ctest builds this executable but does not run it; run by hand, it passes misalignedRegionTests and stops later at importWindowTests "(w) a cache over the pages the import reported sees no change", which fails the same way on main.

  • A heavier title, one level, frames per second over level start +30 to +150 s, warm caches, two runs with the change and four of the base. It does not reach the level on main alone, so this was measured with the fixes needed for the title to reach the level: main 4b6ab6bb73 plus the boot fixes, #425 (with a depth-plane read fix), #1274, #1745, #1059 and an import budget like #290's. The base is that build:

    build level fps Graphics::Draw per draw packet draws continuing a render pass per 10 s
    base (4 runs) 0.455 / 0.448 / 0.415 / 0.436 180-199 µs 4.4k
    base + this 0.596 / 0.558 99 / 117 µs 10.2k

    Level frames show the same scene, geometry and brightness as the base.

  • A lighter title that runs at 60 fps: unchanged, 60.0 fps menu, 59.9 fps gameplay, no skipped draws, all screen checks 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 (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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799320304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2176). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T10:41:56Z. --- ### What A draw build that is not address-based and whose every guest buffer element has a memory offset slot (a push constant byte, or a shader data byte inside its data buffer) binds a region whose offset in its host import is DWORD aligned in place (`GuestBufferMemory::AllowAdjustedRegions`, `bindableInPlace`), like a region at `minStorageBufferOffsetAlignment`: - `Descriptor` binds the view from the aligned offset below it and the shader gets the remainder through its memory offset slot, as it already does for misaligned views; - read-only views are snapshotted per draw by `PrepareDrawBindings` at `address - adjustment`; - the import serial keys the template and `Revalidate` proves it per use, as for aligned regions. Dispatches keep the copy: they read in-place inputs at execution, not at record. ### Why Such a region was copied per build: a new buffer, an input snapshot, and a `vkCmdCopyBuffer` that ends the open render pass. `DirectRegions` also refused the build as a template. In the level measured below, binding them in place more than doubles the draws that continue an open render pass. ### Tested - Linux (CachyOS, GCC 16.2, RTX 4090, NVIDIA 610.57), on `main` a8b032b236: ctest 495/495. `tools/check_conventions.py` passes. - `agc_driver_recorder_tests`, new `misalignedRegionTests`: a misaligned read-only draw region is read in place and the build is reusable (on `main` it is copied and the check fails); the push constant carries the adjustment; the per-draw snapshot starts at the aligned offset below the view and holds the view's bytes after a CPU store. ctest builds this executable but does not run it; run by hand, it passes `misalignedRegionTests` and stops later at `importWindowTests` "(w) a cache over the pages the import reported sees no change", which fails the same way on `main`. - A heavier title, one level, frames per second over level start +30 to +150 s, warm caches, two runs with the change and four of the base. It does not reach the level on `main` alone, so this was measured with the fixes needed for the title to reach the level: `main` 4b6ab6bb73 plus the boot fixes, #425 (with a depth-plane read fix), #1274, #1745, #1059 and an import budget like #290's. The base is that build: | build | level fps | `Graphics::Draw` per draw packet | draws continuing a render pass per 10 s | |---|---|---|---| | base (4 runs) | 0.455 / 0.448 / 0.415 / 0.436 | 180-199 µs | 4.4k | | base + this | 0.596 / 0.558 | 99 / 117 µs | 10.2k | Level frames show the same scene, geometry and brightness as the base. - A lighter title that runs at 60 fps: unchanged, 60.0 fps menu, 59.9 fps gameplay, no skipped draws, all screen checks 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
rmz-24 commented 2026-10-09 12:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T12:38:41Z.


Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. ac2d172e cherry-picked onto current main d70b8998 (applies cleanly).

  • agc_driver_recorder_tests run directly: misalignedRegionTests runs on this host (no "not tested" message, host imports available, minStorageBufferOffsetAlignment in range) and passes. The suite then stops later at the refresh-store assertion that main also hits on Windows (#2155), which this change doesn't touch.
  • Full ctest: 510/510.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081052136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2176#issuecomment-6081052136). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T12:38:41Z. --- Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, full build plus `libs`. ac2d172e cherry-picked onto current `main` d70b8998 (applies cleanly). - `agc_driver_recorder_tests` run directly: `misalignedRegionTests` runs on this host (no "not tested" message, host imports available, `minStorageBufferOffsetAlignment` in range) and passes. The suite then stops later at the refresh-store assertion that `main` also hits on Windows (#2155), which this change doesn't touch. - Full ctest: 510/510. 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!2176
No description provided.