fix(libc): preserve writes during partial shared-memory collection #3783

Merged
jweidenh merged 3 commits from upstream-pr/3783 into main 2026-10-11 22:01:09 +00:00
jweidenh commented 2026-10-11 16:40:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-11T16:40:29Z.


What

Preserve pending CPU writes when Windows collects only part of a shared direct-memory view. Shared views are 16 KiB, while GuestMemory collects and records CPU-write versions in 4 KiB pages. Collecting a prefix previously marked the entire view clean and advanced its seen generation, even though neighboring pages had not been reported. A later UnchangedSinceCollected could therefore incorrectly report a changed neighboring page as unchanged; GPU label synchronization uses that result.

Only mark the collected interval clean, advance seen when a whole view is collected, and stop at already-clean interior intervals instead of reporting them again. The existing early return for a full output buffer and non-reset collection semantics are preserved.

The regression maps direct memory twice on Windows to exercise the shared path, writes the last subpage, collects the first, and verifies that the last subpage is still observed as changed. It also checks independent alias observations, writes through either alias, repeated non-reset probes, previously cleared interior pages, limited output capacity and continuation. Both the normal and two-pass collectors are covered. The portable part runs on Linux; unavailable write watching follows the existing test skip convention.

PRs #637 and #2054 retain the defective shared-view path. This change is independent of their private direct-memory paths; the Windows fixture deliberately creates an alias so it stays relevant with either implementation.

Tested

Current head: 3b32e54ed90777c6dcdf6b7b5aa21f6cfb442bba, rebased onto 0a8b1d32b12a6d6a3acd462787750b482bf78884. The only conflict was adjacent CMake registration; upstream sRGB and both partial-collection cases were preserved. Production and regression-test source are unchanged.

Rebase validation on this exact head rebuilt the focused executables and patched runtime libraries. Windows 11 / RTX 5090 / NVIDIA 617.42 passed all seven cases again without skips (8.06 s total; slowest 2.75 s). Linux GCC 13.3 passed all four portable cases without skips (slowest 0.017 s), on the private self-hosted validation run.

Original regression validation: base a11c8f7f70a0ed4e71504a89de69e8cdae687817, test-only baseline 44bd7086aeba5e3c6b9f68b23c8f1a44083ac4db, fixed head 6b433a19a89a845539646dc740adf054447b90f7. The unchanged negative controls were not rerun after rebase.

  • Native Windows 11 Pro 10.0.26300, Ryzen 7 5800X, RTX 5090 / NVIDIA 617.42, portable WinLibs GCC 15.2.0 UCRT/POSIX/SEH, Release. The test-only baseline fails with partial collect lost a neighboring guest write in both normal and two-pass modes. Final head passes all 7/7 cases without skips or fatal output: agc_shared_write_partial_collect, agc_shared_write_partial_collect_two_pass, agc_shared_write, agc_write_tracking, agc_write_watch_coverage, agc_driver_unimported_label_order, and agc_driver_copied_writer_copy. Both Vulkan tests log selection of the RTX 5090 and reach their success markers. Total 1.16 s; every case below 0.48 s. The initial production-fix run also passed all seven tests (5.12 s total).
  • Linux x86-64 local self-hosted runner, Ubuntu GCC 13.3.0, Release, targeted executables plus all runtime libs: final head passes 4/4 portable cases (agc_shared_write_partial_collect, agc_shared_write, agc_write_tracking, agc_write_watch_coverage), without skips or fatal output, each below 0.012 s. Private run 38156295437, workflow commit 65edae1e06eb69cdb4a9925c6a54b3c09dffe838, pinned to the final source head above.
  • Conventions, whitespace checks and independent review pass.

This demonstrates the lost-write regression and related GPU memory-order/copy behavior. No retail-title reproduction or gameplay/FPS improvement is claimed.

Checklist

  • Based on current main; no other open PR implements the same fix
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no new stubs
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820630715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3783). Originally posted by [jweidenh](https://github.com/jweidenh) on 2026-10-11T16:40:29Z. --- ### What Preserve pending CPU writes when Windows collects only part of a shared direct-memory view. Shared views are 16 KiB, while `GuestMemory` collects and records CPU-write versions in 4 KiB pages. Collecting a prefix previously marked the entire view clean and advanced its `seen` generation, even though neighboring pages had not been reported. A later `UnchangedSinceCollected` could therefore incorrectly report a changed neighboring page as unchanged; GPU label synchronization uses that result. Only mark the collected interval clean, advance `seen` when a whole view is collected, and stop at already-clean interior intervals instead of reporting them again. The existing early return for a full output buffer and non-reset collection semantics are preserved. The regression maps direct memory twice on Windows to exercise the shared path, writes the last subpage, collects the first, and verifies that the last subpage is still observed as changed. It also checks independent alias observations, writes through either alias, repeated non-reset probes, previously cleared interior pages, limited output capacity and continuation. Both the normal and two-pass collectors are covered. The portable part runs on Linux; unavailable write watching follows the existing test skip convention. PRs #637 and #2054 retain the defective shared-view path. This change is independent of their private direct-memory paths; the Windows fixture deliberately creates an alias so it stays relevant with either implementation. ### Tested Current head: `3b32e54ed90777c6dcdf6b7b5aa21f6cfb442bba`, rebased onto `0a8b1d32b12a6d6a3acd462787750b482bf78884`. The only conflict was adjacent CMake registration; upstream sRGB and both partial-collection cases were preserved. Production and regression-test source are unchanged. Rebase validation on this exact head rebuilt the focused executables and patched runtime libraries. Windows 11 / RTX 5090 / NVIDIA 617.42 passed all seven cases again without skips (8.06 s total; slowest 2.75 s). Linux GCC 13.3 passed all four portable cases without skips (slowest 0.017 s), on the [private self-hosted validation run](https://github.com/hammerlab-dev/anyps5-validation/actions/runs/38171102322). Original regression validation: base `a11c8f7f70a0ed4e71504a89de69e8cdae687817`, test-only baseline `44bd7086aeba5e3c6b9f68b23c8f1a44083ac4db`, fixed head `6b433a19a89a845539646dc740adf054447b90f7`. The unchanged negative controls were not rerun after rebase. - Native Windows 11 Pro 10.0.26300, Ryzen 7 5800X, RTX 5090 / NVIDIA 617.42, portable WinLibs GCC 15.2.0 UCRT/POSIX/SEH, Release. The test-only baseline fails with `partial collect lost a neighboring guest write` in both normal and two-pass modes. Final head passes all **7/7** cases without skips or fatal output: `agc_shared_write_partial_collect`, `agc_shared_write_partial_collect_two_pass`, `agc_shared_write`, `agc_write_tracking`, `agc_write_watch_coverage`, `agc_driver_unimported_label_order`, and `agc_driver_copied_writer_copy`. Both Vulkan tests log selection of the RTX 5090 and reach their success markers. Total 1.16 s; every case below 0.48 s. The initial production-fix run also passed all seven tests (5.12 s total). - Linux x86-64 local self-hosted runner, Ubuntu GCC 13.3.0, Release, targeted executables plus all runtime `libs`: final head passes **4/4** portable cases (`agc_shared_write_partial_collect`, `agc_shared_write`, `agc_write_tracking`, `agc_write_watch_coverage`), without skips or fatal output, each below 0.012 s. Private run `38156295437`, workflow commit `65edae1e06eb69cdb4a9925c6a54b3c09dffe838`, pinned to the final source head above. - Conventions, whitespace checks and independent review pass. This demonstrates the lost-write regression and related GPU memory-order/copy behavior. No retail-title reproduction or gameplay/FPS improvement is claimed. ### Checklist - [x] Based on current `main`; no other open PR implements the same fix - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no new stubs - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 20:33:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T20:33:02Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3864 core/libs/prx/libc/include/WindowsMappings.hpp L238-239, L258-259
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113445512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3783#issuecomment-6113445512). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T20:33:02Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3864 | `core/libs/prx/libc/include/WindowsMappings.hpp` [L238-239](https://github.com/boykopovar/AnyPS5/blob/1be2ca2028f1caf4640a765941bfca2fae7d53f2/core/libs/prx/libc/include/WindowsMappings.hpp#L238-L239), [L258-259](https://github.com/boykopovar/AnyPS5/blob/1be2ca2028f1caf4640a765941bfca2fae7d53f2/core/libs/prx/libc/include/WindowsMappings.hpp#L258-L259) | | |
adriadam10 commented 2026-10-11 22:01:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:01:05Z.


Checked the Collect change against the surrounding walk (clean-range lookup, capacity-full early return, seen only on a whole view) and ran build + ctest for libSceAgcDriver and libc on Linux (447 tests green, agc_shared_write_partial_collect passes). The fix itself is Windows-only; relying on the Windows 11 runs in the description for that part. Merging.

Note for #3864: it rewrites the same loop in WindowsMappings::Collect and will need a rebase on this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114294076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3783#issuecomment-6114294076). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:01:05Z. --- Checked the `Collect` change against the surrounding walk (clean-range lookup, capacity-full early return, `seen` only on a whole view) and ran build + ctest for libSceAgcDriver and libc on Linux (447 tests green, `agc_shared_write_partial_collect` passes). The fix itself is Windows-only; relying on the Windows 11 runs in the description for that part. Merging. Note for #3864: it rewrites the same loop in `WindowsMappings::Collect` and will need a rebase on this one.
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!3783
No description provided.